OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [net/] [httpd/] [v2_0/] [include/] [httpd.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
#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
/* Lookup Table
68
 *
69
 *
70
 */
71
 
72
typedef cyg_bool cyg_httpd_handler(FILE *client, char *filename,
73
                              char *formdata, void *arg);
74
 
75
struct cyg_httpd_table_entry
76
{
77
    char                *pattern;
78
    cyg_httpd_handler   *handler;
79
    void                *arg;
80
} CYG_HAL_TABLE_TYPE;
81
 
82
typedef struct cyg_httpd_table_entry cyg_httpd_table_entry;
83
 
84
#define CYG_HTTPD_TABLE_ENTRY( __name, __pattern, __handler, __arg ) \
85
cyg_httpd_table_entry __name CYG_HAL_TABLE_ENTRY( httpd_table ) = { __pattern, __handler, __arg }
86
 
87
/* ================================================================= */
88
/* Useful handler functions
89
 */
90
 
91
/* ----------------------------------------------------------------- */
92
/*
93
 */
94
 
95
__externC int cyg_httpd_send_html( FILE *client, char *filename,
96
                                   char *request, void *arg );
97
 
98
/* ----------------------------------------------------------------- */
99
/*
100
 */
101
 
102
typedef struct
103
{
104
    char        *content_type;
105
    cyg_uint32  content_length;
106
    cyg_uint8   *data;
107
} cyg_httpd_data;
108
 
109
__externC int cyg_httpd_send_data( FILE *client, char *filename,
110
                                   char *request, void *arg );
111
 
112
#define CYG_HTTPD_DATA( __name, __type, __length, __data ) \
113
cyg_httpd_data __name = { __type, __length, __data }
114
 
115
/* ================================================================= */
116
/* HTTP and HTML helper macros and functions
117
 */
118
 
119
/* ----------------------------------------------------------------- */
120
/* HTTP header support
121
 *
122
 * cyg_http_start() sends an HTTP header with the given content type
123
 * and length. cyg_http_finish() terminates an HTTP send.
124
 * html_begin() starts an HTML document, and html_end() finishes it.
125
 */
126
 
127
__externC void cyg_http_start( FILE *client, char *content_type,
128
                               int content_length );
129
__externC void cyg_http_finish( FILE *client );
130
 
131
#define html_begin(__client)                            \
132
        cyg_http_start( __client, "text/html", 0 );     \
133
        html_tag_begin( __client, "html", "" )
134
 
135
#define html_end( __client )                    \
136
        html_tag_end( __client, "html" );       \
137
        cyg_http_finish( __client )
138
 
139
/* ----------------------------------------------------------------- */
140
/*
141
 */
142
 
143
 
144
__externC void cyg_html_tag_begin( FILE *client, char *tag, char *attr );
145
__externC void cyg_html_tag_end( FILE *client, char *tag );
146
 
147
#define html_tag_begin( __client, __tag, __attr ) \
148
        cyg_html_tag_begin( __client, __tag, __attr )
149
 
150
#define html_tag_end( __client, __tag ) cyg_html_tag_end( __client, __tag )
151
 
152
 
153
/* ----------------------------------------------------------------- */
154
/*
155
 */
156
 
157
 
158
#define html_head( __client, __title, __meta )                          \
159
{                                                                       \
160
    fprintf(__client, "<%s><%s>", "head", "title" );                    \
161
    fputs( __title, __client );                                         \
162
    fprintf(__client, "</%s>%s</%s>\n", "title", __meta, "head");       \
163
}
164
 
165
#define html_body_begin( __client, __attr )     \
166
        cyg_html_tag_begin( __client, "body", __attr );
167
 
168
#define html_body_end( __client )               \
169
        cyg_html_tag_end( __client, "body" );
170
 
171
#define html_heading( __client, __level, __heading ) \
172
    fprintf(__client,"<h%d>%s</h%d>\n",__level,__heading,__level);
173
 
174
/* ----------------------------------------------------------------- */
175
/*
176
 */
177
 
178
 
179
#define html_url( __client, __text, __link ) \
180
        fprintf( __client, "<a href=\"%s\">%s</a>\n",__link,__text);
181
 
182
#define html_para_begin( __client, __attr )     \
183
        cyg_html_tag_begin( __client, "p", __attr );
184
 
185
#define html_image( __client, __source, __alt, __attr )                 \
186
        fprintf( __client, "<%s %s=\"%s\" %s=\"%s\" %s>\n", "img",      \
187
                 "src",__source,                                        \
188
                 "alt",__alt,                                           \
189
                 (__attr)?(__attr):"" );
190
 
191
/* ----------------------------------------------------------------- */
192
/*
193
 */
194
 
195
 
196
#define html_table_begin( __client, __attr )     \
197
        cyg_html_tag_begin( __client, "table", __attr );
198
 
199
#define html_table_end( __client )               \
200
        cyg_html_tag_end( __client, "table" );
201
 
202
#define html_table_header( __client, __content, __attr )        \
203
{                                                               \
204
    cyg_html_tag_begin( __client, "th", __attr);                \
205
    fputs( __content, __client );                               \
206
    cyg_html_tag_end( __client, "th" );                         \
207
}
208
 
209
#define html_table_row_begin( __client, __attr )     \
210
        cyg_html_tag_begin( __client, "tr", __attr );
211
 
212
#define html_table_row_end( __client )               \
213
        cyg_html_tag_end( __client, "tr" );
214
 
215
#define html_table_data_begin( __client, __attr )     \
216
        cyg_html_tag_begin( __client, "td", __attr );
217
 
218
#define html_table_data_end( __client )               \
219
        cyg_html_tag_end( __client, "td" );
220
 
221
/* ----------------------------------------------------------------- */
222
/*
223
 */
224
 
225
 
226
#define html_form_begin( __client, __url, __attr )      \
227
        fprintf(__client, "<%s %s=\"%s\" %s>\n","form", \
228
                "action",__url,                         \
229
                (__attr)?(__attr):"" );
230
 
231
#define html_form_end( __client )               \
232
        cyg_html_tag_end( __client, "form" );
233
 
234
#define html_form_input( __client, __type, __name, __value, __attr )            \
235
{                                                                               \
236
    char *__lattr = (__attr);                                                   \
237
    fprintf(__client, "<%s %s=\"%s\" %s=\"%s\" %s=\"%s\" %s>\n","input",        \
238
            "type",__type,                                                      \
239
            "name",__name,                                                      \
240
            "value",__value,                                                    \
241
            __lattr?__lattr:"" );                                               \
242
}
243
 
244
#define html_form_input_radio( __client, __name, __value, __checked ) \
245
        html_form_input( __client, "radio", __name, __value, (__checked)?"checked":"" )
246
 
247
#define html_form_input_checkbox( __client, __name, __value, __checked ) \
248
        html_form_input( __client, "checkbox", __name, __value, (__checked)?"checked":"" )
249
 
250
#define html_form_input_hidden( __client, __name, __value ) \
251
        html_form_input( __client, "hidden", __name, __value, "" )
252
 
253
#define html_form_select_begin( __client, __name, __attr )      \
254
        fprintf( __client, "<%s %s=\"%s\" %s>\n","select",      \
255
                 "name",__name,                                 \
256
                 (__attr)?(__attr):"" );
257
 
258
#define html_form_option( __client, __value, __label, __selected )      \
259
        fprintf( __client, "<%s %s=\"%s\" %s>\n","option",              \
260
                 "value", __value,                                      \
261
                 (__selected)?"selected":"" );                          \
262
        fputs(__label, __client );
263
 
264
#define html_form_select_end( __client ) \
265
        cyg_html_tag_end( __client, "select" );
266
 
267
 
268
/* ================================================================= */
269
/*
270
 */
271
 
272
 
273
__externC void cyg_formdata_parse( char *data, char *list[], int size );
274
 
275
__externC char *cyg_formlist_find( char *list[], char *name );
276
 
277
/* ----------------------------------------------------------------- */
278
#endif /* CYGONCE_NET_HTTPD_HTTPD_H                                  */
279
/* end of httpd.c                                                    */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.