- fix default send buffer size
[m6w6/ext-http] / http_request_method_api.c
index 498dbe2f54b6644cc6fa0b9231c84dd4696fe35e..b587474d26a53c33c70ce44cecc15554f0b56e62 100644 (file)
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2006, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2007, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
@@ -103,6 +103,20 @@ PHP_RINIT_FUNCTION(http_request_method)
 {
        HTTP_G->request.methods.custom.entries = ecalloc(1, sizeof(http_request_method_entry *));
        
+       if (HTTP_G->request.methods.custom.ini && *HTTP_G->request.methods.custom.ini) {
+               HashPosition pos;
+               HashTable methods;
+               zval **data;
+       
+               zend_hash_init(&methods, 0, NULL, ZVAL_PTR_DTOR, 0);
+               http_parse_params(HTTP_G->request.methods.custom.ini, HTTP_PARAMS_DEFAULT, &methods);
+               FOREACH_HASH_VAL(pos, &methods, data) {
+                       if (Z_TYPE_PP(data) == IS_STRING) {
+                               http_request_method_register(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
+                       }
+               }
+               zend_hash_destroy(&methods);
+       }
        return SUCCESS;
 }
 
@@ -177,7 +191,7 @@ PHP_HTTP_API int _http_request_method_register(const char *method_name, int meth
        char *http_method, *method, *mconst;
        http_request_method_entry **ptr = HTTP_G->request.methods.custom.entries;
        
-       if (!isalpha(*method_name)) {
+       if (!HTTP_IS_CTYPE(alpha, *method_name)) {
                http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does not start with a character (%s)", method_name);
                return 0;
        }
@@ -190,22 +204,21 @@ PHP_HTTP_API int _http_request_method_register(const char *method_name, int meth
        method = emalloc(method_name_len + 1);
        mconst = emalloc(method_name_len + 1);
        for (i = 0; i < method_name_len; ++i) {
-               switch (method_name[i])
-               {
+               switch (method_name[i]) {
                        case '-':
                                method[i] = '-';
                                mconst[i] = '_';
-                       break;
+                               break;
                        
                        default:
-                               if (!isalnum(method_name[i])) {
+                               if (!HTTP_IS_CTYPE(alnum, method_name[i])) {
                                        efree(method);
                                        efree(mconst);
                                        http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method contains illegal characters (%s)", method_name);
                                        return 0;
                                }
-                               mconst[i] = method[i] = toupper(method_name[i]);
-                       break;
+                               mconst[i] = method[i] = HTTP_TO_CTYPE(upper, method_name[i]);
+                               break;
                }
        }
        method[method_name_len] = '\0';
@@ -247,7 +260,7 @@ PHP_HTTP_API STATUS _http_request_method_unregister(int method TSRMLS_DC)
        if (    (HTTP_CUSTOM_REQUEST_METHOD(method) < 0) ||
                        (HTTP_CUSTOM_REQUEST_METHOD(method) > HTTP_G->request.methods.custom.count) ||
                        (!ptr[HTTP_CUSTOM_REQUEST_METHOD(method)])) {
-               http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Custom request method with id %lu does not exist", method);
+               http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Custom request method with id %d does not exist", method);
                return FAILURE;
        }