summaryrefslogtreecommitdiff
path: root/ecos/packages/net/httpd/current/include/httpd.h
blob: 11501176b7cf412a54d5b1d894fc94df6b0d3c53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#ifndef CYGONCE_NET_HTTPD_HTTPD_H
#define CYGONCE_NET_HTTPD_HTTPD_H
/* =================================================================
 *
 *      httpd.h
 *
 *      A simple embedded HTTP server
 *
 * ================================================================= 
 * ####ECOSGPLCOPYRIGHTBEGIN####                                     
 * -------------------------------------------                       
 * This file is part of eCos, the Embedded Configurable Operating System.
 * Copyright (C) 2002 Free Software Foundation, Inc.                 
 *
 * eCos is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 or (at your option) any later
 * version.                                                          
 *
 * eCos is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.                                                 
 *
 * You should have received a copy of the GNU General Public License 
 * along with eCos; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.     
 *
 * As a special exception, if other files instantiate templates or use
 * macros or inline functions from this file, or you compile this file
 * and link it with other works to produce a work based on this file,
 * this file does not by itself cause the resulting work to be covered by
 * the GNU General Public License. However the source code for this file
 * must still be made available in accordance with section (3) of the GNU
 * General Public License v2.                                        
 *
 * This exception does not invalidate any other reasons why a work based
 * on this file might be covered by the GNU General Public License.  
 * -------------------------------------------                       
 * ####ECOSGPLCOPYRIGHTEND####                                       
 * =================================================================
 * #####DESCRIPTIONBEGIN####
 * 
 *  Author(s):    nickg@calivar.com
 *  Contributors: nickg@calivar.com
 *  Date:         2002-10-14
 *  Purpose:      
 *  Description:  
 *               
 * ####DESCRIPTIONEND####
 * 
 * =================================================================
 */

#include <pkgconf/system.h>
#include <pkgconf/isoinfra.h>
#include <pkgconf/httpd.h>

#include <cyg/hal/hal_tables.h>

#include <stdio.h>

/* ================================================================= */
/* Start daemon explicitly
 */

#ifndef CYGNUM_HTTPD_SERVER_AUTO_START

__externC void cyg_httpd_startup(void);

#endif

/* ================================================================= */
/* Lookup Table
 *
 * 
 */

typedef cyg_bool cyg_httpd_handler(FILE *client, char *filename,
                              char *formdata, void *arg);

struct cyg_httpd_table_entry
{
    char                *pattern;
    cyg_httpd_handler   *handler;
    void                *arg;
} CYG_HAL_TABLE_TYPE;

typedef struct cyg_httpd_table_entry cyg_httpd_table_entry;

#define CYG_HTTPD_TABLE_ENTRY( __name, __pattern, __handler, __arg ) \
cyg_httpd_table_entry __name CYG_HAL_TABLE_ENTRY( httpd_table ) = { __pattern, __handler, __arg } 

/* ================================================================= */
/* Useful handler functions
 */

/* ----------------------------------------------------------------- */
/*
 */

__externC cyg_bool cyg_httpd_send_html( FILE *client, char *filename,
                                        char *request, void *arg );

/* ----------------------------------------------------------------- */
/*
 */

typedef struct
{
    char        *content_type;
    cyg_uint32  content_length;
    cyg_uint8   *data;
} cyg_httpd_data;

__externC cyg_bool cyg_httpd_send_data( FILE *client, char *filename,
                                        char *request, void *arg );

#define CYG_HTTPD_DATA( __name, __type, __length, __data ) \
cyg_httpd_data __name = { __type, __length, __data }

/* ================================================================= */
/* HTTP and HTML helper macros and functions
 */

/* ----------------------------------------------------------------- */
/* HTTP header support
 *
 * cyg_http_start() sends an HTTP header with the given content type
 * and length. cyg_http_finish() terminates an HTTP send.
 * html_begin() starts an HTML document, and html_end() finishes it.
 */

__externC void cyg_http_start( FILE *client, char *content_type,
                               int content_length );
__externC void cyg_http_finish( FILE *client );

#define html_begin(__client)                            \
        cyg_http_start( __client, "text/html", 0 );     \
        html_tag_begin( __client, "html", "" )

#define html_end( __client )                    \
        html_tag_end( __client, "html" );       \
        cyg_http_finish( __client )

/* ----------------------------------------------------------------- */
/*
 */


__externC void cyg_html_tag_begin( FILE *client, char *tag, char *attr );
__externC void cyg_html_tag_end( FILE *client, char *tag );

#define html_tag_begin( __client, __tag, __attr ) \
        cyg_html_tag_begin( __client, __tag, __attr )

#define html_tag_end( __client, __tag ) cyg_html_tag_end( __client, __tag )


/* ----------------------------------------------------------------- */
/*
 */


#define html_head( __client, __title, __meta )                          \
{                                                                       \
    fprintf(__client, "<%s><%s>", "head", "title" );                    \
    fputs( __title, __client );                                         \
    fprintf(__client, "</%s>%s</%s>\n", "title", __meta, "head");       \
}

#define html_body_begin( __client, __attr )     \
        cyg_html_tag_begin( __client, "body", __attr );

#define html_body_end( __client )               \
        cyg_html_tag_end( __client, "body" );

#define html_heading( __client, __level, __heading ) \
    fprintf(__client,"<h%d>%s</h%d>\n",__level,__heading,__level);

/* ----------------------------------------------------------------- */
/*
 */


#define html_url( __client, __text, __link ) \
        fprintf( __client, "<a href=\"%s\">%s</a>\n",__link,__text);

#define html_para_begin( __client, __attr )     \
        cyg_html_tag_begin( __client, "p", __attr );

#define html_image( __client, __source, __alt, __attr )                 \
        fprintf( __client, "<%s %s=\"%s\" %s=\"%s\" %s>\n", "img",      \
                 "src",__source,                                        \
                 "alt",__alt,                                           \
                 (__attr)?(__attr):"" );

/* ----------------------------------------------------------------- */
/*
 */


#define html_table_begin( __client, __attr )     \
        cyg_html_tag_begin( __client, "table", __attr );

#define html_table_end( __client )               \
        cyg_html_tag_end( __client, "table" );

#define html_table_header( __client, __content, __attr )        \
{                                                               \
    cyg_html_tag_begin( __client, "th", __attr);                \
    fputs( __content, __client );                               \
    cyg_html_tag_end( __client, "th" );                         \
}

#define html_table_row_begin( __client, __attr )     \
        cyg_html_tag_begin( __client, "tr", __attr );

#define html_table_row_end( __client )               \
        cyg_html_tag_end( __client, "tr" );

#define html_table_data_begin( __client, __attr )     \
        cyg_html_tag_begin( __client, "td", __attr );

#define html_table_data_end( __client )               \
        cyg_html_tag_end( __client, "td" );

/* ----------------------------------------------------------------- */
/*
 */


#define html_form_begin( __client, __url, __attr )      \
        fprintf(__client, "<%s %s=\"%s\" %s>\n","form", \
                "action",__url,                         \
                (__attr)?(__attr):"" );

#define html_form_end( __client )               \
        cyg_html_tag_end( __client, "form" );

#define html_form_input( __client, __type, __name, __value, __attr )            \
{                                                                               \
    char *__lattr = (__attr);                                                   \
    fprintf(__client, "<%s %s=\"%s\" %s=\"%s\" %s=\"%s\" %s>\n","input",        \
            "type",__type,                                                      \
            "name",__name,                                                      \
            "value",__value,                                                    \
            __lattr?__lattr:"" );                                               \
}

#define html_form_input_radio( __client, __name, __value, __checked ) \
        html_form_input( __client, "radio", __name, __value, (__checked)?"checked":"" )

#define html_form_input_checkbox( __client, __name, __value, __checked ) \
        html_form_input( __client, "checkbox", __name, __value, (__checked)?"checked":"" )

#define html_form_input_hidden( __client, __name, __value ) \
        html_form_input( __client, "hidden", __name, __value, "" )

#define html_form_select_begin( __client, __name, __attr )      \
        fprintf( __client, "<%s %s=\"%s\" %s>\n","select",      \
                 "name",__name,                                 \
                 (__attr)?(__attr):"" );

#define html_form_option( __client, __value, __label, __selected )      \
        fprintf( __client, "<%s %s=\"%s\" %s>\n","option",              \
                 "value", __value,                                      \
                 (__selected)?"selected":"" );                          \
        fputs(__label, __client );

#define html_form_select_end( __client ) \
        cyg_html_tag_end( __client, "select" );


/* ================================================================= */
/*
 */


__externC void cyg_formdata_parse( char *data, char *list[], int size );

__externC char *cyg_formlist_find( char *list[], char *name );

/* ----------------------------------------------------------------- */
#endif /* CYGONCE_NET_HTTPD_HTTPD_H                                  */
/* end of httpd.c                                                    */