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