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