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.42 1995/07/03 12:59:29 adam
49 * New option for eti: -c dir to chdir before start.
50 * Setting change: gw.max.show defaults to 100.
52 * Revision 1.41 1995/07/03 08:20:18 adam
53 * More help information and better diagnostics.
55 * Revision 1.40 1995/05/23 08:13:00 adam
58 * Revision 1.39 1995/05/22 14:57:30 adam
59 * Next default record position also set by last p=... in show.
61 * Revision 1.38 1995/05/19 13:26:00 adam
62 * Bug fixes. Better command line options.
64 * Revision 1.37 1995/05/18 12:03:09 adam
65 * Bug fixes and minor improvements.
67 * Revision 1.36 1995/05/17 10:51:33 adam
68 * Added a few more error checks to the show command.
70 * Revision 1.35 1995/05/16 09:40:43 adam
71 * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
73 * Revision 1.34 1995/05/04 10:40:08 adam
74 * More work on Def-settings.
76 * Revision 1.33 1995/05/03 16:34:19 adam
77 * CCL def command, i.e. user definitions - saved as resource files.
79 * Revision 1.32 1995/05/03 07:37:46 adam
80 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
81 * are used when possible.
83 * Revision 1.31 1995/05/01 12:43:38 adam
84 * First work on resource monitor program.
86 * Revision 1.30 1995/04/20 16:10:47 adam
87 * Modified to work with non-blocking zass-api. Not using non-blocking
90 * Revision 1.29 1995/04/19 16:01:58 adam
91 * Some hacks to get the FIFO communication work!! Isn't reliable.
92 * Resource gw.account added - default account info.
94 * Revision 1.28 1995/04/19 13:19:09 adam
95 * New command: account - for authentication.
97 * Revision 1.27 1995/04/19 10:46:19 adam
98 * Persistency works much better now. New command: status - history-like
100 * Revision 1.26 1995/04/19 07:31:12 adam
101 * First work on Z39.50 persistence.
103 * Revision 1.25 1995/04/17 09:34:33 adam
104 * Timeout (idletime) adjustable. Minor changes in kernel.
106 * Revision 1.24 1995/03/28 11:42:35 adam
107 * First use of string-queue utility.
109 * Revision 1.23 1995/03/28 08:01:28 adam
110 * FIFO existence is used to test for a running kernel.
112 * Revision 1.22 1995/03/27 12:51:05 adam
113 * New log level in use: GW_LOG_ERRNO.
115 * Revision 1.21 1995/03/27 08:24:04 adam
116 * First use of gip interface and gw-db.
117 * First work on eti program.
119 * Revision 1.20 1995/03/03 17:19:17 adam
120 * Smarter presentation. Bug fix in email header interpretation.
122 * Revision 1.19 1995/03/02 09:32:11 adam
123 * New presentation formats. f0=full, f1=brief, f2=mid
125 * Revision 1.18 1995/03/01 14:32:26 adam
126 * Better diagnostics. Default is, that only one database selected when
129 * Revision 1.17 1995/02/28 13:16:26 adam
130 * Configurable From: added.
132 * Revision 1.16 1995/02/23 10:08:20 adam
133 * Added logging of all user commands.
135 * Revision 1.15 1995/02/23 08:32:17 adam
138 * Revision 1.13 1995/02/22 16:54:42 adam
139 * Qualifiers of LOC target updated. More logging messages.
141 * Revision 1.12 1995/02/22 15:51:51 adam
142 * Bug fix: swap of parameter number and offset in function present.
144 * Revision 1.11 1995/02/22 15:22:33 adam
145 * Much more checking of run-time state. Show command never retrieves
146 * more records than indicated by the previous search request. Help
147 * command available. The maximum number of records retrieved can be
150 * Revision 1.10 1995/02/22 08:51:35 adam
151 * Output function can be customized in fml, which is used to print
152 * the reply to reply_fd.
154 * Revision 1.9 1995/02/21 17:46:21 adam
157 * Revision 1.8 1995/02/21 12:12:00 adam
158 * Diagnostic record with error info. observed.
160 * Revision 1.7 1995/02/20 21:16:20 adam
161 * FML support. Bug fixes. Profile for drewdb.
163 * Revision 1.6 1995/02/17 14:41:14 quinn
164 * Added simple display of records.
166 * Revision 1.5 1995/02/17 14:22:13 adam
167 * First steps of CCL show command. Not finished yet.
169 * Revision 1.4 1995/02/17 09:08:36 adam
170 * Reply with subject. CCL base command implemented.
172 * Revision 1.3 1995/02/16 18:35:09 adam
173 * First use of Zdist library. Search requests are supported.
174 * Present requests are not supported yet.
176 * Revision 1.2 1995/02/16 13:21:00 adam
177 * Organization of resource files for targets and conversion
178 * language implemented.
180 * Revision 1.1 1995/02/15 17:45:30 adam
181 * First version of email gateway kernel. Email requests are read
182 * from stdin. The output is transferred to an MTA if 'From' is
183 * found in the header - or stdout if absent. No Z39.50 client is used.
189 info/status (other name?)
190 better persistence diagnostics
193 automatic information about target-aliases: name, query-support, etc.
206 #include <strqueue.h>
209 static void present (const char *set, int offset, int number,
210 struct ccl_token *format_token);
212 static char line_buf[LINE_MAX+1];
214 static void put_esc_str (const char *s)
220 int reopen_target (void)
224 gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
225 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target");
226 info.zass = zass_open (info.hostname, info.port, NULL, /* complete */
227 *info.account ? info.account : NULL);
230 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d",
231 info.hostname, info.port);
232 fprintf (reply_fd, "%s %s:%d\n",
233 gw_res_get (info.kernel_res, "gw.err.connect",
234 "Cannot connect to target"),
235 info.hostname, info.port);
238 v = gw_res_get (info.kernel_res, "gw.description", NULL);
242 fprintf (reply_fd, "\n");
244 fprintf (reply_fd, "%s %s:%d\n",
245 gw_res_get (info.kernel_res, "gw.msg.connect",
246 "Connection established to"),
247 info.hostname, info.port);
249 fprintf (reply_fd, "%s: %s\n",
250 gw_res_get (info.kernel_res, "gw.msg.databases",
251 "Available databases"),
254 fprintf (reply_fd, "%s: %s\n",
255 gw_res_get (info.kernel_res, "gw.msg.database",
256 "Selected databases"),
259 fprintf (reply_fd, "set=%d\n", info.setno);
261 fprintf (reply_fd, "set=Default\n");
265 struct command_word {
267 char *resource_suffix;
270 static int command_search (struct command_word *tab, struct ccl_token *cmd,
271 const char *resource_prefix)
275 assert (resource_prefix);
278 while (tab->default_value)
280 char *cp, command_names[60];
281 char resource_name[60];
284 sprintf (resource_name, "%s%s", resource_prefix,
285 tab->resource_suffix);
286 v = gw_res_get (info.kernel_res, resource_name, tab->default_value);
288 strcpy (command_names, v);
294 if ((split = strchr (cp, ' ')))
296 if (cmd->len == strlen(cp) &&
297 !memcmp (cmd->name, cp, cmd->len))
309 static struct error_no_struct {
312 } error_ccl_tab[] = {
314 { CCL_ERR_TERM_EXPECTED, "term.expected" },
315 { CCL_ERR_RP_EXPECTED, "rp.expected" },
316 { CCL_ERR_SETNAME_EXPECTED, "setname.expected" },
317 { CCL_ERR_OP_EXPECTED, "op.expected" },
318 { CCL_ERR_BAD_RP, "bad.rp" },
319 { CCL_ERR_UNKNOWN_QUAL, "unknown.qual" },
320 { CCL_ERR_DOUBLE_QUAL, "double.qual" },
321 { CCL_ERR_EQ_EXPECTED, "eq.expected" },
322 { CCL_ERR_BAD_RELATION, "bad.relation" },
323 { CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" },
324 { CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" },
325 { CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" },
329 static char *error_no_search (struct error_no_struct *tab, int no)
331 struct error_no_struct *p = tab;
332 while (p->resource_name)
335 return p->resource_name;
341 static int email_header (struct str_queue *sq,
342 char *from_str, char *subject_str)
346 while (str_queue_deq (sq, line_buf, LINE_MAX))
348 if (line_buf[0] == '\n')
350 if (memcmp (line_buf, "From ", 5) == 0)
351 sscanf (line_buf+4, "%s", from_str);
352 if (memcmp (line_buf, "Subject: ", 9) == 0 &&
353 sscanf (line_buf+9, "%s", subject_str+1) == 1)
354 strcpy (subject_str, line_buf+9);
359 static void help_general (void)
361 put_esc_str (gw_res_get (info.kernel_res, "gw.help.general",
362 "Commands available in this service:\n"));
365 static int exec_help (struct ccl_token *list)
367 static char *sep = "-------------------------------\\n";
371 put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
372 "target <name> - selects a given target\n"));
375 put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
376 "base <base>.. - selects databases\n"));
379 put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
380 "find <query> - performs a search request\n"));
383 put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
384 "show <spec> - retrieves and displays "
387 put_esc_str (gw_res_get (info.kernel_res, "gw.help.def",
388 "def <setting> <value> sets/gets definitons\n"));
390 put_esc_str (gw_res_get (info.kernel_res, "gw.help.account",
391 "account <str> sets authentication string\n"));
395 static void display_diag_error (int code, const char *addinfo)
399 sprintf (str, "gw.bib1.diag.%d", code);
400 fprintf (reply_fd, "%s %d:\n %s: '%s'\n",
401 gw_res_get (info.kernel_res, "gw.msg.z39errcode",
404 gw_res_get (info.kernel_res, str, ""), addinfo);
407 static int exec_find (struct ccl_token *list, const char *search_str)
409 const struct zass_searchent *p;
410 struct gw_user_set *us;
414 struct ccl_rpn_node *rpn;
418 if (info.setno == -1)
419 strcpy (setname, "Default");
421 sprintf (setname, "%d", info.setno);
422 info.next_position = 1;
425 rpn = ccl_find (info.bibset, list, &error, &pos);
428 const char *v = NULL, *n;
431 fprintf (reply_fd, " %*s^ - ", pos - line_buf, " ");
433 n = error_no_search (error_ccl_tab, error);
436 sprintf (name, "gw.err.%s", n);
437 v = gw_res_get (info.kernel_res, name, NULL);
440 v = ccl_err_msg (error);
441 fprintf (reply_fd, "%s\n", v);
444 ccl_pr_tree (rpn, reply_fd);
445 fprintf (reply_fd, "\n");
447 if (!*info.database )
449 fprintf (reply_fd, "%s\n",
450 gw_res_get (info.kernel_res, "gw.err.no.database",
451 "You must select database"));
454 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
457 p = zass_p_search (info.zass, rpn, setname, info.database, info.sets);
460 fprintf (reply_fd, "%s\n",
461 gw_res_get (info.kernel_res, "gw.err.search.fail",
465 if (p->errcode != -1)
467 display_diag_error (p->errcode, p->errstring);
470 fprintf (reply_fd, "%d %s %s\n", p->num,
471 gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s) in set "),
473 us = user_set_add (setname, p->num, info.database, rpn, 1, search_str);
474 autoshow = gw_res_int (info.kernel_res, "gw.auto.show", 0);
475 if (autoshow && p->num > 0)
477 if (autoshow > p->num)
479 present (setname, 1, p->num, NULL);
480 info.next_position = 1+p->num;
484 present (setname, 1, autoshow, NULL);
485 info.next_position = 1+autoshow;
491 static int exec_account (struct ccl_token *list)
493 if (list->kind != CCL_TOK_EOL)
496 memcpy (info.account, list->name, len);
497 info.target[len] = '\0';
500 *info.account = '\0';
504 static int exec_target (struct ccl_token *list)
507 if (list->kind == CCL_TOK_EOL)
510 memcpy (info.target, list->name, len);
511 info.target [len] = '\0';
514 return reopen_target ();
517 static void exec_status_r (struct gw_user_set *sp)
521 exec_status_r (sp->prev);
522 fprintf (reply_fd, "%6s %7d %12.12s %.50s\n", sp->name, sp->hits,
523 sp->database, sp->search_str);
526 static int exec_status (struct ccl_token *list)
528 fprintf (reply_fd, "%s\n",
529 gw_res_get (info.kernel_res,
531 " Name Hits Database Find"));
532 exec_status_r (info.sets);
536 static int exec_base (struct ccl_token *list)
538 struct ccl_token *li = list;
542 if (list->kind == CCL_TOK_EOL)
544 free (info.database);
545 while (li->kind != CCL_TOK_EOL)
549 if (li->kind == CCL_TOK_COMMA)
552 info.database = malloc (len);
553 assert (info.database );
556 while (li->kind != CCL_TOK_EOL)
558 memcpy (info.database+len, li->name, li->len);
560 info.database[len++] = ',';
562 if (li->kind == CCL_TOK_COMMA)
565 info.database[len-1] = '\0';
569 static void present (const char *set, int offset, int number,
570 struct ccl_token *format_token)
572 const struct zass_presentent *zp;
577 max_number = gw_res_int (info.kernel_res, "gw.max.show", 100);
578 if (number > max_number)
580 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
581 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
583 zp = zass_p_present(info.zass, (char *) set, offset, number);
588 int record_log_fd = -1;
589 const char *record_log_name;
591 record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
595 record_log_fd = open (record_log_name,
596 O_WRONLY|O_CREAT|O_APPEND, 0666);
597 if (record_log_fd == -1)
598 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "Cannot open %s",
601 fprintf (reply_fd, gw_res_get (info.kernel_res,
603 "Got %d records from set %s"),
605 fprintf (reply_fd, "\n");
606 for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
610 const char *arg_ar[5];
612 fprintf (reply_fd, "--- %d/%d ---\n",
613 i+offset, offset+zp->num-1);
614 if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
616 if (pp->which == ZASS_REC_DIAG)
618 display_diag_error (pp->errcode, pp->errstring);
621 else if (pp->which != ZASS_REC_USMARC)
623 fprintf (reply_fd, "Unknown record kind %d\n",
628 if (record_log_fd != -1)
629 write (record_log_fd, pp->record, strlen(pp->record));
630 rec = iso2709_cvt (pp->record);
635 gw_res_get (info.kernel_res,
636 "gw.display.format", ""));
639 len = format_token->len;
640 if (len >= sizeof(format_str))
641 len = sizeof(format_str)-1;
642 memcpy (format_str, format_token->name, len);
643 format_str[len] = '\0';
645 if (info.fml && *format_str &&
646 (!strcmp (format_str, "0") || !strcmp (format_str, "1")
647 || !strcmp(format_str, "2")))
650 arg_ar[1] = format_str;
651 arg_ar[2] = " \\list";
652 arg_ar[3] = marc_to_str (info.fml, rec);
654 fml_exec_call_argv (info.fml, arg_ar);
657 iso2709_display (rec, reply_fd);
659 iso2709_display (rec, reply_fd);
664 fprintf (reply_fd, "Not a MARC record\n");
666 if (record_log_fd != -1)
667 close (record_log_fd);
671 static int exec_show (struct ccl_token *list)
673 static struct command_word show_tab [] =
680 struct ccl_token *set_token = NULL;
681 struct ccl_token *format_token = NULL;
682 struct ccl_token *li = list;
683 int no_of_present = 0;
686 while (li->kind != CCL_TOK_EOL)
689 if (li->next->kind == CCL_TOK_EQ)
691 if (li->kind == CCL_TOK_SET) /* set = <name> ? */
698 modifier_no = command_search (show_tab, li, "ccl.token.");
701 fprintf (reply_fd, "Unknown modifier in show\n");
705 if (modifier_no == 1) /* f = <name> ? */
707 else if (modifier_no == 2) /* p = <name> ? */
709 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
710 && li->next->kind == CCL_TOK_MINUS
711 && li->next->next != CCL_TOK_EOL)
717 fprintf (reply_fd, "%s\n", "Missing token after '='");
725 memcpy (tmp_str, li->name, len);
727 if (atoi(tmp_str) <= 0)
729 fprintf (reply_fd, "%s\n",
730 gw_res_get (info.kernel_res, "gw.err.bad.show",
738 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
741 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
745 while (li->kind != CCL_TOK_EOL)
751 if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
753 modifier_no = command_search (show_tab, li, "ccl.token.");
755 if (modifier_no == 2) /* p = <name> ? */
757 if (li->kind != CCL_TOK_EOL /* p = <name> - <name> ? */
758 && li->next->kind == CCL_TOK_MINUS
759 && li->next->next != CCL_TOK_EOL)
762 memcpy (tmp_str, li->name, len);
763 tmp_str [len] = '\0';
764 offset = atoi (tmp_str);
768 memcpy (tmp_str, li->name, len);
769 tmp_str [len] = '\0';
770 number = atoi (tmp_str) - offset + 1;
773 fprintf (reply_fd, "%s\n",
774 gw_res_get (info.kernel_res,
777 "greater than ending position"));
784 memcpy (tmp_str, li->name, len);
785 tmp_str [len] = '\0';
786 offset = atoi (tmp_str);
792 else if (li->kind == CCL_TOK_TERM)
795 memcpy (tmp_str, li->name, len);
797 number = atoi (tmp_str);
801 if (offset > 0 && number > 0)
803 struct gw_user_set *us;
807 len = set_token->len;
808 memcpy (tmp_str, set_token->name, len);
810 us = user_set_search (tmp_str);
813 us = user_set_search (NULL);
814 if (us && us->hits != -1) /* proper result-set? */
816 if (offset <= us->hits)
818 if (offset+number-1 > us->hits)
819 number = us->hits - offset+1;
820 present (us->name, offset, number, format_token);
821 info.next_position = offset+number;
824 else if (!no_of_present) /* display error message once! */
826 fprintf (reply_fd, "%s\n",
827 gw_res_get (info.kernel_res, "gw.err.no.set",
828 "No result-set generated"));
833 if (!no_of_present) /* no records shown so far? */
835 struct gw_user_set *us;
838 us = user_set_search (NULL);
839 if (us && us->hits != -1) /* proper result-set? */
841 default_show = gw_res_int (info.kernel_res, "gw.default.show", 20);
842 if (us->hits >= info.next_position + default_show)
844 present (us->name, info.next_position, default_show,
846 info.next_position += default_show;
848 else if (us->hits >= info.next_position)
850 present (us->name, info.next_position,
851 us->hits - info.next_position + 1,
853 info.next_position = us->hits + 1;
856 else /* display error message */
858 fprintf (reply_fd, "%s\n",
859 gw_res_get (info.kernel_res, "gw.err.no.set",
860 "No result-set generated"));
867 static void show_def (void)
869 fprintf (reply_fd, "format %s\n", gw_res_get
870 (info.kernel_res, "gw.display.format", ""));
871 fprintf (reply_fd, "autoshow %s\n", gw_res_get
872 (info.kernel_res, "gw.auto.show", ""));
873 fprintf (reply_fd, "defaultshow %s\n", gw_res_get
874 (info.kernel_res, "gw.default.show", ""));
875 fprintf (reply_fd, "language %s\n", gw_res_get
876 (info.kernel_res, "gw.language", ""));
879 static int exec_def (struct ccl_token *list)
881 const char *name = NULL;
884 static struct command_word def_tab [] =
886 { "reset", "reset" },
889 { "autoshow", "autoshow" },
890 { "defaultshow", "defaultshow" },
891 { "lang", "language" },
897 sprintf (fname, "user.%d.r", info.userid);
899 if (list->kind == CCL_TOK_EOL)
903 int setting_no = command_search (def_tab, list, "ccl.token.");
907 fprintf (reply_fd, "Unknown setting in def\n");
916 else if (setting_no == 2)
922 if (list->kind == CCL_TOK_EOL)
924 strncpy (value, list->name, 127);
925 value[(size_t) list->len] = '\0';
929 name = "gw.display.format";
932 name = "gw.auto.show";
935 name = "gw.default.show";
938 name = "gw.language";
943 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
945 gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
946 gw_res_put (info.kernel_res, name, value, fname);
947 gw_res_commit (info.kernel_res, fname);
956 * exec_command: parse and execute ccl command in str.
957 * str: ccl command string
958 * stop_flag pointer to integer. On completion the integer
959 * is 1 (stop) or 2 (continue); 0 (other command)
960 * return: 0 success; non-zero otherwise
962 static int exec_command (const char *str, int *stop_flag)
964 static struct command_word command_tab [] =
971 { "continue", "continue" },
972 { "status", "status" },
974 { "target", "target" },
976 { "account", "account" },
980 struct ccl_token *cmd = ccl_tokenize (str);
984 if (cmd->kind != CCL_TOK_EOL &&
985 (no = command_search (command_tab, cmd, "ccl.command.")))
987 if (no == 1 || no == 2 || no == 3) /* find/show/base? */
989 if (!info.zass) /* open if not already opened */
991 fprintf (reply_fd, "\n> %s\n", str);
992 if (!info.zass) /* fail? */
994 fprintf (reply_fd, "\n%s\n",
995 gw_res_get (info.kernel_res, "gw.err.no.target",
996 "No connection established - "
1002 fprintf (reply_fd, "\n> %s\n", str);
1006 return exec_find (cmd->next, str);
1008 return exec_show (cmd->next);
1010 return exec_base (cmd->next);
1012 return exec_help (cmd->next);
1013 case 6: /* continue */
1016 case 7: /* status */
1017 return exec_status (cmd->next);
1021 case 9: /* target */
1022 return exec_target (cmd->next);
1024 return exec_def (cmd->next);
1026 return exec_account (cmd->next);
1028 fprintf (reply_fd, "%s\n",
1029 gw_res_get (info.kernel_res, "gw.err.unimplemented",
1030 "Not implemented yet"));
1035 fprintf (reply_fd, "\n> %s\n", str);
1036 fprintf (reply_fd, " ^ %s\n",
1037 gw_res_get (info.kernel_res, "gw.err.unknown.command",
1039 "Use help to see list of commands"));
1044 int urp_start (int continuation, struct str_queue *queue)
1046 char subject_str[128];
1048 info.command_no = 0;
1049 info.reply_fname = NULL;
1051 if (email_header (queue, info.from_str, subject_str))
1053 gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
1056 tty_init (stdout, 40, 70);
1059 info.reply_fname = (char *)
1060 tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL),
1061 gw_res_get (info.kernel_res,
1062 "gw.reply.tmp.prefix", "gwr"));
1064 reply_fd = fopen (info.reply_fname, "w");
1067 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "Cannot create %s",
1071 tty_init (reply_fd, 0, 0);
1072 fprintf (reply_fd, "From: %s\n",
1073 gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
1074 fprintf (reply_fd, "Subject: ");
1076 fprintf (reply_fd, "Z39.50 Re: %s", subject_str);
1078 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1081 fprintf (reply_fd, "\n");
1082 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", info.from_str);
1085 gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
1086 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
1087 "Email->Z39.50 gateway"));
1089 fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
1095 int urp_command (struct str_queue *queue)
1100 while (str_queue_deq (queue, line_buf, LINE_MAX))
1102 if (line_buf[0] == '\n')
1103 if (info.command_no)
1105 while (str_queue_deq (queue, 0, 0))
1111 if ((cp = strchr (line_buf, '\n')))
1113 gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
1114 if (isalpha (line_buf[0]))
1116 exec_command (line_buf, &stop_flag);
1119 info.command_no++; /* prevent help! */
1120 while (str_queue_deq (queue, line_buf, LINE_MAX))
1132 if (!info.command_no)
1134 fprintf (reply_fd, "%s\n",
1135 gw_res_get (info.kernel_res, "gw.err.nullbody", "No body"));
1144 assert (info.reply_fname);
1148 mta = gw_res_get (info.kernel_res, "gw.reply.mta",
1149 "/usr/lib/sendmail");
1150 sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname);
1151 mta_code = system (cmd);
1153 gw_log (GW_LOG_FATAL, KERNEL_LOG,
1154 "Reply '%s' got exit code %d", cmd, mta_code);
1156 unlink (info.reply_fname);
1157 gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str);