Sat, 11 May 2013 13:28:26 +0200
supports file system ACLs on Solaris
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "protocol.h" |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
31 | #include "../util/pblock.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
32 | #include "../util/pool.h" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "session.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
34 | #include "../util/io.h" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
36 | #include "../util/strbuf.h" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | void protocol_status(Session *sn, Request *rq, int n, const char *m) { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | rq->status_num = n; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | const char *msg = m ? m : protocol_status_message(n); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | pb_param *pp = pblock_removekey(pb_key_status, rq->srvhdrs); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | if (pp != NULL) { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | param_free(pp); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | pp = pblock_key_param_create(rq->srvhdrs, pb_key_status, msg, strlen(msg)); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | pblock_kpinsert(pb_key_status, pp, rq->srvhdrs); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | /* |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | * http_status_message from Open Webserver (frame/http.cpp) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | * TODO: replace, use sstr_t |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | NSAPI_PUBLIC const char * protocol_status_message (int code) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | const char *r; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | switch (code) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | case PROTOCOL_CONTINUE : // 100 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | r = "Continue"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | case PROTOCOL_SWITCHING: //101 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | r = "Switching Protocols"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | case PROTOCOL_OK: // 200 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | r = "OK"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | case PROTOCOL_CREATED: // 201 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | r = "Created"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | case PROTOCOL_ACCEPTED: // 202 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | r = "Accepted"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | case PROTOCOL_NONAUTHORITATIVE: // 203 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | r = "Non-Authoritative Information"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | case PROTOCOL_NO_CONTENT: //204 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | /* There is another define to PROTOCOL_NO_RESPONSE for 204 in nsapi.h |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | The spec maps this to No Content. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | Hence cahnging this to No Content |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | r = "No Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | case PROTOCOL_RESET_CONTENT: // 205 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | r = "Reset Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | case PROTOCOL_PARTIAL_CONTENT: // 206 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | r = "Partial Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | case PROTOCOL_MULTI_STATUS: // 207 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | r = "Multi Status"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | case PROTOCOL_MULTIPLE_CHOICES: // 300 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | r = "Multiple Choices"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | case PROTOCOL_MOVED_PERMANENTLY: // 301 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | r = "Moved Permanently"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | case PROTOCOL_REDIRECT: // 302 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | r = "Moved Temporarily"; /* The spec actually says "Found" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | case PROTOCOL_SEE_OTHER: // 303 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | r = "See Other"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | case PROTOCOL_NOT_MODIFIED: // 304 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | r = "Use local copy"; /* The spec actually says "Not Modified" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | case PROTOCOL_USE_PROXY: // 305 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | r = "Use Proxy"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | case PROTOCOL_TEMPORARY_REDIRECT: // 307 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | r = "Temporary Redirect"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | case PROTOCOL_BAD_REQUEST: // 400 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | r = "Bad request"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | case PROTOCOL_UNAUTHORIZED: // 401 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | r = "Unauthorized"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | case PROTOCOL_PAYMENT_REQUIRED: // 402 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | r = "Payment Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | case PROTOCOL_FORBIDDEN: // 403 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | r = "Forbidden"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | case PROTOCOL_NOT_FOUND: // 404 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | r = "Not found"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | case PROTOCOL_METHOD_NOT_ALLOWED: // 405 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | r = "Method Not Allowed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | case PROTOCOL_NOT_ACCEPTABLE: // 406 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | r = "Not Acceptable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | case PROTOCOL_PROXY_UNAUTHORIZED: // 407 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | r = "Proxy Authentication Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | case PROTOCOL_REQUEST_TIMEOUT: // 408 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | r = "Request Timeout"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | case PROTOCOL_CONFLICT: // 409 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | r = "Conflict"; /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | case PROTOCOL_GONE: // 410 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | r = "Gone"; /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | case PROTOCOL_LENGTH_REQUIRED: // 411 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | r = "Length Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | case PROTOCOL_PRECONDITION_FAIL: // 412 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | r = "Precondition Failed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | case PROTOCOL_ENTITY_TOO_LARGE: // 413 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | r = "Request Entity Too Large"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | case PROTOCOL_URI_TOO_LARGE: // 414 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | r = "Request-URI Too Large"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | case PROTOCOL_UNSUPPORTED_MEDIA_TYPE: // 415 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | r = "Unsupported Media Type"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | case PROTOCOL_REQUESTED_RANGE_NOT_SATISFIABLE: // 416 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | r = "Requested range not satisfiable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | case PROTOCOL_EXPECTATION_FAILED: // 417 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | r = "Expectation Failed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | case PROTOCOL_LOCKED: // 423 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | r = "Locked"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | case PROTOCOL_FAILED_DEPENDENCY: // 424 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | r = "Failed Dependency"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | case PROTOCOL_SERVER_ERROR: // 500 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | r = "Server Error"; /* The spec actually says "Internal Server Error" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | case PROTOCOL_NOT_IMPLEMENTED: // 501 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | r = "Not Implemented"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | case PROTOCOL_BAD_GATEWAY: // 502 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | r = "Bad Gateway"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | case PROTOCOL_SERVICE_UNAVAILABLE: // 503 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | r = "Service Unavailable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | case PROTOCOL_GATEWAY_TIMEOUT: // 504 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | r = "Gateway Timeout"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | case PROTOCOL_VERSION_NOT_SUPPORTED: // 505 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | r = "HTTP Version Not Supported"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | case PROTOCOL_INSUFFICIENT_STORAGE: // 507 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | r = "Insufficient Storage"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | default: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | switch (code / 100) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | case 1: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | r = "Information"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | case 2: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | r = "Success"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | case 3: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | r = "Redirect"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | case 4: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | r = "Client error"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | case 5: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | r = "Server error"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | default: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | r = "Unknown reason"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | return r; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
229 | void add_http_status_line(sbuf_t *out, pool_handle_t *pool, Request *rq) { |
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
230 | sbuf_write(out, "HTTP/1.1 ", 9); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
232 | char *status_code_str = pool_malloc(pool, 8); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | int sc_len = snprintf(status_code_str, 8, "%d ", rq->status_num); |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
234 | sbuf_write(out, status_code_str, sc_len); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | char *scmsg = pblock_findkeyval(pb_key_status, rq->srvhdrs); |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
237 | if(scmsg == NULL) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
238 | scmsg = "OK"; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
239 | } |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
240 | sbuf_write(out, scmsg, strlen(scmsg)); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
242 | sbuf_write(out, "\r\n", 2); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
245 | void add_http_response_header(sbuf_t *out, Request *rq) { |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
246 | pblock *h = rq->srvhdrs; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
247 | pb_entry *p; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
248 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
249 | for(int i=0;i<h->hsize;i++) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
250 | p = h->ht[i]; |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
251 | while(p != NULL) { |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
252 | /* from http.cpp */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
253 | const pb_key *key = PARAM_KEY(p->param); |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
254 | if (key == pb_key_status || key == pb_key_server || key == pb_key_date) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
255 | /* Skip internal Status:, Server:, and Date: information */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
256 | p = p->next; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
257 | continue; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
258 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
259 | /* end http.cpp */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
260 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
261 | char *name = p->param->name; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
262 | char *value = p->param->value; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
263 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
264 | /* make first char of name uppercase */ |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
265 | // TODO: don't modify the headers |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
266 | if(name[0] > 90) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
267 | name[0] -= 32; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
268 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
269 | |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
270 | sbuf_write(out, name, strlen(name)); |
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
271 | sbuf_write(out, ": ", 2); |
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
272 | sbuf_write(out, value, strlen(value)); |
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
273 | sbuf_write(out, "\r\n", 2); |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
274 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
275 | p = p->next; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
276 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
277 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
278 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
279 | |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | int http_start_response(Session *sn, Request *rq) { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | int fd = ((SystemIOStream*)sn->csd)->fd; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
283 | if(rq->status_num == -1) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
284 | protocol_status(sn, rq, 200, "OK"); |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
285 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
286 | |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | /* set socket blocking */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | int flags; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | flags = fcntl(fd, F_GETFL, 0); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | fcntl(fd, F_SETFL, flags ^ O_NONBLOCK); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
292 | /* output buffer */ |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
293 | sbuf_t *out = sbuf_new(512); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | /* add the http status line to the output buffer */ |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
296 | add_http_status_line(out, sn->pool, rq); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | /* add server header */ |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
299 | sbuf_write(out, "Server: webserver\r\n", 19); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
301 | /* add header from rq->srvhdrs */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
302 | add_http_response_header(out, rq); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
303 | |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
304 | /* add connection header */ |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
305 | sbuf_write(out, "Connection: close\r\n", 19); |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
306 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
307 | /* response header end */ |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
308 | sbuf_write(out, "\r\n", 2); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | /* flush buffer to the socket */ |
11
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
311 | write(fd, out->ptr, out->length); |
24d804a2799f
Fixed response header bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
312 | sbuf_free(out); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | rq->senthdrs = 1; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
315 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
316 | return 0; |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
319 | int request_header(char *name, char **value, Session *sn, Request *rq) { |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
320 | const pb_key *key = pblock_key(name); |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
321 | pb_param *pp = pblock_findkey(key, rq->headers); |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
322 | if(pp != NULL) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
323 | *value = pp->value; |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
324 | return REQ_PROCEED; |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
325 | } else { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
326 | //return REQ_ABORTED; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
327 | *value = NULL; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
328 | return REQ_NOACTION; |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
329 | } |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
330 | } |