1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 5 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2016 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 #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 <curl/curl.h> 46 #include <curl/multi.h> 47 48 extern zend_module_entry curl_module_entry; 49 #define curl_module_ptr &curl_module_entry 50 51 #define CURLOPT_RETURNTRANSFER 19913 52 #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */ 53 #define PHP_CURL_STDOUT 0 54 #define PHP_CURL_FILE 1 55 #define PHP_CURL_USER 2 56 #define PHP_CURL_DIRECT 3 57 #define PHP_CURL_RETURN 4 58 #define PHP_CURL_IGNORE 7 59 60 extern int le_curl; 61 #define le_curl_name "cURL handle" 62 extern int le_curl_multi_handle; 63 #define le_curl_multi_handle_name "cURL Multi Handle" 64 extern int le_curl_share_handle; 65 #define le_curl_share_handle_name "cURL Share Handle" 66 67 PHP_MINIT_FUNCTION(curl); 68 PHP_MSHUTDOWN_FUNCTION(curl); 69 PHP_MINFO_FUNCTION(curl); 70 71 PHP_FUNCTION(curl_close); 72 PHP_FUNCTION(curl_copy_handle); 73 PHP_FUNCTION(curl_errno); 74 PHP_FUNCTION(curl_error); 75 PHP_FUNCTION(curl_exec); 76 PHP_FUNCTION(curl_getinfo); 77 PHP_FUNCTION(curl_init); 78 PHP_FUNCTION(curl_setopt); 79 PHP_FUNCTION(curl_setopt_array); 80 PHP_FUNCTION(curl_version); 81 82 PHP_FUNCTION(curl_multi_add_handle); 83 PHP_FUNCTION(curl_multi_close); 84 PHP_FUNCTION(curl_multi_exec); 85 PHP_FUNCTION(curl_multi_getcontent); 86 PHP_FUNCTION(curl_multi_info_read); 87 PHP_FUNCTION(curl_multi_init); 88 PHP_FUNCTION(curl_multi_remove_handle); 89 PHP_FUNCTION(curl_multi_select); 90 91 PHP_FUNCTION(curl_share_close); 92 PHP_FUNCTION(curl_share_init); 93 PHP_FUNCTION(curl_share_setopt); 94 95 #if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */ 96 PHP_FUNCTION(curl_strerror); 97 PHP_FUNCTION(curl_multi_strerror); 98 #endif 99 100 #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ 101 PHP_FUNCTION(curl_reset); 102 #endif 103 104 #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ 105 PHP_FUNCTION(curl_escape); 106 PHP_FUNCTION(curl_unescape); 107 108 PHP_FUNCTION(curl_multi_setopt); 109 #endif 110 111 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ 112 PHP_FUNCTION(curl_pause); 113 #endif 114 PHP_FUNCTION(curl_file_create); 115 116 117 void _php_curl_multi_close(zend_rsrc_list_entry * TSRMLS_DC); 118 void _php_curl_share_close(zend_rsrc_list_entry * TSRMLS_DC); 119 120 typedef struct { 121 zval *func_name; 122 zend_fcall_info_cache fci_cache; 123 FILE *fp; 124 smart_str buf; 125 int method; 126 zval *stream; 127 } php_curl_write; 128 129 typedef struct { 130 zval *func_name; 131 zend_fcall_info_cache fci_cache; 132 FILE *fp; 133 long fd; 134 int method; 135 zval *stream; 136 } php_curl_read; 137 138 typedef struct { 139 zval *func_name; 140 zend_fcall_info_cache fci_cache; 141 int method; 142 } php_curl_progress, php_curl_fnmatch; 143 144 typedef struct { 145 php_curl_write *write; 146 php_curl_write *write_header; 147 php_curl_read *read; 148 #if CURLOPT_PASSWDFUNCTION != 0 149 zval *passwd; 150 #endif 151 zval *std_err; 152 php_curl_progress *progress; 153 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ 154 php_curl_fnmatch *fnmatch; 155 #endif 156 } php_curl_handlers; 157 158 struct _php_curl_error { 159 char str[CURL_ERROR_SIZE + 1]; 160 int no; 161 }; 162 163 struct _php_curl_send_headers { 164 char *str; 165 size_t str_len; 166 }; 167 168 struct _php_curl_free { 169 zend_llist str; 170 zend_llist post; 171 HashTable *slist; 172 }; 173 174 typedef struct { 175 struct _php_curl_error err; 176 struct _php_curl_free *to_free; 177 struct _php_curl_send_headers header; 178 void ***thread_ctx; 179 CURL *cp; 180 php_curl_handlers *handlers; 181 long id; 182 zend_bool in_callback; 183 zval *clone; 184 zend_bool safe_upload; 185 } php_curl; 186 187 #define CURLOPT_SAFE_UPLOAD -1 188 189 typedef struct { 190 int still_running; 191 CURLM *multi; 192 zend_llist easyh; 193 } php_curlm; 194 195 typedef struct { 196 CURLSH *share; 197 } php_curlsh; 198 199 void _php_curl_cleanup_handle(php_curl *); 200 void _php_curl_multi_cleanup_list(void *data); 201 void _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC); 202 203 void curlfile_register_class(TSRMLS_D); 204 PHP_CURL_API extern zend_class_entry *curl_CURLFile_class; 205 206 #else 207 #define curl_module_ptr NULL 208 #endif /* HAVE_CURL */ 209 #define phpext_curl_ptr curl_module_ptr 210 #endif /* _PHP_CURL_H */ 211