1 /* =================================================================
5 * C callbacks as well as directory listings.
7 * =================================================================
8 * ####ECOSGPLCOPYRIGHTBEGIN####
9 * -------------------------------------------
10 * This file is part of eCos, the Embedded Configurable Operating
12 * Copyright (C) 2005 eCosCentric Ltd.
14 * eCos is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 or (at your option)
19 * eCos is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with eCos; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 * As a special exception, if other files instantiate templates or
29 * use macros or inline functions from this file, or you compile this
30 * file and link it with other works to produce a work based on this
31 * file, this file does not by itself cause the resulting work to be
32 * covered by the GNU General Public License. However the source code
33 * for this file must still be made available in accordance with
34 * section (3) of the GNU General Public License.
36 * This exception does not invalidate any other reasons why a work
37 * based on this file might be covered by the GNU General Public
40 * -------------------------------------------
41 * ####ECOSGPLCOPYRIGHTEND####
42 * =================================================================
43 * #####DESCRIPTIONBEGIN####
45 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
51 * ####DESCRIPTIONEND####
53 * =================================================================
55 #include <pkgconf/hal.h>
56 #include <pkgconf/kernel.h>
57 #include <cyg/hal/hal_tables.h>
58 #include <cyg/fileio/fileio.h>
63 #include <stdio.h> // sprintf().
65 #include <cyg/athttpd/http.h>
66 #include <cyg/athttpd/socket.h>
67 #include <cyg/athttpd/handler.h>
68 #include <cyg/athttpd/forms.h>
70 #ifdef CYGOPT_NET_ATHTTPD_USE_DIRLIST
71 static char folder_gif[] = {
72 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x12, 0x00,
73 0x12, 0x00, 0xd5, 0x00, 0x00, 0xfb, 0xfb, 0xfb,
74 0xef, 0xef, 0xef, 0xdb, 0xb7, 0x52, 0xcc, 0x99,
75 0x34, 0xe4, 0xe4, 0xe4, 0xc1, 0xc1, 0xc1, 0xa3,
76 0x71, 0x0b, 0xc2, 0x8f, 0x2a, 0xb7, 0xb7, 0xb7,
77 0x9e, 0x6c, 0x06, 0xba, 0x87, 0x22, 0x9c, 0x6a,
78 0x04, 0xc9, 0x96, 0x31, 0xbd, 0x8a, 0x25, 0xb3,
79 0x81, 0x1b, 0x99, 0x67, 0x01, 0xdb, 0xb7, 0x71,
80 0xb5, 0x82, 0x1d, 0xa0, 0x6e, 0x08, 0xcb, 0x98,
81 0x33, 0xff, 0xff, 0xba, 0xb0, 0x7e, 0x18, 0xc5,
82 0x92, 0x2d, 0xa7, 0x75, 0x0f, 0xc7, 0x94, 0x2f,
83 0xa6, 0xa6, 0xa6, 0xa5, 0x73, 0x0d, 0xb7, 0x84,
84 0x1f, 0xab, 0x79, 0x13, 0xc8, 0x95, 0x30, 0xc0,
85 0x8d, 0x28, 0xc6, 0xc6, 0xc6, 0xae, 0x7c, 0x16,
86 0x9a, 0x68, 0x02, 0xa8, 0x76, 0x10, 0xac, 0x7a,
87 0x14, 0xff, 0xd4, 0x6f, 0xff, 0xf8, 0x93, 0xeb,
88 0xeb, 0xeb, 0xff, 0xff, 0x9c, 0xff, 0xdb, 0x75,
89 0xff, 0xe4, 0x7f, 0xff, 0xef, 0x89, 0xb6, 0xb6,
90 0xb6, 0xff, 0xff, 0xff, 0xff, 0xff, 0x99, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xf9, 0x04,
98 0x01, 0x00, 0x00, 0x2e, 0x00, 0x2c, 0x00, 0x00,
99 0x00, 0x00, 0x12, 0x00, 0x12, 0x00, 0x00, 0x06,
100 0x91, 0x40, 0x97, 0x70, 0x48, 0x2c, 0x1a, 0x8f,
101 0xc8, 0xa4, 0xd2, 0x35, 0x18, 0x4c, 0x18, 0x9d,
102 0x00, 0x40, 0x39, 0x60, 0x59, 0x29, 0x94, 0x03,
103 0x61, 0x7a, 0x1c, 0x40, 0x04, 0x60, 0x30, 0xa4,
104 0xa1, 0xd8, 0x44, 0x1c, 0x95, 0xc0, 0x70, 0x62,
105 0x6d, 0xbb, 0xdb, 0xa3, 0xcf, 0x90, 0xd1, 0x3a,
106 0xd9, 0xef, 0xf8, 0xd6, 0x05, 0x31, 0xc4, 0xb4,
107 0xfe, 0x80, 0x81, 0x7f, 0x06, 0x2b, 0x43, 0x16,
108 0x2d, 0x25, 0x89, 0x8a, 0x8b, 0x2d, 0x12, 0x85,
109 0x42, 0x07, 0x2d, 0x2a, 0x93, 0x94, 0x95, 0x2d,
110 0x09, 0x8f, 0x2e, 0x1e, 0x2d, 0x29, 0x9d, 0x9e,
111 0x9f, 0x2d, 0x0b, 0x99, 0x0d, 0x2d, 0x28, 0xa6,
112 0xa7, 0xa8, 0x2d, 0x21, 0x99, 0x0a, 0x2d, 0x24,
113 0xaf, 0xb0, 0xb1, 0x2d, 0x0f, 0x7c, 0x42, 0x01,
114 0x67, 0x15, 0x20, 0x1c, 0x22, 0x1a, 0x06, 0x12,
115 0x09, 0x0b, 0x0f, 0x19, 0x05, 0x43, 0x00, 0x04,
116 0x05, 0x2b, 0xc9, 0xca, 0xcb, 0x05, 0x04, 0x44,
117 0x00, 0x01, 0x26, 0xd2, 0xd3, 0xd4, 0x52, 0x4b,
118 0x4a, 0x41, 0x00, 0x3b
121 static char doc_gif[] = {
122 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x12, 0x00,
123 0x12, 0x00, 0xe6, 0x00, 0x00, 0xfb, 0xfb, 0xfb,
124 0xef, 0xef, 0xef, 0xf8, 0xfb, 0xff, 0xed, 0xf6,
125 0xff, 0xc1, 0xc1, 0xc1, 0xe4, 0xe4, 0xe4, 0xfd,
126 0xfd, 0xfd, 0xd8, 0xeb, 0xff, 0xc0, 0xdf, 0xff,
127 0xfe, 0xff, 0xff, 0xf3, 0xf9, 0xff, 0xc3, 0xe1,
128 0xff, 0xf4, 0xf4, 0xf5, 0xf9, 0xf9, 0xf9, 0x81,
129 0x95, 0xc3, 0x6b, 0x74, 0xa5, 0xce, 0xe7, 0xff,
130 0x5e, 0x61, 0x90, 0x55, 0xa7, 0xed, 0x93, 0xaa,
131 0xd2, 0x7a, 0x83, 0xb0, 0xc0, 0xc0, 0xff, 0xd9,
132 0xe1, 0xed, 0x84, 0x9b, 0xca, 0x8a, 0xa8, 0xd9,
133 0xe4, 0xf1, 0xff, 0x91, 0xb8, 0xea, 0x92, 0xbc,
134 0xef, 0x73, 0x7e, 0xb0, 0xf5, 0xfa, 0xff, 0xf7,
135 0xf7, 0xf7, 0x90, 0xa3, 0xcb, 0xcd, 0xe6, 0xff,
136 0xba, 0xdd, 0xff, 0xd8, 0xe5, 0xf6, 0x6d, 0x77,
137 0xa8, 0x65, 0x6a, 0x9a, 0x87, 0xa1, 0xd2, 0x7f,
138 0x8e, 0xbc, 0x8f, 0xb3, 0xe5, 0x8c, 0xae, 0xdf,
139 0xce, 0xd3, 0xff, 0xf6, 0xfa, 0xff, 0x67, 0x6d,
140 0x9e, 0xfc, 0xfd, 0xff, 0x7d, 0x89, 0xb6, 0x94,
141 0xbf, 0xf2, 0xc6, 0xc6, 0xc6, 0xfe, 0xfe, 0xfe,
142 0xdb, 0xe7, 0xf7, 0x69, 0x70, 0xa2, 0x6f, 0x7a,
143 0xac, 0x72, 0x7c, 0xae, 0x74, 0x80, 0xb2, 0x87,
144 0xa9, 0xdc, 0xd1, 0xe9, 0xff, 0xc9, 0xe4, 0xff,
145 0xb7, 0xb7, 0xb7, 0xeb, 0xeb, 0xeb, 0xb6, 0xb6,
146 0xb6, 0xe9, 0xf5, 0xff, 0x75, 0x78, 0xa3, 0xe1,
147 0xf0, 0xff, 0xdb, 0xed, 0xff, 0xff, 0xff, 0xff,
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xf9, 0x04,
172 0x01, 0x00, 0x00, 0x41, 0x00, 0x2c, 0x00, 0x00,
173 0x00, 0x00, 0x12, 0x00, 0x12, 0x00, 0x00, 0x07,
174 0xa3, 0x80, 0x41, 0x82, 0x83, 0x84, 0x85, 0x86,
175 0x87, 0x88, 0x2e, 0x36, 0x8b, 0x8c, 0x36, 0x35,
176 0x01, 0x00, 0x87, 0x1b, 0x40, 0x06, 0x00, 0x0d,
177 0x1e, 0x0c, 0x16, 0x35, 0x13, 0x90, 0x86, 0x1a,
178 0x30, 0x40, 0xa1, 0x09, 0x02, 0x31, 0x35, 0x12,
179 0x1f, 0x01, 0x86, 0x27, 0x06, 0xa2, 0x02, 0x1d,
180 0x22, 0x35, 0xb1, 0x2f, 0x86, 0x28, 0xa1, 0x02,
181 0x02, 0x03, 0x3c, 0x3c, 0x29, 0x15, 0x1c, 0x39,
182 0x86, 0x18, 0x2c, 0xb8, 0xb9, 0x3c, 0x3f, 0x3f,
183 0x07, 0x34, 0xbf, 0x85, 0x25, 0x2a, 0x0a, 0xb9,
184 0x3e, 0x3e, 0xc7, 0x37, 0x33, 0xca, 0x84, 0x17,
185 0xce, 0x3c, 0xd0, 0xc6, 0x37, 0x20, 0x23, 0xd5,
186 0x83, 0x0e, 0xba, 0xda, 0x3f, 0x37, 0x38, 0x38,
187 0x0f, 0xdf, 0x82, 0x26, 0xd9, 0xd1, 0xe4, 0xe6,
188 0x0b, 0x32, 0xe9, 0x41, 0x2d, 0x19, 0xed, 0x37,
189 0xe5, 0x0b, 0x08, 0x2b, 0xf2, 0x14, 0xf6, 0x10,
190 0xe6, 0x08, 0x42, 0x90, 0x90, 0xd7, 0xa3, 0xa0,
191 0xc1, 0x83, 0x11, 0x08, 0x18, 0x2a, 0x40, 0x60,
192 0x87, 0xc3, 0x87, 0x0e, 0x09, 0x14, 0x30, 0x04,
193 0x20, 0x80, 0x8e, 0x8b, 0x18, 0x2f, 0x76, 0x42,
194 0xc4, 0xd1, 0x50, 0x20, 0x00, 0x3b
197 static char back_gif[] = {
198 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0a, 0x00,
199 0x09, 0x00, 0xf7, 0x00, 0x00, 0xf8, 0xfa, 0xfb,
200 0x3a, 0x6b, 0x9d, 0xe5, 0xeb, 0xf2, 0x87, 0xa5,
201 0xc3, 0x9d, 0xb5, 0xce, 0xd0, 0xdc, 0xe7, 0xa9,
202 0xbe, 0xd4, 0x74, 0x97, 0xb9, 0x65, 0x8c, 0xb2,
203 0xd9, 0xe2, 0xec, 0xf1, 0xf4, 0xf8, 0xe7, 0xed,
204 0xf3, 0x55, 0x7f, 0xaa, 0xc8, 0xd6, 0xe3, 0xcc,
205 0xcc, 0xcc, 0x91, 0xac, 0xc8, 0x3f, 0x6f, 0x9f,
206 0xfd, 0xfd, 0xfe, 0x4d, 0x7a, 0xa6, 0xac, 0xc1,
207 0xd5, 0x4b, 0x78, 0xa5, 0x33, 0x66, 0x99, 0xff,
208 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00,
296 0x00, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x00, 0x08,
297 0x3b, 0x00, 0x2d, 0x08, 0x1c, 0x68, 0x61, 0xc1,
298 0x83, 0x02, 0x04, 0x2d, 0x00, 0x20, 0x10, 0x80,
299 0xc2, 0x04, 0x82, 0x13, 0x28, 0x54, 0xa8, 0xe0,
300 0x50, 0x60, 0x02, 0x04, 0x13, 0x27, 0x56, 0x04,
301 0x70, 0x20, 0xa3, 0xc6, 0x87, 0x02, 0x1b, 0x30,
302 0xc8, 0x58, 0x71, 0x60, 0x04, 0x03, 0x10, 0x28,
303 0x82, 0x24, 0xa8, 0x60, 0x80, 0x84, 0x95, 0x09,
304 0x05, 0x38, 0x08, 0x08, 0x00, 0x3b
308 // =============================================================================
309 // Internal resources
310 // =============================================================================
311 CYG_HAL_TABLE_BEGIN(cyg_httpd_ires_table, httpd_ires_table);
312 CYG_HAL_TABLE_END(cyg_httpd_ires_table_end, httpd_ires_table);
313 __externC cyg_httpd_ires_table_entry cyg_httpd_ires_table[];
314 __externC cyg_httpd_ires_table_entry cyg_httpd_ires_table_end[];
316 #ifdef CYGOPT_NET_ATHTTPD_USE_DIRLIST
317 // These threes internal resources are used for the directory listing.
318 CYG_HTTPD_IRES_TABLE_ENTRY(cyg_httpd_ires_folder, \
319 "/___folder__gif.gif", \
322 CYG_HTTPD_IRES_TABLE_ENTRY(cyg_httpd_ires_doc, \
323 "/___doc__gif.gif", \
326 CYG_HTTPD_IRES_TABLE_ENTRY(cyg_httpd_ires_back, \
327 "/___back__gif.gif", \
332 cyg_httpd_ires_table_entry *
333 cyg_httpd_find_ires(char *path_name)
335 cyg_httpd_ires_table_entry *entry = cyg_httpd_ires_table;
337 while (entry != cyg_httpd_ires_table_end)
339 if (!strcasecmp((char*)path_name, entry->f_pname))
344 return (cyg_httpd_ires_table_entry*)NULL;
348 cyg_httpd_send_ires(cyg_httpd_ires_table_entry *entry)
350 httpstate.status_code = CYG_HTTPD_STATUS_OK;
352 // Here we'll look for extension to the file. Consider the case where
353 // there might be more than one dot in the file name. We'll look for
354 // the last dot, then we'll check the extension.
355 char *extension = rindex(entry->f_pname, '.');
356 if (extension == NULL)
357 // No extension in the file name.
358 httpstate.mime_type = 0;
360 httpstate.mime_type = cyg_httpd_find_mime_string(++extension);
362 httpstate.payload_len = entry->f_size;
363 cyg_int32 header_length = cyg_httpd_format_header();
365 // As always, the header is always sent out.
366 send(httpstate.sockets[httpstate.client_index].descriptor,
370 if (httpstate.mode & CYG_HTTPD_MODE_SEND_HEADER_ONLY)
372 cyg_httpd_write(entry->f_ptr, entry->f_size);
375 // =============================================================================
377 // =============================================================================
378 CYG_HAL_TABLE_BEGIN(cyg_httpd_handler_table, httpd_handler_table);
379 CYG_HAL_TABLE_END(cyg_httpd_handler_table_end, httpd_handler_table);
381 __externC cyg_httpd_handler_table_entry cyg_httpd_handler_table[];
382 __externC cyg_httpd_handler_table_entry cyg_httpd_handler_table_end[];
385 cyg_httpd_find_handler(void)
387 cyg_httpd_handler_table_entry *entry = cyg_httpd_handler_table;
388 while (entry != cyg_httpd_handler_table_end)
390 if (strcmp((const char*)httpstate.url, entry->path) == 0)
395 return (handler)NULL;
398 // =============================================================================
400 // =============================================================================
401 #ifdef CYGOPT_NET_ATHTTPD_USE_DIRLIST
403 cyg_httpd_print_directory_entry(char *path_name,
407 char fname[CYG_HTTPD_MAXPATH];
409 time_t last_mod = s->st_mtime;
411 struct tm *mod_time = gmtime(&last_mod);
413 "%02d-%s-%04d %02d:%02d",
415 month_of_year[mod_time->tm_mon],
416 mod_time->tm_year + 1900,
420 if (S_ISREG(s->st_mode))
422 strcpy(fname, path_name);
423 if (fname[strlen(fname)-1] != '/')
425 strcat(fname, de->d_name);
426 cyg_httpd_cleanup_filename(fname);
427 sprintf(httpstate.outbuffer,
428 "<tr><td><img src='/___doc__gif.gif'></td>"
429 "<td><a href='%s'>%s</a></td>"
430 "<td>           </td>"
431 "<td>%s </td>"
432 "<td style='color:black'>%d</td></tr>",
441 strcat(fname, path_name);
442 if (fname[strlen(fname)-1] != '/')
444 strcat(fname, de->d_name);
445 cyg_httpd_cleanup_filename(fname);
446 sprintf(httpstate.outbuffer,
447 "<tr><td><img src='/___folder__gif.gif'></td>"
448 "<td><a href='%s/'>%s</a></td>"
449 "<td>           </td>"
450 "<td>%s </td>"
451 "<td style='color:black'></td></tr>",
456 cyg_httpd_write_chunked(httpstate.outbuffer, strlen(httpstate.outbuffer));
460 cyg_httpd_send_directory_listing(char *path_name)
462 struct dirent next_file;
463 struct dirent last_printed;
465 char fname[CYG_HTTPD_MAXPATH];
467 cyg_httpd_start_chunked("html");
468 sprintf(httpstate.outbuffer,
469 "<html><body><h3>Index of %s</h3><p></p>"
470 "<table style='font-family:courier'>",
472 cyg_httpd_write_chunked(httpstate.outbuffer, strlen(httpstate.outbuffer));
474 sprintf(httpstate.outbuffer,
475 "<tr><td></td><td align='center' style='border-style:none none"
476 " solid none;border-width:thin'>Name</td>"
477 "<td style='border-style:none none solid none; border-width:thin'>"
478 "           </td>"
479 "<td align='center' style='border-style:none none solid none;"
480 " border-width:thin'>Last Modified</td>"
481 "<td style='border-style:none none solid none; border-width:thin'>"
483 cyg_httpd_write_chunked(httpstate.outbuffer, strlen(httpstate.outbuffer));
485 // Provide a pointer to the parent directory.
486 strcpy(fname, path_name);
487 if (fname[strlen(fname)-1] == '/')
488 fname[strlen(fname)-1] = '\0';
489 char *slash = rindex(fname, '/');
491 sprintf(httpstate.outbuffer,
492 "<tr><td><img src='/___back__gif.gif'></td></td>"
493 "<td><a href='%s' style='color:red'>Parent "
495 "<td>           </td>"
496 "<td>           </td>"
497 "<td style='color:black'>-</td></tr>",
499 cyg_httpd_write_chunked(httpstate.outbuffer, strlen(httpstate.outbuffer));
501 strcpy(fname, CYGDAT_NET_ATHTTPD_SERVEROPT_ROOTDIR);
502 if (fname[strlen(fname)-1] != '/')
504 strcat(fname, path_name);
505 if (fname[strlen(fname)-1] != '/')
507 cyg_httpd_cleanup_filename(fname);
508 int abs_path_len = strlen(fname);
510 DIR* pdir = opendir(fname);
511 struct dirent *dirent = readdir(pdir);
513 // First time for the directories.
515 memset((void*)&last_printed, 0, sizeof(struct dirent));
516 dirent = readdir(pdir);
520 memset((void*)&next_file, 0, sizeof(struct dirent));
524 if (strcmp(dirent->d_name, "..") &&
525 strcmp(dirent->d_name, "."))
526 if ((next_file.d_name[0] == '\0') ||
527 (strcmp(next_file.d_name, dirent->d_name) > 0))
528 if ((last_printed.d_name[0] == '\0') ||
529 (strcmp(last_printed.d_name, dirent->d_name) < 0))
531 fname[abs_path_len] = '\0';
532 strcat(fname, dirent->d_name);
535 if (S_ISDIR(sp.st_mode))
537 memcpy(&next_file, dirent, sizeof(struct dirent));
538 memcpy(&s, &sp, sizeof(struct stat));
542 dirent = readdir(pdir);
546 cyg_httpd_print_directory_entry(path_name, &s, &next_file);
547 memcpy(&last_printed, &next_file, sizeof(struct dirent));
549 dirent = readdir(pdir);
552 // A second time for the files.
554 memset((void*)&last_printed, 0, sizeof(struct dirent));
555 dirent = readdir(pdir);
559 memset((void*)&next_file, 0, sizeof(struct dirent));
563 if (strcmp(dirent->d_name, "..") &&
564 strcmp(dirent->d_name, "."))
565 if ((next_file.d_name[0] == '\0') ||
566 (strcmp(next_file.d_name, dirent->d_name) > 0))
567 if ((last_printed.d_name[0] == '\0') ||
568 (strcmp(last_printed.d_name, dirent->d_name) < 0))
570 fname[abs_path_len] = '\0';
571 strcat(fname, dirent->d_name);
574 if (S_ISREG(sp.st_mode))
576 memcpy(&next_file, dirent, sizeof(struct dirent));
577 memcpy(&s, &sp, sizeof(struct stat));
581 dirent = readdir(pdir);
585 cyg_httpd_print_directory_entry(path_name, &s, &next_file);
586 memcpy(&last_printed, &next_file, sizeof(struct dirent));
588 dirent = readdir(pdir);
591 strcpy(httpstate.outbuffer, "</table><html><body>");
592 cyg_httpd_write_chunked(httpstate.outbuffer, strlen(httpstate.outbuffer));
593 cyg_httpd_end_chunked();