• 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 owns 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 	lws_sorted_usec_list_t		sul_grace;
60 
61 	struct lws *wsi; /* owner */
62 	unsigned char *headers_buf;
63 	unsigned char *headers_start;
64 	unsigned char *headers_pos;
65 	unsigned char *headers_dumped;
66 	unsigned char *headers_end;
67 
68 	char summary[128];
69 #if defined(LWS_WITH_ZLIB)
70 	z_stream inflate;
71 	uint8_t inflate_buf[1024];
72 #endif
73 
74 	lws_filepos_t post_in_expected;
75 	lws_filepos_t content_length;
76 	lws_filepos_t content_length_seen;
77 
78 	int match[SIGNIFICANT_HDR_COUNT];
79 	char l[12];
80 	int response_code;
81 	int lp;
82 
83 	unsigned char being_closed:1;
84 	unsigned char explicitly_chunked:1;
85 	unsigned char cgi_transaction_over:1;
86 	unsigned char implied_chunked:1;
87 	unsigned char gzip_inflate:1;
88 	unsigned char gzip_init:1;
89 
90 	unsigned char chunked_grace;
91 };
92