php_curl.h 5.9 KB

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