1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 7 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 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) \ 62 do { (__handle)->err.no = (int) __err; } while (0) 63 64 extern int le_curl; 65 #define le_curl_name "cURL handle" 66 extern int le_curl_multi_handle; 67 #define le_curl_multi_handle_name "cURL Multi Handle" 68 extern int le_curl_share_handle; 69 #define le_curl_share_handle_name "cURL Share Handle" 70 //extern int le_curl_pushheaders; 71 //#define le_curl_pushheaders "cURL Push Headers" 72 73 PHP_MINIT_FUNCTION(curl); 74 PHP_MSHUTDOWN_FUNCTION(curl); 75 PHP_MINFO_FUNCTION(curl); 76 77 PHP_FUNCTION(curl_close); 78 PHP_FUNCTION(curl_copy_handle); 79 PHP_FUNCTION(curl_errno); 80 PHP_FUNCTION(curl_error); 81 PHP_FUNCTION(curl_exec); 82 PHP_FUNCTION(curl_getinfo); 83 PHP_FUNCTION(curl_init); 84 PHP_FUNCTION(curl_setopt); 85 PHP_FUNCTION(curl_setopt_array); 86 PHP_FUNCTION(curl_version); 87 88 PHP_FUNCTION(curl_multi_add_handle); 89 PHP_FUNCTION(curl_multi_close); 90 PHP_FUNCTION(curl_multi_exec); 91 PHP_FUNCTION(curl_multi_getcontent); 92 PHP_FUNCTION(curl_multi_info_read); 93 PHP_FUNCTION(curl_multi_init); 94 PHP_FUNCTION(curl_multi_remove_handle); 95 PHP_FUNCTION(curl_multi_select); 96 PHP_FUNCTION(curl_multi_errno); 97 98 PHP_FUNCTION(curl_share_close); 99 PHP_FUNCTION(curl_share_init); 100 PHP_FUNCTION(curl_share_setopt); 101 PHP_FUNCTION(curl_share_errno); 102 103 PHP_FUNCTION(curl_strerror); 104 PHP_FUNCTION(curl_multi_strerror); 105 PHP_FUNCTION(curl_share_strerror); 106 107 PHP_FUNCTION(curl_reset); 108 109 #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ 110 PHP_FUNCTION(curl_escape); 111 PHP_FUNCTION(curl_unescape); 112 113 PHP_FUNCTION(curl_multi_setopt); 114 #endif 115 116 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ 117 PHP_FUNCTION(curl_pause); 118 #endif 119 120 PHP_FUNCTION(curl_file_create); 121 122 123 void _php_curl_multi_close(zend_resource *); 124 void _php_curl_share_close(zend_resource *); 125 126 typedef struct { 127 zval func_name; 128 zend_fcall_info_cache fci_cache; 129 FILE *fp; 130 smart_str buf; 131 int method; 132 zval stream; 133 } php_curl_write; 134 135 typedef struct { 136 zval func_name; 137 zend_fcall_info_cache fci_cache; 138 FILE *fp; 139 zend_resource *res; 140 int method; 141 zval stream; 142 } php_curl_read; 143 144 typedef struct { 145 zval func_name; 146 zend_fcall_info_cache fci_cache; 147 int method; 148 } php_curl_progress, php_curl_fnmatch, php_curlm_server_push; 149 150 typedef struct { 151 php_curl_write *write; 152 php_curl_write *write_header; 153 php_curl_read *read; 154 zval std_err; 155 php_curl_progress *progress; 156 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ 157 php_curl_fnmatch *fnmatch; 158 #endif 159 } php_curl_handlers; 160 161 struct _php_curl_error { 162 char str[CURL_ERROR_SIZE + 1]; 163 int no; 164 }; 165 166 struct _php_curl_send_headers { 167 zend_string *str; 168 }; 169 170 struct _php_curl_free { 171 zend_llist str; 172 zend_llist post; 173 zend_llist stream; 174 HashTable *slist; 175 }; 176 177 typedef struct { 178 CURL *cp; 179 php_curl_handlers *handlers; 180 zend_resource *res; 181 struct _php_curl_free *to_free; 182 struct _php_curl_send_headers header; 183 struct _php_curl_error err; 184 zend_bool in_callback; 185 uint32_t* clone; 186 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */ 187 zval postfields; 188 #endif 189 } php_curl; 190 191 #define CURLOPT_SAFE_UPLOAD -1 192 193 typedef struct { 194 php_curlm_server_push *server_push; 195 } php_curlm_handlers; 196 197 typedef struct { 198 int still_running; 199 CURLM *multi; 200 zend_llist easyh; 201 php_curlm_handlers *handlers; 202 struct { 203 int no; 204 } err; 205 } php_curlm; 206 207 typedef struct { 208 CURLSH *share; 209 struct { 210 int no; 211 } err; 212 } php_curlsh; 213 214 php_curl *alloc_curl_handle(); 215 void _php_curl_cleanup_handle(php_curl *); 216 void _php_curl_multi_cleanup_list(void *data); 217 void _php_curl_verify_handlers(php_curl *ch, int reporterror); 218 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source); 219 220 void curlfile_register_class(void); 221 PHP_CURL_API extern zend_class_entry *curl_CURLFile_class; 222 223 #else 224 #define curl_module_ptr NULL 225 #endif /* HAVE_CURL */ 226 #define phpext_curl_ptr curl_module_ptr 227 #endif /* _PHP_CURL_H */ 228