- release 1.6.0RC1
[m6w6/ext-http] / http_request_body_api.c
index a57702379425374db517eb22126c3f5cacfad688..f2d5f5684569e8294b8e5aac3e3bdd2830d8671c 100644 (file)
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2006, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2007, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
 #include "php_http_url_api.h"
 #include "php_http_request_body_api.h"
 
-#if defined(HAVE_CURL_GETFORMDATA) && !defined(HAVE_CURL_FORMGET)
-struct FormData {
-       struct FormData *next;
-       int type;
-       char *line;
-       size_t length;
-};
-
-CURLcode Curl_getFormData(struct FormData **, struct curl_httppost *post, curl_off_t *size);
-
-static char *file_get_contents(char *file, size_t *len TSRMLS_DC)
-{
-       php_stream *s = NULL;
-       char *buf = NULL;
-       
-       if ((s = php_stream_open_wrapper_ex(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT))) {
-               *len = php_stream_copy_to_mem(s, &buf, (size_t) -1, 0);
-               php_stream_close(s);
-       } else {
-               *len = 0;
-       }
-       return buf;
-}
-
-static int curl_formget(struct FormData *post, phpstr *str TSRMLS_DC)
-{
-       int fgc_error = 0;
-       char *fdata;
-       size_t fsize;
-       struct FormData *next, *pptr = post;
-       
-       while (pptr) {
-               next = pptr->next;
-               
-               if (!fgc_error) {
-                       if (pptr->type) {
-                               if ((fdata = file_get_contents(pptr->line, &fsize TSRMLS_CC))) {
-                                       phpstr_append(str, fdata, fsize);
-                                       efree(fdata);
-                               } else {
-                                       fgc_error = 1;
-                               }
-                       } else {
-                               phpstr_append(str, pptr->line, pptr->length);
-                       }
-               }
-               
-               curl_free(pptr->line);
-               curl_free(pptr);
-               pptr = next;
-       }
-       
-       return fgc_error;
-}
-#endif
-
-
 /* {{{ 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)
 {
@@ -99,22 +42,21 @@ PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *bo
 PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        if (files && (zend_hash_num_elements(files) > 0)) {
-               char *key = NULL;
-               ulong idx;
+               HashKey key = initHashKey(0);
                zval **data;
                HashPosition pos;
                struct curl_httppost *http_post_data[2] = {NULL, NULL};
 
                /* normal data */
                if (fields) {
-                       FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
-                               if (key) {
+                       FOREACH_HASH_KEYVAL(pos, fields, key, data) {
+                               if (key.type == HASH_KEY_IS_STRING) {
                                        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_COPYNAME,                      key.str,
                                                CURLFORM_COPYCONTENTS,          Z_STRVAL_PP(data),
                                                CURLFORM_CONTENTSLENGTH,        (long) Z_STRLEN_PP(data),
                                                CURLFORM_END
@@ -129,9 +71,6 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body,
                                                curl_formfree(http_post_data[0]);
                                                return NULL;
                                        }
-       
-                                       /* reset */
-                                       key = NULL;
                                }
                        }
                }
@@ -206,7 +145,7 @@ PHP_HTTP_API STATUS _http_request_body_encode(http_request_body *body, char **bu
        switch (body->type) {
                case HTTP_REQUEST_BODY_CURLPOST:
                {
-#if defined(HAVE_CURL_FORMGET)
+#ifdef HAVE_CURL_FORMGET
                        phpstr str;
                        
                        phpstr_init_ex(&str, 0x8000, 0);
@@ -218,23 +157,6 @@ PHP_HTTP_API STATUS _http_request_body_encode(http_request_body *body, char **bu
                                *len = PHPSTR_LEN(&str);
                                return SUCCESS;
                        }
-#elif defined(HAVE_CURL_GETFORMDATA)
-                       struct FormData *data;
-                       curl_off_t size;
-                       
-                       if (!Curl_getFormData(&data, body->data, &size)) {
-                               phpstr str;
-                               
-                               phpstr_init_ex(&str, (size_t) size, 0);
-                               if (curl_formget(data, &str TSRMLS_CC)) {
-                                       phpstr_dtor(&str);
-                               } else {
-                                       phpstr_fix(&str);
-                                       *buf = PHPSTR_VAL(&str);
-                                       *len = PHPSTR_LEN(&len);
-                                       return SUCCESS;
-                               }
-                       }
 #endif
                        break;
                }