• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  * This is included from private-lib-core.h if LWS_ROLE_WS
25  */
26 
27 #if defined(LWS_WITH_ZLIB)
28 #if defined(LWS_WITH_MINIZ)
29 #include <miniz.h>
30 #else
31 #include <zlib.h>
32 #endif
33 #endif
34 
35 extern const struct lws_role_ops role_ops_cgi;
36 
37 #define lwsi_role_cgi(wsi) (wsi->role_ops == &role_ops_cgi)
38 
39 #define LWS_HTTP_CHUNK_HDR_SIZE 16
40 
41 enum {
42 	SIGNIFICANT_HDR_CONTENT_LENGTH,		/* numeric */
43 	SIGNIFICANT_HDR_LOCATION,
44 	SIGNIFICANT_HDR_STATUS,			/* numeric */
45 	SIGNIFICANT_HDR_TRANSFER_ENCODING,
46 	SIGNIFICANT_HDR_CONTENT_ENCODING_GZIP,
47 
48 	SIGNIFICANT_HDR_COUNT
49 };
50 
51 struct lws;
52 
53 /* wsi who is master of the cgi points to an lws_cgi */
54 
55 struct lws_cgi {
56 	struct lws_cgi *cgi_list;
57 
58 	struct lws_spawn_piped *lsp;
59 
60 	struct lws *wsi; /* owner */
61 	unsigned char *headers_buf;
62 	unsigned char *headers_start;
63 	unsigned char *headers_pos;
64 	unsigned char *headers_dumped;
65 	unsigned char *headers_end;
66 
67 	char summary[128];
68 #if defined(LWS_WITH_ZLIB)
69 	z_stream inflate;
70 	uint8_t inflate_buf[1024];
71 #endif
72 
73 	lws_filepos_t post_in_expected;
74 	lws_filepos_t content_length;
75 	lws_filepos_t content_length_seen;
76 
77 	int match[SIGNIFICANT_HDR_COUNT];
78 	char l[12];
79 	int response_code;
80 	int lp;
81 
82 	unsigned char being_closed:1;
83 	unsigned char explicitly_chunked:1;
84 	unsigned char cgi_transaction_over:1;
85 	unsigned char implied_chunked:1;
86 	unsigned char gzip_inflate:1;
87 	unsigned char gzip_init:1;
88 
89 	unsigned char chunked_grace;
90 };
91