1 /*
2    ratproxy - HTTP request handling
3    --------------------------------
4 
5    Author: Michal Zalewski <lcamtuf@google.com>
6 
7    Copyright 2007, 2008 by Google Inc. All Rights Reserved.
8 
9    Licensed under the Apache License, Version 2.0 (the "License");
10    you may not use this file except in compliance with the License.
11    You may obtain a copy of the License at
12 
13      http://www.apache.org/licenses/LICENSE-2.0
14 
15    Unless required by applicable law or agreed to in writing, software
16    distributed under the License is distributed on an "AS IS" BASIS,
17    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18    See the License for the specific language governing permissions and
19    limitations under the License.
20 
21  */
22 
23 #ifndef _HAVE_HTTP_H
24 #define _HAVE_HTTP_H
25 
26 #include "types.h"
27 #include "nlist.h"
28 
29 struct http_request {
30   _u8*  method;			/* HTTP method          */
31   _u8*  host;			/* Target host          */
32   _u32  port;                   /* Target TCP port      */
33   _u8*  path;                   /* Target URL path      */
34   _u8*  ext;                    /* File extension       */
35   _u8*  query;                  /* Query string         */
36 
37   struct naive_list2 h;         /* Header set           */
38 
39   _u8   is_connect;		/* CONNECT method?      */
40   _u8   from_ssl;		/* SSL decapsulation?   */
41   _u8   xsrf_safe;		/* Has anti-XSRF token? */
42   _u8   authsub;		/* Uses authsub?        */
43   _u8*  referer;		/* 'Referer' header     */
44   _u8*  ref_host;		/* Referer host, if any */
45   _u8   multipart;		/* Multipart request?   */
46   _u8   non_param;              /* Non-param payload    */
47 
48   _u8*  use_boundary;           /* Multipart boundary   */
49 
50   _u32  ppar_bound;		/* Query/payload delim  */
51 
52   _u32  payload_len;            /* POST payload length  */
53   _u8*  payload;                /* POST payload data    */
54 
55   struct naive_list2 cookies;   /* Sent cookies         */
56 
57   struct naive_list_p p;	/* Decoded parameters   */
58 
59 };
60 
61 #define INTENT_NONE	0
62 #define INTENT_PRIV	1
63 #define INTENT_PUB 	2
64 
65 struct http_response {
66   _u32  code;			/* HTTP return code     */
67 
68   _u8*  ext;			/* File extension       */
69 
70   struct naive_list2 h;		/* Header set           */
71 
72   _u8*  mime_type;		/* Declared MIME type   */
73   _u8*  charset;                /* Declared charset     */
74   _u8*  sniffed_mime;           /* Detected MIME type   */
75   _u8*  location;		/* Location: update     */
76 
77   _u8   ex10intent;		/* Expires intent       */
78   _u8   pr10intent;             /* Pragma intent        */
79   _u8   cc11intent;             /* Cache-Control intent */
80 
81   _u8   has_multiple;		/* Has duplicate fields */
82   _u8   has_badclen;		/* Bad content length?  */
83   _u8   is_attach;		/* Attachment?          */
84   _u8   is_text;		/* Text document?       */
85   _u8   bad_cset;               /* Mistyped charset?    */
86 
87   struct naive_list2 cookies;   /* Set cookies          */
88 
89   _u32  payload_len;		/* Response body length */
90   _u8*  payload;                /* Response body data   */
91 
92   _u64  cksum;			/* Payload checksum     */
93 
94 };
95 
96 
97 struct http_request* collect_request(FILE* client,_u8* ssl_host,_u32 ssl_port);
98 
99 FILE* open_server_complete(FILE* client, struct http_request* r);
100 
101 struct http_response* send_request(FILE* client, FILE* server, struct http_request* r,
102                                    _u8 strip_state);
103 
104 void send_response(FILE* client, struct http_response* r);
105 
106 void checksum_response(struct http_response* r);
107 
108 void detect_charset(struct http_response* r);
109 
110 void parse_urlencoded(struct naive_list_p* p, _u8* string);
111 
112 void parse_multipart(struct naive_list_p* p, _u8* string, _u32 slen);
113 
114 _u8 contains_token(_u8* name, _u8* val);
115 
116 _u8* S(_u8* string, _u8 nl);
117 
118 _u8* stringify_payload(struct http_request* r);
119 
120 void reconstruct_request(struct http_request* r);
121 
122 #endif /* !_HAVE_HTTP_H */
123