From 4e5827ad559e50a1bfa4dc1807add9248acb3be4 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 22 Mar 2012 16:21:26 +0000 Subject: [PATCH] remove 90% of the request method cruft; request methods are now simple strings --- package.xml | 1 + php_http.c | 1 - php_http_curl.c | 43 ++++---- php_http_request.c | 17 +-- php_http_request.h | 6 +- php_http_request_factory.c | 11 +- php_http_request_method.c | 209 +++---------------------------------- php_http_request_method.h | 53 +--------- php_http_request_pool.c | 2 +- php_http_request_pool.h | 2 +- phpunit/RequestTest.php | 2 +- tests/requestpool001.phpt | 5 +- 12 files changed, 57 insertions(+), 295 deletions(-) diff --git a/package.xml b/package.xml index bc6add8..3f34a59 100644 --- a/package.xml +++ b/package.xml @@ -41,6 +41,7 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be - Renamed http\Env\Request::getPost() to ::getForm() - Changed http\Env\Response::setContentDisposition() to take an http\Params like array as argument - Removed http\Env\Response::CONTENT_DISPOSOTION_* constants +- Removed http\Env\Request\Method class; request methods are now used as simple strings ]]> diff --git a/php_http.c b/php_http.c index d5211bc..202317c 100644 --- a/php_http.c +++ b/php_http.c @@ -146,7 +146,6 @@ PHP_MINIT_FUNCTION(http) || SUCCESS != PHP_MINIT_CALL(http_curl) #endif || SUCCESS != PHP_MINIT_CALL(http_request_datashare) - || SUCCESS != PHP_MINIT_CALL(http_request_method) || SUCCESS != PHP_MINIT_CALL(http_request_pool) || SUCCESS != PHP_MINIT_CALL(http_url) || SUCCESS != PHP_MINIT_CALL(http_env) diff --git a/php_http_curl.c b/php_http_curl.c index 65b1746..9bfeda8 100644 --- a/php_http_curl.c +++ b/php_http_curl.c @@ -239,6 +239,8 @@ static int php_http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, curl->progress.state.info = "not disconnected"; } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) { curl->progress.state.info = "disconnected"; + } else if (php_memnstr(data, ZEND_STRL("Issue another request"), data + length)) { + curl->progress.state.info = "redirect"; } php_http_request_progress_notify(&curl->progress TSRMLS_CC); break; @@ -288,7 +290,7 @@ static int php_http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) return n*l; } -static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body) +static STATUS php_http_curl_request_prepare(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body) { php_http_curl_request_t *curl = h->ctx; php_http_curl_request_storage_t *storage = get_storage(curl->handle); @@ -302,30 +304,28 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url); /* request method */ - switch (meth) { - case PHP_HTTP_GET: + switch (php_http_request_method_is(meth, 4, "GET", "HEAD", "POST", "PUT")) { + case 0: curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L); break; - case PHP_HTTP_HEAD: + case 1: curl_easy_setopt(curl->handle, CURLOPT_NOBODY, 1L); break; - case PHP_HTTP_POST: + case 2: curl_easy_setopt(curl->handle, CURLOPT_POST, 1L); break; - case PHP_HTTP_PUT: + case 3: curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L); break; default: { - const char *name = php_http_request_method_name(meth TSRMLS_CC); - - if (name) { - curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, name); + if (meth) { + curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, meth); } else { - php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", meth, url); + php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: '%s' (%s)", meth, url); return FAILURE; } break; @@ -340,17 +340,12 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method * does not allow a request body. */ - switch (meth) { - default: { - size_t body_size = php_http_message_body_size(body); - - curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body); - curl_easy_setopt(curl->handle, CURLOPT_READDATA, body); - curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size); - curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size); - break; - } - } + size_t body_size = php_http_message_body_size(body); + + curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body); + curl_easy_setopt(curl->handle, CURLOPT_READDATA, body); + curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size); + curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size); } return SUCCESS; @@ -1290,7 +1285,7 @@ static void php_http_curl_request_pool_dtor(php_http_request_pool_t *h) h->ctx = NULL; } -static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, php_http_request_method_t m, const char *url, php_http_message_body_t *body) +static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, const char *m, const char *url, php_http_message_body_t *body) { php_http_curl_request_pool_t *curl = h->ctx; php_http_curl_request_t *recurl = r->ctx; @@ -1705,7 +1700,7 @@ static STATUS php_http_curl_request_reset(php_http_request_t *h) return SUCCESS; } -static STATUS php_http_curl_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body) +static STATUS php_http_curl_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body) { uint tries = 0; CURLcode result; diff --git a/php_http_request.c b/php_http_request.c index 4241689..a7086d3 100644 --- a/php_http_request.c +++ b/php_http_request.c @@ -94,7 +94,7 @@ PHP_HTTP_API php_http_request_t *php_http_request_copy(php_http_request_t *from, } } -PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body) +PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body) { if (h->ops->exec) { return h->ops->exec(h, meth, url, body); @@ -416,7 +416,7 @@ static inline zend_object_value php_http_request_object_message(zval *this_ptr, } } -STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, php_http_request_method_t *meth, char **url, php_http_message_body_t **body TSRMLS_DC) +STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC) { zval *zoptions; php_http_request_progress_t *progress; @@ -427,7 +427,7 @@ STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zv zend_update_property_null(php_http_request_class_entry, getThis(), ZEND_STRL("info") TSRMLS_CC); if (meth) { - *meth = (php_http_request_method_t) Z_LVAL_P(zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("method"), 0 TSRMLS_CC)); + *meth = Z_STRVAL_P(zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("method"), 0 TSRMLS_CC)); } if (url) { @@ -948,10 +948,11 @@ PHP_METHOD(HttpRequest, getUrl) PHP_METHOD(HttpRequest, setMethod) { - long meth; + char *meth_str; + int meth_len; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) { - zend_update_property_long(php_http_request_class_entry, getThis(), ZEND_STRL("method"), meth TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) { + zend_update_property_stringl(php_http_request_class_entry, getThis(), ZEND_STRL("method"), meth_str, meth_len TSRMLS_CC); } RETVAL_ZVAL(getThis(), 1, 0); } @@ -1291,8 +1292,8 @@ PHP_METHOD(HttpRequest, send) with_error_handling(EH_THROW, php_http_exception_class_entry) { if (SUCCESS == zend_parse_parameters_none()) { php_http_request_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - php_http_request_method_t meth = PHP_HTTP_NO_REQUEST_METHOD; php_http_message_body_t *body = NULL; + char *meth = NULL; char *url = NULL; if (SUCCESS == php_http_request_object_requesthandler(obj, getThis(), &meth, &url, &body TSRMLS_CC)) { @@ -1327,7 +1328,7 @@ PHP_MINIT_FUNCTION(http_request) zend_declare_property_long(php_http_request_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(php_http_request_class_entry, ZEND_STRL("requestMessage"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(php_http_request_class_entry, ZEND_STRL("method"), PHP_HTTP_GET, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("method"), "GET", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("url"), "", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("contentType"), "", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("requestBody"), "", ZEND_ACC_PRIVATE TSRMLS_CC); diff --git a/php_http_request.h b/php_http_request.h index 3d7b78c..99f75d9 100644 --- a/php_http_request.h +++ b/php_http_request.h @@ -125,7 +125,7 @@ typedef struct php_http_request php_http_request_t; typedef php_http_request_t *(*php_http_request_init_func_t)(php_http_request_t *h, void *arg); typedef php_http_request_t *(*php_http_request_copy_func_t)(php_http_request_t *from, php_http_request_t *to); typedef void (*php_http_request_dtor_func_t)(php_http_request_t *h); -typedef STATUS (*php_http_request_exec_func_t)(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body); +typedef STATUS (*php_http_request_exec_func_t)(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body); typedef STATUS (*php_http_request_reset_func_t)(php_http_request_t *h); typedef STATUS (*php_http_request_setopt_func_t)(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg); typedef STATUS (*php_http_request_getopt_func_t)(php_http_request_t *h, php_http_request_getopt_opt_t opt, void *arg); @@ -157,7 +157,7 @@ struct php_http_request { PHP_HTTP_API php_http_request_t *php_http_request_init(php_http_request_t *h, php_http_request_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC); PHP_HTTP_API php_http_request_t *php_http_request_copy(php_http_request_t *from, php_http_request_t *to); -PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body); +PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body); PHP_HTTP_API STATUS php_http_request_reset(php_http_request_t *h); PHP_HTTP_API STATUS php_http_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg); PHP_HTTP_API STATUS php_http_request_getopt(php_http_request_t *h, php_http_request_getopt_opt_t opt, void *arg); @@ -177,7 +177,7 @@ extern zend_object_value php_http_request_object_new_ex(zend_class_entry *ce, ph extern zend_object_value php_http_request_object_clone(zval *zobject TSRMLS_DC); extern void php_http_request_object_free(void *object TSRMLS_DC); -extern STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, php_http_request_method_t *meth, char **url, php_http_message_body_t **body TSRMLS_DC); +extern STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC); extern STATUS php_http_request_object_responsehandler(php_http_request_object_t *obj, zval *this_ptr TSRMLS_DC); PHP_METHOD(HttpRequest, __construct); diff --git a/php_http_request_factory.c b/php_http_request_factory.c index 79e348f..e739f53 100644 --- a/php_http_request_factory.c +++ b/php_http_request_factory.c @@ -113,13 +113,12 @@ PHP_METHOD(HttpRequestFactory, __construct) PHP_METHOD(HttpRequestFactory, createRequest) { - char *url_str = NULL; - int url_len; - long meth = -1; + char *meth_str = NULL, *url_str = NULL; + int meth_len, url_len; zval *options = NULL; with_error_handling(EH_THROW, php_http_exception_class_entry) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!la!", &url_str, &url_len, &meth, &options)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!", &url_str, &url_len, &meth_str, &meth_len, &options)) { with_error_handling(EH_THROW, php_http_exception_class_entry) { zval *zdriver, *os; zend_object_value ov; @@ -166,8 +165,8 @@ PHP_METHOD(HttpRequestFactory, createRequest) if (url_str) { zend_update_property_stringl(php_http_request_class_entry, return_value, ZEND_STRL("url"), url_str, url_len TSRMLS_CC); } - if (meth > 0) { - zend_update_property_long(php_http_request_class_entry, return_value, ZEND_STRL("method"), meth TSRMLS_CC); + if (meth_str) { + zend_update_property_stringl(php_http_request_class_entry, return_value, ZEND_STRL("method"), meth_str, meth_len TSRMLS_CC); } if (options) { zend_call_method_with_1_params(&return_value, Z_OBJCE_P(return_value), NULL, "setoptions", NULL, options); diff --git a/php_http_request_method.c b/php_http_request_method.c index 118721f..13561ad 100644 --- a/php_http_request_method.c +++ b/php_http_request_method.c @@ -12,210 +12,29 @@ #include "php_http_api.h" -static PHP_HTTP_STRLIST(php_http_request_methods) = - PHP_HTTP_STRLIST_ITEM("UNKNOWN") - /* HTTP/1.1 */ - PHP_HTTP_STRLIST_ITEM("GET") - PHP_HTTP_STRLIST_ITEM("HEAD") - PHP_HTTP_STRLIST_ITEM("POST") - PHP_HTTP_STRLIST_ITEM("PUT") - PHP_HTTP_STRLIST_ITEM("DELETE") - PHP_HTTP_STRLIST_ITEM("OPTIONS") - PHP_HTTP_STRLIST_ITEM("TRACE") - PHP_HTTP_STRLIST_ITEM("CONNECT") - /* WebDAV - RFC 2518 */ - PHP_HTTP_STRLIST_ITEM("PROPFIND") - PHP_HTTP_STRLIST_ITEM("PROPPATCH") - PHP_HTTP_STRLIST_ITEM("MKCOL") - PHP_HTTP_STRLIST_ITEM("COPY") - PHP_HTTP_STRLIST_ITEM("MOVE") - PHP_HTTP_STRLIST_ITEM("LOCK") - PHP_HTTP_STRLIST_ITEM("UNLOCK") - /* WebDAV Versioning - RFC 3253 */ - PHP_HTTP_STRLIST_ITEM("VERSION_CONTROL") - PHP_HTTP_STRLIST_ITEM("REPORT") - PHP_HTTP_STRLIST_ITEM("CHECKOUT") - PHP_HTTP_STRLIST_ITEM("CHECKIN") - PHP_HTTP_STRLIST_ITEM("UNCHECKOUT") - PHP_HTTP_STRLIST_ITEM("MKWORKSPACE") - PHP_HTTP_STRLIST_ITEM("UPDATE") - PHP_HTTP_STRLIST_ITEM("LABEL") - PHP_HTTP_STRLIST_ITEM("MERGE") - PHP_HTTP_STRLIST_ITEM("BASELINE_CONTROL") - PHP_HTTP_STRLIST_ITEM("MKACTIVITY") - /* WebDAV Access Control - RFC 3744 */ - PHP_HTTP_STRLIST_ITEM("ACL") - PHP_HTTP_STRLIST_STOP -; - -PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC) -{ - if (meth > PHP_HTTP_NO_REQUEST_METHOD && meth < PHP_HTTP_MAX_REQUEST_METHOD) { - return php_http_strlist_find(php_http_request_methods, 0, meth); - } else { - zval **val, *cmp, res; - HashPosition pos; - php_http_array_hashkey_t key = php_http_array_hashkey_init(0); - - INIT_PZVAL(&res); - FOREACH_HASH_KEYVAL(pos, &php_http_request_class_entry->constants_table, key, val) { - MAKE_STD_ZVAL(cmp); - ZVAL_LONG(cmp, meth); - is_equal_function(&res, *val, cmp TSRMLS_CC); - zval_ptr_dtor(&cmp); - - if (Z_LVAL(res)) { - return key.str; - } - } - } - return NULL; -} - -PHP_HTTP_API STATUS php_http_request_method_register(const char *meth_str, size_t meth_len, long *id TSRMLS_DC) -{ - long num = zend_hash_num_elements(&php_http_request_class_entry->constants_table); - - if (SUCCESS == zend_declare_class_constant_long(php_http_request_method_class_entry, meth_str, meth_len, num TSRMLS_CC)) { - if (id) { - *id = num; - } - return SUCCESS; - } - return FAILURE; -} - -zend_class_entry *php_http_request_method_class_entry; - -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpRequestMethod, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpRequestMethod, method, 0) -#define PHP_HTTP_REQMETH_ME(method, visibility) PHP_ME(HttpRequestMethod, method, PHP_HTTP_ARGS(HttpRequestMethod, method), visibility) - -#ifdef register -# undef register -#endif - -PHP_HTTP_BEGIN_ARGS(__construct, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(__toString); - -PHP_HTTP_EMPTY_ARGS(getId); - -PHP_HTTP_BEGIN_ARGS(exists, 1) - PHP_HTTP_ARG_VAL(method, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(register, 1) - PHP_HTTP_ARG_VAL(method, 0) -PHP_HTTP_END_ARGS; - -zend_function_entry php_http_request_method_method_entry[] = { - PHP_HTTP_REQMETH_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_REQMETH_ME(__toString, ZEND_ACC_PUBLIC) - PHP_HTTP_REQMETH_ME(getId, ZEND_ACC_PUBLIC) - PHP_HTTP_REQMETH_ME(exists, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_HTTP_REQMETH_ME(register, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - - EMPTY_FUNCTION_ENTRY -}; - -PHP_METHOD(HttpRequestMethod, __construct) +PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { - char *meth_str; - int meth_len; + va_list argv; + int match = -1; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { - zval *zarg, *zret; + if (argc > 0) { + int i; - if (SUCCESS == zend_get_parameters(ZEND_NUM_ARGS(), 1, &zarg)) { - if (zend_call_method_with_1_params(&getThis(), php_http_request_method_class_entry, NULL, "exists", &zret, zarg)) { - if (i_zend_is_true(zret)) { - zend_update_property_stringl(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), meth_str, meth_len TSRMLS_CC); - } else { - php_http_error(HE_THROW, PHP_HTTP_E_REQUEST_METHOD, "Unknown request method '%s'", meth_str); - } - zval_ptr_dtor(&zret); - } - } - } end_error_handling(); - } - } end_error_handling(); -} + va_start(argv, argc); + for (i = 0; i < argc; ++i) { + const char *test = va_arg(argv, const char *); -PHP_METHOD(HttpRequestMethod, __toString) -{ - if (SUCCESS == zend_parse_parameters_none()) { - zval *retval = php_http_ztyp(IS_STRING, zend_read_property(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC)); - - RETURN_ZVAL(retval, 1, 1); - } - RETURN_EMPTY_STRING(); -} - -PHP_METHOD(HttpRequestMethod, getId) -{ - if (SUCCESS == zend_parse_parameters_none()) { - zval **data, *meth = php_http_ztyp(IS_STRING, zend_read_property(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC)); - - if (SUCCESS == zend_hash_find(&php_http_request_method_class_entry->constants_table, Z_STRVAL_P(meth), Z_STRLEN_P(meth) + 1, (void *) &data)) { - zval_ptr_dtor(&meth); - RETURN_ZVAL(*data, 1, 0); + if (!strcasecmp(meth, test)) { + match = i; + break; + } } - zval_ptr_dtor(&meth); + va_end(argv); } - RETURN_FALSE; -} - -PHP_METHOD(HttpRequestMethod, exists) -{ - char *meth_str; - int meth_len; - - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) { - zval **data; - if (SUCCESS == zend_hash_find(&php_http_request_method_class_entry->constants_table, meth_str, meth_len + 1, (void *) &data)) { - RETURN_ZVAL(*data, 1, 0); - } - } - RETURN_FALSE; + return match; } -PHP_METHOD(HttpRequestMethod, register) -{ - char *meth_str; - int meth_len; - - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) { - RETURN_SUCCESS(zend_declare_class_constant_long(php_http_request_method_class_entry, meth_str, meth_len, zend_hash_num_elements(&php_http_request_method_class_entry->constants_table) TSRMLS_CC)); - } - RETURN_FALSE; -} - -PHP_MINIT_FUNCTION(http_request_method) -{ - php_http_strlist_iterator_t std; - - PHP_HTTP_REGISTER_CLASS(http\\Request, Method, http_request_method, php_http_object_class_entry, 0); - - zend_declare_property_null(php_http_request_method_class_entry, ZEND_STRL("name"), ZEND_ACC_PROTECTED TSRMLS_CC); - - php_http_strlist_iterator_init(&std, php_http_request_methods, 1); - do { - unsigned id; - const char *meth = php_http_strlist_iterator_this(&std, &id); - - zend_declare_class_constant_long(php_http_request_method_class_entry, meth, strlen(meth), id TSRMLS_CC); - } while (*php_http_strlist_iterator_next(&std)); - - return SUCCESS; -} - - /* * Local variables: * tab-width: 4 diff --git a/php_http_request_method.h b/php_http_request_method.h index dcfd9b8..85eedbd 100644 --- a/php_http_request_method.h +++ b/php_http_request_method.h @@ -13,58 +13,7 @@ #ifndef PHP_HTTP_REQUEST_METHOD_H #define PHP_HTTP_REQUEST_METHOD_H -typedef enum php_http_request_method { - /* force the enum to be signed */ - PHP_HTTP_NEG_REQUEST_METHOD =-1, - PHP_HTTP_NO_REQUEST_METHOD = 0, - /* HTTP/1.1 */ - PHP_HTTP_GET = 1, - PHP_HTTP_HEAD = 2, - PHP_HTTP_POST = 3, - PHP_HTTP_PUT = 4, - PHP_HTTP_DELETE = 5, - PHP_HTTP_OPTIONS = 6, - PHP_HTTP_TRACE = 7, - PHP_HTTP_CONNECT = 8, - /* WebDAV - RFC 2518 */ - PHP_HTTP_PROPFIND = 9, - PHP_HTTP_PROPPATCH = 10, - PHP_HTTP_MKCOL = 11, - PHP_HTTP_COPY = 12, - PHP_HTTP_MOVE = 13, - PHP_HTTP_LOCK = 14, - PHP_HTTP_UNLOCK = 15, - /* WebDAV Versioning - RFC 3253 */ - PHP_HTTP_VERSION_CONTROL = 16, - PHP_HTTP_REPORT = 17, - PHP_HTTP_CHECKOUT = 18, - PHP_HTTP_CHECKIN = 19, - PHP_HTTP_UNCHECKOUT = 20, - PHP_HTTP_MKWORKSPACE = 21, - PHP_HTTP_UPDATE = 22, - PHP_HTTP_LABEL = 23, - PHP_HTTP_MERGE = 24, - PHP_HTTP_BASELINE_CONTROL = 25, - PHP_HTTP_MKACTIVITY = 26, - /* WebDAV Access Control - RFC 3744 */ - PHP_HTTP_ACL = 27, - PHP_HTTP_MAX_REQUEST_METHOD = 28 -} php_http_request_method_t; - -PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC); -PHP_HTTP_API STATUS php_http_request_method_register(const char *meth_str, size_t meth_len, long *id TSRMLS_DC); - -extern zend_class_entry *php_http_request_method_class_entry; -extern zend_function_entry php_http_request_method_method_entry[]; - -extern PHP_METHOD(HttpRequestMethod, __construct); -extern PHP_METHOD(HttpRequestMethod, __toString); -extern PHP_METHOD(HttpRequestMethod, getId); - -extern PHP_METHOD(HttpRequestMethod, exists); -extern PHP_METHOD(HttpRequestMethod, register); - -extern PHP_MINIT_FUNCTION(http_request_method); +PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...); #endif diff --git a/php_http_request_pool.c b/php_http_request_pool.c index de79504..352c8ef 100644 --- a/php_http_request_pool.c +++ b/php_http_request_pool.c @@ -74,7 +74,7 @@ PHP_HTTP_API STATUS php_http_request_pool_attach(php_http_request_pool_t *h, zva if (h->ops->attach) { char *url = NULL; - php_http_request_method_t m = PHP_HTTP_NO_REQUEST_METHOD; + char *m = NULL; php_http_message_body_t *body = NULL; php_http_request_object_t *obj = zend_object_store_get_object(request TSRMLS_CC); diff --git a/php_http_request_pool.h b/php_http_request_pool.h index d5657a6..c090330 100644 --- a/php_http_request_pool.h +++ b/php_http_request_pool.h @@ -27,7 +27,7 @@ typedef void (*php_http_request_pool_reset_func_t)(php_http_request_pool_t *p); typedef STATUS (*php_http_request_pool_exec_func_t)(php_http_request_pool_t *p); typedef STATUS (*php_http_request_pool_wait_func_t)(php_http_request_pool_t *p, struct timeval *custom_timeout); typedef int (*php_http_request_pool_once_func_t)(php_http_request_pool_t *p); -typedef STATUS (*php_http_request_pool_attach_func_t)(php_http_request_pool_t *p, php_http_request_t *r, php_http_request_method_t m, const char *url, php_http_message_body_t *body); +typedef STATUS (*php_http_request_pool_attach_func_t)(php_http_request_pool_t *p, php_http_request_t *r, const char *m, const char *url, php_http_message_body_t *body); typedef STATUS (*php_http_request_pool_detach_func_t)(php_http_request_pool_t *p, php_http_request_t *r); typedef STATUS (*php_http_request_pool_setopt_func_t)(php_http_request_pool_t *p, php_http_request_pool_setopt_opt_t opt, void *arg); diff --git a/phpunit/RequestTest.php b/phpunit/RequestTest.php index 1126328..fccad01 100644 --- a/phpunit/RequestTest.php +++ b/phpunit/RequestTest.php @@ -102,7 +102,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $this->r->recordHistory = true; - $this->r->setMethod(http\Request\Method::POST); + $this->r->setMethod("POST"); $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php"); $this->r->send(); diff --git a/tests/requestpool001.phpt b/tests/requestpool001.phpt index 462af71..790823c 100644 --- a/tests/requestpool001.phpt +++ b/tests/requestpool001.phpt @@ -9,7 +9,6 @@ include 'skipif.inc'; use http\request\Factory as HttpRequestFactory; use http\request\Pool as HttpRequestPool; -use http\request\Method as HttpRequestMethod; use http\Exception as HttpRequestException; use http\Exception as HttpSocketException; @@ -53,7 +52,7 @@ class Pool extends HttpRequestPool $this->attach( $this->factory->createRequest( $url, - HttpRequestMethod::GET, + "GET", array( 'redirect' => 5, 'compress' => GZIP, @@ -105,7 +104,7 @@ class Pool extends HttpRequestPool $this->attach( $this->factory->createRequest( $url, - HttpRequestMethod::GET, + "GET", array( 'redirect' => 5, 'compress' => GZIP, -- 2.30.2