X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_version.c;h=043b4b33ef4a4d0e5a11b0feb258355bac358381;hp=7adef9d3c897ce66f5923b981c74bd3b46a992d0;hb=b2f41a29a8e35559157619218e8978d4780c2f46;hpb=bdd6edb59194cda9e5fcb393c48ab4230fceb32a diff --git a/src/php_http_version.c b/src/php_http_version.c index 7adef9d..043b4b3 100644 --- a/src/php_http_version.c +++ b/src/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,7 +24,7 @@ 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; @@ -44,25 +44,41 @@ php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *st 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 - 2); - } + switch (separator) { + default: + php_error_docref(NULL, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2); + /* no break */ + case '.': + case ',': minor = *ptr - '0'; - if (minor >= 0 && minor <= 9) { - return php_http_version_init(v, major, minor TSRMLS_CC); + break; + + case ' ': + if (major > 1) { + minor = 0; + } else { + goto error; } } + if (minor >= 0 && minor <= 9) { + return php_http_version_init(v, major, minor); + } } } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP protocol version '%s'", str); + error: + php_error_docref(NULL, E_WARNING, "Could not parse HTTP protocol version '%s'", str); 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 : ""); + /* different semantics for different versions */ + if (v->major == 2) { + *len = spprintf(str, 0, "%s2%s", STR_PTR(pre), STR_PTR(post)); + } else { + *len = spprintf(str, 0, "%s%u.%u%s", STR_PTR(pre), v->major, v->minor, STR_PTR(post)); + } } void php_http_version_dtor(php_http_version_t *v)