fastcgi.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Dmitry Stogov <dmitry@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. /* FastCGI protocol */
  17. #define FCGI_VERSION_1 1
  18. #define FCGI_MAX_LENGTH 0xffff
  19. #define FCGI_KEEP_CONN 1
  20. /* this is near the perfect hash function for most useful FastCGI variables
  21. * which combines efficiency and minimal hash collisions
  22. */
  23. #define FCGI_HASH_FUNC(var, var_len) \
  24. (UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \
  25. (((unsigned int)var[3]) << 2) + \
  26. (((unsigned int)var[var_len-2]) << 4) + \
  27. (((unsigned int)var[var_len-1]) << 2) + \
  28. var_len)
  29. #define FCGI_GETENV(request, name) \
  30. fcgi_quick_getenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1))
  31. #define FCGI_PUTENV(request, name, value) \
  32. fcgi_quick_putenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1), value)
  33. typedef enum _fcgi_role {
  34. FCGI_RESPONDER = 1,
  35. FCGI_AUTHORIZER = 2,
  36. FCGI_FILTER = 3
  37. } fcgi_role;
  38. enum {
  39. FCGI_DEBUG = 1,
  40. FCGI_NOTICE = 2,
  41. FCGI_WARNING = 3,
  42. FCGI_ERROR = 4,
  43. FCGI_ALERT = 5,
  44. };
  45. typedef enum _fcgi_request_type {
  46. FCGI_BEGIN_REQUEST = 1, /* [in] */
  47. FCGI_ABORT_REQUEST = 2, /* [in] (not supported) */
  48. FCGI_END_REQUEST = 3, /* [out] */
  49. FCGI_PARAMS = 4, /* [in] environment variables */
  50. FCGI_STDIN = 5, /* [in] post data */
  51. FCGI_STDOUT = 6, /* [out] response */
  52. FCGI_STDERR = 7, /* [out] errors */
  53. FCGI_DATA = 8, /* [in] filter data (not supported) */
  54. FCGI_GET_VALUES = 9, /* [in] */
  55. FCGI_GET_VALUES_RESULT = 10 /* [out] */
  56. } fcgi_request_type;
  57. typedef enum _fcgi_protocol_status {
  58. FCGI_REQUEST_COMPLETE = 0,
  59. FCGI_CANT_MPX_CONN = 1,
  60. FCGI_OVERLOADED = 2,
  61. FCGI_UNKNOWN_ROLE = 3
  62. } dcgi_protocol_status;
  63. /* FastCGI client API */
  64. typedef void (*fcgi_apply_func)(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
  65. #define FCGI_HASH_TABLE_SIZE 128
  66. #define FCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1)
  67. #define FCGI_HASH_SEG_SIZE 4096
  68. typedef struct _fcgi_request fcgi_request;
  69. int fcgi_init(void);
  70. void fcgi_shutdown(void);
  71. int fcgi_is_fastcgi(void);
  72. int fcgi_is_closed(fcgi_request *req);
  73. void fcgi_close(fcgi_request *req, int force, int destroy);
  74. int fcgi_in_shutdown(void);
  75. void fcgi_terminate(void);
  76. int fcgi_listen(const char *path, int backlog);
  77. fcgi_request* fcgi_init_request(int listen_socket, void(*on_accept)(void), void(*on_read)(void), void(*on_close)(void));
  78. void fcgi_destroy_request(fcgi_request *req);
  79. void fcgi_set_allowed_clients(char *ip);
  80. int fcgi_accept_request(fcgi_request *req);
  81. int fcgi_finish_request(fcgi_request *req, int force_close);
  82. const char *fcgi_get_last_client_ip(void);
  83. void fcgi_set_in_shutdown(int new_value);
  84. void fcgi_request_set_keep(fcgi_request *req, int new_value);
  85. #ifndef HAVE_ATTRIBUTE_WEAK
  86. typedef void (*fcgi_logger)(int type, const char *fmt, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
  87. void fcgi_set_logger(fcgi_logger lg);
  88. #endif
  89. int fcgi_has_env(fcgi_request *req);
  90. char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
  91. char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
  92. char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value);
  93. char* fcgi_quick_putenv(fcgi_request *req, char* var, int var_len, unsigned int hash_value, char* val);
  94. void fcgi_loadenv(fcgi_request *req, fcgi_apply_func load_func, zval *array);
  95. int fcgi_read(fcgi_request *req, char *str, int len);
  96. int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len);
  97. int fcgi_flush(fcgi_request *req, int end);
  98. int fcgi_end(fcgi_request *req);
  99. #ifdef PHP_WIN32
  100. void fcgi_impersonate(void);
  101. #endif
  102. void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len);
  103. void fcgi_free_mgmt_var_cb(zval *zv);