* fix memleak
[m6w6/ext-http] / http_curl_api.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
21
22 #ifdef PHP_WIN32
23 # include <winsock2.h>
24 #endif
25
26 #include <curl/curl.h>
27
28 #include "php.h"
29 #include "php_http.h"
30 #include "php_http_api.h"
31 #include "php_http_curl_api.h"
32 #include "php_http_std_defs.h"
33
34 #ifdef ZEND_ENGINE_2
35 # include "ext/standard/php_http.h"
36 #endif
37
38 #include "ext/standard/php_smart_str.h"
39
40 ZEND_DECLARE_MODULE_GLOBALS(http)
41
42 #if LIBCURL_VERSION_NUM >= 0x070c01
43 # define http_curl_reset(ch) curl_easy_reset(ch)
44 #else
45 # define http_curl_reset(ch)
46 #endif
47
48 /* FIXXME: correct version where strerror is supported! */
49 #if LIBCURL_VERSION_NUM < 0x070b01
50 # define curl_easy_strerror(code) "unkown error"
51 #endif
52
53 #define http_curl_startup(ch, clean_curl, URL, options) \
54 if (!ch) { \
55 if (!(ch = curl_easy_init())) { \
56 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize curl"); \
57 return FAILURE; \
58 } \
59 clean_curl = 1; \
60 } else { \
61 http_curl_reset(ch); \
62 } \
63 http_curl_initbuf(); \
64 http_curl_setopts(ch, URL, options);
65
66 #define http_curl_perform(ch, clean_curl) \
67 { \
68 CURLcode result; \
69 if (CURLE_OK != (result = curl_easy_perform(ch))) { \
70 http_curl_cleanup(ch, clean_curl); \
71 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request: %s", curl_easy_strerror(result)); \
72 return FAILURE; \
73 } \
74 }
75
76 #define http_curl_cleanup(ch, clean_curl) \
77 http_curl_freestr(); \
78 http_curl_freebuf(); \
79 if (clean_curl) { \
80 curl_easy_cleanup(ch); \
81 ch = NULL; \
82 }
83
84 #define http_curl_freestr() \
85 zend_llist_clean(&HTTP_G(to_free))
86
87 #define http_curl_initbuf() \
88 http_curl_initbuf_ex(0)
89
90 #define http_curl_initbuf_ex(chunk_size) \
91 { \
92 size_t size = chunk_size; \
93 if (size < 1) { \
94 size = HTTP_CURLBUF_SIZE; \
95 } \
96 http_curl_freebuf(); \
97 HTTP_G(curlbuf).data = emalloc(size); \
98 HTTP_G(curlbuf).free = size; \
99 HTTP_G(curlbuf).size = size; \
100 }
101
102 #define http_curl_freebuf() \
103 if (HTTP_G(curlbuf).data) { \
104 efree(HTTP_G(curlbuf).data); \
105 HTTP_G(curlbuf).data = NULL; \
106 } \
107 HTTP_G(curlbuf).used = 0; \
108 HTTP_G(curlbuf).free = 0; \
109 HTTP_G(curlbuf).size = 0;
110
111 #define http_curl_copybuf(data, size) \
112 *size = HTTP_G(curlbuf).used; \
113 *data = ecalloc(1, HTTP_G(curlbuf).used + 1); \
114 memcpy(*data, HTTP_G(curlbuf).data, HTTP_G(curlbuf).used);
115
116 #define http_curl_sizebuf(for_size) \
117 { \
118 size_t size = (for_size); \
119 if (size > HTTP_G(curlbuf).free) { \
120 size_t bsize = HTTP_G(curlbuf).size; \
121 while (size > bsize) { \
122 bsize *= 2; \
123 } \
124 HTTP_G(curlbuf).data = erealloc(HTTP_G(curlbuf).data, HTTP_G(curlbuf).used + bsize); \
125 HTTP_G(curlbuf).free += bsize; \
126 } \
127 }
128
129
130 #define http_curl_copystr(s) _http_curl_copystr((s) TSRMLS_CC)
131 static inline char *_http_curl_copystr(const char *str TSRMLS_DC);
132
133 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
134 static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC);
135
136 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
137 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
138 #define http_curl_getopt2(o, k, t1, t2) _http_curl_getopt((o), (k) TSRMLS_CC, 2, (t1), (t2))
139 static inline zval *_http_curl_getopt(HashTable *options, char *key TSRMLS_DC, int checks, ...);
140
141 static size_t http_curl_body_callback(char *, size_t, size_t, void *);
142 static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *);
143
144 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
145 static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC);
146
147 /* {{{ static inline char *http_curl_copystr(char *) */
148 static inline char *_http_curl_copystr(const char *str TSRMLS_DC)
149 {
150 char *new_str = estrdup(str);
151 zend_llist_add_element(&HTTP_G(to_free), &new_str);
152 return new_str;
153 }
154 /* }}} */
155
156 /* {{{ static size_t http_curl_body_callback(char *, size_t, size_t, void *) */
157 static size_t http_curl_body_callback(char *buf, size_t len, size_t n, void *s)
158 {
159 TSRMLS_FETCH();
160
161 http_curl_sizebuf(len *= n);
162
163 memcpy(HTTP_G(curlbuf).data + HTTP_G(curlbuf).used, buf, len);
164 HTTP_G(curlbuf).free -= len;
165 HTTP_G(curlbuf).used += len;
166 return len;
167 }
168 /* }}} */
169
170 /* {{{ static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *) */
171 static size_t http_curl_hdrs_callback(char *buf, size_t len, size_t n, void *s)
172 {
173 TSRMLS_FETCH();
174
175 /* discard previous headers */
176 if ((HTTP_G(curlbuf).used) && (!strncmp(buf, "HTTP/1.", sizeof("HTTP/1.") - 1))) {
177 http_curl_initbuf();
178 }
179 http_curl_sizebuf(len *= n);
180
181 memcpy(HTTP_G(curlbuf).data + HTTP_G(curlbuf).used, buf, len);
182 HTTP_G(curlbuf).free -= len;
183 HTTP_G(curlbuf).used += len;
184 return len;
185 }
186 /* }}} */
187
188 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int, ...) */
189 static inline zval *_http_curl_getopt(HashTable *options, char *key TSRMLS_DC, int checks, ...)
190 {
191 zval **zoption;
192 va_list types;
193 int i;
194
195 if (SUCCESS != zend_hash_find(options, key, strlen(key) + 1, (void **) &zoption)) {
196 return NULL;
197 }
198 if (checks < 1) {
199 return *zoption;
200 }
201
202 va_start(types, checks);
203 for (i = 0; i < checks; ++i) {
204 if ((va_arg(types, int)) == (Z_TYPE_PP(zoption))) {
205 va_end(types);
206 return *zoption;
207 }
208 }
209 va_end(types);
210 return NULL;
211 }
212 /* }}} */
213
214 /* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
215 static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC)
216 {
217 zval *zoption;
218 zend_bool range_req = 0;
219
220 /* standard options */
221 curl_easy_setopt(ch, CURLOPT_URL, url);
222 curl_easy_setopt(ch, CURLOPT_HEADER, 0);
223 curl_easy_setopt(ch, CURLOPT_FILETIME, 1);
224 curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
225 curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1);
226 curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, http_curl_body_callback);
227 curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, http_curl_hdrs_callback);
228 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
229 curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1);
230 #endif
231
232 if ((!options) || (1 > zend_hash_num_elements(options))) {
233 return;
234 }
235
236 /* proxy */
237 if (zoption = http_curl_getopt1(options, "proxyhost", IS_STRING)) {
238 curl_easy_setopt(ch, CURLOPT_PROXY, http_curl_copystr(Z_STRVAL_P(zoption)));
239 /* port */
240 if (zoption = http_curl_getopt1(options, "proxyport", IS_LONG)) {
241 curl_easy_setopt(ch, CURLOPT_PROXYPORT, Z_LVAL_P(zoption));
242 }
243 /* user:pass */
244 if (zoption = http_curl_getopt1(options, "proxyauth", IS_STRING)) {
245 curl_easy_setopt(ch, CURLOPT_PROXYUSERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
246 }
247 #if LIBCURL_VERSION_NUM >= 0x070a07
248 /* auth method */
249 if (zoption = http_curl_getopt1(options, "proxyauthtype", IS_LONG)) {
250 curl_easy_setopt(ch, CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
251 }
252 #endif
253 }
254
255 /* outgoing interface */
256 if (zoption = http_curl_getopt1(options, "interface", IS_STRING)) {
257 curl_easy_setopt(ch, CURLOPT_INTERFACE, http_curl_copystr(Z_STRVAL_P(zoption)));
258 }
259
260 /* another port */
261 if (zoption = http_curl_getopt1(options, "port", IS_LONG)) {
262 curl_easy_setopt(ch, CURLOPT_PORT, Z_LVAL_P(zoption));
263 }
264
265 /* auth */
266 if (zoption = http_curl_getopt1(options, "httpauth", IS_STRING)) {
267 curl_easy_setopt(ch, CURLOPT_USERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
268 }
269 #if LIBCURL_VERSION_NUM >= 0x070a06
270 if (zoption = http_curl_getopt1(options, "httpauthtype", IS_LONG)) {
271 curl_easy_setopt(ch, CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
272 }
273 #endif
274
275 /* compress, empty string enables deflate and gzip */
276 if (zoption = http_curl_getopt2(options, "compress", IS_LONG, IS_BOOL)) {
277 if (Z_LVAL_P(zoption)) {
278 curl_easy_setopt(ch, CURLOPT_ENCODING, "");
279 }
280 }
281
282 /* redirects, defaults to 0 */
283 if (zoption = http_curl_getopt1(options, "redirect", IS_LONG)) {
284 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
285 curl_easy_setopt(ch, CURLOPT_MAXREDIRS, Z_LVAL_P(zoption));
286 if (zoption = http_curl_getopt2(options, "unrestrictedauth", IS_LONG, IS_BOOL)) {
287 curl_easy_setopt(ch, CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
288 }
289 } else {
290 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 0);
291 }
292
293 /* referer */
294 if (zoption = http_curl_getopt1(options, "referer", IS_STRING)) {
295 curl_easy_setopt(ch, CURLOPT_REFERER, http_curl_copystr(Z_STRVAL_P(zoption)));
296 }
297
298 /* useragent, default "PECL::HTTP/version (PHP/version)" */
299 if (zoption = http_curl_getopt1(options, "useragent", IS_STRING)) {
300 curl_easy_setopt(ch, CURLOPT_USERAGENT, http_curl_copystr(Z_STRVAL_P(zoption)));
301 } else {
302 curl_easy_setopt(ch, CURLOPT_USERAGENT,
303 "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")");
304 }
305
306 /* additional headers, array('name' => 'value') */
307 if (zoption = http_curl_getopt1(options, "headers", IS_ARRAY)) {
308 char *header_key;
309 long header_idx;
310 struct curl_slist *headers = NULL;
311
312 FOREACH_KEY(zoption, header_key, header_idx) {
313 if (header_key) {
314 zval **header_val;
315 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &header_val)) {
316 char header[1024] = {0};
317 snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_PP(header_val));
318 headers = curl_slist_append(headers, http_curl_copystr(header));
319 }
320
321 /* reset */
322 header_key = NULL;
323 }
324 }
325
326 if (headers) {
327 curl_easy_setopt(ch, CURLOPT_HTTPHEADER, headers);
328 }
329 }
330
331 /* cookies, array('name' => 'value') */
332 if (zoption = http_curl_getopt1(options, "cookies", IS_ARRAY)) {
333 char *cookie_key = NULL;
334 long cookie_idx = 0;
335 smart_str qstr = {0};
336
337 FOREACH_KEY(zoption, cookie_key, cookie_idx) {
338 if (cookie_key) {
339 zval **cookie_val;
340 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &cookie_val)) {
341 smart_str_appends(&qstr, cookie_key);
342 smart_str_appendl(&qstr, "=", 1);
343 smart_str_appendl(&qstr, Z_STRVAL_PP(cookie_val), Z_STRLEN_PP(cookie_val));
344 smart_str_appendl(&qstr, "; ", 2);
345 }
346
347 /* reset */
348 cookie_key = NULL;
349 }
350 }
351 smart_str_0(&qstr);
352
353 if (qstr.c) {
354 curl_easy_setopt(ch, CURLOPT_COOKIE, http_curl_copystr(qstr.c));
355 efree(qstr.c);
356 }
357 }
358
359 /* cookiestore */
360 if (zoption = http_curl_getopt1(options, "cookiestore", IS_STRING)) {
361 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, http_curl_copystr(Z_STRVAL_P(zoption)));
362 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, http_curl_copystr(Z_STRVAL_P(zoption)));
363 }
364
365 /* resume */
366 if (zoption = http_curl_getopt1(options, "resume", IS_LONG)) {
367 range_req = 1;
368 curl_easy_setopt(ch, CURLOPT_RESUME_FROM, Z_LVAL_P(zoption));
369 }
370
371 /* maxfilesize */
372 if (zoption = http_curl_getopt1(options, "maxfilesize", IS_LONG)) {
373 curl_easy_setopt(ch, CURLOPT_MAXFILESIZE, Z_LVAL_P(zoption));
374 }
375
376 /* lastmodified */
377 if (zoption = http_curl_getopt1(options, "lastmodified", IS_LONG)) {
378 curl_easy_setopt(ch, CURLOPT_TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE);
379 curl_easy_setopt(ch, CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
380 }
381
382 /* timeout */
383 if (zoption = http_curl_getopt1(options, "timeout", IS_LONG)) {
384 curl_easy_setopt(ch, CURLOPT_TIMEOUT, Z_LVAL_P(zoption));
385 }
386
387 /* connecttimeout */
388 if (zoption = http_curl_getopt1(options, "connecttimeout", IS_LONG)) {
389 curl_easy_setopt(ch, CURLOPT_CONNECTTIMEOUT, Z_LVAL_P(zoption));
390 }
391 }
392 /* }}} */
393
394 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
395 static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
396 {
397 zval array;
398 Z_ARRVAL(array) = info;
399
400 #define HTTP_CURL_INFO(I) HTTP_CURL_INFO_EX(I, I)
401 #define HTTP_CURL_INFO_EX(I, X) \
402 switch (CURLINFO_ ##I & ~CURLINFO_MASK) \
403 { \
404 case CURLINFO_STRING: \
405 { \
406 char *c; \
407 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &c)) { \
408 add_assoc_string(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), c ? c : "", 1); \
409 } \
410 } \
411 break; \
412 \
413 case CURLINFO_DOUBLE: \
414 { \
415 double d; \
416 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &d)) { \
417 add_assoc_double(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), d); \
418 } \
419 } \
420 break; \
421 \
422 case CURLINFO_LONG: \
423 { \
424 long l; \
425 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &l)) { \
426 add_assoc_long(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), l); \
427 } \
428 } \
429 break; \
430 }
431
432 HTTP_CURL_INFO(EFFECTIVE_URL);
433
434 #if LIBCURL_VERSION_NUM >= 0x070a07
435 HTTP_CURL_INFO(RESPONSE_CODE);
436 #else
437 HTTP_CURL_INFO_EX(HTTP_CODE, RESPONSE_CODE);
438 #endif
439 HTTP_CURL_INFO(HTTP_CONNECTCODE);
440
441 #if LIBCURL_VERSION_NUM >= 0x070500
442 HTTP_CURL_INFO(FILETIME);
443 #endif
444 HTTP_CURL_INFO(TOTAL_TIME);
445 HTTP_CURL_INFO(NAMELOOKUP_TIME);
446 HTTP_CURL_INFO(CONNECT_TIME);
447 HTTP_CURL_INFO(PRETRANSFER_TIME);
448 HTTP_CURL_INFO(STARTTRANSFER_TIME);
449 #if LIBCURL_VERSION_NUM >= 0x070907
450 HTTP_CURL_INFO(REDIRECT_TIME);
451 HTTP_CURL_INFO(REDIRECT_COUNT);
452 #endif
453
454 HTTP_CURL_INFO(SIZE_UPLOAD);
455 HTTP_CURL_INFO(SIZE_DOWNLOAD);
456 HTTP_CURL_INFO(SPEED_DOWNLOAD);
457 HTTP_CURL_INFO(SPEED_UPLOAD);
458
459 HTTP_CURL_INFO(HEADER_SIZE);
460 HTTP_CURL_INFO(REQUEST_SIZE);
461
462 HTTP_CURL_INFO(SSL_VERIFYRESULT);
463 #if LIBCURL_VERSION_NUM >= 0x070c03
464 /*HTTP_CURL_INFO(SSL_ENGINES);
465 todo: CURLINFO_SLIST */
466 #endif
467
468 HTTP_CURL_INFO(CONTENT_LENGTH_DOWNLOAD);
469 HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD);
470 HTTP_CURL_INFO(CONTENT_TYPE);
471
472 #if LIBCURL_VERSION_NUM >= 0x070a03
473 /*HTTP_CURL_INFO(PRIVATE);*/
474 #endif
475
476 #if LIBCURL_VERSION_NUM >= 0x070a08
477 HTTP_CURL_INFO(HTTPAUTH_AVAIL);
478 HTTP_CURL_INFO(PROXYAUTH_AVAIL);
479 #endif
480
481 #if LIBCURL_VERSION_NUM >= 0x070c02
482 /*HTTP_CURL_INFO(OS_ERRNO);*/
483 #endif
484
485 #if LIBCURL_VERSION_NUM >= 0x070c03
486 HTTP_CURL_INFO(NUM_CONNECTS);
487 #endif
488 }
489 /* }}} */
490
491 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
492 PHP_HTTP_API STATUS _http_get_ex(CURL *ch, const char *URL, HashTable *options,
493 HashTable *info, char **data, size_t *data_len TSRMLS_DC)
494 {
495 zend_bool clean_curl = 0;
496
497 http_curl_startup(ch, clean_curl, URL, options);
498 curl_easy_setopt(ch, CURLOPT_HTTPGET, 1);
499 http_curl_perform(ch, clean_curl);
500
501 if (info) {
502 http_curl_getinfo(ch, info);
503 }
504
505 http_curl_copybuf(data, data_len);
506 http_curl_cleanup(ch, clean_curl);
507
508 return SUCCESS;
509 }
510
511 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
512 PHP_HTTP_API STATUS _http_head_ex(CURL *ch, const char *URL, HashTable *options,
513 HashTable *info, char **data, size_t *data_len TSRMLS_DC)
514 {
515 zend_bool clean_curl = 0;
516
517 http_curl_startup(ch, clean_curl, URL, options);
518 curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
519 http_curl_perform(ch, clean_curl);
520
521 if (info) {
522 http_curl_getinfo(ch, info);
523 }
524
525 http_curl_copybuf(data, data_len);
526 http_curl_cleanup(ch, clean_curl);
527
528 return SUCCESS;
529 }
530
531 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
532 PHP_HTTP_API STATUS _http_post_data_ex(CURL *ch, const char *URL, char *postdata,
533 size_t postdata_len, HashTable *options, HashTable *info, char **data,
534 size_t *data_len TSRMLS_DC)
535 {
536 zend_bool clean_curl = 0;
537
538 http_curl_startup(ch, clean_curl, URL, options);
539 curl_easy_setopt(ch, CURLOPT_POST, 1);
540 curl_easy_setopt(ch, CURLOPT_POSTFIELDS, postdata);
541 curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, postdata_len);
542 http_curl_perform(ch, clean_curl);
543
544 if (info) {
545 http_curl_getinfo(ch, info);
546 }
547
548 http_curl_copybuf(data, data_len);
549 http_curl_cleanup(ch, clean_curl);
550
551 return SUCCESS;
552 }
553 /* }}} */
554
555 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
556 PHP_HTTP_API STATUS _http_post_array_ex(CURL *ch, const char *URL, HashTable *postarray,
557 HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC)
558 {
559 smart_str qstr = {0};
560 STATUS status;
561
562 HTTP_URL_ARGSEP_OVERRIDE;
563 if (php_url_encode_hash_ex(postarray, &qstr, NULL,0,NULL,0,NULL,0,NULL TSRMLS_CC) != SUCCESS) {
564 if (qstr.c) {
565 efree(qstr.c);
566 }
567 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not encode post data");
568 HTTP_URL_ARGSEP_RESTORE;
569 return FAILURE;
570 }
571 smart_str_0(&qstr);
572 HTTP_URL_ARGSEP_RESTORE;
573
574 status = http_post_data_ex(ch, URL, qstr.c, qstr.len, options, info, data, data_len);
575
576 if (qstr.c) {
577 efree(qstr.c);
578 }
579 return status;
580 }
581 /* }}} */
582
583 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, char **, size_t *) */
584 PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL,
585 struct curl_httppost *curldata, HashTable *options, HashTable *info,
586 char **data, size_t *data_len TSRMLS_DC)
587 {
588 zend_bool clean_curl = 0;
589
590 http_curl_startup(ch, clean_curl, URL, options);
591 curl_easy_setopt(ch, CURLOPT_POST, 1);
592 curl_easy_setopt(ch, CURLOPT_HTTPPOST, curldata);
593 http_curl_perform(ch, clean_curl);
594
595 if (info) {
596 http_curl_getinfo(ch, info);
597 }
598
599 http_curl_copybuf(data, data_len);
600 http_curl_cleanup(ch, clean_curl);
601
602 return SUCCESS;
603 }
604 /* }}} */
605
606 /*
607 * Local variables:
608 * tab-width: 4
609 * c-basic-offset: 4
610 * End:
611 * vim600: noet sw=4 ts=4 fdm=marker
612 * vim<600: noet sw=4 ts=4
613 */
614