From: Michael Wallner Date: Thu, 22 Mar 2012 17:34:36 +0000 (+0000) Subject: remove php_http_request_method.[ch]; add support for CURL_LOCK_DATA_SSL_SESSION,... X-Git-Tag: DEV_2-before-client~7 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=f2f85ecef84a1dfc7982f9fd9b10f5a0dadb2540 remove php_http_request_method.[ch]; add support for CURL_LOCK_DATA_SSL_SESSION, CURLOPT_RESOLVE, CURLOPT_DNS_SERVERS --- diff --git a/config9.m4 b/config9.m4 index 2a03cef..be7bdf9 100644 --- a/config9.m4 +++ b/config9.m4 @@ -421,7 +421,6 @@ dnl ---- php_http_curl.c \ php_http_request_pool.c \ php_http_request_datashare.c \ - php_http_request_method.c \ php_http_strlist.c \ php_http_url.c \ php_http_version.c \ @@ -464,7 +463,6 @@ dnl ---- php_http_request.h \ php_http_request_factory.h \ php_http_curl.h \ - php_http_request_method.h \ php_http_request_pool.h \ php_http_strlist.h \ php_http_url.h \ diff --git a/package.xml b/package.xml index 3f34a59..4546749 100644 --- a/package.xml +++ b/package.xml @@ -41,7 +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 +- Removed http\Request\Method class; request methods are now used as simple strings ]]> @@ -107,8 +107,6 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be - - diff --git a/php_http_api.h b/php_http_api.h index a6ea120..23e63cd 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -98,7 +98,6 @@ typedef int STATUS; #include "php_http_request.h" #include "php_http_request_datashare.h" #include "php_http_request_factory.h" -#include "php_http_request_method.h" #include "php_http_request_pool.h" #include "php_http_serf.h" #include "php_http_url.h" diff --git a/php_http_curl.c b/php_http_curl.c index 9bfeda8..f4a4244 100644 --- a/php_http_curl.c +++ b/php_http_curl.c @@ -28,6 +28,7 @@ typedef struct php_http_curl_request { HashTable cache; struct curl_slist *headers; + struct curl_slist *resolve; php_http_buffer_t cookies; long redirects; @@ -304,7 +305,7 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, const char *m curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url); /* request method */ - switch (php_http_request_method_is(meth, 4, "GET", "HEAD", "POST", "PUT")) { + switch (php_http_select_str(meth, 4, "GET", "HEAD", "POST", "PUT")) { case 0: curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L); break; @@ -624,6 +625,30 @@ static STATUS set_options(php_http_request_t *h, HashTable *options) if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("ipresolve"), IS_LONG)) && Z_LVAL_P(zoption)) { curl_easy_setopt(ch, CURLOPT_IPRESOLVE, Z_LVAL_P(zoption)); } +#if PHP_HTTP_CURL_VERSION(7,21,3) + if (curl->options.resolve) { + curl_slist_free_all(curl->options.resolve); + curl->options.resolve = NULL; + } + if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("resolve"), IS_ARRAY))) { + php_http_array_hashkey_t key = php_http_array_hashkey_init(0); + HashPosition pos; + zval **data; + + FOREACH_KEYVAL(pos, zoption, key, data) { + zval *cpy = php_http_ztyp(IS_STRING, *data); + + curl->options.resolve = curl_slist_append(curl->options.resolve, Z_STRVAL_P(cpy)); + + zval_ptr_dtor(&cpy); + } + } +#endif +#if PHP_HTTP_CURL_VERSION(7,24,0) + if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("dns_servers"), IS_STRING)) && Z_STRLEN_P(zoption)) { + curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, Z_STRVAL_P(zoption)); + } +#endif /* limits */ if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("low_speed_limit"), IS_LONG))) { @@ -1215,6 +1240,17 @@ static STATUS php_http_curl_request_datashare_setopt(php_http_request_datashare_ } break; +#if PHP_HTTP_CURL_VERSION(7,23,0) + case PHP_HTTP_REQUEST_DATASHARE_OPT_SSLSESSIONS: + if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_SSL_SESSION))) { + TSRMLS_FETCH_FROM_CTX(h->ts); + + php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "Could not %s sharing of SSL session data: %s", *((zend_bool *) arg) ? "enable" : "disable", curl_share_strerror(rc)); + return FAILURE; + } + break; +#endif + default: return FAILURE; } @@ -1606,6 +1642,12 @@ static STATUS php_http_curl_request_reset(php_http_request_t *h) curl_easy_setopt(ch, CURLOPT_HTTPPROXYTUNNEL, 0L); curl_easy_setopt(ch, CURLOPT_DNS_CACHE_TIMEOUT, 60L); curl_easy_setopt(ch, CURLOPT_IPRESOLVE, 0); +#if PHP_HTTP_CURL_VERSION(7,21,3) + curl_easy_setopt(ch, CURLOPT_RESOLVE, NULL); +#endif +#if PHP_HTTP_CURL_VERSION(7,24,0) + curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, NULL); +#endif curl_easy_setopt(ch, CURLOPT_LOW_SPEED_LIMIT, 0L); curl_easy_setopt(ch, CURLOPT_LOW_SPEED_TIME, 0L); /* LFS weirdance diff --git a/php_http_misc.c b/php_http_misc.c index e4411e0..fa4bbbf 100644 --- a/php_http_misc.c +++ b/php_http_misc.c @@ -116,6 +116,30 @@ size_t php_http_boundary(char *buf, size_t buf_len TSRMLS_DC) return snprintf(buf, buf_len, "%15.15F", PHP_HTTP_G->env.request.time * php_combined_lcg(TSRMLS_C)); } +int php_http_select_str(const char *cmp, int argc, ...) +{ + va_list argv; + int match = -1; + + if (cmp && argc > 0) { + int i; + + va_start(argv, argc); + for (i = 0; i < argc; ++i) { + const char *test = va_arg(argv, const char *); + + if (!strcasecmp(cmp, test)) { + match = i; + break; + } + } + va_end(argv); + } + + return match; +} + + /* ARRAYS */ int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) diff --git a/php_http_misc.h b/php_http_misc.h index 35c8951..6c00cc5 100644 --- a/php_http_misc.h +++ b/php_http_misc.h @@ -80,9 +80,9 @@ PHP_HTTP_API void php_http_sleep(double s); #define PHP_HTTP_MATCH_STRICT (PHP_HTTP_MATCH_CASE|PHP_HTTP_MATCH_FULL) extern int php_http_match(const char *haystack, const char *needle, int flags); - extern char *php_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen); extern size_t php_http_boundary(char *buf, size_t len TSRMLS_DC); +extern int php_http_select_str(const char *cmp, int argc, ...); static inline const char *php_http_locate_str(const char *h, size_t h_len, const char *n, size_t n_len) { diff --git a/php_http_request.h b/php_http_request.h index 99f75d9..d535dc4 100644 --- a/php_http_request.h +++ b/php_http_request.h @@ -13,7 +13,6 @@ #ifndef PHP_HTTP_REQUEST_H #define PHP_HTTP_REQUEST_H -#include "php_http_request_method.h" #include "php_http_message_body.h" #include "php_http_message_parser.h" diff --git a/php_http_request_datashare.c b/php_http_request_datashare.c index a4502e5..5dbf9dd 100644 --- a/php_http_request_datashare.c +++ b/php_http_request_datashare.c @@ -212,6 +212,8 @@ static void php_http_request_datashare_object_write_prop(zval *object, zval *mem opt = PHP_HTTP_REQUEST_DATASHARE_OPT_COOKIES; } else if (!strcmp(pi->name, "dns")) { opt = PHP_HTTP_REQUEST_DATASHARE_OPT_RESOLVER; + } else if (!strcmp(pi->name, "ssl")) { + opt = PHP_HTTP_REQUEST_DATASHARE_OPT_SSLSESSIONS; } else { return; } @@ -314,6 +316,7 @@ PHP_MINIT_FUNCTION(http_request_datashare) zend_declare_property_bool(php_http_request_datashare_class_entry, ZEND_STRL("cookie"), 0, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_bool(php_http_request_datashare_class_entry, ZEND_STRL("dns"), 0, ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_bool(php_http_request_datashare_class_entry, ZEND_STRL("ssl"), 0, ZEND_ACC_PUBLIC TSRMLS_CC); return SUCCESS; } diff --git a/php_http_request_datashare.h b/php_http_request_datashare.h index a6939ac..066a1bd 100644 --- a/php_http_request_datashare.h +++ b/php_http_request_datashare.h @@ -16,6 +16,7 @@ typedef enum php_http_request_datashare_setopt_opt { PHP_HTTP_REQUEST_DATASHARE_OPT_COOKIES, PHP_HTTP_REQUEST_DATASHARE_OPT_RESOLVER, + PHP_HTTP_REQUEST_DATASHARE_OPT_SSLSESSIONS, } php_http_request_datashare_setopt_opt_t; typedef struct php_http_request_datashare php_http_request_datashare_t; diff --git a/php_http_request_method.c b/php_http_request_method.c deleted file mode 100644 index 13561ad..0000000 --- a/php_http_request_method.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - +--------------------------------------------------------------------+ - | PECL :: http | - +--------------------------------------------------------------------+ - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted provided that the conditions mentioned | - | in the accompanying LICENSE file are met. | - +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | - +--------------------------------------------------------------------+ -*/ - -#include "php_http_api.h" - -PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...) -{ - va_list argv; - int match = -1; - - if (argc > 0) { - int i; - - va_start(argv, argc); - for (i = 0; i < argc; ++i) { - const char *test = va_arg(argv, const char *); - - if (!strcasecmp(meth, test)) { - match = i; - break; - } - } - va_end(argv); - } - - return match; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_request_method.h b/php_http_request_method.h deleted file mode 100644 index 85eedbd..0000000 --- a/php_http_request_method.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +--------------------------------------------------------------------+ - | PECL :: http | - +--------------------------------------------------------------------+ - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted provided that the conditions mentioned | - | in the accompanying LICENSE file are met. | - +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | - +--------------------------------------------------------------------+ -*/ - -#ifndef PHP_HTTP_REQUEST_METHOD_H -#define PHP_HTTP_REQUEST_METHOD_H - -PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ -