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 /* $Id$ */ 21 22 #ifndef _PHP_CURL_H 23 #define _PHP_CURL_H 24 25 #include "php.h" 26 #include "zend_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 #ifdef PHP_WIN32 38 # define PHP_CURL_API __declspec(dllexport) 39 #elif defined(__GNUC__) && __GNUC__ >= 4 40 # define PHP_CURL_API __attribute__ ((visibility("default"))) 41 #else 42 # define PHP_CURL_API 43 #endif 44 45 #include "php_version.h" 46 #define PHP_CURL_VERSION PHP_VERSION 47 48 #include <curl/curl.h> 49 #include <curl/multi.h> 50 51 extern zend_module_entry curl_module_entry; 52 #define curl_module_ptr &curl_module_entry 53 54 #define CURLOPT_RETURNTRANSFER 19913 55 #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */ 56 #define PHP_CURL_STDOUT 0 57 #define PHP_CURL_FILE 1 58 #define PHP_CURL_USER 2 59 #define PHP_CURL_DIRECT 3 60 #define PHP_CURL_RETURN 4 61 #define PHP_CURL_IGNORE 7 62 63 #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err; 64 65 extern int le_curl; 66 #define le_curl_name "cURL handle" 67 extern int le_curl_multi_handle; 68 #define le_curl_multi_handle_name "cURL Multi Handle" 69 extern int le_curl_share_handle; 70 #define le_curl_share_handle_name "cURL Share Handle" 71 //extern int le_curl_pushheaders; 72 //#define le_curl_pushheaders "cURL Push Headers" 73 74 PHP_MINIT_FUNCTION(curl); 75 PHP_MSHUTDOWN_FUNCTION(curl); 76 PHP_MINFO_FUNCTION(curl); 77 78 PHP_FUNCTION(curl_close); 79 PHP_FUNCTION(curl_copy_handle); 80 PHP_FUNCTION(curl_errno); 81 PHP_FUNCTION(curl_error); 82 PHP_FUNCTION(curl_exec); 83 PHP_FUNCTION(curl_getinfo); 84 PHP_FUNCTION(curl_init); 85 PHP_FUNCTION(curl_setopt); 86 PHP_FUNCTION(curl_setopt_array); 87 PHP_FUNCTION(curl_version); 88 89 PHP_FUNCTION(curl_multi_add_handle); 90 PHP_FUNCTION(curl_multi_close); 91 PHP_FUNCTION(curl_multi_exec); 92 PHP_FUNCTION(curl_multi_getcontent); 93 PHP_FUNCTION(curl_multi_info_read); 94 PHP_FUNCTION(curl_multi_init); 95 PHP_FUNCTION(curl_multi_remove_handle); 96 PHP_FUNCTION(curl_multi_select); 97 PHP_FUNCTION(curl_multi_errno); 98 99 PHP_FUNCTION(curl_share_close); 100 PHP_FUNCTION(curl_share_init); 101 PHP_FUNCTION(curl_share_setopt); 102 PHP_FUNCTION(curl_share_errno); 103 104 #if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */ 105 PHP_FUNCTION(curl_strerror); 106 PHP_FUNCTION(curl_multi_strerror); 107 PHP_FUNCTION(curl_share_strerror); 108 #endif 109 110 #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ 111 PHP_FUNCTION(curl_reset); 112 #endif 113 114 #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ 115 PHP_FUNCTION(curl_escape); 116 PHP_FUNCTION(curl_unescape); 117 118 PHP_FUNCTION(curl_multi_setopt); 119 #endif 120 121 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ 122 PHP_FUNCTION(curl_pause); 123 #endif 124 125 PHP_FUNCTION(curl_file_create); 126 127 128 void _php_curl_multi_close(zend_resource *); 129 void _php_curl_share_close(zend_resource *); 130 131 typedef struct { 132 zval func_name; 133 zend_fcall_info_cache fci_cache; 134 FILE *fp; 135 smart_str buf; 136 int method; 137 zval stream; 138 } php_curl_write; 139 140 typedef struct { 141 zval func_name; 142 zend_fcall_info_cache fci_cache; 143 FILE *fp; 144 zend_resource *res; 145 int method; 146 zval stream; 147 } php_curl_read; 148 149 typedef struct { 150 zval func_name; 151 zend_fcall_info_cache fci_cache; 152 int method; 153 } php_curl_progress, php_curl_fnmatch, php_curlm_server_push; 154 155 typedef struct { 156 php_curl_write *write; 157 php_curl_write *write_header; 158 php_curl_read *read; 159 #if CURLOPT_PASSWDFUNCTION != 0 160 zval passwd; 161 #endif 162 zval std_err; 163 php_curl_progress *progress; 164 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ 165 php_curl_fnmatch *fnmatch; 166 #endif 167 } php_curl_handlers; 168 169 struct _php_curl_error { 170 char str[CURL_ERROR_SIZE + 1]; 171 int no; 172 }; 173 174 struct _php_curl_send_headers { 175 zend_string *str; 176 }; 177 178 struct _php_curl_free { 179 zend_llist str; 180 zend_llist post; 181 HashTable *slist; 182 }; 183 184 typedef struct { 185 CURL *cp; 186 php_curl_handlers *handlers; 187 zend_resource *res; 188 struct _php_curl_free *to_free; 189 struct _php_curl_send_headers header; 190 struct _php_curl_error err; 191 zend_bool in_callback; 192 uint32_t* clone; 193 } php_curl; 194 195 #define CURLOPT_SAFE_UPLOAD -1 196 197 typedef struct { 198 php_curlm_server_push *server_push; 199 } php_curlm_handlers; 200 201 typedef struct { 202 int still_running; 203 CURLM *multi; 204 zend_llist easyh; 205 php_curlm_handlers *handlers; 206 struct { 207 int no; 208 } err; 209 } php_curlm; 210 211 typedef struct { 212 CURLSH *share; 213 struct { 214 int no; 215 } err; 216 } php_curlsh; 217 218 php_curl *alloc_curl_handle(); 219 void _php_curl_cleanup_handle(php_curl *); 220 void _php_curl_multi_cleanup_list(void *data); 221 void _php_curl_verify_handlers(php_curl *ch, int reporterror); 222 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source); 223 224 void curlfile_register_class(void); 225 PHP_CURL_API extern zend_class_entry *curl_CURLFile_class; 226 227 #else 228 #define curl_module_ptr NULL 229 #endif /* HAVE_CURL */ 230 #define phpext_curl_ptr curl_module_ptr 231 #endif /* _PHP_CURL_H */ 232