* Europagate, 1995
*
* $Log: eti.c,v $
- * Revision 1.3 1995/03/28 08:01:23 adam
+ * 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
#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];
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;
}
}
}
+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];
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");
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
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);
}
* Europagate, 1995
*
* $Log: kernel.h,v $
- * Revision 1.10 1995/03/27 08:24:01 adam
+ * Revision 1.11 1995/03/28 11:42:34 adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.10 1995/03/27 08:24:01 adam
* First use of gip interface and gw-db.
* First work on eti program.
*
#if USE_FML
#include <fmlmarc.h>
#endif
+#include <strqueue.h>
-int urp (int fd);
+int urp (struct str_queue *queue);
struct gw_user_set {
char *name; /* name of result set */
* Europagate, 1995
*
* $Log: main.c,v $
- * Revision 1.13 1995/03/28 08:01:25 adam
+ * Revision 1.14 1995/03/28 11:42:34 adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.13 1995/03/28 08:01:25 adam
* FIFO existence is used to test for a running kernel.
*
* Revision 1.12 1995/03/27 12:51:05 adam
#include <fcntl.h>
#include <gip.h>
+#include <strqueue.h>
#include "kernel.h"
FILE *reply_fd = stdout;
struct gw_kernel_info info;
-static void kernel_events (int userid)
+static void kernel_events (struct str_queue *queue, int userid)
{
char fifo_client_name[1024];
char fifo_server_name[1024];
+ char line_buf[1024];
GIP gip;
fd_set set_r;
int r, gip_fd;
if (!strcmp (command, "mail"))
{
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n");
- urp (gip_fd);
+ while (lgets (line_buf, sizeof(line_buf)-1, gip_fd))
+ str_queue_enq (queue, line_buf);
+ urp (queue);
+ while (str_queue_deq (queue, 0, 0))
+ ;
}
else if (!strcmp (command, "stop"))
{
int main (int argc, char **argv)
{
int userid = -1;
+ struct str_queue *queue;
info.kernel_res = NULL;
info.default_res = "default.res";
info.default_res = *argv;
}
read_kernel_res ();
+ if (!(queue = str_queue_mk ()))
+ {
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk");
+ exit (1);
+ }
if (userid != -1)
- kernel_events (userid);
+ kernel_events (queue, userid);
else
- urp (0);
+ {
+ char line_buf[512];
+ while (lgets (line_buf, sizeof(line_buf)-1, 0))
+ str_queue_enq (queue, line_buf);
+ urp (queue);
+ }
return 0;
}
* Europagate, 1995
*
* $Log: urp.c,v $
- * Revision 1.23 1995/03/28 08:01:28 adam
+ * Revision 1.24 1995/03/28 11:42:35 adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.23 1995/03/28 08:01:28 adam
* FIFO existence is used to test for a running kernel.
*
* Revision 1.22 1995/03/27 12:51:05 adam
#include <unistd.h>
#include <fcntl.h>
+#include <strqueue.h>
#include "kernel.h"
-#define LINE_MAX 256
+#define LINE_MAX 1024
+static char line_buf[LINE_MAX+1];
static void put_esc_str (const char *s)
{
return 0;
}
-static char line_buf[LINE_MAX+1];
static struct command_word {
char *default_value;
return NULL;
}
-static int email_header (int fd, char *from_str, char *subject_str)
+static int email_header (struct str_queue *sq,
+ char *from_str, char *subject_str)
{
*from_str = '\0';
- *subject_str = '\0';
- while (lgets (line_buf, LINE_MAX, fd))
+ *subject_str = '\0';
+ while (str_queue_deq (sq, line_buf, LINE_MAX))
{
if (line_buf[0] == '\n')
return 0;
- if (strncmp (line_buf, "From ", 5) == 0)
+ if (memcmp (line_buf, "From ", 5) == 0)
sscanf (line_buf+4, "%s", from_str);
- if (strncmp (line_buf, "Subject: ", 9) == 0 &&
+ if (memcmp (line_buf, "Subject: ", 9) == 0 &&
sscanf (line_buf+9, "%s", subject_str+1) == 1)
strcpy (subject_str, line_buf+9);
}
return 0;
}
-int urp (int fd)
+int urp (struct str_queue *queue)
{
char from_str[128];
char subject_str[128];
int command_no = 0;
char *reply_fname = NULL;
+ char *cp;
- if (email_header (fd, from_str, subject_str))
+ if (email_header (queue, from_str, subject_str))
{
gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
return -1;
gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
"Email->Z39.50 gateway"));
- while (lgets (line_buf, LINE_MAX, fd))
+ while (str_queue_deq (queue, line_buf, LINE_MAX))
{
- char *cp;
-
if (line_buf[0] == '\n')
if (command_no)
{
- while (lgets (line_buf, LINE_MAX, fd))
+ while (str_queue_deq (queue, 0, 0))
;
break;
}