From 5e3100c03c68fd3192bbcef8de7c3b9488b4d3c3 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 24 Jan 1997 13:13:10 +0000 Subject: [PATCH] Implemnted egw_source and added a "raw" option to the URL. Fixed a bug in the buffering system of wproto; the macro wo_putc could override memory if it was the first HTML generating function called. --- www/Makefile | 32 +++++++++++++++++++------------- www/wcgi.c | 7 ++++++- www/wproto.c | 17 +++++++++++------ www/wproto.h | 12 ++++++++++++ www/wshmain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- www/wtcl.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 151 insertions(+), 28 deletions(-) diff --git a/www/Makefile b/www/Makefile index bc47ff9..b1285ea 100644 --- a/www/Makefile +++ b/www/Makefile @@ -1,7 +1,7 @@ # Makefile for www gateway utility # Europagate, 1995 # -# $Id: Makefile,v 1.41 1996/06/06 11:10:10 adam Exp $ +# $Id: Makefile,v 1.42 1997/01/24 13:13:10 adam Exp $ # SHELL=/bin/sh @@ -16,7 +16,7 @@ IRTCLINC=-I$(IRTCLDIR) #ELIB=-lnsl -lsocket OLIB=../lib/util.a ../lib/libres+log.a -TCLLIB=/usr/local/lib/libtcl7.5.a +TCLLIB=-L/usr/local/lib -ltcl8.0 -lm TCLINC= HSCRIPTS=egwindex.html @@ -31,18 +31,13 @@ P3=wproto.o wtest.o P4=wproto.o winterp.o waissh.o wtcl.o wirtcl.o wshmain.o wwaistcl.o CPP=$(CC) -E +EGWUSER=nobody HTTPDDIR=/usr/local/etc/httpd CGIDIR=$(HTTPDDIR)/cgi-bin HTDOCS=$(HTTPDDIR)/htdocs EGWDIR=$(HTTPDDIR)/egw GIFDIR=$(HTDOCS)/egwgif -#HTTPDDIR=/usr/local/www -#CGIDIR=/usr/local/www/cgi-bin -#HTDOCS=/data2/html/egw/html -#EGWDIR=/data2/html/egw/scripts -#GIFDIR=/data2/html/egw/gif - INCLUDE=-I../include $(ZINC) $(TCLINC) $(IRTCLINC) DEFS=$(INCLUDE) $(ZDEFS) -DEGWDIR=\"$(EGWDIR)\" @@ -78,24 +73,30 @@ install.prog: echo "Making directory $(EGWDIR)"; \ mkdir $(EGWDIR); \ fi + @chown $(EGWUSER) $(EGWDIR) @for x in $(TPROG1); do \ echo Installing $$x; \ cp $$x $(CGIDIR); \ - chmod a+x $(CGIDIR)/$$x; \ + chown $(EGWUSER) $(CGIDIR)/$$x; \ + chmod +x $(CGIDIR)/$$x; \ + chmod u+s $(CGIDIR)/$$x; \ done; \ for x in $(TPROG2); do \ echo Installing $$x; \ - cp $$x $(EGWDIR); \ - chmod a+x $(EGWDIR)/$$x; \ + cp $$x $(EGWDIR)/$$x; \ + chown $(EGWUSER) $(EGWDIR)/$$x; \ + chmod +x $(EGWDIR)/$$x; \ done; \ for p in egwtcl egwirtcl egwhtml; do \ rm -f $(EGWDIR)/$$p; \ ln $(EGWDIR)/$(TPROG2) $(EGWDIR)/$$p; \ + chown $(EGWUSER) $(EGWDIR)/$$p; \ done @if [ -x $(TPROG4) ]; then \ echo Installing $(TPROG4); \ cp $(TPROG4) $(EGWDIR)/$(TPROG4); \ - chmod a+x $(EGWDIR)/$(TPROG4); \ + chmod +x $(EGWDIR)/$(TPROG4); \ + chown $(EGWUSER) $(EGWDIR)/$(TPROG4); \ fi install.script: @@ -110,24 +111,29 @@ install.script: @for x in *.egw *.tcl; do \ echo Installing $$x; \ cp $$x $(EGWDIR)/$$x; \ + chown $(EGWUSER) $(EGWDIR)/$$x; \ done @for x in $(HSCRIPTS); do \ echo Installing $$x; \ cp $$x $(HTDOCS); \ + chmod a+r $(HTDOCS)/$$x; \ done @for x in $(CONFFILES); do \ echo Installing $$x; \ cp $$x $(EGWDIR); \ + chown $(EGWUSER) $(EGWDIR)/$$x; \ done install.gif: @if [ ! -d $(GIFDIR) ]; then \ echo "Making directory $(GIFDIR)"; \ mkdir $(GIFDIR); \ + chmod a+x $(GIFDIR); \ fi - @for x in gif/*.gif; do \ + @cd gif; for x in *.gif; do \ echo Installing $$x; \ cp $$x $(GIFDIR); \ + chmod a+r $(GIFDIR)/$$x; \ done .c.o: diff --git a/www/wcgi.c b/www/wcgi.c index 6a43239..a16fc6f 100644 --- a/www/wcgi.c +++ b/www/wcgi.c @@ -41,6 +41,11 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wcgi.c,v $ + * Revision 1.19 1997/01/24 13:13:10 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * * Revision 1.18 1996/03/14 11:48:37 adam * New function egw_prog that returns name of shell. * @@ -204,7 +209,7 @@ int main() int linein = -1, lineout, data, gw_id; if (chdir (EGWDIR)) - fatal ("Couldn't change directory to " EGWDIR); + fatal ("egwcgi: Couldn't change directory to " EGWDIR); gw_log_init ("egw"); gw_log_file (GW_LOG_ALL, "egwcgi_log"); #if 0 diff --git a/www/wproto.c b/www/wproto.c index 5d3fc37..62448aa 100644 --- a/www/wproto.c +++ b/www/wproto.c @@ -41,6 +41,11 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.c,v $ + * Revision 1.22 1997/01/24 13:13:11 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * * Revision 1.21 1996/05/23 15:53:11 adam * Bug fix: egw_enc failed on 8-bit chars. * New command: egw_parms. @@ -137,6 +142,7 @@ #include #include #include +#include #include "wproto.h" @@ -150,12 +156,9 @@ void wo_write (WCLIENT wc, const char *s, size_t len) { if (wc->outbuffer_offset + len >= wc->outbuffer_size) { - if (!wc->outbuffer) - wc->outbuffer = malloc (wc->outbuffer_size += - ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK)); - else - wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size += - ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK)); + assert (wc->outbuffer); + wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size += + ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK)); } memcpy(wc->outbuffer + wc->outbuffer_offset, s, len); wc->outbuffer_offset += len; @@ -179,6 +182,8 @@ void wo_printf (WCLIENT wc, const char *fmt, ...) void wo_clear (WCLIENT wc, const char *type) { + if (!wc->outbuffer) + wc->outbuffer = malloc (wc->outbuffer_size = OUTBUFFER_CHUNK); wc->outbuffer_offset = 0; if (type) wo_printf(wc, "Content-type: %s\n\n", type); diff --git a/www/wproto.h b/www/wproto.h index c483671..988fa8f 100644 --- a/www/wproto.h +++ b/www/wproto.h @@ -41,6 +41,11 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.h,v $ + * Revision 1.12 1997/01/24 13:13:12 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * * Revision 1.11 1996/05/23 15:53:11 adam * Bug fix: egw_enc failed on 8-bit chars. * New command: egw_parms. @@ -144,8 +149,15 @@ typedef struct wclient_data (*((wc)->outbuffer + (wc)->outbuffer_offset++) = (char) (ch)), 0) char *wgetval (WCLIENT wc, char *name); + +/* wproto_process: wait for one request from egwcgi. returns <=0 on + timeout; returns >0 otherwise. */ int wproto_process (WCLIENT wc, int timeout); + +/* wproto_init: initializes communication with egwcgi. */ WCLIENT wproto_init (const char *fifoDir, const char *prog); + + void wo_printf (WCLIENT wc, const char *fmt, ...); void wo_clear (WCLIENT wc, const char *type); int wo_finish (WCLIENT wc); diff --git a/www/wshmain.c b/www/wshmain.c index 74d96ee..ea6edfe 100644 --- a/www/wshmain.c +++ b/www/wshmain.c @@ -41,6 +41,11 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wshmain.c,v $ + * Revision 1.5 1997/01/24 13:13:12 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * * Revision 1.4 1996/05/23 15:53:12 adam * Bug fix: egw_enc failed on 8-bit chars. * New command: egw_parms. @@ -120,6 +125,7 @@ void wshmain (int argc, char **argv, W_Interp_Type w_interp_type) { char *p; int r; + int raw_mode = 0; r = wproto_process (wcl, timeout); if (r <= 0) @@ -142,13 +148,13 @@ void wshmain (int argc, char **argv, W_Interp_Type w_interp_type) if (*script) { +#if 0 p = script + strlen(script); while (*--p && p != script) switch (*p) { case '+': wproto_cache (wcl, wcl->cache_level+1); - *p = '\0'; break; case '-': if (p[1]) @@ -168,8 +174,53 @@ void wshmain (int argc, char **argv, W_Interp_Type w_interp_type) *p = '\0'; break; } +#else + p = script; + while (*p) + { + if (*p == ';') /* ";" or ";" */ + { + wo_printf (wcl, "Expires: %s\n", p[1] ? p+1 : "0"); + gw_log (GW_LOG_DEBUG, mod, "Expires: %s", p[1] ?p+1:"0"); + *p = '\0'; + break; + } + else if (*p == '+') /* "+=" or "+" */ + { + const char *name1 = NULL; + const char *name2 = NULL; + const char *value1 = NULL; + const char *value2 = NULL; + int len; + *p = '\0'; + name1 = ++p; + while (*p && *p != ';' && *p != '+') + { + if (*p == '=') + { + name2 = p++; + value1 = p; + while (*p && *p != ';' && *p != '+') + p++; + value2 = p; + break; + } + p++; + } + if (!name2) + name2 = p; + len = name2 - name1; + if (len == 3 && !memcmp (name1, "raw", len)) + raw_mode = 1; + } + else + p++; + } + *p = '\0'; +#endif } - wo_printf (wcl, "Content-type: text/html\n\n"); + if (!raw_mode) + wo_printf (wcl, "Content-type: text/html\n\n"); for (p = parms; *p; p++) if (*p == '+') *p = ' '; @@ -177,6 +228,8 @@ void wshmain (int argc, char **argv, W_Interp_Type w_interp_type) gw_log (GW_LOG_STAT, mod, "parms: %s", parms); if (w_interp_exec (w_interp, script, parms)) { + if (raw_mode) + wo_printf (wcl, "Content-type: text/html\n\n"); wo_printf (wcl, "wsh error\n"); wo_printf (wcl, "Couldn't execute script %s", script); diff --git a/www/wtcl.c b/www/wtcl.c index fea3bfd..a3fa1f6 100644 --- a/www/wtcl.c +++ b/www/wtcl.c @@ -41,6 +41,11 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wtcl.c,v $ + * Revision 1.18 1997/01/24 13:13:13 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * * Revision 1.17 1996/05/31 08:02:56 adam * Bug fix: egw_enc encoded '/' - it shouldn't. * @@ -138,6 +143,8 @@ struct tcl_info { WCLIENT wcl; }; +static int exec_file (const char *fname, struct tcl_info *p); + Tcl_Interp *w_interp_tcl_get (W_Interp w_interp) { struct tcl_info *p; @@ -369,6 +376,35 @@ static int proc_prog (ClientData clientData, Tcl_Interp *interp, return TCL_OK; } +static int proc_source (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + struct tcl_info *p = (struct tcl_info*) clientData; + int r; + + if (argc != 2) + { + Tcl_AppendResult (p->interp, + "wrong # args: should be egw_source file", NULL); + return TCL_ERROR; + } + r = exec_file (argv[1], p); + if (r == -2) + { + Tcl_AppendResult (p->interp, "egw_source: couldn't source ", + argv[1], NULL); + return TCL_ERROR; + } + else if (r == -1) + { + Tcl_AppendResult (p->interp, "egw_source: Tcl error in script ", + argv[1], NULL); + return TCL_ERROR; + } + return TCL_OK; +} + + int Tcl_AppInit (Tcl_Interp *interp) { if (Tcl_Init (interp) == TCL_ERROR) @@ -408,6 +444,7 @@ static void *do_create (WCLIENT wcl, void *args) Tcl_CreateCommand (p->interp, "egw_enc", proc_enc, p, NULL); Tcl_CreateCommand (p->interp, "egw_dec", proc_dec, p, NULL); Tcl_CreateCommand (p->interp, "egw_prog", proc_prog, p, NULL); + Tcl_CreateCommand (p->interp, "egw_source", proc_source, p, NULL); sprintf (tmp_str, "%d", wcl->id); Tcl_SetVar (p->interp, "sessionId", tmp_str, TCL_GLOBAL_ONLY); return p; @@ -424,8 +461,8 @@ static void report_error (struct tcl_info *p, int errorLine, wo_printf (p->wcl, "\n%s\n
\n", msg); } -static int tcl_exec (const char *fname, char *parms, - struct tcl_info *p, FILE *inf, int *lineno) +static int tcl_exec (const char *fname, struct tcl_info *p, FILE *inf, + int *lineno) { int c, escape = 0, level = 0; int r, fbuf_ptr = 0; @@ -487,9 +524,8 @@ static int tcl_exec (const char *fname, char *parms, return r; } -static int do_exec (const char *fname, char *parms, void *mydata) +static int exec_file (const char *fname, struct tcl_info *p) { - struct tcl_info *p = mydata; int c, escape = 0; int lineno = 1; FILE *inf = fopen (fname, "r"); @@ -500,7 +536,6 @@ static int do_exec (const char *fname, char *parms, void *mydata) gw_log (GW_LOG_WARN|GW_LOG_ERRNO, mod, "open %s", fname); return -1; } - Tcl_SetVar (p->interp, "sessionParms", parms, TCL_GLOBAL_ONLY); while ((c = getc(inf)) != EOF) { if (c == '\\') @@ -511,7 +546,7 @@ static int do_exec (const char *fname, char *parms, void *mydata) wo_putc (p->wcl, c); else { - int r = tcl_exec (fname, parms, p, inf, &lineno); + int r = tcl_exec (fname, p, inf, &lineno); if (r == TCL_RETURN) { fclose (inf); @@ -537,6 +572,13 @@ static int do_exec (const char *fname, char *parms, void *mydata) return 0; } +static int do_exec (const char *fname, char *parms, void *mydata) +{ + struct tcl_info *p = mydata; + + Tcl_SetVar (p->interp, "sessionParms", parms, TCL_GLOBAL_ONLY); + return exec_file (fname, p); +} static int do_load (char *parms, void *mydata) { -- 1.7.10.4