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.37 1995/05/18 12:03:09 adam
49 * Bug fixes and minor improvements.
51 * Revision 1.36 1995/05/17 10:51:33 adam
52 * Added a few more error checks to the show command.
54 * Revision 1.35 1995/05/16 09:40:43 adam
55 * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
57 * Revision 1.34 1995/05/04 10:40:08 adam
58 * More work on Def-settings.
60 * Revision 1.33 1995/05/03 16:34:19 adam
61 * CCL def command, i.e. user definitions - saved as resource files.
63 * Revision 1.32 1995/05/03 07:37:46 adam
64 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
65 * are used when possible.
67 * Revision 1.31 1995/05/01 12:43:38 adam
68 * First work on resource monitor program.
70 * Revision 1.30 1995/04/20 16:10:47 adam
71 * Modified to work with non-blocking zass-api. Not using non-blocking
74 * Revision 1.29 1995/04/19 16:01:58 adam
75 * Some hacks to get the FIFO communication work!! Isn't reliable.
76 * Resource gw.account added - default account info.
78 * Revision 1.28 1995/04/19 13:19:09 adam
79 * New command: account - for authentication.
81 * Revision 1.27 1995/04/19 10:46:19 adam
82 * Persistency works much better now. New command: status - history-like
84 * Revision 1.26 1995/04/19 07:31:12 adam
85 * First work on Z39.50 persistence.
87 * Revision 1.25 1995/04/17 09:34:33 adam
88 * Timeout (idletime) adjustable. Minor changes in kernel.
90 * Revision 1.24 1995/03/28 11:42:35 adam
91 * First use of string-queue utility.
93 * Revision 1.23 1995/03/28 08:01:28 adam
94 * FIFO existence is used to test for a running kernel.
96 * Revision 1.22 1995/03/27 12:51:05 adam
97 * New log level in use: GW_LOG_ERRNO.
99 * Revision 1.21 1995/03/27 08:24:04 adam
100 * First use of gip interface and gw-db.
101 * First work on eti program.
103 * Revision 1.20 1995/03/03 17:19:17 adam
104 * Smarter presentation. Bug fix in email header interpretation.
106 * Revision 1.19 1995/03/02 09:32:11 adam
107 * New presentation formats. f0=full, f1=brief, f2=mid
109 * Revision 1.18 1995/03/01 14:32:26 adam
110 * Better diagnostics. Default is, that only one database selected when
113 * Revision 1.17 1995/02/28 13:16:26 adam
114 * Configurable From: added.
116 * Revision 1.16 1995/02/23 10:08:20 adam
117 * Added logging of all user commands.
119 * Revision 1.15 1995/02/23 08:32:17 adam
122 * Revision 1.13 1995/02/22 16:54:42 adam
123 * Qualifiers of LOC target updated. More logging messages.
125 * Revision 1.12 1995/02/22 15:51:51 adam
126 * Bug fix: swap of parameter number and offset in function present.
128 * Revision 1.11 1995/02/22 15:22:33 adam
129 * Much more checking of run-time state. Show command never retrieves
130 * more records than indicated by the previous search request. Help
131 * command available. The maximum number of records retrieved can be
134 * Revision 1.10 1995/02/22 08:51:35 adam
135 * Output function can be customized in fml, which is used to print
136 * the reply to reply_fd.
138 * Revision 1.9 1995/02/21 17:46:21 adam
141 * Revision 1.8 1995/02/21 12:12:00 adam
142 * Diagnostic record with error info. observed.
144 * Revision 1.7 1995/02/20 21:16:20 adam
145 * FML support. Bug fixes. Profile for drewdb.
147 * Revision 1.6 1995/02/17 14:41:14 quinn
148 * Added simple display of records.
150 * Revision 1.5 1995/02/17 14:22:13 adam
151 * First steps of CCL show command. Not finished yet.
153 * Revision 1.4 1995/02/17 09:08:36 adam
154 * Reply with subject. CCL base command implemented.
156 * Revision 1.3 1995/02/16 18:35:09 adam
157 * First use of Zdist library. Search requests are supported.
158 * Present requests are not supported yet.
160 * Revision 1.2 1995/02/16 13:21:00 adam
161 * Organization of resource files for targets and conversion
162 * language implemented.
164 * Revision 1.1 1995/02/15 17:45:30 adam
165 * First version of email gateway kernel. Email requests are read
166 * from stdin. The output is transferred to an MTA if 'From' is
167 * found in the header - or stdout if absent. No Z39.50 client is used.
173 info/status (other name?)
174 better persistence diagnostics
175 resource gw.path - use chdir call instead
178 automatic information about target-aliases: name, query-support, etc.
191 #include <strqueue.h>
194 static void present (const char *set, int offset, int number,
195 struct ccl_token *format_token);
197 static char line_buf[LINE_MAX+1];
199 static void put_esc_str (const char *s)
205 int reopen_target (void)
209 gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
210 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target");
211 info.zass = zass_open (info.hostname, info.port, NULL, /* complete */
212 *info.account ? info.account : NULL);
215 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d",
216 info.hostname, info.port);
217 fprintf (reply_fd, "%s %s:%d\n",
218 gw_res_get (info.kernel_res, "gw.err.connect",
219 "Cannot connect to target"),
220 info.hostname, info.port);
223 v = gw_res_get (info.kernel_res, "gw.description", NULL);
227 fprintf (reply_fd, "\n");
229 fprintf (reply_fd, "%s %s:%d\n",
230 gw_res_get (info.kernel_res, "gw.msg.connect",
231 "Connection established to"),
232 info.hostname, info.port);
234 fprintf (reply_fd, "%s: %s\n",
235 gw_res_get (info.kernel_res, "gw.msg.databases",
236 "Available databases"),
239 fprintf (reply_fd, "%s: %s\n",
240 gw_res_get (info.kernel_res, "gw.msg.database",
241 "Selected databases"),
244 fprintf (reply_fd, "set=%d\n", info.setno);
246 fprintf (reply_fd, "set=Default\n");
250 struct command_word {
252 char *resource_suffix;
255 static int command_search (struct command_word *tab, struct ccl_token *cmd,
256 const char *resource_prefix)
260 assert (resource_prefix);
263 while (tab->default_value)
265 char *cp, command_names[60];
266 char resource_name[60];
269 sprintf (resource_name, "%s%s", resource_prefix,
270 tab->resource_suffix);
271 v = gw_res_get (info.kernel_res, resource_name, tab->default_value);
273 strcpy (command_names, v);
279 if ((split = strchr (cp, ' ')))
281 if (cmd->len == strlen(cp) &&
282 !memcmp (cmd->name, cp, cmd->len))
294 static struct error_no_struct {
297 } error_ccl_tab[] = {
299 { CCL_ERR_TERM_EXPECTED, "term.expected" },
300 { CCL_ERR_RP_EXPECTED, "rp.expected" },
301 { CCL_ERR_SETNAME_EXPECTED, "setname.expected" },
302 { CCL_ERR_OP_EXPECTED, "op.expected" },
303 { CCL_ERR_BAD_RP, "bad.rp" },
304 { CCL_ERR_UNKNOWN_QUAL, "unknown.qual" },
305 { CCL_ERR_DOUBLE_QUAL, "double.qual" },
306 { CCL_ERR_EQ_EXPECTED, "eq.expected" },
307 { CCL_ERR_BAD_RELATION, "bad.relation" },
308 { CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" },
309 { CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" },
310 { CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" },
314 static char *error_no_search (struct error_no_struct *tab, int no)
316 struct error_no_struct *p = tab;
317 while (p->resource_name)
320 return p->resource_name;
326 static int email_header (struct str_queue *sq,
327 char *from_str, char *subject_str)
331 while (str_queue_deq (sq, line_buf, LINE_MAX))
333 if (line_buf[0] == '\n')
335 if (memcmp (line_buf, "From ", 5) == 0)
336 sscanf (line_buf+4, "%s", from_str);
337 if (memcmp (line_buf, "Subject: ", 9) == 0 &&
338 sscanf (line_buf+9, "%s", subject_str+1) == 1)
339 strcpy (subject_str, line_buf+9);
344 static void help_general (void)
346 put_esc_str (gw_res_get (info.kernel_res, "gw.help.general",
347 "Commands available in this service:\n"));
350 static int exec_help (struct ccl_token *list)
352 static char *sep = "-------------------------------\\n";
356 put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
357 "target <name> - selects a given target\n"));
360 put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
361 "base <base>.. - selects databases\n"));
364 put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
365 "find <query> - performs a search request\n"));
368 put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
369 "show <spec> - retrieves and displays "
374 static void display_diag_error (int code, const char *addinfo)
378 sprintf (str, "gw.bib1.diag.%d", code);
379 fprintf (reply_fd, "%s %d:\n %s: '%s'\n",
380 gw_res_get (info.kernel_res, "gw.msg.z39errcode",
383 gw_res_get (info.kernel_res, str, ""), addinfo);
386 static int exec_find (struct ccl_token *list, const char *search_str)
388 const struct zass_searchent *p;
389 struct gw_user_set *us;
393 struct ccl_rpn_node *rpn;
397 if (info.setno == -1)
398 strcpy (setname, "Default");
400 sprintf (setname, "%d", info.setno);
401 info.next_position = 1;
404 rpn = ccl_find (info.bibset, list, &error, &pos);
407 const char *v = NULL, *n;
410 fprintf (reply_fd, " %*s^ - ", pos - line_buf, " ");
412 n = error_no_search (error_ccl_tab, error);
415 sprintf (name, "gw.err.%s", n);
416 v = gw_res_get (info.kernel_res, name, NULL);
419 v = ccl_err_msg (error);
420 fprintf (reply_fd, "%s\n", v);
423 ccl_pr_tree (rpn, reply_fd);
424 fprintf (reply_fd, "\n");
426 if (!*info.database )
428 fprintf (reply_fd, "%s\n",
429 gw_res_get (info.kernel_res, "gw.err.no.database",
430 "You must select database"));
433 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
436 p = zass_p_search (info.zass, rpn, setname, info.database, info.sets);
439 fprintf (reply_fd, "%s\n",
440 gw_res_get (info.kernel_res, "gw.err.search.fail",
441 "Search fail. Connection closed"));
444 if (p->errcode != -1)
446 display_diag_error (p->errcode, p->errstring);
449 fprintf (reply_fd, "%d %s %s\n", p->num,
450 gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s) in set "),
452 us = user_set_add (setname, p->num, info.database, rpn, 1, search_str);
453 autoshow = gw_res_int (info.kernel_res, "gw.auto.show", 0);
454 if (autoshow && p->num > 0)
456 if (autoshow > p->num)
458 present (setname, 1, p->num, NULL);
459 info.next_position = 1+p->num;
463 present (setname, 1, autoshow, NULL);
464 info.next_position = 1+autoshow;
470 static int exec_account (struct ccl_token *list)
472 if (list->kind != CCL_TOK_EOL)
475 memcpy (info.account, list->name, len);
476 info.target[len] = '\0';
479 *info.account = '\0';
483 static int exec_target (struct ccl_token *list)
486 if (list->kind == CCL_TOK_EOL)
489 memcpy (info.target, list->name, len);
490 info.target [len] = '\0';
493 return reopen_target ();
496 static void exec_status_r (struct gw_user_set *sp)
500 exec_status_r (sp->prev);
501 fprintf (reply_fd, "%6s %7d %12.12s %.50s\n", sp->name, sp->hits,
502 sp->database, sp->search_str);
505 static int exec_status (struct ccl_token *list)
507 fprintf (reply_fd, "%s\n",
508 gw_res_get (info.kernel_res,
510 " Name Hits Database Find"));
511 exec_status_r (info.sets);
515 static int exec_base (struct ccl_token *list)
517 struct ccl_token *li = list;
521 if (list->kind == CCL_TOK_EOL)
523 free (info.database);
524 while (li->kind != CCL_TOK_EOL)
528 if (li->kind == CCL_TOK_COMMA)
531 info.database = malloc (len);
532 assert (info.database );
535 while (li->kind != CCL_TOK_EOL)
537 memcpy (info.database+len, li->name, li->len);
539 info.database[len++] = ',';
541 if (li->kind == CCL_TOK_COMMA)
544 info.database[len-1] = '\0';
548 static void present (const char *set, int offset, int number,
549 struct ccl_token *format_token)
551 const struct zass_presentent *zp;
556 max_number = gw_res_int (info.kernel_res, "gw.max.show", 200);
557 if (number > max_number)
559 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
560 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
562 zp = zass_p_present(info.zass, (char *) set, offset, number);
568 int record_log_fd = -1;
569 const char *record_log_name;
571 record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
575 sprintf (path, "%s/%s", gw_res_get (info.kernel_res,
578 record_log_fd = open (path, O_WRONLY|O_CREAT|O_APPEND, 0666);
579 if (record_log_fd == -1)
580 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "Cannot open %s", path);
582 fprintf (reply_fd, gw_res_get (info.kernel_res,
584 "Got %d records from set %s"),
586 fprintf (reply_fd, "\n");
587 for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
591 const char *arg_ar[5];
593 fprintf (reply_fd, "--- %d/%d ---\n",
594 i+offset, offset+zp->num-1);
595 if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
597 if (pp->which == ZASS_REC_DIAG)
599 display_diag_error (pp->errcode, pp->errstring);
602 else if (pp->which != ZASS_REC_USMARC)
604 fprintf (reply_fd, "Unknown record kind %d\n",
609 if (record_log_fd != -1)
610 write (record_log_fd, pp->record, strlen(pp->record));
611 rec = iso2709_cvt (pp->record);
616 gw_res_get (info.kernel_res,
617 "gw.display.format", ""));
620 len = format_token->len;
621 if (len >= sizeof(format_str))
622 len = sizeof(format_str)-1;
623 memcpy (format_str, format_token->name, len);
624 format_str[len] = '\0';
626 if (info.fml && *format_str &&
627 (!strcmp (format_str, "0") || !strcmp (format_str, "1")
628 || !strcmp(format_str, "2")))
631 arg_ar[1] = format_str;
632 arg_ar[2] = " \\list";
633 arg_ar[3] = marc_to_str (info.fml, rec);
635 fml_exec_call_argv (info.fml, arg_ar);
638 iso2709_display (rec, reply_fd);
640 iso2709_display (rec, reply_fd);
645 fprintf (reply_fd, "Not a MARC record\n");
647 if (record_log_fd != -1)
648 close (record_log_fd);
652 static int exec_show (struct ccl_token *list)
654 static struct command_word show_tab [] =
661 struct ccl_token *set_token = NULL;
662 struct ccl_token *format_token = NULL;
663 struct ccl_token *li = list;
664 int no_of_present = 0;
667 while (li->kind != CCL_TOK_EOL)
670 if (li->next->kind == CCL_TOK_EQ)
672 if (li->kind == CCL_TOK_SET) /* set = <name> ? */
679 modifier_no = command_search (show_tab, li, "ccl.token.");
682 fprintf (reply_fd, "Unknown modifier in show\n");
686 if (modifier_no == 1) /* f = <name> ? */
688 else if (modifier_no == 2) /* p = <name> ? */
690 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
691 && li->next->kind == CCL_TOK_MINUS
692 && li->next->next != CCL_TOK_EOL)
698 fprintf (reply_fd, "%s\n", "Missing token after '='");
706 memcpy (tmp_str, li->name, len);
708 if (atoi(tmp_str) <= 0)
710 fprintf (reply_fd, "%s\n",
711 gw_res_get (info.kernel_res, "gw.err.bad.show",
712 "Integer expected"));
719 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
722 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
726 while (li->kind != CCL_TOK_EOL)
732 if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
734 modifier_no = command_search (show_tab, li, "ccl.token.");
736 if (modifier_no == 2) /* p = <name> ? */
738 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
739 && li->next->kind == CCL_TOK_MINUS
740 && li->next->next != CCL_TOK_EOL)
743 memcpy (tmp_str, li->name, len);
744 tmp_str [len] = '\0';
745 offset = atoi (tmp_str);
749 memcpy (tmp_str, li->name, len);
750 tmp_str [len] = '\0';
751 number = atoi (tmp_str) - offset + 1;
754 fprintf (reply_fd, "%s\n",
755 gw_res_get (info.kernel_res,
758 "greater than ending position"));
765 memcpy (tmp_str, li->name, len);
766 tmp_str [len] = '\0';
767 offset = atoi (tmp_str);
773 else if (li->kind == CCL_TOK_TERM)
776 memcpy (tmp_str, li->name, len);
778 number = atoi (tmp_str);
782 if (offset > 0 && number > 0)
784 struct gw_user_set *us;
788 len = set_token->len;
789 memcpy (tmp_str, set_token->name, len);
791 us = user_set_search (tmp_str);
794 us = user_set_search (NULL);
795 if (us && us->hits != -1) /* proper result-set? */
797 if (offset <= us->hits)
799 if (offset+number-1 > us->hits)
800 number = us->hits - offset+1;
801 present (us->name, offset, number, format_token);
804 else if (!no_of_present) /* display error message once! */
806 fprintf (reply_fd, "%s\n",
807 gw_res_get (info.kernel_res, "gw.err.no.set",
808 "No result-set generated"));
813 if (!no_of_present) /* no records shown so far? */
815 struct gw_user_set *us;
818 us = user_set_search (NULL);
819 if (us && us->hits != -1) /* proper result-set? */
821 default_show = gw_res_int (info.kernel_res, "gw.default.show", 20);
822 if (us->hits >= info.next_position + default_show)
824 present (us->name, info.next_position, default_show,
826 info.next_position += default_show;
828 else if (us->hits >= info.next_position)
830 present (us->name, info.next_position,
831 us->hits - info.next_position + 1,
833 info.next_position = us->hits + 1;
836 else /* display error message */
838 fprintf (reply_fd, "%s\n",
839 gw_res_get (info.kernel_res, "gw.err.no.set",
840 "No result-set generated"));
847 static void show_def (void)
849 fprintf (reply_fd, "format %s\n", gw_res_get
850 (info.kernel_res, "gw.display.format", ""));
851 fprintf (reply_fd, "autoshow %s\n", gw_res_get
852 (info.kernel_res, "gw.auto.show", ""));
853 fprintf (reply_fd, "defaultshow %s\n", gw_res_get
854 (info.kernel_res, "gw.default.show", ""));
855 fprintf (reply_fd, "language %s\n", gw_res_get
856 (info.kernel_res, "gw.language", ""));
859 static int exec_def (struct ccl_token *list)
861 const char *name = NULL;
864 static struct command_word def_tab [] =
866 { "reset", "reset" },
869 { "autoshow", "autoshow" },
870 { "defaultshow", "defaultshow" },
871 { "lang", "language" },
877 sprintf (fname, "%s/user.%d.r", gw_res_get (info.kernel_res,
881 if (list->kind == CCL_TOK_EOL)
885 int setting_no = command_search (def_tab, list, "ccl.token.");
889 fprintf (reply_fd, "Unknown setting in def\n");
898 else if (setting_no == 2)
904 if (list->kind == CCL_TOK_EOL)
906 strncpy (value, list->name, 127);
907 value[(size_t) list->len] = '\0';
911 name = "gw.display.format";
914 name = "gw.auto.show";
917 name = "gw.default.show";
920 name = "gw.language";
925 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
927 gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
928 gw_res_put (info.kernel_res, name, value, fname);
929 gw_res_commit (info.kernel_res, fname);
938 * exec_command: parse and execute ccl command in str.
939 * str: ccl command string
940 * stop_flag pointer to integer. On completion the integer
941 * is 1 (stop) or 2 (continue); 0 (other command)
942 * return: 0 success; non-zero otherwise
944 static int exec_command (const char *str, int *stop_flag)
946 static struct command_word command_tab [] =
953 { "continue", "continue" },
954 { "status", "status" },
956 { "target", "target" },
958 { "account", "account" },
962 struct ccl_token *cmd = ccl_tokenize (str);
966 if (cmd->kind != CCL_TOK_EOL &&
967 (no = command_search (command_tab, cmd, "ccl.command.")))
969 if (no == 1 || no == 2 || no == 3) /* find/show/base? */
971 if (!info.zass) /* open if not already opened */
973 fprintf (reply_fd, "\n> %s\n", str);
974 if (!info.zass) /* fail? */
976 fprintf (reply_fd, "%s\n",
977 gw_res_get (info.kernel_res, "gw.err.no.target",
978 "No connection established - "
984 fprintf (reply_fd, "\n> %s\n", str);
988 return exec_find (cmd->next, str);
990 return exec_show (cmd->next);
992 return exec_base (cmd->next);
994 return exec_help (cmd->next);
995 case 6: /* continue */
999 return exec_status (cmd->next);
1003 case 9: /* target */
1004 return exec_target (cmd->next);
1006 return exec_def (cmd->next);
1008 return exec_account (cmd->next);
1010 fprintf (reply_fd, "%s\n",
1011 gw_res_get (info.kernel_res, "gw.err.unimplemented",
1012 "Not implemented yet"));
1017 fprintf (reply_fd, "\n> %s\n", str);
1018 fprintf (reply_fd, " ^ %s\n",
1019 gw_res_get (info.kernel_res, "gw.err.unknown.command",
1021 "Use help to see list of commands"));
1026 int urp_start (int continuation, struct str_queue *queue)
1028 char subject_str[128];
1030 info.command_no = 0;
1031 info.reply_fname = NULL;
1033 if (email_header (queue, info.from_str, subject_str))
1035 gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
1038 tty_init (stdout, 40, 70);
1041 info.reply_fname = (char *)
1042 tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL),
1043 gw_res_get (info.kernel_res,
1044 "gw.reply.tmp.prefix", "gwr"));
1046 reply_fd = fopen (info.reply_fname, "w");
1049 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "Cannot create %s",
1053 tty_init (reply_fd, 0, 0);
1054 fprintf (reply_fd, "From: %s\n",
1055 gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
1056 fprintf (reply_fd, "Subject: ");
1058 fprintf (reply_fd, "Z39.50 Re: %s", subject_str);
1060 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1063 fprintf (reply_fd, "\n");
1064 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", info.from_str);
1067 gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
1068 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
1069 "Email->Z39.50 gateway"));
1071 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1077 int urp_command (struct str_queue *queue)
1082 while (str_queue_deq (queue, line_buf, LINE_MAX))
1084 if (line_buf[0] == '\n')
1085 if (info.command_no)
1087 while (str_queue_deq (queue, 0, 0))
1093 if ((cp = strchr (line_buf, '\n')))
1095 gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
1096 if (isalpha (line_buf[0]))
1098 exec_command (line_buf, &stop_flag);
1101 info.command_no++; /* prevent help! */
1102 while (str_queue_deq (queue, line_buf, LINE_MAX))
1114 if (!info.command_no)
1116 fprintf (reply_fd, "%s\n",
1117 gw_res_get (info.kernel_res, "gw.err.nullbody", "No body"));
1126 assert (info.reply_fname);
1130 mta = gw_res_get (info.kernel_res, "gw.reply.mta",
1131 "/usr/lib/sendmail");
1132 sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname);
1134 mta_code = system (cmd);
1136 gw_log (GW_LOG_FATAL, KERNEL_LOG,
1137 "Reply '%s' got exit code %d", cmd, mta_code);
1139 unlink (info.reply_fname);
1141 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str);