* ditch some inline functions and replace them with a macro
[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
197 /* standard options */
198 curl_easy_setopt(ch, CURLOPT_URL, url);
199 curl_easy_setopt(ch, CURLOPT_HEADER, 0);
200 curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
201 curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1);
202 curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, http_curl_body_callback);
203 curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, http_curl_hdrs_callback);
204 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
205 curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1);
206 #endif
207
208 if ((!options) || (1 > zend_hash_num_elements(options))) {
209 return;
210 }
211
212 /* redirects, defaults to 0 */
213 if (zoption = http_curl_getopt1(options, "redirect", IS_LONG)) {
214 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
215 curl_easy_setopt(ch, CURLOPT_MAXREDIRS, Z_LVAL_P(zoption));
216 if (zoption = http_curl_getopt2(options, "unrestrictedauth", IS_LONG, IS_BOOL)) {
217 curl_easy_setopt(ch, CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
218 }
219 } else {
220 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 0);
221 }
222
223 /* proxy */
224 if (zoption = http_curl_getopt1(options, "proxyhost", IS_STRING)) {
225 curl_easy_setopt(ch, CURLOPT_PROXY, http_curl_copystr(Z_STRVAL_P(zoption)));
226 /* port */
227 if (zoption = http_curl_getopt1(options, "proxyport", IS_LONG)) {
228 curl_easy_setopt(ch, CURLOPT_PROXYPORT, Z_LVAL_P(zoption));
229 }
230 /* user:pass */
231 if (zoption = http_curl_getopt1(options, "proxyauth", IS_STRING)) {
232 curl_easy_setopt(ch, CURLOPT_PROXYUSERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
233 }
234 #if LIBCURL_VERSION_NUM > 0x070a06
235 /* auth method */
236 if (zoption = http_curl_getopt1(options, "proxyauthtype", IS_LONG)) {
237 curl_easy_setopt(ch, CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
238 }
239 #endif
240 }
241
242 /* auth */
243 if (zoption = http_curl_getopt1(options, "httpauth", IS_STRING)) {
244 curl_easy_setopt(ch, CURLOPT_USERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
245 }
246 #if LIBCURL_VERSION_NUM > 0x070a05
247 if (zoption = http_curl_getopt1(options, "httpauthtype", IS_LONG)) {
248 curl_easy_setopt(ch, CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
249 }
250 #endif
251
252 /* compress, enabled by default (empty string enables deflate and gzip) */
253 if (zoption = http_curl_getopt2(options, "compress", IS_LONG, IS_BOOL)) {
254 if (Z_LVAL_P(zoption)) {
255 curl_easy_setopt(ch, CURLOPT_ENCODING, "");
256 }
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 /* referer */
265 if (zoption = http_curl_getopt1(options, "referer", IS_STRING)) {
266 curl_easy_setopt(ch, CURLOPT_REFERER, http_curl_copystr(Z_STRVAL_P(zoption)));
267 }
268
269 /* useragent, default "PECL::HTTP/version (PHP/version)" */
270 if (zoption = http_curl_getopt1(options, "useragent", IS_STRING)) {
271 curl_easy_setopt(ch, CURLOPT_USERAGENT, http_curl_copystr(Z_STRVAL_P(zoption)));
272 } else {
273 curl_easy_setopt(ch, CURLOPT_USERAGENT,
274 "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")");
275 }
276
277 /* cookies, array('name' => 'value') */
278 if (zoption = http_curl_getopt1(options, "cookies", IS_ARRAY)) {
279 char *cookie_key = NULL;
280 long cookie_idx = 0;
281 smart_str qstr = {0};
282
283 FOREACH_KEY(zoption, cookie_key, cookie_idx) {
284 if (cookie_key) {
285 zval **cookie_val;
286 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &cookie_val)) {
287 smart_str_appends(&qstr, cookie_key);
288 smart_str_appendl(&qstr, "=", 1);
289 smart_str_appendl(&qstr, Z_STRVAL_PP(cookie_val), Z_STRLEN_PP(cookie_val));
290 smart_str_appendl(&qstr, "; ", 2);
291 }
292
293 /* reset */
294 cookie_key = NULL;
295 }
296 }
297 smart_str_0(&qstr);
298
299 if (qstr.c) {
300 curl_easy_setopt(ch, CURLOPT_COOKIE, http_curl_copystr(qstr.c));
301 efree(qstr.c);
302 }
303 }
304
305 /* cookiestore */
306 if (zoption = http_curl_getopt1(options, "cookiestore", IS_STRING)) {
307 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, http_curl_copystr(Z_STRVAL_P(zoption)));
308 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, http_curl_copystr(Z_STRVAL_P(zoption)));
309 }
310
311 /* additional headers, array('name' => 'value') */
312 if (zoption = http_curl_getopt1(options, "headers", IS_ARRAY)) {
313 char *header_key;
314 long header_idx;
315 struct curl_slist *headers = NULL;
316
317 FOREACH_KEY(zoption, header_key, header_idx) {
318 if (header_key) {
319 zval **header_val;
320 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &header_val)) {
321 char header[1024] = {0};
322 snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_PP(header_val));
323 headers = curl_slist_append(headers, http_curl_copystr(header));
324 }
325
326 /* reset */
327 header_key = NULL;
328 }
329 }
330
331 if (headers) {
332 curl_easy_setopt(ch, CURLOPT_HTTPHEADER, headers);
333 }
334 }
335 }
336 /* }}} */
337
338 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
339 static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
340 {
341 zval array;
342 Z_ARRVAL(array) = info;
343
344 #define HTTP_CURL_INFO(I) HTTP_CURL_INFO_EX(I, I)
345 #define HTTP_CURL_INFO_EX(I, X) \
346 switch (CURLINFO_ ##I & ~CURLINFO_MASK) \
347 { \
348 case CURLINFO_STRING: \
349 { \
350 char *c; \
351 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &c)) { \
352 add_assoc_string(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), c ? c : "", 1); \
353 } \
354 } \
355 break; \
356 \
357 case CURLINFO_DOUBLE: \
358 { \
359 double d; \
360 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &d)) { \
361 add_assoc_double(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), d); \
362 } \
363 } \
364 break; \
365 \
366 case CURLINFO_LONG: \
367 { \
368 long l; \
369 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &l)) { \
370 add_assoc_long(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), l); \
371 } \
372 } \
373 break; \
374 } \
375
376 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
377 HTTP_CURL_INFO(EFFECTIVE_URL);
378 #if LIBCURL_VERSION_NUM > 0x070a06
379 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
380 HTTP_CURL_INFO(RESPONSE_CODE);
381 #else
382 HTTP_CURL_INFO_EX(HTTP_CODE, RESPONSE_CODE);
383 #endif
384 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
385 HTTP_CURL_INFO(TOTAL_TIME);
386 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
387 HTTP_CURL_INFO(NAMELOOKUP_TIME);
388 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
389 HTTP_CURL_INFO(CONNECT_TIME);
390 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
391 HTTP_CURL_INFO(PRETRANSFER_TIME);
392 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
393 HTTP_CURL_INFO(SIZE_UPLOAD);
394 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
395 HTTP_CURL_INFO(SIZE_DOWNLOAD);
396 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
397 HTTP_CURL_INFO(SPEED_DOWNLOAD);
398 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
399 HTTP_CURL_INFO(SPEED_UPLOAD);
400 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
401 HTTP_CURL_INFO(HEADER_SIZE);
402 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
403 HTTP_CURL_INFO(REQUEST_SIZE);
404 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
405 HTTP_CURL_INFO(SSL_VERIFYRESULT);
406 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
407 HTTP_CURL_INFO(FILETIME);
408 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
409 HTTP_CURL_INFO(CONTENT_LENGTH_DOWNLOAD);
410 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
411 HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD);
412 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
413 HTTP_CURL_INFO(STARTTRANSFER_TIME);
414 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
415 HTTP_CURL_INFO(CONTENT_TYPE);
416 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
417 HTTP_CURL_INFO(REDIRECT_TIME);
418 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
419 HTTP_CURL_INFO(REDIRECT_COUNT);
420 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
421 HTTP_CURL_INFO(PRIVATE);
422 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
423 HTTP_CURL_INFO(HTTP_CONNECTCODE);
424 #if LIBCURL_VERSION_NUM > 0x070a07
425 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
426 HTTP_CURL_INFO(HTTPAUTH_AVAIL);
427 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
428 HTTP_CURL_INFO(PROXYAUTH_AVAIL);
429 #endif
430 }
431 /* }}} */
432
433 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
434 PHP_HTTP_API STATUS _http_get_ex(CURL *ch, const char *URL, HashTable *options,
435 HashTable *info, char **data, size_t *data_len TSRMLS_DC)
436 {
437 zend_bool clean_curl = 0;
438
439 http_curl_startup(ch, clean_curl, URL, options);
440 curl_easy_setopt(ch, CURLOPT_NOBODY, 0);
441 curl_easy_setopt(ch, CURLOPT_POST, 0);
442
443 if (CURLE_OK != curl_easy_perform(ch)) {
444 http_curl_cleanup(ch, clean_curl);
445 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
446 return FAILURE;
447 }
448
449 if (info) {
450 http_curl_getinfo(ch, info);
451 }
452
453 http_curl_copybuf(data, data_len);
454 http_curl_cleanup(ch, clean_curl);
455
456 return SUCCESS;
457 }
458
459 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
460 PHP_HTTP_API STATUS _http_head_ex(CURL *ch, const char *URL, HashTable *options,
461 HashTable *info, char **data, size_t *data_len TSRMLS_DC)
462 {
463 zend_bool clean_curl = 0;
464
465 http_curl_startup(ch, clean_curl, URL, options);
466 curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
467 curl_easy_setopt(ch, CURLOPT_POST, 0);
468
469 if (CURLE_OK != curl_easy_perform(ch)) {
470 http_curl_cleanup(ch, clean_curl);
471 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
472 return FAILURE;
473 }
474
475 if (info) {
476 http_curl_getinfo(ch, info);
477 }
478
479 http_curl_copybuf(data, data_len);
480 http_curl_cleanup(ch, clean_curl);
481
482 return SUCCESS;
483 }
484
485 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
486 PHP_HTTP_API STATUS _http_post_data_ex(CURL *ch, const char *URL, char *postdata,
487 size_t postdata_len, HashTable *options, HashTable *info, char **data,
488 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_POST, 1);
494 curl_easy_setopt(ch, CURLOPT_POSTFIELDS, postdata);
495 curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, postdata_len);
496
497 if (CURLE_OK != curl_easy_perform(ch)) {
498 http_curl_cleanup(ch, clean_curl);
499 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
500 return FAILURE;
501 }
502
503 if (info) {
504 http_curl_getinfo(ch, info);
505 }
506
507 http_curl_copybuf(data, data_len);
508 http_curl_cleanup(ch, clean_curl);
509
510 return SUCCESS;
511 }
512 /* }}} */
513
514 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
515 PHP_HTTP_API STATUS _http_post_array_ex(CURL *ch, const char *URL, HashTable *postarray,
516 HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC)
517 {
518 smart_str qstr = {0};
519 STATUS status;
520
521 HTTP_URL_ARGSEP_OVERRIDE;
522 if (php_url_encode_hash_ex(postarray, &qstr, NULL,0,NULL,0,NULL,0,NULL TSRMLS_CC) != SUCCESS) {
523 if (qstr.c) {
524 efree(qstr.c);
525 }
526 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not encode post data");
527 HTTP_URL_ARGSEP_RESTORE;
528 return FAILURE;
529 }
530 smart_str_0(&qstr);
531 HTTP_URL_ARGSEP_RESTORE;
532
533 status = http_post_data_ex(ch, URL, qstr.c, qstr.len, options, info, data, data_len);
534
535 if (qstr.c) {
536 efree(qstr.c);
537 }
538 return status;
539 }
540 /* }}} */
541
542 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, char **, size_t *) */
543 PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL,
544 struct curl_httppost *curldata, HashTable *options, HashTable *info,
545 char **data, size_t *data_len TSRMLS_DC)
546 {
547 zend_bool clean_curl = 0;
548
549 http_curl_startup(ch, clean_curl, URL, options);
550 curl_easy_setopt(ch, CURLOPT_POST, 1);
551 curl_easy_setopt(ch, CURLOPT_HTTPPOST, curldata);
552
553 if (CURLE_OK != curl_easy_perform(ch)) {
554 http_curl_cleanup(ch, clean_curl);
555 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
556 return FAILURE;
557 }
558
559 if (info) {
560 http_curl_getinfo(ch, info);
561 }
562
563 http_curl_copybuf(data, data_len);
564 http_curl_cleanup(ch, clean_curl);
565
566 return SUCCESS;
567 }
568 /* }}} */
569
570 /*
571 * Local variables:
572 * tab-width: 4
573 * c-basic-offset: 4
574 * End:
575 * vim600: noet sw=4 ts=4 fdm=marker
576 * vim<600: noet sw=4 ts=4
577 */
578