source: rtems/cpukit/httpd/form.c @ c1cdaa0

4.104.114.84.95
Last change on this file since c1cdaa0 was c1cdaa0, checked in by Joel Sherrill <joel.sherrill@…>, on 10/27/99 at 12:50:33

Patch from Emmanuel Raguet <raguet@…> and Eric Valette
<valette@…> to add a port of the GoAhead? web server
(httpd) to the RTEMS build tree. They have successfully used
this BSP on i386/pc386 and PowerPC/mcp750.

Mark and Joel spoke with Nick Berliner <nickb@…> on
26 Oct 1999 about this port and got verbal approval to include
it in RTEMS distributions.

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