From 60086d086e7f0dbfccf61931c1b2e2b410ccb5bb Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 17 Feb 2006 16:35:05 +0000 Subject: [PATCH] - add portrange request option --- docs/functions.html | 5 ++++- http_functions.c | 3 +++ http_request_api.c | 32 ++++++++++++++++++++++++++++---- package2.xml | 1 + php_http.h | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docs/functions.html b/docs/functions.html index cca7dc4..7871ba1 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -326,6 +326,7 @@ array where the following keys will be recognized:

 - redirect:
  - encodecookies:    bool, whether to urlencode the cookies (default: true)
- resetcookies: bool, wheter to reset the cookies
- cookiestore: string, path to a file where cookies are/will be stored
+ - cookiesession: bool, accept (true) or reset (false) sessioncookies
- resume: int, byte offset to start the download from;
if the server supports ranges
- maxfilesize: int, maximum file size that should be downloaded;
@@ -335,6 +336,8 @@ array where the following keys will be recognized:

 - redirect:
  - timeout:          int, seconds the request may take
- connecttimeout: int, seconds the connect may take
- onprogress: mixed, progress callback
+ - interface: string, outgoing network interface (ifname, ip or hostname)
+ - portrange: array, 2 integers specifying outgoing portrange to try
- ssl: array, with the following options:
cert: string, path to certificate
certtype: string, type of certificate
@@ -1355,7 +1358,7 @@ http.cache_log is set.

-

Generated at: Wed, 15 Feb 2006 08:40:01 +0100

+

Generated at: Fri, 17 Feb 2006 17:34:44 +0100

diff --git a/http_functions.c b/http_functions.c index 8a5e49e..1c63ba0 100644 --- a/http_functions.c +++ b/http_functions.c @@ -1246,6 +1246,7 @@ PHP_FUNCTION(http_match_request_header) * - encodecookies: bool, whether to urlencode the cookies (default: true) * - resetcookies: bool, wheter to reset the cookies * - cookiestore: string, path to a file where cookies are/will be stored + * - cookiesession: bool, accept (true) or reset (false) sessioncookies * - resume: int, byte offset to start the download from; * if the server supports ranges * - maxfilesize: int, maximum file size that should be downloaded; @@ -1255,6 +1256,8 @@ PHP_FUNCTION(http_match_request_header) * - timeout: int, seconds the request may take * - connecttimeout: int, seconds the connect may take * - onprogress: mixed, progress callback + * - interface: string, outgoing network interface (ifname, ip or hostname) + * - portrange: array, 2 integers specifying outgoing portrange to try * - ssl: array, with the following options: * cert: string, path to certificate * certtype: string, type of certificate diff --git a/http_request_api.c b/http_request_api.c index 613c32a..e34b866 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -429,6 +429,10 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0); HTTP_CURL_OPT(CURLOPT_INTERFACE, NULL); HTTP_CURL_OPT(CURLOPT_PORT, 0); +#if HTTP_CURL_VERSION(7,15,2) + HTTP_CURL_OPT(CURLOPT_LOCALPORT, 0); + HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, 0); +#endif HTTP_CURL_OPT(CURLOPT_USERPWD, NULL); HTTP_CURL_OPT(CURLOPT_HTTPAUTH, 0); HTTP_CURL_OPT(CURLOPT_ENCODING, NULL); @@ -438,7 +442,7 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(CURLOPT_USERAGENT, "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")"); HTTP_CURL_OPT(CURLOPT_HTTPHEADER, NULL); HTTP_CURL_OPT(CURLOPT_COOKIE, NULL); -#if LIBCURL_VERSION_NUM >= 0x070e01 +#if HTTP_CURL_VERSION(7,14,1) HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL); #endif HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL); @@ -540,6 +544,27 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti /* outgoing interface */ if ((zoption = http_request_option(request, options, "interface", IS_STRING))) { HTTP_CURL_OPT(CURLOPT_INTERFACE, Z_STRVAL_P(zoption)); + +#if HTTP_CURL_VERSION(7,15,2) + if ((zoption = http_request_option(request, options, "portrange", IS_ARRAY))) { + zval *prs, *pre; + + zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption)); + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &prs)) { + zend_hash_move_forward(Z_ARRVAL_P(zoption)); + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &pre)) { + zval *prs_cpy = zval_copy(IS_LONG, *prs), *pre_cpy = zval_copy(IS_LONG, *pre); + + if (Z_LVAL_P(prs_cpy) && Z_LVAL_P(pre_cpy)) { + HTTP_CURL_OPT(CURLOPT_LOCALPORT, MIN(Z_LVAL_P(prs_cpy), Z_LVAL_P(pre_cpy))); + HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, ABS(Z_LVAL_P(prs_cpy)-Z_LVAL_P(pre_cpy))+1L); + } + zval_free(&prs_cpy); + zval_free(&pre_cpy); + } + } + } +#endif } /* another port */ @@ -660,7 +685,6 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } else { HashPosition pos; - zval *cookie_val = NULL; char *cookie_key = NULL; ulong cookie_idx; @@ -686,7 +710,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } -#if LIBCURL_VERSION_NUM >= 0x070e01 +#if HTTP_CURL_VERSION(7,14,1) /* reset cookies */ if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) { HTTP_CURL_OPT(CURLOPT_COOKIELIST, "ALL"); @@ -873,7 +897,7 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info) HTTP_CURL_INFO(CURLINFO_HTTPAUTH_AVAIL); HTTP_CURL_INFO(CURLINFO_PROXYAUTH_AVAIL); HTTP_CURL_INFO(CURLINFO_NUM_CONNECTS); -#if LIBCURL_VERSION_NUM >= 0x070e01 +#if HTTP_CURL_VERSION(7,14,1) HTTP_CURL_INFO_EX(CURLINFO_COOKIELIST, "cookies"); #endif HTTP_CURL_INFO(CURLINFO_OS_ERRNO); diff --git a/package2.xml b/package2.xml index 930391a..c3aa039 100644 --- a/package2.xml +++ b/package2.xml @@ -47,6 +47,7 @@ HttpResponse BSD, revised +# define HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z))) #endif #if defined(HTTP_WANT_MAGIC) && defined(HTTP_HAVE_MAGIC) -- 2.30.2