xref: /PHP-7.4/ext/curl/php_curl.h (revision 2d0dec91)
167870714SSterling Hughes /*
267870714SSterling Hughes    +----------------------------------------------------------------------+
3d0cb7153SJohannes Schlüter    | PHP Version 7                                                        |
467870714SSterling Hughes    +----------------------------------------------------------------------+
50cf7de1cSZeev Suraski    | Copyright (c) The PHP Group                                          |
667870714SSterling Hughes    +----------------------------------------------------------------------+
75bd93221Sfoobar    | This source file is subject to version 3.01 of the PHP license,      |
867870714SSterling Hughes    | that is bundled with this package in the file LICENSE, and is        |
9f68c7ff2SJames Cox    | available through the world-wide-web at the following url:           |
105bd93221Sfoobar    | http://www.php.net/license/3_01.txt                                  |
1167870714SSterling Hughes    | If you did not receive a copy of the PHP license and are unable to   |
1267870714SSterling Hughes    | obtain it through the world-wide-web, please send a note to          |
1367870714SSterling Hughes    | license@php.net so we can mail you a copy immediately.               |
1467870714SSterling Hughes    +----------------------------------------------------------------------+
152f0238dcSSterling Hughes    | Author: Sterling Hughes <sterling@php.net>                           |
1653728441SSterling Hughes    |         Wez Furlong <wez@thebrainroom.com>                           |
1767870714SSterling Hughes    +----------------------------------------------------------------------+
1867870714SSterling Hughes */
1967870714SSterling Hughes 
2067870714SSterling Hughes #ifndef _PHP_CURL_H
2167870714SSterling Hughes #define _PHP_CURL_H
2267870714SSterling Hughes 
23ea2cf185SSterling Hughes #include "php.h"
24a770d29dSNikita Popov #include "zend_smart_str.h"
25ea2cf185SSterling Hughes 
2667870714SSterling Hughes #ifdef COMPILE_DL_CURL
2767870714SSterling Hughes #undef HAVE_CURL
2867870714SSterling Hughes #define HAVE_CURL 1
2967870714SSterling Hughes #endif
3067870714SSterling Hughes 
3167870714SSterling Hughes #if HAVE_CURL
3267870714SSterling Hughes 
3353728441SSterling Hughes #define PHP_CURL_DEBUG 0
346e10dc54SSterling Hughes 
35a9d013bbSStanislav Malyshev #ifdef PHP_WIN32
36a9d013bbSStanislav Malyshev # define PHP_CURL_API __declspec(dllexport)
37a9d013bbSStanislav Malyshev #elif defined(__GNUC__) && __GNUC__ >= 4
38a9d013bbSStanislav Malyshev # define PHP_CURL_API __attribute__ ((visibility("default")))
39a9d013bbSStanislav Malyshev #else
40a9d013bbSStanislav Malyshev # define PHP_CURL_API
41a9d013bbSStanislav Malyshev #endif
42a9d013bbSStanislav Malyshev 
43ec89c850SAnatol Belski #include "php_version.h"
44ec89c850SAnatol Belski #define PHP_CURL_VERSION PHP_VERSION
45ec89c850SAnatol Belski 
4653728441SSterling Hughes #include <curl/curl.h>
4753728441SSterling Hughes #include <curl/multi.h>
48ea2cf185SSterling Hughes 
4967870714SSterling Hughes extern zend_module_entry curl_module_entry;
5067870714SSterling Hughes #define curl_module_ptr &curl_module_entry
5167870714SSterling Hughes 
5236dc3e1cSSterling Hughes #define CURLOPT_RETURNTRANSFER 19913
5333d3eb1eSPierrick Charron #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
5453728441SSterling Hughes #define PHP_CURL_STDOUT 0
5553728441SSterling Hughes #define PHP_CURL_FILE   1
5653728441SSterling Hughes #define PHP_CURL_USER   2
5753728441SSterling Hughes #define PHP_CURL_DIRECT 3
5853728441SSterling Hughes #define PHP_CURL_RETURN 4
5953728441SSterling Hughes #define PHP_CURL_IGNORE 7
6053728441SSterling Hughes 
61be7f405fSNikita Popov #define SAVE_CURL_ERROR(__handle, __err) \
62be7f405fSNikita Popov     do { (__handle)->err.no = (int) __err; } while (0)
63c8c183ebSAbyr Valg 
64d0ec2396SGeorge Schlossnagle extern int  le_curl;
6553728441SSterling Hughes #define le_curl_name "cURL handle"
66d0ec2396SGeorge Schlossnagle extern int  le_curl_multi_handle;
6753728441SSterling Hughes #define le_curl_multi_handle_name "cURL Multi Handle"
68e69f9879SPierrick Charron extern int  le_curl_share_handle;
69e69f9879SPierrick Charron #define le_curl_share_handle_name "cURL Share Handle"
70ad15e1ccSDavey Shafik //extern int  le_curl_pushheaders;
71ad15e1ccSDavey Shafik //#define le_curl_pushheaders "cURL Push Headers"
7236dc3e1cSSterling Hughes 
73bba7086aSSterling Hughes PHP_MINIT_FUNCTION(curl);
74958675c0SSterling Hughes PHP_MSHUTDOWN_FUNCTION(curl);
75bba7086aSSterling Hughes PHP_MINFO_FUNCTION(curl);
76ded889e8SPierrick Charron 
77ded889e8SPierrick Charron PHP_FUNCTION(curl_close);
78177db33cSSterling Hughes PHP_FUNCTION(curl_copy_handle);
79ded889e8SPierrick Charron PHP_FUNCTION(curl_errno);
80ded889e8SPierrick Charron PHP_FUNCTION(curl_error);
81bba7086aSSterling Hughes PHP_FUNCTION(curl_exec);
826b8faeb1SSterling Hughes PHP_FUNCTION(curl_getinfo);
83ded889e8SPierrick Charron PHP_FUNCTION(curl_init);
84ded889e8SPierrick Charron PHP_FUNCTION(curl_setopt);
85ded889e8SPierrick Charron PHP_FUNCTION(curl_setopt_array);
86ded889e8SPierrick Charron PHP_FUNCTION(curl_version);
87e69f9879SPierrick Charron 
8853728441SSterling Hughes PHP_FUNCTION(curl_multi_add_handle);
89ded889e8SPierrick Charron PHP_FUNCTION(curl_multi_close);
9053728441SSterling Hughes PHP_FUNCTION(curl_multi_exec);
9153728441SSterling Hughes PHP_FUNCTION(curl_multi_getcontent);
9253728441SSterling Hughes PHP_FUNCTION(curl_multi_info_read);
93ded889e8SPierrick Charron PHP_FUNCTION(curl_multi_init);
94ded889e8SPierrick Charron PHP_FUNCTION(curl_multi_remove_handle);
95ded889e8SPierrick Charron PHP_FUNCTION(curl_multi_select);
963d71c1deSPierrick Charron PHP_FUNCTION(curl_multi_errno);
97ded889e8SPierrick Charron 
98e69f9879SPierrick Charron PHP_FUNCTION(curl_share_close);
99ded889e8SPierrick Charron PHP_FUNCTION(curl_share_init);
100e69f9879SPierrick Charron PHP_FUNCTION(curl_share_setopt);
1013d71c1deSPierrick Charron PHP_FUNCTION(curl_share_errno);
102e69f9879SPierrick Charron 
1034b4f3db7SPierrick Charron PHP_FUNCTION(curl_strerror);
1044b4f3db7SPierrick Charron PHP_FUNCTION(curl_multi_strerror);
1053d71c1deSPierrick Charron PHP_FUNCTION(curl_share_strerror);
1064b4f3db7SPierrick Charron 
107e69f9879SPierrick Charron PHP_FUNCTION(curl_reset);
108e69f9879SPierrick Charron 
109e69f9879SPierrick Charron #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
110e69f9879SPierrick Charron PHP_FUNCTION(curl_escape);
111e69f9879SPierrick Charron PHP_FUNCTION(curl_unescape);
11264595a5dSPierrick Charron 
11364595a5dSPierrick Charron PHP_FUNCTION(curl_multi_setopt);
114e69f9879SPierrick Charron #endif
115e69f9879SPierrick Charron 
11633f44af1SPierrick Charron #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
11733f44af1SPierrick Charron PHP_FUNCTION(curl_pause);
11833f44af1SPierrick Charron #endif
1193d71c1deSPierrick Charron 
120a9d013bbSStanislav Malyshev PHP_FUNCTION(curl_file_create);
121a9d013bbSStanislav Malyshev 
12233f44af1SPierrick Charron 
123bdeb220fSAnatol Belski void _php_curl_multi_close(zend_resource *);
124bdeb220fSAnatol Belski void _php_curl_share_close(zend_resource *);
12567870714SSterling Hughes 
1266e10dc54SSterling Hughes typedef struct {
127f05baec0SXinchen Hui 	zval                  func_name;
128f05baec0SXinchen Hui 	zend_fcall_info_cache fci_cache;
129f05baec0SXinchen Hui 	FILE                 *fp;
130f05baec0SXinchen Hui 	smart_str             buf;
131f05baec0SXinchen Hui 	int                   method;
132c5e63f8aSXinchen Hui 	zval					stream;
133ea2cf185SSterling Hughes } php_curl_write;
134ea2cf185SSterling Hughes 
135ea2cf185SSterling Hughes typedef struct {
136f05baec0SXinchen Hui 	zval                  func_name;
137f05baec0SXinchen Hui 	zend_fcall_info_cache fci_cache;
138f05baec0SXinchen Hui 	FILE                 *fp;
139f05baec0SXinchen Hui 	zend_resource        *res;
140f05baec0SXinchen Hui 	int                   method;
141f05baec0SXinchen Hui 	zval                  stream;
142ea2cf185SSterling Hughes } php_curl_read;
143ea2cf185SSterling Hughes 
1448e703108SPierre Joye typedef struct {
145f05baec0SXinchen Hui 	zval                  func_name;
146f05baec0SXinchen Hui 	zend_fcall_info_cache fci_cache;
147f05baec0SXinchen Hui 	int                   method;
148ad15e1ccSDavey Shafik } php_curl_progress, php_curl_fnmatch, php_curlm_server_push;
1498e703108SPierre Joye 
150ea2cf185SSterling Hughes typedef struct {
151f05baec0SXinchen Hui 	php_curl_write    *write;
152f05baec0SXinchen Hui 	php_curl_write    *write_header;
153f05baec0SXinchen Hui 	php_curl_read     *read;
154f05baec0SXinchen Hui 	zval               std_err;
155f05baec0SXinchen Hui 	php_curl_progress *progress;
1568253bdbbSPierrick Charron #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
157f05baec0SXinchen Hui 	php_curl_fnmatch  *fnmatch;
1588253bdbbSPierrick Charron #endif
159ea2cf185SSterling Hughes } php_curl_handlers;
160ea2cf185SSterling Hughes 
161ea2cf185SSterling Hughes struct _php_curl_error  {
162ea2cf185SSterling Hughes 	char str[CURL_ERROR_SIZE + 1];
163ea2cf185SSterling Hughes 	int  no;
164ea2cf185SSterling Hughes };
165ea2cf185SSterling Hughes 
1665f25d80dSIlia Alshanetsky struct _php_curl_send_headers {
167763cee63SXinchen Hui 	zend_string *str;
1685f25d80dSIlia Alshanetsky };
1695f25d80dSIlia Alshanetsky 
170ea2cf185SSterling Hughes struct _php_curl_free {
171ea2cf185SSterling Hughes 	zend_llist str;
172ea2cf185SSterling Hughes 	zend_llist post;
173c68dc6b5SChristoph M. Becker 	zend_llist stream;
174aa7d3d8eSAdam Harvey 	HashTable *slist;
175ea2cf185SSterling Hughes };
176ea2cf185SSterling Hughes 
177ea2cf185SSterling Hughes typedef struct {
178f05baec0SXinchen Hui 	CURL                         *cp;
179f05baec0SXinchen Hui 	php_curl_handlers            *handlers;
180f05baec0SXinchen Hui 	zend_resource                *res;
181f05baec0SXinchen Hui 	struct _php_curl_free        *to_free;
1825f25d80dSIlia Alshanetsky 	struct _php_curl_send_headers header;
183f05baec0SXinchen Hui 	struct _php_curl_error        err;
184f05baec0SXinchen Hui 	zend_bool                     in_callback;
1854df6f264SXinchen Hui 	uint32_t*                     clone;
186*2d0dec91SChristoph M. Becker #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
187*2d0dec91SChristoph M. Becker 	zval                          postfields;
188*2d0dec91SChristoph M. Becker #endif
1896e10dc54SSterling Hughes } php_curl;
1908a8b5dacSSterling Hughes 
191a9d013bbSStanislav Malyshev #define CURLOPT_SAFE_UPLOAD -1
192a9d013bbSStanislav Malyshev 
193ad15e1ccSDavey Shafik typedef struct {
194ad15e1ccSDavey Shafik 	php_curlm_server_push	*server_push;
195ad15e1ccSDavey Shafik } php_curlm_handlers;
196ad15e1ccSDavey Shafik 
19753728441SSterling Hughes typedef struct {
198f05baec0SXinchen Hui 	int         still_running;
199f05baec0SXinchen Hui 	CURLM      *multi;
200f05baec0SXinchen Hui 	zend_llist  easyh;
201ad15e1ccSDavey Shafik 	php_curlm_handlers	*handlers;
2023d71c1deSPierrick Charron 	struct {
2033d71c1deSPierrick Charron 		int no;
2043d71c1deSPierrick Charron 	} err;
20553728441SSterling Hughes } php_curlm;
20653728441SSterling Hughes 
207e69f9879SPierrick Charron typedef struct {
208e69f9879SPierrick Charron 	CURLSH                   *share;
2093d71c1deSPierrick Charron 	struct {
2103d71c1deSPierrick Charron 		int no;
2113d71c1deSPierrick Charron 	} err;
212e69f9879SPierrick Charron } php_curlsh;
213e69f9879SPierrick Charron 
214ad15e1ccSDavey Shafik php_curl *alloc_curl_handle();
21553728441SSterling Hughes void _php_curl_cleanup_handle(php_curl *);
216a5d86612SAntony Dovgal void _php_curl_multi_cleanup_list(void *data);
217bdeb220fSAnatol Belski void _php_curl_verify_handlers(php_curl *ch, int reporterror);
21863275a1eSDavey Shafik void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
21953728441SSterling Hughes 
220bdeb220fSAnatol Belski void curlfile_register_class(void);
221a9d013bbSStanislav Malyshev PHP_CURL_API extern zend_class_entry *curl_CURLFile_class;
2226b8faeb1SSterling Hughes 
22367870714SSterling Hughes #else
22467870714SSterling Hughes #define curl_module_ptr NULL
22567870714SSterling Hughes #endif /* HAVE_CURL */
22667870714SSterling Hughes #define phpext_curl_ptr curl_module_ptr
22719687ea1SKristian Köhntopp #endif  /* _PHP_CURL_H */
228