LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
[egate.git] / kernel / main.c
index 8a5971c..4f4b0b7 100644 (file)
@@ -1,8 +1,60 @@
+/*
+ * 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.
+ *
+ */
 /* Gateway kernel - Main
  * Europagate, 1995
  *
  * $Log: main.c,v $
- * Revision 1.22  1995/05/03 07:37:39  adam
+ * Revision 1.25  1995/05/16 09:40:42  adam
+ * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
+ *
+ * Revision 1.24  1995/05/04  10:40:07  adam
+ * More work on Def-settings.
+ *
+ * Revision 1.23  1995/05/03  16:34:18  adam
+ * CCL def command, i.e. user definitions - saved as resource files.
+ *
+ * Revision 1.22  1995/05/03  07:37:39  adam
  * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
  * are used when possible.
  *
@@ -96,7 +148,7 @@ FILE *reply_fd = stdout;
 
 struct gw_kernel_info info;
 
-static void kernel_events (struct str_queue *queue, int userid)
+static void kernel_events (struct str_queue *queue)
 {
     char fifo_client_name[1024];
     char fifo_server_name[1024];
@@ -114,8 +166,8 @@ static void kernel_events (struct str_queue *queue, int userid)
     timeout = gw_res_int (info.kernel_res, "gw.timeout", 600);
     gw_log (GW_LOG_DEBUG, KERNEL_LOG, "event loop");
 
-    sprintf (fifo_client_name, "fifo.c.%d", userid);
-    sprintf (fifo_server_name, "fifo.s.%d", userid);
+    sprintf (fifo_client_name, "fifo.c.%d", info.userid);
+    sprintf (fifo_server_name, "fifo.s.%d", info.userid);
 
     gip = gips_initialize (fifo_server_name);
     gips_open (gip, fifo_client_name);
@@ -141,7 +193,7 @@ static void kernel_events (struct str_queue *queue, int userid)
            gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", 
                    timeout);
            if (info.zass && persist_flag)
-               save_p_state (userid);
+               save_p_state (info.userid);
            break;
        }
        if (FD_ISSET (gip_fd, &set_r))
@@ -163,10 +215,16 @@ static void kernel_events (struct str_queue *queue, int userid)
                     str_queue_enq (queue, line_buf);
                urp_start (continuation, queue);
                 if (persist_flag && !continuation)
-                   load_p_state (userid);      
+                   load_p_state (info.userid); 
                r = urp_command (queue);
-               if (persist_flag && r == 1)
-                   del_p_state (userid);
+               if (r == 1)                         /* stop? */
+                {
+                    info.zass = NULL;               /* delete association */
+                    *info.target = 0;               /* indicate no target */
+                    read_kernel_res();              /* reread resources */
+                    if (persist_flag)
+                        del_p_state (info.userid);  /* remove persist file */
+                }
                urp_end ();
                 while (str_queue_deq (queue, 0, 0))
                     ;
@@ -186,13 +244,13 @@ static void kernel_events (struct str_queue *queue, int userid)
     close (extra_fd);
     gips_close (gip);
     gips_destroy (gip);
+
     unlink (fifo_client_name);
     unlink (fifo_server_name);
 }
 
 int main (int argc, char **argv)
 {
-    int userid = -1;
     struct str_queue *queue;
 
     info.kernel_res = NULL;
@@ -208,6 +266,7 @@ int main (int argc, char **argv)
     info.databases = NULL;
     info.database = NULL;
     info.setno = -1;
+    info.userid = -1;
 #if USE_FML
     info.fml = NULL;
 #endif
@@ -327,11 +386,11 @@ int main (int argc, char **argv)
                 break;
            case 'i':
                 if (argv[0][2])
-                   userid = atoi (argv[0]+2);
+                   info.userid = atoi (argv[0]+2);
                 else if (argc > 0)
                 {
                     --argc;
-                   userid = atoi (*++argv);
+                   info.userid = atoi (*++argv);
                 }
                 else
                 {
@@ -352,10 +411,10 @@ int main (int argc, char **argv)
         gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk");
         exit (1);
     }
-    if (userid != -1)
+    if (info.userid != -1)
     {
        read_kernel_res ();
-        kernel_events (queue, userid);
+        kernel_events (queue);
     }
     else
     {
@@ -459,6 +518,7 @@ void read_kernel_res (void)
         gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading kernel resource, lang %s",
                 info.lang);
 
+    /* read default resources. These should exist */
     if (gw_res_merge (info.kernel_res, info.default_res))
     {
         gw_log (GW_LOG_WARN, KERNEL_LOG, "Couldn't read resource file %s",
@@ -467,6 +527,7 @@ void read_kernel_res (void)
     }
     strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
     
+    /* fetch target definitions (if defined at all) */
     if (*info.target)
     {
         sprintf (resource_name, "gw.target.%s", info.target);
@@ -477,21 +538,34 @@ void read_kernel_res (void)
             gw_res_merge (info.kernel_res, fname);
         }
     }
-    if (info.lang)
+    /* fetch user definitions (if user-id is specified) */
+    if (info.userid >= 0)
     {
-        sprintf (resource_name, "gw.lang.%s", info.lang);
+        sprintf (fname, "%s/user.%d.r", path_prefix, info.userid);
+        gw_res_merge (info.kernel_res, fname);
+    }
+    /* fetch language definitions (if specified at all) */
+    v = gw_res_get (info.kernel_res, "gw.language", info.lang);
+    if (v)
+    {
+        sprintf (resource_name, "gw.lang.%s", v);
         v = gw_res_get (info.kernel_res, resource_name, NULL);
         if (v)
         {
             sprintf (fname, "%s/%s", path_prefix, v);
+            gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Reading language resources %s",
+                    fname);
             gw_res_merge (info.kernel_res, fname);
         }
     }
+    /* fetch overriding resources from file (if specified) */
     if (info.override_res)
     {
         sprintf (fname, "%s/%s", path_prefix, info.override_res);
         gw_res_merge (info.kernel_res, fname);        
     }
+
+    /* read bibset definition for ccl */
     v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
     if (v)
     {
@@ -508,10 +582,12 @@ void read_kernel_res (void)
             fclose (bib_inf);
         }
     }
+
+    /* determine host name and port no */
     sprintf (resource_name, "gw.target.%s", info.target);
     if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
     {
-        /* target is there, and there is no sub-resource for it... */
+        /* target is specified, and there is no sub-resource for it... */
         const char *split;
 
         if ((split = strchr (info.target, ':')))
@@ -527,13 +603,15 @@ void read_kernel_res (void)
         }
     }
     else
-    {
+    {   /* resources gw.hostname and gw.portno will be used */
         strncpy (info.hostname, gw_res_get (info.kernel_res,
                                             "gw.hostname", "localhost"),
                  sizeof(info.hostname)-1);
         info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
         strcpy (info.account, gw_res_get (info.kernel_res, "gw.account", ""));
     }
+    /* set info.databases (all available databases for target) */
+    /* set info.database (first database for target) */
     if (info.databases)
         free (info.databases);
     if (info.database)
@@ -560,11 +638,22 @@ void read_kernel_res (void)
         for (cp = info.database; (cp = strchr (cp, ' ')); cp++)
             *cp = ',';
     }
+
+    /* the port no can be explicitly overridden by a command line option */
     if (info.override_portno)
         info.port = atoi (info.override_portno);
+
+    /* the hostname can be explicitly overridden by a command line option */
     if (info.override_hostname)
         strncpy (info.hostname, info.override_hostname,
                  sizeof(info.hostname)-1);
+
+    ccl_token_and = gw_res_get (info.kernel_res, "ccl.token.and", "and");
+    ccl_token_or = gw_res_get (info.kernel_res, "ccl.token.or", "or");
+    ccl_token_not = gw_res_get (info.kernel_res, "ccl.token.not", "not");
+    ccl_token_set = gw_res_get (info.kernel_res, "ccl.token.set", "set");
+
+    /* determine if more than one result-set names is supported */
     if (gw_res_bool (info.kernel_res, "gw.result.set", 1))
         info.setno = 0;
     else