Coverage Report

Created: 2025-12-14 06:30

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