Imported Upstream version 3.2.0
[platform/upstream/libwebsockets.git] / lib / roles / cgi / private.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation:
9  *  version 2.1 of the License.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA  02110-1301  USA
20  *
21  *  This is included from core/private.h if LWS_ROLE_WS
22  */
23
24 #if defined(LWS_WITH_ZLIB)
25 #if defined(LWS_WITH_MINIZ)
26 #include <miniz.h>
27 #else
28 #include <zlib.h>
29 #endif
30 #endif
31
32 extern struct lws_role_ops role_ops_cgi;
33
34 #define lwsi_role_cgi(wsi) (wsi->role_ops == &role_ops_cgi)
35
36 #define LWS_HTTP_CHUNK_HDR_SIZE 16
37
38 enum {
39         SIGNIFICANT_HDR_CONTENT_LENGTH,         /* numeric */
40         SIGNIFICANT_HDR_LOCATION,
41         SIGNIFICANT_HDR_STATUS,                 /* numeric */
42         SIGNIFICANT_HDR_TRANSFER_ENCODING,
43         SIGNIFICANT_HDR_CONTENT_ENCODING_GZIP,
44
45         SIGNIFICANT_HDR_COUNT
46 };
47
48 struct lws;
49
50 /* wsi who is master of the cgi points to an lws_cgi */
51
52 struct lws_cgi {
53         struct lws_cgi *cgi_list;
54         struct lws *stdwsi[3]; /* points to the associated stdin/out/err wsis */
55         struct lws *wsi; /* owner */
56         unsigned char *headers_buf;
57         unsigned char *headers_start;
58         unsigned char *headers_pos;
59         unsigned char *headers_dumped;
60         unsigned char *headers_end;
61
62         char summary[128];
63 #if defined(LWS_WITH_ZLIB)
64         z_stream inflate;
65         uint8_t inflate_buf[1024];
66 #endif
67
68         lws_filepos_t post_in_expected;
69         lws_filepos_t content_length;
70         lws_filepos_t content_length_seen;
71
72         int pipe_fds[3][2];
73         int match[SIGNIFICANT_HDR_COUNT];
74         char l[12];
75         int pid;
76         int response_code;
77         int lp;
78
79         unsigned char being_closed:1;
80         unsigned char explicitly_chunked:1;
81         unsigned char cgi_transaction_over:1;
82         unsigned char implied_chunked:1;
83         unsigned char gzip_inflate:1;
84         unsigned char gzip_init:1;
85
86         unsigned char chunked_grace;
87 };