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.41 1995/07/03 08:20:18 adam
49 * More help information and better diagnostics.
51 * Revision 1.40 1995/05/23 08:13:00 adam
54 * Revision 1.39 1995/05/22 14:57:30 adam
55 * Next default record position also set by last p=... in show.
57 * Revision 1.38 1995/05/19 13:26:00 adam
58 * Bug fixes. Better command line options.
60 * Revision 1.37 1995/05/18 12:03:09 adam
61 * Bug fixes and minor improvements.
63 * Revision 1.36 1995/05/17 10:51:33 adam
64 * Added a few more error checks to the show command.
66 * Revision 1.35 1995/05/16 09:40:43 adam
67 * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
69 * Revision 1.34 1995/05/04 10:40:08 adam
70 * More work on Def-settings.
72 * Revision 1.33 1995/05/03 16:34:19 adam
73 * CCL def command, i.e. user definitions - saved as resource files.
75 * Revision 1.32 1995/05/03 07:37:46 adam
76 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
77 * are used when possible.
79 * Revision 1.31 1995/05/01 12:43:38 adam
80 * First work on resource monitor program.
82 * Revision 1.30 1995/04/20 16:10:47 adam
83 * Modified to work with non-blocking zass-api. Not using non-blocking
86 * Revision 1.29 1995/04/19 16:01:58 adam
87 * Some hacks to get the FIFO communication work!! Isn't reliable.
88 * Resource gw.account added - default account info.
90 * Revision 1.28 1995/04/19 13:19:09 adam
91 * New command: account - for authentication.
93 * Revision 1.27 1995/04/19 10:46:19 adam
94 * Persistency works much better now. New command: status - history-like
96 * Revision 1.26 1995/04/19 07:31:12 adam
97 * First work on Z39.50 persistence.
99 * Revision 1.25 1995/04/17 09:34:33 adam
100 * Timeout (idletime) adjustable. Minor changes in kernel.
102 * Revision 1.24 1995/03/28 11:42:35 adam
103 * First use of string-queue utility.
105 * Revision 1.23 1995/03/28 08:01:28 adam
106 * FIFO existence is used to test for a running kernel.
108 * Revision 1.22 1995/03/27 12:51:05 adam
109 * New log level in use: GW_LOG_ERRNO.
111 * Revision 1.21 1995/03/27 08:24:04 adam
112 * First use of gip interface and gw-db.
113 * First work on eti program.
115 * Revision 1.20 1995/03/03 17:19:17 adam
116 * Smarter presentation. Bug fix in email header interpretation.
118 * Revision 1.19 1995/03/02 09:32:11 adam
119 * New presentation formats. f0=full, f1=brief, f2=mid
121 * Revision 1.18 1995/03/01 14:32:26 adam
122 * Better diagnostics. Default is, that only one database selected when
125 * Revision 1.17 1995/02/28 13:16:26 adam
126 * Configurable From: added.
128 * Revision 1.16 1995/02/23 10:08:20 adam
129 * Added logging of all user commands.
131 * Revision 1.15 1995/02/23 08:32:17 adam
134 * Revision 1.13 1995/02/22 16:54:42 adam
135 * Qualifiers of LOC target updated. More logging messages.
137 * Revision 1.12 1995/02/22 15:51:51 adam
138 * Bug fix: swap of parameter number and offset in function present.
140 * Revision 1.11 1995/02/22 15:22:33 adam
141 * Much more checking of run-time state. Show command never retrieves
142 * more records than indicated by the previous search request. Help
143 * command available. The maximum number of records retrieved can be
146 * Revision 1.10 1995/02/22 08:51:35 adam
147 * Output function can be customized in fml, which is used to print
148 * the reply to reply_fd.
150 * Revision 1.9 1995/02/21 17:46:21 adam
153 * Revision 1.8 1995/02/21 12:12:00 adam
154 * Diagnostic record with error info. observed.
156 * Revision 1.7 1995/02/20 21:16:20 adam
157 * FML support. Bug fixes. Profile for drewdb.
159 * Revision 1.6 1995/02/17 14:41:14 quinn
160 * Added simple display of records.
162 * Revision 1.5 1995/02/17 14:22:13 adam
163 * First steps of CCL show command. Not finished yet.
165 * Revision 1.4 1995/02/17 09:08:36 adam
166 * Reply with subject. CCL base command implemented.
168 * Revision 1.3 1995/02/16 18:35:09 adam
169 * First use of Zdist library. Search requests are supported.
170 * Present requests are not supported yet.
172 * Revision 1.2 1995/02/16 13:21:00 adam
173 * Organization of resource files for targets and conversion
174 * language implemented.
176 * Revision 1.1 1995/02/15 17:45:30 adam
177 * First version of email gateway kernel. Email requests are read
178 * from stdin. The output is transferred to an MTA if 'From' is
179 * found in the header - or stdout if absent. No Z39.50 client is used.
185 info/status (other name?)
186 better persistence diagnostics
189 automatic information about target-aliases: name, query-support, etc.
202 #include <strqueue.h>
205 static void present (const char *set, int offset, int number,
206 struct ccl_token *format_token);
208 static char line_buf[LINE_MAX+1];
210 static void put_esc_str (const char *s)
216 int reopen_target (void)
220 gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
221 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target");
222 info.zass = zass_open (info.hostname, info.port, NULL, /* complete */
223 *info.account ? info.account : NULL);
226 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d",
227 info.hostname, info.port);
228 fprintf (reply_fd, "%s %s:%d\n",
229 gw_res_get (info.kernel_res, "gw.err.connect",
230 "Cannot connect to target"),
231 info.hostname, info.port);
234 v = gw_res_get (info.kernel_res, "gw.description", NULL);
238 fprintf (reply_fd, "\n");
240 fprintf (reply_fd, "%s %s:%d\n",
241 gw_res_get (info.kernel_res, "gw.msg.connect",
242 "Connection established to"),
243 info.hostname, info.port);
245 fprintf (reply_fd, "%s: %s\n",
246 gw_res_get (info.kernel_res, "gw.msg.databases",
247 "Available databases"),
250 fprintf (reply_fd, "%s: %s\n",
251 gw_res_get (info.kernel_res, "gw.msg.database",
252 "Selected databases"),
255 fprintf (reply_fd, "set=%d\n", info.setno);
257 fprintf (reply_fd, "set=Default\n");
261 struct command_word {
263 char *resource_suffix;
266 static int command_search (struct command_word *tab, struct ccl_token *cmd,
267 const char *resource_prefix)
271 assert (resource_prefix);
274 while (tab->default_value)
276 char *cp, command_names[60];
277 char resource_name[60];
280 sprintf (resource_name, "%s%s", resource_prefix,
281 tab->resource_suffix);
282 v = gw_res_get (info.kernel_res, resource_name, tab->default_value);
284 strcpy (command_names, v);
290 if ((split = strchr (cp, ' ')))
292 if (cmd->len == strlen(cp) &&
293 !memcmp (cmd->name, cp, cmd->len))
305 static struct error_no_struct {
308 } error_ccl_tab[] = {
310 { CCL_ERR_TERM_EXPECTED, "term.expected" },
311 { CCL_ERR_RP_EXPECTED, "rp.expected" },
312 { CCL_ERR_SETNAME_EXPECTED, "setname.expected" },
313 { CCL_ERR_OP_EXPECTED, "op.expected" },
314 { CCL_ERR_BAD_RP, "bad.rp" },
315 { CCL_ERR_UNKNOWN_QUAL, "unknown.qual" },
316 { CCL_ERR_DOUBLE_QUAL, "double.qual" },
317 { CCL_ERR_EQ_EXPECTED, "eq.expected" },
318 { CCL_ERR_BAD_RELATION, "bad.relation" },
319 { CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" },
320 { CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" },
321 { CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" },
325 static char *error_no_search (struct error_no_struct *tab, int no)
327 struct error_no_struct *p = tab;
328 while (p->resource_name)
331 return p->resource_name;
337 static int email_header (struct str_queue *sq,
338 char *from_str, char *subject_str)
342 while (str_queue_deq (sq, line_buf, LINE_MAX))
344 if (line_buf[0] == '\n')
346 if (memcmp (line_buf, "From ", 5) == 0)
347 sscanf (line_buf+4, "%s", from_str);
348 if (memcmp (line_buf, "Subject: ", 9) == 0 &&
349 sscanf (line_buf+9, "%s", subject_str+1) == 1)
350 strcpy (subject_str, line_buf+9);
355 static void help_general (void)
357 put_esc_str (gw_res_get (info.kernel_res, "gw.help.general",
358 "Commands available in this service:\n"));
361 static int exec_help (struct ccl_token *list)
363 static char *sep = "-------------------------------\\n";
367 put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
368 "target <name> - selects a given target\n"));
371 put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
372 "base <base>.. - selects databases\n"));
375 put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
376 "find <query> - performs a search request\n"));
379 put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
380 "show <spec> - retrieves and displays "
383 put_esc_str (gw_res_get (info.kernel_res, "gw.help.def",
384 "def <setting> <value> sets/gets definitons\n"));
386 put_esc_str (gw_res_get (info.kernel_res, "gw.help.account",
387 "account <str> sets authentication string\n"));
391 static void display_diag_error (int code, const char *addinfo)
395 sprintf (str, "gw.bib1.diag.%d", code);
396 fprintf (reply_fd, "%s %d:\n %s: '%s'\n",
397 gw_res_get (info.kernel_res, "gw.msg.z39errcode",
400 gw_res_get (info.kernel_res, str, ""), addinfo);
403 static int exec_find (struct ccl_token *list, const char *search_str)
405 const struct zass_searchent *p;
406 struct gw_user_set *us;
410 struct ccl_rpn_node *rpn;
414 if (info.setno == -1)
415 strcpy (setname, "Default");
417 sprintf (setname, "%d", info.setno);
418 info.next_position = 1;
421 rpn = ccl_find (info.bibset, list, &error, &pos);
424 const char *v = NULL, *n;
427 fprintf (reply_fd, " %*s^ - ", pos - line_buf, " ");
429 n = error_no_search (error_ccl_tab, error);
432 sprintf (name, "gw.err.%s", n);
433 v = gw_res_get (info.kernel_res, name, NULL);
436 v = ccl_err_msg (error);
437 fprintf (reply_fd, "%s\n", v);
440 ccl_pr_tree (rpn, reply_fd);
441 fprintf (reply_fd, "\n");
443 if (!*info.database )
445 fprintf (reply_fd, "%s\n",
446 gw_res_get (info.kernel_res, "gw.err.no.database",
447 "You must select database"));
450 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
453 p = zass_p_search (info.zass, rpn, setname, info.database, info.sets);
456 fprintf (reply_fd, "%s\n",
457 gw_res_get (info.kernel_res, "gw.err.search.fail",
461 if (p->errcode != -1)
463 display_diag_error (p->errcode, p->errstring);
466 fprintf (reply_fd, "%d %s %s\n", p->num,
467 gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s) in set "),
469 us = user_set_add (setname, p->num, info.database, rpn, 1, search_str);
470 autoshow = gw_res_int (info.kernel_res, "gw.auto.show", 0);
471 if (autoshow && p->num > 0)
473 if (autoshow > p->num)
475 present (setname, 1, p->num, NULL);
476 info.next_position = 1+p->num;
480 present (setname, 1, autoshow, NULL);
481 info.next_position = 1+autoshow;
487 static int exec_account (struct ccl_token *list)
489 if (list->kind != CCL_TOK_EOL)
492 memcpy (info.account, list->name, len);
493 info.target[len] = '\0';
496 *info.account = '\0';
500 static int exec_target (struct ccl_token *list)
503 if (list->kind == CCL_TOK_EOL)
506 memcpy (info.target, list->name, len);
507 info.target [len] = '\0';
510 return reopen_target ();
513 static void exec_status_r (struct gw_user_set *sp)
517 exec_status_r (sp->prev);
518 fprintf (reply_fd, "%6s %7d %12.12s %.50s\n", sp->name, sp->hits,
519 sp->database, sp->search_str);
522 static int exec_status (struct ccl_token *list)
524 fprintf (reply_fd, "%s\n",
525 gw_res_get (info.kernel_res,
527 " Name Hits Database Find"));
528 exec_status_r (info.sets);
532 static int exec_base (struct ccl_token *list)
534 struct ccl_token *li = list;
538 if (list->kind == CCL_TOK_EOL)
540 free (info.database);
541 while (li->kind != CCL_TOK_EOL)
545 if (li->kind == CCL_TOK_COMMA)
548 info.database = malloc (len);
549 assert (info.database );
552 while (li->kind != CCL_TOK_EOL)
554 memcpy (info.database+len, li->name, li->len);
556 info.database[len++] = ',';
558 if (li->kind == CCL_TOK_COMMA)
561 info.database[len-1] = '\0';
565 static void present (const char *set, int offset, int number,
566 struct ccl_token *format_token)
568 const struct zass_presentent *zp;
573 max_number = gw_res_int (info.kernel_res, "gw.max.show", 200);
574 if (number > max_number)
576 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
577 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
579 zp = zass_p_present(info.zass, (char *) set, offset, number);
584 int record_log_fd = -1;
585 const char *record_log_name;
587 record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
591 record_log_fd = open (record_log_name,
592 O_WRONLY|O_CREAT|O_APPEND, 0666);
593 if (record_log_fd == -1)
594 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "Cannot open %s",
597 fprintf (reply_fd, gw_res_get (info.kernel_res,
599 "Got %d records from set %s"),
601 fprintf (reply_fd, "\n");
602 for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
606 const char *arg_ar[5];
608 fprintf (reply_fd, "--- %d/%d ---\n",
609 i+offset, offset+zp->num-1);
610 if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
612 if (pp->which == ZASS_REC_DIAG)
614 display_diag_error (pp->errcode, pp->errstring);
617 else if (pp->which != ZASS_REC_USMARC)
619 fprintf (reply_fd, "Unknown record kind %d\n",
624 if (record_log_fd != -1)
625 write (record_log_fd, pp->record, strlen(pp->record));
626 rec = iso2709_cvt (pp->record);
631 gw_res_get (info.kernel_res,
632 "gw.display.format", ""));
635 len = format_token->len;
636 if (len >= sizeof(format_str))
637 len = sizeof(format_str)-1;
638 memcpy (format_str, format_token->name, len);
639 format_str[len] = '\0';
641 if (info.fml && *format_str &&
642 (!strcmp (format_str, "0") || !strcmp (format_str, "1")
643 || !strcmp(format_str, "2")))
646 arg_ar[1] = format_str;
647 arg_ar[2] = " \\list";
648 arg_ar[3] = marc_to_str (info.fml, rec);
650 fml_exec_call_argv (info.fml, arg_ar);
653 iso2709_display (rec, reply_fd);
655 iso2709_display (rec, reply_fd);
660 fprintf (reply_fd, "Not a MARC record\n");
662 if (record_log_fd != -1)
663 close (record_log_fd);
667 static int exec_show (struct ccl_token *list)
669 static struct command_word show_tab [] =
676 struct ccl_token *set_token = NULL;
677 struct ccl_token *format_token = NULL;
678 struct ccl_token *li = list;
679 int no_of_present = 0;
682 while (li->kind != CCL_TOK_EOL)
685 if (li->next->kind == CCL_TOK_EQ)
687 if (li->kind == CCL_TOK_SET) /* set = <name> ? */
694 modifier_no = command_search (show_tab, li, "ccl.token.");
697 fprintf (reply_fd, "Unknown modifier in show\n");
701 if (modifier_no == 1) /* f = <name> ? */
703 else if (modifier_no == 2) /* p = <name> ? */
705 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
706 && li->next->kind == CCL_TOK_MINUS
707 && li->next->next != CCL_TOK_EOL)
713 fprintf (reply_fd, "%s\n", "Missing token after '='");
721 memcpy (tmp_str, li->name, len);
723 if (atoi(tmp_str) <= 0)
725 fprintf (reply_fd, "%s\n",
726 gw_res_get (info.kernel_res, "gw.err.bad.show",
734 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
737 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
741 while (li->kind != CCL_TOK_EOL)
747 if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
749 modifier_no = command_search (show_tab, li, "ccl.token.");
751 if (modifier_no == 2) /* p = <name> ? */
753 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
754 && li->next->kind == CCL_TOK_MINUS
755 && li->next->next != CCL_TOK_EOL)
758 memcpy (tmp_str, li->name, len);
759 tmp_str [len] = '\0';
760 offset = atoi (tmp_str);
764 memcpy (tmp_str, li->name, len);
765 tmp_str [len] = '\0';
766 number = atoi (tmp_str) - offset + 1;
769 fprintf (reply_fd, "%s\n",
770 gw_res_get (info.kernel_res,
773 "greater than ending position"));
780 memcpy (tmp_str, li->name, len);
781 tmp_str [len] = '\0';
782 offset = atoi (tmp_str);
788 else if (li->kind == CCL_TOK_TERM)
791 memcpy (tmp_str, li->name, len);
793 number = atoi (tmp_str);
797 if (offset > 0 && number > 0)
799 struct gw_user_set *us;
803 len = set_token->len;
804 memcpy (tmp_str, set_token->name, len);
806 us = user_set_search (tmp_str);
809 us = user_set_search (NULL);
810 if (us && us->hits != -1) /* proper result-set? */
812 if (offset <= us->hits)
814 if (offset+number-1 > us->hits)
815 number = us->hits - offset+1;
816 present (us->name, offset, number, format_token);
817 info.next_position = offset+number;
820 else if (!no_of_present) /* display error message once! */
822 fprintf (reply_fd, "%s\n",
823 gw_res_get (info.kernel_res, "gw.err.no.set",
824 "No result-set generated"));
829 if (!no_of_present) /* no records shown so far? */
831 struct gw_user_set *us;
834 us = user_set_search (NULL);
835 if (us && us->hits != -1) /* proper result-set? */
837 default_show = gw_res_int (info.kernel_res, "gw.default.show", 20);
838 if (us->hits >= info.next_position + default_show)
840 present (us->name, info.next_position, default_show,
842 info.next_position += default_show;
844 else if (us->hits >= info.next_position)
846 present (us->name, info.next_position,
847 us->hits - info.next_position + 1,
849 info.next_position = us->hits + 1;
852 else /* display error message */
854 fprintf (reply_fd, "%s\n",
855 gw_res_get (info.kernel_res, "gw.err.no.set",
856 "No result-set generated"));
863 static void show_def (void)
865 fprintf (reply_fd, "format %s\n", gw_res_get
866 (info.kernel_res, "gw.display.format", ""));
867 fprintf (reply_fd, "autoshow %s\n", gw_res_get
868 (info.kernel_res, "gw.auto.show", ""));
869 fprintf (reply_fd, "defaultshow %s\n", gw_res_get
870 (info.kernel_res, "gw.default.show", ""));
871 fprintf (reply_fd, "language %s\n", gw_res_get
872 (info.kernel_res, "gw.language", ""));
875 static int exec_def (struct ccl_token *list)
877 const char *name = NULL;
880 static struct command_word def_tab [] =
882 { "reset", "reset" },
885 { "autoshow", "autoshow" },
886 { "defaultshow", "defaultshow" },
887 { "lang", "language" },
893 sprintf (fname, "user.%d.r", info.userid);
895 if (list->kind == CCL_TOK_EOL)
899 int setting_no = command_search (def_tab, list, "ccl.token.");
903 fprintf (reply_fd, "Unknown setting in def\n");
912 else if (setting_no == 2)
918 if (list->kind == CCL_TOK_EOL)
920 strncpy (value, list->name, 127);
921 value[(size_t) list->len] = '\0';
925 name = "gw.display.format";
928 name = "gw.auto.show";
931 name = "gw.default.show";
934 name = "gw.language";
939 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
941 gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
942 gw_res_put (info.kernel_res, name, value, fname);
943 gw_res_commit (info.kernel_res, fname);
952 * exec_command: parse and execute ccl command in str.
953 * str: ccl command string
954 * stop_flag pointer to integer. On completion the integer
955 * is 1 (stop) or 2 (continue); 0 (other command)
956 * return: 0 success; non-zero otherwise
958 static int exec_command (const char *str, int *stop_flag)
960 static struct command_word command_tab [] =
967 { "continue", "continue" },
968 { "status", "status" },
970 { "target", "target" },
972 { "account", "account" },
976 struct ccl_token *cmd = ccl_tokenize (str);
980 if (cmd->kind != CCL_TOK_EOL &&
981 (no = command_search (command_tab, cmd, "ccl.command.")))
983 if (no == 1 || no == 2 || no == 3) /* find/show/base? */
985 if (!info.zass) /* open if not already opened */
987 fprintf (reply_fd, "\n> %s\n", str);
988 if (!info.zass) /* fail? */
990 fprintf (reply_fd, "\n%s\n",
991 gw_res_get (info.kernel_res, "gw.err.no.target",
992 "No connection established - "
998 fprintf (reply_fd, "\n> %s\n", str);
1002 return exec_find (cmd->next, str);
1004 return exec_show (cmd->next);
1006 return exec_base (cmd->next);
1008 return exec_help (cmd->next);
1009 case 6: /* continue */
1012 case 7: /* status */
1013 return exec_status (cmd->next);
1017 case 9: /* target */
1018 return exec_target (cmd->next);
1020 return exec_def (cmd->next);
1022 return exec_account (cmd->next);
1024 fprintf (reply_fd, "%s\n",
1025 gw_res_get (info.kernel_res, "gw.err.unimplemented",
1026 "Not implemented yet"));
1031 fprintf (reply_fd, "\n> %s\n", str);
1032 fprintf (reply_fd, " ^ %s\n",
1033 gw_res_get (info.kernel_res, "gw.err.unknown.command",
1035 "Use help to see list of commands"));
1040 int urp_start (int continuation, struct str_queue *queue)
1042 char subject_str[128];
1044 info.command_no = 0;
1045 info.reply_fname = NULL;
1047 if (email_header (queue, info.from_str, subject_str))
1049 gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
1052 tty_init (stdout, 40, 70);
1055 info.reply_fname = (char *)
1056 tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL),
1057 gw_res_get (info.kernel_res,
1058 "gw.reply.tmp.prefix", "gwr"));
1060 reply_fd = fopen (info.reply_fname, "w");
1063 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "Cannot create %s",
1067 tty_init (reply_fd, 0, 0);
1068 fprintf (reply_fd, "From: %s\n",
1069 gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
1070 fprintf (reply_fd, "Subject: ");
1072 fprintf (reply_fd, "Z39.50 Re: %s", subject_str);
1074 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1077 fprintf (reply_fd, "\n");
1078 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", info.from_str);
1081 gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
1082 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
1083 "Email->Z39.50 gateway"));
1085 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1091 int urp_command (struct str_queue *queue)
1096 while (str_queue_deq (queue, line_buf, LINE_MAX))
1098 if (line_buf[0] == '\n')
1099 if (info.command_no)
1101 while (str_queue_deq (queue, 0, 0))
1107 if ((cp = strchr (line_buf, '\n')))
1109 gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
1110 if (isalpha (line_buf[0]))
1112 exec_command (line_buf, &stop_flag);
1115 info.command_no++; /* prevent help! */
1116 while (str_queue_deq (queue, line_buf, LINE_MAX))
1128 if (!info.command_no)
1130 fprintf (reply_fd, "%s\n",
1131 gw_res_get (info.kernel_res, "gw.err.nullbody", "No body"));
1140 assert (info.reply_fname);
1144 mta = gw_res_get (info.kernel_res, "gw.reply.mta",
1145 "/usr/lib/sendmail");
1146 sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname);
1147 mta_code = system (cmd);
1149 gw_log (GW_LOG_FATAL, KERNEL_LOG,
1150 "Reply '%s' got exit code %d", cmd, mta_code);
1152 unlink (info.reply_fname);
1153 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str);