Christopher Faulet | 63bbf28 | 2019-08-11 23:08:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/common/fcgi.h |
| 3 | * This file contains FastCGI protocol definitions. |
| 4 | * |
| 5 | * Copyright (C) 2019 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _COMMON_FCGI_H |
| 23 | #define _COMMON_FCGI_H |
| 24 | |
| 25 | #include <inttypes.h> |
| 26 | #include <stdio.h> |
| 27 | #include <common/config.h> |
| 28 | #include <common/standard.h> |
| 29 | #include <common/buf.h> |
| 30 | #include <common/ist.h> |
| 31 | |
| 32 | /* FCGI protocol version */ |
| 33 | #define FCGI_VERSION 0x1 |
| 34 | |
| 35 | /* flags for FCGI_BEGIN_REQUEST records */ |
| 36 | #define FCGI_KEEP_CONN 0x01 |
| 37 | |
| 38 | /* FCGI record's type */ |
| 39 | enum fcgi_record_type { |
| 40 | FCGI_BEGIN_REQUEST = 1, |
| 41 | FCGI_ABORT_REQUEST = 2, |
| 42 | FCGI_END_REQUEST = 3, |
| 43 | FCGI_PARAMS = 4, |
| 44 | FCGI_STDIN = 5, |
| 45 | FCGI_STDOUT = 6, |
| 46 | FCGI_STDERR = 7, |
| 47 | FCGI_DATA = 8, |
| 48 | FCGI_GET_VALUES = 9, |
| 49 | FCGI_GET_VALUES_RESULT = 10, |
| 50 | FCGI_UNKNOWN_TYPE = 11, |
| 51 | FCGI_ENTRIES |
| 52 | } __attribute__((packed)); |
| 53 | |
| 54 | enum fcgi_role { |
| 55 | FCGI_RESPONDER = 1, |
| 56 | FCGI_AUTHORIZER = 2, /* Unsupported */ |
| 57 | FCGI_FILTER = 3, /* Unsupported */ |
| 58 | } __attribute__((packed)); |
| 59 | |
| 60 | /* Protocol status */ |
| 61 | enum fcgi_proto_status { |
| 62 | FCGI_PS_REQUEST_COMPLETE = 0, |
| 63 | FCGI_PS_CANT_MPX_CONN = 1, |
| 64 | FCGI_PS_OVERLOADED = 2, |
| 65 | FCGI_PS_UNKNOWN_ROLE = 3, |
| 66 | FCGI_PS_ENTRIES, |
| 67 | } __attribute__((packed)); |
| 68 | |
| 69 | struct fcgi_header { |
| 70 | uint8_t vsn; |
| 71 | uint8_t type; |
| 72 | uint16_t id; |
| 73 | uint16_t len; |
| 74 | uint8_t padding; |
| 75 | uint8_t rsv; |
| 76 | }; |
| 77 | |
| 78 | struct fcgi_param { |
| 79 | struct ist n; |
| 80 | struct ist v; |
| 81 | }; |
| 82 | |
| 83 | struct fcgi_begin_request { |
| 84 | enum fcgi_role role; |
| 85 | uint8_t flags; |
| 86 | }; |
| 87 | |
| 88 | struct fcgi_end_request { |
| 89 | uint32_t status; |
| 90 | uint8_t errcode; |
| 91 | }; |
| 92 | |
| 93 | struct fcgi_unknown_type { |
| 94 | uint8_t type; |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | |
| 99 | int fcgi_encode_record_hdr(struct buffer *out, const struct fcgi_header *h); |
| 100 | size_t fcgi_decode_record_hdr(const struct buffer *in, size_t o, struct fcgi_header *h); |
| 101 | |
| 102 | int fcgi_encode_begin_request(struct buffer *out, const struct fcgi_begin_request *r); |
| 103 | |
| 104 | int fcgi_encode_param(struct buffer *out, const struct fcgi_param *p); |
| 105 | size_t fcgi_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p); |
| 106 | size_t fcgi_aligned_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p); |
| 107 | |
| 108 | size_t fcgi_decode_end_request(const struct buffer *in, size_t o, struct fcgi_end_request *r); |
| 109 | |
| 110 | #endif /* _COMMON_FCGI_H */ |
| 111 | |
| 112 | /* |
| 113 | * Local variables: |
| 114 | * c-indent-level: 8 |
| 115 | * c-basic-offset: 8 |
| 116 | * End: |
| 117 | */ |