source: rtems/cpukit/httpd/rom.c @ 9b05600

4.104.114.84.95
Last change on this file since 9b05600 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.9 KB
Line 
1/*
2 * rom.c -- Support for ROMed page retrieval.
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 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#if CE
24#define         EINVAL  22
25#define         EBADF   9
26#else
27#include        <errno.h>
28#endif
29
30#include        "wsIntrn.h"
31
32/******************************** Local Data **********************************/
33
34#if WEBS_PAGE_ROM
35
36sym_fd_t        romTab;                                         /* Symbol table for web pages */
37
38/*********************************** Code *************************************/
39/*
40 *      Open the ROM module
41 */
42
43int websRomOpen()
44{
45        websRomPageIndexType    *wip;
46        int                                             nchars;
47        char_t                                  name[SYM_MAX];
48
49        romTab = symOpen(64);
50
51        for (wip = websRomPageIndex; wip->path; wip++) {
52                gstrncpy(name, wip->path, SYM_MAX);
53                nchars = gstrlen(name) - 1;
54                if (nchars > 0 &&
55                        (name[nchars] == '/' || name[nchars] == '\\')) {
56                        name[nchars] = '\0';
57                }
58                symEnter(romTab, name, valueInteger((int) wip), 0);
59        }
60        return 0;
61}
62
63/******************************************************************************/
64/*
65 *      Close the ROM module
66 */
67
68void websRomClose()
69{
70        symClose(romTab, NULL);
71}
72
73/******************************************************************************/
74/*
75 *      Open a web page
76 */
77
78int websRomPageOpen(webs_t wp, char_t *path, int mode, int perm)
79{
80        websRomPageIndexType    *wip;
81        sym_t                                   *sp;
82
83        a_assert(websValid(wp));
84        a_assert(path && *path);
85
86        if ((sp = symLookup(romTab, path)) == NULL) {
87                return -1;
88        }
89        wip = (websRomPageIndexType*) sp->content.value.integer;
90        wip->pos = 0;
91        return (wp->docfd = wip - websRomPageIndex);
92}
93
94/******************************************************************************/
95/*
96 *      Close a web page
97 */
98
99void websRomPageClose(int fd)
100{
101}
102
103/******************************************************************************/
104/*
105 *      Stat a web page
106 */
107
108int websRomPageStat(char_t *path, websStatType* sbuf)
109{
110        websRomPageIndexType    *wip;
111        sym_t                                   *sp;
112
113        a_assert(path && *path);
114
115        if ((sp = symLookup(romTab, path)) == NULL) {
116                return -1;
117        }
118        wip = (websRomPageIndexType*) sp->content.value.integer;
119
120        memset(sbuf, 0, sizeof(websStatType));
121        sbuf->size = wip->size;
122        if (wip->page == NULL) {
123                sbuf->isDir = 1;
124        }
125        return 0;
126}
127
128/******************************************************************************/
129/*
130 *      Read a web page
131 */
132
133int websRomPageReadData(webs_t wp, char *buf, int nBytes)
134{
135        websRomPageIndexType    *wip;
136        int                                             len;
137
138        a_assert(websValid(wp));
139        a_assert(buf);
140        a_assert(wp->docfd >= 0);
141
142        wip = &websRomPageIndex[wp->docfd];
143
144        len = min(wip->size - wip->pos, nBytes);
145        memcpy(buf, &wip->page[wip->pos], len);
146        wip->pos += len;
147        return len;
148}
149
150/******************************************************************************/
151/*
152 *      Position a web page
153 */
154
155long websRomPageSeek(webs_t wp, long offset, int origin)
156{
157        websRomPageIndexType    *wip;
158        long pos;
159
160        a_assert(websValid(wp));
161        a_assert(origin == SEEK_SET || origin == SEEK_CUR || origin == SEEK_END);
162        a_assert(wp->docfd >= 0);
163
164        wip = &websRomPageIndex[wp->docfd];
165
166        if (origin != SEEK_SET && origin != SEEK_CUR && origin != SEEK_END) {
167                errno = EINVAL;
168                return -1;
169        }
170
171        if (wp->docfd < 0) {
172                errno = EBADF;
173                return -1;
174        }
175
176        pos = offset;
177        switch (origin) {
178        case SEEK_CUR:
179                pos = wip->pos + offset;
180                break;
181        case SEEK_END:
182                pos = wip->size + offset;
183                break;
184        default:
185                break;
186        }
187
188        if (pos < 0) {
189                errno = EBADF;
190                return -1;
191        }
192
193        return (wip->pos = pos);
194}
195
196#endif
197
198/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.