#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));
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;
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)