summaryrefslogtreecommitdiffstats
path: root/cpukit/httpd/rom.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-10-27 12:50:33 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-10-27 12:50:33 +0000
commitc1cdaa0ce8017b075487e6670f89eb4e715258ea (patch)
treed4571a02595d6cf6a24d40d6968d83ece3b7a574 /cpukit/httpd/rom.c
parentNew files created by split of old imfs_handlers.c. (diff)
downloadrtems-c1cdaa0ce8017b075487e6670f89eb4e715258ea.tar.bz2
Patch from Emmanuel Raguet <raguet@crf.canon.fr> and Eric Valette
<valette@crf.canon.fr> 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@goahead.com> on 26 Oct 1999 about this port and got verbal approval to include it in RTEMS distributions.
Diffstat (limited to 'cpukit/httpd/rom.c')
-rw-r--r--cpukit/httpd/rom.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/cpukit/httpd/rom.c b/cpukit/httpd/rom.c
new file mode 100644
index 0000000000..4e6c8f1e93
--- /dev/null
+++ b/cpukit/httpd/rom.c
@@ -0,0 +1,198 @@
+/*
+ * rom.c -- Support for ROMed page retrieval.
+ *
+ * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved.
+ *
+ * See the file "license.txt" for usage and redistribution license requirements
+ */
+
+/******************************** Description *********************************/
+
+/*
+ * This module provides web page retrieval from compiled web pages. Use the
+ * webcomp program to compile web pages and link into the GoAhead WebServer.
+ * This module uses a hashed symbol table for fast page lookup.
+ *
+ * Usage: webcomp -f webPageFileList -p Prefix >webrom.c
+ */
+
+/********************************* Includes ***********************************/
+
+#include <stdlib.h>
+
+#if CE
+#define EINVAL 22
+#define EBADF 9
+#else
+#include <errno.h>
+#endif
+
+#include "wsIntrn.h"
+
+/******************************** Local Data **********************************/
+
+#if WEBS_PAGE_ROM
+
+sym_fd_t romTab; /* Symbol table for web pages */
+
+/*********************************** Code *************************************/
+/*
+ * Open the ROM module
+ */
+
+int websRomOpen()
+{
+ websRomPageIndexType *wip;
+ int nchars;
+ char_t name[SYM_MAX];
+
+ romTab = symOpen(64);
+
+ for (wip = websRomPageIndex; wip->path; wip++) {
+ gstrncpy(name, wip->path, SYM_MAX);
+ nchars = gstrlen(name) - 1;
+ if (nchars > 0 &&
+ (name[nchars] == '/' || name[nchars] == '\\')) {
+ name[nchars] = '\0';
+ }
+ symEnter(romTab, name, valueInteger((int) wip), 0);
+ }
+ return 0;
+}
+
+/******************************************************************************/
+/*
+ * Close the ROM module
+ */
+
+void websRomClose()
+{
+ symClose(romTab, NULL);
+}
+
+/******************************************************************************/
+/*
+ * Open a web page
+ */
+
+int websRomPageOpen(webs_t wp, char_t *path, int mode, int perm)
+{
+ websRomPageIndexType *wip;
+ sym_t *sp;
+
+ a_assert(websValid(wp));
+ a_assert(path && *path);
+
+ if ((sp = symLookup(romTab, path)) == NULL) {
+ return -1;
+ }
+ wip = (websRomPageIndexType*) sp->content.value.integer;
+ wip->pos = 0;
+ return (wp->docfd = wip - websRomPageIndex);
+}
+
+/******************************************************************************/
+/*
+ * Close a web page
+ */
+
+void websRomPageClose(int fd)
+{
+}
+
+/******************************************************************************/
+/*
+ * Stat a web page
+ */
+
+int websRomPageStat(char_t *path, websStatType* sbuf)
+{
+ websRomPageIndexType *wip;
+ sym_t *sp;
+
+ a_assert(path && *path);
+
+ if ((sp = symLookup(romTab, path)) == NULL) {
+ return -1;
+ }
+ wip = (websRomPageIndexType*) sp->content.value.integer;
+
+ memset(sbuf, 0, sizeof(websStatType));
+ sbuf->size = wip->size;
+ if (wip->page == NULL) {
+ sbuf->isDir = 1;
+ }
+ return 0;
+}
+
+/******************************************************************************/
+/*
+ * Read a web page
+ */
+
+int websRomPageReadData(webs_t wp, char *buf, int nBytes)
+{
+ websRomPageIndexType *wip;
+ int len;
+
+ a_assert(websValid(wp));
+ a_assert(buf);
+ a_assert(wp->docfd >= 0);
+
+ wip = &websRomPageIndex[wp->docfd];
+
+ len = min(wip->size - wip->pos, nBytes);
+ memcpy(buf, &wip->page[wip->pos], len);
+ wip->pos += len;
+ return len;
+}
+
+/******************************************************************************/
+/*
+ * Position a web page
+ */
+
+long websRomPageSeek(webs_t wp, long offset, int origin)
+{
+ websRomPageIndexType *wip;
+ long pos;
+
+ a_assert(websValid(wp));
+ a_assert(origin == SEEK_SET || origin == SEEK_CUR || origin == SEEK_END);
+ a_assert(wp->docfd >= 0);
+
+ wip = &websRomPageIndex[wp->docfd];
+
+ if (origin != SEEK_SET && origin != SEEK_CUR && origin != SEEK_END) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (wp->docfd < 0) {
+ errno = EBADF;
+ return -1;
+ }
+
+ pos = offset;
+ switch (origin) {
+ case SEEK_CUR:
+ pos = wip->pos + offset;
+ break;
+ case SEEK_END:
+ pos = wip->size + offset;
+ break;
+ default:
+ break;
+ }
+
+ if (pos < 0) {
+ errno = EBADF;
+ return -1;
+ }
+
+ return (wip->pos = pos);
+}
+
+#endif
+
+/******************************************************************************/