First work on resource monitor program.
[egate.git] / kernel / urp.c
index 0c6c333..d052151 100644 (file)
@@ -2,7 +2,21 @@
  * Europagate, 1995
  *
  * $Log: urp.c,v $
- * Revision 1.27  1995/04/19 10:46:19  adam
+ * Revision 1.31  1995/05/01 12:43:38  adam
+ * First work on resource monitor program.
+ *
+ * Revision 1.30  1995/04/20  16:10:47  adam
+ * Modified to work with non-blocking zass-api. Not using non-blocking
+ * facility yet.
+ *
+ * Revision 1.29  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.28  1995/04/19  13:19:09  adam
+ * New command: account - for authentication.
+ *
+ * Revision 1.27  1995/04/19  10:46:19  adam
  * Persistency works much better now. New command: status - history-like
  *
  * Revision 1.26  1995/04/19  07:31:12  adam
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <lgets.h>
 #include <ttyemit.h>
 #include <strqueue.h>
 #include "kernel.h"
@@ -112,36 +127,14 @@ static void put_esc_str (const char *s)
         tty_emit (*s++);
 }
 
-int lgets (char *buf, int max, int fd)
-{
-    int r, no = 0;
-
-    --max;
-    while (no <= max)
-    {
-        if ((r=read (fd, buf+no, 1)) != 1)
-       {
-           if (r == -1)
-               gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG, "read fail");
-           buf[no] = '\0';
-           return 0;
-       }
-       if (buf[no] == 1)
-            return 0;    
-       if (buf[no++] == '\n')
-           break;
-    }
-    buf[no] = '\0';    
-    return 1;
-}
-
 int reopen_target (void)
 {
     const char *v;
     if (info.zass)
         gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
     gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target");
-    info.zass = zass_open (info.hostname, info.port);
+    info.zass = zass_open (info.hostname, info.port, NULL, /* complete */
+                           *info.account ? info.account : NULL);
     if (!info.zass)
     {
         gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d",
@@ -195,6 +188,7 @@ static struct command_word {
 {   "cancel", "cancel" },
 {   "target", "target" },
 {   "stop",   "stop" },
+{   "account", "account" },
 {   NULL, NULL }
 };
 
@@ -398,6 +392,19 @@ static int exec_find (struct ccl_token *list, const char *search_str)
     return 0;
 }
 
+static int exec_account (struct ccl_token *list)
+{
+    if (list->kind != CCL_TOK_EOL)
+    {
+        int len = list->len;
+        memcpy (info.account, list->name, len);
+        info.target[len] = '\0';
+    }
+    else
+        *info.account = '\0';
+    return 0;
+}
+
 static int exec_target (struct ccl_token *list)
 {
     int len;
@@ -737,7 +744,7 @@ static int exec_command (const char *str)
     if (cmd->kind != CCL_TOK_EOL &&
         (no = command_search (command_tab, cmd, "ccl.command.")))
     {
-        if (!info.zass && no != 9 && no != 4)
+        if (!info.zass && no != 9 && no != 4 && no != 11 && no != 7)
             reopen_target ();
         fprintf (reply_fd, "\n> %s\n", str);
         if (!info.zass && (no == 1 || no == 2 || no == 3))
@@ -768,6 +775,8 @@ static int exec_command (const char *str)
             return exec_status (cmd->next);
         case 9:
             return exec_target (cmd->next);
+        case 11:
+            return exec_account (cmd->next);
         default:
             fprintf (reply_fd, "%s\n",
                      gw_res_get (info.kernel_res, "gw.err.unimplemented",