blob: 6d3c6eb19b6b0a105bb1b7cff8b009e8fe627c6b [file] [log] [blame]
Christopher Faulet63bbf282019-08-11 23:08:53 +02001/*
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
Christopher Faulet63bbf282019-08-11 23:08:53 +020025#include <stdio.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020026#include <haproxy/api.h>
Christopher Faulet63bbf282019-08-11 23:08:53 +020027#include <common/standard.h>
28#include <common/buf.h>
Willy Tarreaueb6f7012020-05-27 16:21:26 +020029#include <import/ist.h>
Christopher Faulet63bbf282019-08-11 23:08:53 +020030
31/* FCGI protocol version */
32#define FCGI_VERSION 0x1
33
34/* flags for FCGI_BEGIN_REQUEST records */
35#define FCGI_KEEP_CONN 0x01
36
37/* FCGI record's type */
38enum fcgi_record_type {
39 FCGI_BEGIN_REQUEST = 1,
40 FCGI_ABORT_REQUEST = 2,
41 FCGI_END_REQUEST = 3,
42 FCGI_PARAMS = 4,
43 FCGI_STDIN = 5,
44 FCGI_STDOUT = 6,
45 FCGI_STDERR = 7,
46 FCGI_DATA = 8,
47 FCGI_GET_VALUES = 9,
48 FCGI_GET_VALUES_RESULT = 10,
49 FCGI_UNKNOWN_TYPE = 11,
50 FCGI_ENTRIES
51} __attribute__((packed));
52
Christopher Fauletc5a3eb42019-10-04 15:20:47 +020053
Christopher Faulet63bbf282019-08-11 23:08:53 +020054enum fcgi_role {
55 FCGI_RESPONDER = 1,
56 FCGI_AUTHORIZER = 2, /* Unsupported */
57 FCGI_FILTER = 3, /* Unsupported */
58} __attribute__((packed));
59
60/* Protocol status */
61enum 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
69struct 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
78struct fcgi_param {
79 struct ist n;
80 struct ist v;
81};
82
83struct fcgi_begin_request {
84 enum fcgi_role role;
85 uint8_t flags;
86};
87
88struct fcgi_end_request {
89 uint32_t status;
90 uint8_t errcode;
91};
92
93struct fcgi_unknown_type {
94 uint8_t type;
95};
96
97
Christopher Fauletc5a3eb42019-10-04 15:20:47 +020098static inline const char *fcgi_rt_str(int type)
99{
100 switch (type) {
101 case FCGI_BEGIN_REQUEST : return "BEGIN_REQUEST";
102 case FCGI_ABORT_REQUEST : return "ABORT_REQUEST";
103 case FCGI_END_REQUEST : return "END_REQUEST";
104 case FCGI_PARAMS : return "PARAMS";
105 case FCGI_STDIN : return "STDIN";
106 case FCGI_STDOUT : return "STDOUT";
107 case FCGI_STDERR : return "STDERR";
108 case FCGI_DATA : return "DATA";
109 case FCGI_GET_VALUES : return "GET_VALUES";
110 case FCGI_GET_VALUES_RESULT : return "GET_VALUES_RESULT";
111 case FCGI_UNKNOWN_TYPE : return "UNKNOWN_TYPE";
112 default : return "_UNKNOWN_";
113 }
114}
115
Christopher Faulet63bbf282019-08-11 23:08:53 +0200116
117int fcgi_encode_record_hdr(struct buffer *out, const struct fcgi_header *h);
118size_t fcgi_decode_record_hdr(const struct buffer *in, size_t o, struct fcgi_header *h);
119
120int fcgi_encode_begin_request(struct buffer *out, const struct fcgi_begin_request *r);
121
122int fcgi_encode_param(struct buffer *out, const struct fcgi_param *p);
123size_t fcgi_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p);
124size_t fcgi_aligned_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p);
125
126size_t fcgi_decode_end_request(const struct buffer *in, size_t o, struct fcgi_end_request *r);
127
128#endif /* _COMMON_FCGI_H */
129
130/*
131 * Local variables:
132 * c-indent-level: 8
133 * c-basic-offset: 8
134 * End:
135 */