/ChunkFix

By SReject on Sep 17, 2011

This snippet removes the header and "chunk-length" from a &bvar containing the header and page content read from an http socket.

To Use: /ChunkFix &inputvaraible

alias ChunkFix {
  if ($1 == &CF:Size) { echo -ac info2 * /ChunkFix: Input varaible cannot be "&CF:Size" | halt }
  if ($1 == &CF:Head) { echo -ac info2 * /ChunkFix: Input varaible cannot be "&CF:Head" | halt }
  if ($1 == &CF:Page) { echo -ac info2 * /ChunkFix: Input varaible cannot be "&CF:Page" | halt }
  if (!$bvar($1,0)) { echo -ac info2 * /ChunkFix: Invalid varaible specified. | halt }

  if ($bfind($1,1,$crlf $+ $crlf) == 0) return
  bcopy &CF:Head 1 $1 1 $calc($v1 +3)
  bcopy -c $1 1 $1 $calc($v1 +4) -1
  if ($bfind(&CF:Head,1,Transfer-Encoding: chunked) == 0) return
  var %x = 1
  while ($bfind($1,1,$crlf)) {
    bcopy -c &CF:Size 1 $1 1 %cend $calc($v1 -1)
    if ($base($bvar(&CF:Size,1,$bvar(&CF:Size,0)).text,16,10)) {
      bcopy -c &CF:Page $calc($bvar(&CF:Page,0) +1) $1 $calc($bvar(&CF:Size,0) + 3) $v1
      bcopy -c $1 1 $1 $calc($bvar(&CF:Size,0) +5 + $v1) -1
    }
    else break
  }
  bcopy -c $1 1 &CF:Page 1 -1
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.