static void process_header(struct http_ctx *cx, char *str) { char *p; if (cx->chunkhdr) { p = strchr(str, ';'); if (p) *p = 0; cx->rxtogo = strtoul(str, NULL, 16); cx->chunkhdr = 0; if (!cx->rxtogo) cx->chunked = 0; } if (!str[0]) { cx->rxtogo = cx->contlen; cx->chunkhdr = cx->chunked; if (!cx->contlen && !cx->chunked && cx->ret!=100) cx->state = HTS_DONE; return; } if (!strncmp(str, "HTTP/", 5)) { p = strchr(str, ' '); if (!p) { cx->ret = 603; cx->state = HTS_DONE; return; } p++; cx->ret = atoi(p); return; } if (!strncmp(str, "Content-Length: ", 16)) { str = eatwhitespace(str+16); cx->contlen = atoi(str); return; } if (!strncmp(str, "Transfer-Encoding: ", 19)) { str = eatwhitespace(str+19); if(!strncmp(str, "chunked", 8)) { cx->chunked = 1; } return; } if (!strncmp(str, "Connection: ", 12)) { str = eatwhitespace(str+12); if(!strncmp(str, "close", 6)) { cx->cclose = 1; } return; } }
token_type_t get_token(tokenizer_t* t) { if (t->token_value) { free(t->token_value); t->token_value = NULL; } eatwhitespace(t); stack_push(t->index_stack, &t->source_index); if ('\0' == t->source[t->source_index]) { t->token_type = TT_EOF; return TT_EOF; } if (is_digit(t->source[t->source_index])) { tokenize_number(t); return TT_NUMBER; } if (is_alpha(t->source[t->source_index])) { tokenize_identifier(t); return TT_IDENT; } if ('"' == t->source[t->source_index]) { tokenize_string(t); return TT_STRING; } return TT_UNKNOWN; }