- do {
- if ((eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) {
- if (eol_str + eol_len - buffer->data < buffer->used) {
- char nextline = *(eol_str + eol_len);
-
- if (nextline == '\t' || nextline == ' ') {
- php_http_buffer_cut(buffer, eol_str - buffer->data, eol_len);
- continue;
- }
+#define SET_ADD_VAL(slen, eol_len) \
+ do { \
+ const char *ptr = buffer->data; \
+ size_t len = slen; \
+ \
+ while (len > 0 && PHP_HTTP_IS_CTYPE(space, *ptr)) { \
+ ++ptr; \
+ --len; \
+ } \
+ while (len > 0 && PHP_HTTP_IS_CTYPE(space, ptr[len - 1])) { \
+ --len; \
+ } \
+ \
+ if (len > 0) { \
+ if (parser->_val.str) { \
+ parser->_val.str = erealloc(parser->_val.str, parser->_val.len + len + 2); \
+ parser->_val.str[parser->_val.len++] = ' '; \
+ memcpy(&parser->_val.str[parser->_val.len], ptr, len); \
+ parser->_val.len += len; \
+ parser->_val.str[parser->_val.len] = '\0'; \
+ } else { \
+ parser->_val.len = len; \
+ parser->_val.str = estrndup(ptr, len); \
+ } \
+ } \
+ php_http_buffer_cut(buffer, 0, slen + eol_len); \
+ } while (0)
+
+ if ((eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) {
+ SET_ADD_VAL(eol_str - buffer->data, eol_len);
+
+ if (buffer->used) {
+ if (*buffer->data != '\t' && *buffer->data != ' ') {
+ php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE);
+ break;
+ } else {
+ php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_VALUE);
+ break;