diff --git a/c/src/exec/libnetworking/Makefile.am b/c/src/exec/libnetworking/Makefile.am index ceb8e92c91..faa250ad31 100644 --- a/c/src/exec/libnetworking/Makefile.am +++ b/c/src/exec/libnetworking/Makefile.am @@ -5,7 +5,8 @@ AUTOMAKE_OPTIONS = foreign 1.4 ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal -SUBDIRS = include kern lib libc net netinet nfs rtems rtems_servers wrapup +SUBDIRS = include kern lib libc net netinet nfs rtems rtems_servers \ +rtems_webserver wrapup EXTRA_DIST = \ CHANGELOG \ diff --git a/c/src/libnetworking/Makefile.am b/c/src/libnetworking/Makefile.am index ceb8e92c91..faa250ad31 100644 --- a/c/src/libnetworking/Makefile.am +++ b/c/src/libnetworking/Makefile.am @@ -5,7 +5,8 @@ AUTOMAKE_OPTIONS = foreign 1.4 ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal -SUBDIRS = include kern lib libc net netinet nfs rtems rtems_servers wrapup +SUBDIRS = include kern lib libc net netinet nfs rtems rtems_servers \ +rtems_webserver wrapup EXTRA_DIST = \ CHANGELOG \ diff --git a/c/src/libnetworking/configure.in b/c/src/libnetworking/configure.in index 237c27ce07..7906b85d6a 100644 --- a/c/src/libnetworking/configure.in +++ b/c/src/libnetworking/configure.in @@ -42,5 +42,6 @@ netinet/Makefile nfs/Makefile rtems/Makefile rtems_servers/Makefile +rtems_webserver/Makefile wrapup/Makefile ) diff --git a/c/src/libnetworking/include/Makefile.in b/c/src/libnetworking/include/Makefile.in index 32dc7ed9c9..9cdb3c1005 100644 --- a/c/src/libnetworking/include/Makefile.in +++ b/c/src/libnetworking/include/Makefile.in @@ -56,6 +56,9 @@ SRCS = $(H_FILES) $(SYS_H_FILES) $(RTEMS_H_FILES) $(MACHINE_H_FILES) \ $(VM_H_FILES) $(NET_H_FILES) $(NETINET_H_FILES) $(ARPA_H_FILES) \ $(NFS_H_FILES) $(RTEMS_SERVERS_H_FILES) +RTEMS_WEBSERVER_H_PIECES= rtems_webserver +RTEMS_WEBSERVER_H_FILES=$(RTEMS_WEBSERVER_H_PIECES:%=$(srcdir)/../rtems_webserver/%.h) + include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg include $(RTEMS_ROOT)/make/leaf.cfg @@ -87,6 +90,7 @@ preinstall: $(INSTALLDIRS) $(SRCS) @$(INSTALL_CHANGE) -m 644 $(ARPA_H_FILES) $(PROJECT_INCLUDE)/arpa @$(INSTALL_CHANGE) -m 644 $(NFS_H_FILES) $(PROJECT_INCLUDE)/nfs @$(INSTALL_CHANGE) -m 644 $(RTEMS_SERVERS_H_FILES) $(PROJECT_INCLUDE) + @$(INSTALL_CHANGE) -m 644 $(RTEMS_WEBSERVER_H_FILES) $(PROJECT_INCLUDE) all: preinstall diff --git a/c/src/libnetworking/rtems_webserver/Makefile.in b/c/src/libnetworking/rtems_webserver/Makefile.in new file mode 100644 index 0000000000..2951acb714 --- /dev/null +++ b/c/src/libnetworking/rtems_webserver/Makefile.in @@ -0,0 +1,59 @@ +# +# $Id$ +# + +@SET_MAKE@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = .. +subdir = rtems_servers + +RTEMS_ROOT = @RTEMS_ROOT@ +PROJECT_ROOT = @PROJECT_ROOT@ + +VPATH = @srcdir@ + +LIBNAME = lib.a +LIB = ${ARCH}/${LIBNAME} + +# C and C++ source names, if any, go here -- minus the .c or .cc +C_PIECES=asp balloc wbase64 default ejlex ejparse form h handler mime \ + misc webpage ringq rom security socket sym uemf url value webcomp \ + webrom webs websuemf webmain +C_FILES = $(C_PIECES:%=%.c) +C_O_FILES = $(C_PIECES:%=${ARCH}/%.o) + +SRCS = $(C_FILES) +OBJS = $(C_O_FILES) + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(RTEMS_ROOT)/make/lib.cfg + +INSTALL_CHANGE = @INSTALL_CHANGE@ + +# +# Add local stuff here using += +# + +DEFINES += -DWEBS -DUEMF -DOS="LINUX" -DLINUX +CPPFLAGS += +CFLAGS += + +# +# Add your list of files to delete here. The config files +# already know how to delete some stuff, so you may want +# to just run 'make clean' first to see what gets missed. +# 'make clobber' already includes 'make clean' +# + +CLEAN_ADDITIONS += $(LIB) +CLOBBER_ADDITIONS += + +all: ${ARCH} $(LIB) + +$(LIB): $(SRCS) ${OBJS} + $(make-library) + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status diff --git a/c/src/libnetworking/rtems_webserver/asp.c b/c/src/libnetworking/rtems_webserver/asp.c new file mode 100644 index 0000000000..4611a8f422 --- /dev/null +++ b/c/src/libnetworking/rtems_webserver/asp.c @@ -0,0 +1,313 @@ +/* + * asp.c -- Active Server Page Support + * + * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved. + * + * See the file "license.txt" for usage and redistribution license requirements + */ + +/******************************** Description *********************************/ + +/* + * The ASP module processes ASP pages and executes embedded scripts. It + * support an open scripting architecture with in-built support for + * Ejscript(TM). + */ + +/********************************* Includes ***********************************/ + +#include "wsIntrn.h" + +/********************************** Locals ************************************/ + +static sym_fd_t websAspFunctions = -1; /* Symbol table of functions */ + +/***************************** Forward Declarations ***************************/ + +static char_t *strtokcmp(char_t* s1, char_t* s2); +static char_t *skipWhite(char_t *s); + +/************************************* Code ***********************************/ +/* + * Create script spaces and commands + */ + +int websAspOpen() +{ +/* + * Create the table for ASP functions + */ + websAspFunctions = symOpen(128); + +/* + * Create standard ASP commands + */ + websAspDefine(T("write"), websAspWrite); + return 0; +} + +/************************************* Code ***********************************/ +/* + * Close Asp symbol table. + */ + +void websAspClose() +{ + if (websAspFunctions != -1) { + symClose(websAspFunctions, NULL); + } +} + +/******************************************************************************/ +/* + * Process ASP requests and expand all scripting commands. We read the + * entire ASP page into memory and then process. If you have really big + * documents, it is better to make them plain HTML files rather than ASPs. + */ + +int websAspRequest(webs_t wp, char_t* lpath) +{ + websStatType sbuf; + char *rbuf; + char_t *token, *lang, *result, *path, *ep, *cp, *buf, *nextp; + char_t *last; + int rc, engine, len, ejid; + + a_assert(websValid(wp)); + a_assert(lpath && *lpath); + + rc = -1; + buf = NULL; + rbuf = NULL; + engine = EMF_SCRIPT_EJSCRIPT; + wp->flags |= WEBS_HEADER_DONE; + path = websGetRequestPath(wp); + +/* + * Create Ejscript instance incase it is needed + */ + ejid = ejOpenEngine(wp->cgiVars, websAspFunctions); + if (ejid < 0) { + websError(wp, 200, T("Can't create Ejscript engine")); + goto done; + } + ejSetUserHandle(ejid, (int) wp); + + if (websPageStat(wp, lpath, path, &sbuf) < 0) { + websError(wp, 200, T("Can't stat %s"), lpath); + goto done; + } + +/* + * Create a buffer to hold the ASP file in-memory + */ + len = sbuf.size * sizeof(char); + if ((rbuf = balloc(B_L, len + 1)) == NULL) { + websError(wp, 200, T("Can't get memory")); + goto done; + } + rbuf[len] = '\0'; + + if (websPageReadData(wp, rbuf, len) != len) { + websError(wp, 200, T("Cant read %s"), lpath); + goto done; + } + websCloseFileHandle(wp); + +/* + * Convert to UNICODE if necessary. + */ + if ((buf = ballocAscToUni(rbuf)) == NULL) { + websError(wp, 200, T("Can't get memory")); + goto done; + } + +/* + * Scan for the next "<%" + */ + last = buf; + rc = 0; + while (rc == 0 && *last && ((nextp = gstrstr(last, T("<%"))) != NULL)) { + websWriteBlock(wp, last, (nextp - last)); + nextp = skipWhite(nextp + 2); + +/* + * Decode the language + */ + token = T("language"); + + if ((lang = strtokcmp(nextp, token)) != NULL) { + if ((cp = strtokcmp(lang, T("=javascript"))) != NULL) { + engine = EMF_SCRIPT_EJSCRIPT; + } else { + cp = nextp; + } + nextp = cp; + } + +/* + * Find tailing bracket and then evaluate the script + */ + if ((ep = gstrstr(nextp, T("%>"))) != NULL) { + + *ep = '\0'; + last = ep + 2; + nextp = skipWhite(nextp); +/* + * Handle backquoted newlines + */ + for (cp = nextp; *cp; ) { + if (*cp == '\\' && (cp[1] == '\r' || cp[1] == '\n')) { + *cp++ = ' '; + while (*cp == '\r' || *cp == '\n') { + *cp++ = ' '; + } + } else { + cp++; + } + } + +/* + * Now call the relevant script engine. Output is done directly + * by the ASP script procedure by calling websWrite() + */ + if (*nextp) { + result = NULL; + if (engine == EMF_SCRIPT_EJSCRIPT) { + rc = scriptEval(engine, nextp, &result, ejid); + } else { + rc = scriptEval(engine, nextp, &result, (int) wp); + } + if (rc < 0) { +/* + * On an error, discard all output accumulated so far + * and store the error in the result buffer. Be careful if the + * user has called websError() already. + */ + if (websValid(wp)) { + if (result) { + websWrite(wp, T("
%s"), nextp); + bfree(B_L, result); + } else { + websWrite(wp, T("