From 5414eafed41a60ef3625cfc6770184b36016186e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 23 Oct 1995 16:55:33 +0000 Subject: [PATCH] A lot of changes - really. --- www/Makefile | 11 +++++--- www/egwindex.html | 8 ++++-- www/egwscript | 16 ++++++++---- www/wcgi.c | 6 ++++- www/whtml.c | 31 +++++++++++++++++----- www/winterp.c | 9 ++++--- www/winterp.h | 13 ++++++---- www/wproto.c | 14 ++++++---- www/wproto.h | 6 ++++- www/wsh.c | 72 ++++++++++++++++++++++++++++++++++++++------------ www/wtcl.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-------- 11 files changed, 201 insertions(+), 60 deletions(-) diff --git a/www/Makefile b/www/Makefile index 4420d24..5f12e0f 100644 --- a/www/Makefile +++ b/www/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.2 1995/10/20 14:02:40 adam +# Revision 1.3 1995/10/23 16:55:33 adam +# A lot of changes - really. +# +# Revision 1.2 1995/10/20 14:02:40 adam # First version of WWW gateway with embedded Tcl. # # Revision 1.1 1995/10/20 11:49:24 adam @@ -12,7 +15,7 @@ SHELL=/bin/sh INCLUDE=-I../include #CFLAGS=-g -Wall -pedantic -ansi OLIB=../lib/libres+log.a -TCLLIB=/usr/local/lib/libtcl7.5.a +TCLLIB=/usr/local/lib/libtcl7.4.a WSCRIPTS=egwscript HSCRIPTS=egwindex.html TPROG1=egwcgi @@ -44,7 +47,9 @@ install: $(TPROG1) $(TPROG2) echo Installing $$x; \ cp $$x $(CGIBIN); \ chmod +x $(CGIBIN)/$$x; \ - done + done; \ + ln -f $(CGIBIN)/$(TPROG2) $(CGIBIN)/egwtcl; \ + ln -f $(CGIBIN)/$(TPROG2) $(CGIBIN)/egwhtml @for x in $(WSCRIPTS); do \ echo Installing $$x; \ cp $$x $(CGIBIN); \ diff --git a/www/egwindex.html b/www/egwindex.html index b7b1d17..a0752d9 100644 --- a/www/egwindex.html +++ b/www/egwindex.html @@ -3,9 +3,13 @@ Europagate WWW index -

Europagate WWW index, $Id: egwindex.html,v 1.1 1995/10/20 14:02:41 adam Exp $

+

Europagate WWW index, $Id: egwindex.html,v 1.2 1995/10/23 16:55:35 adam Exp $

-egwcgi ref: egwcgi +egwcgi ref: + egwcgi +

+z39 targets: + targets diff --git a/www/egwscript b/www/egwscript index 94303b7..4a192ee 100644 --- a/www/egwscript +++ b/www/egwscript @@ -1,11 +1,17 @@ -Europgate WWW gateway test script $Id: egwscript,v 1.1 1995/10/20 14:02:41 adam Exp $ +Europgate WWW gateway test script $Id: egwscript,v 1.2 1995/10/23 16:55:35 adam Exp $ -howdi +Test script with embedded Tcl.

{ - set f [open mylog a+] - puts $f "Hello world" - close $f + if {[catch {incr count}]} { + set count 1 + } } +session Id: {html $sessionId}
+session Parms: {html $sessionParms}
+Click + +here to go to this page again.
+Number of times this page has been referenced: {html $count}

diff --git a/www/wcgi.c b/www/wcgi.c index 3fb3cec..4ab8aa0 100644 --- a/www/wcgi.c +++ b/www/wcgi.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wcgi.c,v $ - * Revision 1.1 1995/10/20 11:49:25 adam + * Revision 1.2 1995/10/23 16:55:36 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 11:49:25 adam * First version of www gateway. * */ @@ -87,6 +90,7 @@ static int spawn(char *sprog) case 0: close (0); close (1); + gw_log (GW_LOG_DEBUG, prog, "execl %s", path); execl (path, sprog, 0); gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "execl %s", path); exit(0); diff --git a/www/whtml.c b/www/whtml.c index 3c1e080..e111ee5 100644 --- a/www/whtml.c +++ b/www/whtml.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: whtml.c,v $ - * Revision 1.1 1995/10/20 14:02:41 adam + * Revision 1.2 1995/10/23 16:55:37 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 14:02:41 adam * First version of WWW gateway with embedded Tcl. * */ @@ -55,8 +58,8 @@ #include "wproto.h" #include "winterp.h" -static void *do_create (void *args); -static int do_exec (WCLIENT wcl, const char *fname, char *parms, void *mydata); +static void *do_create (WCLIENT wcl, void *args); +static int do_exec (const char *fname, char *parms, void *mydata); static struct w_interp_type w_interp_t = { "html", @@ -68,14 +71,28 @@ W_Interp_Type w_interp_html = &w_interp_t; static char *mod = "whtml"; -static void *do_create (void *args) +struct html_info { + WCLIENT wcl; +}; + +static void *do_create (WCLIENT wcl, void *args) { - return NULL; + struct html_info *p; + + p = malloc (sizeof(*p)); + if (!p) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "malloc: html_info"); + exit (1); + } + p->wcl = wcl; + return p; } -static int do_exec (WCLIENT wcl, const char *fname, char *parms, void *mydata) +static int do_exec (const char *fname, char *parms, void *mydata) { int c; + struct html_info *p = mydata; FILE *inf = fopen (fname, "r"); gw_log (GW_LOG_DEBUG, mod, "executing %s", fname); @@ -85,7 +102,7 @@ static int do_exec (WCLIENT wcl, const char *fname, char *parms, void *mydata) return -1; } while ((c = getc (inf)) != EOF) - wo_putc (wcl, c); + wo_putc (p->wcl, c); fclose (inf); return 0; } diff --git a/www/winterp.c b/www/winterp.c index 61b0388..c2a7faf 100644 --- a/www/winterp.c +++ b/www/winterp.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: winterp.c,v $ - * Revision 1.1 1995/10/20 14:02:41 adam + * Revision 1.2 1995/10/23 16:55:38 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 14:02:41 adam * First version of WWW gateway with embedded Tcl. * */ @@ -53,7 +56,7 @@ static char *mod = "winterp"; -W_Interp w_interp_create (W_Interp_Type type, void *args) +W_Interp w_interp_create (W_Interp_Type type, WCLIENT wcl, void *args) { W_Interp p = malloc (sizeof(*p)); gw_log (GW_LOG_DEBUG, mod, "Creating w_interp: %s", type->name); @@ -63,6 +66,6 @@ W_Interp w_interp_create (W_Interp_Type type, void *args) exit (1); } p->ctrl = type; - p->mydata = (*p->ctrl->create)(args); + p->mydata = (*p->ctrl->create)(wcl, args); return p; } diff --git a/www/winterp.h b/www/winterp.h index 272446d..fec5d39 100644 --- a/www/winterp.h +++ b/www/winterp.h @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: winterp.h,v $ - * Revision 1.1 1995/10/20 14:02:42 adam + * Revision 1.2 1995/10/23 16:55:39 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 14:02:42 adam * First version of WWW gateway with embedded Tcl. * */ @@ -53,8 +56,8 @@ typedef struct w_interp_type { char *name; - void *(*create)(void *args); - int (*exec)(WCLIENT wcl, const char *fname, char *parms, void *private); + void *(*create)(WCLIENT wcl, void *args); + int (*exec)(const char *fname, char *parms, void *private); } *W_Interp_Type; typedef struct w_interp { @@ -62,8 +65,8 @@ typedef struct w_interp { W_Interp_Type ctrl; } *W_Interp; -W_Interp w_interp_create (W_Interp_Type type, void *args); -#define w_interp_exec(w,c,f,p) (*(w)->ctrl->exec)((c),(f),(p), (w)->mydata) +W_Interp w_interp_create (W_Interp_Type type, WCLIENT wcl, void *args); +#define w_interp_exec(w,f,p) (*(w)->ctrl->exec)((f),(p), (w)->mydata) #define w_interp_name(w) ((w)->ctrl.name) W_Interp_Type w_interp_tcl; diff --git a/www/wproto.c b/www/wproto.c index 6bc7cb0..1a41b72 100644 --- a/www/wproto.c +++ b/www/wproto.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.c,v $ - * Revision 1.1 1995/10/20 11:49:26 adam + * Revision 1.2 1995/10/23 16:55:39 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 11:49:26 adam * First version of www gateway. * */ @@ -305,7 +308,8 @@ WCLIENT wproto_init(void) gw_log (GW_LOG_DEBUG, mod, "wproto_init"); close(1); /* release us from the wserver */ new = malloc(sizeof(*new)); - sprintf(new->path, "%s/%s/clt%d", FIFOROOT, FIFODIR, getpid()); + new->id = getpid(); + sprintf(new->path, "%s/%s/clt%d", FIFOROOT, FIFODIR, new->id); if (mkfifo(new->path, 0666 | S_IFIFO) < 0) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "mkfifo(%s)", new->path); @@ -315,7 +319,7 @@ WCLIENT wproto_init(void) sprintf(path2, "%s/%s/srv%d", FIFOROOT, FIFODIR, getppid()); if ((new->lineout = open(path2, O_WRONLY)) < 0) { - gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "open %s", path2); + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "open out %s", path2); exit(1); } if (write(new->lineout, "OK", 2) < 2) @@ -326,7 +330,7 @@ WCLIENT wproto_init(void) gw_log (GW_LOG_DEBUG, mod, "Synchronized."); if ((new->linein = open(new->path, O_RDONLY)) < 0) { - gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "open input handle %s", new->path); + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "open input %s", new->path); exit(1); } /* we put a handle on this so we get a blocking read when no peer */ @@ -366,7 +370,7 @@ int wproto_cache(WCLIENT wc, int level) } wproto_uncache(wc, level); p = &wc->cache[++wc->cache_level]; - sprintf(p->path, "%s/%s/csh%d.%d", FIFOROOT, FIFODIR, getpid(), level); + sprintf(p->path, "%s/%s/csh%d.%d", FIFOROOT, FIFODIR, wc->id, level); if ((wc->cache_fd = open(p->path, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "open %s", p->path); diff --git a/www/wproto.h b/www/wproto.h index fef0d48..266a713 100644 --- a/www/wproto.h +++ b/www/wproto.h @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.h,v $ - * Revision 1.1 1995/10/20 11:49:27 adam + * Revision 1.2 1995/10/23 16:55:41 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 11:49:27 adam * First version of www gateway. * */ @@ -72,6 +75,7 @@ typedef struct cache_data typedef struct wclient_data { + int id; wform_data wf_data[100]; char wf_parms[512]; char wf_serverp[512]; diff --git a/www/wsh.c b/www/wsh.c index 4bd4257..990d141 100644 --- a/www/wsh.c +++ b/www/wsh.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wsh.c,v $ - * Revision 1.2 1995/10/20 14:02:42 adam + * Revision 1.3 1995/10/23 16:55:41 adam + * A lot of changes - really. + * + * Revision 1.2 1995/10/20 14:02:42 adam * First version of WWW gateway with embedded Tcl. * * Revision 1.1 1995/10/20 11:49:28 adam @@ -67,35 +70,70 @@ static char *mod = "wsh"; int main (int argc, char **argv) { - char *script, *p, parms[512]; + char *script, *parms, parms_buf[512]; int timeout = TIMEOUT_SHORT; - W_Interp tcl_interp, html_interp; + W_Interp w_interp; chdir("/usr/local/etc/httpd/cgi-bin"); - gw_log_init ("egw"); + gw_log_init (*argv); gw_log_file (GW_LOG_ALL, "/usr/local/etc/httpd/logs/egwsh_log"); gw_log_level (GW_LOG_ALL); - gw_log (GW_LOG_STAT, mod, "Europagate www shell"); - + gw_log (GW_LOG_STAT, mod, "Europagate www shell: %s", *argv); + if (!(wcl = wproto_init())) { gw_log (GW_LOG_FATAL, mod, "init"); exit(1); } - tcl_interp = w_interp_create (w_interp_tcl, NULL); - html_interp = w_interp_create (w_interp_html, NULL); + gw_log_session (wcl->id); + if (!strcmp (*argv, "egwtcl")) + w_interp = w_interp_create (w_interp_tcl, wcl, NULL); + else if (!strcmp (*argv, "egwhtml")) + w_interp = w_interp_create (w_interp_html, wcl, NULL); + else + { + gw_log (GW_LOG_FATAL, mod, "Cannot determine shell type. prog=%s", + *argv); + exit (1); + } while (wproto_process(wcl, timeout) > 0) { - wo_clear(wcl, "text/html"); - strcpy(parms, wcl->wf_parms); - script = p = parms; - while (*p && *p != '/') - p++; - if (*p == '/') - *(p++) = '\0'; + wo_clear (wcl, "text/html"); + strcpy (parms_buf, wcl->wf_parms); + script = parms = parms_buf; + while (*parms && *parms != '/') + parms++; + if (*parms == '/') + *parms++ = '\0'; + if (*script) + { + char *p = script + strlen(script) - 1; + while (*p && p != script) + switch (*p) + { + case '+': + wproto_cache (wcl, wcl->cache_level+1); + *p = '\0'; + break; + case '-': + if (p[1]) + wproto_cache (wcl, wcl->cache_level-atoi(p+1)); + else + wproto_cache (wcl, wcl->cache_level-1); + *p = '\0'; + break; + case '=': + if (isdigit(p[1])) + wproto_cache (wcl, atoi(p+1)); + *p = '\0'; + break; + default: + --p; + } + } gw_log (GW_LOG_DEBUG, mod, "script: %s", script); - gw_log (GW_LOG_DEBUG, mod, "parms: %s", p); - if (w_interp_exec (tcl_interp, wcl, script, p)) + gw_log (GW_LOG_DEBUG, mod, "parms: %s", parms); + if (w_interp_exec (w_interp, script, parms)) { wo_printf (wcl, "wsh error\n"); wo_printf (wcl, "Couldn't execute script %s", diff --git a/www/wtcl.c b/www/wtcl.c index ebdabb5..59fda21 100644 --- a/www/wtcl.c +++ b/www/wtcl.c @@ -41,7 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wtcl.c,v $ - * Revision 1.1 1995/10/20 14:02:42 adam + * Revision 1.2 1995/10/23 16:55:43 adam + * A lot of changes - really. + * + * Revision 1.1 1995/10/20 14:02:42 adam * First version of WWW gateway with embedded Tcl. * */ @@ -57,8 +60,8 @@ #include "wproto.h" #include "winterp.h" -static void *do_create (void *args); -static int do_exec (WCLIENT wcl, const char *fname, char *parms, void *mydata); +static void *do_create (WCLIENT wcl, void *args); +static int do_exec (const char *fname, char *parms, void *mydata); static struct w_interp_type w_interp_t = { "tcl", @@ -76,11 +79,56 @@ struct tcl_info { char *fbuf; int fbuf_size; int fbuf_ptr; + WCLIENT wcl; }; -static void *do_create (void *args) +static int proc_html_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + struct tcl_info *p = (struct tcl_info*) clientData; + int i; + + gw_log (GW_LOG_DEBUG, mod, "proc html"); + for (i = 1; iwcl, argv[i]); + return TCL_OK; +} + +static int proc_htmlr_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + struct tcl_info *p = (struct tcl_info*) clientData; + int r; + + r = proc_html_invoke (clientData, interp, argc, argv); + wo_putc (p->wcl, '\n'); + return r; +} + +static int proc_form_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + struct tcl_info *p = (struct tcl_info*) clientData; + int i; + if (argc == 2) + { + Tcl_AppendResult (p->interp, wgetval (p->wcl, argv[1]), NULL); + return TCL_OK; + } + for (i = 0; *p->wcl->wf_data[i].name; i++) + { + Tcl_AppendResult (p->interp, "{ ", NULL); + Tcl_AppendElement (p->interp, p->wcl->wf_data[i].name); + Tcl_AppendElement (p->interp, p->wcl->wf_data[i].value); + Tcl_AppendResult (p->interp, " }\n", NULL); + } + return TCL_OK; +} + +static void *do_create (WCLIENT wcl, void *args) { struct tcl_info *p; + char tmp_str[256]; if (!(p = malloc (sizeof(*p)))) { @@ -92,23 +140,29 @@ static void *do_create (void *args) gw_log (GW_LOG_FATAL, mod, "Cannot make Tcl_Interp"); exit (1); } + p->wcl = wcl; p->fbuf_size = 1024; if (!(p->fbuf = malloc (p->fbuf_size))) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "malloc: tcl_info fbuf"); exit (1); } + Tcl_CreateCommand (p->interp, "html", proc_html_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "htmlr", proc_htmlr_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "form", proc_form_invoke, p, NULL); + sprintf (tmp_str, "%d", wcl->id); + Tcl_SetVar (p->interp, "sessionId", tmp_str, TCL_GLOBAL_ONLY); return p; } -static int tcl_exec (WCLIENT wcl, const char *fname, char *parms, +static int tcl_exec (const char *fname, char *parms, struct tcl_info *p, FILE *inf, int *lineno) { int c, escape = 0, level = 0; int r, fbuf_ptr = 0; int local_line = 0; - gw_log (GW_LOG_DEBUG, mod, "tcl_exec. line %d", *lineno); + Tcl_SetVar (p->interp, "sessionParms", p->wcl->wf_parms, TCL_GLOBAL_ONLY); while (1) { if (fbuf_ptr == p->fbuf_size-1) @@ -152,7 +206,6 @@ static int tcl_exec (WCLIENT wcl, const char *fname, char *parms, p->fbuf[fbuf_ptr++] = c; } p->fbuf[fbuf_ptr] = '\0'; - gw_log (GW_LOG_DEBUG, mod, "Tcl_Eval. %d lines", local_line); r = Tcl_Eval (p->interp, p->fbuf); if (r != TCL_OK) { @@ -163,7 +216,7 @@ static int tcl_exec (WCLIENT wcl, const char *fname, char *parms, return 0; } -static int do_exec (WCLIENT wcl, const char *fname, char *parms, +static int do_exec (const char *fname, char *parms, void *mydata) { struct tcl_info *p = mydata; @@ -184,10 +237,10 @@ static int do_exec (WCLIENT wcl, const char *fname, char *parms, else if (c == '{') { if (escape) - wo_putc (wcl, c); + wo_putc (p->wcl, c); else { - if (tcl_exec (wcl, fname, parms, p, inf, &lineno)) + if (tcl_exec (fname, parms, p, inf, &lineno)) { fclose (inf); return -2; @@ -200,7 +253,7 @@ static int do_exec (WCLIENT wcl, const char *fname, char *parms, if (c == '\n') lineno++; escape = 0; - wo_putc (wcl, c); + wo_putc (p->wcl, c); } } fclose (inf); -- 1.7.10.4