From: Michael Wallner Date: Mon, 27 Feb 2006 16:55:13 +0000 (+0000) Subject: - add 'range' request option X-Git-Tag: RELEASE_1_0_0RC1~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=370748ba4211ca298fec6706343413888c8b393f;p=m6w6%2Fext-http - add 'range' request option - add 'proxytype' request option - add proxy type constants --- diff --git a/http_functions.c b/http_functions.c index 8f91300..04377f5 100644 --- a/http_functions.c +++ b/http_functions.c @@ -1230,6 +1230,7 @@ PHP_FUNCTION(http_match_request_header) * redirects to a different host * - proxyhost: string, proxy host in "host[:port]" format * - proxyport: int, use another proxy port as specified in proxyhost + * - proxytype: int, HTTP_PROXY_HTTP, SOCKS4 or SOCKS5 * - proxyauth: string, proxy credentials in "user:pass" format * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM * - httpauth: string, http credentials in "user:pass" format @@ -1249,6 +1250,9 @@ PHP_FUNCTION(http_match_request_header) * - cookiesession: bool, accept (true) or reset (false) sessioncookies * - resume: int, byte offset to start the download from; * if the server supports ranges + * - range: array, array of arrays, each containing two integers, + * specifying the ranges to download if server support is + * given; only recognized if the resume option is empty * - maxfilesize: int, maximum file size that should be downloaded; * has no effect, if the size of the requested entity is not known * - lastmodified: int, timestamp for If-(Un)Modified-Since header diff --git a/http_request_api.c b/http_request_api.c index 8e8fa9c..7927648 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -147,6 +147,11 @@ PHP_MINIT_FUNCTION(http_request) HTTP_LONG_CONSTANT("HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0); HTTP_LONG_CONSTANT("HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1); +#if HTTP_CURL_VERSION(7,15,2) + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS4", CURLPROXY_SOCKS4); +#endif + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS5", CURLPROXY_SOCKS5); + HTTP_LONG_CONSTANT("HTTP_PROXY_HTTP", CURLPROXY_HTTP); return SUCCESS; } /* }}} */ @@ -425,6 +430,7 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 1); HTTP_CURL_OPT(CURLOPT_PROXY, NULL); HTTP_CURL_OPT(CURLOPT_PROXYPORT, 0); + HTTP_CURL_OPT(CURLOPT_PROXYTYPE, 0); HTTP_CURL_OPT(CURLOPT_PROXYUSERPWD, NULL); HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0); HTTP_CURL_OPT(CURLOPT_INTERFACE, NULL); @@ -447,6 +453,7 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) #endif HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL); HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL); + HTTP_CURL_OPT(CURLOPT_RANGE, NULL); HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0); HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0); HTTP_CURL_OPT(CURLOPT_TIMECONDITION, 0); @@ -526,7 +533,10 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti if (Z_STRLEN_P(zoption)) { HTTP_CURL_OPT(CURLOPT_PROXY, Z_STRVAL_P(zoption)); } - + /* type */ + if ((zoption = http_request_option(request, options, "proxytype", IS_LONG))) { + HTTP_CURL_OPT(CURLOPT_PROXYTYPE, Z_LVAL_P(zoption)); + } /* port */ if ((zoption = http_request_option(request, options, "proxyport", IS_LONG))) { HTTP_CURL_OPT(CURLOPT_PROXYPORT, Z_LVAL_P(zoption)); @@ -609,6 +619,46 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti range_req = 1; HTTP_CURL_OPT(CURLOPT_RESUME_FROM, Z_LVAL_P(zoption)); } + /* or range of kind array(array(0,499), array(100,1499)) */ + else if ((zoption = http_request_option(request, options, "range", IS_ARRAY)) && zend_hash_num_elements(Z_ARRVAL_P(zoption))) { + HashPosition pos1, pos2; + zval **rr, **rb, **re; + phpstr rs; + + phpstr_init(&rs); + FOREACH_VAL(pos1, zoption, rr) { + if (Z_TYPE_PP(rr) == IS_ARRAY) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(rr), &pos2); + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void **) &rb, &pos2)) { + zend_hash_move_forward_ex(Z_ARRVAL_PP(rr), &pos2); + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void **) &re, &pos2)) { + if ( ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) && + ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) { + zval *rbl = zval_copy(IS_LONG, *rb), *rel = zval_copy(IS_LONG, *re); + + if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) { + phpstr_appendf(&rs, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel)); + } + zval_free(&rbl); + zval_free(&rel); + } + } + } + } + } + + if (PHPSTR_LEN(&rs)) { + zval *cached_range; + + /* ditch last comma */ + PHPSTR_VAL(&rs)[PHPSTR_LEN(&rs)-- -1] = '\0'; + /* cache string */ + MAKE_STD_ZVAL(cached_range); + ZVAL_STRINGL(cached_range, PHPSTR_VAL(&rs), PHPSTR_LEN(&rs), 0); + HTTP_CURL_OPT(CURLOPT_RANGE, Z_STRVAL_P(http_request_option_cache(request, "range", cached_range))); + zval_ptr_dtor(&cached_range); + } + } /* additional headers, array('name' => 'value') */ if (request->_cache.headers) { diff --git a/http_request_object.c b/http_request_object.c index c5fd293..9b0dd91 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -419,7 +419,9 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) /* WebDAV Access Control - RFC 3744 */ DCL_CONST(long, "METH_ACL", HTTP_ACL); - /* cURL HTTP protocol versions */ + /* + * HTTP Protocol Version Constants + */ DCL_CONST(long, "VERSION_1_0", CURL_HTTP_VERSION_1_0); DCL_CONST(long, "VERSION_1_1", CURL_HTTP_VERSION_1_1); DCL_CONST(long, "VERSION_NONE", CURL_HTTP_VERSION_NONE); @@ -431,6 +433,15 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST); DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM); DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY); + + /* + * Proxy Type Constants + */ +# if HTTP_CURL_VERSION(7,15,2) + DCL_CONST(long, "PROXY_SOCKS4", CURLPROXY_SOCKS4); +# endif + DCL_CONST(long, "PROXY_SOCKS5", CURLPROXY_SOCKS5); + DCL_CONST(long, "PROXY_HTTP", CURLPROXY_HTTP); #endif /* WONKY */ } diff --git a/package2.xml b/package2.xml index 0efb93a..ec7504b 100644 --- a/package2.xml +++ b/package2.xml @@ -46,10 +46,13 @@ HttpResponse BSD, revised