Minor changes.
[egate.git] / kernel / main.c
index a8fadfb..8a5971c 100644 (file)
@@ -2,7 +2,24 @@
  * Europagate, 1995
  *
  * $Log: main.c,v $
- * Revision 1.17  1995/04/19 10:46:18  adam
+ * 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.
+ *
+ * Revision 1.21  1995/05/01  16:26:56  adam
+ * More work on resource monitor.
+ *
+ * Revision 1.20  1995/05/01  12:43:32  adam
+ * First work on resource monitor program.
+ *
+ * Revision 1.19  1995/04/19  16:01:58  adam
+ * Some hacks to get the FIFO communication work!! Isn't reliable.
+ * Resource gw.account added - default account info.
+ *
+ * Revision 1.18  1995/04/19  13:19:09  adam
+ * New command: account - for authentication.
+ *
+ * Revision 1.17  1995/04/19  10:46:18  adam
  * Persistency works much better now. New command: status - history-like
  *
  * Revision 1.16  1995/04/19  07:31:07  adam
@@ -90,9 +107,12 @@ static void kernel_events (struct str_queue *queue, int userid)
     struct timeval tv;
     int timeout;
     int continuation = 0;
+    int extra_fd;
+    int persist_flag;
 
-    timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600"));
-    gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop");
+    persist_flag = gw_res_bool (info.kernel_res, "gw.persist", 0);
+    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);
@@ -100,6 +120,7 @@ static void kernel_events (struct str_queue *queue, int userid)
     gip = gips_initialize (fifo_server_name);
     gips_open (gip, fifo_client_name);
     gip_fd = gip_infileno (gip);
+    extra_fd = open (fifo_server_name, O_WRONLY);
 
     while (1)
     {
@@ -119,7 +140,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)
+           if (info.zass && persist_flag)
                save_p_state (userid);
            break;
        }
@@ -137,13 +158,15 @@ static void kernel_events (struct str_queue *queue, int userid)
            gw_log (GW_LOG_STAT, KERNEL_LOG, "IPC: %s", command);
             if (!strcmp (command, "mail"))
            {
-               gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n");
+               gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail");
                 while (lgets (line_buf, sizeof(line_buf)-1, gip_fd))
                     str_queue_enq (queue, line_buf);
                urp_start (continuation, queue);
-                if (!continuation)
+                if (persist_flag && !continuation)
                    load_p_state (userid);      
-               urp_command (queue);
+               r = urp_command (queue);
+               if (persist_flag && r == 1)
+                   del_p_state (userid);
                urp_end ();
                 while (str_queue_deq (queue, 0, 0))
                     ;
@@ -160,6 +183,7 @@ static void kernel_events (struct str_queue *queue, int userid)
            continuation = 1;
        }
     }
+    close (extra_fd);
     gips_close (gip);
     gips_destroy (gip);
     unlink (fifo_client_name);
@@ -175,6 +199,7 @@ int main (int argc, char **argv)
     info.default_res = "default.res";
     info.override_res = NULL;
     *info.target = 0;
+    *info.account = 0;
     info.lang = NULL;
     info.bibset = NULL;
     info.zass = NULL;
@@ -487,24 +512,27 @@ void read_kernel_res (void)
     if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
     {
         /* target is there, and there is no sub-resource for it... */
-        char *split;
+        const char *split;
 
         if ((split = strchr (info.target, ':')))
-            *split++ = '\0';
-        strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
-        if (split)
-            info.port = atoi (split);
+        {
+            memcpy (info.hostname, info.target, split-info.target);
+            info.hostname[split-info.target] = '\0';
+            info.port = atoi (split+1);
+        }
         else
-            info.port = atoi (gw_res_get
-                              (info.kernel_res, "gw.portno", "210"));
+        {
+            strcpy (info.hostname, info.target);
+            info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
+        }
     }
     else
     {
         strncpy (info.hostname, gw_res_get (info.kernel_res,
                                             "gw.hostname", "localhost"),
                  sizeof(info.hostname)-1);
-        info.port = atoi (gw_res_get (info.kernel_res,
-                                      "gw.portno", "210"));
+        info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
+        strcpy (info.account, gw_res_get (info.kernel_res, "gw.account", ""));
     }
     if (info.databases)
         free (info.databases);
@@ -537,8 +565,10 @@ void read_kernel_res (void)
     if (info.override_hostname)
         strncpy (info.hostname, info.override_hostname,
                  sizeof(info.hostname)-1);
-    v = gw_res_get (info.kernel_res, "gw.result.set", NULL);
-    info.setno = v ? -1 : 0;
+    if (gw_res_bool (info.kernel_res, "gw.result.set", 1))
+        info.setno = 0;
+    else
+        info.setno = -1;
 #if USE_FML
     if (!info.fml)
     {