1 #ifndef CYGONCE_NET_HTTPD_HTTPD_H
2 #define CYGONCE_NET_HTTPD_HTTPD_H
3 /* =================================================================
7 * A simple embedded HTTP server
9 * =================================================================
10 * ####ECOSGPLCOPYRIGHTBEGIN####
11 * -------------------------------------------
12 * This file is part of eCos, the Embedded Configurable Operating
14 * Copyright (C) 2002 Nick Garnett
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)
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.
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.
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.
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
42 * -------------------------------------------
43 * ####ECOSGPLCOPYRIGHTEND####
44 * =================================================================
45 * #####DESCRIPTIONBEGIN####
47 * Author(s): nickg@calivar.com
48 * Contributors: nickg@calivar.com
53 * ####DESCRIPTIONEND####
55 * =================================================================
58 #include <pkgconf/system.h>
59 #include <pkgconf/isoinfra.h>
60 #include <pkgconf/httpd.h>
62 #include <cyg/hal/hal_tables.h>
66 /* ================================================================= */
67 /* Start daemon explicitly
70 #ifndef CYGNUM_HTTPD_SERVER_AUTO_START
72 __externC void cyg_httpd_startup(void);
76 /* ================================================================= */
82 typedef cyg_bool cyg_httpd_handler(FILE *client, char *filename,
83 char *formdata, void *arg);
85 struct cyg_httpd_table_entry
88 cyg_httpd_handler *handler;
92 typedef struct cyg_httpd_table_entry cyg_httpd_table_entry;
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 }
97 /* ================================================================= */
98 /* Useful handler functions
101 /* ----------------------------------------------------------------- */
105 __externC cyg_bool cyg_httpd_send_html( FILE *client, char *filename,
106 char *request, void *arg );
108 /* ----------------------------------------------------------------- */
115 cyg_uint32 content_length;
119 __externC cyg_bool cyg_httpd_send_data( FILE *client, char *filename,
120 char *request, void *arg );
122 #define CYG_HTTPD_DATA( __name, __type, __length, __data ) \
123 cyg_httpd_data __name = { __type, __length, __data }
125 /* ================================================================= */
126 /* HTTP and HTML helper macros and functions
129 /* ----------------------------------------------------------------- */
130 /* HTTP header support
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.
137 __externC void cyg_http_start( FILE *client, char *content_type,
138 int content_length );
139 __externC void cyg_http_finish( FILE *client );
141 #define html_begin(__client) \
142 cyg_http_start( __client, "text/html", 0 ); \
143 html_tag_begin( __client, "html", "" )
145 #define html_end( __client ) \
146 html_tag_end( __client, "html" ); \
147 cyg_http_finish( __client )
149 /* ----------------------------------------------------------------- */
154 __externC void cyg_html_tag_begin( FILE *client, char *tag, char *attr );
155 __externC void cyg_html_tag_end( FILE *client, char *tag );
157 #define html_tag_begin( __client, __tag, __attr ) \
158 cyg_html_tag_begin( __client, __tag, __attr )
160 #define html_tag_end( __client, __tag ) cyg_html_tag_end( __client, __tag )
163 /* ----------------------------------------------------------------- */
168 #define html_head( __client, __title, __meta ) \
170 fprintf(__client, "<%s><%s>", "head", "title" ); \
171 fputs( __title, __client ); \
172 fprintf(__client, "</%s>%s</%s>\n", "title", __meta, "head"); \
175 #define html_body_begin( __client, __attr ) \
176 cyg_html_tag_begin( __client, "body", __attr );
178 #define html_body_end( __client ) \
179 cyg_html_tag_end( __client, "body" );
181 #define html_heading( __client, __level, __heading ) \
182 fprintf(__client,"<h%d>%s</h%d>\n",__level,__heading,__level);
184 /* ----------------------------------------------------------------- */
189 #define html_url( __client, __text, __link ) \
190 fprintf( __client, "<a href=\"%s\">%s</a>\n",__link,__text);
192 #define html_para_begin( __client, __attr ) \
193 cyg_html_tag_begin( __client, "p", __attr );
195 #define html_image( __client, __source, __alt, __attr ) \
196 fprintf( __client, "<%s %s=\"%s\" %s=\"%s\" %s>\n", "img", \
199 (__attr)?(__attr):"" );
201 /* ----------------------------------------------------------------- */
206 #define html_table_begin( __client, __attr ) \
207 cyg_html_tag_begin( __client, "table", __attr );
209 #define html_table_end( __client ) \
210 cyg_html_tag_end( __client, "table" );
212 #define html_table_header( __client, __content, __attr ) \
214 cyg_html_tag_begin( __client, "th", __attr); \
215 fputs( __content, __client ); \
216 cyg_html_tag_end( __client, "th" ); \
219 #define html_table_row_begin( __client, __attr ) \
220 cyg_html_tag_begin( __client, "tr", __attr );
222 #define html_table_row_end( __client ) \
223 cyg_html_tag_end( __client, "tr" );
225 #define html_table_data_begin( __client, __attr ) \
226 cyg_html_tag_begin( __client, "td", __attr );
228 #define html_table_data_end( __client ) \
229 cyg_html_tag_end( __client, "td" );
231 /* ----------------------------------------------------------------- */
236 #define html_form_begin( __client, __url, __attr ) \
237 fprintf(__client, "<%s %s=\"%s\" %s>\n","form", \
239 (__attr)?(__attr):"" );
241 #define html_form_end( __client ) \
242 cyg_html_tag_end( __client, "form" );
244 #define html_form_input( __client, __type, __name, __value, __attr ) \
246 char *__lattr = (__attr); \
247 fprintf(__client, "<%s %s=\"%s\" %s=\"%s\" %s=\"%s\" %s>\n","input", \
251 __lattr?__lattr:"" ); \
254 #define html_form_input_radio( __client, __name, __value, __checked ) \
255 html_form_input( __client, "radio", __name, __value, (__checked)?"checked":"" )
257 #define html_form_input_checkbox( __client, __name, __value, __checked ) \
258 html_form_input( __client, "checkbox", __name, __value, (__checked)?"checked":"" )
260 #define html_form_input_hidden( __client, __name, __value ) \
261 html_form_input( __client, "hidden", __name, __value, "" )
263 #define html_form_select_begin( __client, __name, __attr ) \
264 fprintf( __client, "<%s %s=\"%s\" %s>\n","select", \
266 (__attr)?(__attr):"" );
268 #define html_form_option( __client, __value, __label, __selected ) \
269 fprintf( __client, "<%s %s=\"%s\" %s>\n","option", \
271 (__selected)?"selected":"" ); \
272 fputs(__label, __client );
274 #define html_form_select_end( __client ) \
275 cyg_html_tag_end( __client, "select" );
278 /* ================================================================= */
283 __externC void cyg_formdata_parse( char *data, char *list[], int size );
285 __externC char *cyg_formlist_find( char *list[], char *name );
287 /* ----------------------------------------------------------------- */
288 #endif /* CYGONCE_NET_HTTPD_HTTPD_H */