Back to index

php5  5.3.10
SAPI.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author:  Zeev Suraski <zeev@zend.com>                                |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: SAPI.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef SAPI_H
00022 #define SAPI_H
00023 
00024 #include "zend.h"
00025 #include "zend_API.h"
00026 #include "zend_llist.h"
00027 #include "zend_operators.h"
00028 #ifdef PHP_WIN32
00029 #include "win95nt.h"
00030 #endif
00031 #include <sys/stat.h>
00032 
00033 #define SAPI_OPTION_NO_CHDIR 1
00034 
00035 #define SAPI_POST_BLOCK_SIZE 4000
00036 
00037 #ifdef PHP_WIN32
00038 #      ifdef SAPI_EXPORTS
00039 #             define SAPI_API __declspec(dllexport) 
00040 #      else
00041 #             define SAPI_API __declspec(dllimport) 
00042 #      endif
00043 #elif defined(__GNUC__) && __GNUC__ >= 4
00044 #      define SAPI_API __attribute__ ((visibility("default")))
00045 #else
00046 #      define SAPI_API
00047 #endif
00048 
00049 #undef shutdown
00050 
00051 typedef struct {
00052        char *header;
00053        uint header_len;
00054 } sapi_header_struct;
00055 
00056 
00057 typedef struct {
00058        zend_llist headers;
00059        int http_response_code;
00060        unsigned char send_default_content_type;
00061        char *mimetype;
00062        char *http_status_line;
00063 } sapi_headers_struct;
00064 
00065 
00066 typedef struct _sapi_post_entry sapi_post_entry;
00067 typedef struct _sapi_module_struct sapi_module_struct;
00068 
00069 BEGIN_EXTERN_C()
00070 extern SAPI_API sapi_module_struct sapi_module;  /* true global */
00071 END_EXTERN_C()
00072 
00073 /* Some values in this structure needs to be filled in before
00074  * calling sapi_activate(). We WILL change the `char *' entries,
00075  * so make sure that you allocate a separate buffer for them
00076  * and that you free them after sapi_deactivate().
00077  */
00078 
00079 typedef struct {
00080        const char *request_method;
00081        char *query_string;
00082        char *post_data, *raw_post_data;
00083        char *cookie_data;
00084        long content_length;
00085        uint post_data_length, raw_post_data_length;
00086 
00087        char *path_translated;
00088        char *request_uri;
00089 
00090        const char *content_type;
00091 
00092        zend_bool headers_only;
00093        zend_bool no_headers;
00094        zend_bool headers_read;
00095 
00096        sapi_post_entry *post_entry;
00097 
00098        char *content_type_dup;
00099 
00100        /* for HTTP authentication */
00101        char *auth_user;
00102        char *auth_password;
00103        char *auth_digest;
00104 
00105        /* this is necessary for the CGI SAPI module */
00106        char *argv0;
00107 
00108        /* this is necessary for Safe Mode */
00109        char *current_user;
00110        int current_user_length;
00111 
00112        /* this is necessary for CLI module */
00113        int argc;
00114        char **argv;
00115        int proto_num;
00116 } sapi_request_info;
00117 
00118 
00119 typedef struct _sapi_globals_struct {
00120        void *server_context;
00121        sapi_request_info request_info;
00122        sapi_headers_struct sapi_headers;
00123        int read_post_bytes;
00124        unsigned char headers_sent;
00125        struct stat global_stat;
00126        char *default_mimetype;
00127        char *default_charset;
00128        HashTable *rfc1867_uploaded_files;
00129        long post_max_size;
00130        int options;
00131        zend_bool sapi_started;
00132        time_t global_request_time;
00133        HashTable known_post_content_types;
00134 } sapi_globals_struct;
00135 
00136 
00137 BEGIN_EXTERN_C()
00138 #ifdef ZTS
00139 # define SG(v) TSRMG(sapi_globals_id, sapi_globals_struct *, v)
00140 SAPI_API extern int sapi_globals_id;
00141 #else
00142 # define SG(v) (sapi_globals.v)
00143 extern SAPI_API sapi_globals_struct sapi_globals;
00144 #endif
00145 
00146 SAPI_API void sapi_startup(sapi_module_struct *sf);
00147 SAPI_API void sapi_shutdown(void);
00148 SAPI_API void sapi_activate(TSRMLS_D);
00149 SAPI_API void sapi_deactivate(TSRMLS_D);
00150 SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
00151 END_EXTERN_C()
00152 
00153 /*
00154  * This is the preferred and maintained API for 
00155  * operating on HTTP headers.
00156  */
00157 
00158 /*
00159  * Always specify a sapi_header_line this way:
00160  *
00161  *     sapi_header_line ctr = {0};
00162  */
00163  
00164 typedef struct {
00165        char *line; /* If you allocated this, you need to free it yourself */
00166        uint line_len;
00167        long response_code; /* long due to zend_parse_parameters compatibility */
00168 } sapi_header_line;
00169 
00170 typedef enum {                                   /* Parameter:                      */
00171        SAPI_HEADER_REPLACE,        /* sapi_header_line*        */
00172        SAPI_HEADER_ADD,                   /* sapi_header_line*        */
00173        SAPI_HEADER_DELETE,                /* sapi_header_line*        */
00174        SAPI_HEADER_DELETE_ALL,            /* void                                   */
00175        SAPI_HEADER_SET_STATUS             /* int                                    */
00176 } sapi_header_op_enum;
00177 
00178 BEGIN_EXTERN_C()
00179 SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC);
00180 
00181 /* Deprecated functions. Use sapi_header_op instead. */
00182 SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC);
00183 #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1 TSRMLS_CC)
00184 
00185 
00186 SAPI_API int sapi_send_headers(TSRMLS_D);
00187 SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
00188 SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
00189 
00190 SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry TSRMLS_DC);
00191 SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
00192 SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
00193 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D));
00194 SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC));
00195 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));
00196 
00197 SAPI_API int sapi_flush(TSRMLS_D);
00198 SAPI_API struct stat *sapi_get_stat(TSRMLS_D);
00199 SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC);
00200 
00201 SAPI_API char *sapi_get_default_content_type(TSRMLS_D);
00202 SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC);
00203 SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC);
00204 SAPI_API void sapi_activate_headers_only(TSRMLS_D);
00205 
00206 SAPI_API int sapi_get_fd(int *fd TSRMLS_DC);
00207 SAPI_API int sapi_force_http_10(TSRMLS_D);
00208 
00209 SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
00210 SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
00211 SAPI_API time_t sapi_get_request_time(TSRMLS_D);
00212 SAPI_API void sapi_terminate_process(TSRMLS_D);
00213 END_EXTERN_C()
00214 
00215 struct _sapi_module_struct {
00216        char *name;
00217        char *pretty_name;
00218 
00219        int (*startup)(struct _sapi_module_struct *sapi_module);
00220        int (*shutdown)(struct _sapi_module_struct *sapi_module);
00221 
00222        int (*activate)(TSRMLS_D);
00223        int (*deactivate)(TSRMLS_D);
00224 
00225        int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
00226        void (*flush)(void *server_context);
00227        struct stat *(*get_stat)(TSRMLS_D);
00228        char *(*getenv)(char *name, size_t name_len TSRMLS_DC);
00229 
00230        void (*sapi_error)(int type, const char *error_msg, ...);
00231 
00232        int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
00233        int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);
00234        void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC);
00235 
00236        int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC);
00237        char *(*read_cookies)(TSRMLS_D);
00238 
00239        void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
00240        void (*log_message)(char *message);
00241        time_t (*get_request_time)(TSRMLS_D);
00242        void (*terminate_process)(TSRMLS_D);
00243 
00244        char *php_ini_path_override;
00245 
00246        void (*block_interruptions)(void);
00247        void (*unblock_interruptions)(void);
00248 
00249        void (*default_post_reader)(TSRMLS_D);
00250        void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
00251        char *executable_location;
00252 
00253        int php_ini_ignore;
00254 
00255        int (*get_fd)(int *fd TSRMLS_DC);
00256 
00257        int (*force_http_10)(TSRMLS_D);
00258 
00259        int (*get_target_uid)(uid_t * TSRMLS_DC);
00260        int (*get_target_gid)(gid_t * TSRMLS_DC);
00261 
00262        unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC);
00263        
00264        void (*ini_defaults)(HashTable *configuration_hash);
00265        int phpinfo_as_text;
00266 
00267        char *ini_entries;
00268        const zend_function_entry *additional_functions;
00269        unsigned int (*input_filter_init)(TSRMLS_D);
00270 };
00271 
00272 
00273 struct _sapi_post_entry {
00274        char *content_type;
00275        uint content_type_len;
00276        void (*post_reader)(TSRMLS_D);
00277        void (*post_handler)(char *content_type_dup, void *arg TSRMLS_DC);
00278 };
00279 
00280 /* header_handler() constants */
00281 #define SAPI_HEADER_ADD                   (1<<0)
00282 
00283 
00284 #define SAPI_HEADER_SENT_SUCCESSFULLY     1
00285 #define SAPI_HEADER_DO_SEND                      2
00286 #define SAPI_HEADER_SEND_FAILED                  3
00287 
00288 #define SAPI_DEFAULT_MIMETYPE             "text/html"
00289 #define SAPI_DEFAULT_CHARSET              ""
00290 #define SAPI_PHP_VERSION_HEADER           "X-Powered-By: PHP/" PHP_VERSION
00291 
00292 #define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D)
00293 #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC)
00294 
00295 #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
00296 #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)
00297 
00298 BEGIN_EXTERN_C()
00299 SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
00300 SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
00301 SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
00302 SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter);
00303 END_EXTERN_C()
00304 
00305 #define STANDARD_SAPI_MODULE_PROPERTIES
00306 
00307 #endif /* SAPI_H */
00308 
00309 /*
00310  * Local variables:
00311  * tab-width: 4
00312  * c-basic-offset: 4
00313  * End:
00314  */