comparison packages/net/athttpd/current/include/http.h @ 2250:0830ae6acddc

Add ATHTTPD server from Anthony Tonizzo.
author jlarmour
date Tue, 18 Jul 2006 16:37:23 +0000
parents
children bd648d8929f6
comparison
equal deleted inserted replaced
2249:6778c16dcfcd 2250:0830ae6acddc
1 /* =================================================================
2 *
3 * http.h
4 *
5 * Improved HTTPD server.
6 *
7 * =================================================================
8 * ####ECOSGPLCOPYRIGHTBEGIN####
9 * -------------------------------------------
10 * This file is part of eCos, the Embedded Configurable Operating
11 * System.
12 * Copyright (C) 2005 eCosCentric Ltd.
13 *
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)
17 * any later version.
18 *
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.
23 *
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.
27 *
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.
35 *
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
38 * License.
39 *
40 * -------------------------------------------
41 * ####ECOSGPLCOPYRIGHTEND####
42 * =================================================================
43 * #####DESCRIPTIONBEGIN####
44 *
45 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
46 * Contributors:
47 * Date: 2006-06-12
48 * Purpose:
49 * Description:
50 *
51 * ####DESCRIPTIONEND####
52 *
53 * =================================================================
54 */
55 #ifndef __HTTP_H__
56 #define __HTTP_H__
57
58 #include <pkgconf/system.h>
59 #include <pkgconf/isoinfra.h>
60 #include <cyg/hal/hal_tables.h>
61
62 #include <pkgconf/athttpd.h>
63 #include <cyg/athttpd/auth.h>
64
65 #ifdef CYGOPT_NET_ATHTTPD_USE_CGIBIN_TCL
66 #include <cyg/athttpd/jim.h>
67 #endif
68
69
70 typedef enum cyg_httpd_req_type
71 {
72 CYG_HTTPD_METHOD_GET = 1,
73 CYG_HTTPD_METHOD_HEAD = 2,
74 CYG_HTTPD_METHOD_POST = 3
75 } cyg_httpd_req_type;
76
77 #define CYG_HTTPD_MAXURL 128
78 #define CYG_HTTPD_MAXPATH 128
79
80 #define CYG_HTTPD_MAXINBUFFER CYGNUM_ATHTTPD_SERVER_BUFFER_SIZE
81 #define CYG_HTTPD_MAXOUTBUFFER CYGNUM_ATHTTPD_SERVER_BUFFER_SIZE
82
83 #define CYG_HTTPD_DEFAULT_CGIBIN_OBJLOADER_EXTENSION ".o"
84 #define CYG_HTTPD_DEFAULT_CGIBIN_TCL_EXTENSION ".tcl"
85
86 #define CYG_HTTPD_TIME_STRING_LEN 32
87
88 #define CYG_HTTPD_STATUS_OK 200
89 #define CYG_HTTPD_STATUS_MOVED_PERMANENTLY 301
90 #define CYG_HTTPD_STATUS_NOT_MODIFIED 304
91 #define CYG_HTTPD_STATUS_BAD_REQUEST 400
92 #define CYG_HTTPD_STATUS_NOT_AUTHORIZED 401
93 #define CYG_HTTPD_STATUS_FORBIDDEN 403
94 #define CYG_HTTPD_STATUS_NOT_FOUND 404
95 #define CYG_HTTPD_STATUS_METHOD_NOT_ALLOWED 405
96 #define CYG_HTTPD_STATUS_SYSTEM_ERROR 500
97 #define CYG_HTTPD_STATUS_NOT_IMPLEMENTED 501
98
99 #define CYG_HTTPD_MODE_CLOSE_CONN 0x0001
100 #define CYG_HTTPD_MODE_TRANSFER_CHUNKED 0x0002
101 #define CYG_HTTPD_SEND_HEADER_ONLY 0x0004
102
103 // This must be generated at random...
104 #define CYG_HTTPD_MD5_AUTH_NAME "MD5"
105 #define CYG_HTTPD_MD5_AUTH_QOP "auth"
106 #define CYG_HTTPD_MD5_AUTH_OPAQUE "0000000000000000"
107
108 typedef struct __socket_entry
109 {
110 cyg_int32 descriptor;
111 time_t timestamp;
112 } socket_entry;
113
114 // =============================================================================
115 // Main HTTP structure.
116 // =============================================================================
117 typedef struct
118 {
119 cyg_httpd_req_type method;
120 fd_set rfds;
121
122 cyg_int32 host[4];
123
124 char url[CYG_HTTPD_MAXURL+1];
125 char inbuffer[CYG_HTTPD_MAXINBUFFER+1];
126 cyg_int32 inbuffer_len;
127
128
129 // Packet status.
130 //
131 // bit Description
132 // -------------------------------------------------------------------------
133 // 0 When set inserts 'Pragma: no-cache' and
134 // 'Cache-control: no-cache' in the header. Default for callback
135 // functions.
136 // 1 When to close the connection:
137 // 'Connection: close' when 0, 'Connection: keep-alive' when 1.
138 cyg_uint16 mode;
139
140 // Ouptut data.
141 cyg_uint16 status_code;
142 char *mime_type;
143 cyg_int32 payload_len;
144 char outbuffer[CYG_HTTPD_MAXOUTBUFFER+1];
145
146 socket_entry sockets[CYGNUM_FILEIO_NFILE];
147 cyg_int32 fdmax;
148
149 // Socket handle.
150 cyg_int32 client_index;
151
152 time_t modified_since;
153 time_t last_modified;
154
155 #ifdef CYGOPT_NET_ATHTTPD_USE_CGIBIN_TCL
156 Jim_Interp *jim_interp;
157 #endif
158
159 // This pointer points to the information about the domain that needs
160 // to be authenticated. It is only used by the function that builds the
161 // header.
162 cyg_httpd_auth_table_entry *needs_auth;
163
164 struct sockaddr_in server_conn;
165 struct sockaddr_in client_conn;
166 } CYG_HTTPD_STATE;
167
168 extern CYG_HTTPD_STATE httpstate;
169
170 extern const char *day_of_week[];
171 extern const char *month_of_year[];
172
173 struct cyg_httpd_mime_table_entry
174 {
175 char *extension;
176 char *mime_string;
177 } CYG_HAL_TABLE_TYPE;
178
179 typedef struct cyg_httpd_mime_table_entry cyg_httpd_mime_table_entry;
180
181 #define CYG_HTTPD_MIME_TABLE_ENTRY(__name, __pattern, __arg) \
182 cyg_httpd_mime_table_entry __name CYG_HAL_TABLE_ENTRY(httpd_mime_table) = \
183 { __pattern, __arg }
184
185 extern cyg_int32 debug_print;
186
187 void cyg_httpd_format_time_string(char*, time_t*);
188 void cyg_httpd_set_home_page(cyg_int8*);
189 char* cyg_httpd_find_mime_string(char*);
190 cyg_int32 cyg_httpd_initialize(void);
191 void cyg_httpd_cleanup_filename(char*);
192 char* cyg_httpd_parse_GET(char*);
193 char* cyg_httpd_parse_POST(char*);
194 char* cyg_httpd_parse_HEAD(char*);
195 void cyg_httpd_handle_method_GET(void);
196 void cyg_httpd_handle_method_HEAD(void);
197 cyg_int32 cyg_httpd_process_method(void);
198 void cyg_httpd_send_file(char*);
199 void cyg_httpd_send_error(cyg_int32);
200 cyg_int32 cyg_httpd_format_header(void);
201
202 #endif