- add 'range' request option
authorMichael Wallner <mike@php.net>
Mon, 27 Feb 2006 16:55:13 +0000 (16:55 +0000)
committerMichael Wallner <mike@php.net>
Mon, 27 Feb 2006 16:55:13 +0000 (16:55 +0000)
- add 'proxytype' request option
- add proxy type constants

http_functions.c
http_request_api.c
http_request_object.c
package2.xml

index 8f9130042def69c1a234e5e3f2a46d6970ae271c..04377f54ac12c34d94082d799a3916f4f3246b6e 100644 (file)
@@ -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
index 8e8fa9ca08e2b00a1c106585f2e612a41925fae8..7927648221c52a624dd977ca0095a6342a795dd3 100644 (file)
@@ -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) {
index c5fd2936b76688d74f0e1ed7e3e3bd2b969b8e88..9b0dd91f12d3652160ff3fae37a8712880733c67 100644 (file)
@@ -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 */
 }
 
index 0efb93aec6959af05937450fb57e4816eb6773d3..ec7504ba09f59d1ba6df7023fe99c0c50546f4c7 100644 (file)
@@ -46,10 +46,13 @@ HttpResponse
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
-* Fixed bug #6924 - Linking fails on Mac OSX
+* Fixed bug #6924 (Linking fails on Mac OSX).
 * Fixed HttpRequest::addRawPostData().
 
 + Added feature request http_put_data() and HttpRequest::(set|get|add)PutData().
++ Added 'range' request option.
++ Added 'proxytype' request option.
++ Added HTTP_PROXY_HTTP, HTTP_PROXY_SOCKS4, HTTP_PROXY_SOCKS5 constants.
 ]]></notes>
  <contents>
   <dir name="/">