blob: 43174f0959396362ad7430b233bfe1d52efcaaf2 [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>
Willy Tarreau8dabda72020-05-27 17:22:10 +020027#include <haproxy/buf-t.h>
Willy Tarreaueb6f7012020-05-27 16:21:26 +020028#include <import/ist.h>
Christopher Faulet63bbf282019-08-11 23:08:53 +020029
30/* FCGI protocol version */
31#define FCGI_VERSION 0x1
32
33/* flags for FCGI_BEGIN_REQUEST records */
34#define FCGI_KEEP_CONN 0x01
35
36/* FCGI record's type */
37enum fcgi_record_type {
38 FCGI_BEGIN_REQUEST = 1,
39 FCGI_ABORT_REQUEST = 2,
40 FCGI_END_REQUEST = 3,
41 FCGI_PARAMS = 4,
42 FCGI_STDIN = 5,
43 FCGI_STDOUT = 6,
44 FCGI_STDERR = 7,
45 FCGI_DATA = 8,
46 FCGI_GET_VALUES = 9,
47 FCGI_GET_VALUES_RESULT = 10,
48 FCGI_UNKNOWN_TYPE = 11,
49 FCGI_ENTRIES
50} __attribute__((packed));
51
Christopher Fauletc5a3eb42019-10-04 15:20:47 +020052
Christopher Faulet63bbf282019-08-11 23:08:53 +020053enum fcgi_role {
54 FCGI_RESPONDER = 1,
55 FCGI_AUTHORIZER = 2, /* Unsupported */
56 FCGI_FILTER = 3, /* Unsupported */
57} __attribute__((packed));
58
59/* Protocol status */
60enum fcgi_proto_status {
61 FCGI_PS_REQUEST_COMPLETE = 0,
62 FCGI_PS_CANT_MPX_CONN = 1,
63 FCGI_PS_OVERLOADED = 2,
64 FCGI_PS_UNKNOWN_ROLE = 3,
65 FCGI_PS_ENTRIES,
66} __attribute__((packed));
67
68struct fcgi_header {
69 uint8_t vsn;
70 uint8_t type;
71 uint16_t id;
72 uint16_t len;
73 uint8_t padding;
74 uint8_t rsv;
75};
76
77struct fcgi_param {
78 struct ist n;
79 struct ist v;
80};
81
82struct fcgi_begin_request {
83 enum fcgi_role role;
84 uint8_t flags;
85};
86
87struct fcgi_end_request {
88 uint32_t status;
89 uint8_t errcode;
90};
91
92struct fcgi_unknown_type {
93 uint8_t type;
94};
95
96
Christopher Fauletc5a3eb42019-10-04 15:20:47 +020097static inline const char *fcgi_rt_str(int type)
98{
99 switch (type) {
100 case FCGI_BEGIN_REQUEST : return "BEGIN_REQUEST";
101 case FCGI_ABORT_REQUEST : return "ABORT_REQUEST";
102 case FCGI_END_REQUEST : return "END_REQUEST";
103 case FCGI_PARAMS : return "PARAMS";
104 case FCGI_STDIN : return "STDIN";
105 case FCGI_STDOUT : return "STDOUT";
106 case FCGI_STDERR : return "STDERR";
107 case FCGI_DATA : return "DATA";
108 case FCGI_GET_VALUES : return "GET_VALUES";
109 case FCGI_GET_VALUES_RESULT : return "GET_VALUES_RESULT";
110 case FCGI_UNKNOWN_TYPE : return "UNKNOWN_TYPE";
111 default : return "_UNKNOWN_";
112 }
113}
114
Christopher Faulet63bbf282019-08-11 23:08:53 +0200115
116int fcgi_encode_record_hdr(struct buffer *out, const struct fcgi_header *h);
117size_t fcgi_decode_record_hdr(const struct buffer *in, size_t o, struct fcgi_header *h);
118
119int fcgi_encode_begin_request(struct buffer *out, const struct fcgi_begin_request *r);
120
121int fcgi_encode_param(struct buffer *out, const struct fcgi_param *p);
122size_t fcgi_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p);
123size_t fcgi_aligned_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p);
124
125size_t fcgi_decode_end_request(const struct buffer *in, size_t o, struct fcgi_end_request *r);
126
127#endif /* _COMMON_FCGI_H */
128
129/*
130 * Local variables:
131 * c-indent-level: 8
132 * c-basic-offset: 8
133 * End:
134 */