xref: /PHP-7.3/ext/curl/php_curl.h (revision 06e78cad)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Author: Sterling Hughes <sterling@php.net>                           |
16    |         Wez Furlong <wez@thebrainroom.com>                           |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef _PHP_CURL_H
21 #define _PHP_CURL_H
22 
23 #include "php.h"
24 #include "zend_smart_str.h"
25 
26 #ifdef COMPILE_DL_CURL
27 #undef HAVE_CURL
28 #define HAVE_CURL 1
29 #endif
30 
31 #if HAVE_CURL
32 
33 #define PHP_CURL_DEBUG 0
34 
35 #ifdef PHP_WIN32
36 # define PHP_CURL_API __declspec(dllexport)
37 #elif defined(__GNUC__) && __GNUC__ >= 4
38 # define PHP_CURL_API __attribute__ ((visibility("default")))
39 #else
40 # define PHP_CURL_API
41 #endif
42 
43 #include "php_version.h"
44 #define PHP_CURL_VERSION PHP_VERSION
45 
46 #include <curl/curl.h>
47 #include <curl/multi.h>
48 
49 extern zend_module_entry curl_module_entry;
50 #define curl_module_ptr &curl_module_entry
51 
52 #define CURLOPT_RETURNTRANSFER 19913
53 #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
54 #define PHP_CURL_STDOUT 0
55 #define PHP_CURL_FILE   1
56 #define PHP_CURL_USER   2
57 #define PHP_CURL_DIRECT 3
58 #define PHP_CURL_RETURN 4
59 #define PHP_CURL_IGNORE 7
60 
61 #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
62 
63 extern int  le_curl;
64 #define le_curl_name "cURL handle"
65 extern int  le_curl_multi_handle;
66 #define le_curl_multi_handle_name "cURL Multi Handle"
67 extern int  le_curl_share_handle;
68 #define le_curl_share_handle_name "cURL Share Handle"
69 //extern int  le_curl_pushheaders;
70 //#define le_curl_pushheaders "cURL Push Headers"
71 
72 PHP_MINIT_FUNCTION(curl);
73 PHP_MSHUTDOWN_FUNCTION(curl);
74 PHP_MINFO_FUNCTION(curl);
75 
76 PHP_FUNCTION(curl_close);
77 PHP_FUNCTION(curl_copy_handle);
78 PHP_FUNCTION(curl_errno);
79 PHP_FUNCTION(curl_error);
80 PHP_FUNCTION(curl_exec);
81 PHP_FUNCTION(curl_getinfo);
82 PHP_FUNCTION(curl_init);
83 PHP_FUNCTION(curl_setopt);
84 PHP_FUNCTION(curl_setopt_array);
85 PHP_FUNCTION(curl_version);
86 
87 PHP_FUNCTION(curl_multi_add_handle);
88 PHP_FUNCTION(curl_multi_close);
89 PHP_FUNCTION(curl_multi_exec);
90 PHP_FUNCTION(curl_multi_getcontent);
91 PHP_FUNCTION(curl_multi_info_read);
92 PHP_FUNCTION(curl_multi_init);
93 PHP_FUNCTION(curl_multi_remove_handle);
94 PHP_FUNCTION(curl_multi_select);
95 PHP_FUNCTION(curl_multi_errno);
96 
97 PHP_FUNCTION(curl_share_close);
98 PHP_FUNCTION(curl_share_init);
99 PHP_FUNCTION(curl_share_setopt);
100 PHP_FUNCTION(curl_share_errno);
101 
102 PHP_FUNCTION(curl_strerror);
103 PHP_FUNCTION(curl_multi_strerror);
104 PHP_FUNCTION(curl_share_strerror);
105 
106 PHP_FUNCTION(curl_reset);
107 
108 #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
109 PHP_FUNCTION(curl_escape);
110 PHP_FUNCTION(curl_unescape);
111 
112 PHP_FUNCTION(curl_multi_setopt);
113 #endif
114 
115 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
116 PHP_FUNCTION(curl_pause);
117 #endif
118 
119 PHP_FUNCTION(curl_file_create);
120 
121 
122 void _php_curl_multi_close(zend_resource *);
123 void _php_curl_share_close(zend_resource *);
124 
125 typedef struct {
126 	zval                  func_name;
127 	zend_fcall_info_cache fci_cache;
128 	FILE                 *fp;
129 	smart_str             buf;
130 	int                   method;
131 	zval					stream;
132 } php_curl_write;
133 
134 typedef struct {
135 	zval                  func_name;
136 	zend_fcall_info_cache fci_cache;
137 	FILE                 *fp;
138 	zend_resource        *res;
139 	int                   method;
140 	zval                  stream;
141 } php_curl_read;
142 
143 typedef struct {
144 	zval                  func_name;
145 	zend_fcall_info_cache fci_cache;
146 	int                   method;
147 } php_curl_progress, php_curl_fnmatch, php_curlm_server_push;
148 
149 typedef struct {
150 	php_curl_write    *write;
151 	php_curl_write    *write_header;
152 	php_curl_read     *read;
153 	zval               std_err;
154 	php_curl_progress *progress;
155 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
156 	php_curl_fnmatch  *fnmatch;
157 #endif
158 } php_curl_handlers;
159 
160 struct _php_curl_error  {
161 	char str[CURL_ERROR_SIZE + 1];
162 	int  no;
163 };
164 
165 struct _php_curl_send_headers {
166 	zend_string *str;
167 };
168 
169 struct _php_curl_free {
170 	zend_llist str;
171 	zend_llist post;
172 	HashTable *slist;
173 };
174 
175 typedef struct {
176 	CURL                         *cp;
177 	php_curl_handlers            *handlers;
178 	zend_resource                *res;
179 	struct _php_curl_free        *to_free;
180 	struct _php_curl_send_headers header;
181 	struct _php_curl_error        err;
182 	zend_bool                     in_callback;
183 	uint32_t*                     clone;
184 } php_curl;
185 
186 #define CURLOPT_SAFE_UPLOAD -1
187 
188 typedef struct {
189 	php_curlm_server_push	*server_push;
190 } php_curlm_handlers;
191 
192 typedef struct {
193 	int         still_running;
194 	CURLM      *multi;
195 	zend_llist  easyh;
196 	php_curlm_handlers	*handlers;
197 	struct {
198 		int no;
199 	} err;
200 } php_curlm;
201 
202 typedef struct {
203 	CURLSH                   *share;
204 	struct {
205 		int no;
206 	} err;
207 } php_curlsh;
208 
209 php_curl *alloc_curl_handle();
210 void _php_curl_cleanup_handle(php_curl *);
211 void _php_curl_multi_cleanup_list(void *data);
212 void _php_curl_verify_handlers(php_curl *ch, int reporterror);
213 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
214 
215 void curlfile_register_class(void);
216 PHP_CURL_API extern zend_class_entry *curl_CURLFile_class;
217 
218 #else
219 #define curl_module_ptr NULL
220 #endif /* HAVE_CURL */
221 #define phpext_curl_ptr curl_module_ptr
222 #endif  /* _PHP_CURL_H */
223