Live data from Hacker News

Chunked-transfer decoding from stdin yy045

news.ycombinator.com

1–2 of 2 posts

Re: Chunked-transfer decoding from stdin yy045

#2

   /* chunked transfer decoding */
   
    #define echo do{if(fwrite(yytext,(size_t)yyleng,1,yyout)){}}while(0)
    #define jmp (yy_start) = 1 + 2 *
    int fileno (FILE *);
    int ischunked,chunksize,count;
   xa "\15"|"\12"
   xb "\15\12" 
   xc "HTTP/0.9"|"HTTP/1.0"|"HTTP/1.1"
   xd [Cc][Hh][Uu][Nn][Kk][Ee][Dd]
   xe [0-9a-fA-F]+\r\n
   xf [0-9a-fA-F]*\r\n
   %option noyywrap nounput noinput 
   %s xb xc xd xe xf
   %%
   ^{xc} echo;ischunked=0;jmp xc;
   ^transfer-encoding: echo;jmp xb;
   \r\n\r\n echo;jmp xe;
   {xd} echo;ischunked=1;
   {xf}|{xe} {
   count=0;
   if(ischunked==1)
   {chunksize=strtol(yytext,NULL,16);
   jmp xd;};
   };
   {xb} jmp xf;
   . { 
   count++;
   if(count==chunksize)jmp xe;
   echo;
   };
   ^[A-Fa-f0-9]+{xa}
   {xa}+[A-Fa-f0-9]+{xa}
   {xb}[A-Fa-f0-9]+{xb}
   %%
   int main(){ yylex();exit(0);}