xref: /php-src/ext/curl/curl_private.h (revision f4dbe239)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Sterling Hughes <sterling@php.net>                           |
14    |         Wez Furlong <wez@thebrainroom.com>                           |
15    +----------------------------------------------------------------------+
16 */
17 
18 #ifndef _PHP_CURL_PRIVATE_H
19 #define _PHP_CURL_PRIVATE_H
20 
21 #include "php_curl.h"
22 
23 #define PHP_CURL_DEBUG 0
24 
25 #include "php_version.h"
26 #define PHP_CURL_VERSION PHP_VERSION
27 
28 #include <curl/curl.h>
29 #include <curl/multi.h>
30 
31 #define CURLOPT_RETURNTRANSFER 19913
32 #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
33 #define PHP_CURL_STDOUT 0
34 #define PHP_CURL_FILE   1
35 #define PHP_CURL_USER   2
36 #define PHP_CURL_DIRECT 3
37 #define PHP_CURL_RETURN 4
38 #define PHP_CURL_IGNORE 7
39 
40 #define SAVE_CURL_ERROR(__handle, __err) \
41     do { (__handle)->err.no = (int) __err; } while (0)
42 
43 PHP_MINIT_FUNCTION(curl);
44 PHP_MSHUTDOWN_FUNCTION(curl);
45 PHP_MINFO_FUNCTION(curl);
46 
47 typedef struct {
48 	zend_fcall_info_cache fcc;
49 	FILE                 *fp;
50 	smart_str             buf;
51 	int                   method;
52 	zval					stream;
53 } php_curl_write;
54 
55 typedef struct {
56 	zend_fcall_info_cache fcc;
57 	FILE                 *fp;
58 	zend_resource        *res;
59 	int                   method;
60 	zval                  stream;
61 } php_curl_read;
62 
63 typedef struct {
64 	php_curl_write    *write;
65 	php_curl_write    *write_header;
66 	php_curl_read     *read;
67 	zval               std_err;
68 	zend_fcall_info_cache progress;
69 	zend_fcall_info_cache xferinfo;
70 	zend_fcall_info_cache fnmatch;
71 #if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
72 	zend_fcall_info_cache sshhostkey;
73 #endif
74 } php_curl_handlers;
75 
76 struct _php_curl_error  {
77 	char str[CURL_ERROR_SIZE + 1];
78 	int  no;
79 };
80 
81 struct _php_curl_send_headers {
82 	zend_string *str;
83 };
84 
85 struct _php_curl_free {
86 	zend_llist post;
87 	zend_llist stream;
88 	HashTable *slist;
89 };
90 
91 typedef struct {
92 	CURL                         *cp;
93 	php_curl_handlers             handlers;
94 	struct _php_curl_free        *to_free;
95 	struct _php_curl_send_headers header;
96 	struct _php_curl_error        err;
97 	bool                     in_callback;
98 	uint32_t*                     clone;
99 	zval                          postfields;
100 	/* For CURLOPT_PRIVATE */
101 	zval private_data;
102 	/* CurlShareHandle object set using CURLOPT_SHARE. */
103 	struct _php_curlsh *share;
104 	zend_object                   std;
105 } php_curl;
106 
107 #define CURLOPT_SAFE_UPLOAD -1
108 
109 typedef struct {
110 	zend_fcall_info_cache server_push;
111 } php_curlm_handlers;
112 
113 typedef struct {
114 	CURLM      *multi;
115 	zend_llist  easyh;
116 	php_curlm_handlers handlers;
117 	struct {
118 		int no;
119 	} err;
120 	zend_object std;
121 } php_curlm;
122 
123 typedef struct _php_curlsh {
124 	CURLSH                   *share;
125 	struct {
126 		int no;
127 	} err;
128 	zend_object std;
129 } php_curlsh;
130 
131 php_curl *init_curl_handle_into_zval(zval *curl);
132 void init_curl_handle(php_curl *ch);
133 void _php_curl_cleanup_handle(php_curl *);
134 void _php_curl_multi_cleanup_list(void *data);
135 void _php_curl_verify_handlers(php_curl *ch, bool reporterror);
136 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
137 
curl_from_obj(zend_object * obj)138 static inline php_curl *curl_from_obj(zend_object *obj) {
139 	return (php_curl *)((char *)(obj) - XtOffsetOf(php_curl, std));
140 }
141 
142 #define Z_CURL_P(zv) curl_from_obj(Z_OBJ_P(zv))
143 
curl_share_from_obj(zend_object * obj)144 static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
145 	return (php_curlsh *)((char *)(obj) - XtOffsetOf(php_curlsh, std));
146 }
147 
148 #define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))
149 
150 void curl_multi_register_handlers(void);
151 void curl_share_register_handlers(void);
152 void curlfile_register_class(void);
153 zend_result curl_cast_object(zend_object *obj, zval *result, int type);
154 
155 #endif  /* _PHP_CURL_PRIVATE_H */
156