Removed unused variable.
[egate.git] / kernel / eti.c
index 0398f56..6cce040 100644 (file)
@@ -2,7 +2,13 @@
  * Europagate, 1995
  *
  * $Log: eti.c,v $
- * Revision 1.3  1995/03/28 08:01:23  adam
+ * Revision 1.5  1995/03/31 09:43:13  adam
+ * Removed unused variable.
+ *
+ * Revision 1.4  1995/03/28  11:42:34  adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.3  1995/03/28  08:01:23  adam
  * FIFO existence is used to test for a running kernel.
  *
  * Revision 1.2  1995/03/27  12:51:05  adam
@@ -27,9 +33,9 @@
 #include <gw-log.h>
 #include <gw-db.h>
 #include <gip.h>
+#include <strqueue.h>
 
 #define LINE_MAX 1024
-static char line_buf[LINE_MAX+1];
 
 static char *module = "eti";
 static jmp_buf retry_jmp;
@@ -39,19 +45,23 @@ static void pipe_handle (int dummy)
     longjmp (retry_jmp, 1);
 }
 
-static int email_header (FILE *inf, char *from_str, char *subject_str)
+static int email_header (struct str_queue *sq,
+                         char *from_str, char *subject_str)
 {
+    char *msg;
+    int index = 0;
+
     *from_str = '\0';
-    *subject_str = '\0';
-    while (fgets (line_buf, LINE_MAX, inf))
+    *subject_str = '\0';    
+    while ((msg = str_queue_get (sq, index++)))
     {
-        if (line_buf[0] == '\n')
+        if (msg[0] == '\n')
             return 0;
-        if (strncmp (line_buf, "From ", 5) == 0)
-            sscanf (line_buf+4, "%s", from_str);
-        if (strncmp (line_buf, "Subject: ", 9) == 0 &&
-            sscanf (line_buf+9, "%s", subject_str+1) == 1)
-            strcpy (subject_str, line_buf+9);
+        if (memcmp (msg, "From ", 5) == 0)
+            sscanf (msg+4, "%s", from_str);
+        if (memcmp (msg, "Subject: ", 9) == 0 &&
+            sscanf (msg+9, "%s", subject_str+1) == 1)
+            strcpy (subject_str, msg+9);
     }
     return 1;
 }
@@ -91,6 +101,17 @@ static void start_kernel (int argc, char **argv, int id)
     }
 }
 
+static void deliver (struct str_queue *sq, GIP gip)
+{
+    int index = 0;
+    char *msg;
+
+    gip_wline (gip, "mail\n");
+    while ((msg = str_queue_get (sq, index++)))
+        gip_wline (gip, msg);
+    gip_wline (gip, "\001");
+}
+
 int main (int argc, char **argv)
 {
     char from_str[LINE_MAX+1];
@@ -105,11 +126,21 @@ int main (int argc, char **argv)
     static int pass = 0;
     char fifo_client_name[1024];
     char fifo_server_name[1024];
+    struct str_queue *queue;
 
     gw_log_init (*argv);
     gw_log_level (GW_LOG_ALL);
     gw_log_file (GW_LOG_ALL, "eti.log");
-    r = email_header (stdin, from_str, subject_str);
+
+    if (!(queue = str_queue_mk ()))
+    {
+        gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk");
+        exit (1);
+    }
+    while (fgets (line_str, LINE_MAX, stdin))
+        str_queue_enq (queue, line_str);
+
+    r = email_header (queue, from_str, subject_str);
     if (! *from_str)
     {
         gw_log (GW_LOG_WARN, module, "No \"From\" in mail");
@@ -167,12 +198,12 @@ int main (int argc, char **argv)
     if (r < 0)
         if (r == -2)
        {
-           gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-2");
+           gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-2");
            longjmp (retry_jmp, 1);
        }
        else if (r == -1)
        {
-           gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-1");
+           gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-1");
            longjmp (retry_jmp, 1);
        }
        else
@@ -181,26 +212,13 @@ int main (int argc, char **argv)
            exit (1);
        }
     /* deliver message ... */
-    gw_log (GW_LOG_DEBUG, module, "Delivering mail header");
-    gip_wline (gip, "mail\n");
-    gip_wline (gip, "From ");
-    gip_wline (gip, from_str);
-    gip_wline (gip, "\n");
-    if (*subject_str)
-    {
-        gip_wline (gip, "Subject: ");
-       gip_wline (gip, subject_str);
-       gip_wline (gip, "\n");
-    }
-    gip_wline (gip, "\n");
-    gw_log (GW_LOG_DEBUG, module, "Delivering mail body");
-    while (fgets (line_str, LINE_MAX, stdin))
-        gip_wline (gip, line_str);
-    gip_wline (gip, "\001");
+    gw_log (GW_LOG_DEBUG, module, "Delivering mail");
+    deliver (queue, gip);
     gw_log (GW_LOG_DEBUG, module, "Closing");
     gipc_close (gip);
     gipc_destroy (gip);
     gw_db_close (user_db);
+    gw_log (GW_LOG_DEBUG, module, "Exiting");
     exit (0);
 }