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