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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [libnetworking/] [rtems_webserver/] [rom.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 
29
sym_fd_t        romTab;                                         /* Symbol table for web pages */
30
 
31
/*********************************** Code *************************************/
32
/*
33
 *      Open the ROM module
34
 */
35
 
36
int 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
 
61
void websRomClose()
62
{
63
        symClose(romTab);
64
}
65
 
66
/******************************************************************************/
67
/*
68
 *      Open a web page
69
 */
70
 
71
int 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
 
92
void websRomPageClose(int fd)
93
{
94
}
95
 
96
/******************************************************************************/
97
/*
98
 *      Stat a web page
99
 */
100
 
101
int 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
 
126
int 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
 
148
long 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
/******************************************************************************/

powered by: WebSVN 2.1.0

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