- get rid of 1001 strict-aliasing warnings
[m6w6/ext-http] / http_functions.c
index 8a5e49ed5f260bef1087dece1562edb39784703d..aeb41da2482de0316695c67b340968ec4b0a52f3 100644 (file)
@@ -250,7 +250,7 @@ PHP_FUNCTION(http_build_str)
                zval **value; \
                 \
                zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \
-               if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void **) &value)) { \
+               if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void *) &value)) { \
                        RETVAL_ZVAL(*value, 1, 0); \
                } else { \
                        RETVAL_NULL(); \
@@ -1206,7 +1206,7 @@ PHP_FUNCTION(http_match_request_header)
                zval **bodyonly; \
                 \
                /* check if only the body should be returned */ \
-               if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void **) &bodyonly)) && zval_is_true(*bodyonly)) { \
+               if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void *) &bodyonly)) && zval_is_true(*bodyonly)) { \
                        http_message *msg = http_message_parse(PHPSTR_VAL(&request.conv.response), PHPSTR_LEN(&request.conv.response)); \
                         \
                        if (msg) { \
@@ -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
@@ -1246,8 +1247,12 @@ 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
+ *  - 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
@@ -1255,6 +1260,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
@@ -1499,7 +1506,7 @@ PHP_FUNCTION(http_put_file)
                RETURN_FALSE;
        }
 
-       if (!(stream = php_stream_open_wrapper(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL))) {
+       if (!(stream = php_stream_open_wrapper_ex(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT))) {
                RETURN_FALSE;
        }
        if (php_stream_stat(stream, &ssb)) {
@@ -1514,12 +1521,8 @@ PHP_FUNCTION(http_put_file)
 
        RETVAL_FALSE;
 
-       body.type = HTTP_REQUEST_BODY_UPLOADFILE;
-       body.data = stream;
-       body.size = ssb.sb.st_size;
-
        http_request_init_ex(&request, NULL, HTTP_PUT, URL);
-       request.body = &body;
+       request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
        if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
                http_request_exec(&request);
                if (info) {
@@ -1527,8 +1530,6 @@ PHP_FUNCTION(http_put_file)
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       http_request_body_dtor(&body);
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */
@@ -1541,7 +1542,7 @@ PHP_FUNCTION(http_put_file)
  * opened stream, from which the data to upload should be read.
  * See http_get() for a full list of available options.
  * 
- * Returns the HTTP response(s) as string on success. or FALSE on failure.
+ * Returns the HTTP response(s) as string on success, or FALSE on failure.
  */
 PHP_FUNCTION(http_put_stream)
 {
@@ -1569,12 +1570,49 @@ PHP_FUNCTION(http_put_stream)
 
        RETVAL_FALSE;
 
-       body.type = HTTP_REQUEST_BODY_UPLOADFILE;
-       body.data = stream;
-       body.size = ssb.sb.st_size;
+       http_request_init_ex(&request, NULL, HTTP_PUT, URL);
+       request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 0);
+       if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
+               http_request_exec(&request);
+               if (info) {
+                       http_request_info(&request, Z_ARRVAL_P(info));
+               }
+               RETVAL_RESPONSE_OR_BODY(request);
+       }
+       http_request_dtor(&request);
+}
+/* }}} */
 
-       http_request_init_ex(&request, NULL, HTTP_POST, URL);
-       request.body = &body;
+/* {{{ proto string http_put_data(string url, string data[, array options[, array &info]])
+ *
+ * Performs an HTTP PUT request on the supplied url.
+ * 
+ * Expects the second parameter to be a string containing the data to upload.
+ * See http_get() for a full list of available options.
+ * 
+ * Returns the HTTP response(s) as string on success, or FALSE on failure.
+ */
+PHP_FUNCTION(http_put_data)
+{
+       char *URL, *data;
+       int URL_len, data_len;
+       zval *options = NULL, *info = NULL;
+       http_request_body body;
+       http_request request;
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &data, &data_len, &options, &info)) {
+               RETURN_FALSE;
+       }
+       
+       if (info) {
+               zval_dtor(info);
+               array_init(info);
+       }
+       
+       RETVAL_FALSE;
+       
+       http_request_init_ex(&request, NULL, HTTP_PUT, URL);
+       request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
        if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
                http_request_exec(&request);
                if (info) {
@@ -1582,7 +1620,6 @@ PHP_FUNCTION(http_put_stream)
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */