X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_headers_api.c;h=09673e99a884d9f6c23a5a4dda075ca704535f21;hb=47c525716db7a03c84af5efc9953db3634084263;hp=933b4c8b003922b4490e8a442fd2dac30a20c8ae;hpb=1076272e2da97d6df6c2f2423b92a1694709e65a;p=m6w6%2Fext-http diff --git a/http_headers_api.c b/http_headers_api.c index 933b4c8..09673e9 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -111,7 +111,7 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_ range = Z_STRVAL_P(zrange); if (strncmp(range, "bytes=", sizeof("bytes=") - 1)) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Range header misses bytes="); + http_error(E_NOTICE, HTTP_E_HEADER, "Range header misses bytes="); return RANGE_NO; } @@ -248,7 +248,8 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(char *header, size_t header_len, Z_ARRVAL(array) = headers; - if (header_len < 2) { + if (header_len < 2 || !strchr(header, ':')) { + http_error(E_WARNING, HTTP_E_PARSE, "Cannot parse too short or malformed HTTP headers"); return FAILURE; } @@ -267,18 +268,18 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(char *header, size_t header_len, if ( (!strncmp(header, "HTTP/1.", lenof("HTTP/1."))) || (!strncmp(line - lenof("HTTP/1.x\r") + value_len, "HTTP/1.", lenof("HTTP/1.")))) { if (func) { - func(callback_data, header, header - (line + 1), &headers TSRMLS_CC); + func(callback_data, header, line - header + value_len, &headers TSRMLS_CC); Z_ARRVAL(array) = headers; } } else - + /* "header: value" pair */ if (colon) { /* skip empty key */ if (header != colon) { zval **previous = NULL; - char *value = empty_string; + char *value; int keylen = colon - header; char *key = estrndup(header, keylen); @@ -296,6 +297,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(char *header, size_t header_len, if (value_len > 0) { value = estrndup(colon, value_len); } else { + value = estrdup(""); value_len = 0; } @@ -343,15 +345,15 @@ PHP_HTTP_API void _http_parse_headers_default_callback(void **cb_data, char *htt { zval array; Z_ARRVAL(array) = *headers; - + /* response */ if (!strncmp(http_line, "HTTP/1.", lenof("HTTP/1."))) { - add_assoc_stringl(&array, "Response Status", http_line + lenof("HTTP/1.x "), line_length - lenof("HTTP/1.x \r\n"), 0); + add_assoc_stringl(&array, "Response Status", http_line + lenof("HTTP/1.x "), line_length - lenof("HTTP/1.x \r\n"), 1); } else /* request */ if (!strncmp(http_line + line_length - lenof("HTTP/1.x\r\n"), "HTTP/1.", lenof("HTTP/1."))) { char *sep = strchr(http_line, ' '); - + add_assoc_stringl(&array, "Request Method", http_line, sep - http_line, 1); add_assoc_stringl(&array, "Request Uri", sep + 1, strstr(sep, "HTTP/1.") - sep + 1 + 1, 1); }