source: rtems/cpukit/httpd/form.c @ 54650f51

4.104.114.84.95
Last change on this file since 54650f51 was ee3afa2, checked in by Joel Sherrill <joel.sherrill@…>, on 04/11/03 at 14:46:55

2002-04-10 Mike Siers <mikes@…>

  • rtems_webserver/NOTES, rtems_webserver/asp.c, rtems_webserver/balloc.c, rtems_webserver/default.c, rtems_webserver/ej.h, rtems_webserver/ejIntrn.h, rtems_webserver/ejlex.c, rtems_webserver/ejparse.c, rtems_webserver/emfdb.c, rtems_webserver/emfdb.h, rtems_webserver/form.c, rtems_webserver/h.c, rtems_webserver/handler.c, rtems_webserver/license.txt, rtems_webserver/md5.h, rtems_webserver/md5c.c, rtems_webserver/mime.c, rtems_webserver/misc.c, rtems_webserver/ringq.c, rtems_webserver/rom.c, rtems_webserver/security.c, rtems_webserver/sock.c, rtems_webserver/sym.c, rtems_webserver/uemf.c, rtems_webserver/uemf.h, rtems_webserver/um.c, rtems_webserver/um.h, rtems_webserver/url.c, rtems_webserver/value.c, rtems_webserver/wbase64.c, rtems_webserver/webcomp.c, rtems_webserver/webpage.c, rtems_webserver/webrom.c, rtems_webserver/webs.c, rtems_webserver/webs.h, rtems_webserver/websuemf.c, rtems_webserver/wsIntrn.h: Update to GoAhead? Webserver 2.1.4. The following URL is the release notes from GoAhead?.

http://data.goahead.com/Software/Webserver/2.1.4/release.htm

I have only done a minimal amount of testing (i.e. the network
demo program works fine). Please try this out and let me know
if it works. The patch needs to be applied on the
c/src/libnetworking/rtems_webserver directory.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * form.c -- Form processing (in-memory CGI) for the GoAhead Web server
3 *
4 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
5 *
6 * See the file "license.txt" for usage and redistribution license requirements
7 *
8 * $Id$
9 */
10
11/********************************** Description *******************************/
12
13/*
14 *      This module implements the /goform handler. It emulates CGI processing
15 *      but performs this in-process and not as an external process. This enables
16 *      a very high performance implementation with easy parsing and decoding
17 *      of query strings and posted data.
18 */
19
20/*********************************** Includes *********************************/
21
22#include        "wsIntrn.h"
23
24/************************************ Locals **********************************/
25
26static sym_fd_t formSymtab = -1;                        /* Symbol table for form handlers */
27
28/************************************* Code ***********************************/
29/*
30 *      Process a form request. Returns 1 always to indicate it handled the URL
31 */
32
33int websFormHandler(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg,
34        char_t *url, char_t *path, char_t *query)
35{
36        sym_t           *sp;
37        char_t          formBuf[FNAMESIZE];
38        char_t          *cp, *formName;
39        int                     (*fn)(void *sock, char_t *path, char_t *args);
40
41        a_assert(websValid(wp));
42        a_assert(url && *url);
43        a_assert(path && *path == '/');
44
45        websStats.formHits++;
46
47/*
48 *      Extract the form name
49 */
50        gstrncpy(formBuf, path, TSZ(formBuf));
51        if ((formName = gstrchr(&formBuf[1], '/')) == NULL) {
52                websError(wp, 200, T("Missing form name"));
53                return 1;
54        }
55        formName++;
56        if ((cp = gstrchr(formName, '/')) != NULL) {
57                *cp = '\0';
58        }
59
60/*
61 *      Lookup the C form function first and then try tcl (no javascript support
62 *      yet).
63 */
64        sp = symLookup(formSymtab, formName);
65        if (sp == NULL) {
66                websError(wp, 200, T("Form %s is not defined"), formName);
67        } else {
68                fn = (int (*)(void *, char_t *, char_t *)) sp->content.value.integer;
69                a_assert(fn);
70                if (fn) {
71/*
72 *                      For good practice, forms must call websDone()
73 */
74                        (*fn)((void*) wp, formName, query);
75
76/*
77 *                      Remove the test to force websDone, since this prevents
78 *                      the server "push" from a form>
79 */
80#if 0 /* push */
81                        if (websValid(wp)) {
82                                websError(wp, 200, T("Form didn't call websDone"));
83                        }
84#endif /* push */
85                }
86        }
87        return 1;
88}
89
90/******************************************************************************/
91/*
92 *      Define a form function in the "form" map space.
93 */
94
95int websFormDefine(char_t *name, void (*fn)(webs_t wp, char_t *path,
96        char_t *query))
97{
98        a_assert(name && *name);
99        a_assert(fn);
100
101        if (fn == NULL) {
102                return -1;
103        }
104
105        symEnter(formSymtab, name, valueInteger((int) fn), (int) NULL);
106        return 0;
107}
108
109/******************************************************************************/
110/*
111 *      Open the symbol table for forms.
112 */
113
114void websFormOpen()
115{
116        formSymtab = symOpen(WEBS_SYM_INIT);
117}
118
119/******************************************************************************/
120/*
121 *      Close the symbol table for forms.
122 */
123
124void websFormClose()
125{
126        if (formSymtab != -1) {
127                symClose(formSymtab);
128                formSymtab = -1;
129        }
130}
131
132/******************************************************************************/
133/*
134 *      Write a webs header. This is a convenience routine to write a common
135 *      header for a form back to the browser.
136 */
137
138void websHeader(webs_t wp)
139{
140        a_assert(websValid(wp));
141
142        websWrite(wp, T("HTTP/1.0 200 OK\n"));
143
144/*
145 *      By license terms the following line of code must not be modified
146 */
147        websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);
148
149        websWrite(wp, T("Pragma: no-cache\n"));
150        websWrite(wp, T("Cache-control: no-cache\n"));
151        websWrite(wp, T("Content-Type: text/html\n"));
152        websWrite(wp, T("\n"));
153        websWrite(wp, T("<html>\n"));
154}
155
156/******************************************************************************/
157/*
158 *      Write a webs footer
159 */
160
161void websFooter(webs_t wp)
162{
163        a_assert(websValid(wp));
164
165        websWrite(wp, T("</html>\n"));
166}
167
168/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.