X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_info_api.c;h=9cd8fbe451e542faa37eee977145e20daf4190ef;hp=244b6808f76ed5a01deee9d08e18a41cd6535ef0;hb=878af6cf27f64a1979100ecb0d74e4c972da13d8;hpb=438d27e988e114136d931c6e3586ce3ee38e2ad2 diff --git a/http_info_api.c b/http_info_api.c index 244b680..9cd8fbe 100644 --- a/http_info_api.c +++ b/http_info_api.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2006, Michael Wallner | + | Copyright (c) 2004-2007, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -97,8 +97,18 @@ PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info, const char *code = http + sizeof("HTTP/1.1"); info->type = IS_HTTP_RESPONSE; - HTTP_INFO(info).response.code = (code && (end > code)) ? strtol(code, &status, 10) : 0; - HTTP_INFO(info).response.status = (status && (end > ++status)) ? estrndup(status, end - status) : ecalloc(1,1); + while (' ' == *code) ++code; + if (code && end > code) { + HTTP_INFO(info).response.code = strtol(code, &status, 10); + } else { + HTTP_INFO(info).response.code = 0; + } + if (status && end > status) { + while (' ' == *status) ++status; + HTTP_INFO(info).response.status = estrndup(status, end - status); + } else { + HTTP_INFO(info).response.status = NULL; + } return SUCCESS; } @@ -110,10 +120,17 @@ PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info, info->type = IS_HTTP_REQUEST; if (url && http > url) { HTTP_INFO(info).request.method = estrndup(pre_header, url - pre_header); - HTTP_INFO(info).request.url = estrndup(url + 1, http - url - 2); + while (' ' == *url) ++url; + while (' ' == *(http-1)) --http; + if (http > url) { + HTTP_INFO(info).request.url = estrndup(url, http - url); + } else { + efree(HTTP_INFO(info).request.method); + return FAILURE; + } } else { - HTTP_INFO(info).request.method = ecalloc(1,1); - HTTP_INFO(info).request.url = ecalloc(1,1); + HTTP_INFO(info).request.method = NULL; + HTTP_INFO(info).request.url = NULL; } return SUCCESS; @@ -125,7 +142,6 @@ PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info, } } - /* * Local variables: * tab-width: 4