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