source: rtems/cpukit/httpd/rom.c @ a85d8ec

4.104.114.84.95
Last change on this file since a85d8ec was a6b4c0df, checked in by Joel Sherrill <joel.sherrill@…>, on 09/01/00 at 10:57:21

2000-08-30 Joel Sherrill <joel@…>

  • Merged version 2.1 of GoAhead? webserver. This update was submitted by Antti P Miettinen <antti.p.miettinen@…>.
  • NOTES, base64.c, ejIntrn.h, emfdb.c, emfdb.h, md5.h, md5c.c, um.c, um.h: New files.
  • wbase64.c: Removed.
  • Makefile.am, asp.c, balloc.c, default.c, ej.h, ejlex.c, ejparse.c, form.c, h.c, handler.c, mime.c, misc.c, ringq.c, rom.c, security.c, socket.c, sym.c, uemf.c, uemf.h, url.c, value.c, webcomp.c, webmain.c, webpage.c, webrom.c, webs.c, webs.h, websuemf.c, wsIntrn.h: Modified.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * rom.c -- Support for ROMed page retrieval.
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
9/******************************** Description *********************************/
10
11/*
12 *      This module provides web page retrieval from compiled web pages. Use the
13 *      webcomp program to compile web pages and link into the GoAhead WebServer.
14 *      This module uses a hashed symbol table for fast page lookup.
15 *
16 *      Usage: webcomp -f webPageFileList -p Prefix >webrom.c
17 */
18
19/********************************* Includes ***********************************/
20
21#include        <stdlib.h>
22
23#include        "wsIntrn.h"
24
25/******************************** Local Data **********************************/
26
27#if WEBS_PAGE_ROM
28
29sym_fd_t        romTab;                                         /* Symbol table for web pages */
30
31/*********************************** Code *************************************/
32/*
33 *      Open the ROM module
34 */
35
36int websRomOpen()
37{
38        websRomPageIndexType    *wip;
39        int                                             nchars;
40        char_t                                  name[SYM_MAX];
41
42        romTab = symOpen(WEBS_SYM_INIT);
43
44        for (wip = websRomPageIndex; wip->path; wip++) {
45                gstrncpy(name, wip->path, SYM_MAX);
46                nchars = gstrlen(name) - 1;
47                if (nchars > 0 &&
48                        (name[nchars] == '/' || name[nchars] == '\\')) {
49                        name[nchars] = '\0';
50                }
51                symEnter(romTab, name, valueInteger((int) wip), 0);
52        }
53        return 0;
54}
55
56/******************************************************************************/
57/*
58 *      Close the ROM module
59 */
60
61void websRomClose()
62{
63        symClose(romTab);
64}
65
66/******************************************************************************/
67/*
68 *      Open a web page
69 */
70
71int websRomPageOpen(webs_t wp, char_t *path, int mode, int perm)
72{
73        websRomPageIndexType    *wip;
74        sym_t                                   *sp;
75
76        a_assert(websValid(wp));
77        a_assert(path && *path);
78
79        if ((sp = symLookup(romTab, path)) == NULL) {
80                return -1;
81        }
82        wip = (websRomPageIndexType*) sp->content.value.integer;
83        wip->pos = 0;
84        return (wp->docfd = wip - websRomPageIndex);
85}
86
87/******************************************************************************/
88/*
89 *      Close a web page
90 */
91
92void websRomPageClose(int fd)
93{
94}
95
96/******************************************************************************/
97/*
98 *      Stat a web page
99 */
100
101int websRomPageStat(char_t *path, websStatType *sbuf)
102{
103        websRomPageIndexType    *wip;
104        sym_t                                   *sp;
105
106        a_assert(path && *path);
107
108        if ((sp = symLookup(romTab, path)) == NULL) {
109                return -1;
110        }
111        wip = (websRomPageIndexType*) sp->content.value.integer;
112
113        memset(sbuf, 0, sizeof(websStatType));
114        sbuf->size = wip->size;
115        if (wip->page == NULL) {
116                sbuf->isDir = 1;
117        }
118        return 0;
119}
120
121/******************************************************************************/
122/*
123 *      Read a web page
124 */
125
126int websRomPageReadData(webs_t wp, char *buf, int nBytes)
127{
128        websRomPageIndexType    *wip;
129        int                                             len;
130
131        a_assert(websValid(wp));
132        a_assert(buf);
133        a_assert(wp->docfd >= 0);
134
135        wip = &websRomPageIndex[wp->docfd];
136
137        len = min(wip->size - wip->pos, nBytes);
138        memcpy(buf, &wip->page[wip->pos], len);
139        wip->pos += len;
140        return len;
141}
142
143/******************************************************************************/
144/*
145 *      Position a web page
146 */
147
148long websRomPageSeek(webs_t wp, long offset, int origin)
149{
150        websRomPageIndexType    *wip;
151        long pos;
152
153        a_assert(websValid(wp));
154        a_assert(origin == SEEK_SET || origin == SEEK_CUR || origin == SEEK_END);
155        a_assert(wp->docfd >= 0);
156
157        wip = &websRomPageIndex[wp->docfd];
158
159        if (origin != SEEK_SET && origin != SEEK_CUR && origin != SEEK_END) {
160                errno = EINVAL;
161                return -1;
162        }
163
164        if (wp->docfd < 0) {
165                errno = EBADF;
166                return -1;
167        }
168
169        pos = offset;
170        switch (origin) {
171        case SEEK_CUR:
172                pos = wip->pos + offset;
173                break;
174        case SEEK_END:
175                pos = wip->size + offset;
176                break;
177        default:
178                break;
179        }
180
181        if (pos < 0) {
182                errno = EBADF;
183                return -1;
184        }
185
186        return (wip->pos = pos);
187}
188
189#endif /* WEBS_PAGE_ROM */
190
191/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.