- some minor strlen() and strlcat() tweaks
[m6w6/ext-http] / http_request_method_api.c
index 57636d088b2b065e7e050bc3015a6859803ea2cf..a2197c6425324305a4bfb6b15c10d14b48bb2048 100644 (file)
@@ -28,6 +28,7 @@
 #      include "php_http_request_object.h"
 #endif
 
 #      include "php_http_request_object.h"
 #endif
 
+#include "missing.h"
 #include "phpstr/phpstr.h"
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
 #include "phpstr/phpstr.h"
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
@@ -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 *) */
 /* }}} */
 
 /* {{{ 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;
 {
        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[i] = toupper(method_name[i]);
        }
-       method[method_len] = '\0';
+       method[method_name_len] = '\0';
        
        
-       Z_ARRVAL(array) = &HTTP_G(request).methods.custom;
-       add_next_index_stringl(&array, method, method_len, 0);
+       INIT_ZARR(array, &HTTP_G(request).methods.custom);
+       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);
        
        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
 
        efree(http_method);
 #endif
 
@@ -196,7 +196,7 @@ PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_
                return FAILURE;
        }
 
                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);
        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);