curl_private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Sterling Hughes <sterling@php.net> |
  14. | Wez Furlong <wez@thebrainroom.com> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef _PHP_CURL_PRIVATE_H
  18. #define _PHP_CURL_PRIVATE_H
  19. #include "php_curl.h"
  20. #define PHP_CURL_DEBUG 0
  21. #include "php_version.h"
  22. #define PHP_CURL_VERSION PHP_VERSION
  23. #include <curl/curl.h>
  24. #include <curl/multi.h>
  25. #define CURLOPT_RETURNTRANSFER 19913
  26. #define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
  27. #define PHP_CURL_STDOUT 0
  28. #define PHP_CURL_FILE 1
  29. #define PHP_CURL_USER 2
  30. #define PHP_CURL_DIRECT 3
  31. #define PHP_CURL_RETURN 4
  32. #define PHP_CURL_IGNORE 7
  33. #define SAVE_CURL_ERROR(__handle, __err) \
  34. do { (__handle)->err.no = (int) __err; } while (0)
  35. PHP_MINIT_FUNCTION(curl);
  36. PHP_MSHUTDOWN_FUNCTION(curl);
  37. PHP_MINFO_FUNCTION(curl);
  38. typedef struct {
  39. zval func_name;
  40. zend_fcall_info_cache fci_cache;
  41. FILE *fp;
  42. smart_str buf;
  43. int method;
  44. zval stream;
  45. } php_curl_write;
  46. typedef struct {
  47. zval func_name;
  48. zend_fcall_info_cache fci_cache;
  49. FILE *fp;
  50. zend_resource *res;
  51. int method;
  52. zval stream;
  53. } php_curl_read;
  54. typedef struct {
  55. zval func_name;
  56. zend_fcall_info_cache fci_cache;
  57. } php_curl_callback;
  58. typedef struct {
  59. php_curl_write *write;
  60. php_curl_write *write_header;
  61. php_curl_read *read;
  62. zval std_err;
  63. php_curl_callback *progress;
  64. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  65. php_curl_callback *fnmatch;
  66. #endif
  67. } php_curl_handlers;
  68. struct _php_curl_error {
  69. char str[CURL_ERROR_SIZE + 1];
  70. int no;
  71. };
  72. struct _php_curl_send_headers {
  73. zend_string *str;
  74. };
  75. struct _php_curl_free {
  76. zend_llist post;
  77. zend_llist stream;
  78. #if LIBCURL_VERSION_NUM < 0x073800 /* 7.56.0 */
  79. zend_llist buffers;
  80. #endif
  81. HashTable *slist;
  82. };
  83. typedef struct {
  84. CURL *cp;
  85. php_curl_handlers handlers;
  86. struct _php_curl_free *to_free;
  87. struct _php_curl_send_headers header;
  88. struct _php_curl_error err;
  89. bool in_callback;
  90. uint32_t* clone;
  91. zval postfields;
  92. /* For CURLOPT_PRIVATE */
  93. zval private_data;
  94. /* CurlShareHandle object set using CURLOPT_SHARE. */
  95. struct _php_curlsh *share;
  96. zend_object std;
  97. } php_curl;
  98. #define CURLOPT_SAFE_UPLOAD -1
  99. typedef struct {
  100. php_curl_callback *server_push;
  101. } php_curlm_handlers;
  102. typedef struct {
  103. CURLM *multi;
  104. zend_llist easyh;
  105. php_curlm_handlers handlers;
  106. struct {
  107. int no;
  108. } err;
  109. zend_object std;
  110. } php_curlm;
  111. typedef struct _php_curlsh {
  112. CURLSH *share;
  113. struct {
  114. int no;
  115. } err;
  116. zend_object std;
  117. } php_curlsh;
  118. php_curl *init_curl_handle_into_zval(zval *curl);
  119. void init_curl_handle(php_curl *ch);
  120. void _php_curl_cleanup_handle(php_curl *);
  121. void _php_curl_multi_cleanup_list(void *data);
  122. void _php_curl_verify_handlers(php_curl *ch, int reporterror);
  123. void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
  124. static inline php_curl *curl_from_obj(zend_object *obj) {
  125. return (php_curl *)((char *)(obj) - XtOffsetOf(php_curl, std));
  126. }
  127. #define Z_CURL_P(zv) curl_from_obj(Z_OBJ_P(zv))
  128. static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
  129. return (php_curlsh *)((char *)(obj) - XtOffsetOf(php_curlsh, std));
  130. }
  131. #define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))
  132. void curl_multi_register_handlers(void);
  133. void curl_share_register_handlers(void);
  134. void curlfile_register_class(void);
  135. int curl_cast_object(zend_object *obj, zval *result, int type);
  136. #endif /* _PHP_CURL_PRIVATE_H */