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