fastcgi.h 5.1 KB

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