fastcgi.h 5.0 KB

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