]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/net/httpd/v2_0/include/httpd.h
Initial revision
[karo-tx-redboot.git] / packages / net / httpd / v2_0 / include / httpd.h
1 #ifndef CYGONCE_NET_HTTPD_HTTPD_H
2 #define CYGONCE_NET_HTTPD_HTTPD_H
3 /* =================================================================
4  *
5  *      httpd.h
6  *
7  *      A simple embedded HTTP server
8  *
9  * ================================================================= 
10  * ####ECOSGPLCOPYRIGHTBEGIN####
11  * -------------------------------------------
12  * This file is part of eCos, the Embedded Configurable Operating
13  * System.
14  * Copyright (C) 2002 Nick Garnett
15  * 
16  * eCos is free software; you can redistribute it and/or modify it
17  * under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 or (at your option)
19  * any later version.
20  * 
21  * eCos is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  * 
26  * You should have received a copy of the GNU General Public License
27  * along with eCos; if not, write to the Free Software Foundation,
28  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29  * 
30  * As a special exception, if other files instantiate templates or
31  * use macros or inline functions from this file, or you compile this
32  * file and link it with other works to produce a work based on this
33  * file, this file does not by itself cause the resulting work to be
34  * covered by the GNU General Public License. However the source code
35  * for this file must still be made available in accordance with
36  * section (3) of the GNU General Public License.
37  * 
38  * This exception does not invalidate any other reasons why a work
39  * based on this file might be covered by the GNU General Public
40  * License.
41  *
42  * -------------------------------------------
43  * ####ECOSGPLCOPYRIGHTEND####
44  * =================================================================
45  * #####DESCRIPTIONBEGIN####
46  * 
47  *  Author(s):    nickg@calivar.com
48  *  Contributors: nickg@calivar.com
49  *  Date:         2002-10-14
50  *  Purpose:      
51  *  Description:  
52  *               
53  * ####DESCRIPTIONEND####
54  * 
55  * =================================================================
56  */
57
58 #include <pkgconf/system.h>
59 #include <pkgconf/isoinfra.h>
60 #include <pkgconf/httpd.h>
61
62 #include <cyg/hal/hal_tables.h>
63
64 #include <stdio.h>
65
66 /* ================================================================= */
67 /* Start daemon explicitly
68  */
69
70 #ifndef CYGNUM_HTTPD_SERVER_AUTO_START
71
72 __externC void cyg_httpd_startup(void);
73
74 #endif
75
76 /* ================================================================= */
77 /* Lookup Table
78  *
79  * 
80  */
81
82 typedef cyg_bool cyg_httpd_handler(FILE *client, char *filename,
83                               char *formdata, void *arg);
84
85 struct cyg_httpd_table_entry
86 {
87     char                *pattern;
88     cyg_httpd_handler   *handler;
89     void                *arg;
90 } CYG_HAL_TABLE_TYPE;
91
92 typedef struct cyg_httpd_table_entry cyg_httpd_table_entry;
93
94 #define CYG_HTTPD_TABLE_ENTRY( __name, __pattern, __handler, __arg ) \
95 cyg_httpd_table_entry __name CYG_HAL_TABLE_ENTRY( httpd_table ) = { __pattern, __handler, __arg } 
96
97 /* ================================================================= */
98 /* Useful handler functions
99  */
100
101 /* ----------------------------------------------------------------- */
102 /*
103  */
104
105 __externC cyg_bool cyg_httpd_send_html( FILE *client, char *filename,
106                                         char *request, void *arg );
107
108 /* ----------------------------------------------------------------- */
109 /*
110  */
111
112 typedef struct
113 {
114     char        *content_type;
115     cyg_uint32  content_length;
116     cyg_uint8   *data;
117 } cyg_httpd_data;
118
119 __externC cyg_bool cyg_httpd_send_data( FILE *client, char *filename,
120                                         char *request, void *arg );
121
122 #define CYG_HTTPD_DATA( __name, __type, __length, __data ) \
123 cyg_httpd_data __name = { __type, __length, __data }
124
125 /* ================================================================= */
126 /* HTTP and HTML helper macros and functions
127  */
128
129 /* ----------------------------------------------------------------- */
130 /* HTTP header support
131  *
132  * cyg_http_start() sends an HTTP header with the given content type
133  * and length. cyg_http_finish() terminates an HTTP send.
134  * html_begin() starts an HTML document, and html_end() finishes it.
135  */
136
137 __externC void cyg_http_start( FILE *client, char *content_type,
138                                int content_length );
139 __externC void cyg_http_finish( FILE *client );
140
141 #define html_begin(__client)                            \
142         cyg_http_start( __client, "text/html", 0 );     \
143         html_tag_begin( __client, "html", "" )
144
145 #define html_end( __client )                    \
146         html_tag_end( __client, "html" );       \
147         cyg_http_finish( __client )
148
149 /* ----------------------------------------------------------------- */
150 /*
151  */
152
153
154 __externC void cyg_html_tag_begin( FILE *client, char *tag, char *attr );
155 __externC void cyg_html_tag_end( FILE *client, char *tag );
156
157 #define html_tag_begin( __client, __tag, __attr ) \
158         cyg_html_tag_begin( __client, __tag, __attr )
159
160 #define html_tag_end( __client, __tag ) cyg_html_tag_end( __client, __tag )
161
162
163 /* ----------------------------------------------------------------- */
164 /*
165  */
166
167
168 #define html_head( __client, __title, __meta )                          \
169 {                                                                       \
170     fprintf(__client, "<%s><%s>", "head", "title" );                    \
171     fputs( __title, __client );                                         \
172     fprintf(__client, "</%s>%s</%s>\n", "title", __meta, "head");       \
173 }
174
175 #define html_body_begin( __client, __attr )     \
176         cyg_html_tag_begin( __client, "body", __attr );
177
178 #define html_body_end( __client )               \
179         cyg_html_tag_end( __client, "body" );
180
181 #define html_heading( __client, __level, __heading ) \
182     fprintf(__client,"<h%d>%s</h%d>\n",__level,__heading,__level);
183
184 /* ----------------------------------------------------------------- */
185 /*
186  */
187
188
189 #define html_url( __client, __text, __link ) \
190         fprintf( __client, "<a href=\"%s\">%s</a>\n",__link,__text);
191
192 #define html_para_begin( __client, __attr )     \
193         cyg_html_tag_begin( __client, "p", __attr );
194
195 #define html_image( __client, __source, __alt, __attr )                 \
196         fprintf( __client, "<%s %s=\"%s\" %s=\"%s\" %s>\n", "img",      \
197                  "src",__source,                                        \
198                  "alt",__alt,                                           \
199                  (__attr)?(__attr):"" );
200
201 /* ----------------------------------------------------------------- */
202 /*
203  */
204
205
206 #define html_table_begin( __client, __attr )     \
207         cyg_html_tag_begin( __client, "table", __attr );
208
209 #define html_table_end( __client )               \
210         cyg_html_tag_end( __client, "table" );
211
212 #define html_table_header( __client, __content, __attr )        \
213 {                                                               \
214     cyg_html_tag_begin( __client, "th", __attr);                \
215     fputs( __content, __client );                               \
216     cyg_html_tag_end( __client, "th" );                         \
217 }
218
219 #define html_table_row_begin( __client, __attr )     \
220         cyg_html_tag_begin( __client, "tr", __attr );
221
222 #define html_table_row_end( __client )               \
223         cyg_html_tag_end( __client, "tr" );
224
225 #define html_table_data_begin( __client, __attr )     \
226         cyg_html_tag_begin( __client, "td", __attr );
227
228 #define html_table_data_end( __client )               \
229         cyg_html_tag_end( __client, "td" );
230
231 /* ----------------------------------------------------------------- */
232 /*
233  */
234
235
236 #define html_form_begin( __client, __url, __attr )      \
237         fprintf(__client, "<%s %s=\"%s\" %s>\n","form", \
238                 "action",__url,                         \
239                 (__attr)?(__attr):"" );
240
241 #define html_form_end( __client )               \
242         cyg_html_tag_end( __client, "form" );
243
244 #define html_form_input( __client, __type, __name, __value, __attr )            \
245 {                                                                               \
246     char *__lattr = (__attr);                                                   \
247     fprintf(__client, "<%s %s=\"%s\" %s=\"%s\" %s=\"%s\" %s>\n","input",        \
248             "type",__type,                                                      \
249             "name",__name,                                                      \
250             "value",__value,                                                    \
251             __lattr?__lattr:"" );                                               \
252 }
253
254 #define html_form_input_radio( __client, __name, __value, __checked ) \
255         html_form_input( __client, "radio", __name, __value, (__checked)?"checked":"" )
256
257 #define html_form_input_checkbox( __client, __name, __value, __checked ) \
258         html_form_input( __client, "checkbox", __name, __value, (__checked)?"checked":"" )
259
260 #define html_form_input_hidden( __client, __name, __value ) \
261         html_form_input( __client, "hidden", __name, __value, "" )
262
263 #define html_form_select_begin( __client, __name, __attr )      \
264         fprintf( __client, "<%s %s=\"%s\" %s>\n","select",      \
265                  "name",__name,                                 \
266                  (__attr)?(__attr):"" );
267
268 #define html_form_option( __client, __value, __label, __selected )      \
269         fprintf( __client, "<%s %s=\"%s\" %s>\n","option",              \
270                  "value", __value,                                      \
271                  (__selected)?"selected":"" );                          \
272         fputs(__label, __client );
273
274 #define html_form_select_end( __client ) \
275         cyg_html_tag_end( __client, "select" );
276
277
278 /* ================================================================= */
279 /*
280  */
281
282
283 __externC void cyg_formdata_parse( char *data, char *list[], int size );
284
285 __externC char *cyg_formlist_find( char *list[], char *name );
286
287 /* ----------------------------------------------------------------- */
288 #endif /* CYGONCE_NET_HTTPD_HTTPD_H                                  */
289 /* end of httpd.c                                                    */