X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_version.c;h=5e8008dc2aacb3f19e9a80161d804270d3cf34cc;hp=f4fcfc85367417dee7cb8f711fe39d89f18250b3;hb=468e8d748d365811af4ce890fd8fc4c1f88cc08a;hpb=5dc1e4273e37ed0cb37bc7cb1e7168a61374c367 diff --git a/php_http_version.c b/php_http_version.c index f4fcfc8..5e8008d 100644 --- a/php_http_version.c +++ b/php_http_version.c @@ -12,7 +12,7 @@ #include "php_http_api.h" -php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC) +php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor) { if (!v) { v = emalloc(sizeof(*v)); @@ -24,10 +24,10 @@ php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, return v; } -php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC) +php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str) { long major, minor; - char separator = 0, *stop = NULL; + char separator = 0; register const char *ptr = str; switch (*ptr) { @@ -40,16 +40,16 @@ php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *st ++ptr; /* no break */ default: - major = strtol(ptr, &stop, 10); - if (stop && stop != ptr && major != LONG_MIN && major != LONG_MAX) { - separator = *stop; + /* rfc7230#2.6 The HTTP version number consists of two decimal digits separated by a "." (period or decimal point) */ + major = *ptr++ - '0'; + if (major >= 0 && major <= 9) { + separator = *ptr++; if (separator) { if (separator != '.' && separator != ',') { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2); } - ptr = stop + 1; - minor = strtol(ptr, &stop, 10); - if (minor != LONG_MIN && minor != LONG_MAX) { + minor = *ptr - '0'; + if (minor >= 0 && minor <= 9) { return php_http_version_init(v, major, minor TSRMLS_CC); } } @@ -60,7 +60,7 @@ php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *st return NULL; } -void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC) +void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post) { *len = spprintf(str, 0, "%s%u.%u%s", pre ? pre : "", v->major, v->minor, post ? post : ""); }