Merge branch 'v2.6.x'
authorMichael Wallner <mike@php.net>
Thu, 8 Sep 2016 06:30:51 +0000 (08:30 +0200)
committerMichael Wallner <mike@php.net>
Thu, 8 Sep 2016 06:30:51 +0000 (08:30 +0200)
1  2 
src/php_http_info.c
src/php_http_info.h
src/php_http_message.c
src/php_http_version.c

index 4e43fda8eaa27888c6b72aca907d8e2f5fcf1ac7,81bf727b1e4d135bf931af3b084984743f41dc0a..cbaee88490c17421a7c618f7653ed2c6c8c819bc
@@@ -49,7 -49,47 +49,47 @@@ void php_http_info_free(php_http_info_
        }
  }
  
 -void php_http_info_to_string(php_http_info_t *info, char **str, size_t *len, const char *eol TSRMLS_DC)
++void php_http_info_to_string(php_http_info_t *info, char **str, size_t *len, const char *eol)
+ {
+       char *tmp = NULL;
+       if (info->http.version.major == 2) {
+               if (info->type == PHP_HTTP_REQUEST) {
+                       *len = spprintf(str, 0, "%s %s HTTP/2%s",
+                                       info->http.info.request.method?info->http.info.request.method:"UNKNOWN",
+                                       info->http.info.request.method&&!strcasecmp(info->http.info.request.method,"CONNECT")?(
+                                       info->http.info.request.url?php_http_url_authority_to_string(info->http.info.request.url, &(tmp), NULL):"0"):(
+                                       info->http.info.request.url?php_http_url_to_string(info->http.info.request.url, &(tmp), NULL, 0):"/"),
+                                       eol);
+               } else if (info->type == PHP_HTTP_RESPONSE) {
+                       *len = spprintf(str, 0, "HTTP/2 %d%s%s%s",
+                                       info->http.info.response.code?info->http.info.response.code:200,
+                                       info->http.info.response.status&&*info->http.info.response.status ? " ":"",
+                                       STR_PTR(info->http.info.response.status),
+                                       eol);
+               }
+       } else if (info->type == PHP_HTTP_REQUEST) {
+               *len = spprintf(str, 0, "%s %s HTTP/%u.%u%s",
+                               info->http.info.request.method?info->http.info.request.method:"UNKNOWN",
+                               info->http.info.request.method&&!strcasecmp(info->http.info.request.method,"CONNECT")?(
+                               info->http.info.request.url?php_http_url_authority_to_string(info->http.info.request.url, &(tmp), NULL):"0"):(
+                               info->http.info.request.url?php_http_url_to_string(info->http.info.request.url, &(tmp), NULL, 0):"/"),
+                               info->http.version.major||info->http.version.major?info->http.version.major:1,
+                               info->http.version.major||info->http.version.minor?info->http.version.minor:1,
+                               eol);
+       } else if (info->type == PHP_HTTP_RESPONSE){
+               *len = spprintf(str, 0, "HTTP/%u.%u %d%s%s%s", info->http.version.major||info->http.version.major?info->http.version.major:1,
+                               info->http.version.major||info->http.version.minor?info->http.version.minor:1,
+                               info->http.info.response.code?info->http.info.response.code:200,
+                               info->http.info.response.status&&*info->http.info.response.status ? " ":"",
+                               STR_PTR(info->http.info.response.status),
+                               eol);
+       }
 -      STR_FREE(tmp);
++      PTR_FREE(tmp);
+ }
 -php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC)
 +php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header)
  {
        const char *end, *http, *off;
        zend_bool free_info = !info;
index 8a52ee2df19adf543a89e0be0b6adab47e42ed8a,e1cce6fc6766a876591ee308af41f4e1ebad7515..700dd34d96431b4ba670364d03390748fd3d6332
@@@ -58,10 -41,11 +43,11 @@@ typedef struct php_http_info 
        PHP_HTTP_INFO_IMPL(http, type)
  } php_http_info_t;
  
 -typedef zend_bool (*php_http_info_callback_t)(void **callback_data, HashTable **headers, php_http_info_t *info TSRMLS_DC);
 +typedef zend_bool (*php_http_info_callback_t)(void **callback_data, HashTable **headers, php_http_info_t *info);
  
 -PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *info TSRMLS_DC);
 -PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC);
 -PHP_HTTP_API void php_http_info_to_string(php_http_info_t *info, char **str, size_t *len, const char *eol TSRMLS_DC);
 +PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *info);
 +PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header);
++PHP_HTTP_API void php_http_info_to_string(php_http_info_t *info, char **str, size_t *len, const char *eol);
  PHP_HTTP_API void php_http_info_dtor(php_http_info_t *info);
  PHP_HTTP_API void php_http_info_free(php_http_info_t **info);
  
index 078ae4cea4f90fa28a478fc837f920f0546ad06c,60569b8be62f336f2199ba72196c6fe1f8178e03..5a5b5ca4f0d222c3e085b8cf763dcbf900fad934
@@@ -330,24 -358,15 +330,14 @@@ void php_http_message_update_headers(ph
  static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
  {
        char *tmp = NULL;
 -      TSRMLS_FETCH_FROM_CTX(msg->ts);
+       size_t len = 0;
  
-       switch (msg->type) {
-               case PHP_HTTP_REQUEST:
-                       php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
-                       PTR_FREE(tmp);
-                       break;
-               case PHP_HTTP_RESPONSE:
-                       php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
-                       PTR_FREE(tmp);
-                       break;
-               default:
-                       break;
-       }
+       php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF TSRMLS_CC);
        php_http_message_update_headers(msg);
 -      php_http_header_to_string(str, &msg->hdrs TSRMLS_CC);
 -      STR_FREE(tmp);
+       php_http_buffer_append(str, tmp, len);
 +      php_http_header_to_string(str, &msg->hdrs);
++      PTR_FREE(tmp);
  }
  
  void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
@@@ -1375,27 -1381,15 +1365,14 @@@ ZEND_END_ARG_INFO()
  static PHP_METHOD(HttpMessage, getInfo)
  {
        if (SUCCESS == zend_parse_parameters_none()) {
-               char *str, *tmp = NULL;
-               size_t len;
++              char *str = NULL;
+               size_t len = 0;
 -              php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 +              php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
  
                PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
-               switch (obj->message->type) {
-                       case PHP_HTTP_REQUEST:
-                               len = spprintf(&str, 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, ""));
-                               PTR_FREE(tmp);
-                               break;
-                       case PHP_HTTP_RESPONSE:
-                               len = spprintf(&str, 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
-                               PTR_FREE(tmp);
-                               break;
-                       default:
-                               RETURN_NULL();
-                               break;
-               }
++              php_http_info_to_string((php_http_info_t *) obj->message, &str, &len, "");
  
 -              php_http_info_to_string((php_http_info_t *) obj->message, &Z_STRVAL_P(return_value), &len, "" TSRMLS_CC);
 -              Z_STRLEN_P(return_value) = len;
 -              Z_TYPE_P(return_value) = IS_STRING;
 -              return;
 +              RETVAL_STR(php_http_cs2zs(str, len));
        }
  }
  
index 7f7d34245384f000376d2ba6f1725dac3131c466,2cba01e3615ae773eecdec6ca42fe44d1b4d6b72..043b4b33ef4a4d0e5a11b0feb258355bac358381
@@@ -71,9 -71,14 +71,14 @@@ php_http_version_t *php_http_version_pa
        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)