- fix "UNKNOWN" for unknown request methods
[m6w6/ext-http] / http_request_method_api.c
index 28365f73edc080d473b32b78694dd861ab97692e..595a1de5bfb7e39b01e93eb8d8e1447ee1826fb0 100644 (file)
 #      include "php_http_request_object.h"
 #endif
 
+#include "missing.h"
 #include "phpstr/phpstr.h"
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
 /* {{{ char *http_request_methods[] */
 static const char *const http_request_methods[] = {
-       "UNKOWN",
+       "UNKNOWN",
        /* HTTP/1.1 */
        "GET",
        "HEAD",
@@ -154,29 +155,28 @@ PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsign
 /* }}} */
 
 /* {{{ unsigned long http_request_method_register(char *) */
-PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name TSRMLS_DC)
+PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name, size_t method_name_len TSRMLS_DC)
 {
        zval array;
        char *http_method, *method;
-       int i, method_len = strlen(method_name);
-       unsigned long meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
+       unsigned long i, meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
 
-       method = emalloc(method_len + 1);
-       for (i = 0; i < method_len; ++i) {
+       method = emalloc(method_name_len + 1);
+       for (i = 0; i < method_name_len; ++i) {
                method[i] = toupper(method_name[i]);
        }
-       method[method_len] = '\0';
+       method[method_name_len] = '\0';
        
        INIT_ZARR(array, &HTTP_G(request).methods.custom);
-       add_next_index_stringl(&array, method, method_len, 0);
+       add_next_index_stringl(&array, method, method_name_len, 0);
 
-       method_len = spprintf(&http_method, 0, "HTTP_METH_%s", method);
-       zend_register_long_constant(http_method, method_len + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC);
+       method_name_len = spprintf(&http_method, 0, "HTTP_METH_%s", method);
+       zend_register_long_constant(http_method, method_name_len + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC);
        efree(http_method);
        
-#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
-       method_len = spprintf(&http_method, 0, "METH_%s", method);
-       zend_declare_class_constant_long(http_request_object_ce, http_method, method_len, meth_num TSRMLS_CC);
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
+       method_name_len = spprintf(&http_method, 0, "METH_%s", method);
+       zend_declare_class_constant_long(http_request_object_ce, http_method, method_name_len, meth_num TSRMLS_CC);
        efree(http_method);
 #endif
 
@@ -196,7 +196,7 @@ PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_
                return FAILURE;
        }
 
-#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
        method_len = spprintf(&http_method, 0, "METH_%s", Z_STRVAL_PP(zmethod));
        if ((SUCCESS != zend_hash_del(&http_request_object_ce->constants_table, http_method, method_len + 1))) {
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: HttpRequest::%s", http_method);