# 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
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
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); \
<title>Europagate WWW index</title>
</head>
<body>
-<h2>Europagate WWW index, $Id: egwindex.html,v 1.1 1995/10/20 14:02:41 adam Exp $</h2>
+<h2>Europagate WWW index, $Id: egwindex.html,v 1.2 1995/10/23 16:55:35 adam Exp $</h2>
<p>
-egwcgi ref: <a href="http://localhost/cgi-bin/egwcgi/egwsh/egwscript">egwcgi</a>
+egwcgi ref:
+ <a href="http://localhost/cgi-bin/egwcgi/egwtcl/egwscript">egwcgi</a>
+<p>
+z39 targets:
+ <a href="http://localhost/cgi-bin/egwcgi/egwtcl/targets">targets</a>
</body>
</html>
<html>
-<head><title>Europgate WWW gateway test script $Id: egwscript,v 1.1 1995/10/20 14:02:41 adam Exp $</title></head>
+<head><title>Europgate WWW gateway test script $Id: egwscript,v 1.2 1995/10/23 16:55:35 adam Exp $</title></head>
<body>
-howdi
+Test script with embedded Tcl. <p>
{
- set f [open mylog a+]
- puts $f "Hello world"
- close $f
+ if {[catch {incr count}]} {
+ set count 1
+ }
}
+session Id: {html $sessionId}<br>
+session Parms: {html $sessionParms}<br>
+Click
+<a href="http:/cgi-bin/egwcgi/{html $sessionId}/egwscript/{html $count}">
+here</a> to go to this page again. <br>
+Number of times this page has been referenced: {html $count} <p>
</body>
</html>
* 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.
*
*/
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);
* 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.
*
*/
#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",
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);
return -1;
}
while ((c = getc (inf)) != EOF)
- wo_putc (wcl, c);
+ wo_putc (p->wcl, c);
fclose (inf);
return 0;
}
* 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.
*
*/
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);
exit (1);
}
p->ctrl = type;
- p->mydata = (*p->ctrl->create)(args);
+ p->mydata = (*p->ctrl->create)(wcl, args);
return p;
}
* 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.
*
*/
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 {
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;
* 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.
*
*/
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);
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)
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 */
}
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);
* 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.
*
*/
typedef struct wclient_data
{
+ int id;
wform_data wf_data[100];
char wf_parms[512];
char wf_serverp[512];
* 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
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, "<html><head><title>wsh error</title></head>\n");
wo_printf (wcl, "<body>Couldn't execute script %s</body></html>",
* 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.
*
*/
#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",
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; i<argc; i++)
+ wo_puts (p->wcl, 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))))
{
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)
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)
{
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;
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;
if (c == '\n')
lineno++;
escape = 0;
- wo_putc (wcl, c);
+ wo_putc (p->wcl, c);
}
}
fclose (inf);