Main shell loop implemented as a separate function called wshmain.
[egate.git] / www / wsh.c
index dc9a251..9ee4a14 100644 (file)
--- a/www/wsh.c
+++ b/www/wsh.c
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wsh.c,v $
- * Revision 1.9  1996/01/09 10:46:51  adam
+ * Revision 1.13  1996/02/29 15:36:34  adam
+ * Main shell loop implemented as a separate function called wshmain.
+ *
+ * Revision 1.12  1996/02/19  15:45:00  adam
+ * Sort of targets in multiple-targets selection.
+ *
+ * Revision 1.11  1996/02/12  10:10:32  adam
+ * Resource/config system used by the gateway.
+ *
+ * Revision 1.10  1996/01/12  10:05:22  adam
+ * If script name ends with ';' HTTP/GET/Expires will be defined.
+ * The cgi interface only reads final handshake if response from
+ * server (shell) was zero-terminated [If it isn't it probably died].
+ *
+ * Revision 1.9  1996/01/09  10:46:51  adam
  * New defines: LOGDIR/EGWDIR/CGIDIR set in Makefile.
  *
  * Revision 1.8  1995/12/20  16:31:33  adam
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include <gw-db.h>
 #include "whtml.h"
 #include "wtcl.h"
 #include "wirtcl.h"
 
-#define TIMEOUT 60
-
-static WCLIENT wcl;
-static char *mod = "wsh";
-
 int main (int argc, char **argv)
 {
-    char *script, *parms, parms_buf[512];
-    int timeout;
-    W_Interp w_interp;
-    GW_DB gw_db;
+    W_Interp_Type w_interp_type;
 
-    chdir (EGWDIR);
-    gw_log_init (*argv);
-    gw_log_file (GW_LOG_ALL, LOGDIR "/egwsh_log");
-    gw_log_level (GW_LOG_ALL);
-    gw_log (GW_LOG_STAT, mod, "Europagate www shell: %s", *argv);
-    
-    if (!(wcl = wproto_init()))
-    {
-       gw_log (GW_LOG_FATAL, mod, "init");
-       exit(1);
-    }
-    gw_log_session (wcl->id);
     if (!strcmp (*argv, "egwtcl"))
-        w_interp = w_interp_create (w_interp_tcl, wcl, NULL);
+        w_interp_type = w_interp_tcl;
     else if (!strcmp (*argv, "egwirtcl"))
-        w_interp = w_interp_create (w_interp_irtcl, wcl, NULL);
+        w_interp_type = w_interp_irtcl;
     else if (!strcmp (*argv, "egwhtml"))
-        w_interp = w_interp_create (w_interp_html, wcl, NULL);
+        w_interp_type = w_interp_html;
     else
     {
-        gw_log (GW_LOG_FATAL, mod, "Cannot determine shell type. prog=%s",
+        gw_log (GW_LOG_FATAL, "wsh", "Cannot determine shell type. prog=%s",
                *argv);
         exit (1);
     }
-    w_interp_load_state (w_interp, NULL);
-    timeout = TIMEOUT;
-    while (1)
-    {
-        char *p;
-        int r;
-
-        r = wproto_process (wcl, timeout);
-        if (r <= 0)
-        {
-            gw_db = gw_db_open ("www.db", 0, 0);
-            if (gw_db)
-                break;
-            gw_log (GW_LOG_DEBUG, mod, "Cannot terminate - new request");
-            timeout = 10;
-            continue;
-        }
-        timeout = TIMEOUT;
-       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)
-        {
-            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;
-                }
-        }
-        for (p = parms; *p; p++)
-            if (*p == '+')
-                *p = ' ';
-       gw_log (GW_LOG_DEBUG, mod, "script: %s", script);
-       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>",
-                       script);
-        }
-       wo_finish(wcl);
-    }
-    w_interp_save_state (w_interp, NULL);
-    wproto_terminate(wcl);
-    return 0;
+    wshmain (argc, argv, w_interp_type);
+    exit (0);
 }
 
+