- less custom macro cruft
[m6w6/ext-http] / php_http_client.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
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-2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14 #include "php_http_client.h"
15
16 #include <ext/spl/spl_observer.h>
17
18 /*
19 * array of name => php_http_client_driver_t*
20 */
21 static HashTable php_http_client_drivers;
22
23 PHP_HTTP_API STATUS php_http_client_driver_add(php_http_client_driver_t *driver)
24 {
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);
26 }
27
28 PHP_HTTP_API STATUS php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver)
29 {
30 php_http_client_driver_t *tmp;
31
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))) {
34 *driver = *tmp;
35 return SUCCESS;
36 }
37 return FAILURE;
38 }
39
40 static int apply_driver_list(void *p, void *arg TSRMLS_DC)
41 {
42 php_http_client_driver_t *d = p;
43 zval *zname;
44
45 MAKE_STD_ZVAL(zname);
46 ZVAL_STRINGL(zname, d->name_str, d->name_len, 1);
47
48 zend_hash_next_index_insert(arg, &zname, sizeof(zval *), NULL);
49 return ZEND_HASH_APPLY_KEEP;
50 }
51
52 PHP_HTTP_API void php_http_client_driver_list(HashTable *ht TSRMLS_DC)
53 {
54 zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht TSRMLS_CC);
55 }
56
57 void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite TSRMLS_DC)
58 {
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;
62
63 MAKE_STD_ZVAL(new_opts);
64 array_init(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));
68 }
69
70 if (overwrite) {
71 if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
72 Z_ADDREF_P(opts);
73 zend_symtable_update(Z_ARRVAL_P(new_opts), key, len, (void *) &opts, sizeof(zval *), NULL);
74 } else {
75 zend_symtable_del(Z_ARRVAL_P(new_opts), key, len);
76 }
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);
80 } else {
81 Z_ADDREF_P(opts);
82 zend_symtable_update(Z_ARRVAL_P(new_opts), key, len, (void *) &opts, sizeof(zval *), NULL);
83 }
84 }
85
86 zend_update_property(this_ce, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC);
87 zval_ptr_dtor(&new_opts);
88 }
89 }
90
91 void php_http_client_options_set(zval *this_ptr, zval *opts TSRMLS_DC)
92 {
93 php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
94 HashPosition pos;
95 zval *new_opts;
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);
98
99 MAKE_STD_ZVAL(new_opts);
100 array_init(new_opts);
101
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);
105 } else {
106 zval *old_opts, *add_opts, **opt;
107
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);
122 }
123 } else {
124 Z_ADDREF_P(*opt);
125 add_assoc_zval_ex(add_opts, key.str, key.len, *opt);
126 }
127 }
128 }
129
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));
133 }
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);
138 }
139 }
140
141 void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value TSRMLS_DC)
142 {
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);
145
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);
148 }
149 }
150
151 static void queue_dtor(void *enqueued)
152 {
153 php_http_client_enqueue_t *e = enqueued;
154
155 if (e->dtor) {
156 e->dtor(e);
157 }
158 }
159
160 PHP_HTTP_API 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)
161 {
162 php_http_client_t *free_h = NULL;
163
164 if (!h) {
165 free_h = h = emalloc(sizeof(*h));
166 }
167 memset(h, 0, sizeof(*h));
168
169 h->ops = ops;
170 if (rf) {
171 h->rf = rf;
172 } else if (ops->rsrc) {
173 h->rf = php_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
174 }
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);
178
179 if (h->ops->init) {
180 if (!(h = h->ops->init(h, init_arg))) {
181 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Could not initialize client");
182 if (free_h) {
183 efree(h);
184 }
185 }
186 }
187
188 return h;
189 }
190
191 PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, php_http_client_t *to)
192 {
193 if (from->ops->copy) {
194 return from->ops->copy(from, to);
195 }
196
197 return NULL;
198 }
199
200 PHP_HTTP_API void php_http_client_dtor(php_http_client_t *h)
201 {
202 if (h->ops->dtor) {
203 h->ops->dtor(h);
204 }
205
206 zend_llist_clean(&h->requests);
207 zend_llist_clean(&h->responses);
208
209 php_resource_factory_free(&h->rf);
210 }
211
212 PHP_HTTP_API void php_http_client_free(php_http_client_t **h) {
213 if (*h) {
214 php_http_client_dtor(*h);
215 efree(*h);
216 *h = NULL;
217 }
218 }
219
220 PHP_HTTP_API STATUS php_http_client_enqueue(php_http_client_t *h, php_http_client_enqueue_t *enqueue)
221 {
222 TSRMLS_FETCH_FROM_CTX(h->ts);
223
224 if (h->ops->enqueue) {
225 if (php_http_client_enqueued(h, enqueue->request, NULL)) {
226 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to enqueue request; request already in queue");
227 return FAILURE;
228 }
229 return h->ops->enqueue(h, enqueue);
230 }
231
232 return FAILURE;
233 }
234
235 PHP_HTTP_API STATUS php_http_client_dequeue(php_http_client_t *h, php_http_message_t *request)
236 {
237 TSRMLS_FETCH_FROM_CTX(h->ts);
238
239 if (h->ops->dequeue) {
240 php_http_client_enqueue_t *enqueue = php_http_client_enqueued(h, request, NULL);
241
242 if (!enqueue) {
243 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to dequeue request; request not in queue");
244 return FAILURE;
245 }
246 return h->ops->dequeue(h, enqueue);
247 }
248 return FAILURE;
249 }
250
251 PHP_HTTP_API 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 {
253 zend_llist_element *el = NULL;
254
255 if (compare_func) {
256 for (el = h->requests.head; el; el = el->next) {
257 if (compare_func((php_http_client_enqueue_t *) el->data, compare_arg)) {
258 break;
259 }
260 }
261 } else {
262 for (el = h->requests.head; el; el = el->next) {
263 if (((php_http_client_enqueue_t *) el->data)->request == compare_arg) {
264 break;
265 }
266 }
267 }
268 return el ? (php_http_client_enqueue_t *) el->data : NULL;
269 }
270
271 PHP_HTTP_API STATUS php_http_client_wait(php_http_client_t *h, struct timeval *custom_timeout)
272 {
273 if (h->ops->wait) {
274 return h->ops->wait(h, custom_timeout);
275 }
276
277 return FAILURE;
278 }
279
280 PHP_HTTP_API int php_http_client_once(php_http_client_t *h)
281 {
282 if (h->ops->once) {
283 return h->ops->once(h);
284 }
285
286 return FAILURE;
287 }
288
289 PHP_HTTP_API STATUS php_http_client_exec(php_http_client_t *h)
290 {
291 if (h->ops->exec) {
292 return h->ops->exec(h);
293 }
294
295 return FAILURE;
296 }
297
298 PHP_HTTP_API void php_http_client_reset(php_http_client_t *h)
299 {
300 if (h->ops->reset) {
301 h->ops->reset(h);
302 }
303
304 zend_llist_clean(&h->requests);
305 zend_llist_clean(&h->responses);
306 }
307
308 PHP_HTTP_API STATUS php_http_client_setopt(php_http_client_t *h, php_http_client_setopt_opt_t opt, void *arg)
309 {
310 if (h->ops->setopt) {
311 return h->ops->setopt(h, opt, arg);
312 }
313
314 return FAILURE;
315 }
316
317 PHP_HTTP_API STATUS php_http_client_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg, void *res_ptr)
318 {
319 if (h->ops->getopt) {
320 return h->ops->getopt(h, opt, arg, res_ptr);
321 }
322 return FAILURE;
323 }
324
325 zend_class_entry *php_http_client_class_entry;
326 static zend_object_handlers php_http_client_object_handlers;
327
328 void php_http_client_object_free(void *object TSRMLS_DC)
329 {
330 php_http_client_object_t *o = (php_http_client_object_t *) object;
331
332 php_http_client_free(&o->client);
333 zend_object_std_dtor((zend_object *) o TSRMLS_CC);
334 efree(o);
335 }
336
337 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)
338 {
339 php_http_client_object_t *o;
340
341 o = ecalloc(1, sizeof(php_http_client_object_t));
342 zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
343 object_properties_init((zend_object *) o, ce);
344
345 o->client = client;
346
347 if (ptr) {
348 *ptr = o;
349 }
350
351 o->zv.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
352 o->zv.handlers = &php_http_client_object_handlers;
353
354 return o->zv;
355 }
356
357 zend_object_value php_http_client_object_new(zend_class_entry *ce TSRMLS_DC)
358 {
359 return php_http_client_object_new_ex(ce, NULL, NULL TSRMLS_CC);
360 }
361
362 static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response TSRMLS_DC)
363 {
364 zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC);
365 php_http_message_t *zipped = php_http_message_zip(response, request);
366 zend_object_value ov = php_http_message_object_new_ex(php_http_message_class_entry, zipped, NULL TSRMLS_CC);
367
368 MAKE_STD_ZVAL(new_hist);
369 ZVAL_OBJVAL(new_hist, ov, 0);
370
371 if (Z_TYPE_P(old_hist) == IS_OBJECT) {
372 php_http_message_object_prepend(new_hist, old_hist, 1 TSRMLS_CC);
373 }
374
375 zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), new_hist TSRMLS_CC);
376 zval_ptr_dtor(&new_hist);
377 }
378
379 static STATUS handle_response(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_message_t **request, php_http_message_t **response)
380 {
381 zval zclient;
382 php_http_message_t *msg;
383 php_http_client_progress_state_t *progress;
384 TSRMLS_FETCH_FROM_CTX(client->ts);
385
386 INIT_PZVAL(&zclient);
387 ZVAL_OBJVAL(&zclient, ((php_http_client_object_t*) arg)->zv, 0);
388
389 if ((msg = *response)) {
390 php_http_message_object_t *msg_obj;
391 zval *info, *zresponse, *zrequest;
392
393 if (i_zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
394 handle_history(&zclient, *request, *response TSRMLS_CC);
395 }
396
397 /* hard detach, redirects etc. are in the history */
398 php_http_message_free(&msg->parent);
399 *response = NULL;
400
401 MAKE_STD_ZVAL(zresponse);
402 ZVAL_OBJVAL(zresponse, php_http_message_object_new_ex(php_http_client_response_class_entry, msg, &msg_obj TSRMLS_CC), 0);
403
404 MAKE_STD_ZVAL(zrequest);
405 ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1);
406
407 php_http_message_object_prepend(zresponse, zrequest, 1 TSRMLS_CC);
408
409 MAKE_STD_ZVAL(info);
410 array_init(info);
411 php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &Z_ARRVAL_P(info));
412 zend_update_property(php_http_client_response_class_entry, zresponse, ZEND_STRL("transferInfo"), info TSRMLS_CC);
413 zval_ptr_dtor(&info);
414
415 zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
416 zend_llist_add_element(&client->responses, &msg_obj);
417
418 if (e->closure.fci.size) {
419 zval *retval = NULL;
420
421 zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 1, &zresponse);
422 with_error_handling(EH_NORMAL, NULL) {
423 zend_fcall_info_call(&e->closure.fci, &e->closure.fcc, &retval, NULL TSRMLS_CC);
424 } end_error_handling();
425 zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 0);
426
427 if (retval) {
428 if (Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)) {
429 php_http_client_dequeue(client, e->request);
430 }
431 zval_ptr_dtor(&retval);
432 }
433 }
434
435 zval_ptr_dtor(&zresponse);
436 zval_ptr_dtor(&zrequest);
437 }
438
439 if (SUCCESS == php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, e->request, &progress)) {
440 progress->info = "finished";
441 progress->finished = 1;
442 client->callback.progress.func(client->callback.progress.arg, client, e, progress);
443 }
444
445 return SUCCESS;
446 }
447
448 static void handle_progress(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *progress)
449 {
450 zval *zrequest, *zprogress, *retval = NULL, *zclient;
451 TSRMLS_FETCH_FROM_CTX(client->ts);
452
453 MAKE_STD_ZVAL(zclient);
454 ZVAL_OBJVAL(zclient, ((php_http_client_object_t *) arg)->zv, 1);
455 MAKE_STD_ZVAL(zrequest);
456 ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1);
457 MAKE_STD_ZVAL(zprogress);
458 object_init(zprogress);
459 add_property_bool(zprogress, "started", progress->started);
460 add_property_bool(zprogress, "finished", progress->finished);
461 add_property_string(zprogress, "info", STR_PTR(progress->info), 1);
462 add_property_double(zprogress, "dltotal", progress->dl.total);
463 add_property_double(zprogress, "dlnow", progress->dl.now);
464 add_property_double(zprogress, "ultotal", progress->ul.total);
465 add_property_double(zprogress, "ulnow", progress->ul.now);
466 with_error_handling(EH_NORMAL, NULL) {
467 zend_call_method_with_2_params(&zclient, NULL, NULL, "notify", &retval, zrequest, zprogress);
468 } end_error_handling();
469 zval_ptr_dtor(&zclient);
470 zval_ptr_dtor(&zrequest);
471 zval_ptr_dtor(&zprogress);
472 if (retval) {
473 zval_ptr_dtor(&retval);
474 }
475 }
476
477 static void response_dtor(void *data)
478 {
479 php_http_message_object_t *msg_obj = *(php_http_message_object_t **) data;
480 TSRMLS_FETCH_FROM_CTX(msg_obj->message->ts);
481
482 zend_objects_store_del_ref_by_handle_ex(msg_obj->zv.handle, msg_obj->zv.handlers TSRMLS_CC);
483 }
484
485 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0)
486 ZEND_ARG_INFO(0, driver)
487 ZEND_ARG_INFO(0, persistent_handle_id)
488 ZEND_END_ARG_INFO();
489 static PHP_METHOD(HttpClient, __construct)
490 {
491 with_error_handling(EH_THROW, php_http_exception_class_entry) {
492 char *driver_str = NULL, *persistent_handle_str = NULL;
493 int driver_len = 0, persistent_handle_len = 0;
494
495 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len)) {
496 php_http_client_driver_t driver;
497
498 if (SUCCESS == php_http_client_driver_get(driver_str, driver_len, &driver)) {
499 php_resource_factory_t *rf = NULL;
500 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
501 zval *os;
502
503 MAKE_STD_ZVAL(os);
504 object_init_ex(os, spl_ce_SplObjectStorage);
505 zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), os TSRMLS_CC);
506 zval_ptr_dtor(&os);
507
508 if (persistent_handle_len) {
509 char *name_str;
510 size_t name_len;
511 php_persistent_handle_factory_t *pf;
512
513 name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver.name_str);
514 php_http_pretty_key(name_str + sizeof("http\\Client"), driver.name_len, 1, 1);
515
516 if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL TSRMLS_CC))) {
517 rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon);
518 }
519
520 efree(name_str);
521 }
522
523 if ((obj->client = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC))) {
524 obj->client->callback.response.func = handle_response;
525 obj->client->callback.response.arg = obj;
526 obj->client->callback.progress.func = handle_progress;
527 obj->client->callback.progress.arg = obj;
528
529 obj->client->responses.dtor = response_dtor;
530 }
531 } else {
532 php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_FACTORY, "Failed to locate \"%s\" client request handler", driver_str);
533 }
534 }
535 } end_error_handling();
536 }
537
538 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_reset, 0, 0, 0)
539 ZEND_END_ARG_INFO();
540 static PHP_METHOD(HttpClient, reset)
541 {
542 if (SUCCESS == zend_parse_parameters_none()) {
543 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
544
545 obj->iterator = 0;
546 php_http_client_reset(obj->client);
547 }
548 RETVAL_ZVAL(getThis(), 1, 0);
549 }
550
551 static HashTable *combined_options(zval *client, zval *request TSRMLS_DC)
552 {
553 HashTable *options;
554 int num_options = 0;
555 zval *z_roptions = NULL, *z_coptions = zend_read_property(php_http_client_class_entry, client, ZEND_STRL("options"), 0 TSRMLS_CC);
556
557 if (Z_TYPE_P(z_coptions) == IS_ARRAY) {
558 num_options = zend_hash_num_elements(Z_ARRVAL_P(z_coptions));
559 }
560 zend_call_method_with_0_params(&request, NULL, NULL, "getOptions", &z_roptions);
561 if (z_roptions && Z_TYPE_P(z_roptions) == IS_ARRAY) {
562 int num = zend_hash_num_elements(Z_ARRVAL_P(z_roptions));
563 if (num > num_options) {
564 num_options = num;
565 }
566 }
567 ALLOC_HASHTABLE(options);
568 ZEND_INIT_SYMTABLE_EX(options, num_options, 0);
569 if (Z_TYPE_P(z_coptions) == IS_ARRAY) {
570 array_copy(Z_ARRVAL_P(z_coptions), options);
571 }
572 if (z_roptions) {
573 if (Z_TYPE_P(z_roptions) == IS_ARRAY) {
574 array_join(Z_ARRVAL_P(z_roptions), options, 0, 0);
575 }
576 zval_ptr_dtor(&z_roptions);
577 }
578 return options;
579 }
580
581 static void msg_queue_dtor(php_http_client_enqueue_t *e)
582 {
583 php_http_message_object_t *msg_obj = e->opaque;
584 TSRMLS_FETCH_FROM_CTX(msg_obj->message->ts);
585
586 zend_objects_store_del_ref_by_handle_ex(msg_obj->zv.handle, msg_obj->zv.handlers TSRMLS_CC);
587 zend_hash_destroy(e->options);
588 FREE_HASHTABLE(e->options);
589
590 if (e->closure.fci.size) {
591 zval_ptr_dtor(&e->closure.fci.function_name);
592 if (e->closure.fci.object_ptr) {
593 zval_ptr_dtor(&e->closure.fci.object_ptr);
594 }
595 }
596 }
597
598 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enqueue, 0, 0, 1)
599 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 0)
600 ZEND_ARG_INFO(0, callable)
601 ZEND_END_ARG_INFO();
602 static PHP_METHOD(HttpClient, enqueue)
603 {
604 with_error_handling(EH_THROW, php_http_exception_class_entry) {
605 zval *request;
606 zend_fcall_info fci = empty_fcall_info;
607 zend_fcall_info_cache fcc = empty_fcall_info_cache;
608
609 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc)) {
610 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
611 php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
612
613 if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
614 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to enqueue request; request already in queue");
615 } else {
616 php_http_client_enqueue_t q = {
617 msg_obj->message,
618 combined_options(getThis(), request TSRMLS_CC),
619 msg_queue_dtor,
620 msg_obj,
621 {fci, fcc}
622 };
623
624 if (fci.size) {
625 Z_ADDREF_P(fci.function_name);
626 if (fci.object_ptr) {
627 Z_ADDREF_P(fci.object_ptr);
628 }
629 }
630
631 zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
632 php_http_client_enqueue(obj->client, &q);
633 }
634 }
635 } end_error_handling();
636
637 RETVAL_ZVAL(getThis(), 1, 0);
638 }
639
640 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_dequeue, 0, 0, 1)
641 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 0)
642 ZEND_END_ARG_INFO();
643 static PHP_METHOD(HttpClient, dequeue)
644 {
645 with_error_handling(EH_THROW, php_http_exception_class_entry) {
646 zval *request;
647
648 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
649 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
650 php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
651
652 php_http_client_dequeue(obj->client, msg_obj->message);
653 }
654 } end_error_handling();
655
656 RETVAL_ZVAL(getThis(), 1, 0);
657 }
658
659 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_requeue, 0, 0, 1)
660 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 0)
661 ZEND_ARG_INFO(0, callable)
662 ZEND_END_ARG_INFO();
663 static PHP_METHOD(HttpClient, requeue)
664 {
665 with_error_handling(EH_THROW, php_http_exception_class_entry) {
666 zval *request;
667 zend_fcall_info fci = empty_fcall_info;
668 zend_fcall_info_cache fcc = empty_fcall_info_cache;
669
670 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc)) {
671 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
672 php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
673 php_http_client_enqueue_t q = {
674 msg_obj->message,
675 combined_options(getThis(), request TSRMLS_CC),
676 msg_queue_dtor,
677 msg_obj,
678 {fci, fcc}
679 };
680
681 if (fci.size) {
682 Z_ADDREF_P(fci.function_name);
683 if (fci.object_ptr) {
684 Z_ADDREF_P(fci.object_ptr);
685 }
686 }
687
688 zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
689 if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
690 php_http_client_dequeue(obj->client, msg_obj->message);
691 }
692 php_http_client_enqueue(obj->client, &q);
693 }
694 } end_error_handling();
695
696 RETVAL_ZVAL(getThis(), 1, 0);
697 }
698
699 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getResponse, 0, 0, 0)
700 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 1)
701 ZEND_END_ARG_INFO();
702 static PHP_METHOD(HttpClient, getResponse)
703 {
704 zval *zrequest = NULL;
705
706 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_class_entry)) {
707 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
708
709 if (!zrequest) {
710 /* pop off the last respone */
711 if (obj->client->responses.tail) {
712 php_http_message_object_t *response_obj = *(php_http_message_object_t **) obj->client->responses.tail->data;
713
714 /* pop off and go */
715 if (response_obj) {
716 RETVAL_OBJVAL(response_obj->zv, 1);
717 zend_llist_remove_tail(&obj->client->responses);
718 }
719 }
720 } else {
721 /* lookup the response with the request */
722 zend_llist_element *el = NULL;
723 php_http_message_object_t *req_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
724
725 for (el = obj->client->responses.head; el; el = el->next) {
726 php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data;
727
728 if (response_obj->message->parent == req_obj->message) {
729 RETVAL_OBJVAL(response_obj->zv, 1);
730 break;
731 }
732 }
733 }
734 }
735 }
736
737 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getHistory, 0, 0, 0)
738 ZEND_END_ARG_INFO();
739 static PHP_METHOD(HttpClient, getHistory)
740 {
741 if (SUCCESS == zend_parse_parameters_none()) {
742 zval *zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC);
743 RETVAL_ZVAL(zhistory, 1, 0);
744 }
745 }
746
747 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_send, 0, 0, 0)
748 ZEND_END_ARG_INFO();
749 static PHP_METHOD(HttpClient, send)
750 {
751 RETVAL_FALSE;
752
753 with_error_handling(EH_THROW, php_http_exception_class_entry) {
754 if (SUCCESS == zend_parse_parameters_none()) {
755 with_error_handling(EH_THROW, php_http_exception_class_entry) {
756 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
757
758 php_http_client_exec(obj->client);
759 } end_error_handling();
760 }
761 } end_error_handling();
762
763 RETVAL_ZVAL(getThis(), 1, 0);
764 }
765
766 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_once, 0, 0, 0)
767 ZEND_END_ARG_INFO();
768 static PHP_METHOD(HttpClient, once)
769 {
770 if (SUCCESS == zend_parse_parameters_none()) {
771 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
772
773 if (0 < php_http_client_once(obj->client)) {
774 RETURN_TRUE;
775 }
776 }
777 RETURN_FALSE;
778 }
779
780 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_wait, 0, 0, 0)
781 ZEND_ARG_INFO(0, timeout)
782 ZEND_END_ARG_INFO();
783 static PHP_METHOD(HttpClient, wait)
784 {
785 double timeout = 0;
786
787 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout)) {
788 struct timeval timeout_val;
789 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
790
791 timeout_val.tv_sec = (time_t) timeout;
792 timeout_val.tv_usec = PHP_HTTP_USEC(timeout) % PHP_HTTP_MCROSEC;
793
794 RETURN_BOOL(SUCCESS == php_http_client_wait(obj->client, timeout > 0 ? &timeout_val : NULL));
795 }
796 RETURN_FALSE;
797 }
798
799 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enablePipelining, 0, 0, 0)
800 ZEND_ARG_INFO(0, enable)
801 ZEND_END_ARG_INFO();
802 static PHP_METHOD(HttpClient, enablePipelining)
803 {
804 zend_bool enable = 1;
805
806 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
807 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
808
809 php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING, &enable);
810 }
811 RETVAL_ZVAL(getThis(), 1, 0);
812 }
813
814 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enableEvents, 0, 0, 0)
815 ZEND_ARG_INFO(0, enable)
816 ZEND_END_ARG_INFO();
817 static PHP_METHOD(HttpClient, enableEvents)
818 {
819 zend_bool enable = 1;
820
821 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
822 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
823
824 php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_USE_EVENTS, &enable);
825 }
826 RETVAL_ZVAL(getThis(), 1, 0);
827 }
828
829 static int notify(zend_object_iterator *iter, void *puser TSRMLS_DC)
830 {
831 zval **observer = NULL, ***args = puser;
832
833 iter->funcs->get_current_data(iter, &observer TSRMLS_CC);
834 if (observer) {
835 return php_http_method_call(*observer, ZEND_STRL("update"), args[2]?3:args[1]?2:args[0]?1:0, args, NULL TSRMLS_CC);
836 }
837 return FAILURE;
838 }
839
840 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify, 0, 0, 0)
841 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 1)
842 ZEND_END_ARG_INFO();
843 static PHP_METHOD(HttpClient, notify)
844 {
845 zval *request = NULL, *zprogress = NULL;
846
847 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_class_entry, &zprogress)) {
848 zval **args[3], *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
849
850 if (Z_TYPE_P(observers) == IS_OBJECT) {
851 Z_ADDREF_P(getThis());
852 args[0] = &getThis();
853 if (request) {
854 Z_ADDREF_P(request);
855 }
856 args[1] = &request;
857 if (zprogress) {
858 Z_ADDREF_P(zprogress);
859 }
860 args[2] = &zprogress;
861 spl_iterator_apply(observers, notify, args TSRMLS_CC);
862 zval_ptr_dtor(&getThis());
863 if (request) {
864 zval_ptr_dtor(&request);
865 }
866 if (zprogress) {
867 zval_ptr_dtor(&zprogress);
868 }
869 }
870 }
871
872 RETVAL_ZVAL(getThis(), 1, 0);
873 }
874
875 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_attach, 0, 0, 1)
876 ZEND_ARG_OBJ_INFO(0, observer, SplObserver, 0)
877 ZEND_END_ARG_INFO();
878 static PHP_METHOD(HttpClient, attach)
879 {
880 zval *observer;
881
882 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver)) {
883 zval *retval = NULL, *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
884 zend_call_method_with_1_params(&observers, NULL, NULL, "attach", &retval, observer);
885 if (retval) {
886 zval_ptr_dtor(&retval);
887 }
888 }
889
890 RETVAL_ZVAL(getThis(), 1, 0);
891 }
892
893 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_detach, 0, 0, 1)
894 ZEND_ARG_OBJ_INFO(0, observer, SplObserver, 0)
895 ZEND_END_ARG_INFO();
896 static PHP_METHOD(HttpClient, detach)
897 {
898 zval *observer;
899
900 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver)) {
901 zval *retval, *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
902 zend_call_method_with_1_params(&observers, NULL, NULL, "detach", &retval, observer);
903 zval_ptr_dtor(&retval);
904 }
905
906 RETVAL_ZVAL(getThis(), 1, 0);
907 }
908
909 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getObservers, 0, 0, 0)
910 ZEND_END_ARG_INFO();
911 static PHP_METHOD(HttpClient, getObservers)
912 {
913 with_error_handling(EH_THROW, php_http_exception_class_entry) {
914 if (SUCCESS == zend_parse_parameters_none()) {
915 zval *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
916 RETVAL_ZVAL(observers, 1, 0);
917 }
918 } end_error_handling();
919 }
920
921 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getProgressInfo, 0, 0, 1)
922 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 0)
923 ZEND_END_ARG_INFO();
924 static PHP_METHOD(HttpClient, getProgressInfo)
925 {
926 zval *request;
927
928 with_error_handling(EH_THROW, php_http_exception_class_entry) {
929 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
930 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
931 php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
932 php_http_client_progress_state_t *progress;
933
934 if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, req_obj->message, &progress)) {
935 object_init(return_value);
936 add_property_bool(return_value, "started", progress->started);
937 add_property_bool(return_value, "finished", progress->finished);
938 add_property_string(return_value, "info", STR_PTR(progress->info), 1);
939 add_property_double(return_value, "dltotal", progress->dl.total);
940 add_property_double(return_value, "dlnow", progress->dl.now);
941 add_property_double(return_value, "ultotal", progress->ul.total);
942 add_property_double(return_value, "ulnow", progress->ul.now);
943 }
944 }
945 } end_error_handling();
946 }
947
948 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getTransferInfo, 0, 0, 1)
949 ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 0)
950 ZEND_END_ARG_INFO();
951 static PHP_METHOD(HttpClient, getTransferInfo)
952 {
953 zval *request;
954
955 with_error_handling(EH_THROW, php_http_exception_class_entry) {
956 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
957 php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
958 php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
959
960 array_init(return_value);
961 php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &Z_ARRVAL_P(return_value));
962 }
963 } end_error_handling();
964 }
965
966 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setOptions, 0, 0, 0)
967 ZEND_ARG_ARRAY_INFO(0, options, 1)
968 ZEND_END_ARG_INFO();
969 static PHP_METHOD(HttpClient, setOptions)
970 {
971 zval *opts = NULL;
972
973 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
974 php_http_client_options_set(getThis(), opts TSRMLS_CC);
975
976 RETVAL_ZVAL(getThis(), 1, 0);
977 }
978 }
979
980 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getOptions, 0, 0, 0)
981 ZEND_END_ARG_INFO();
982 static PHP_METHOD(HttpClient, getOptions)
983 {
984 if (SUCCESS == zend_parse_parameters_none()) {
985 zval *options = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
986 RETVAL_ZVAL(options, 1, 0);
987 }
988 }
989
990 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setSslOptions, 0, 0, 0)
991 ZEND_ARG_ARRAY_INFO(0, ssl_option, 1)
992 ZEND_END_ARG_INFO();
993 static PHP_METHOD(HttpClient, setSslOptions)
994 {
995 zval *opts = NULL;
996
997 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
998 php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
999
1000 RETVAL_ZVAL(getThis(), 1, 0);
1001 }
1002 }
1003
1004 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addSslOptions, 0, 0, 0)
1005 ZEND_ARG_ARRAY_INFO(0, ssl_options, 1)
1006 ZEND_END_ARG_INFO();
1007 static PHP_METHOD(HttpClient, addSslOptions)
1008 {
1009 zval *opts = NULL;
1010
1011 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
1012 php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
1013
1014 RETVAL_ZVAL(getThis(), 1, 0);
1015 }
1016 }
1017
1018 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getSslOptions, 0, 0, 0)
1019 ZEND_END_ARG_INFO();
1020 static PHP_METHOD(HttpClient, getSslOptions)
1021 {
1022 if (SUCCESS == zend_parse_parameters_none()) {
1023 php_http_client_options_get_subr(getThis(), ZEND_STRS("ssl"), return_value TSRMLS_CC);
1024 }
1025 }
1026
1027 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setCookies, 0, 0, 0)
1028 ZEND_ARG_ARRAY_INFO(0, cookies, 1)
1029 ZEND_END_ARG_INFO();
1030 static PHP_METHOD(HttpClient, setCookies)
1031 {
1032 zval *opts = NULL;
1033
1034 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
1035 php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 1 TSRMLS_CC);
1036
1037 RETVAL_ZVAL(getThis(), 1, 0);
1038 }
1039 }
1040
1041 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addCookies, 0, 0, 0)
1042 ZEND_ARG_ARRAY_INFO(0, cookies, 1)
1043 ZEND_END_ARG_INFO();
1044 static PHP_METHOD(HttpClient, addCookies)
1045 {
1046 zval *opts = NULL;
1047
1048 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
1049 php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
1050
1051 RETVAL_ZVAL(getThis(), 1, 0);
1052 }
1053 }
1054
1055 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getCookies, 0, 0, 0)
1056 ZEND_END_ARG_INFO();
1057 static PHP_METHOD(HttpClient, getCookies)
1058 {
1059 if (SUCCESS == zend_parse_parameters_none()) {
1060 php_http_client_options_get_subr(getThis(), ZEND_STRS("cookies"), return_value TSRMLS_CC);
1061 }
1062 }
1063
1064 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableDrivers, 0, 0, 0)
1065 ZEND_END_ARG_INFO();
1066 static PHP_METHOD(HttpClient, getAvailableDrivers) {
1067 if (SUCCESS == zend_parse_parameters_none()) {
1068 array_init(return_value);
1069 php_http_client_driver_list(Z_ARRVAL_P(return_value) TSRMLS_CC);
1070 }
1071 }
1072
1073 static zend_function_entry php_http_client_methods[] = {
1074 PHP_ME(HttpClient, __construct, ai_HttpClient_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1075 PHP_ME(HttpClient, reset, ai_HttpClient_reset, ZEND_ACC_PUBLIC)
1076 PHP_ME(HttpClient, enqueue, ai_HttpClient_enqueue, ZEND_ACC_PUBLIC)
1077 PHP_ME(HttpClient, dequeue, ai_HttpClient_dequeue, ZEND_ACC_PUBLIC)
1078 PHP_ME(HttpClient, requeue, ai_HttpClient_requeue, ZEND_ACC_PUBLIC)
1079 PHP_ME(HttpClient, send, ai_HttpClient_send, ZEND_ACC_PUBLIC)
1080 PHP_ME(HttpClient, once, ai_HttpClient_once, ZEND_ACC_PUBLIC)
1081 PHP_ME(HttpClient, wait, ai_HttpClient_wait, ZEND_ACC_PUBLIC)
1082 PHP_ME(HttpClient, getResponse, ai_HttpClient_getResponse, ZEND_ACC_PUBLIC)
1083 PHP_ME(HttpClient, getHistory, ai_HttpClient_getHistory, ZEND_ACC_PUBLIC)
1084 PHP_ME(HttpClient, enablePipelining, ai_HttpClient_enablePipelining, ZEND_ACC_PUBLIC)
1085 PHP_ME(HttpClient, enableEvents, ai_HttpClient_enableEvents, ZEND_ACC_PUBLIC)
1086 PHP_ME(HttpClient, notify, ai_HttpClient_notify, ZEND_ACC_PUBLIC)
1087 PHP_ME(HttpClient, attach, ai_HttpClient_attach, ZEND_ACC_PUBLIC)
1088 PHP_ME(HttpClient, detach, ai_HttpClient_detach, ZEND_ACC_PUBLIC)
1089 PHP_ME(HttpClient, getObservers, ai_HttpClient_getObservers, ZEND_ACC_PUBLIC)
1090 PHP_ME(HttpClient, getProgressInfo, ai_HttpClient_getProgressInfo, ZEND_ACC_PUBLIC)
1091 PHP_ME(HttpClient, getTransferInfo, ai_HttpClient_getTransferInfo, ZEND_ACC_PUBLIC)
1092 PHP_ME(HttpClient, setOptions, ai_HttpClient_setOptions, ZEND_ACC_PUBLIC)
1093 PHP_ME(HttpClient, getOptions, ai_HttpClient_getOptions, ZEND_ACC_PUBLIC)
1094 PHP_ME(HttpClient, setSslOptions, ai_HttpClient_setSslOptions, ZEND_ACC_PUBLIC)
1095 PHP_ME(HttpClient, addSslOptions, ai_HttpClient_addSslOptions, ZEND_ACC_PUBLIC)
1096 PHP_ME(HttpClient, getSslOptions, ai_HttpClient_getSslOptions, ZEND_ACC_PUBLIC)
1097 PHP_ME(HttpClient, setCookies, ai_HttpClient_setCookies, ZEND_ACC_PUBLIC)
1098 PHP_ME(HttpClient, addCookies, ai_HttpClient_addCookies, ZEND_ACC_PUBLIC)
1099 PHP_ME(HttpClient, getCookies, ai_HttpClient_getCookies, ZEND_ACC_PUBLIC)
1100 PHP_ME(HttpClient, getAvailableDrivers, ai_HttpClient_getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1101 EMPTY_FUNCTION_ENTRY
1102 };
1103
1104 PHP_MINIT_FUNCTION(http_client)
1105 {
1106 zend_class_entry ce = {0};
1107
1108 INIT_NS_CLASS_ENTRY(ce, "http", "Client", php_http_client_methods);
1109 php_http_client_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
1110 php_http_client_class_entry->create_object = php_http_client_object_new;
1111 zend_class_implements(php_http_client_class_entry TSRMLS_CC, 1, spl_ce_SplSubject);
1112 memcpy(&php_http_client_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1113 php_http_client_object_handlers.clone_obj = NULL;
1114 zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE TSRMLS_CC);
1115 zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED TSRMLS_CC);
1116 zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("history"), ZEND_ACC_PROTECTED TSRMLS_CC);
1117 zend_declare_property_bool(php_http_client_class_entry, ZEND_STRL("recordHistory"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
1118
1119 zend_hash_init(&php_http_client_drivers, 2, NULL, NULL, 1);
1120
1121 return SUCCESS;
1122 }
1123
1124 PHP_MSHUTDOWN_FUNCTION(http_client)
1125 {
1126 zend_hash_destroy(&php_http_client_drivers);
1127 return SUCCESS;
1128 }
1129
1130 /*
1131 * Local variables:
1132 * tab-width: 4
1133 * c-basic-offset: 4
1134 * End:
1135 * vim600: noet sw=4 ts=4 fdm=marker
1136 * vim<600: noet sw=4 ts=4
1137 */