- unset in http_curl_defaults() too
[m6w6/ext-http] / http_request_method_api.c
index 8c1812965f5851a77d8b4933a455e6a66cfd59de..37895d7d916b3da0f4917b32c93c80180d2b625b 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",
@@ -70,7 +71,7 @@ static const char *const http_request_methods[] = {
 };
 /* }}} */
 
-STATUS _http_request_method_global_init(INIT_FUNC_ARGS)
+PHP_MINIT_FUNCTION(http_request_method)
 {
        /* HTTP/1.1 */
        HTTP_LONG_CONSTANT("HTTP_METH_GET", HTTP_GET);
@@ -107,6 +108,17 @@ STATUS _http_request_method_global_init(INIT_FUNC_ARGS)
        return SUCCESS;
 }
 
+PHP_RSHUTDOWN_FUNCTION(http_request_method)
+{
+       int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom);
+       
+       for (i = 0; i < c; ++i) {
+               http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i);
+       }
+       
+       return SUCCESS;
+}
+
 /* {{{ char *http_request_method_name(http_request_method) */
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC)
 {
@@ -154,29 +166,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) && !defined(WONKY)
-       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);
+       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