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 5                                                        |
   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 
  35 #define SAPI_OPTION_NO_CHDIR 1
  36 #define SAPI_POST_BLOCK_SIZE 0x4000
  37 
  38 #ifdef PHP_WIN32
  39 #       ifdef SAPI_EXPORTS
  40 #               define SAPI_API __declspec(dllexport) 
  41 #       else
  42 #               define SAPI_API __declspec(dllimport) 
  43 #       endif
  44 #elif defined(__GNUC__) && __GNUC__ >= 4
  45 #       define SAPI_API __attribute__ ((visibility("default")))
  46 #else
  47 #       define SAPI_API
  48 #endif
  49 
  50 #undef shutdown
  51 
  52 typedef struct {
  53         char *header;
  54         uint header_len;
  55 } sapi_header_struct;
  56 
  57 
  58 typedef struct {
  59         zend_llist headers;
  60         int http_response_code;
  61         unsigned char send_default_content_type;
  62         char *mimetype;
  63         char *http_status_line;
  64 } sapi_headers_struct;
  65 
  66 
  67 typedef struct _sapi_post_entry sapi_post_entry;
  68 typedef struct _sapi_module_struct sapi_module_struct;
  69 
  70 BEGIN_EXTERN_C()
  71 extern SAPI_API sapi_module_struct sapi_module;  /* true global */
  72 END_EXTERN_C()
  73 
  74 /* Some values in this structure needs to be filled in before
  75  * calling sapi_activate(). We WILL change the `char *' entries,
  76  * so make sure that you allocate a separate buffer for them
  77  * and that you free them after sapi_deactivate().
  78  */
  79 
  80 typedef struct {
  81         const char *request_method;
  82         char *query_string;
  83         char *cookie_data;
  84         long content_length;
  85 
  86         char *path_translated;
  87         char *request_uri;
  88 
  89         /* Do not use request_body directly, but the php://input stream wrapper instead */
  90         struct _php_stream *request_body;
  91 
  92         const char *content_type;
  93 
  94         zend_bool headers_only;
  95         zend_bool no_headers;
  96         zend_bool headers_read;
  97 
  98         sapi_post_entry *post_entry;
  99 
 100         char *content_type_dup;
 101 
 102         /* for HTTP authentication */
 103         char *auth_user;
 104         char *auth_password;
 105         char *auth_digest;
 106 
 107         /* this is necessary for the CGI SAPI module */
 108         char *argv0;
 109 
 110         char *current_user;
 111         int current_user_length;
 112 
 113         /* this is necessary for CLI module */
 114         int argc;
 115         char **argv;
 116         int proto_num;
 117 } sapi_request_info;
 118 
 119 
 120 typedef struct _sapi_globals_struct {
 121         void *server_context;
 122         sapi_request_info request_info;
 123         sapi_headers_struct sapi_headers;
 124         int64_t read_post_bytes;
 125         unsigned char post_read;
 126         unsigned char headers_sent;
 127         struct stat global_stat;
 128         char *default_mimetype;
 129         char *default_charset;
 130         HashTable *rfc1867_uploaded_files;
 131         long post_max_size;
 132         int options;
 133         zend_bool sapi_started;
 134         double global_request_time;
 135         HashTable known_post_content_types;
 136         zval *callback_func;
 137         zend_fcall_info_cache fci_cache;
 138         zend_bool callback_run;
 139 } sapi_globals_struct;
 140 
 141 
 142 BEGIN_EXTERN_C()
 143 #ifdef ZTS
 144 # define SG(v) 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(TSRMLS_D);
 154 SAPI_API void sapi_deactivate(TSRMLS_D);
 155 SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
 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         uint line_len;
 172         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 TSRMLS_DC);
 185 
 186 /* Deprecated functions. Use sapi_header_op instead. */
 187 SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC);
 188 #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1 TSRMLS_CC)
 189 
 190 
 191 SAPI_API int sapi_send_headers(TSRMLS_D);
 192 SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
 193 SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
 194 SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC);
 195 SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry TSRMLS_DC);
 196 SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
 197 SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
 198 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC);
 199 SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC) TSRMLS_DC);
 200 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);
 201 
 202 SAPI_API int sapi_flush(TSRMLS_D);
 203 SAPI_API struct stat *sapi_get_stat(TSRMLS_D);
 204 SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC);
 205 
 206 SAPI_API char *sapi_get_default_content_type(TSRMLS_D);
 207 SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC);
 208 SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC);
 209 SAPI_API void sapi_activate_headers_only(TSRMLS_D);
 210 
 211 SAPI_API int sapi_get_fd(int *fd TSRMLS_DC);
 212 SAPI_API int sapi_force_http_10(TSRMLS_D);
 213 
 214 SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
 215 SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
 216 SAPI_API double sapi_get_request_time(TSRMLS_D);
 217 SAPI_API void sapi_terminate_process(TSRMLS_D);
 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)(TSRMLS_D);
 228         int (*deactivate)(TSRMLS_D);
 229 
 230         int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
 231         void (*flush)(void *server_context);
 232         struct stat *(*get_stat)(TSRMLS_D);
 233         char *(*getenv)(char *name, size_t name_len TSRMLS_DC);
 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 TSRMLS_DC);
 238         int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);
 239         void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC);
 240 
 241         int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC);
 242         char *(*read_cookies)(TSRMLS_D);
 243 
 244         void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
 245         void (*log_message)(char *message TSRMLS_DC);
 246         double (*get_request_time)(TSRMLS_D);
 247         void (*terminate_process)(TSRMLS_D);
 248 
 249         char *php_ini_path_override;
 250 
 251         void (*block_interruptions)(void);
 252         void (*unblock_interruptions)(void);
 253 
 254         void (*default_post_reader)(TSRMLS_D);
 255         void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
 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 TSRMLS_DC);
 262 
 263         int (*force_http_10)(TSRMLS_D);
 264 
 265         int (*get_target_uid)(uid_t * TSRMLS_DC);
 266         int (*get_target_gid)(gid_t * TSRMLS_DC);
 267 
 268         unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC);
 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)(TSRMLS_D);
 276 };
 277 
 278 
 279 struct _sapi_post_entry {
 280         char *content_type;
 281         uint content_type_len;
 282         void (*post_reader)(TSRMLS_D);
 283         void (*post_handler)(char *content_type_dup, void *arg TSRMLS_DC);
 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(TSRMLS_D)
 299 #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC)
 300 
 301 #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
 302 #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)
 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] */