2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
14 #include "php_http_client.h"
16 #include <ext/spl/spl_observer.h>
19 * array of name => php_http_client_driver_t*
21 static HashTable php_http_client_drivers
;
23 STATUS
php_http_client_driver_add(php_http_client_driver_t
*driver
)
25 return zend_hash_add(&php_http_client_drivers
, driver
->name_str
, driver
->name_len
+ 1, (void *) driver
, sizeof(php_http_client_driver_t
), NULL
);
28 STATUS
php_http_client_driver_get(const char *name_str
, size_t name_len
, php_http_client_driver_t
*driver
)
30 php_http_client_driver_t
*tmp
;
32 if ((name_str
&& SUCCESS
== zend_hash_find(&php_http_client_drivers
, name_str
, name_len
+ 1, (void *) &tmp
))
33 || (SUCCESS
== zend_hash_get_current_data(&php_http_client_drivers
, (void *) &tmp
))) {
40 static int apply_driver_list(void *p
, void *arg TSRMLS_DC
)
42 php_http_client_driver_t
*d
= p
;
46 ZVAL_STRINGL(zname
, d
->name_str
, d
->name_len
, 1);
48 zend_hash_next_index_insert(arg
, &zname
, sizeof(zval
*), NULL
);
49 return ZEND_HASH_APPLY_KEEP
;
52 void php_http_client_driver_list(HashTable
*ht TSRMLS_DC
)
54 zend_hash_apply_with_argument(&php_http_client_drivers
, apply_driver_list
, ht TSRMLS_CC
);
57 void php_http_client_options_set_subr(zval
*this_ptr
, char *key
, size_t len
, zval
*opts
, int overwrite TSRMLS_DC
)
59 if (overwrite
|| (opts
&& zend_hash_num_elements(Z_ARRVAL_P(opts
)))) {
60 zend_class_entry
*this_ce
= Z_OBJCE_P(getThis());
61 zval
*old_opts
, *new_opts
, **entry
= NULL
;
63 MAKE_STD_ZVAL(new_opts
);
65 old_opts
= zend_read_property(this_ce
, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC
);
66 if (Z_TYPE_P(old_opts
) == IS_ARRAY
) {
67 array_copy(Z_ARRVAL_P(old_opts
), Z_ARRVAL_P(new_opts
));
71 if (opts
&& zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
73 zend_symtable_update(Z_ARRVAL_P(new_opts
), key
, len
, (void *) &opts
, sizeof(zval
*), NULL
);
75 zend_symtable_del(Z_ARRVAL_P(new_opts
), key
, len
);
77 } else if (opts
&& zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
78 if (SUCCESS
== zend_symtable_find(Z_ARRVAL_P(new_opts
), key
, len
, (void *) &entry
)) {
79 array_join(Z_ARRVAL_P(opts
), Z_ARRVAL_PP(entry
), 0, 0);
82 zend_symtable_update(Z_ARRVAL_P(new_opts
), key
, len
, (void *) &opts
, sizeof(zval
*), NULL
);
86 zend_update_property(this_ce
, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC
);
87 zval_ptr_dtor(&new_opts
);
91 void php_http_client_options_set(zval
*this_ptr
, zval
*opts TSRMLS_DC
)
93 php_http_array_hashkey_t key
= php_http_array_hashkey_init(0);
96 zend_class_entry
*this_ce
= Z_OBJCE_P(getThis());
97 zend_bool is_client
= instanceof_function(this_ce
, php_http_client_class_entry TSRMLS_CC
);
99 MAKE_STD_ZVAL(new_opts
);
100 array_init(new_opts
);
102 if (!opts
|| !zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
103 zend_update_property(this_ce
, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC
);
104 zval_ptr_dtor(&new_opts
);
106 zval
*old_opts
, *add_opts
, **opt
;
108 MAKE_STD_ZVAL(add_opts
);
109 array_init(add_opts
);
110 /* some options need extra attention -- thus cannot use array_merge() directly */
111 FOREACH_KEYVAL(pos
, opts
, key
, opt
) {
112 if (key
.type
== HASH_KEY_IS_STRING
) {
113 #define KEYMATCH(k, s) ((sizeof(s)==k.len) && !strcasecmp(k.str, s))
114 if (Z_TYPE_PP(opt
) == IS_ARRAY
&& (KEYMATCH(key
, "ssl") || KEYMATCH(key
, "cookies"))) {
115 php_http_client_options_set_subr(getThis(), key
.str
, key
.len
, *opt
, 0 TSRMLS_CC
);
116 } else if (is_client
&& (KEYMATCH(key
, "recordHistory") || KEYMATCH(key
, "responseMessageClass"))) {
117 zend_update_property(this_ce
, getThis(), key
.str
, key
.len
-1, *opt TSRMLS_CC
);
118 } else if (Z_TYPE_PP(opt
) == IS_NULL
) {
119 old_opts
= zend_read_property(this_ce
, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC
);
120 if (Z_TYPE_P(old_opts
) == IS_ARRAY
) {
121 zend_symtable_del(Z_ARRVAL_P(old_opts
), key
.str
, key
.len
);
125 add_assoc_zval_ex(add_opts
, key
.str
, key
.len
, *opt
);
130 old_opts
= zend_read_property(this_ce
, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC
);
131 if (Z_TYPE_P(old_opts
) == IS_ARRAY
) {
132 array_copy(Z_ARRVAL_P(old_opts
), Z_ARRVAL_P(new_opts
));
134 array_join(Z_ARRVAL_P(add_opts
), Z_ARRVAL_P(new_opts
), 0, 0);
135 zend_update_property(this_ce
, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC
);
136 zval_ptr_dtor(&new_opts
);
137 zval_ptr_dtor(&add_opts
);
141 void php_http_client_options_get_subr(zval
*this_ptr
, char *key
, size_t len
, zval
*return_value TSRMLS_DC
)
143 zend_class_entry
*this_ce
= Z_OBJCE_P(getThis());
144 zval
**options
, *opts
= zend_read_property(this_ce
, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC
);
146 if ((Z_TYPE_P(opts
) == IS_ARRAY
) && (SUCCESS
== zend_symtable_find(Z_ARRVAL_P(opts
), key
, len
, (void *) &options
))) {
147 RETVAL_ZVAL(*options
, 1, 0);
151 static void queue_dtor(void *enqueued
)
153 php_http_client_enqueue_t
*e
= enqueued
;
160 php_http_client_t
*php_http_client_init(php_http_client_t
*h
, php_http_client_ops_t
*ops
, php_resource_factory_t
*rf
, void *init_arg TSRMLS_DC
)
162 php_http_client_t
*free_h
= NULL
;
165 free_h
= h
= emalloc(sizeof(*h
));
167 memset(h
, 0, sizeof(*h
));
172 } else if (ops
->rsrc
) {
173 h
->rf
= php_resource_factory_init(NULL
, h
->ops
->rsrc
, h
, NULL
);
175 zend_llist_init(&h
->requests
, sizeof(php_http_client_enqueue_t
), queue_dtor
, 0);
176 zend_llist_init(&h
->responses
, sizeof(void *), NULL
, 0);
177 TSRMLS_SET_CTX(h
->ts
);
180 if (!(h
= h
->ops
->init(h
, init_arg
))) {
181 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize client");
191 php_http_client_t
*php_http_client_copy(php_http_client_t
*from
, php_http_client_t
*to
)
193 if (from
->ops
->copy
) {
194 return from
->ops
->copy(from
, to
);
200 void php_http_client_dtor(php_http_client_t
*h
)
202 php_http_client_reset(h
);
208 php_resource_factory_free(&h
->rf
);
211 void php_http_client_free(php_http_client_t
**h
) {
213 php_http_client_dtor(*h
);
219 STATUS
php_http_client_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
221 TSRMLS_FETCH_FROM_CTX(h
->ts
);
223 if (h
->ops
->enqueue
) {
224 if (php_http_client_enqueued(h
, enqueue
->request
, NULL
)) {
225 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to enqueue request; request already in queue");
228 return h
->ops
->enqueue(h
, enqueue
);
234 STATUS
php_http_client_dequeue(php_http_client_t
*h
, php_http_message_t
*request
)
236 TSRMLS_FETCH_FROM_CTX(h
->ts
);
238 if (h
->ops
->dequeue
) {
239 php_http_client_enqueue_t
*enqueue
= php_http_client_enqueued(h
, request
, NULL
);
242 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to dequeue request; request not in queue");
245 return h
->ops
->dequeue(h
, enqueue
);
250 php_http_client_enqueue_t
*php_http_client_enqueued(php_http_client_t
*h
, void *compare_arg
, php_http_client_enqueue_cmp_func_t compare_func
)
252 zend_llist_element
*el
= NULL
;
255 for (el
= h
->requests
.head
; el
; el
= el
->next
) {
256 if (compare_func((php_http_client_enqueue_t
*) el
->data
, compare_arg
)) {
261 for (el
= h
->requests
.head
; el
; el
= el
->next
) {
262 if (((php_http_client_enqueue_t
*) el
->data
)->request
== compare_arg
) {
267 return el
? (php_http_client_enqueue_t
*) el
->data
: NULL
;
270 STATUS
php_http_client_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
273 return h
->ops
->wait(h
, custom_timeout
);
279 int php_http_client_once(php_http_client_t
*h
)
282 return h
->ops
->once(h
);
288 STATUS
php_http_client_exec(php_http_client_t
*h
)
291 return h
->ops
->exec(h
);
297 void php_http_client_reset(php_http_client_t
*h
)
303 zend_llist_clean(&h
->requests
);
304 zend_llist_clean(&h
->responses
);
307 STATUS
php_http_client_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
309 if (h
->ops
->setopt
) {
310 return h
->ops
->setopt(h
, opt
, arg
);
316 STATUS
php_http_client_getopt(php_http_client_t
*h
, php_http_client_getopt_opt_t opt
, void *arg
, void *res_ptr
)
318 if (h
->ops
->getopt
) {
319 return h
->ops
->getopt(h
, opt
, arg
, res_ptr
);
324 zend_class_entry
*php_http_client_class_entry
;
325 static zend_object_handlers php_http_client_object_handlers
;
327 void php_http_client_object_free(void *object TSRMLS_DC
)
329 php_http_client_object_t
*o
= (php_http_client_object_t
*) object
;
331 php_http_client_free(&o
->client
);
332 php_http_object_method_dtor(&o
->notify
);
333 php_http_object_method_free(&o
->update
);
334 zend_object_std_dtor((zend_object
*) o TSRMLS_CC
);
338 zend_object_value
php_http_client_object_new_ex(zend_class_entry
*ce
, php_http_client_t
*client
, php_http_client_object_t
**ptr TSRMLS_DC
)
340 php_http_client_object_t
*o
;
342 o
= ecalloc(1, sizeof(php_http_client_object_t
));
343 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
344 object_properties_init((zend_object
*) o
, ce
);
352 o
->zv
.handle
= zend_objects_store_put(o
, NULL
, php_http_client_object_free
, NULL TSRMLS_CC
);
353 o
->zv
.handlers
= &php_http_client_object_handlers
;
358 zend_object_value
php_http_client_object_new(zend_class_entry
*ce TSRMLS_DC
)
360 return php_http_client_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
363 static void handle_history(zval
*zclient
, php_http_message_t
*request
, php_http_message_t
*response TSRMLS_DC
)
365 zval
*new_hist
, *old_hist
= zend_read_property(php_http_client_class_entry
, zclient
, ZEND_STRL("history"), 0 TSRMLS_CC
);
366 php_http_message_t
*zipped
= php_http_message_zip(response
, request
);
367 zend_object_value ov
= php_http_message_object_new_ex(php_http_message_class_entry
, zipped
, NULL TSRMLS_CC
);
369 MAKE_STD_ZVAL(new_hist
);
370 ZVAL_OBJVAL(new_hist
, ov
, 0);
372 if (Z_TYPE_P(old_hist
) == IS_OBJECT
) {
373 php_http_message_object_prepend(new_hist
, old_hist
, 1 TSRMLS_CC
);
376 zend_update_property(php_http_client_class_entry
, zclient
, ZEND_STRL("history"), new_hist TSRMLS_CC
);
377 zval_ptr_dtor(&new_hist
);
380 static STATUS
handle_response(void *arg
, php_http_client_t
*client
, php_http_client_enqueue_t
*e
, php_http_message_t
**response
)
382 zend_bool dequeue
= 0;
384 php_http_message_t
*msg
;
385 php_http_client_progress_state_t
*progress
;
386 TSRMLS_FETCH_FROM_CTX(client
->ts
);
388 INIT_PZVAL(&zclient
);
389 ZVAL_OBJVAL(&zclient
, ((php_http_client_object_t
*) arg
)->zv
, 0);
391 if ((msg
= *response
)) {
392 php_http_message_object_t
*msg_obj
;
393 zval
*info
, *zresponse
, *zrequest
;
396 /* ensure the message is of type response (could be uninitialized in case of early error, like DNS) */
397 php_http_message_set_type(msg
, PHP_HTTP_RESPONSE
);
399 if (z_is_true(zend_read_property(php_http_client_class_entry
, &zclient
, ZEND_STRL("recordHistory"), 0 TSRMLS_CC
))) {
400 handle_history(&zclient
, e
->request
, *response TSRMLS_CC
);
403 /* hard detach, redirects etc. are in the history */
404 php_http_message_free(&msg
->parent
);
407 MAKE_STD_ZVAL(zresponse
);
408 ZVAL_OBJVAL(zresponse
, php_http_message_object_new_ex(php_http_client_response_class_entry
, msg
, &msg_obj TSRMLS_CC
), 0);
410 MAKE_STD_ZVAL(zrequest
);
411 ZVAL_OBJVAL(zrequest
, ((php_http_message_object_t
*) e
->opaque
)->zv
, 1);
413 php_http_message_object_prepend(zresponse
, zrequest
, 1 TSRMLS_CC
);
417 info_ht
= HASH_OF(info
);
418 php_http_client_getopt(client
, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
, e
->request
, &info_ht
);
419 zend_update_property(php_http_client_response_class_entry
, zresponse
, ZEND_STRL("transferInfo"), info TSRMLS_CC
);
420 zval_ptr_dtor(&info
);
422 zend_objects_store_add_ref_by_handle(msg_obj
->zv
.handle TSRMLS_CC
);
423 zend_llist_add_element(&client
->responses
, &msg_obj
);
425 if (e
->closure
.fci
.size
) {
427 zend_error_handling zeh
;
429 zend_fcall_info_argn(&e
->closure
.fci TSRMLS_CC
, 1, &zresponse
);
430 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh TSRMLS_CC
);
431 zend_fcall_info_call(&e
->closure
.fci
, &e
->closure
.fcc
, &retval
, NULL TSRMLS_CC
);
432 zend_restore_error_handling(&zeh TSRMLS_CC
);
433 zend_fcall_info_argn(&e
->closure
.fci TSRMLS_CC
, 0);
436 if (Z_TYPE_P(retval
) == IS_BOOL
) {
437 dequeue
= Z_BVAL_P(retval
);
439 zval_ptr_dtor(&retval
);
443 zval_ptr_dtor(&zresponse
);
444 zval_ptr_dtor(&zrequest
);
447 if (SUCCESS
== php_http_client_getopt(client
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, e
->request
, &progress
)) {
448 progress
->info
= "finished";
449 progress
->finished
= 1;
450 client
->callback
.progress
.func(client
->callback
.progress
.arg
, client
, e
, progress
);
454 php_http_client_dequeue(client
, e
->request
);
460 static void handle_progress(void *arg
, php_http_client_t
*client
, php_http_client_enqueue_t
*e
, php_http_client_progress_state_t
*progress
)
462 zval
*zrequest
, *zprogress
, *zclient
, **args
[2];
463 php_http_client_object_t
*client_obj
= arg
;
464 zend_error_handling zeh
;
465 TSRMLS_FETCH_FROM_CTX(client
->ts
);
467 MAKE_STD_ZVAL(zclient
);
468 ZVAL_OBJVAL(zclient
, client_obj
->zv
, 1);
470 MAKE_STD_ZVAL(zrequest
);
471 ZVAL_OBJVAL(zrequest
, ((php_http_message_object_t
*) e
->opaque
)->zv
, 1);
474 MAKE_STD_ZVAL(zprogress
);
475 object_init(zprogress
);
476 add_property_bool(zprogress
, "started", progress
->started
);
477 add_property_bool(zprogress
, "finished", progress
->finished
);
478 add_property_string(zprogress
, "info", STR_PTR(progress
->info
), 1);
479 add_property_double(zprogress
, "dltotal", progress
->dl
.total
);
480 add_property_double(zprogress
, "dlnow", progress
->dl
.now
);
481 add_property_double(zprogress
, "ultotal", progress
->ul
.total
);
482 add_property_double(zprogress
, "ulnow", progress
->ul
.now
);
483 args
[1] = &zprogress
;
485 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh TSRMLS_CC
);
486 php_http_object_method_call(&client_obj
->notify
, zclient
, NULL
, 2, args TSRMLS_CC
);
487 zend_restore_error_handling(&zeh TSRMLS_CC
);
489 zval_ptr_dtor(&zclient
);
490 zval_ptr_dtor(&zrequest
);
491 zval_ptr_dtor(&zprogress
);
494 static void response_dtor(void *data
)
496 php_http_message_object_t
*msg_obj
= *(php_http_message_object_t
**) data
;
497 TSRMLS_FETCH_FROM_CTX(msg_obj
->message
->ts
);
499 zend_objects_store_del_ref_by_handle_ex(msg_obj
->zv
.handle
, msg_obj
->zv
.handlers TSRMLS_CC
);
502 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct
, 0, 0, 0)
503 ZEND_ARG_INFO(0, driver
)
504 ZEND_ARG_INFO(0, persistent_handle_id
)
506 static PHP_METHOD(HttpClient
, __construct
)
508 char *driver_str
= NULL
, *persistent_handle_str
= NULL
;
509 int driver_len
= 0, persistent_handle_len
= 0;
510 php_http_client_driver_t driver
;
511 php_resource_factory_t
*rf
= NULL
;
512 php_http_client_object_t
*obj
;
515 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|ss", &driver_str
, &driver_len
, &persistent_handle_str
, &persistent_handle_len
), invalid_arg
, return);
517 if (SUCCESS
!= php_http_client_driver_get(driver_str
, driver_len
, &driver
)) {
518 php_http_throw(unexpected_val
, "Failed to locate \"%s\" client request handler", driver_str
);
523 object_init_ex(os
, spl_ce_SplObjectStorage
);
524 zend_update_property(php_http_client_class_entry
, getThis(), ZEND_STRL("observers"), os TSRMLS_CC
);
527 if (persistent_handle_len
) {
530 php_persistent_handle_factory_t
*pf
;
532 name_len
= spprintf(&name_str
, 0, "http\\Client\\%s", driver
.name_str
);
533 php_http_pretty_key(name_str
+ sizeof("http\\Client"), driver
.name_len
, 1, 1);
535 if ((pf
= php_persistent_handle_concede(NULL
, name_str
, name_len
, persistent_handle_str
, persistent_handle_len
, NULL
, NULL TSRMLS_CC
))) {
536 rf
= php_resource_factory_init(NULL
, php_persistent_handle_get_resource_factory_ops(), pf
, (void (*)(void *)) php_persistent_handle_abandon
);
542 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
544 php_http_expect(obj
->client
= php_http_client_init(NULL
, driver
.client_ops
, rf
, NULL TSRMLS_CC
), runtime
, return);
546 php_http_object_method_init(&obj
->notify
, getThis(), ZEND_STRL("notify") TSRMLS_CC
);
548 obj
->client
->callback
.response
.func
= handle_response
;
549 obj
->client
->callback
.response
.arg
= obj
;
550 obj
->client
->callback
.progress
.func
= handle_progress
;
551 obj
->client
->callback
.progress
.arg
= obj
;
553 obj
->client
->responses
.dtor
= response_dtor
;
556 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_reset
, 0, 0, 0)
558 static PHP_METHOD(HttpClient
, reset
)
560 php_http_client_object_t
*obj
;
561 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
563 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
566 php_http_client_reset(obj
->client
);
568 RETVAL_ZVAL(getThis(), 1, 0);
571 static HashTable
*combined_options(zval
*client
, zval
*request TSRMLS_DC
)
575 zval
*z_roptions
= NULL
, *z_coptions
= zend_read_property(php_http_client_class_entry
, client
, ZEND_STRL("options"), 0 TSRMLS_CC
);
577 if (Z_TYPE_P(z_coptions
) == IS_ARRAY
) {
578 num_options
= zend_hash_num_elements(Z_ARRVAL_P(z_coptions
));
580 zend_call_method_with_0_params(&request
, NULL
, NULL
, "getOptions", &z_roptions
);
581 if (z_roptions
&& Z_TYPE_P(z_roptions
) == IS_ARRAY
) {
582 int num
= zend_hash_num_elements(Z_ARRVAL_P(z_roptions
));
583 if (num
> num_options
) {
587 ALLOC_HASHTABLE(options
);
588 ZEND_INIT_SYMTABLE_EX(options
, num_options
, 0);
589 if (Z_TYPE_P(z_coptions
) == IS_ARRAY
) {
590 array_copy(Z_ARRVAL_P(z_coptions
), options
);
593 if (Z_TYPE_P(z_roptions
) == IS_ARRAY
) {
594 array_join(Z_ARRVAL_P(z_roptions
), options
, 0, 0);
596 zval_ptr_dtor(&z_roptions
);
601 static void msg_queue_dtor(php_http_client_enqueue_t
*e
)
603 php_http_message_object_t
*msg_obj
= e
->opaque
;
604 TSRMLS_FETCH_FROM_CTX(msg_obj
->message
->ts
);
606 zend_objects_store_del_ref_by_handle_ex(msg_obj
->zv
.handle
, msg_obj
->zv
.handlers TSRMLS_CC
);
607 zend_hash_destroy(e
->options
);
608 FREE_HASHTABLE(e
->options
);
610 if (e
->closure
.fci
.size
) {
611 zval_ptr_dtor(&e
->closure
.fci
.function_name
);
612 if (e
->closure
.fci
.object_ptr
) {
613 zval_ptr_dtor(&e
->closure
.fci
.object_ptr
);
618 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enqueue
, 0, 0, 1)
619 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 0)
620 ZEND_ARG_INFO(0, callable
)
622 static PHP_METHOD(HttpClient
, enqueue
)
625 zend_fcall_info fci
= empty_fcall_info
;
626 zend_fcall_info_cache fcc
= empty_fcall_info_cache
;
627 php_http_client_object_t
*obj
;
628 php_http_message_object_t
*msg_obj
;
629 php_http_client_enqueue_t q
;
631 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O|f", &request
, php_http_client_request_class_entry
, &fci
, &fcc
), invalid_arg
, return);
633 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
634 msg_obj
= zend_object_store_get_object(request TSRMLS_CC
);
636 if (php_http_client_enqueued(obj
->client
, msg_obj
->message
, NULL
)) {
637 php_http_throw(bad_method_call
, "Failed to enqueue request; request already in queue", NULL
);
641 q
.request
= msg_obj
->message
;
642 q
.options
= combined_options(getThis(), request TSRMLS_CC
);
643 q
.dtor
= msg_queue_dtor
;
649 Z_ADDREF_P(fci
.function_name
);
650 if (fci
.object_ptr
) {
651 Z_ADDREF_P(fci
.object_ptr
);
655 zend_objects_store_add_ref_by_handle(msg_obj
->zv
.handle TSRMLS_CC
);
657 php_http_expect(SUCCESS
== php_http_client_enqueue(obj
->client
, &q
), runtime
,
662 RETVAL_ZVAL(getThis(), 1, 0);
665 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_dequeue
, 0, 0, 1)
666 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 0)
668 static PHP_METHOD(HttpClient
, dequeue
)
671 php_http_client_object_t
*obj
;
672 php_http_message_object_t
*msg_obj
;
674 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O", &request
, php_http_client_request_class_entry
), invalid_arg
, return);
676 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
677 msg_obj
= zend_object_store_get_object(request TSRMLS_CC
);
679 if (!php_http_client_enqueued(obj
->client
, msg_obj
->message
, NULL
)) {
680 php_http_throw(bad_method_call
, "Failed to dequeue request; request not in queue", NULL
);
684 php_http_expect(SUCCESS
== php_http_client_dequeue(obj
->client
, msg_obj
->message
), runtime
, return);
686 RETVAL_ZVAL(getThis(), 1, 0);
689 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_requeue
, 0, 0, 1)
690 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 0)
691 ZEND_ARG_INFO(0, callable
)
693 static PHP_METHOD(HttpClient
, requeue
)
696 zend_fcall_info fci
= empty_fcall_info
;
697 zend_fcall_info_cache fcc
= empty_fcall_info_cache
;
698 php_http_client_object_t
*obj
;
699 php_http_message_object_t
*msg_obj
;
700 php_http_client_enqueue_t q
;
702 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O|f", &request
, php_http_client_request_class_entry
, &fci
, &fcc
), invalid_arg
, return);
704 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
705 msg_obj
= zend_object_store_get_object(request TSRMLS_CC
);
707 if (php_http_client_enqueued(obj
->client
, msg_obj
->message
, NULL
)) {
708 php_http_expect(SUCCESS
== php_http_client_dequeue(obj
->client
, msg_obj
->message
), runtime
, return);
711 q
.request
= msg_obj
->message
;
712 q
.options
= combined_options(getThis(), request TSRMLS_CC
);
713 q
.dtor
= msg_queue_dtor
;
719 Z_ADDREF_P(fci
.function_name
);
720 if (fci
.object_ptr
) {
721 Z_ADDREF_P(fci
.object_ptr
);
725 zend_objects_store_add_ref_by_handle(msg_obj
->zv
.handle TSRMLS_CC
);
727 php_http_expect(SUCCESS
== php_http_client_enqueue(obj
->client
, &q
), runtime
,
732 RETVAL_ZVAL(getThis(), 1, 0);
735 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_count
, 0, 0, 0)
737 static PHP_METHOD(HttpClient
, count
)
739 long count_mode
= -1;
741 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &count_mode
)) {
742 php_http_client_object_t
*obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
744 RETVAL_LONG(zend_llist_count(&obj
->client
->requests
));
748 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getResponse
, 0, 0, 0)
749 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 1)
751 static PHP_METHOD(HttpClient
, getResponse
)
753 zval
*zrequest
= NULL
;
754 php_http_client_object_t
*obj
;
756 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|O", &zrequest
, php_http_client_request_class_entry
), invalid_arg
, return);
758 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
761 /* lookup the response with the request */
762 zend_llist_element
*el
= NULL
;
763 php_http_message_object_t
*req_obj
= zend_object_store_get_object(zrequest TSRMLS_CC
);
765 for (el
= obj
->client
->responses
.head
; el
; el
= el
->next
) {
766 php_http_message_object_t
*response_obj
= *(php_http_message_object_t
**) el
->data
;
768 if (response_obj
->message
->parent
== req_obj
->message
) {
769 RETURN_OBJVAL(response_obj
->zv
, 1);
773 /* not found for the request! */
774 php_http_throw(unexpected_val
, "Could not find response for the request", NULL
);
778 /* pop off the last response */
779 if (obj
->client
->responses
.tail
) {
780 php_http_message_object_t
*response_obj
= *(php_http_message_object_t
**) obj
->client
->responses
.tail
->data
;
784 RETVAL_OBJVAL(response_obj
->zv
, 1);
785 zend_llist_remove_tail(&obj
->client
->responses
);
790 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getHistory
, 0, 0, 0)
792 static PHP_METHOD(HttpClient
, getHistory
)
796 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
798 zhistory
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC
);
799 RETVAL_ZVAL(zhistory
, 1, 0);
802 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_send
, 0, 0, 0)
804 static PHP_METHOD(HttpClient
, send
)
806 php_http_client_object_t
*obj
;
808 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
810 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
812 php_http_expect(SUCCESS
== php_http_client_exec(obj
->client
), runtime
, return);
814 RETVAL_ZVAL(getThis(), 1, 0);
817 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_once
, 0, 0, 0)
819 static PHP_METHOD(HttpClient
, once
)
821 if (SUCCESS
== zend_parse_parameters_none()) {
822 php_http_client_object_t
*obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
824 RETURN_BOOL(0 < php_http_client_once(obj
->client
));
828 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_wait
, 0, 0, 0)
829 ZEND_ARG_INFO(0, timeout
)
831 static PHP_METHOD(HttpClient
, wait
)
835 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|d", &timeout
)) {
836 struct timeval timeout_val
;
837 php_http_client_object_t
*obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
839 timeout_val
.tv_sec
= (time_t) timeout
;
840 timeout_val
.tv_usec
= PHP_HTTP_USEC(timeout
) % PHP_HTTP_MCROSEC
;
842 RETURN_BOOL(SUCCESS
== php_http_client_wait(obj
->client
, timeout
> 0 ? &timeout_val
: NULL
));
846 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_configure
, 0, 0, 1)
847 ZEND_ARG_ARRAY_INFO(0, settings
, 1)
849 static PHP_METHOD(HttpClient
, configure
)
851 HashTable
*settings
= NULL
;
852 php_http_client_object_t
*obj
;
854 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|H!", &settings
), invalid_arg
, return);
855 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
857 php_http_expect(SUCCESS
== php_http_client_setopt(obj
->client
, PHP_HTTP_CLIENT_OPT_CONFIGURATION
, settings
), unexpected_val
, return);
859 RETVAL_ZVAL(getThis(), 1, 0);
862 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enablePipelining
, 0, 0, 0)
863 ZEND_ARG_INFO(0, enable
)
865 static PHP_METHOD(HttpClient
, enablePipelining
)
867 zend_bool enable
= 1;
868 php_http_client_object_t
*obj
;
870 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|b", &enable
), invalid_arg
, return);
872 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
874 php_http_expect(SUCCESS
== php_http_client_setopt(obj
->client
, PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
, &enable
), unexpected_val
, return);
876 RETVAL_ZVAL(getThis(), 1, 0);
879 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enableEvents
, 0, 0, 0)
880 ZEND_ARG_INFO(0, enable
)
882 static PHP_METHOD(HttpClient
, enableEvents
)
884 zend_bool enable
= 1;
885 php_http_client_object_t
*obj
;
887 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|b", &enable
), invalid_arg
, return);
889 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
891 php_http_expect(SUCCESS
== php_http_client_setopt(obj
->client
, PHP_HTTP_CLIENT_OPT_USE_EVENTS
, &enable
), unexpected_val
, return);
893 RETVAL_ZVAL(getThis(), 1, 0);
897 php_http_object_method_t
*cb
;
902 static int notify(zend_object_iterator
*iter
, void *puser TSRMLS_DC
)
904 zval
**observer
= NULL
;
905 struct notify_arg
*arg
= puser
;
907 iter
->funcs
->get_current_data(iter
, &observer TSRMLS_CC
);
909 return php_http_object_method_call(arg
->cb
, *observer
, NULL
, arg
->argc
, arg
->args TSRMLS_CC
);
914 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify
, 0, 0, 0)
915 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 1)
917 static PHP_METHOD(HttpClient
, notify
)
919 zval
*request
= NULL
, *zprogress
= NULL
, *observers
;
920 php_http_client_object_t
*client_obj
;
921 struct notify_arg arg
= {NULL
};
923 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|O!o!", &request
, php_http_client_request_class_entry
, &zprogress
), invalid_arg
, return);
925 client_obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
926 observers
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC
);
928 if (Z_TYPE_P(observers
) != IS_OBJECT
) {
929 php_http_throw(unexpected_val
, "Observer storage is corrupted", NULL
);
933 if (client_obj
->update
) {
934 arg
.cb
= client_obj
->update
;
936 Z_ADDREF_P(getThis());
937 arg
.args
[0] = &getThis();
942 arg
.args
[1] = &request
;
947 Z_ADDREF_P(zprogress
);
948 arg
.args
[2] = &zprogress
;
952 spl_iterator_apply(observers
, notify
, &arg TSRMLS_CC
);
954 zval_ptr_dtor(&getThis());
956 zval_ptr_dtor(&request
);
959 zval_ptr_dtor(&zprogress
);
963 RETVAL_ZVAL(getThis(), 1, 0);
966 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_attach
, 0, 0, 1)
967 ZEND_ARG_OBJ_INFO(0, observer
, SplObserver
, 0)
969 static PHP_METHOD(HttpClient
, attach
)
971 zval
*observers
, *observer
, *retval
= NULL
;
972 php_http_client_object_t
*client_obj
;
974 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O", &observer
, spl_ce_SplObserver
), invalid_arg
, return);
976 client_obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
977 observers
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC
);
979 if (Z_TYPE_P(observers
) != IS_OBJECT
) {
980 php_http_throw(unexpected_val
, "Observer storage is corrupted", NULL
);
984 if (!client_obj
->update
) {
985 client_obj
->update
= php_http_object_method_init(NULL
, observer
, ZEND_STRL("update") TSRMLS_CC
);
988 zend_call_method_with_1_params(&observers
, NULL
, NULL
, "attach", &retval
, observer
);
990 zval_ptr_dtor(&retval
);
993 RETVAL_ZVAL(getThis(), 1, 0);
996 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_detach
, 0, 0, 1)
997 ZEND_ARG_OBJ_INFO(0, observer
, SplObserver
, 0)
999 static PHP_METHOD(HttpClient
, detach
)
1001 zval
*observers
, *observer
, *retval
= NULL
;
1003 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O", &observer
, spl_ce_SplObserver
), invalid_arg
, return);
1005 observers
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC
);
1007 if (Z_TYPE_P(observers
) != IS_OBJECT
) {
1008 php_http_throw(unexpected_val
, "Observer storage is corrupted", NULL
);
1012 zend_call_method_with_1_params(&observers
, NULL
, NULL
, "detach", &retval
, observer
);
1014 zval_ptr_dtor(&retval
);
1017 RETVAL_ZVAL(getThis(), 1, 0);
1020 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getObservers
, 0, 0, 0)
1021 ZEND_END_ARG_INFO();
1022 static PHP_METHOD(HttpClient
, getObservers
)
1026 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1028 observers
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC
);
1030 if (Z_TYPE_P(observers
) != IS_OBJECT
) {
1031 php_http_throw(unexpected_val
, "Observer storage is corrupted", NULL
);
1035 RETVAL_ZVAL(observers
, 1, 0);
1038 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getProgressInfo
, 0, 0, 1)
1039 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 0)
1040 ZEND_END_ARG_INFO();
1041 static PHP_METHOD(HttpClient
, getProgressInfo
)
1044 php_http_client_object_t
*obj
;
1045 php_http_message_object_t
*req_obj
;
1046 php_http_client_progress_state_t
*progress
;
1048 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O", &request
, php_http_client_request_class_entry
), invalid_arg
, return);
1050 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
1051 req_obj
= zend_object_store_get_object(request TSRMLS_CC
);
1053 php_http_expect(SUCCESS
== php_http_client_getopt(obj
->client
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, req_obj
->message
, &progress
), unexpected_val
, return);
1055 object_init(return_value
);
1056 add_property_bool(return_value
, "started", progress
->started
);
1057 add_property_bool(return_value
, "finished", progress
->finished
);
1058 add_property_string(return_value
, "info", STR_PTR(progress
->info
), 1);
1059 add_property_double(return_value
, "dltotal", progress
->dl
.total
);
1060 add_property_double(return_value
, "dlnow", progress
->dl
.now
);
1061 add_property_double(return_value
, "ultotal", progress
->ul
.total
);
1062 add_property_double(return_value
, "ulnow", progress
->ul
.now
);
1065 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getTransferInfo
, 0, 0, 1)
1066 ZEND_ARG_OBJ_INFO(0, request
, http
\\Client
\\Request
, 0)
1067 ZEND_END_ARG_INFO();
1068 static PHP_METHOD(HttpClient
, getTransferInfo
)
1072 php_http_client_object_t
*obj
;
1073 php_http_message_object_t
*req_obj
;
1075 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O", &request
, php_http_client_request_class_entry
), invalid_arg
, return);
1077 obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
1078 req_obj
= zend_object_store_get_object(request TSRMLS_CC
);
1080 object_init(return_value
);
1081 info
= HASH_OF(return_value
);
1082 php_http_expect(SUCCESS
== php_http_client_getopt(obj
->client
, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
, req_obj
->message
, &info
), unexpected_val
, return);
1085 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setOptions
, 0, 0, 0)
1086 ZEND_ARG_ARRAY_INFO(0, options
, 1)
1087 ZEND_END_ARG_INFO();
1088 static PHP_METHOD(HttpClient
, setOptions
)
1092 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
), invalid_arg
, return);
1094 php_http_client_options_set(getThis(), opts TSRMLS_CC
);
1096 RETVAL_ZVAL(getThis(), 1, 0);
1099 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getOptions
, 0, 0, 0)
1100 ZEND_END_ARG_INFO();
1101 static PHP_METHOD(HttpClient
, getOptions
)
1103 if (SUCCESS
== zend_parse_parameters_none()) {
1104 zval
*options
= zend_read_property(php_http_client_class_entry
, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC
);
1105 RETVAL_ZVAL(options
, 1, 0);
1109 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setSslOptions
, 0, 0, 0)
1110 ZEND_ARG_ARRAY_INFO(0, ssl_option
, 1)
1111 ZEND_END_ARG_INFO();
1112 static PHP_METHOD(HttpClient
, setSslOptions
)
1116 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
), invalid_arg
, return);
1118 php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts
, 1 TSRMLS_CC
);
1120 RETVAL_ZVAL(getThis(), 1, 0);
1123 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addSslOptions
, 0, 0, 0)
1124 ZEND_ARG_ARRAY_INFO(0, ssl_options
, 1)
1125 ZEND_END_ARG_INFO();
1126 static PHP_METHOD(HttpClient
, addSslOptions
)
1130 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
), invalid_arg
, return);
1132 php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts
, 0 TSRMLS_CC
);
1134 RETVAL_ZVAL(getThis(), 1, 0);
1137 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getSslOptions
, 0, 0, 0)
1138 ZEND_END_ARG_INFO();
1139 static PHP_METHOD(HttpClient
, getSslOptions
)
1141 if (SUCCESS
== zend_parse_parameters_none()) {
1142 php_http_client_options_get_subr(getThis(), ZEND_STRS("ssl"), return_value TSRMLS_CC
);
1146 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setCookies
, 0, 0, 0)
1147 ZEND_ARG_ARRAY_INFO(0, cookies
, 1)
1148 ZEND_END_ARG_INFO();
1149 static PHP_METHOD(HttpClient
, setCookies
)
1153 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
), invalid_arg
, return);
1155 php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts
, 1 TSRMLS_CC
);
1157 RETVAL_ZVAL(getThis(), 1, 0);
1160 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addCookies
, 0, 0, 0)
1161 ZEND_ARG_ARRAY_INFO(0, cookies
, 1)
1162 ZEND_END_ARG_INFO();
1163 static PHP_METHOD(HttpClient
, addCookies
)
1167 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
), invalid_arg
, return);
1169 php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts
, 0 TSRMLS_CC
);
1171 RETVAL_ZVAL(getThis(), 1, 0);
1174 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getCookies
, 0, 0, 0)
1175 ZEND_END_ARG_INFO();
1176 static PHP_METHOD(HttpClient
, getCookies
)
1178 if (SUCCESS
== zend_parse_parameters_none()) {
1179 php_http_client_options_get_subr(getThis(), ZEND_STRS("cookies"), return_value TSRMLS_CC
);
1183 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableDrivers
, 0, 0, 0)
1184 ZEND_END_ARG_INFO();
1185 static PHP_METHOD(HttpClient
, getAvailableDrivers
) {
1186 if (SUCCESS
== zend_parse_parameters_none()) {
1187 array_init(return_value
);
1188 php_http_client_driver_list(Z_ARRVAL_P(return_value
) TSRMLS_CC
);
1192 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableOptions
, 0, 0, 0)
1193 ZEND_END_ARG_INFO();
1194 static PHP_METHOD(HttpClient
, getAvailableOptions
)
1196 if (SUCCESS
== zend_parse_parameters_none()) {
1197 php_http_client_object_t
*obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
1199 array_init(return_value
);
1200 php_http_client_getopt(obj
->client
, PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
, NULL
, &Z_ARRVAL_P(return_value
));
1204 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableConfiguration
, 0, 0, 0)
1205 ZEND_END_ARG_INFO();
1206 static PHP_METHOD(HttpClient
, getAvailableConfiguration
)
1208 if (SUCCESS
== zend_parse_parameters_none()) {
1209 php_http_client_object_t
*obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
1211 array_init(return_value
);
1212 php_http_client_getopt(obj
->client
, PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
, NULL
, &Z_ARRVAL_P(return_value
));
1216 static zend_function_entry php_http_client_methods
[] = {
1217 PHP_ME(HttpClient
, __construct
, ai_HttpClient_construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1218 PHP_ME(HttpClient
, reset
, ai_HttpClient_reset
, ZEND_ACC_PUBLIC
)
1219 PHP_ME(HttpClient
, enqueue
, ai_HttpClient_enqueue
, ZEND_ACC_PUBLIC
)
1220 PHP_ME(HttpClient
, dequeue
, ai_HttpClient_dequeue
, ZEND_ACC_PUBLIC
)
1221 PHP_ME(HttpClient
, requeue
, ai_HttpClient_requeue
, ZEND_ACC_PUBLIC
)
1222 PHP_ME(HttpClient
, count
, ai_HttpClient_count
, ZEND_ACC_PUBLIC
)
1223 PHP_ME(HttpClient
, send
, ai_HttpClient_send
, ZEND_ACC_PUBLIC
)
1224 PHP_ME(HttpClient
, once
, ai_HttpClient_once
, ZEND_ACC_PUBLIC
)
1225 PHP_ME(HttpClient
, wait
, ai_HttpClient_wait
, ZEND_ACC_PUBLIC
)
1226 PHP_ME(HttpClient
, getResponse
, ai_HttpClient_getResponse
, ZEND_ACC_PUBLIC
)
1227 PHP_ME(HttpClient
, getHistory
, ai_HttpClient_getHistory
, ZEND_ACC_PUBLIC
)
1228 PHP_ME(HttpClient
, configure
, ai_HttpClient_configure
, ZEND_ACC_PUBLIC
)
1229 PHP_ME(HttpClient
, enablePipelining
, ai_HttpClient_enablePipelining
, ZEND_ACC_PUBLIC
|ZEND_ACC_DEPRECATED
)
1230 PHP_ME(HttpClient
, enableEvents
, ai_HttpClient_enableEvents
, ZEND_ACC_PUBLIC
|ZEND_ACC_DEPRECATED
)
1231 PHP_ME(HttpClient
, notify
, ai_HttpClient_notify
, ZEND_ACC_PUBLIC
)
1232 PHP_ME(HttpClient
, attach
, ai_HttpClient_attach
, ZEND_ACC_PUBLIC
)
1233 PHP_ME(HttpClient
, detach
, ai_HttpClient_detach
, ZEND_ACC_PUBLIC
)
1234 PHP_ME(HttpClient
, getObservers
, ai_HttpClient_getObservers
, ZEND_ACC_PUBLIC
)
1235 PHP_ME(HttpClient
, getProgressInfo
, ai_HttpClient_getProgressInfo
, ZEND_ACC_PUBLIC
)
1236 PHP_ME(HttpClient
, getTransferInfo
, ai_HttpClient_getTransferInfo
, ZEND_ACC_PUBLIC
)
1237 PHP_ME(HttpClient
, setOptions
, ai_HttpClient_setOptions
, ZEND_ACC_PUBLIC
)
1238 PHP_ME(HttpClient
, getOptions
, ai_HttpClient_getOptions
, ZEND_ACC_PUBLIC
)
1239 PHP_ME(HttpClient
, setSslOptions
, ai_HttpClient_setSslOptions
, ZEND_ACC_PUBLIC
)
1240 PHP_ME(HttpClient
, addSslOptions
, ai_HttpClient_addSslOptions
, ZEND_ACC_PUBLIC
)
1241 PHP_ME(HttpClient
, getSslOptions
, ai_HttpClient_getSslOptions
, ZEND_ACC_PUBLIC
)
1242 PHP_ME(HttpClient
, setCookies
, ai_HttpClient_setCookies
, ZEND_ACC_PUBLIC
)
1243 PHP_ME(HttpClient
, addCookies
, ai_HttpClient_addCookies
, ZEND_ACC_PUBLIC
)
1244 PHP_ME(HttpClient
, getCookies
, ai_HttpClient_getCookies
, ZEND_ACC_PUBLIC
)
1245 PHP_ME(HttpClient
, getAvailableDrivers
, ai_HttpClient_getAvailableDrivers
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
1246 PHP_ME(HttpClient
, getAvailableOptions
, ai_HttpClient_getAvailableOptions
, ZEND_ACC_PUBLIC
)
1247 PHP_ME(HttpClient
, getAvailableConfiguration
, ai_HttpClient_getAvailableConfiguration
, ZEND_ACC_PUBLIC
)
1248 EMPTY_FUNCTION_ENTRY
1251 PHP_MINIT_FUNCTION(http_client
)
1253 zend_class_entry ce
= {0};
1255 INIT_NS_CLASS_ENTRY(ce
, "http", "Client", php_http_client_methods
);
1256 php_http_client_class_entry
= zend_register_internal_class_ex(&ce
, NULL
, NULL TSRMLS_CC
);
1257 php_http_client_class_entry
->create_object
= php_http_client_object_new
;
1258 zend_class_implements(php_http_client_class_entry TSRMLS_CC
, 2, spl_ce_SplSubject
, spl_ce_Countable
);
1259 memcpy(&php_http_client_object_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1260 php_http_client_object_handlers
.clone_obj
= NULL
;
1261 zend_declare_property_null(php_http_client_class_entry
, ZEND_STRL("observers"), ZEND_ACC_PRIVATE TSRMLS_CC
);
1262 zend_declare_property_null(php_http_client_class_entry
, ZEND_STRL("options"), ZEND_ACC_PROTECTED TSRMLS_CC
);
1263 zend_declare_property_null(php_http_client_class_entry
, ZEND_STRL("history"), ZEND_ACC_PROTECTED TSRMLS_CC
);
1264 zend_declare_property_bool(php_http_client_class_entry
, ZEND_STRL("recordHistory"), 0, ZEND_ACC_PUBLIC TSRMLS_CC
);
1266 zend_hash_init(&php_http_client_drivers
, 2, NULL
, NULL
, 1);
1271 PHP_MSHUTDOWN_FUNCTION(http_client
)
1273 zend_hash_destroy(&php_http_client_drivers
);
1282 * vim600: noet sw=4 ts=4 fdm=marker
1283 * vim<600: noet sw=4 ts=4