From: Michael Wallner Date: Thu, 15 Sep 2005 13:39:03 +0000 (+0000) Subject: - more descriptive constant names X-Git-Tag: RELEASE_0_14_0~26 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=36fa8b05be7aaf8e7f9e503c3e82733022500c03;p=m6w6%2Fext-http - more descriptive constant names - add request method constants to HttpRequest and handle them in method_(un)register() --- diff --git a/http.c b/http.c index b14befe..700fa9e 100644 --- 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; } diff --git a/http_message_object.c b/http_message_object.c index 99b6354..b187f55 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -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); diff --git a/http_request_api.c b/http_request_api.c index 748cede..1e74a80 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -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; } diff --git a/http_request_method_api.c b/http_request_method_api.c index 5a26927..57636d0 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -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; } /* }}} */ diff --git a/http_request_object.c b/http_request_object.c index 711872c..0a6c5d1 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -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) diff --git a/php_http_request_method_api.h b/php_http_request_method_api.h index 6958cbd..362b5dc 100644 --- a/php_http_request_method_api.h +++ b/php_http_request_method_api.h @@ -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)