xref: /PHP-5.4/ext/curl/php_curl.h (revision c0d060f5)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2014 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 /* $Id$ */
21 
22 #ifndef _PHP_CURL_H
23 #define _PHP_CURL_H
24 
25 #include "php.h"
26 #include "ext/standard/php_smart_str.h"
27 
28 #ifdef COMPILE_DL_CURL
29 #undef HAVE_CURL
30 #define HAVE_CURL 1
31 #endif
32 
33 #if HAVE_CURL
34 
35 #define PHP_CURL_DEBUG 0
36 
37 #include <curl/curl.h>
38 #include <curl/multi.h>
39 
40 extern zend_module_entry curl_module_entry;
41 #define curl_module_ptr &curl_module_entry
42 
43 #define CURLOPT_RETURNTRANSFER 19913
44 #define CURLOPT_BINARYTRANSFER 19914
45 #define PHP_CURL_STDOUT 0
46 #define PHP_CURL_FILE   1
47 #define PHP_CURL_USER   2
48 #define PHP_CURL_DIRECT 3
49 #define PHP_CURL_RETURN 4
50 #define PHP_CURL_ASCII  5
51 #define PHP_CURL_BINARY 6
52 #define PHP_CURL_IGNORE 7
53 
54 extern int  le_curl;
55 #define le_curl_name "cURL handle"
56 extern int  le_curl_multi_handle;
57 #define le_curl_multi_handle_name "cURL Multi Handle"
58 
59 PHP_MINIT_FUNCTION(curl);
60 PHP_MSHUTDOWN_FUNCTION(curl);
61 PHP_MINFO_FUNCTION(curl);
62 PHP_FUNCTION(curl_version);
63 PHP_FUNCTION(curl_init);
64 PHP_FUNCTION(curl_copy_handle);
65 PHP_FUNCTION(curl_setopt);
66 PHP_FUNCTION(curl_setopt_array);
67 PHP_FUNCTION(curl_exec);
68 PHP_FUNCTION(curl_getinfo);
69 PHP_FUNCTION(curl_error);
70 PHP_FUNCTION(curl_errno);
71 PHP_FUNCTION(curl_close);
72 PHP_FUNCTION(curl_multi_init);
73 PHP_FUNCTION(curl_multi_add_handle);
74 PHP_FUNCTION(curl_multi_remove_handle);
75 PHP_FUNCTION(curl_multi_select);
76 PHP_FUNCTION(curl_multi_exec);
77 PHP_FUNCTION(curl_multi_getcontent);
78 PHP_FUNCTION(curl_multi_info_read);
79 PHP_FUNCTION(curl_multi_close);
80 void _php_curl_multi_close(zend_rsrc_list_entry * TSRMLS_DC);
81 
82 typedef struct {
83 	zval            *func_name;
84 	zend_fcall_info_cache fci_cache;
85 	FILE            *fp;
86 	smart_str       buf;
87 	int             method;
88 	int             type;
89 	zval		*stream;
90 } php_curl_write;
91 
92 typedef struct {
93 	zval            *func_name;
94 	zend_fcall_info_cache fci_cache;
95 	FILE            *fp;
96 	long            fd;
97 	int             method;
98 	zval		*stream;
99 } php_curl_read;
100 
101 typedef struct {
102 	zval 		*func_name;
103 	zend_fcall_info_cache fci_cache;
104 	int    	        method;
105 } php_curl_progress;
106 
107 typedef struct {
108 	php_curl_write *write;
109 	php_curl_write *write_header;
110 	php_curl_read  *read;
111 	zval           *passwd;
112 	zval           *std_err;
113 	php_curl_progress *progress;
114 } php_curl_handlers;
115 
116 struct _php_curl_error  {
117 	char str[CURL_ERROR_SIZE + 1];
118 	int  no;
119 };
120 
121 struct _php_curl_send_headers {
122 	char *str;
123 	size_t str_len;
124 };
125 
126 struct _php_curl_free {
127 	zend_llist str;
128 	zend_llist post;
129 	HashTable *slist;
130 };
131 
132 typedef struct {
133 	struct _php_curl_error   err;
134 	struct _php_curl_free    *to_free;
135 	struct _php_curl_send_headers header;
136 	void ***thread_ctx;
137 	CURL                    *cp;
138 	php_curl_handlers       *handlers;
139 	long                     id;
140 	unsigned int             uses;
141 	zend_bool                in_callback;
142 	zval                     *clone;
143 } php_curl;
144 
145 typedef struct {
146 	int    still_running;
147 	CURLM *multi;
148 	zend_llist easyh;
149 } php_curlm;
150 
151 void _php_curl_cleanup_handle(php_curl *);
152 void _php_curl_multi_cleanup_list(void *data);
153 int  _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC);
154 
155 /* streams support */
156 
157 extern php_stream_ops php_curl_stream_ops;
158 #define PHP_STREAM_IS_CURL	&php_curl_stream_ops
159 
160 php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename, char *mode,
161 		int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
162 
163 extern php_stream_wrapper php_curl_wrapper;
164 
165 struct php_curl_buffer {
166 	off_t readpos, writepos;
167 	php_stream *buf;
168 };
169 
170 typedef struct {
171 	CURL	*curl;
172 	CURLM	*multi;
173 	char *url;
174 	struct php_curl_buffer readbuffer; /* holds downloaded data */
175 	struct php_curl_buffer writebuffer; /* holds data to upload */
176 
177 	fd_set readfds, writefds, excfds;
178 	int maxfd;
179 
180 	char errstr[CURL_ERROR_SIZE + 1];
181 	CURLMcode mcode;
182 	int pending;
183 	zval *headers;
184 	struct curl_slist *headers_slist; /* holds custom headers sent out in the request */
185 } php_curl_stream;
186 
187 
188 #else
189 #define curl_module_ptr NULL
190 #endif /* HAVE_CURL */
191 #define phpext_curl_ptr curl_module_ptr
192 #endif  /* _PHP_CURL_H */
193