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