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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [httpd/] [current/] [include/] [httpd.h] - Blame information for rev 817

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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