remove php_http_request_method.[ch]; add support for CURL_LOCK_DATA_SSL_SESSION,...
authorMichael Wallner <mike@php.net>
Thu, 22 Mar 2012 17:34:36 +0000 (17:34 +0000)
committerMichael Wallner <mike@php.net>
Thu, 22 Mar 2012 17:34:36 +0000 (17:34 +0000)
config9.m4
package.xml
php_http_api.h
php_http_curl.c
php_http_misc.c
php_http_misc.h
php_http_request.h
php_http_request_datashare.c
php_http_request_datashare.h
php_http_request_method.c [deleted file]
php_http_request_method.h [deleted file]

index 2a03cef..be7bdf9 100644 (file)
@@ -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 \
index 3f34a59..4546749 100644 (file)
@@ -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
 ]]></notes>
  <contents>
   <dir name="/">
@@ -107,8 +107,6 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
    <file role="src" name="php_http_request_factory.c"/>
    <file role="src" name="php_http_request_factory.h"/>
    <file role="src" name="php_http_request.h"/>
-   <file role="src" name="php_http_request_method.c"/>
-   <file role="src" name="php_http_request_method.h"/>
    <file role="src" name="php_http_request_pool.c"/>
    <file role="src" name="php_http_request_pool.h"/>
    <file role="src" name="php_http_resource_factory.c"/>
index a6ea120..23e63cd 100644 (file)
@@ -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"
index 9bfeda8..f4a4244 100644 (file)
@@ -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
index e4411e0..fa4bbbf 100644 (file)
@@ -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)
index 35c8951..6c00cc5 100644 (file)
@@ -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)
 {
index 99f75d9..d535dc4 100644 (file)
@@ -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"
 
index a4502e5..5dbf9dd 100644 (file)
@@ -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;
 }
index a6939ac..066a1bd 100644 (file)
@@ -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 (file)
index 13561ad..0000000
+++ /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 <mike@php.net>            |
-    +--------------------------------------------------------------------+
-*/
-
-#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 (file)
index 85eedbd..0000000
+++ /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 <mike@php.net>            |
-    +--------------------------------------------------------------------+
-*/
-
-#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
- */
-