Better diagnostics. Default is, that only one database selected when
[egate.git] / kernel / urp.c
1 /* Gateway kernel
2  * Europagate, 1995
3  *
4  * $Log: urp.c,v $
5  * Revision 1.18  1995/03/01 14:32:26  adam
6  * Better diagnostics. Default is, that only one database selected when
7  * several are known.
8  *
9  * Revision 1.17  1995/02/28  13:16:26  adam
10  * Configurable From: added.
11  *
12  * Revision 1.16  1995/02/23  10:08:20  adam
13  * Added logging of all user commands.
14  *
15  * Revision 1.15  1995/02/23  08:32:17  adam
16  * Changed header.
17  *
18  * Revision 1.13  1995/02/22  16:54:42  adam
19  * Qualifiers of LOC target updated. More logging messages.
20  *
21  * Revision 1.12  1995/02/22  15:51:51  adam
22  * Bug fix: swap of parameter number and offset in function present.
23  *
24  * Revision 1.11  1995/02/22  15:22:33  adam
25  * Much more checking of run-time state. Show command never retrieves
26  * more records than indicated by the previous search request. Help
27  * command available. The maximum number of records retrieved can be
28  * controlled now.
29  *
30  * Revision 1.10  1995/02/22  08:51:35  adam
31  * Output function can be customized in fml, which is used to print
32  * the reply to reply_fd.
33  *
34  * Revision 1.9  1995/02/21  17:46:21  adam
35  * Minor changes.
36  *
37  * Revision 1.8  1995/02/21  12:12:00  adam
38  * Diagnostic record with error info. observed.
39  *
40  * Revision 1.7  1995/02/20  21:16:20  adam
41  * FML support. Bug fixes. Profile for drewdb.
42  *
43  * Revision 1.6  1995/02/17  14:41:14  quinn
44  * Added simple display of records.
45  *
46  * Revision 1.5  1995/02/17  14:22:13  adam
47  * First steps of CCL show command. Not finished yet.
48  *
49  * Revision 1.4  1995/02/17  09:08:36  adam
50  * Reply with subject. CCL base command implemented.
51  *
52  * Revision 1.3  1995/02/16  18:35:09  adam
53  * First use of Zdist library. Search requests are supported.
54  * Present requests are not supported yet.
55  *
56  * Revision 1.2  1995/02/16  13:21:00  adam
57  * Organization of resource files for targets and conversion
58  * language implemented.
59  *
60  * Revision 1.1  1995/02/15  17:45:30  adam
61  * First version of email gateway kernel. Email requests are read
62  * from stdin. The output is transferred to an MTA if 'From' is
63  * found in the header - or stdout if absent. No Z39.50 client is used.
64  *
65  */
66
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <assert.h>
70 #include <ctype.h>
71 #include <string.h>
72 #include <unistd.h>
73 #include <fcntl.h>
74
75 #include "kernel.h"
76
77 #define LINE_MAX 256
78
79 static void put_esc_str (const char *s)
80 {
81     int escape_flag = 0;
82     while (*s)
83     {
84         if (*s == '\\' && s[1])
85         {
86             switch (*++s)
87             {
88             case 'n':
89                 fputc ('\n', reply_fd);
90                 break;
91             case 't':
92                 fputc ('\t', reply_fd);
93                 break;
94             default:
95                 fputc (*s, reply_fd);
96                 break;
97             }
98             escape_flag = 1;
99         }
100         else
101         {
102             if (*s != ' ' || !escape_flag)
103                 fputc (*s, reply_fd);
104             escape_flag = 0;
105         }
106         s++;
107     }
108 }
109
110 static int reopen_target (void)
111 {
112     const char *v;
113     if (info.zass)
114         gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free...");
115     info.zass = zass_open (info.hostname, info.port);
116     if (!info.zass)
117     {
118         fprintf (reply_fd, "%s %s:%d\n", 
119                  gw_res_get (info.kernel_res, "gw.err.connect",
120                              "Cannot connect to target"),
121                  info.hostname, info.port);
122         return -1;
123     }
124     v = gw_res_get (info.kernel_res, "gw.description", NULL);
125     if (v)
126     {
127         put_esc_str (v);
128         fprintf (reply_fd, "\n");
129     }
130     fprintf (reply_fd, "%s %s:%d\n",
131              gw_res_get (info.kernel_res, "gw.msg.connect",
132                          "Connection established to"),
133              info.hostname, info.port);
134     if (*info.databases)
135         fprintf (reply_fd, "%s:\n%s\n",
136                  gw_res_get (info.kernel_res, "gw.msg.databases",
137                              "Available databases"),
138                  info.databases);
139     if (*info.database)
140         fprintf (reply_fd, "%s:\n%s\n",
141                  gw_res_get (info.kernel_res, "gw.msg.database",
142                              "Selected databases"),
143                  info.database);
144     return 0;
145 }
146
147 static char line_buf[LINE_MAX+1];
148
149 static struct command_word {
150     char *default_value;
151     char *resource_suffix;
152 } command_tab [] = 
153 {
154 {   "find", "find"},
155 {   "show", "show"},
156 {   "base", "base" },
157 {   "help", "help" },
158 {   "info", "info" },
159 {   "continue", "continue" },
160 {   "status", "status" },
161 {   "cancel", "cancel" },
162 {   "target", "target" },
163 {   NULL, NULL }
164 };
165
166 static int command_search (struct command_word *tab, struct ccl_token *cmd,
167 const char *resource_prefix)
168 {
169     int no = 1;
170
171     assert (resource_prefix);
172     assert (tab);
173     assert (cmd);
174     while (tab->default_value)
175     {
176         char *cp, command_names[60];
177         char resource_name[60];
178         const char *v;
179
180         sprintf (resource_name, "%s%s", resource_prefix,
181                  tab->resource_suffix);
182         v = gw_res_get (info.kernel_res, resource_name, tab->default_value);
183         assert (v);
184         strcpy (command_names, v);
185         cp = command_names;
186         while (1)
187         {
188             char *split;
189
190             if ((split = strchr (cp, ' ')))
191                 *split = '\0';
192             if (cmd->len == strlen(cp) &&
193                 !memcmp (cmd->name, cp, cmd->len))
194                 return no;
195             if (!split)
196                 break;
197             cp = split+1;
198         }        
199         no++;
200         tab++;
201     }
202     return 0;
203 }
204
205 static struct error_no_struct {
206     int no;
207     char *resource_name;
208 } error_ccl_tab[] = {
209 {  CCL_ERR_OK, "ok"},
210 {  CCL_ERR_TERM_EXPECTED, "term.expected" },
211 {  CCL_ERR_RP_EXPECTED, "rp.expected" },
212 {  CCL_ERR_SETNAME_EXPECTED, "setname.expected" },
213 {  CCL_ERR_OP_EXPECTED, "op.expected" },
214 {  CCL_ERR_BAD_RP, "bad.rp" },
215 {  CCL_ERR_UNKNOWN_QUAL, "unknown.qual" },
216 {  CCL_ERR_DOUBLE_QUAL, "double.qual" },
217 {  CCL_ERR_EQ_EXPECTED, "eq.expected" },
218 {  CCL_ERR_BAD_RELATION, "bad.relation" },
219 {  CCL_ERR_TRUNC_NOT_LEFT, "trunc.not.left" },
220 {  CCL_ERR_TRUNC_NOT_BOTH, "trunc.not.both" },
221 {  CCL_ERR_TRUNC_NOT_RIGHT, "trunc.not.right" },
222 {  0, NULL }
223 };
224
225 static char *error_no_search (struct error_no_struct *tab, int no)
226 {
227     struct error_no_struct *p = tab;
228     while (p->resource_name)
229     {
230         if (no == p->no)
231             return p->resource_name;
232         p++;
233     }
234     return NULL;
235 }
236
237 static int email_header (FILE *inf, char *from_str, char *subject_str)
238 {
239     *from_str = '\0';
240     *subject_str = '\0';
241     while (fgets (line_buf, LINE_MAX, inf))
242     {
243         if (line_buf[0] == '\n')
244             return 0;
245         if (strncmp (line_buf, "From ", 5) == 0)
246             sscanf (line_buf+4, "%s", from_str);
247         if (strncmp (line_buf, "Subject: ", 9) == 0 &&
248             sscanf (line_buf+9, "%s", subject_str+1) == 1)
249             strcpy (subject_str, line_buf+9);
250     }
251     return 1;
252 }
253
254 static void help_general (void)
255 {
256     put_esc_str (gw_res_get (info.kernel_res, "gw.help.general",
257                              "Commands available in this service:\n"));
258 }
259
260 static int exec_help (struct ccl_token *list)
261 {
262     help_general ();
263
264 #if 0
265     put_esc_str (gw_res_get (info.kernel_res, "gw.help.target",
266                              "target <name> - selects a given target\n"));
267
268     put_esc_str (gw_res_get (info.kernel_res, "gw.help.base",
269                              "base <base>..  - selects databases\n"));
270
271     put_esc_str (gw_res_get (info.kernel_res, "gw.help.find",
272                              "find <query>   - performs a search request\n"));
273
274     put_esc_str (gw_res_get (info.kernel_res, "gw.help.show",
275                              "show <spec>    - retrieves and displays "
276                              "records\n"));
277     put_esc_str (gw_res_get (info.kernel_res, "gw.help.help",
278                              "help           - displays help\n"));
279 #endif
280     return 0;
281 }
282
283 static void display_diag_error (int code, const char *addinfo)
284 {
285     static char str[20];
286
287     sprintf (str, "gw.bib1.diag.%d", code);
288     fprintf (reply_fd, "%s %d:\n %s: '%s'\n",
289              gw_res_get (info.kernel_res, "gw.msg.z39errcode", 
290                          "Z39.50 Error"),
291              code,
292              gw_res_get (info.kernel_res, str, ""), addinfo);
293 }
294
295 static int exec_find (struct ccl_token *list)
296 {
297     const struct zass_searchent *p;
298     struct gw_user_set *us;
299
300     struct ccl_rpn_node *rpn;
301     int error;
302     const char *pos;
303
304     us = user_set_add ("Default", -1);
305     rpn = ccl_find (info.bibset, list, &error, &pos);
306     if (!rpn)
307     {
308         const char *v = NULL, *n;
309         char name[128];
310
311         fprintf (reply_fd, "  %*s^ - ", pos - line_buf, " ");
312
313         n = error_no_search (error_ccl_tab, error);
314         if (n)
315         {
316             sprintf (name, "gw.err.%s", n);
317             v = gw_res_get (info.kernel_res, name, NULL);
318         }
319         if (!v)
320             v = ccl_err_msg (error);
321         fprintf (reply_fd, "%s\n", v);
322         return -1;
323     }
324     ccl_pr_tree (rpn, reply_fd);
325     fprintf (reply_fd, "\n");
326
327     if (!*info.database )
328     {
329         fprintf (reply_fd, "%s\n",
330                  gw_res_get (info.kernel_res, "gw.err.no.database",
331                              "You must select database"));
332         return -3;
333     }
334     gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
335             info.database );
336     assert (info.zass);
337     p = zass_search (info.zass, rpn, "Default", info.database );
338     if (!p)
339         return -1;
340     if (p->errcode != -1)
341     {
342         display_diag_error (p->errcode, p->errstring);
343         return -2;
344     }
345     fprintf (reply_fd, "%d %s\n", p->num,
346              gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)"));
347     us->hits = p->num;
348     return 0;
349 }
350
351 static int exec_target (struct ccl_token *list)
352 {
353     int len;
354     if (list->kind == CCL_TOK_EOL)
355         return -1;
356     len = list->len;
357     memcpy (info.target, list->name, len);
358     info.target [len] = '\0';
359
360     read_kernel_res ();
361     return reopen_target ();
362 }
363
364 static int exec_base (struct ccl_token *list)
365 {
366     struct ccl_token *li = list;
367     int len = 0;
368
369     assert (info.zass);
370     if (list->kind == CCL_TOK_EOL)
371         return -1;
372     free (info.database);
373     while (li->kind != CCL_TOK_EOL)
374     {
375         len += li->len + 1;
376         li = li->next;
377         if (li->kind == CCL_TOK_COMMA)
378             li = li->next;
379     }
380     info.database  = malloc (len);
381     assert (info.database );
382     len = 0;
383     li = list;
384     while (li->kind != CCL_TOK_EOL)
385     {
386         memcpy (info.database+len, li->name, li->len);
387         len += li->len;
388         info.database[len++] = ',';
389         li = li->next;
390         if (li->kind == CCL_TOK_COMMA)
391             li = li->next;
392     }
393     info.database[len-1] = '\0';
394     return 0;
395 }
396
397 struct command_word show_tab [] = 
398 {
399 {   "f", "format"},
400 {   "p", "position"},
401 {   NULL, NULL }
402 };
403
404 static void present (const char *set, int offset, int number,
405                      struct ccl_token *format_token)
406 {
407     const struct zass_presentent *zp;
408     int len;
409     int max_number;
410     char format_str[40];
411     
412     max_number = atoi (gw_res_get (info.kernel_res, "gw.max.show", 
413                                    "200"));
414     if (number > max_number)
415         number = max_number;
416     gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
417     gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
418             number, offset);
419     zp = zass_present(info.zass, (char *) set, offset, number);
420     if (zp)
421     {
422         int i;
423         zass_record *pp;
424         char path[128];
425         int  record_log_fd = -1;
426         const char *record_log_name;
427
428         record_log_name = gw_res_get (info.kernel_res, "gw.marc.log",
429                                       NULL);
430         if (record_log_name)
431         {
432             sprintf (path, "%s/%s", gw_res_get (info.kernel_res,
433                                                 "gw.path", "."),
434                      record_log_name );
435             record_log_fd = open (path, O_WRONLY|O_CREAT|O_APPEND, 0666);
436             if (record_log_fd == -1)
437                 gw_log (GW_LOG_WARN, "Cannot open %s", path);
438         }
439         fprintf (reply_fd, gw_res_get (info.kernel_res,
440                                        "gw.msg.records",
441                                        "Got %d records"),
442                  zp->num);
443         fprintf (reply_fd, "\n");
444         for (i = 0, pp = zp->records; pp; pp = pp->next, i++)
445         {
446             Iso2709Rec rec;
447 #if USE_FML
448             const char *arg_ar[5];
449 #endif
450             fprintf (reply_fd, "--- %d/%d ---\n",
451                      i+offset, offset+zp->num-1);
452             if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL))
453             {
454                 if (pp->which == ZASS_REC_DIAG)
455                 {
456                     display_diag_error (pp->errcode, pp->errstring);
457                     continue;
458                 }
459                 else if (pp->which != ZASS_REC_USMARC)
460                 {
461                     fprintf (reply_fd, "Unknown record kind %d\n",
462                              pp->which);
463                     continue;
464                 }
465             }
466             if (record_log_fd != -1)
467                 write (record_log_fd, pp->record, strlen(pp->record));
468             rec = iso2709_cvt (pp->record);
469             if (rec)
470             {
471 #if USE_FML
472                 if (format_token)
473                 {
474                     len = format_token->len;
475                     memcpy (format_str, format_token->name, len);
476                     format_str[len] = '\0';
477                 }
478                 if (info.fml && format_token && 
479                     (!strcmp (format_str, "0") || !strcmp (format_str, "1")))
480                 {
481                     arg_ar[0] = "\\f";
482                     arg_ar[1] = format_str;
483                     arg_ar[2] = " \\list";
484                     arg_ar[3] = marc_to_str (info.fml, rec);
485                     arg_ar[4] = NULL;
486                     fml_exec_call_argv (info.fml, arg_ar);
487                 }
488                 else
489                     iso2709_display (rec, reply_fd);
490 #else
491                 iso2709_display (rec, reply_fd);
492 #endif
493                 iso2709_rm (rec);
494             }
495             else
496                 fprintf (reply_fd, "Not a MARC record\n");
497         }
498         if (record_log_fd != -1)
499             close (record_log_fd);
500     }
501 }
502
503 static int exec_show (struct ccl_token *list)
504 {
505     char tmp_str[20];
506     struct ccl_token *set_token = NULL;
507     struct ccl_token *format_token = NULL;
508     struct ccl_token *li = list;
509     int no_of_present = 0;
510
511     assert (info.zass);
512     while (li->kind != CCL_TOK_EOL)
513     {
514         int modifier_no = 0;
515         if (li->next->kind == CCL_TOK_EQ)
516         {
517             if (li->kind == CCL_TOK_SET)    /* set = <name> ? */
518             {
519                 li = li->next->next;
520                 set_token = li;
521             }
522             else 
523             {
524                 modifier_no = command_search (show_tab, li, "ccl.token.");
525                 if (!modifier_no)
526                 {
527                     fprintf (reply_fd, "Unknown modifier in show\n");
528                     return -1;
529                 }
530                 li = li->next->next;
531                 if (modifier_no == 1)       /* f = <name> ? */
532                     format_token = li;
533                 else if (modifier_no == 2)  /* p = <name> ? */
534                 {
535                     if (li->kind != CCL_TOK_EOL   /* p = <name> - <name> ? */
536                         && li->next->kind == CCL_TOK_MINUS
537                         && li->next->next != CCL_TOK_EOL)
538                         li = li->next->next;
539                 }
540             }
541             if (!li->next)
542             {
543                 fprintf (reply_fd, "%s\n", "Missing token after '='");
544                 return -2;
545             }
546             li = li->next;
547         }
548         else
549             li = li->next;
550     }
551     if (set_token)
552         gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got set=%.*s", set_token->len,
553                 set_token->name);
554     if (format_token)
555         gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Got format=%.*s", format_token->len,
556                 format_token->name);
557
558     li = list;
559     while (li->kind != CCL_TOK_EOL)
560     {
561         int modifier_no = 0;
562         int offset = 0;
563         int number = 0;
564         int len;
565         if (li->next->kind == CCL_TOK_EQ && li->kind != CCL_TOK_SET)
566         {
567             modifier_no = command_search (show_tab, li, "ccl.token.");
568             li = li->next->next;
569             if (modifier_no == 2)  /* p = <name> ? */
570             {
571                 if (li->kind != CCL_TOK_EOL   /* p = <name> - <name> ? */
572                     && li->next->kind == CCL_TOK_MINUS
573                     && li->next->next != CCL_TOK_EOL)
574                 {
575                     len = li->len;
576                     memcpy (tmp_str, li->name, len);
577                     tmp_str [len] = '\0';
578                     offset = atoi (tmp_str);
579                     li = li->next->next;
580
581                     len = li->len;
582                     memcpy (tmp_str, li->name, len);
583                     tmp_str [len] = '\0';
584                     number = atoi (tmp_str) - offset + 1;
585                 }
586                 else
587                 {
588                     len = li->len;
589                     memcpy (tmp_str, li->name, len);
590                     tmp_str [len] = '\0';
591                     offset = atoi (tmp_str);
592                     number = 1;
593                 }
594             }
595             li = li->next;
596         }
597         else
598         {
599             len = li->len;
600             memcpy (tmp_str, li->name, len);
601             tmp_str[len] = '\0';
602             number = atoi (tmp_str);
603             offset = 1;
604             li = li->next;
605         }
606         if (offset > 0 && number > 0)
607         {
608             struct gw_user_set *us;
609
610             if (set_token)
611             {
612                 len = set_token->len;
613                 memcpy (tmp_str, set_token->name, len);
614                 tmp_str[len] = '\0';
615                 us = user_set_search (tmp_str);
616             }
617             else
618                 us = user_set_search (NULL);
619             if (us && us->hits != -1) /* proper result-set? */
620             {
621                 if (offset <= us->hits)
622                 {
623                     if (offset+number-1 > us->hits)
624                         number = us->hits - offset+1;
625                     present (us->name, offset, number, format_token);
626                 }
627             }
628             else if (!no_of_present) /* display error message once! */
629             {
630                 fprintf (reply_fd, "%s\n",
631                          gw_res_get (info.kernel_res, "gw.err.no.set",
632                                      "No result-set generated"));
633             }
634             no_of_present++;
635         }
636     }
637     if (!no_of_present) /* no records shown so far? */
638     {
639         struct gw_user_set *us;
640         int default_show;
641         
642         us = user_set_search (NULL);
643         if (us && us->hits != -1)    /* proper result-set? */
644         {
645             default_show = atoi (gw_res_get (info.kernel_res,
646                                              "gw.default.show", "20"));
647             if (us->hits > default_show)
648                 present (us->name, 1, default_show, format_token);
649             else if (us->hits > 0)
650                 present (us->name, 1, us->hits, format_token);
651         }
652         else                         /* display error message */
653         {
654             fprintf (reply_fd, "%s\n",
655                      gw_res_get (info.kernel_res, "gw.err.no.set",
656                                  "No result-set generated"));
657             return -3;
658         }        
659     }
660     return 0;
661 }
662
663 static int exec_command (const char *str)
664 {
665     struct ccl_token *cmd = ccl_tokenize (str);
666     int no;
667
668     if (cmd->kind != CCL_TOK_EOL &&
669         (no = command_search (command_tab, cmd, "ccl.command.")))
670     {
671         if (!info.zass && no != 9 && no != 4)
672             reopen_target ();
673         fprintf (reply_fd, "\n> %s\n", str);
674         if (!info.zass && (no == 1 || no == 2 || no == 3))
675         {
676             fprintf (reply_fd, "%s\n",
677                      gw_res_get (info.kernel_res, "gw.err.no.target",
678                                  "No connection established - "
679                                  "command ignored"));
680             return 0;
681         }
682         switch (no)
683         {
684         case 1:
685             return exec_find (cmd->next);
686         case 2:
687             return exec_show (cmd->next);
688         case 3:
689             return exec_base (cmd->next);
690         case 4:
691             return exec_help (cmd->next);
692         case 9:
693             return exec_target (cmd->next);
694         default:
695             fprintf (reply_fd, "%s\n",
696                      gw_res_get (info.kernel_res, "gw.err.unimplemented",
697                                  "Not implemented yet"));
698         }
699     }
700     else
701     {
702         fprintf (reply_fd, "\n> %s\n", str);
703         fprintf (reply_fd, "  ^ %s\n", 
704                  gw_res_get (info.kernel_res, "gw.err.unknown.command",
705                              "unknown command. "
706                              "Use help to see list of commands"));
707     }
708     return 0;
709 }
710
711 int urp (FILE *inf)
712 {
713     char from_str[128];
714     char subject_str[128];
715     int command_no = 0;
716     char *reply_fname = NULL;
717
718     if (email_header (inf, from_str, subject_str))
719     {
720         gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body");
721         return -1;
722     }
723     if (*from_str)
724     {
725         reply_fname = tempnam (gw_res_get (info.kernel_res,
726                                            "gw.reply.tmp.dir", NULL),
727                                gw_res_get (info.kernel_res,
728                                            "gw.reply.tmp.prefix", "gwr"));
729                                                  
730         reply_fd = fopen (reply_fname, "w");
731         if (!reply_fd)
732         {
733             gw_log (GW_LOG_FATAL, KERNEL_LOG, "Cannot create %s",
734                     reply_fname);
735             return -1;
736         }
737         fprintf (reply_fd, "From: %s\n",
738                  gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway"));
739         fprintf (reply_fd, "Subject: ");
740         if (*subject_str)
741             fprintf (reply_fd, "Z39.50 Re: %s", subject_str);
742         else
743             fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
744                                                    "gw.msg.subject",
745                                                    "Your Query"));
746         fprintf (reply_fd, "\n");
747         gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", from_str);
748     }
749     else
750         gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header");
751     fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting",
752                                            "Email->Z39.50 gateway"));
753     while (fgets (line_buf, LINE_MAX, inf))
754     {
755         char *cp;
756
757         if (line_buf[0] == '\n')
758             break;
759         if ((cp = strchr (line_buf, '\n')))
760             *cp = '\0';
761         gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);
762         ccl_token_and = gw_res_get (info.kernel_res, "ccl.token.and", "and");
763         ccl_token_or = gw_res_get (info.kernel_res, "ccl.token.or", "or");
764         ccl_token_not = gw_res_get (info.kernel_res, "ccl.token.not", "not");
765         ccl_token_set = gw_res_get (info.kernel_res, "ccl.token.set", "set");
766         if (isalpha (line_buf[0]))
767             exec_command (line_buf);
768         command_no++;
769     }
770     if (!command_no)
771     {
772         fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res,
773                                                "gw.err.nullbody",
774                                                "No body"));
775         help_general ();
776     }
777     if (*from_str)
778     {
779         const char *mta;
780         char cmd[256];
781         int mta_code;
782
783         assert (reply_fname);
784         fclose (reply_fd);
785         reply_fd = stdout;
786
787         mta = gw_res_get (info.kernel_res, "gw.reply.mta",
788                           "/usr/lib/sendmail");
789         sprintf (cmd, "%s %s < %s", mta, from_str, reply_fname);
790         
791         mta_code = system (cmd);
792         if (mta_code)
793             gw_log (GW_LOG_FATAL, KERNEL_LOG, "Reply '%s' got exit code %d",
794                     cmd, mta_code);
795         unlink (reply_fname);        
796         gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", from_str);
797     }
798     return 0;
799 }