root/main/SAPI.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. BEGIN_EXTERN_C
  2. END_EXTERN_C
  3. END_EXTERN_C

   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 7                                                        |
   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:  Zeev Suraski <zeev@zend.com>                                |
  16    +----------------------------------------------------------------------+
  17 */
  18 
  19 /* $Id$ */
  20 
  21 #ifndef SAPI_H
  22 #define SAPI_H
  23 
  24 #include "php.h"
  25 #include "zend.h"
  26 #include "zend_API.h"
  27 #include "zend_llist.h"
  28 #include "zend_operators.h"
  29 #ifdef PHP_WIN32
  30 #include "win95nt.h"
  31 #include "win32/php_stdint.h"
  32 #endif
  33 #include <sys/stat.h>
  34 #include "php.h"
  35 
  36 #define SAPI_OPTION_NO_CHDIR 1
  37 #define SAPI_POST_BLOCK_SIZE 0x4000
  38 
  39 #ifdef PHP_WIN32
  40 #       ifdef SAPI_EXPORTS
  41 #               define SAPI_API __declspec(dllexport)
  42 #       else
  43 #               define SAPI_API __declspec(dllimport)
  44 #       endif
  45 #elif defined(__GNUC__) && __GNUC__ >= 4
  46 #       define SAPI_API __attribute__ ((visibility("default")))
  47 #else
  48 #       define SAPI_API
  49 #endif
  50 
  51 #undef shutdown
  52 
  53 typedef struct {
  54         char *header;
  55         size_t header_len;
  56 } sapi_header_struct;
  57 
  58 
  59 typedef struct {
  60         zend_llist headers;
  61         int http_response_code;
  62         unsigned char send_default_content_type;
  63         char *mimetype;
  64         char *http_status_line;
  65 } sapi_headers_struct;
  66 
  67 
  68 typedef struct _sapi_post_entry sapi_post_entry;
  69 typedef struct _sapi_module_struct sapi_module_struct;
  70 
  71 BEGIN_EXTERN_C()
  72 extern SAPI_API sapi_module_struct sapi_module;  /* true global */
  73 END_EXTERN_C()
  74 
  75 /* Some values in this structure needs to be filled in before
  76  * calling sapi_activate(). We WILL change the `char *' entries,
  77  * so make sure that you allocate a separate buffer for them
  78  * and that you free them after sapi_deactivate().
  79  */
  80 
  81 typedef struct {
  82         const char *request_method;
  83         char *query_string;
  84         char *cookie_data;
  85         zend_long content_length;
  86 
  87         char *path_translated;
  88         char *request_uri;
  89 
  90         /* Do not use request_body directly, but the php://input stream wrapper instead */
  91         struct _php_stream *request_body;
  92 
  93         const char *content_type;
  94 
  95         zend_bool headers_only;
  96         zend_bool no_headers;
  97         zend_bool headers_read;
  98 
  99         sapi_post_entry *post_entry;
 100 
 101         char *content_type_dup;
 102 
 103         /* for HTTP authentication */
 104         char *auth_user;
 105         char *auth_password;
 106         char *auth_digest;
 107 
 108         /* this is necessary for the CGI SAPI module */
 109         char *argv0;
 110 
 111         char *current_user;
 112         int current_user_length;
 113 
 114         /* this is necessary for CLI module */
 115         int argc;
 116         char **argv;
 117         int proto_num;
 118 } sapi_request_info;
 119 
 120 
 121 typedef struct _sapi_globals_struct {
 122         void *server_context;
 123         sapi_request_info request_info;
 124         sapi_headers_struct sapi_headers;
 125         int64_t read_post_bytes;
 126         unsigned char post_read;
 127         unsigned char headers_sent;
 128         zend_stat_t global_stat;
 129         char *default_mimetype;
 130         char *default_charset;
 131         HashTable *rfc1867_uploaded_files;
 132         zend_long post_max_size;
 133         int options;
 134         zend_bool sapi_started;
 135         double global_request_time;
 136         HashTable known_post_content_types;
 137         zval callback_func;
 138         zend_fcall_info_cache fci_cache;
 139 } sapi_globals_struct;
 140 
 141 
 142 BEGIN_EXTERN_C()
 143 #ifdef ZTS
 144 # define SG(v) ZEND_TSRMG(sapi_globals_id, sapi_globals_struct *, v)
 145 SAPI_API extern int sapi_globals_id;
 146 #else
 147 # define SG(v) (sapi_globals.v)
 148 extern SAPI_API sapi_globals_struct sapi_globals;
 149 #endif
 150 
 151 SAPI_API void sapi_startup(sapi_module_struct *sf);
 152 SAPI_API void sapi_shutdown(void);
 153 SAPI_API void sapi_activate(void);
 154 SAPI_API void sapi_deactivate(void);
 155 SAPI_API void sapi_initialize_empty_request(void);
 156 END_EXTERN_C()
 157 
 158 /*
 159  * This is the preferred and maintained API for
 160  * operating on HTTP headers.
 161  */
 162 
 163 /*
 164  * Always specify a sapi_header_line this way:
 165  *
 166  *     sapi_header_line ctr = {0};
 167  */
 168 
 169 typedef struct {
 170         char *line; /* If you allocated this, you need to free it yourself */
 171         size_t line_len;
 172         zend_long response_code; /* long due to zend_parse_parameters compatibility */
 173 } sapi_header_line;
 174 
 175 typedef enum {                                  /* Parameter:                   */
 176         SAPI_HEADER_REPLACE,            /* sapi_header_line*    */
 177         SAPI_HEADER_ADD,                        /* sapi_header_line*    */
 178         SAPI_HEADER_DELETE,                     /* sapi_header_line*    */
 179         SAPI_HEADER_DELETE_ALL,         /* void                                 */
 180         SAPI_HEADER_SET_STATUS          /* int                                  */
 181 } sapi_header_op_enum;
 182 
 183 BEGIN_EXTERN_C()
 184 SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg);
 185 
 186 /* Deprecated functions. Use sapi_header_op instead. */
 187 SAPI_API int sapi_add_header_ex(char *header_line, size_t header_line_len, zend_bool duplicate, zend_bool replace);
 188 #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1)
 189 
 190 
 191 SAPI_API int sapi_send_headers(void);
 192 SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
 193 SAPI_API void sapi_handle_post(void *arg);
 194 SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen);
 195 SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry);
 196 SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry);
 197 SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry);
 198 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void));
 199 SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray));
 200 SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void));
 201 
 202 SAPI_API int sapi_flush(void);
 203 SAPI_API zend_stat_t *sapi_get_stat(void);
 204 SAPI_API char *sapi_getenv(char *name, size_t name_len);
 205 
 206 SAPI_API char *sapi_get_default_content_type(void);
 207 SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header);
 208 SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len);
 209 SAPI_API void sapi_activate_headers_only(void);
 210 
 211 SAPI_API int sapi_get_fd(int *fd);
 212 SAPI_API int sapi_force_http_10(void);
 213 
 214 SAPI_API int sapi_get_target_uid(uid_t *);
 215 SAPI_API int sapi_get_target_gid(gid_t *);
 216 SAPI_API double sapi_get_request_time(void);
 217 SAPI_API void sapi_terminate_process(void);
 218 END_EXTERN_C()
 219 
 220 struct _sapi_module_struct {
 221         char *name;
 222         char *pretty_name;
 223 
 224         int (*startup)(struct _sapi_module_struct *sapi_module);
 225         int (*shutdown)(struct _sapi_module_struct *sapi_module);
 226 
 227         int (*activate)(void);
 228         int (*deactivate)(void);
 229 
 230         size_t (*ub_write)(const char *str, size_t str_length);
 231         void (*flush)(void *server_context);
 232         zend_stat_t *(*get_stat)(void);
 233         char *(*getenv)(char *name, size_t name_len);
 234 
 235         void (*sapi_error)(int type, const char *error_msg, ...);
 236 
 237         int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers);
 238         int (*send_headers)(sapi_headers_struct *sapi_headers);
 239         void (*send_header)(sapi_header_struct *sapi_header, void *server_context);
 240 
 241         size_t (*read_post)(char *buffer, size_t count_bytes);
 242         char *(*read_cookies)(void);
 243 
 244         void (*register_server_variables)(zval *track_vars_array);
 245         void (*log_message)(char *message);
 246         double (*get_request_time)(void);
 247         void (*terminate_process)(void);
 248 
 249         char *php_ini_path_override;
 250 
 251         void (*block_interruptions)(void);
 252         void (*unblock_interruptions)(void);
 253 
 254         void (*default_post_reader)(void);
 255         void (*treat_data)(int arg, char *str, zval *destArray);
 256         char *executable_location;
 257 
 258         int php_ini_ignore;
 259         int php_ini_ignore_cwd; /* don't look for php.ini in the current directory */
 260 
 261         int (*get_fd)(int *fd);
 262 
 263         int (*force_http_10)(void);
 264 
 265         int (*get_target_uid)(uid_t *);
 266         int (*get_target_gid)(gid_t *);
 267 
 268         unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len);
 269 
 270         void (*ini_defaults)(HashTable *configuration_hash);
 271         int phpinfo_as_text;
 272 
 273         char *ini_entries;
 274         const zend_function_entry *additional_functions;
 275         unsigned int (*input_filter_init)(void);
 276 };
 277 
 278 
 279 struct _sapi_post_entry {
 280         char *content_type;
 281         uint content_type_len;
 282         void (*post_reader)(void);
 283         void (*post_handler)(char *content_type_dup, void *arg);
 284 };
 285 
 286 /* header_handler() constants */
 287 #define SAPI_HEADER_ADD                 (1<<0)
 288 
 289 
 290 #define SAPI_HEADER_SENT_SUCCESSFULLY   1
 291 #define SAPI_HEADER_DO_SEND                             2
 292 #define SAPI_HEADER_SEND_FAILED                 3
 293 
 294 #define SAPI_DEFAULT_MIMETYPE           "text/html"
 295 #define SAPI_DEFAULT_CHARSET            PHP_DEFAULT_CHARSET
 296 #define SAPI_PHP_VERSION_HEADER         "X-Powered-By: PHP/" PHP_VERSION
 297 
 298 #define SAPI_POST_READER_FUNC(post_reader) void post_reader(void)
 299 #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg)
 300 
 301 #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray)
 302 #define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len)
 303 
 304 BEGIN_EXTERN_C()
 305 SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
 306 SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
 307 SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
 308 SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter);
 309 END_EXTERN_C()
 310 
 311 #define STANDARD_SAPI_MODULE_PROPERTIES
 312 
 313 #endif /* SAPI_H */
 314 
 315 /*
 316  * Local variables:
 317  * tab-width: 4
 318  * c-basic-offset: 4
 319  * End:
 320  */

/* [<][>][^][v][top][bottom][index][help] */