You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
8.2 KiB

27 years ago
25 years ago
27 years ago
24 years ago
27 years ago
27 years ago
27 years ago
24 years ago
27 years ago
27 years ago
26 years ago
27 years ago
27 years ago
27 years ago
27 years ago
26 years ago
23 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
24 years ago
26 years ago
25 years ago
23 years ago
23 years ago
23 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 4 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2003 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.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: Zeev Suraski <zeev@zend.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef SAPI_H
  19. #define SAPI_H
  20. #include "zend.h"
  21. #include "zend_llist.h"
  22. #include "zend_operators.h"
  23. #include <sys/stat.h>
  24. #define SAPI_OPTION_NO_CHDIR 1
  25. #define SAPI_POST_BLOCK_SIZE 4000
  26. #ifdef PHP_WIN32
  27. # ifdef SAPI_EXPORTS
  28. # define SAPI_API __declspec(dllexport)
  29. # else
  30. # define SAPI_API __declspec(dllimport)
  31. # endif
  32. #else
  33. #define SAPI_API
  34. #endif
  35. #undef shutdown
  36. typedef struct {
  37. char *header;
  38. uint header_len;
  39. zend_bool replace;
  40. } sapi_header_struct;
  41. typedef struct {
  42. zend_llist headers;
  43. int http_response_code;
  44. unsigned char send_default_content_type;
  45. char *mimetype;
  46. char *http_status_line;
  47. } sapi_headers_struct;
  48. typedef struct _sapi_post_entry sapi_post_entry;
  49. typedef struct _sapi_module_struct sapi_module_struct;
  50. extern SAPI_API sapi_module_struct sapi_module; /* true global */
  51. /* Some values in this structure needs to be filled in before
  52. * calling sapi_activate(). We WILL change the `char *' entries,
  53. * so make sure that you allocate a separate buffer for them
  54. * and that you free them after sapi_deactivate().
  55. */
  56. typedef struct {
  57. const char *request_method;
  58. char *query_string;
  59. char *post_data, *raw_post_data;
  60. char *cookie_data;
  61. long content_length;
  62. uint post_data_length, raw_post_data_length;
  63. char *path_translated;
  64. char *request_uri;
  65. const char *content_type;
  66. zend_bool headers_only;
  67. zend_bool no_headers;
  68. zend_bool headers_read;
  69. sapi_post_entry *post_entry;
  70. char *content_type_dup;
  71. /* for HTTP authentication */
  72. char *auth_user;
  73. char *auth_password;
  74. /* this is necessary for the CGI SAPI module */
  75. char *argv0;
  76. /* this is necessary for Safe Mode */
  77. char *current_user;
  78. int current_user_length;
  79. /* this is necessary for CLI module */
  80. int argc;
  81. char **argv;
  82. } sapi_request_info;
  83. typedef struct _sapi_globals_struct {
  84. void *server_context;
  85. sapi_request_info request_info;
  86. sapi_headers_struct sapi_headers;
  87. int read_post_bytes;
  88. unsigned char headers_sent;
  89. struct stat global_stat;
  90. char *default_mimetype;
  91. char *default_charset;
  92. HashTable *rfc1867_uploaded_files;
  93. long post_max_size;
  94. int options;
  95. zend_bool sapi_started;
  96. } sapi_globals_struct;
  97. #ifdef ZTS
  98. # define SG(v) TSRMG(sapi_globals_id, sapi_globals_struct *, v)
  99. SAPI_API extern int sapi_globals_id;
  100. #else
  101. # define SG(v) (sapi_globals.v)
  102. extern SAPI_API sapi_globals_struct sapi_globals;
  103. #endif
  104. SAPI_API void sapi_startup(sapi_module_struct *sf);
  105. SAPI_API void sapi_shutdown(void);
  106. SAPI_API void sapi_activate(TSRMLS_D);
  107. SAPI_API void sapi_deactivate(TSRMLS_D);
  108. SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
  109. /*
  110. * This is the preferred and maintained API for
  111. * operating on HTTP headers.
  112. */
  113. /*
  114. * Always specify a sapi_header_line this way:
  115. *
  116. * sapi_header_line ctr = {0};
  117. */
  118. typedef struct {
  119. char *line; /* If you allocated this, you need to free it yourself */
  120. uint line_len;
  121. long response_code; /* long due to zend_parse_parameters compatibility */
  122. } sapi_header_line;
  123. typedef enum { /* Parameter: */
  124. SAPI_HEADER_REPLACE, /* sapi_header_line* */
  125. SAPI_HEADER_ADD, /* sapi_header_line* */
  126. SAPI_HEADER_SET_STATUS /* int */
  127. } sapi_header_op_enum;
  128. SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC);
  129. /* Deprecated functions. Use sapi_header_op instead. */
  130. SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC);
  131. #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1 TSRMLS_CC)
  132. SAPI_API int sapi_send_headers(TSRMLS_D);
  133. SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
  134. SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
  135. SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry);
  136. SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry);
  137. SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry);
  138. SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D));
  139. SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC));
  140. SAPI_API int sapi_flush(TSRMLS_D);
  141. SAPI_API struct stat *sapi_get_stat(TSRMLS_D);
  142. SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC);
  143. SAPI_API char *sapi_get_default_content_type(TSRMLS_D);
  144. SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC);
  145. SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC);
  146. SAPI_API void sapi_activate_headers_only(TSRMLS_D);
  147. SAPI_API int sapi_get_fd(int *fd TSRMLS_DC);
  148. SAPI_API int sapi_force_http_10(TSRMLS_D);
  149. SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
  150. SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
  151. struct _sapi_module_struct {
  152. char *name;
  153. char *pretty_name;
  154. int (*startup)(struct _sapi_module_struct *sapi_module);
  155. int (*shutdown)(struct _sapi_module_struct *sapi_module);
  156. int (*activate)(TSRMLS_D);
  157. int (*deactivate)(TSRMLS_D);
  158. int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
  159. void (*flush)(void *server_context);
  160. struct stat *(*get_stat)(TSRMLS_D);
  161. char *(*getenv)(char *name, size_t name_len TSRMLS_DC);
  162. void (*sapi_error)(int type, const char *error_msg, ...);
  163. int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC);
  164. int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);
  165. void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC);
  166. int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC);
  167. char *(*read_cookies)(TSRMLS_D);
  168. void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
  169. void (*log_message)(char *message);
  170. char *php_ini_path_override;
  171. void (*block_interruptions)(void);
  172. void (*unblock_interruptions)(void);
  173. void (*default_post_reader)(TSRMLS_D);
  174. void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
  175. char *executable_location;
  176. int php_ini_ignore;
  177. int (*get_fd)(int *fd TSRMLS_DC);
  178. int (*force_http_10)(TSRMLS_D);
  179. int (*get_target_uid)(uid_t * TSRMLS_DC);
  180. int (*get_target_gid)(gid_t * TSRMLS_DC);
  181. };
  182. struct _sapi_post_entry {
  183. char *content_type;
  184. uint content_type_len;
  185. void (*post_reader)(TSRMLS_D);
  186. void (*post_handler)(char *content_type_dup, void *arg TSRMLS_DC);
  187. };
  188. /* header_handler() constants */
  189. #define SAPI_HEADER_ADD (1<<0)
  190. #define SAPI_HEADER_DELETE_ALL (1<<1)
  191. #define SAPI_HEADER_SEND_NOW (1<<2)
  192. #define SAPI_HEADER_SENT_SUCCESSFULLY 1
  193. #define SAPI_HEADER_DO_SEND 2
  194. #define SAPI_HEADER_SEND_FAILED 3
  195. #define SAPI_DEFAULT_MIMETYPE "text/html"
  196. #define SAPI_DEFAULT_CHARSET ""
  197. #define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
  198. #define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D)
  199. #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC)
  200. #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
  201. SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
  202. SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
  203. SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
  204. #define STANDARD_SAPI_MODULE_PROPERTIES
  205. #endif /* SAPI_H */
  206. /*
  207. * Local variables:
  208. * tab-width: 4
  209. * c-basic-offset: 4
  210. * End:
  211. */