Possible null pointer dereference in php_http_url_mod() fixed.
[m6w6/ext-http] / src / php_http_client.h
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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_CLIENT_H
14 #define PHP_HTTP_CLIENT_H
15
16 typedef enum php_http_client_setopt_opt {
17 PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING,
18 PHP_HTTP_CLIENT_OPT_USE_EVENTS,
19 PHP_HTTP_CLIENT_OPT_CONFIGURATION,
20 } php_http_client_setopt_opt_t;
21
22 typedef enum php_http_client_getopt_opt {
23 PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, /* php_http_client_enqueue_t*, php_http_client_progress_state_t** */
24 PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, /* php_http_client_enqueue_t*, HashTable* */
25 PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS, /* NULL, HashTable* */
26 PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION,/* NULL, HashTable */
27 } php_http_client_getopt_opt_t;
28
29 typedef struct php_http_client_enqueue {
30 php_http_message_t *request; /* unique */
31 HashTable *options;
32 void (*dtor)(struct php_http_client_enqueue *);
33 void *opaque;
34 struct {
35 zend_fcall_info fci;
36 zend_fcall_info_cache fcc;
37 } closure;
38 } php_http_client_enqueue_t;
39
40 typedef struct php_http_client *(*php_http_client_init_func_t)(struct php_http_client *p, void *init_arg);
41 typedef struct php_http_client *(*php_http_client_copy_func_t)(struct php_http_client *from, struct php_http_client *to);
42 typedef void (*php_http_client_dtor_func_t)(struct php_http_client *p);
43 typedef void (*php_http_client_reset_func_t)(struct php_http_client *p);
44 typedef ZEND_RESULT_CODE (*php_http_client_exec_func_t)(struct php_http_client *p);
45 typedef int (*php_http_client_once_func_t)(struct php_http_client *p);
46 typedef ZEND_RESULT_CODE (*php_http_client_wait_func_t)(struct php_http_client *p, struct timeval *custom_timeout);
47 typedef ZEND_RESULT_CODE (*php_http_client_enqueue_func_t)(struct php_http_client *p, php_http_client_enqueue_t *enqueue);
48 typedef ZEND_RESULT_CODE (*php_http_client_dequeue_func_t)(struct php_http_client *p, php_http_client_enqueue_t *enqueue);
49 typedef ZEND_RESULT_CODE (*php_http_client_setopt_func_t)(struct php_http_client *p, php_http_client_setopt_opt_t opt, void *arg);
50 typedef ZEND_RESULT_CODE (*php_http_client_getopt_func_t)(struct php_http_client *h, php_http_client_getopt_opt_t opt, void *arg, void **res);
51
52 typedef struct php_http_client_ops {
53 php_resource_factory_ops_t *rsrc;
54 php_http_client_init_func_t init;
55 php_http_client_copy_func_t copy;
56 php_http_client_dtor_func_t dtor;
57 php_http_client_reset_func_t reset;
58 php_http_client_exec_func_t exec;
59 php_http_client_wait_func_t wait;
60 php_http_client_once_func_t once;
61 php_http_client_enqueue_func_t enqueue;
62 php_http_client_dequeue_func_t dequeue;
63 php_http_client_setopt_func_t setopt;
64 php_http_client_getopt_func_t getopt;
65 } php_http_client_ops_t;
66
67 typedef struct php_http_client_driver {
68 const char *name_str;
69 size_t name_len;
70 php_http_client_ops_t *client_ops;
71 } php_http_client_driver_t;
72
73 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver);
74 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver);
75
76 typedef struct php_http_client_progress_state {
77 struct {
78 double now;
79 double total;
80 } ul;
81 struct {
82 double now;
83 double total;
84 } dl;
85 const char *info;
86 unsigned started:1;
87 unsigned finished:1;
88 } php_http_client_progress_state_t;
89
90 typedef ZEND_RESULT_CODE (*php_http_client_response_callback_t)(void *arg, struct php_http_client *client, php_http_client_enqueue_t *e, php_http_message_t **response);
91 typedef void (*php_http_client_progress_callback_t)(void *arg, struct php_http_client *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *state);
92
93 typedef struct php_http_client {
94 void *ctx;
95 php_resource_factory_t *rf;
96 php_http_client_ops_t *ops;
97
98 struct {
99 struct {
100 php_http_client_response_callback_t func;
101 void *arg;
102 } response;
103 struct {
104 php_http_client_progress_callback_t func;
105 void *arg;
106 } progress;
107 } callback;
108
109 zend_llist requests;
110 zend_llist responses;
111
112 #ifdef ZTS
113 void ***ts;
114 #endif
115 } php_http_client_t;
116
117 PHP_HTTP_API zend_class_entry *php_http_client_class_entry;
118
119 typedef struct php_http_client_object {
120 zend_object zo;
121 zend_object_value zv;
122 php_http_client_t *client;
123 long iterator;
124 php_http_object_method_t *update;
125 php_http_object_method_t notify;
126 } php_http_client_object_t;
127
128 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);
129 PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, php_http_client_t *to);
130 PHP_HTTP_API void php_http_client_dtor(php_http_client_t *h);
131 PHP_HTTP_API void php_http_client_free(php_http_client_t **h);
132
133 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_enqueue(php_http_client_t *h, php_http_client_enqueue_t *enqueue);
134 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_dequeue(php_http_client_t *h, php_http_message_t *request);
135
136 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_wait(php_http_client_t *h, struct timeval *custom_timeout);
137 PHP_HTTP_API int php_http_client_once(php_http_client_t *h);
138
139 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_exec(php_http_client_t *h);
140 PHP_HTTP_API void php_http_client_reset(php_http_client_t *h);
141
142 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_setopt(php_http_client_t *h, php_http_client_setopt_opt_t opt, void *arg);
143 PHP_HTTP_API ZEND_RESULT_CODE php_http_client_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg, void *res_ptr);
144
145 typedef int (*php_http_client_enqueue_cmp_func_t)(php_http_client_enqueue_t *cmp, void *arg);
146 /* compare with request message pointer if compare_func is NULL */
147 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);
148
149 PHP_MINIT_FUNCTION(http_client);
150 PHP_MSHUTDOWN_FUNCTION(http_client);
151
152 #endif
153
154 /*
155 * Local variables:
156 * tab-width: 4
157 * c-basic-offset: 4
158 * End:
159 * vim600: noet sw=4 ts=4 fdm=marker
160 * vim<600: noet sw=4 ts=4
161 */