- add request method constants to HttpRequest and handle them in method_(un)register()
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;
/* {{{ 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;
}
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);
}
#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;
}
#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"
};
/* }}} */
+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)
{
/* }}} */
/* {{{ 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;
}
{
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;
}
/* }}} */
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)
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)
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)