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