- more descriptive constant names
authorMichael Wallner <mike@php.net>
Thu, 15 Sep 2005 13:39:03 +0000 (13:39 +0000)
committerMichael Wallner <mike@php.net>
Thu, 15 Sep 2005 13:39:03 +0000 (13:39 +0000)
- add request method constants to HttpRequest and handle them in method_(un)register()

http.c
http_message_object.c
http_request_api.c
http_request_method_api.c
http_request_object.c
php_http_request_method_api.h

diff --git a/http.c b/http.c
index b14befebaee917925b89edb31ced7549a479eefd..700fa9e33bc6923624bb573d811fe356fcd3300d 100644 (file)
--- a/http.c
+++ b/http.c
@@ -268,6 +268,9 @@ PHP_MINIT_FUNCTION(http)
        if (SUCCESS != http_cache_global_init()) {
                return FAILURE;
        }
+       if (SUCCESS != http_request_method_global_init()) {
+               return FAILURE;
+       }
 #ifdef HTTP_HAVE_CURL
        if (SUCCESS != http_request_global_init()) {
                return FAILURE;
@@ -319,6 +322,14 @@ PHP_RINIT_FUNCTION(http)
 /* {{{ PHP_RSHUTDOWN_FUNCTION */
 PHP_RSHUTDOWN_FUNCTION(http)
 {
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+       int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom);
+       
+       for (i = 0; i < c; ++i) {
+               zend_printf("RSHUTDOWN: unregistering %d (%d)\n", i, 
+               http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i));
+       }
+#endif
        http_globals_free(HTTP_GLOBALS);
        return SUCCESS;
 }
index 99b63547562ac06e742597b8e01da289c86d3a6b..b187f559c02f199d4bff19c1b970de10415575c4 100644 (file)
@@ -190,9 +190,9 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D)
        zend_class_entry *ce = http_message_object_ce;
 
 #ifndef WONKY
-       DCL_CONST(long, "NONE", HTTP_MSG_NONE);
-       DCL_CONST(long, "REQUEST", HTTP_MSG_REQUEST);
-       DCL_CONST(long, "RESPONSE", HTTP_MSG_RESPONSE);
+       DCL_CONST(long, "TYPE_NONE", HTTP_MSG_NONE);
+       DCL_CONST(long, "TYPE_REQUEST", HTTP_MSG_REQUEST);
+       DCL_CONST(long, "TYPE_RESPONSE", HTTP_MSG_RESPONSE);
 #endif
 
        DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE);
index 748cede69b2ace8d653f865a5c2f6f883eb17bbf..1e74a802213f7ccafa1ba356b2cbdac67555a2ac 100644 (file)
@@ -71,6 +71,13 @@ STATUS _http_request_global_init(INIT_FUNC_ARGS)
        }
 #endif
 
+#if LIBCURL_VERSION_NUM >= 0x070a05
+       HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC);
+       HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
+       HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
+       HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY);
+#endif /* LIBCURL_VERSION_NUM */
+
        return SUCCESS;
 }
 
index 5a26927158792e64c42fb64f4448a2053e06cd92..57636d088b2b065e7e050bc3015a6859803ea2cf 100644 (file)
@@ -24,6 +24,9 @@
 #include "php_http_std_defs.h"
 #include "php_http_api.h"
 #include "php_http_request_method_api.h"
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+#      include "php_http_request_object.h"
+#endif
 
 #include "phpstr/phpstr.h"
 
@@ -67,6 +70,43 @@ static const char *const http_request_methods[] = {
 };
 /* }}} */
 
+STATUS _http_request_method_global_init(INIT_FUNC_ARGS)
+{
+       /* HTTP/1.1 */
+       HTTP_LONG_CONSTANT("HTTP_METH_GET", HTTP_GET);
+       HTTP_LONG_CONSTANT("HTTP_METH_HEAD", HTTP_HEAD);
+       HTTP_LONG_CONSTANT("HTTP_METH_POST", HTTP_POST);
+       HTTP_LONG_CONSTANT("HTTP_METH_PUT", HTTP_PUT);
+       HTTP_LONG_CONSTANT("HTTP_METH_DELETE", HTTP_DELETE);
+       HTTP_LONG_CONSTANT("HTTP_METH_OPTIONS", HTTP_OPTIONS);
+       HTTP_LONG_CONSTANT("HTTP_METH_TRACE", HTTP_TRACE);
+       HTTP_LONG_CONSTANT("HTTP_METH_CONNECT", HTTP_CONNECT);
+       /* WebDAV - RFC 2518 */
+       HTTP_LONG_CONSTANT("HTTP_METH_PROPFIND", HTTP_PROPFIND);
+       HTTP_LONG_CONSTANT("HTTP_METH_PROPPATCH", HTTP_PROPPATCH);
+       HTTP_LONG_CONSTANT("HTTP_METH_MKCOL", HTTP_MKCOL);
+       HTTP_LONG_CONSTANT("HTTP_METH_COPY", HTTP_COPY);
+       HTTP_LONG_CONSTANT("HTTP_METH_MOVE", HTTP_MOVE);
+       HTTP_LONG_CONSTANT("HTTP_METH_LOCK", HTTP_LOCK);
+       HTTP_LONG_CONSTANT("HTTP_METH_UNLOCK", HTTP_UNLOCK);
+       /* WebDAV Versioning - RFC 3253 */
+       HTTP_LONG_CONSTANT("HTTP_METH_VERSION_CONTROL", HTTP_VERSION_CONTROL);
+       HTTP_LONG_CONSTANT("HTTP_METH_REPORT", HTTP_REPORT);
+       HTTP_LONG_CONSTANT("HTTP_METH_CHECKOUT", HTTP_CHECKOUT);
+       HTTP_LONG_CONSTANT("HTTP_METH_CHECKIN", HTTP_CHECKIN);
+       HTTP_LONG_CONSTANT("HTTP_METH_UNCHECKOUT", HTTP_UNCHECKOUT);
+       HTTP_LONG_CONSTANT("HTTP_METH_MKWORKSPACE", HTTP_MKWORKSPACE);
+       HTTP_LONG_CONSTANT("HTTP_METH_UPDATE", HTTP_UPDATE);
+       HTTP_LONG_CONSTANT("HTTP_METH_LABEL", HTTP_LABEL);
+       HTTP_LONG_CONSTANT("HTTP_METH_MERGE", HTTP_MERGE);
+       HTTP_LONG_CONSTANT("HTTP_METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL);
+       HTTP_LONG_CONSTANT("HTTP_METH_MKACTIVITY", HTTP_MKACTIVITY);
+       /* WebDAV Access Control - RFC 3744 */
+       HTTP_LONG_CONSTANT("HTTP_METH_ACL", HTTP_ACL);
+       
+       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)
 {
@@ -114,18 +154,31 @@ 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 TSRMLS_DC)
+PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name TSRMLS_DC)
 {
        zval array;
-       char *http_method;
+       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;
 
+       method = emalloc(method_len + 1);
+       for (i = 0; i < method_len; ++i) {
+               method[i] = toupper(method_name[i]);
+       }
+       method[method_len] = '\0';
+       
        Z_ARRVAL(array) = &HTTP_G(request).methods.custom;
-       add_next_index_string(&array, estrdup(method), 0);
+       add_next_index_stringl(&array, method, method_len, 0);
 
-       spprintf(&http_method, 0, "HTTP_%s", method);
-       zend_register_long_constant(http_method, strlen(http_method) + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC);
+       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);
+       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);
        efree(http_method);
+#endif
 
        return meth_num;
 }
@@ -136,22 +189,32 @@ PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_
 {
        zval **zmethod;
        char *http_method;
+       int method_len;
 
        if (SUCCESS != zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method), (void **) &zmethod)) {
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Request method with id %lu does not exist", method);
                return FAILURE;
        }
 
-       spprintf(&http_method, 0, "HTTP_%s", Z_STRVAL_PP(zmethod));
-
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+       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);
+               efree(http_method);
+               return FAILURE;
+       }
+       efree(http_method);
+#endif
+       
+       method_len = spprintf(&http_method, 0, "HTTP_METH_%s", Z_STRVAL_PP(zmethod));
        if (    (SUCCESS != zend_hash_index_del(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method)))
-               ||      (SUCCESS != zend_hash_del(EG(zend_constants), http_method, strlen(http_method) + 1))) {
+               ||      (SUCCESS != zend_hash_del(EG(zend_constants), http_method, method_len + 1))) {
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: %s", http_method);
                efree(http_method);
                return FAILURE;
        }
-
        efree(http_method);
+       
        return SUCCESS;
 }
 /* }}} */
index 711872cb1a3c006667d479bd5c5bb1f5e8736289..0a6c5d1a4ea47df32b7f84a8708e2199ab6bcaae 100644 (file)
@@ -296,45 +296,6 @@ static zend_object_handlers http_request_object_handlers;
 void _http_request_object_init(INIT_FUNC_ARGS)
 {
        HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
-
-       /* HTTP/1.1 */
-       HTTP_LONG_CONSTANT("HTTP_GET", HTTP_GET);
-       HTTP_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD);
-       HTTP_LONG_CONSTANT("HTTP_POST", HTTP_POST);
-       HTTP_LONG_CONSTANT("HTTP_PUT", HTTP_PUT);
-       HTTP_LONG_CONSTANT("HTTP_DELETE", HTTP_DELETE);
-       HTTP_LONG_CONSTANT("HTTP_OPTIONS", HTTP_OPTIONS);
-       HTTP_LONG_CONSTANT("HTTP_TRACE", HTTP_TRACE);
-       HTTP_LONG_CONSTANT("HTTP_CONNECT", HTTP_CONNECT);
-       /* WebDAV - RFC 2518 */
-       HTTP_LONG_CONSTANT("HTTP_PROPFIND", HTTP_PROPFIND);
-       HTTP_LONG_CONSTANT("HTTP_PROPPATCH", HTTP_PROPPATCH);
-       HTTP_LONG_CONSTANT("HTTP_MKCOL", HTTP_MKCOL);
-       HTTP_LONG_CONSTANT("HTTP_COPY", HTTP_COPY);
-       HTTP_LONG_CONSTANT("HTTP_MOVE", HTTP_MOVE);
-       HTTP_LONG_CONSTANT("HTTP_LOCK", HTTP_LOCK);
-       HTTP_LONG_CONSTANT("HTTP_UNLOCK", HTTP_UNLOCK);
-       /* WebDAV Versioning - RFC 3253 */
-       HTTP_LONG_CONSTANT("HTTP_VERSION_CONTROL", HTTP_VERSION_CONTROL);
-       HTTP_LONG_CONSTANT("HTTP_REPORT", HTTP_REPORT);
-       HTTP_LONG_CONSTANT("HTTP_CHECKOUT", HTTP_CHECKOUT);
-       HTTP_LONG_CONSTANT("HTTP_CHECKIN", HTTP_CHECKIN);
-       HTTP_LONG_CONSTANT("HTTP_UNCHECKOUT", HTTP_UNCHECKOUT);
-       HTTP_LONG_CONSTANT("HTTP_MKWORKSPACE", HTTP_MKWORKSPACE);
-       HTTP_LONG_CONSTANT("HTTP_UPDATE", HTTP_UPDATE);
-       HTTP_LONG_CONSTANT("HTTP_LABEL", HTTP_LABEL);
-       HTTP_LONG_CONSTANT("HTTP_MERGE", HTTP_MERGE);
-       HTTP_LONG_CONSTANT("HTTP_BASELINE_CONTROL", HTTP_BASELINE_CONTROL);
-       HTTP_LONG_CONSTANT("HTTP_MKACTIVITY", HTTP_MKACTIVITY);
-       /* WebDAV Access Control - RFC 3744 */
-       HTTP_LONG_CONSTANT("HTTP_ACL", HTTP_ACL);
-
-
-#      if LIBCURL_VERSION_NUM >= 0x070a05
-       HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC);
-       HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
-       HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
-#      endif /* LIBCURL_VERSION_NUM */
 }
 
 zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
@@ -382,6 +343,51 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        DCL_PROP(PROTECTED, string, putFile, "");
 
        DCL_PROP(PUBLIC, bool, recordHistory, 1);
+
+       /*
+        * Request Method Constants
+        */
+       /* HTTP/1.1 */
+       DCL_CONST(long, "METH_GET", HTTP_GET);
+       DCL_CONST(long, "METH_HEAD", HTTP_HEAD);
+       DCL_CONST(long, "METH_POST", HTTP_POST);
+       DCL_CONST(long, "METH_PUT", HTTP_PUT);
+       DCL_CONST(long, "METH_DELETE", HTTP_DELETE);
+       DCL_CONST(long, "METH_OPTIONS", HTTP_OPTIONS);
+       DCL_CONST(long, "METH_TRACE", HTTP_TRACE);
+       DCL_CONST(long, "METH_CONNECT", HTTP_CONNECT);
+       /* WebDAV - RFC 2518 */
+       DCL_CONST(long, "METH_PROPFIND", HTTP_PROPFIND);
+       DCL_CONST(long, "METH_PROPPATCH", HTTP_PROPPATCH);
+       DCL_CONST(long, "METH_MKCOL", HTTP_MKCOL);
+       DCL_CONST(long, "METH_COPY", HTTP_COPY);
+       DCL_CONST(long, "METH_MOVE", HTTP_MOVE);
+       DCL_CONST(long, "METH_LOCK", HTTP_LOCK);
+       DCL_CONST(long, "METH_UNLOCK", HTTP_UNLOCK);
+       /* WebDAV Versioning - RFC 3253 */
+       DCL_CONST(long, "METH_VERSION_CONTROL", HTTP_VERSION_CONTROL);
+       DCL_CONST(long, "METH_REPORT", HTTP_REPORT);
+       DCL_CONST(long, "METH_CHECKOUT", HTTP_CHECKOUT);
+       DCL_CONST(long, "METH_CHECKIN", HTTP_CHECKIN);
+       DCL_CONST(long, "METH_UNCHECKOUT", HTTP_UNCHECKOUT);
+       DCL_CONST(long, "METH_MKWORKSPACE", HTTP_MKWORKSPACE);
+       DCL_CONST(long, "METH_UPDATE", HTTP_UPDATE);
+       DCL_CONST(long, "METH_LABEL", HTTP_LABEL);
+       DCL_CONST(long, "METH_MERGE", HTTP_MERGE);
+       DCL_CONST(long, "METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL);
+       DCL_CONST(long, "METH_MKACTIVITY", HTTP_MKACTIVITY);
+       /* WebDAV Access Control - RFC 3744 */
+       DCL_CONST(long, "METH_ACL", HTTP_ACL);
+
+       /*
+        * Auth Constants
+        */
+#      if LIBCURL_VERSION_NUM >= 0x070a05
+       DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC);
+       DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST);
+       DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM);
+       DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY);
+#      endif /* LIBCURL_VERSION_NUM */
 }
 
 void _http_request_object_free(zend_object *object TSRMLS_DC)
index 6958cbdae56cb437ec6843c74f443c66b6a2c634..362b5dc6a4bba500cf228391ba277fa5dcc8d83f 100644 (file)
@@ -57,6 +57,9 @@ typedef enum {
        HTTP_MAX_REQUEST_METHOD = 28
 } http_request_method;
 
+#define http_request_method_global_init() _http_request_method_global_init(INIT_FUNC_ARGS_PASSTHRU)
+STATUS _http_request_method_global_init(INIT_FUNC_ARGS);
+
 #define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD))
 #define HTTP_CUSTOM_REQUEST_METHOD(m) (m - HTTP_MAX_REQUEST_METHOD)