- commonize some error messages
[m6w6/ext-http] / http_request_object.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
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22 #include "php.h"
23
24 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
25
26 #include "php_http_std_defs.h"
27 #include "php_http_request_object.h"
28 #include "php_http_request_api.h"
29 #include "php_http_request_pool_api.h"
30 #include "php_http.h"
31 #include "php_http_api.h"
32 #include "php_http_url_api.h"
33 #include "php_http_message_api.h"
34 #include "php_http_message_object.h"
35 #include "php_http_exception_object.h"
36
37 #include "missing.h"
38
39 #ifdef PHP_WIN32
40 # include <winsock2.h>
41 #endif
42 #include <curl/curl.h>
43
44 ZEND_EXTERN_MODULE_GLOBALS(http);
45
46 #define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args)
47 #define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref)
48 #define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
49 #define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
50
51 HTTP_EMPTY_ARGS(__destruct, 0);
52 HTTP_BEGIN_ARGS(__construct, 0, 0)
53 HTTP_ARG_VAL(url, 0)
54 HTTP_ARG_VAL(method, 0)
55 HTTP_END_ARGS;
56
57 HTTP_EMPTY_ARGS(getOptions, 0);
58 HTTP_BEGIN_ARGS(setOptions, 0, 0)
59 HTTP_ARG_VAL(options, 0)
60 HTTP_END_ARGS;
61
62 HTTP_EMPTY_ARGS(getSslOptions, 0);
63 HTTP_BEGIN_ARGS(setSslOptions, 0, 0)
64 HTTP_ARG_VAL(ssl_options, 0)
65 HTTP_END_ARGS;
66
67 HTTP_EMPTY_ARGS(getHeaders, 0);
68 HTTP_BEGIN_ARGS(setHeaders, 0, 0)
69 HTTP_ARG_VAL(headers, 0)
70 HTTP_END_ARGS;
71
72 HTTP_BEGIN_ARGS(addHeaders, 0, 1)
73 HTTP_ARG_VAL(headers, 0)
74 HTTP_END_ARGS;
75
76 HTTP_EMPTY_ARGS(getCookies, 0);
77 HTTP_BEGIN_ARGS(setCookies, 0, 0)
78 HTTP_ARG_VAL(cookies, 0)
79 HTTP_END_ARGS;
80
81 HTTP_BEGIN_ARGS(addCookies, 0, 1)
82 HTTP_ARG_VAL(cookies, 0)
83 HTTP_END_ARGS;
84
85 HTTP_EMPTY_ARGS(getUrl, 0);
86 HTTP_BEGIN_ARGS(setUrl, 0, 1)
87 HTTP_ARG_VAL(url, 0)
88 HTTP_END_ARGS;
89
90 HTTP_EMPTY_ARGS(getMethod, 0);
91 HTTP_BEGIN_ARGS(setMethod, 0, 1)
92 HTTP_ARG_VAL(request_method, 0)
93 HTTP_END_ARGS;
94
95 HTTP_EMPTY_ARGS(getContentType, 0);
96 HTTP_BEGIN_ARGS(setContentType, 0, 1)
97 HTTP_ARG_VAL(content_type, 0)
98 HTTP_END_ARGS;
99
100 HTTP_EMPTY_ARGS(getQueryData, 0);
101 HTTP_BEGIN_ARGS(setQueryData, 0, 0)
102 HTTP_ARG_VAL(query_data, 0)
103 HTTP_END_ARGS;
104
105 HTTP_BEGIN_ARGS(addQueryData, 0, 1)
106 HTTP_ARG_VAL(query_data, 0)
107 HTTP_END_ARGS;
108
109 HTTP_EMPTY_ARGS(getPostFields, 0);
110 HTTP_BEGIN_ARGS(setPostFields, 0, 0)
111 HTTP_ARG_VAL(post_fields, 0)
112 HTTP_END_ARGS;
113
114 HTTP_BEGIN_ARGS(addPostFields, 0, 1)
115 HTTP_ARG_VAL(post_fields, 0)
116 HTTP_END_ARGS;
117
118 HTTP_EMPTY_ARGS(getPostFiles, 0);
119 HTTP_BEGIN_ARGS(setPostFiles, 0, 0)
120 HTTP_ARG_VAL(post_files, 0)
121 HTTP_END_ARGS;
122
123 HTTP_BEGIN_ARGS(addPostFile, 0, 2)
124 HTTP_ARG_VAL(formname, 0)
125 HTTP_ARG_VAL(filename, 0)
126 HTTP_ARG_VAL(content_type, 0)
127 HTTP_END_ARGS;
128
129 HTTP_EMPTY_ARGS(getRawPostData, 0);
130 HTTP_BEGIN_ARGS(setRawPostData, 0, 0)
131 HTTP_ARG_VAL(raw_post_data, 0)
132 HTTP_END_ARGS;
133
134 HTTP_BEGIN_ARGS(addRawPostData, 0, 1)
135 HTTP_ARG_VAL(raw_post_data, 0)
136 HTTP_END_ARGS;
137
138 HTTP_EMPTY_ARGS(getPutFile, 0);
139 HTTP_BEGIN_ARGS(setPutFile, 0, 0)
140 HTTP_ARG_VAL(filename, 0)
141 HTTP_END_ARGS;
142
143 HTTP_EMPTY_ARGS(getResponseData, 0);
144 HTTP_BEGIN_ARGS(getResponseHeader, 0, 0)
145 HTTP_ARG_VAL(name, 0)
146 HTTP_END_ARGS;
147
148 HTTP_BEGIN_ARGS(getResponseCookie, 0, 0)
149 HTTP_ARG_VAL(name, 0)
150 HTTP_END_ARGS;
151
152 HTTP_EMPTY_ARGS(getResponseBody, 0);
153 HTTP_EMPTY_ARGS(getResponseCode, 0);
154 HTTP_BEGIN_ARGS(getResponseInfo, 0, 0)
155 HTTP_ARG_VAL(name, 0)
156 HTTP_END_ARGS;
157
158 HTTP_EMPTY_ARGS(getResponseMessage, 1);
159 HTTP_EMPTY_ARGS(getRequestMessage, 1);
160 HTTP_EMPTY_ARGS(getHistory, 1);
161 HTTP_EMPTY_ARGS(clearHistory, 0);
162 HTTP_EMPTY_ARGS(send, 1);
163
164 HTTP_BEGIN_ARGS(get, 0, 1)
165 HTTP_ARG_VAL(url, 0)
166 HTTP_ARG_VAL(options, 0)
167 HTTP_ARG_VAL(info, 1)
168 HTTP_END_ARGS;
169
170 HTTP_BEGIN_ARGS(head, 0, 1)
171 HTTP_ARG_VAL(url, 0)
172 HTTP_ARG_VAL(options, 0)
173 HTTP_ARG_VAL(info, 1)
174 HTTP_END_ARGS;
175
176 HTTP_BEGIN_ARGS(postData, 0, 2)
177 HTTP_ARG_VAL(url, 0)
178 HTTP_ARG_VAL(data, 0)
179 HTTP_ARG_VAL(options, 0)
180 HTTP_ARG_VAL(info, 1)
181 HTTP_END_ARGS;
182
183 HTTP_BEGIN_ARGS(postFields, 0, 2)
184 HTTP_ARG_VAL(url, 0)
185 HTTP_ARG_VAL(data, 0)
186 HTTP_ARG_VAL(options, 0)
187 HTTP_ARG_VAL(info, 1)
188 HTTP_END_ARGS;
189
190 HTTP_BEGIN_ARGS(putFile, 0, 2)
191 HTTP_ARG_VAL(url, 0)
192 HTTP_ARG_VAL(file, 0)
193 HTTP_ARG_VAL(options, 0)
194 HTTP_ARG_VAL(info, 1)
195 HTTP_END_ARGS;
196
197 HTTP_BEGIN_ARGS(putStream, 0, 2)
198 HTTP_ARG_VAL(url, 0)
199 HTTP_ARG_VAL(stream, 0)
200 HTTP_ARG_VAL(options, 0)
201 HTTP_ARG_VAL(info, 1)
202 HTTP_END_ARGS;
203
204 HTTP_BEGIN_ARGS(methodRegister, 0, 1)
205 HTTP_ARG_VAL(method_name, 0)
206 HTTP_END_ARGS;
207
208 HTTP_BEGIN_ARGS(methodUnregister, 0, 1)
209 HTTP_ARG_VAL(method, 0)
210 HTTP_END_ARGS;
211
212 HTTP_BEGIN_ARGS(methodName, 0, 1)
213 HTTP_ARG_VAL(method_id, 0)
214 HTTP_END_ARGS;
215
216 HTTP_BEGIN_ARGS(methodExists, 0, 1)
217 HTTP_ARG_VAL(method, 0)
218 HTTP_END_ARGS;
219
220 #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C)
221 static inline void _http_request_object_declare_default_properties(TSRMLS_D);
222
223 zend_class_entry *http_request_object_ce;
224 zend_function_entry http_request_object_fe[] = {
225 HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
226 HTTP_REQUEST_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
227
228 HTTP_REQUEST_ME(setOptions, ZEND_ACC_PUBLIC)
229 HTTP_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC)
230 HTTP_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC)
231 HTTP_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC)
232
233 HTTP_REQUEST_ME(addHeaders, ZEND_ACC_PUBLIC)
234 HTTP_REQUEST_ME(getHeaders, ZEND_ACC_PUBLIC)
235 HTTP_REQUEST_ME(setHeaders, ZEND_ACC_PUBLIC)
236
237 HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC)
238 HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC)
239 HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC)
240
241 HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC)
242 HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC)
243
244 HTTP_REQUEST_ME(setUrl, ZEND_ACC_PUBLIC)
245 HTTP_REQUEST_ME(getUrl, ZEND_ACC_PUBLIC)
246
247 HTTP_REQUEST_ME(setContentType, ZEND_ACC_PUBLIC)
248 HTTP_REQUEST_ME(getContentType, ZEND_ACC_PUBLIC)
249
250 HTTP_REQUEST_ME(setQueryData, ZEND_ACC_PUBLIC)
251 HTTP_REQUEST_ME(getQueryData, ZEND_ACC_PUBLIC)
252 HTTP_REQUEST_ME(addQueryData, ZEND_ACC_PUBLIC)
253
254 HTTP_REQUEST_ME(setPostFields, ZEND_ACC_PUBLIC)
255 HTTP_REQUEST_ME(getPostFields, ZEND_ACC_PUBLIC)
256 HTTP_REQUEST_ME(addPostFields, ZEND_ACC_PUBLIC)
257
258 HTTP_REQUEST_ME(setRawPostData, ZEND_ACC_PUBLIC)
259 HTTP_REQUEST_ME(getRawPostData, ZEND_ACC_PUBLIC)
260 HTTP_REQUEST_ME(addRawPostData, ZEND_ACC_PUBLIC)
261
262 HTTP_REQUEST_ME(setPostFiles, ZEND_ACC_PUBLIC)
263 HTTP_REQUEST_ME(addPostFile, ZEND_ACC_PUBLIC)
264 HTTP_REQUEST_ME(getPostFiles, ZEND_ACC_PUBLIC)
265
266 HTTP_REQUEST_ME(setPutFile, ZEND_ACC_PUBLIC)
267 HTTP_REQUEST_ME(getPutFile, ZEND_ACC_PUBLIC)
268
269 HTTP_REQUEST_ME(send, ZEND_ACC_PUBLIC)
270
271 HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
272 HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC)
273 HTTP_REQUEST_ME(getResponseCookie, ZEND_ACC_PUBLIC)
274 HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC)
275 HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC)
276 HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC)
277 HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC)
278 HTTP_REQUEST_ME(getRequestMessage, ZEND_ACC_PUBLIC)
279 HTTP_REQUEST_ME(getHistory, ZEND_ACC_PUBLIC)
280 HTTP_REQUEST_ME(clearHistory, ZEND_ACC_PUBLIC)
281
282 HTTP_REQUEST_ALIAS(get, http_get)
283 HTTP_REQUEST_ALIAS(head, http_head)
284 HTTP_REQUEST_ALIAS(postData, http_post_data)
285 HTTP_REQUEST_ALIAS(postFields, http_post_fields)
286 HTTP_REQUEST_ALIAS(putFile, http_put_file)
287 HTTP_REQUEST_ALIAS(putStream, http_put_stream)
288
289 HTTP_REQUEST_ALIAS(methodRegister, http_request_method_register)
290 HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
291 HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
292 HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
293
294 EMPTY_FUNCTION_ENTRY
295 };
296 static zend_object_handlers http_request_object_handlers;
297
298 void _http_request_object_init(INIT_FUNC_ARGS)
299 {
300 HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
301 }
302
303 zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
304 {
305 zend_object_value ov;
306 http_request_object *o;
307
308 o = ecalloc(1, sizeof(http_request_object));
309 o->zo.ce = ce;
310 o->ch = curl_easy_init();
311
312 phpstr_init(&o->history);
313 phpstr_init(&o->request);
314 phpstr_init_ex(&o->response, HTTP_CURLBUF_SIZE, 0);
315
316 ALLOC_HASHTABLE(OBJ_PROP(o));
317 zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
318 zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
319
320 ov.handle = putObject(http_request_object, o);
321 ov.handlers = &http_request_object_handlers;
322
323 return ov;
324 }
325
326 static inline void _http_request_object_declare_default_properties(TSRMLS_D)
327 {
328 zend_class_entry *ce = http_request_object_ce;
329
330 DCL_PROP_N(PROTECTED, options);
331 DCL_PROP_N(PROTECTED, responseInfo);
332 DCL_PROP_N(PROTECTED, responseData);
333 DCL_PROP_N(PROTECTED, responseCode);
334 DCL_PROP_N(PROTECTED, responseMessage);
335 DCL_PROP_N(PROTECTED, postFields);
336 DCL_PROP_N(PROTECTED, postFiles);
337
338 DCL_PROP(PROTECTED, long, method, HTTP_GET);
339
340 DCL_PROP(PROTECTED, string, url, "");
341 DCL_PROP(PROTECTED, string, contentType, "");
342 DCL_PROP(PROTECTED, string, rawPostData, "");
343 DCL_PROP(PROTECTED, string, queryData, "");
344 DCL_PROP(PROTECTED, string, putFile, "");
345
346 DCL_PROP(PUBLIC, bool, recordHistory, 1);
347
348 #ifndef WONKY
349 /*
350 * Request Method Constants
351 */
352 /* HTTP/1.1 */
353 DCL_CONST(long, "METH_GET", HTTP_GET);
354 DCL_CONST(long, "METH_HEAD", HTTP_HEAD);
355 DCL_CONST(long, "METH_POST", HTTP_POST);
356 DCL_CONST(long, "METH_PUT", HTTP_PUT);
357 DCL_CONST(long, "METH_DELETE", HTTP_DELETE);
358 DCL_CONST(long, "METH_OPTIONS", HTTP_OPTIONS);
359 DCL_CONST(long, "METH_TRACE", HTTP_TRACE);
360 DCL_CONST(long, "METH_CONNECT", HTTP_CONNECT);
361 /* WebDAV - RFC 2518 */
362 DCL_CONST(long, "METH_PROPFIND", HTTP_PROPFIND);
363 DCL_CONST(long, "METH_PROPPATCH", HTTP_PROPPATCH);
364 DCL_CONST(long, "METH_MKCOL", HTTP_MKCOL);
365 DCL_CONST(long, "METH_COPY", HTTP_COPY);
366 DCL_CONST(long, "METH_MOVE", HTTP_MOVE);
367 DCL_CONST(long, "METH_LOCK", HTTP_LOCK);
368 DCL_CONST(long, "METH_UNLOCK", HTTP_UNLOCK);
369 /* WebDAV Versioning - RFC 3253 */
370 DCL_CONST(long, "METH_VERSION_CONTROL", HTTP_VERSION_CONTROL);
371 DCL_CONST(long, "METH_REPORT", HTTP_REPORT);
372 DCL_CONST(long, "METH_CHECKOUT", HTTP_CHECKOUT);
373 DCL_CONST(long, "METH_CHECKIN", HTTP_CHECKIN);
374 DCL_CONST(long, "METH_UNCHECKOUT", HTTP_UNCHECKOUT);
375 DCL_CONST(long, "METH_MKWORKSPACE", HTTP_MKWORKSPACE);
376 DCL_CONST(long, "METH_UPDATE", HTTP_UPDATE);
377 DCL_CONST(long, "METH_LABEL", HTTP_LABEL);
378 DCL_CONST(long, "METH_MERGE", HTTP_MERGE);
379 DCL_CONST(long, "METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL);
380 DCL_CONST(long, "METH_MKACTIVITY", HTTP_MKACTIVITY);
381 /* WebDAV Access Control - RFC 3744 */
382 DCL_CONST(long, "METH_ACL", HTTP_ACL);
383
384 /*
385 * Auth Constants
386 */
387 # if LIBCURL_VERSION_NUM >= 0x070a05
388 DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC);
389 DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST);
390 DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM);
391 DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY);
392 # endif /* LIBCURL_VERSION_NUM */
393 #endif /* WONKY */
394 }
395
396 void _http_request_object_free(zend_object *object TSRMLS_DC)
397 {
398 http_request_object *o = (http_request_object *) object;
399
400 if (OBJ_PROP(o)) {
401 zend_hash_destroy(OBJ_PROP(o));
402 FREE_HASHTABLE(OBJ_PROP(o));
403 }
404 if (o->ch) {
405 /* avoid nasty segfaults with already cleaned up callbacks */
406 curl_easy_setopt(o->ch, CURLOPT_NOPROGRESS, 1);
407 curl_easy_setopt(o->ch, CURLOPT_PROGRESSFUNCTION, NULL);
408 curl_easy_setopt(o->ch, CURLOPT_VERBOSE, 0);
409 curl_easy_setopt(o->ch, CURLOPT_DEBUGFUNCTION, NULL);
410 curl_easy_cleanup(o->ch);
411 }
412 phpstr_dtor(&o->response);
413 phpstr_dtor(&o->request);
414 phpstr_dtor(&o->history);
415 efree(o);
416 }
417
418 STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC)
419 {
420 zval *meth, *URL;
421 char *request_uri;
422 STATUS status = SUCCESS;
423
424 if (!body) {
425 return FAILURE;
426 }
427 HTTP_CHECK_CURL_INIT(obj->ch, curl_easy_init(), return FAILURE);
428
429 URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url));
430 // HTTP_URI_MAXLEN+1 long char *
431 if (!(request_uri = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0))) {
432 return FAILURE;
433 }
434
435 meth = convert_to_type_ex(IS_LONG, GET_PROP(obj, method));
436 switch (Z_LVAL_P(meth))
437 {
438 case HTTP_GET:
439 case HTTP_HEAD:
440 body->type = -1;
441 body = NULL;
442 break;
443
444 case HTTP_PUT:
445 {
446 php_stream_statbuf ssb;
447 php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
448
449 if (stream && !php_stream_stat(stream, &ssb)) {
450 body->type = HTTP_REQUEST_BODY_UPLOADFILE;
451 body->data = stream;
452 body->size = ssb.sb.st_size;
453 } else {
454 status = FAILURE;
455 }
456 }
457 break;
458
459 case HTTP_POST:
460 default:
461 {
462 /* check for raw post data */
463 zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
464
465 if (Z_STRLEN_P(raw_data)) {
466 zval *ctype = convert_to_type_ex(IS_STRING, GET_PROP(obj, contentType));
467
468 if (Z_STRLEN_P(ctype)) {
469 zval **headers, *opts = GET_PROP(obj, options);
470
471 convert_to_array(opts);
472
473 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) {
474 zval **ct_header;
475
476 convert_to_array(*headers);
477 /* only override if not already set */
478 if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header)) {
479 add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
480 }
481 } else {
482 zval *headers;
483
484 MAKE_STD_ZVAL(headers);
485 array_init(headers);
486 add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
487 add_assoc_zval(opts, "headers", headers);
488 }
489 }
490
491 body->type = HTTP_REQUEST_BODY_CSTRING;
492 body->data = estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data));
493 body->size = Z_STRLEN_P(raw_data);
494 } else {
495 status = http_request_body_fill(body, Z_ARRVAL_P(GET_PROP(obj, postFields)), Z_ARRVAL_P(GET_PROP(obj, postFiles)));
496 }
497 }
498 break;
499 }
500
501 if (status == SUCCESS) {
502 zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
503
504 if (Z_STRLEN_P(qdata) && (strlen(request_uri) < HTTP_URI_MAXLEN)) {
505 if (!strchr(request_uri, '?')) {
506 strcat(request_uri, "?");
507 } else {
508 strcat(request_uri, "&");
509 }
510 strncat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN - strlen(request_uri));
511 }
512
513 status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(GET_PROP(obj, options)));
514 }
515 efree(request_uri);
516
517 /* clean previous response */
518 phpstr_dtor(&obj->response);
519 /* clean previous request */
520 phpstr_dtor(&obj->request);
521
522 return status;
523 }
524
525 STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
526 {
527 http_message *msg;
528
529 phpstr_fix(&obj->request);
530 phpstr_fix(&obj->response);
531
532 msg = http_message_parse(PHPSTR_VAL(&obj->response), PHPSTR_LEN(&obj->response));
533
534 if (!msg) {
535 return FAILURE;
536 } else {
537 char *body;
538 size_t body_len;
539 zval *headers, *message,
540 *resp = convert_to_type(IS_ARRAY, GET_PROP(obj, responseData)),
541 *info = convert_to_type(IS_ARRAY, GET_PROP(obj, responseInfo));
542
543 if (zval_is_true(GET_PROP(obj, recordHistory))) {
544 /* we need to act like a zipper, as we'll receive
545 * the requests and the responses in separate chains
546 * for redirects
547 */
548 http_message *response = msg, *request = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request));
549 http_message *free_msg = request;
550
551 do {
552 char *message;
553 size_t msglen;
554
555 http_message_tostring(response, &message, &msglen);
556 phpstr_append(&obj->history, message, msglen);
557 efree(message);
558
559 http_message_tostring(request, &message, &msglen);
560 phpstr_append(&obj->history, message, msglen);
561 efree(message);
562
563 } while ((response = response->parent) && (request = request->parent));
564
565 http_message_free(&free_msg);
566 phpstr_fix(&obj->history);
567 }
568
569 UPD_PROP(obj, long, responseCode, msg->http.info.response.code);
570
571 MAKE_STD_ZVAL(headers)
572 array_init(headers);
573
574 zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
575 phpstr_data(PHPSTR(msg), &body, &body_len);
576
577 add_assoc_zval(resp, "headers", headers);
578 add_assoc_stringl(resp, "body", body, body_len, 0);
579
580 MAKE_STD_ZVAL(message);
581 ZVAL_OBJVAL(message, http_message_object_from_msg(msg));
582 SET_PROP(obj, responseMessage, message);
583 zval_ptr_dtor(&message);
584
585 http_request_info(obj->ch, Z_ARRVAL_P(info));
586 SET_PROP(obj, responseInfo, info);
587
588 return SUCCESS;
589 }
590 }
591
592 #define http_request_object_set_options_subr(key, ow) \
593 _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow))
594 static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite)
595 {
596 zval *opts, **options, *new_options = NULL;
597 getObject(http_request_object, obj);
598
599 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &new_options)) {
600 RETURN_FALSE;
601 }
602
603 opts = convert_to_type(IS_ARRAY, GET_PROP(obj, options));
604
605 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) {
606 convert_to_array(*options);
607 if (overwrite) {
608 zend_hash_clean(Z_ARRVAL_PP(options));
609 }
610 if (new_options && zend_hash_num_elements(Z_ARRVAL_P(new_options))) {
611 if (overwrite) {
612 array_copy(new_options, *options);
613 } else {
614 array_merge(new_options, *options);
615 }
616 }
617 } else if (new_options && zend_hash_num_elements(Z_ARRVAL_P(new_options))) {
618 zval_add_ref(&new_options);
619 add_assoc_zval(opts, key, new_options);
620 }
621
622 RETURN_TRUE;
623 }
624
625 #define http_request_object_get_options_subr(key) \
626 _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
627 static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len)
628 {
629 NO_ARGS;
630
631 IF_RETVAL_USED {
632 zval *opts, **options;
633 getObject(http_request_object, obj);
634
635 opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options));
636
637 array_init(return_value);
638
639 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) {
640 convert_to_array(*options);
641 array_copy(*options, return_value);
642 }
643 }
644 }
645
646
647 /* ### USERLAND ### */
648
649 /* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET]])
650 *
651 * Instantiate a new HttpRequest object.
652 *
653 * Accepts a string as optional parameter containing the target request url.
654 * Additianally accepts an optional int parameter specifying the request method
655 * to use.
656 *
657 * Throws HttpException.
658 */
659 PHP_METHOD(HttpRequest, __construct)
660 {
661 char *URL = NULL;
662 int URL_len;
663 long meth = -1;
664 getObject(http_request_object, obj);
665
666 SET_EH_THROW_HTTP();
667 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &URL, &URL_len, &meth)) {
668 INIT_PARR(obj, options);
669 INIT_PARR(obj, responseInfo);
670 INIT_PARR(obj, responseData);
671 INIT_PARR(obj, postFields);
672 INIT_PARR(obj, postFiles);
673
674 if (URL) {
675 UPD_STRL(obj, url, URL, URL_len);
676 }
677 if (meth > -1) {
678 UPD_PROP(obj, long, method, meth);
679 }
680 }
681 SET_EH_NORMAL();
682 }
683 /* }}} */
684
685 /* {{{ proto void HttpRequest::__destruct()
686 *
687 * Destroys the HttpRequest object.
688 */
689 PHP_METHOD(HttpRequest, __destruct)
690 {
691 getObject(http_request_object, obj);
692
693 NO_ARGS;
694
695 FREE_PARR(obj, options);
696 FREE_PARR(obj, responseInfo);
697 FREE_PARR(obj, responseData);
698 FREE_PARR(obj, postFields);
699 FREE_PARR(obj, postFiles);
700 }
701 /* }}} */
702
703 /* {{{ proto bool HttpRequest::setOptions([array options])
704 *
705 * Set the request options to use. See http_get() for a full list of available options.
706 *
707 * Accepts an array as optional parameters, wich values will overwrite the
708 * currently set request options. If the parameter is empty or mitted,
709 * the optoions of the HttpRequest object will be reset.
710 *
711 * Returns TRUE on success, or FALSE on failure.
712 */
713 PHP_METHOD(HttpRequest, setOptions)
714 {
715 char *key = NULL;
716 ulong idx = 0;
717 zval *opts = NULL, *old_opts, **opt;
718 getObject(http_request_object, obj);
719
720 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
721 RETURN_FALSE;
722 }
723
724 old_opts = convert_to_type(IS_ARRAY, GET_PROP(obj, options));
725
726 if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
727 zend_hash_clean(Z_ARRVAL_P(old_opts));
728 RETURN_TRUE;
729 }
730
731 /* some options need extra attention -- thus cannot use array_merge() directly */
732 FOREACH_KEYVAL(opts, key, idx, opt) {
733 if (key) {
734 if (!strcmp(key, "headers")) {
735 zval **headers;
736 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "headers", sizeof("headers"), (void **) &headers)) {
737 convert_to_array(*opt);
738 convert_to_array(*headers);
739 array_merge(*opt, *headers);
740 continue;
741 }
742 } else if (!strcmp(key, "cookies")) {
743 zval **cookies;
744 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "cookies", sizeof("cookies"), (void **) &cookies)) {
745 convert_to_array(*opt);
746 convert_to_array(*cookies);
747 array_merge(*opt, *cookies);
748 continue;
749 }
750 } else if (!strcmp(key, "ssl")) {
751 zval **ssl;
752 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "ssl", sizeof("ssl"), (void **) &ssl)) {
753 convert_to_array(*opt);
754 convert_to_array(*ssl);
755 array_merge(*opt, *ssl);
756 continue;
757 }
758 } else if ((!strcasecmp(key, "url")) || (!strcasecmp(key, "uri"))) {
759 if (Z_TYPE_PP(opt) != IS_STRING) {
760 convert_to_string_ex(opt);
761 }
762 UPD_STRL(obj, url, Z_STRVAL_PP(opt), Z_STRLEN_PP(opt));
763 continue;
764 } else if (!strcmp(key, "method")) {
765 if (Z_TYPE_PP(opt) != IS_LONG) {
766 convert_to_long_ex(opt);
767 }
768 UPD_PROP(obj, long, method, Z_LVAL_PP(opt));
769 continue;
770 }
771
772 zval_add_ref(opt);
773 add_assoc_zval(old_opts, key, *opt);
774
775 /* reset */
776 key = NULL;
777 }
778 }
779
780 RETURN_TRUE;
781 }
782 /* }}} */
783
784 /* {{{ proto array HttpRequest::getOptions()
785 *
786 * Get currently set options.
787 *
788 * Returns an associative array containing currently set options.
789 */
790 PHP_METHOD(HttpRequest, getOptions)
791 {
792 NO_ARGS;
793
794 IF_RETVAL_USED {
795 zval *opts;
796 getObject(http_request_object, obj);
797
798 opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options));
799 array_init(return_value);
800 array_copy(opts, return_value);
801 }
802 }
803 /* }}} */
804
805 /* {{{ proto bool HttpRequest::setSslOptions([array options])
806 *
807 * Set SSL options.
808 *
809 * Accepts an associative array as parameter containing any SSL specific options.
810 * If the parameter is empty or omitted, the SSL options will be reset.
811 *
812 * Returns TRUE on success, or FALSE on failure.
813 */
814 PHP_METHOD(HttpRequest, setSslOptions)
815 {
816 http_request_object_set_options_subr("ssl", 1);
817 }
818 /* }}} */
819
820 /* {{{ proto bool HttpRequest::addSslOptions(array options)
821 *
822 * Set additional SSL options.
823 *
824 * Expects an associative array as parameter containing additional SSL specific options.
825 *
826 * Returns TRUE on success, or FALSE on failure.
827 */
828 PHP_METHOD(HttpRequest, addSslOptions)
829 {
830 http_request_object_set_options_subr("ssl", 0);
831 }
832 /* }}} */
833
834 /* {{{ proto array HttpRequest::getSslOtpions()
835 *
836 * Get previously set SSL options.
837 *
838 * Returns an associative array containing any previously set SSL options.
839 */
840 PHP_METHOD(HttpRequest, getSslOptions)
841 {
842 http_request_object_get_options_subr("ssl");
843 }
844 /* }}} */
845
846 /* {{{ proto bool HttpRequest::addHeaders(array headers)
847 *
848 * Add request header name/value pairs.
849 *
850 * Expects an ssociative array as parameter containing additional header
851 * name/value pairs.
852 *
853 * Returns TRUE on success, or FALSE on failure.
854 */
855 PHP_METHOD(HttpRequest, addHeaders)
856 {
857 http_request_object_set_options_subr("headers", 0);
858 }
859
860 /* {{{ proto bool HttpRequest::setHeaders([array headers])
861 *
862 * Set request header name/value pairs.
863 *
864 * Accepts an associative array as parameter containing header name/value pairs.
865 * If the parameter is empty or omitted, all previously set headers will be unset.
866 *
867 * Returns TRUE on success, or FALSE on failure.
868 */
869 PHP_METHOD(HttpRequest, setHeaders)
870 {
871 http_request_object_set_options_subr("headers", 1);
872 }
873 /* }}} */
874
875 /* {{{ proto array HttpRequest::getHeaders()
876 *
877 * Get previously set request headers.
878 *
879 * Returns an associative array containing all currently set headers.
880 */
881 PHP_METHOD(HttpRequest, getHeaders)
882 {
883 http_request_object_get_options_subr("headers");
884 }
885 /* }}} */
886
887 /* {{{ proto bool HttpRequest::setCookies([array cookies])
888 *
889 * Set cookies.
890 *
891 * Accepts an associative array as parameter containing cookie name/value pairs.
892 * If the parameter is empty or omitted, all previously set cookies will be unset.
893 *
894 * Returns TRUE on success, or FALSE on failure.
895 */
896 PHP_METHOD(HttpRequest, setCookies)
897 {
898 http_request_object_set_options_subr("cookies", 1);
899 }
900 /* }}} */
901
902 /* {{{ proto bool HttpRequest::addCookies(array cookies)
903 *
904 * Add cookies.
905 *
906 * Expects an associative array as parameter containing any cookie name/value
907 * pairs to add.
908 *
909 * Returns TRUE on success, or FALSE on failure.
910 */
911 PHP_METHOD(HttpRequest, addCookies)
912 {
913 http_request_object_set_options_subr("cookies", 0);
914 }
915 /* }}} */
916
917 /* {{{ proto array HttpRequest::getCookies()
918 *
919 * Get previously set cookies.
920 *
921 * Returns an associative array containing any previously set cookies.
922 */
923 PHP_METHOD(HttpRequest, getCookies)
924 {
925 http_request_object_get_options_subr("cookies");
926 }
927 /* }}} */
928
929 /* {{{ proto bool HttpRequest::setUrl(string url)
930 *
931 * Set the request URL.
932 *
933 * Expects a string as parameter specifying the request url.
934 *
935 * Returns TRUE on success, or FALSE on failure.
936 */
937 PHP_METHOD(HttpRequest, setUrl)
938 {
939 char *URL = NULL;
940 int URL_len;
941 getObject(http_request_object, obj);
942
943 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) {
944 RETURN_FALSE;
945 }
946
947 UPD_STRL(obj, url, URL, URL_len);
948 RETURN_TRUE;
949 }
950 /* }}} */
951
952 /* {{{ proto string HttpRequest::getUrl()
953 *
954 * Get the previously set request URL.
955 *
956 * Returns the currently set request url as string.
957 */
958 PHP_METHOD(HttpRequest, getUrl)
959 {
960 NO_ARGS;
961
962 IF_RETVAL_USED {
963 getObject(http_request_object, obj);
964 zval *URL = GET_PROP(obj, url);
965
966 RETURN_ZVAL(URL, 1, 0);
967 }
968 }
969 /* }}} */
970
971 /* {{{ proto bool HttpRequest::setMethod(int request_method)
972 *
973 * Set the request method.
974 *
975 * Expects an int as parameter specifying the request method to use.
976 * In PHP 5.1+ HttpRequest::METH, otherwise the HTTP_METH constants can be used.
977 *
978 * Returns TRUE on success, or FALSE on failure.
979 */
980 PHP_METHOD(HttpRequest, setMethod)
981 {
982 long meth;
983 getObject(http_request_object, obj);
984
985 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
986 RETURN_FALSE;
987 }
988
989 UPD_PROP(obj, long, method, meth);
990 RETURN_TRUE;
991 }
992 /* }}} */
993
994 /* {{{ proto int HttpRequest::getMethod()
995 *
996 * Get the previously set request method.
997 *
998 * Returns the currently set request method.
999 */
1000 PHP_METHOD(HttpRequest, getMethod)
1001 {
1002 NO_ARGS;
1003
1004 IF_RETVAL_USED {
1005 getObject(http_request_object, obj);
1006 zval *meth = GET_PROP(obj, method);
1007
1008 RETURN_ZVAL(meth, 1, 0);
1009 }
1010 }
1011 /* }}} */
1012
1013 /* {{{ proto bool HttpRequest::setContentType(string content_type)
1014 *
1015 * Set the content type the post request should have.
1016 *
1017 * Expects a string as parameters containing the content type of the request
1018 * (primary/secondary).
1019 *
1020 * Returns TRUE on success, or FALSE if the content type does not seem to
1021 * contain a primary and a secondary part.
1022 */
1023 PHP_METHOD(HttpRequest, setContentType)
1024 {
1025 char *ctype;
1026 int ct_len;
1027 getObject(http_request_object, obj);
1028
1029 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) {
1030 RETURN_FALSE;
1031 }
1032
1033 HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
1034 UPD_STRL(obj, contentType, ctype, ct_len);
1035 RETURN_TRUE;
1036 }
1037 /* }}} */
1038
1039 /* {{{ proto string HttpRequest::getContentType()
1040 *
1041 * Get the previously content type.
1042 *
1043 * Returns the previously set content type as string.
1044 */
1045 PHP_METHOD(HttpRequest, getContentType)
1046 {
1047 NO_ARGS;
1048
1049 IF_RETVAL_USED {
1050 getObject(http_request_object, obj);
1051 zval *ctype = GET_PROP(obj, contentType);
1052
1053 RETURN_ZVAL(ctype, 1, 0);
1054 }
1055 }
1056 /* }}} */
1057
1058 /* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
1059 *
1060 * Set the URL query parameters to use, overwriting previously set query parameters.
1061 * Affects any request types.
1062 *
1063 * Accepts a string or associative array parameter containing the pre-encoded
1064 * query string or to be encoded query fields. If the parameter is empty or
1065 * omitted, the query data will be unset.
1066 *
1067 * Returns TRUE on success, or FALSE on failure.
1068 */
1069 PHP_METHOD(HttpRequest, setQueryData)
1070 {
1071 zval *qdata = NULL;
1072 getObject(http_request_object, obj);
1073
1074 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
1075 RETURN_FALSE;
1076 }
1077
1078 if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
1079 UPD_STRL(obj, queryData, "", 0);
1080 } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
1081 char *query_data = NULL;
1082
1083 if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) {
1084 RETURN_FALSE;
1085 }
1086
1087 UPD_PROP(obj, string, queryData, query_data);
1088 efree(query_data);
1089 } else {
1090 convert_to_string_ex(&qdata);
1091 UPD_STRL(obj, queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata));
1092 }
1093 RETURN_TRUE;
1094 }
1095 /* }}} */
1096
1097 /* {{{ proto string HttpRequest::getQueryData()
1098 *
1099 * Get the current query data in form of an urlencoded query string.
1100 *
1101 * Returns a string containing the urlencoded query.
1102 */
1103 PHP_METHOD(HttpRequest, getQueryData)
1104 {
1105 NO_ARGS;
1106
1107 IF_RETVAL_USED {
1108 getObject(http_request_object, obj);
1109 zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
1110
1111 RETURN_ZVAL(qdata, 1, 0);
1112 }
1113 }
1114 /* }}} */
1115
1116 /* {{{ proto bool HttpRequest::addQueryData(array query_params)
1117 *
1118 * Add parameters to the query parameter list, leaving previously set unchanged.
1119 * Affects any request type.
1120 *
1121 * Expects an associative array as parameter containing the query fields to add.
1122 *
1123 * Returns TRUE on success, or FALSE on failure.
1124 */
1125 PHP_METHOD(HttpRequest, addQueryData)
1126 {
1127 zval *qdata, *old_qdata;
1128 char *query_data = NULL;
1129 size_t query_data_len = 0;
1130 getObject(http_request_object, obj);
1131
1132 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &qdata)) {
1133 RETURN_FALSE;
1134 }
1135
1136 old_qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
1137
1138 if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) {
1139 RETURN_FALSE;
1140 }
1141
1142 UPD_STRL(obj, queryData, query_data, query_data_len);
1143 efree(query_data);
1144
1145 RETURN_TRUE;
1146 }
1147 /* }}} */
1148
1149 /* {{{ proto bool HttpRequest::addPostFields(array post_data)
1150 *
1151 * Adds POST data entries, leaving previously set unchanged, unless a
1152 * post entry with the same name already exists.
1153 * Affects only POST and custom requests.
1154 *
1155 * Expects an associative array as parameter containing the post fields.
1156 *
1157 * Returns TRUE on success, or FALSE on failure.
1158 */
1159 PHP_METHOD(HttpRequest, addPostFields)
1160 {
1161 zval *post, *post_data;
1162 getObject(http_request_object, obj);
1163
1164 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &post_data)) {
1165 RETURN_FALSE;
1166 }
1167
1168 post = convert_to_type(IS_ARRAY, GET_PROP(obj, postFields));
1169 array_merge(post_data, post);
1170
1171 RETURN_TRUE;
1172 }
1173 /* }}} */
1174
1175 /* {{{ proto bool HttpRequest::setPostFields([array post_data])
1176 *
1177 * Set the POST data entries, overwriting previously set POST data.
1178 * Affects only POST and custom requests.
1179 *
1180 * Accepts an associative array as parameter containing the post fields.
1181 * If the parameter is empty or omitted, the post data will be unset.
1182 *
1183 * Returns TRUE on success, or FALSE on failure.
1184 */
1185 PHP_METHOD(HttpRequest, setPostFields)
1186 {
1187 zval *post, *post_data = NULL;
1188 getObject(http_request_object, obj);
1189
1190 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!", &post_data)) {
1191 RETURN_FALSE;
1192 }
1193
1194 post = convert_to_type(IS_ARRAY, GET_PROP(obj, postFields));
1195 zend_hash_clean(Z_ARRVAL_P(post));
1196
1197 if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
1198 array_copy(post_data, post);
1199 }
1200
1201 RETURN_TRUE;
1202 }
1203 /* }}}*/
1204
1205 /* {{{ proto array HttpRequest::getPostFields()
1206 *
1207 * Get previously set POST data.
1208 *
1209 * Returns the currently set post fields as associative array.
1210 */
1211 PHP_METHOD(HttpRequest, getPostFields)
1212 {
1213 NO_ARGS;
1214
1215 IF_RETVAL_USED {
1216 getObject(http_request_object, obj);
1217 zval *post_data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFields));
1218
1219 array_init(return_value);
1220 array_copy(post_data, return_value);
1221 }
1222 }
1223 /* }}} */
1224
1225 /* {{{ proto bool HttpRequest::setRawPostData([string raw_post_data])
1226 *
1227 * Set raw post data to send, overwriting previously set raw post data. Don't
1228 * forget to specify a content type. Affects only POST and custom requests.
1229 * Only either post fields or raw post data can be used for each request.
1230 * Raw post data has higher precedence and will be used even if post fields
1231 * are set.
1232 *
1233 * Accepts a string as parameter containing the *raw* post data.
1234 *
1235 * Returns TRUE on success, or FALSE on failure.
1236 */
1237 PHP_METHOD(HttpRequest, setRawPostData)
1238 {
1239 char *raw_data = NULL;
1240 int data_len = 0;
1241 getObject(http_request_object, obj);
1242
1243 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) {
1244 RETURN_FALSE;
1245 }
1246
1247 if (!raw_data) {
1248 raw_data = "";
1249 }
1250
1251 UPD_STRL(obj, rawPostData, raw_data, data_len);
1252 RETURN_TRUE;
1253 }
1254 /* }}} */
1255
1256 /* {{{ proto bool HttpRequest::addRawPostData(string raw_post_data)
1257 *
1258 * Add raw post data, leaving previously set raw post data unchanged.
1259 * Affects only POST and custom requests.
1260 *
1261 * Expects a string as parameter containing the raw post data to concatenate.
1262 *
1263 * Returns TRUE on success, or FALSE on failure.
1264 */
1265 PHP_METHOD(HttpRequest, addRawPostData)
1266 {
1267 char *raw_data, *new_data;
1268 int data_len;
1269 getObject(http_request_object, obj);
1270
1271 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) {
1272 RETURN_FALSE;
1273 }
1274
1275 if (data_len) {
1276 zval *zdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
1277
1278 new_data = emalloc(Z_STRLEN_P(zdata) + data_len + 1);
1279 new_data[Z_STRLEN_P(zdata) + data_len] = '\0';
1280
1281 if (Z_STRLEN_P(zdata)) {
1282 memcpy(new_data, Z_STRVAL_P(zdata), Z_STRLEN_P(zdata));
1283 }
1284
1285 memcpy(new_data + Z_STRLEN_P(zdata), raw_data, data_len);
1286 UPD_STRL(obj, rawPostData, new_data, Z_STRLEN_P(zdata) + data_len);
1287 }
1288
1289 RETURN_TRUE;
1290 }
1291 /* }}} */
1292
1293 /* {{{ proto string HttpRequest::getRawPostData()
1294 *
1295 * Get previously set raw post data.
1296 *
1297 * Returns a string containing the currently set raw post data.
1298 */
1299 PHP_METHOD(HttpRequest, getRawPostData)
1300 {
1301 NO_ARGS;
1302
1303 IF_RETVAL_USED {
1304 getObject(http_request_object, obj);
1305 zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
1306
1307 RETURN_ZVAL(raw_data, 1, 0);
1308 }
1309 }
1310 /* }}} */
1311
1312 /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
1313 *
1314 * Add a file to the POST request, leaving prefiously set files unchanged.
1315 * Affects only POST and custom requests. Cannot be used with raw post data.
1316 *
1317 * Expects a string parameter containing the form element name, and a string
1318 * paremeter containing the path to the file which should be uploaded.
1319 * Additionally accepts an optional string parameter which chould contain
1320 * the content type of the file.
1321 *
1322 * Returns TRUE on success, or FALSE if the content type seems not to contain a
1323 * primary and a secondary content type part.
1324 */
1325 PHP_METHOD(HttpRequest, addPostFile)
1326 {
1327 zval *files, *entry;
1328 char *name, *file, *type = NULL;
1329 int name_len, file_len, type_len = 0;
1330 getObject(http_request_object, obj);
1331
1332 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) {
1333 RETURN_FALSE;
1334 }
1335
1336 if (type_len) {
1337 HTTP_CHECK_CONTENT_TYPE(type, RETURN_FALSE);
1338 } else {
1339 type = "application/x-octetstream";
1340 type_len = sizeof("application/x-octetstream") - 1;
1341 }
1342
1343 MAKE_STD_ZVAL(entry);
1344 array_init(entry);
1345
1346 add_assoc_stringl(entry, "name", name, name_len, 1);
1347 add_assoc_stringl(entry, "type", type, type_len, 1);
1348 add_assoc_stringl(entry, "file", file, file_len, 1);
1349
1350 files = convert_to_type(IS_ARRAY, GET_PROP(obj, postFiles));
1351 add_next_index_zval(files, entry);
1352
1353 RETURN_TRUE;
1354 }
1355 /* }}} */
1356
1357 /* {{{ proto bool HttpRequest::setPostFiles([array post_files])
1358 *
1359 * Set files to post, overwriting previously set post files.
1360 * Affects only POST and requests. Cannot be used with raw post data.
1361 *
1362 * Accepts an array containing the files to post. Each entry should be an
1363 * associative array with "name", "file" and "type" keys. If the parameter
1364 * is empty or omitted the post files will be unset.
1365 *
1366 * Returns TRUE on success, or FALSE on failure.
1367 */
1368 PHP_METHOD(HttpRequest, setPostFiles)
1369 {
1370 zval *files, *pFiles;
1371 getObject(http_request_object, obj);
1372
1373 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &files)) {
1374 RETURN_FALSE;
1375 }
1376
1377 pFiles = convert_to_type(IS_ARRAY, GET_PROP(obj, postFiles));
1378 zend_hash_clean(Z_ARRVAL_P(pFiles));
1379
1380 if (files && zend_hash_num_elements(Z_ARRVAL_P(files))) {
1381 array_copy(files, pFiles);
1382 }
1383
1384 RETURN_TRUE;
1385 }
1386 /* }}} */
1387
1388 /* {{{ proto array HttpRequest::getPostFiles()
1389 *
1390 * Get all previously added POST files.
1391 *
1392 * Returns an array containing currently set post files.
1393 */
1394 PHP_METHOD(HttpRequest, getPostFiles)
1395 {
1396 NO_ARGS;
1397
1398 IF_RETVAL_USED {
1399 getObject(http_request_object, obj);
1400 zval *files = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFiles));
1401
1402 array_init(return_value);
1403 array_copy(files, return_value);
1404 }
1405 }
1406 /* }}} */
1407
1408 /* {{{ proto bool HttpRequest::setPutFile([string file])
1409 *
1410 * Set file to put. Affects only PUT requests.
1411 *
1412 * Accepts a string as parameter referencing the path to file.
1413 * If the parameter is empty or omitted the put file will be unset.
1414 *
1415 * Returns TRUE on success, or FALSE on failure.
1416 */
1417 PHP_METHOD(HttpRequest, setPutFile)
1418 {
1419 char *file = "";
1420 int file_len = 0;
1421 getObject(http_request_object, obj);
1422
1423 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) {
1424 RETURN_FALSE;
1425 }
1426
1427 UPD_STRL(obj, putFile, file, file_len);
1428 RETURN_TRUE;
1429 }
1430 /* }}} */
1431
1432 /* {{{ proto string HttpRequest::getPutFile()
1433 *
1434 * Get previously set put file.
1435 *
1436 * Returns a string containing the path to the currently set put file.
1437 */
1438 PHP_METHOD(HttpRequest, getPutFile)
1439 {
1440 NO_ARGS;
1441
1442 IF_RETVAL_USED {
1443 getObject(http_request_object, obj);
1444 zval *putfile = convert_to_type_ex(IS_STRING, GET_PROP(obj, putFile));
1445
1446 RETURN_ZVAL(putfile, 1, 0);
1447 }
1448 }
1449 /* }}} */
1450
1451 /* {{{ proto array HttpRequest::getResponseData()
1452 *
1453 * Get all response data after the request has been sent.
1454 *
1455 * Returns an associative array with the key "headers" containing an associative
1456 * array holding all response headers, as well as the ley "body" containing a
1457 * string with the response body.
1458 *
1459 * If redirects were allowed and several responses were received, the data
1460 * references the last received response.
1461 */
1462 PHP_METHOD(HttpRequest, getResponseData)
1463 {
1464 NO_ARGS;
1465
1466 IF_RETVAL_USED {
1467 getObject(http_request_object, obj);
1468 zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
1469
1470 array_init(return_value);
1471 array_copy(data, return_value);
1472 }
1473 }
1474 /* }}} */
1475
1476 /* {{{ proto mixed HttpRequest::getResponseHeader([string name])
1477 *
1478 * Get response header(s) after the request has been sent.
1479 *
1480 * Accepts an string as optional parameter specifying a certain header to read.
1481 * If the parameter is empty or omitted all response headers will be returned.
1482 *
1483 * Returns either a string with the value of the header matching name if requested,
1484 * FALSE on failure, or an associative array containing all reponse headers.
1485 *
1486 * If redirects were allowed and several responses were received, the data
1487 * references the last received response.
1488 */
1489 PHP_METHOD(HttpRequest, getResponseHeader)
1490 {
1491 IF_RETVAL_USED {
1492 zval *data, **headers, **header;
1493 char *header_name = NULL;
1494 int header_len = 0;
1495 getObject(http_request_object, obj);
1496
1497 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
1498 RETURN_FALSE;
1499 }
1500
1501 data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
1502 if (SUCCESS != zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
1503 RETURN_FALSE;
1504 }
1505 convert_to_array_ex(headers);
1506 if (!header_len || !header_name) {
1507 array_init(return_value);
1508 array_copy(*headers, return_value);
1509 } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) {
1510 RETURN_ZVAL(*header, 1, 0);
1511 } else {
1512 RETURN_FALSE;
1513 }
1514 }
1515 }
1516 /* }}} */
1517
1518 /* {{{ proto array HttpRequest::getResponseCookie([string name])
1519 *
1520 * Get response cookie(s) after the request has been sent.
1521 *
1522 * Accepts a string as optional parameter specifying the name of the cookie to read.
1523 * If the parameter is empty or omitted, an associative array with all received
1524 * cookies will be returned.
1525 *
1526 * Returns either an associative array with the cookie's name, value and any
1527 * additional params of the cookie matching name if requested, FALSE on failure,
1528 * or an array containing all received cookies as arrays.
1529 *
1530 * If redirects were allowed and several responses were received, the data
1531 * references the last received response.
1532 */
1533 PHP_METHOD(HttpRequest, getResponseCookie)
1534 {
1535 IF_RETVAL_USED {
1536 zval *data, **headers;
1537 char *cookie_name = NULL;
1538 int cookie_len = 0;
1539 getObject(http_request_object, obj);
1540
1541 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) {
1542 RETURN_FALSE;
1543 }
1544
1545 array_init(return_value);
1546
1547 data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
1548 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
1549 ulong idx = 0;
1550 char *key = NULL;
1551 zval **header = NULL;
1552
1553 convert_to_array_ex(headers);
1554 FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers), key, idx, header) {
1555 if (key && !strcasecmp(key, "Set-Cookie")) {
1556 /* several cookies? */
1557 if (Z_TYPE_PP(header) == IS_ARRAY) {
1558 zval **cookie;
1559
1560 FOREACH_HASH_VAL(Z_ARRVAL_PP(header), cookie) {
1561 zval *cookie_hash;
1562 MAKE_STD_ZVAL(cookie_hash);
1563 array_init(cookie_hash);
1564
1565 if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(cookie), Z_ARRVAL_P(cookie_hash))) {
1566 if (!cookie_len) {
1567 add_next_index_zval(return_value, cookie_hash);
1568 } else {
1569 zval **name;
1570
1571 if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
1572 (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
1573 add_next_index_zval(return_value, cookie_hash);
1574 return; /* <<< FOUND >>> */
1575 } else {
1576 zval_dtor(cookie_hash);
1577 efree(cookie_hash);
1578 }
1579 }
1580 } else {
1581 zval_dtor(cookie_hash);
1582 efree(cookie_hash);
1583 }
1584 }
1585 } else {
1586 zval *cookie_hash;
1587
1588 MAKE_STD_ZVAL(cookie_hash);
1589 array_init(cookie_hash);
1590 convert_to_string_ex(header);
1591
1592 if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(header), Z_ARRVAL_P(cookie_hash))) {
1593 if (!cookie_len) {
1594 add_next_index_zval(return_value, cookie_hash);
1595 } else {
1596 zval **name;
1597
1598 if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
1599 (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
1600 add_next_index_zval(return_value, cookie_hash);
1601 } else {
1602 zval_dtor(cookie_hash);
1603 efree(cookie_hash);
1604 }
1605 }
1606 } else {
1607 zval_dtor(cookie_hash);
1608 efree(cookie_hash);
1609 }
1610 }
1611 break;
1612 }
1613 /* reset key */
1614 key = NULL;
1615 }
1616 }
1617 }
1618 }
1619 /* }}} */
1620
1621 /* {{{ proto string HttpRequest::getResponseBody()
1622 *
1623 * Get the response body after the request has been sent.
1624 *
1625 * Returns a string containing the response body.
1626 *
1627 * If redirects were allowed and several responses were received, the data
1628 * references the last received response.
1629 */
1630 PHP_METHOD(HttpRequest, getResponseBody)
1631 {
1632 NO_ARGS;
1633
1634 IF_RETVAL_USED {
1635 zval **body;
1636 getObject(http_request_object, obj);
1637 zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
1638
1639 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body)) {
1640 convert_to_string_ex(body);
1641 RETURN_ZVAL(*body, 1, 0);
1642 } else {
1643 RETURN_FALSE;
1644 }
1645 }
1646 }
1647 /* }}} */
1648
1649 /* {{{ proto int HttpRequest::getResponseCode()
1650 *
1651 * Get the response code after the request has been sent.
1652 *
1653 * Returns an int representing the response code.
1654 *
1655 * If redirects were allowed and several responses were received, the data
1656 * references the last received response.
1657 */
1658 PHP_METHOD(HttpRequest, getResponseCode)
1659 {
1660 NO_ARGS;
1661
1662 IF_RETVAL_USED {
1663 getObject(http_request_object, obj);
1664 zval *code = convert_to_type_ex(IS_LONG, GET_PROP(obj, responseCode));
1665
1666 RETURN_ZVAL(code, 1, 0);
1667 }
1668 }
1669 /* }}} */
1670
1671 /* {{{ proto mixed HttpRequest::getResponseInfo([string name])
1672 *
1673 * Get response info after the request has been sent.
1674 * See http_get() for a full list of returned info.
1675 *
1676 * Accepts a string as optional parameter specifying the info to read.
1677 * If the parameter is empty or omitted, an associative array containing
1678 * all available info will be returned.
1679 *
1680 * Returns either a scalar containing the value of the info matching name if
1681 * requested, FALSE on failure, or an associative array containing all
1682 * available info.
1683 *
1684 * If redirects were allowed and several responses were received, the data
1685 * references the last received response.
1686 */
1687 PHP_METHOD(HttpRequest, getResponseInfo)
1688 {
1689 IF_RETVAL_USED {
1690 zval *info, **infop;
1691 char *info_name = NULL;
1692 int info_len = 0;
1693 getObject(http_request_object, obj);
1694
1695 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
1696 RETURN_FALSE;
1697 }
1698
1699 info = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseInfo));
1700
1701 if (info_len && info_name) {
1702 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) {
1703 RETURN_ZVAL(*infop, 1, 0);
1704 } else {
1705 http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name);
1706 RETURN_FALSE;
1707 }
1708 } else {
1709 array_init(return_value);
1710 array_copy(info, return_value);
1711 }
1712 }
1713 }
1714 /* }}}*/
1715
1716 /* {{{ proto HttpMessage HttpRequest::getResponseMessage()
1717 *
1718 * Get the full response as HttpMessage object after the request has been sent.
1719 *
1720 * Returns an HttpMessage object of the response.
1721 *
1722 * If redirects were allowed and several responses were received, the data
1723 * references the last received response. Use HttpMessage::getParentMessage()
1724 * to access the data of previously received responses whithin this request
1725 * cycle.
1726 *
1727 * Throws HttpException.
1728 */
1729 PHP_METHOD(HttpRequest, getResponseMessage)
1730 {
1731 NO_ARGS;
1732
1733 IF_RETVAL_USED {
1734 zval *message;
1735 getObject(http_request_object, obj);
1736
1737 SET_EH_THROW_HTTP();
1738 message = GET_PROP(obj, responseMessage);
1739 if (Z_TYPE_P(message) == IS_OBJECT) {
1740 RETVAL_OBJECT(message);
1741 } else {
1742 RETVAL_NULL();
1743 }
1744 SET_EH_NORMAL();
1745 }
1746 }
1747 /* }}} */
1748
1749 /* {{{ proto HttpMessage HttpRequest::getRequestMessage()
1750 *
1751 * Get sent HTTP message.
1752 *
1753 * Returns an HttpMessage object representing the sent request.
1754 *
1755 * If redirects were allowed and several responses were received, the data
1756 * references the last received response. Use HttpMessage::getParentMessage()
1757 * to access the data of previously sent requests whithin this request
1758 * cycle.
1759 */
1760 PHP_METHOD(HttpRequest, getRequestMessage)
1761 {
1762 NO_ARGS;
1763
1764 IF_RETVAL_USED {
1765 http_message *msg;
1766 getObject(http_request_object, obj);
1767
1768 SET_EH_THROW_HTTP();
1769 if (msg = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request))) {
1770 RETVAL_OBJVAL(http_message_object_from_msg(msg));
1771 }
1772 SET_EH_NORMAL();
1773 }
1774 }
1775 /* }}} */
1776
1777 /* {{{ proto HttpMessage HttpRequest::getHistory()
1778 *
1779 * Get all sent requests and received responses as an HttpMessage object.
1780 *
1781 * If you don't want to record history at all, set the instance variable
1782 * HttpRequest::$recoedHistory to FALSE.
1783 *
1784 * Returns an HttpMessage object representing the complete request/response
1785 * history.
1786 *
1787 * The object references the last received response, use HttpMessage::getParentMessage()
1788 * to access the data of previously sent requests and received responses.
1789 *
1790 * Throws HttpMalformedHeaderException.
1791 */
1792 PHP_METHOD(HttpRequest, getHistory)
1793 {
1794 NO_ARGS;
1795
1796 IF_RETVAL_USED {
1797 http_message *msg;
1798 getObject(http_request_object, obj);
1799
1800 SET_EH_THROW_HTTP();
1801 if (msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history))) {
1802 RETVAL_OBJVAL(http_message_object_from_msg(msg));
1803 }
1804 SET_EH_NORMAL();
1805 }
1806 }
1807 /* }}} */
1808
1809 /* {{{ proto void HttpRequest::clearHistory()
1810 *
1811 * Clear the history.
1812 */
1813 PHP_METHOD(HttpRequest, clearHistory)
1814 {
1815 NO_ARGS {
1816 getObject(http_request_object, obj);
1817 phpstr_dtor(&obj->history);
1818 }
1819 }
1820 /* }}} */
1821
1822 /* {{{ proto HttpMessage HttpRequest::send()
1823 *
1824 * Send the HTTP request.
1825 *
1826 * Returns the received response as HttpMessage object.
1827 *
1828 * Throws HttpRuntimeException, HttpRequestException,
1829 * HttpMalformedHeaderException, HttpEncodingException.
1830 *
1831 * GET example:
1832 * <pre>
1833 * <?php
1834 * $r = new HttpRequest('http://example.com/feed.rss', HTTP_GET);
1835 * $r->setOptions(array('lastmodified' => filemtime('local.rss')));
1836 * $r->addQueryData(array('category' => 3));
1837 * try {
1838 * $r->send();
1839 * if ($r->getResponseCode() == 200) {
1840 * file_put_contents('local.rss', $r->getResponseBody());
1841 * }
1842 * } catch (HttpException $ex) {
1843 * echo $ex;
1844 * }
1845 * ?>
1846 * </pre>
1847 *
1848 * POST example:
1849 * <pre>
1850 * <?php
1851 * $r = new HttpRequest('http://example.com/form.php', HTTP_POST);
1852 * $r->setOptions(array('cookies' => array('lang' => 'de')));
1853 * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
1854 * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
1855 * try {
1856 * echo $r->send()->getBody();
1857 * } catch (HttpException $ex) {
1858 * echo $ex;
1859 * }
1860 * ?>
1861 * </pre>
1862 */
1863 PHP_METHOD(HttpRequest, send)
1864 {
1865 http_request_body body = {0, NULL, 0};
1866 getObject(http_request_object, obj);
1867
1868 NO_ARGS;
1869
1870 SET_EH_THROW_HTTP();
1871
1872 if (obj->pool) {
1873 http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool");
1874 SET_EH_NORMAL();
1875 RETURN_FALSE;
1876 }
1877
1878 RETVAL_NULL();
1879
1880 if ( (SUCCESS == http_request_object_requesthandler(obj, getThis(), &body)) &&
1881 (SUCCESS == http_request_exec(obj->ch, NULL, &obj->response, &obj->request)) &&
1882 (SUCCESS == http_request_object_responsehandler(obj, getThis()))) {
1883 RETVAL_OBJECT(GET_PROP(obj, responseMessage));
1884 }
1885 http_request_body_dtor(&body);
1886
1887 SET_EH_NORMAL();
1888 }
1889 /* }}} */
1890
1891 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
1892
1893 /*
1894 * Local variables:
1895 * tab-width: 4
1896 * c-basic-offset: 4
1897 * End:
1898 * vim600: noet sw=4 ts=4 fdm=marker
1899 * vim<600: noet sw=4 ts=4
1900 */
1901