PageRenderTime 78ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext_zend_compat/php-src/main/SAPI.h

https://gitlab.com/iranjith4/hhvm
C Header | 310 lines | 195 code | 72 blank | 43 comment | 1 complexity | 8798b8139857de4be7538678e9592c28 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2013 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: Zeev Suraski <zeev@zend.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef SAPI_H
  20. #define SAPI_H
  21. #include "zend.h"
  22. #include "zend_API.h"
  23. #include "zend_llist.h"
  24. #include "zend_operators.h"
  25. #include <sys/stat.h>
  26. #define SAPI_OPTION_NO_CHDIR 1
  27. #define SAPI_POST_BLOCK_SIZE 4000
  28. #if defined(__GNUC__) && __GNUC__ >= 4
  29. # define SAPI_API __attribute__ ((__visibility__("default")))
  30. #else
  31. # define SAPI_API
  32. #endif
  33. #undef shutdown
  34. typedef struct {
  35. char *header;
  36. uint header_len;
  37. } sapi_header_struct;
  38. typedef struct {
  39. zend_llist headers;
  40. int http_response_code;
  41. unsigned char send_default_content_type;
  42. char *mimetype;
  43. char *http_status_line;
  44. } sapi_headers_struct;
  45. typedef struct _sapi_post_entry sapi_post_entry;
  46. typedef struct _sapi_module_struct sapi_module_struct;
  47. BEGIN_EXTERN_C()
  48. extern SAPI_API sapi_module_struct sapi_module; /* true global */
  49. END_EXTERN_C()
  50. /* Some values in this structure needs to be filled in before
  51. * calling sapi_activate(). We WILL change the `char *' entries,
  52. * so make sure that you allocate a separate buffer for them
  53. * and that you free them after sapi_deactivate().
  54. */
  55. typedef struct {
  56. const char *request_method;
  57. char *query_string;
  58. char *post_data, *raw_post_data;
  59. char *cookie_data;
  60. long content_length;
  61. uint post_data_length, raw_post_data_length;
  62. char *path_translated;
  63. char *request_uri;
  64. const char *content_type;
  65. zend_bool headers_only;
  66. zend_bool no_headers;
  67. zend_bool headers_read;
  68. sapi_post_entry *post_entry;
  69. char *content_type_dup;
  70. /* for HTTP authentication */
  71. char *auth_user;
  72. char *auth_password;
  73. char *auth_digest;
  74. /* this is necessary for the CGI SAPI module */
  75. char *argv0;
  76. char *current_user;
  77. int current_user_length;
  78. /* this is necessary for CLI module */
  79. int argc;
  80. char **argv;
  81. int proto_num;
  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. double global_request_time;
  97. #ifndef HHVM
  98. HashTable known_post_content_types;
  99. #endif
  100. zval *callback_func;
  101. zend_fcall_info_cache fci_cache;
  102. zend_bool callback_run;
  103. } sapi_globals_struct;
  104. BEGIN_EXTERN_C()
  105. #ifdef ZTS
  106. # define SG(v) TSRMG(sapi_globals_id, sapi_globals_struct *, v)
  107. SAPI_API extern int sapi_globals_id;
  108. #else
  109. # define SG(v) (sapi_globals.v)
  110. extern SAPI_API sapi_globals_struct sapi_globals;
  111. #endif
  112. SAPI_API void sapi_startup(sapi_module_struct *sf);
  113. SAPI_API void sapi_shutdown(void);
  114. SAPI_API void sapi_activate(TSRMLS_D);
  115. SAPI_API void sapi_deactivate(TSRMLS_D);
  116. SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
  117. END_EXTERN_C()
  118. /*
  119. * This is the preferred and maintained API for
  120. * operating on HTTP headers.
  121. */
  122. /*
  123. * Always specify a sapi_header_line this way:
  124. *
  125. * sapi_header_line ctr = {0};
  126. */
  127. typedef struct {
  128. char *line; /* If you allocated this, you need to free it yourself */
  129. uint line_len;
  130. long response_code; /* long due to zend_parse_parameters compatibility */
  131. } sapi_header_line;
  132. typedef enum { /* Parameter: */
  133. SAPI_HEADER_REPLACE, /* sapi_header_line* */
  134. SAPI_HEADER_ADD, /* sapi_header_line* */
  135. SAPI_HEADER_DELETE, /* sapi_header_line* */
  136. SAPI_HEADER_DELETE_ALL, /* void */
  137. SAPI_HEADER_SET_STATUS /* int */
  138. } sapi_header_op_enum;
  139. BEGIN_EXTERN_C()
  140. SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC);
  141. /* Deprecated functions. Use sapi_header_op instead. */
  142. SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC);
  143. #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1 TSRMLS_CC)
  144. SAPI_API int sapi_send_headers(TSRMLS_D);
  145. SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
  146. SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
  147. SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry TSRMLS_DC);
  148. SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
  149. SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
  150. SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC);
  151. SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC) TSRMLS_DC);
  152. SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC);
  153. SAPI_API int sapi_flush(TSRMLS_D);
  154. SAPI_API struct stat *sapi_get_stat(TSRMLS_D);
  155. SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC);
  156. SAPI_API char *sapi_get_default_content_type(TSRMLS_D);
  157. SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC);
  158. SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC);
  159. SAPI_API void sapi_activate_headers_only(TSRMLS_D);
  160. SAPI_API int sapi_get_fd(int *fd TSRMLS_DC);
  161. SAPI_API int sapi_force_http_10(TSRMLS_D);
  162. SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
  163. SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
  164. SAPI_API double sapi_get_request_time(TSRMLS_D);
  165. SAPI_API void sapi_terminate_process(TSRMLS_D);
  166. END_EXTERN_C()
  167. struct _sapi_module_struct {
  168. char *name;
  169. char *pretty_name;
  170. int (*startup)(struct _sapi_module_struct *sapi_module);
  171. int (*shutdown)(struct _sapi_module_struct *sapi_module);
  172. int (*activate)(TSRMLS_D);
  173. int (*deactivate)(TSRMLS_D);
  174. int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
  175. void (*flush)(void *server_context);
  176. struct stat *(*get_stat)(TSRMLS_D);
  177. char *(*getenv)(char *name, size_t name_len TSRMLS_DC);
  178. void (*sapi_error)(int type, const char *error_msg, ...);
  179. int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
  180. int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);
  181. void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC);
  182. int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC);
  183. char *(*read_cookies)(TSRMLS_D);
  184. void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
  185. void (*log_message)(char *message TSRMLS_DC);
  186. double (*get_request_time)(TSRMLS_D);
  187. void (*terminate_process)(TSRMLS_D);
  188. char *php_ini_path_override;
  189. void (*block_interruptions)(void);
  190. void (*unblock_interruptions)(void);
  191. void (*default_post_reader)(TSRMLS_D);
  192. void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
  193. char *executable_location;
  194. int php_ini_ignore;
  195. int php_ini_ignore_cwd; /* don't look for php.ini in the current directory */
  196. int (*get_fd)(int *fd TSRMLS_DC);
  197. int (*force_http_10)(TSRMLS_D);
  198. int (*get_target_uid)(uid_t * TSRMLS_DC);
  199. int (*get_target_gid)(gid_t * TSRMLS_DC);
  200. unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC);
  201. void (*ini_defaults)(HashTable *configuration_hash);
  202. int phpinfo_as_text;
  203. char *ini_entries;
  204. const zend_function_entry *additional_functions;
  205. unsigned int (*input_filter_init)(TSRMLS_D);
  206. };
  207. struct _sapi_post_entry {
  208. char *content_type;
  209. uint content_type_len;
  210. void (*post_reader)(TSRMLS_D);
  211. void (*post_handler)(char *content_type_dup, void *arg TSRMLS_DC);
  212. };
  213. /* header_handler() constants */
  214. #define SAPI_HEADER_ADD (1<<0)
  215. #define SAPI_HEADER_SENT_SUCCESSFULLY 1
  216. #define SAPI_HEADER_DO_SEND 2
  217. #define SAPI_HEADER_SEND_FAILED 3
  218. #define SAPI_DEFAULT_MIMETYPE "text/html"
  219. #define SAPI_DEFAULT_CHARSET ""
  220. #define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
  221. #define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D)
  222. #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC)
  223. #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
  224. #define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC)
  225. BEGIN_EXTERN_C()
  226. SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
  227. SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
  228. SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
  229. SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter);
  230. END_EXTERN_C()
  231. #define STANDARD_SAPI_MODULE_PROPERTIES
  232. #endif /* SAPI_H */
  233. /*
  234. * Local variables:
  235. * tab-width: 4
  236. * c-basic-offset: 4
  237. * End:
  238. */