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