2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
44 /* Gateway kernel - User Request Processor
48 * Revision 1.35 1995/05/16 09:40:43 adam
49 * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
51 * Revision 1.34 1995/05/04 10:40:08 adam
52 * More work on Def-settings.
54 * Revision 1.33 1995/05/03 16:34:19 adam
55 * CCL def command, i.e. user definitions - saved as resource files.
57 * Revision 1.32 1995/05/03 07:37:46 adam
58 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
59 * are used when possible.
61 * Revision 1.31 1995/05/01 12:43:38 adam
62 * First work on resource monitor program.
64 * Revision 1.30 1995/04/20 16:10:47 adam
65 * Modified to work with non-blocking zass-api. Not using non-blocking
68 * Revision 1.29 1995/04/19 16:01:58 adam
69 * Some hacks to get the FIFO communication work!! Isn't reliable.
70 * Resource gw.account added - default account info.
72 * Revision 1.28 1995/04/19 13:19:09 adam
73 * New command: account - for authentication.
75 * Revision 1.27 1995/04/19 10:46:19 adam
76 * Persistency works much better now. New command: status - history-like
78 * Revision 1.26 1995/04/19 07:31:12 adam
79 * First work on Z39.50 persistence.
81 * Revision 1.25 1995/04/17 09:34:33 adam
82 * Timeout (idletime) adjustable. Minor changes in kernel.
84 * Revision 1.24 1995/03/28 11:42:35 adam
85 * First use of string-queue utility.
87 * Revision 1.23 1995/03/28 08:01:28 adam
88 * FIFO existence is used to test for a running kernel.
90 * Revision 1.22 1995/03/27 12:51:05 adam
91 * New log level in use: GW_LOG_ERRNO.
93 * Revision 1.21 1995/03/27 08:24:04 adam
94 * First use of gip interface and gw-db.
95 * First work on eti program.
97 * Revision 1.20 1995/03/03 17:19:17 adam
98 * Smarter presentation. Bug fix in email header interpretation.
100 * Revision 1.19 1995/03/02 09:32:11 adam
101 * New presentation formats. f0=full, f1=brief, f2=mid
103 * Revision 1.18 1995/03/01 14:32:26 adam
104 * Better diagnostics. Default is, that only one database selected when
107 * Revision 1.17 1995/02/28 13:16:26 adam
108 * Configurable From: added.
110 * Revision 1.16 1995/02/23 10:08:20 adam
111 * Added logging of all user commands.
113 * Revision 1.15 1995/02/23 08:32:17 adam
116 * Revision 1.13 1995/02/22 16:54:42 adam
117 * Qualifiers of LOC target updated. More logging messages.
119 * Revision 1.12 1995/02/22 15:51:51 adam
120 * Bug fix: swap of parameter number and offset in function present.
122 * Revision 1.11 1995/02/22 15:22:33 adam
123 * Much more checking of run-time state. Show command never retrieves
124 * more records than indicated by the previous search request. Help
125 * command available. The maximum number of records retrieved can be
128 * Revision 1.10 1995/02/22 08:51:35 adam
129 * Output function can be customized in fml, which is used to print
130 * the reply to reply_fd.
132 * Revision 1.9 1995/02/21 17:46:21 adam
135 * Revision 1.8 1995/02/21 12:12:00 adam
136 * Diagnostic record with error info. observed.
138 * Revision 1.7 1995/02/20 21:16:20 adam
139 * FML support. Bug fixes. Profile for drewdb.
141 * Revision 1.6 1995/02/17 14:41:14 quinn
142 * Added simple display of records.
144 * Revision 1.5 1995/02/17 14:22:13 adam
145 * First steps of CCL show command. Not finished yet.
147 * Revision 1.4 1995/02/17 09:08:36 adam
148 * Reply with subject. CCL base command implemented.
150 * Revision 1.3 1995/02/16 18:35:09 adam
151 * First use of Zdist library. Search requests are supported.
152 * Present requests are not supported yet.
154 * Revision 1.2 1995/02/16 13:21:00 adam
155 * Organization of resource files for targets and conversion
156 * language implemented.
158 * Revision 1.1 1995/02/15 17:45:30 adam
159 * First version of email gateway kernel. Email requests are read
160 * from stdin. The output is transferred to an MTA if 'From' is
161 * found in the header - or stdout if absent. No Z39.50 client is used.
167 info/status (other name?)
168 better persistence diagnostics
169 resource gw.path - use chdir call instead
172 automatic information about target-aliases: name, query-support, etc.
185 #include <strqueue.h>
188 static void present (const char *set, int offset, int number,
189 struct ccl_token *format_token);
191 static char line_buf[LINE_MAX+1];
193 static void put_esc_str (const char *s)
199 int reopen_target (void)
203 gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
204 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target");
205 info.zass = zass_open (info.hostname, info.port, NULL, /* complete */
206 *info.account ? info.account : NULL);
209 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d",
210 info.hostname, info.port);
211 fprintf (reply_fd, "%s %s:%d\n",
212 gw_res_get (info.kernel_res, "gw.err.connect",
213 "Cannot connect to target"),
214 info.hostname, info.port);
217 v = gw_res_get (info.kernel_res, "gw.description", NULL);
221 fprintf (reply_fd, "\n");
223 fprintf (reply_fd, "%s %s:%d\n",
224 gw_res_get (info.kernel_res, "gw.msg.connect",
225 "Connection established to"),
226 info.hostname, info.port);
228 fprintf (reply_fd, "%s: %s\n",
229 gw_res_get (info.kernel_res, "gw.msg.databases",
230 "Available databases"),
233 fprintf (reply_fd, "%s: %s\n",
234 gw_res_get (info.kernel_res, "gw.msg.database",
235 "Selected databases"),
238 fprintf (reply_fd, "set=%d\n", info.setno);
240 fprintf (reply_fd, "set=Default\n");
244 struct command_word {
246 char *resource_suffix;
249 static int command_search (struct command_word *tab, struct ccl_token *cmd,
250 const char *resource_prefix)
254 assert (resource_prefix);
257 while (tab->default_value)
259 char *cp, command_names[60];
260 char resource_name[60];
263 sprintf (resource_name, "%s%s", resource_prefix,
264 tab->resource_suffix);
265 v = gw_res_get (info.kernel_res, resource_name, tab->default_value);
267 strcpy (command_names, v);
273 if ((split = strchr (cp, ' ')))
275 if (cmd->len == strlen(cp) &&
276 !memcmp (cmd->name, cp, cmd->len))
288 static struct error_no_struct {
291 } error_ccl_tab[] = {
293 { CCL_ERR_TERM_EXPECTED, "term.expected" },
294 { CCL_ERR_RP_EXPECTED, "rp.expected" },
295 { CCL_ERR_SETNAME_EXPECTED, "setname.expected" },
296 { CCL_ERR_OP_EXPECTED, "op.expected" },
297 { CCL_ERR_BAD_RP, "bad.rp" },
298 { CCL_ERR_UNKNOWN_QUAL, "unknown.qual" },
299 { CCL_ERR_DOUBLE_QUAL, "double.qual" },
300 { CCL_ERR_EQ_EXPECTED, "eq.expected" },
301 { CCL_ERR_BAD_RELATION, "bad.relation" },
302 { CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" },
303 { CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" },
304 { CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" },
308 static char *error_no_search (struct error_no_struct *tab, int no)
310 struct error_no_struct *p = tab;
311 while (p->resource_name)
314 return p->resource_name;
320 static int email_header (struct str_queue *sq,
321 char *from_str, char *subject_str)
325 while (str_queue_deq (sq, line_buf, LINE_MAX))
327 if (line_buf[0] == '\n')
329 if (memcmp (line_buf, "From ", 5) == 0)
330 sscanf (line_buf+4, "%s", from_str);
331 if (memcmp (line_buf, "Subject: ", 9) == 0 &&
332 sscanf (line_buf+9, "%s", subject_str+1) == 1)
333 strcpy (subject_str, line_buf+9);
338 static void help_general (void)
340 put_esc_str (gw_res_get (info.kernel_res, "gw.help.general",
341 "Commands available in this service:\n"));
344 static int exec_help (struct ccl_token *list)
346 static char *sep = "-------------------------------\\n";
350 put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
351 "target <name> - selects a given target\n"));
354 put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
355 "base <base>.. - selects databases\n"));
358 put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
359 "find <query> - performs a search request\n"));
362 put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
363 "show <spec> - retrieves and displays "
368 static void display_diag_error (int code, const char *addinfo)
372 sprintf (str, "gw.bib1.diag.%d", code);
373 fprintf (reply_fd, "%s %d:\n %s: '%s'\n",
374 gw_res_get (info.kernel_res, "gw.msg.z39errcode",
377 gw_res_get (info.kernel_res, str, ""), addinfo);
380 static int exec_find (struct ccl_token *list, const char *search_str)
382 const struct zass_searchent *p;
383 struct gw_user_set *us;
387 struct ccl_rpn_node *rpn;
391 if (info.setno == -1)
392 strcpy (setname, "Default");
394 sprintf (setname, "%d", info.setno);
395 info.next_position = 1;
398 rpn = ccl_find (info.bibset, list, &error, &pos);
401 const char *v = NULL, *n;
404 fprintf (reply_fd, " %*s^ - ", pos - line_buf, " ");
406 n = error_no_search (error_ccl_tab, error);
409 sprintf (name, "gw.err.%s", n);
410 v = gw_res_get (info.kernel_res, name, NULL);
413 v = ccl_err_msg (error);
414 fprintf (reply_fd, "%s\n", v);
417 ccl_pr_tree (rpn, reply_fd);
418 fprintf (reply_fd, "\n");
420 if (!*info.database )
422 fprintf (reply_fd, "%s\n",
423 gw_res_get (info.kernel_res, "gw.err.no.database",
424 "You must select database"));
427 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
430 p = zass_p_search (info.zass, rpn, setname, info.database, info.sets);
433 fprintf (reply_fd, "%s\n",
434 gw_res_get (info.kernel_res, "gw.err.search.fail",
435 "Search fail. Connection closed"));
438 if (p->errcode != -1)
440 display_diag_error (p->errcode, p->errstring);
443 fprintf (reply_fd, "%d %s %s\n", p->num,
444 gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s) in set "),
446 us = user_set_add (setname, p->num, info.database, rpn, 1, search_str);
447 autoshow = gw_res_int (info.kernel_res, "gw.auto.show", 0);
448 if (autoshow && p->num > 0)
450 if (autoshow > p->num)
452 present (setname, 1, p->num, NULL);
453 info.next_position = 1+p->num;
457 present (setname, 1, autoshow, NULL);
458 info.next_position = 1+autoshow;
464 static int exec_account (struct ccl_token *list)
466 if (list->kind != CCL_TOK_EOL)
469 memcpy (info.account, list->name, len);
470 info.target[len] = '\0';
473 *info.account = '\0';
477 static int exec_target (struct ccl_token *list)
480 if (list->kind == CCL_TOK_EOL)
483 memcpy (info.target, list->name, len);
484 info.target [len] = '\0';
487 return reopen_target ();
490 static void exec_status_r (struct gw_user_set *sp)
494 exec_status_r (sp->prev);
495 fprintf (reply_fd, "%6s %7d %12.12s %.50s\n", sp->name, sp->hits,
496 sp->database, sp->search_str);
499 static int exec_status (struct ccl_token *list)
501 fprintf (reply_fd, "%s\n",
502 gw_res_get (info.kernel_res,
504 " Name Hits Database Find"));
505 exec_status_r (info.sets);
509 static int exec_base (struct ccl_token *list)
511 struct ccl_token *li = list;
515 if (list->kind == CCL_TOK_EOL)
517 free (info.database);
518 while (li->kind != CCL_TOK_EOL)
522 if (li->kind == CCL_TOK_COMMA)
525 info.database = malloc (len);
526 assert (info.database );
529 while (li->kind != CCL_TOK_EOL)
531 memcpy (info.database+len, li->name, li->len);
533 info.database[len++] = ',';
535 if (li->kind == CCL_TOK_COMMA)
538 info.database[len-1] = '\0';
542 static void present (const char *set, int offset, int number,
543 struct ccl_token *format_token)
545 const struct zass_presentent *zp;
550 max_number = gw_res_int (info.kernel_res, "gw.max.show", 200);
551 if (number > max_number)
553 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
554 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
556 zp = zass_p_present(info.zass, (char *) set, offset, number);
562 int record_log_fd = -1;
563 const char *record_log_name;
565 record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
569 sprintf (path, "%s/%s", gw_res_get (info.kernel_res,
572 record_log_fd = open (path, O_WRONLY|O_CREAT|O_APPEND, 0666);
573 if (record_log_fd == -1)
574 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "Cannot open %s", path);
576 fprintf (reply_fd, gw_res_get (info.kernel_res,
578 "Got %d records from set %s"),
580 fprintf (reply_fd, "\n");
581 for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
585 const char *arg_ar[5];
587 fprintf (reply_fd, "--- %d/%d ---\n",
588 i+offset, offset+zp->num-1);
589 if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
591 if (pp->which == ZASS_REC_DIAG)
593 display_diag_error (pp->errcode, pp->errstring);
596 else if (pp->which != ZASS_REC_USMARC)
598 fprintf (reply_fd, "Unknown record kind %d\n",
603 if (record_log_fd != -1)
604 write (record_log_fd, pp->record, strlen(pp->record));
605 rec = iso2709_cvt (pp->record);
610 gw_res_get (info.kernel_res,
611 "gw.display.format", ""));
614 len = format_token->len;
615 if (len >= sizeof(format_str))
616 len = sizeof(format_str)-1;
617 memcpy (format_str, format_token->name, len);
618 format_str[len] = '\0';
620 if (info.fml && *format_str &&
621 (!strcmp (format_str, "0") || !strcmp (format_str, "1")
622 || !strcmp(format_str, "2")))
625 arg_ar[1] = format_str;
626 arg_ar[2] = " \\list";
627 arg_ar[3] = marc_to_str (info.fml, rec);
629 fml_exec_call_argv (info.fml, arg_ar);
632 iso2709_display (rec, reply_fd);
634 iso2709_display (rec, reply_fd);
639 fprintf (reply_fd, "Not a MARC record\n");
641 if (record_log_fd != -1)
642 close (record_log_fd);
646 static int exec_show (struct ccl_token *list)
648 static struct command_word show_tab [] =
655 struct ccl_token *set_token = NULL;
656 struct ccl_token *format_token = NULL;
657 struct ccl_token *li = list;
658 int no_of_present = 0;
661 while (li->kind != CCL_TOK_EOL)
664 if (li->next->kind == CCL_TOK_EQ)
666 if (li->kind == CCL_TOK_SET) /* set = <name> ? */
673 modifier_no = command_search (show_tab, li, "ccl.token.");
676 fprintf (reply_fd, "Unknown modifier in show\n");
680 if (modifier_no == 1) /* f = <name> ? */
682 else if (modifier_no == 2) /* p = <name> ? */
684 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
685 && li->next->kind == CCL_TOK_MINUS
686 && li->next->next != CCL_TOK_EOL)
692 fprintf (reply_fd, "%s\n", "Missing token after '='");
701 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
704 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
708 while (li->kind != CCL_TOK_EOL)
714 if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
716 modifier_no = command_search (show_tab, li, "ccl.token.");
718 if (modifier_no == 2) /* p = <name> ? */
720 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
721 && li->next->kind == CCL_TOK_MINUS
722 && li->next->next != CCL_TOK_EOL)
725 memcpy (tmp_str, li->name, len);
726 tmp_str [len] = '\0';
727 offset = atoi (tmp_str);
731 memcpy (tmp_str, li->name, len);
732 tmp_str [len] = '\0';
733 number = atoi (tmp_str) - offset + 1;
738 memcpy (tmp_str, li->name, len);
739 tmp_str [len] = '\0';
740 offset = atoi (tmp_str);
749 memcpy (tmp_str, li->name, len);
751 number = atoi (tmp_str);
755 if (offset > 0 && number > 0)
757 struct gw_user_set *us;
761 len = set_token->len;
762 memcpy (tmp_str, set_token->name, len);
764 us = user_set_search (tmp_str);
767 us = user_set_search (NULL);
768 if (us && us->hits != -1) /* proper result-set? */
770 if (offset <= us->hits)
772 if (offset+number-1 > us->hits)
773 number = us->hits - offset+1;
774 present (us->name, offset, number, format_token);
777 else if (!no_of_present) /* display error message once! */
779 fprintf (reply_fd, "%s\n",
780 gw_res_get (info.kernel_res, "gw.err.no.set",
781 "No result-set generated"));
786 if (!no_of_present) /* no records shown so far? */
788 struct gw_user_set *us;
791 us = user_set_search (NULL);
792 if (us && us->hits != -1) /* proper result-set? */
794 default_show = gw_res_int (info.kernel_res, "gw.default.show", 20);
795 if (us->hits >= info.next_position + default_show)
797 present (us->name, info.next_position, default_show,
799 info.next_position += default_show;
801 else if (us->hits >= info.next_position)
803 present (us->name, info.next_position,
804 us->hits - info.next_position + 1,
806 info.next_position = us->hits + 1;
809 else /* display error message */
811 fprintf (reply_fd, "%s\n",
812 gw_res_get (info.kernel_res, "gw.err.no.set",
813 "No result-set generated"));
820 static void show_def (void)
822 fprintf (reply_fd, "format %s\n", gw_res_get
823 (info.kernel_res, "gw.display.format", ""));
824 fprintf (reply_fd, "autoshow %s\n", gw_res_get
825 (info.kernel_res, "gw.auto.show", ""));
826 fprintf (reply_fd, "defaultshow %s\n", gw_res_get
827 (info.kernel_res, "gw.default.show", ""));
828 fprintf (reply_fd, "language %s\n", gw_res_get
829 (info.kernel_res, "gw.language", ""));
832 static int exec_def (struct ccl_token *list)
834 const char *name = NULL;
837 static struct command_word def_tab [] =
839 { "reset", "reset" },
842 { "autoshow", "autoshow" },
843 { "defaultshow", "defaultshow" },
844 { "lang", "language" },
850 sprintf (fname, "%s/user.%d.r", gw_res_get (info.kernel_res,
854 if (list->kind == CCL_TOK_EOL)
858 int setting_no = command_search (def_tab, list, "ccl.token.");
862 fprintf (reply_fd, "Unknown setting in def\n");
871 else if (setting_no == 2)
877 if (list->kind == CCL_TOK_EOL)
879 strncpy (value, list->name, 127);
880 value[(size_t) list->len] = '\0';
884 name = "gw.display.format";
887 name = "gw.auto.show";
890 name = "gw.default.show";
893 name = "gw.language";
898 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
900 gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
901 gw_res_put (info.kernel_res, name, value, fname);
902 gw_res_commit (info.kernel_res, fname);
911 * exec_command: parse and execute ccl command in str.
912 * str: ccl command string
913 * stop_flag pointer to integer. On completion the integer
914 * is 1 (stop) or 2 (continue); 0 (other command)
915 * return: 0 success; non-zero otherwise
917 static int exec_command (const char *str, int *stop_flag)
919 static struct command_word command_tab [] =
926 { "continue", "continue" },
927 { "status", "status" },
929 { "target", "target" },
931 { "account", "account" },
935 struct ccl_token *cmd = ccl_tokenize (str);
939 if (cmd->kind != CCL_TOK_EOL &&
940 (no = command_search (command_tab, cmd, "ccl.command.")))
942 if (no == 1 || no == 2 || no == 3) /* find/show/base? */
944 if (!info.zass) /* open if not already opened */
946 fprintf (reply_fd, "\n> %s\n", str);
947 if (!info.zass) /* fail? */
949 fprintf (reply_fd, "%s\n",
950 gw_res_get (info.kernel_res, "gw.err.no.target",
951 "No connection established - "
957 fprintf (reply_fd, "\n> %s\n", str);
961 return exec_find (cmd->next, str);
963 return exec_show (cmd->next);
965 return exec_base (cmd->next);
967 return exec_help (cmd->next);
968 case 6: /* continue */
972 return exec_status (cmd->next);
977 return exec_target (cmd->next);
979 return exec_def (cmd->next);
981 return exec_account (cmd->next);
983 fprintf (reply_fd, "%s\n",
984 gw_res_get (info.kernel_res, "gw.err.unimplemented",
985 "Not implemented yet"));
990 fprintf (reply_fd, "\n> %s\n", str);
991 fprintf (reply_fd, " ^ %s\n",
992 gw_res_get (info.kernel_res, "gw.err.unknown.command",
994 "Use help to see list of commands"));
999 int urp_start (int continuation, struct str_queue *queue)
1001 char subject_str[128];
1003 info.command_no = 0;
1004 info.reply_fname = NULL;
1006 if (email_header (queue, info.from_str, subject_str))
1008 gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
1011 tty_init (stdout, 40, 70);
1014 info.reply_fname = (char *)
1015 tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL),
1016 gw_res_get (info.kernel_res,
1017 "gw.reply.tmp.prefix", "gwr"));
1019 reply_fd = fopen (info.reply_fname, "w");
1022 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "Cannot create %s",
1026 tty_init (reply_fd, 0, 0);
1027 fprintf (reply_fd, "From: %s\n",
1028 gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
1029 fprintf (reply_fd, "Subject: ");
1031 fprintf (reply_fd, "Z39.50 Re: %s", subject_str);
1033 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1036 fprintf (reply_fd, "\n");
1037 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", info.from_str);
1040 gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
1041 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
1042 "Email->Z39.50 gateway"));
1044 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1050 int urp_command (struct str_queue *queue)
1055 while (str_queue_deq (queue, line_buf, LINE_MAX))
1057 if (line_buf[0] == '\n')
1058 if (info.command_no)
1060 while (str_queue_deq (queue, 0, 0))
1066 if ((cp = strchr (line_buf, '\n')))
1068 gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
1069 if (isalpha (line_buf[0]))
1071 exec_command (line_buf, &stop_flag);
1074 info.command_no++; /* prevent help! */
1075 while (str_queue_deq (queue, line_buf, LINE_MAX))
1087 if (!info.command_no)
1089 fprintf (reply_fd, "%s\n",
1090 gw_res_get (info.kernel_res, "gw.err.nullbody", "No body"));
1099 assert (info.reply_fname);
1103 mta = gw_res_get (info.kernel_res, "gw.reply.mta",
1104 "/usr/lib/sendmail");
1105 sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname);
1107 mta_code = system (cmd);
1109 gw_log (GW_LOG_FATAL, KERNEL_LOG,
1110 "Reply '%s' got exit code %d", cmd, mta_code);
1112 unlink (info.reply_fname);
1113 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str);