- get rid of 1001 strict-aliasing warnings
[m6w6/ext-http] / http_request_body_api.c
index 75b3c45bb4746d819ca9df925b1d35be3b381746..fcaa635d00f54603a9ba1c820aa944e70427cef1 100644 (file)
@@ -6,16 +6,12 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2005, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2006, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
@@ -25,8 +21,6 @@
 #include "php_http_url_api.h"
 #include "php_http_request_body_api.h"
 
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
 /* {{{ http_request_body *http_request_body_new() */
 PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
@@ -36,6 +30,7 @@ PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *bo
        
        body->type = type;
        body->free = free;
+       body->priv = 0;
        body->data = data;
        body->size = size;
        
@@ -54,31 +49,33 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body,
                struct curl_httppost *http_post_data[2] = {NULL, NULL};
 
                /* normal data */
-               FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
-                       if (key) {
-                               CURLcode err;
-                               zval *orig = *data;
-                               
-                               convert_to_string_ex(data);
-                               err = curl_formadd(&http_post_data[0], &http_post_data[1],
-                                       CURLFORM_COPYNAME,                      key,
-                                       CURLFORM_COPYCONTENTS,          Z_STRVAL_PP(data),
-                                       CURLFORM_CONTENTSLENGTH,        (long) Z_STRLEN_PP(data),
-                                       CURLFORM_END
-                               );
-                               
-                               if (orig != *data) {
-                                       zval_ptr_dtor(data);
-                               }
-                               
-                               if (CURLE_OK != err) {
-                                       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
-                                       curl_formfree(http_post_data[0]);
-                                       return NULL;
+               if (fields) {
+                       FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
+                               if (key) {
+                                       CURLcode err;
+                                       zval *orig = *data;
+                                       
+                                       convert_to_string_ex(data);
+                                       err = curl_formadd(&http_post_data[0], &http_post_data[1],
+                                               CURLFORM_COPYNAME,                      key,
+                                               CURLFORM_COPYCONTENTS,          Z_STRVAL_PP(data),
+                                               CURLFORM_CONTENTSLENGTH,        (long) Z_STRLEN_PP(data),
+                                               CURLFORM_END
+                                       );
+                                       
+                                       if (orig != *data) {
+                                               zval_ptr_dtor(data);
+                                       }
+                                       
+                                       if (CURLE_OK != err) {
+                                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
+                                               curl_formfree(http_post_data[0]);
+                                               return NULL;
+                                       }
+       
+                                       /* reset */
+                                       key = NULL;
                                }
-
-                               /* reset */
-                               key = NULL;
                        }
                }
 
@@ -88,9 +85,9 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body,
                        
                        if (Z_TYPE_PP(data) != IS_ARRAY) {
                                http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Unrecognized type of post file array entry");
-                       } else if (     SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void **) &name) ||
-                                               SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &type) ||
-                                               SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
+                       } else if (     SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void *) &name) ||
+                                               SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void *) &type) ||
+                                               SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void *) &file)) {
                                http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
                        } else {
                                CURLcode err;
@@ -131,7 +128,7 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body,
                
                return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
 
-       } else {
+       } else if (fields) {
                char *encoded;
                size_t encoded_len;
 
@@ -141,6 +138,8 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body,
                }
                
                return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
+       } else {
+               return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, estrndup("", 0), 0, 1);
        }
 }