From 0869c05bd5a456f027823ca0783216acf4424b65 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 29 Feb 1996 15:36:34 +0000 Subject: [PATCH] Main shell loop implemented as a separate function called wshmain. --- www/wsh.c | 138 ++++--------------------------------------- www/wshmain.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 126 deletions(-) create mode 100644 www/wshmain.c diff --git a/www/wsh.c b/www/wsh.c index 55eb3d8..9ee4a14 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.12 1996/02/19 15:45:00 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 @@ -88,145 +91,28 @@ */ #include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include #include "whtml.h" #include "wtcl.h" #include "wirtcl.h" -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; - GwRes shRes; -#if 0 - struct rlimit rlim; - - rlim.rlim_cur = RLIM_INFINITY; - rlim.rlim_max = RLIM_INFINITY; - setrlimit (RLIMIT_CORE, &rlim); -#endif - - gw_log_init (*argv); - gw_log_file (GW_LOG_ALL, "egwsh_log"); -#if 0 - gw_log_level (GW_LOG_ALL); -#endif - gw_log (GW_LOG_STAT, mod, "Europagate www shell: %s", *argv); - shRes = gw_res_init (); - gw_res_merge (shRes, "egw.res"); - gw_res_merge (shRes, "shell.res"); + W_Interp_Type w_interp_type; -#if 1 - gw_log_level (gw_log_mask_str ( - gw_res_get (shRes, "log.level", "default"))); -#endif - if (!(wcl = wproto_init (gw_res_get (shRes, "fifo.dir", "/tmp/egw")))) - { - 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 = atoi (gw_res_get (shRes, "timeout", "120")); - if (timeout < 1) - timeout = 1; - 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 = atoi (gw_res_get (shRes, "timeout", "120")); - if (timeout < 1) - timeout = 1; - wo_clear (wcl, NULL); - strcpy (parms_buf, wcl->wf_parms); - script = parms = parms_buf; - while (*parms && *parms != '/') - parms++; - if (*parms) - *parms++ = '\0'; - if (*script) - { - 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]) - 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; - case ';': - 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; - } - } - wo_printf (wcl, "Content-type: text/html\n\n"); - for (p = parms; *p; p++) - if (*p == '+') - *p = ' '; - gw_log (GW_LOG_STAT, mod, "script: %s", script); - gw_log (GW_LOG_STAT, 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", - script); - } - wo_finish(wcl); - } - w_interp_save_state (w_interp, NULL); - wproto_terminate(wcl); - return 0; + wshmain (argc, argv, w_interp_type); + exit (0); } + diff --git a/www/wshmain.c b/www/wshmain.c new file mode 100644 index 0000000..680d0fc --- /dev/null +++ b/www/wshmain.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 1995, the EUROPAGATE consortium (see below). + * + * The EUROPAGATE consortium members are: + * + * University College Dublin + * Danmarks Teknologiske Videnscenter + * An Chomhairle Leabharlanna + * Consejo Superior de Investigaciones Cientificas + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of EUROPAGATE or the project partners may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * 3. Users of this software (implementors and gateway operators) agree to + * inform the EUROPAGATE consortium of their use of the software. This + * information will be used to evaluate the EUROPAGATE project and the + * software, and to plan further developments. The consortium may use + * the information in later publications. + * + * 4. Users of this software agree to make their best efforts, when + * documenting their use of the software, to acknowledge the EUROPAGATE + * consortium, and the role played by the software in their work. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE + * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF + * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND + * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Log: wshmain.c,v $ + * Revision 1.1 1996/02/29 15:36:34 adam + * Main shell loop implemented as a separate function called wshmain. + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include "winterp.h" + +WCLIENT wcl; +static char *mod = "w"; + +void wshmain (int argc, char **argv, W_Interp_Type w_interp_type) +{ + char *script, *parms, parms_buf[512]; + int timeout; + W_Interp w_interp; + GW_DB gw_db; + GwRes shRes; +#if 0 + struct rlimit rlim; + + rlim.rlim_cur = RLIM_INFINITY; + rlim.rlim_max = RLIM_INFINITY; + setrlimit (RLIMIT_CORE, &rlim); +#endif + + gw_log_init (*argv); + gw_log_file (GW_LOG_ALL, "egwsh_log"); +#if 0 + gw_log_level (GW_LOG_ALL); +#endif + gw_log (GW_LOG_STAT, *argv, "Europagate www shell"); + shRes = gw_res_init (); + gw_res_merge (shRes, "egw.res"); + gw_res_merge (shRes, "shell.res"); + +#if 1 + gw_log_level (gw_log_mask_str ( + gw_res_get (shRes, "log.level", "default"))); +#endif + if (!(wcl = wproto_init (gw_res_get (shRes, "fifo.dir", "/tmp/egw")))) + { + gw_log (GW_LOG_FATAL, mod, "init"); + exit(1); + } + gw_log_session (wcl->id); + + w_interp = w_interp_create (w_interp_type, wcl, NULL); + + w_interp_load_state (w_interp, NULL); + timeout = atoi (gw_res_get (shRes, "timeout", "120")); + if (timeout < 1) + timeout = 1; + 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 = atoi (gw_res_get (shRes, "timeout", "120")); + if (timeout < 1) + timeout = 1; + wo_clear (wcl, NULL); + strcpy (parms_buf, wcl->wf_parms); + script = parms = parms_buf; + while (*parms && *parms != '/') + parms++; + if (*parms) + *parms++ = '\0'; + if (*script) + { + 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]) + 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; + case ';': + 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; + } + } + wo_printf (wcl, "Content-type: text/html\n\n"); + for (p = parms; *p; p++) + if (*p == '+') + *p = ' '; + gw_log (GW_LOG_STAT, mod, "script: %s", script); + gw_log (GW_LOG_STAT, 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", + script); + } + wo_finish(wcl); + } + gw_log (GW_LOG_DEBUG, mod, "save state.."); + w_interp_save_state (w_interp, NULL); + wproto_terminate(wcl); +} + + -- 1.7.10.4