root/main/fastcgi.h

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

INCLUDED FROM


   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    | Authors: Dmitry Stogov <dmitry@zend.com>                             |
  16    +----------------------------------------------------------------------+
  17 */
  18 
  19 /* $Id$ */
  20 
  21 /* FastCGI protocol */
  22 
  23 #define FCGI_VERSION_1 1
  24 
  25 #define FCGI_MAX_LENGTH 0xffff
  26 
  27 #define FCGI_KEEP_CONN  1
  28 
  29 /* this is near the perfect hash function for most useful FastCGI variables
  30  * which combines efficiency and minimal hash collisions
  31  */
  32 
  33 #define FCGI_HASH_FUNC(var, var_len) \
  34         (UNEXPECTED(var_len < 3) ? var_len : \
  35                 (((unsigned int)var[3]) << 2) + \
  36                 (((unsigned int)var[var_len-2]) << 4) + \
  37                 (((unsigned int)var[var_len-1]) << 2) + \
  38                 var_len)
  39 
  40 #define FCGI_GETENV(request, name) \
  41         fcgi_quick_getenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1))
  42 
  43 #define FCGI_PUTENV(request, name, value) \
  44         fcgi_quick_putenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1), value)
  45 
  46 typedef enum _fcgi_role {
  47         FCGI_RESPONDER  = 1,
  48         FCGI_AUTHORIZER = 2,
  49         FCGI_FILTER             = 3
  50 } fcgi_role;
  51 
  52 enum {
  53         FCGI_DEBUG              = 1,
  54         FCGI_NOTICE             = 2,
  55         FCGI_WARNING    = 3,
  56         FCGI_ERROR              = 4,
  57         FCGI_ALERT              = 5,
  58 };
  59 
  60 typedef enum _fcgi_request_type {
  61         FCGI_BEGIN_REQUEST              =  1, /* [in]                              */
  62         FCGI_ABORT_REQUEST              =  2, /* [in]  (not supported)             */
  63         FCGI_END_REQUEST                =  3, /* [out]                             */
  64         FCGI_PARAMS                             =  4, /* [in]  environment variables       */
  65         FCGI_STDIN                              =  5, /* [in]  post data                   */
  66         FCGI_STDOUT                             =  6, /* [out] response                    */
  67         FCGI_STDERR                             =  7, /* [out] errors                      */
  68         FCGI_DATA                               =  8, /* [in]  filter data (not supported) */
  69         FCGI_GET_VALUES                 =  9, /* [in]                              */
  70         FCGI_GET_VALUES_RESULT  = 10  /* [out]                             */
  71 } fcgi_request_type;
  72 
  73 typedef enum _fcgi_protocol_status {
  74         FCGI_REQUEST_COMPLETE   = 0,
  75         FCGI_CANT_MPX_CONN              = 1,
  76         FCGI_OVERLOADED                 = 2,
  77         FCGI_UNKNOWN_ROLE               = 3
  78 } dcgi_protocol_status;
  79 
  80 /* FastCGI client API */
  81 
  82 typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
  83 
  84 #define FCGI_HASH_TABLE_SIZE 128
  85 #define FCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1)
  86 #define FCGI_HASH_SEG_SIZE   4096
  87 
  88 typedef struct _fcgi_request fcgi_request;
  89 
  90 int fcgi_init(void);
  91 void fcgi_shutdown(void);
  92 int fcgi_is_fastcgi(void);
  93 int fcgi_is_closed(fcgi_request *req);
  94 void fcgi_close(fcgi_request *req, int force, int destroy);
  95 int fcgi_in_shutdown(void);
  96 void fcgi_terminate(void);
  97 int fcgi_listen(const char *path, int backlog);
  98 fcgi_request* fcgi_init_request(int listen_socket, void(*on_accept)(), void(*on_read)(), void(*on_close)());
  99 void fcgi_destroy_request(fcgi_request *req);
 100 void fcgi_set_allowed_clients(char *ip);
 101 int fcgi_accept_request(fcgi_request *req);
 102 int fcgi_finish_request(fcgi_request *req, int force_close);
 103 const char *fcgi_get_last_client_ip();
 104 void fcgi_set_in_shutdown(int new_value);
 105 
 106 #ifndef HAVE_ATTRIBUTE_WEAK
 107 typedef void (*fcgi_logger)(int type, const char *fmt, ...);
 108 void fcgi_set_logger(fcgi_logger lg);
 109 #endif
 110 
 111 int   fcgi_has_env(fcgi_request *req);
 112 char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
 113 char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
 114 char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value);
 115 char* fcgi_quick_putenv(fcgi_request *req, char* var, int var_len, unsigned int hash_value, char* val);
 116 void  fcgi_loadenv(fcgi_request *req, fcgi_apply_func load_func, zval *array);
 117 
 118 int fcgi_read(fcgi_request *req, char *str, int len);
 119 
 120 int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len);
 121 int fcgi_flush(fcgi_request *req, int close);
 122 
 123 #ifdef PHP_WIN32
 124 void fcgi_impersonate(void);
 125 #endif
 126 
 127 void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len);
 128 void fcgi_free_mgmt_var_cb(zval *zv);
 129 
 130 /*
 131  * Local variables:
 132  * tab-width: 4
 133  * c-basic-offset: 4
 134  * End:
 135  * vim600: sw=4 ts=4 fdm=marker
 136  * vim<600: sw=4 ts=4
 137  */

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