Config.w32: add curl dependent libs
[m6w6/ext-http] / src / php_http_version.c
index 7adef9d3c897ce66f5923b981c74bd3b46a992d0..043b4b33ef4a4d0e5a11b0feb258355bac358381 100644 (file)
@@ -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)