5 * Revision 1.9 1995/02/23 08:32:17 adam
8 * Revision 1.7 1995/02/22 15:22:33 adam
9 * Much more checking of run-time state. Show command never retrieves
10 * more records than indicated by the previous search request. Help
11 * command available. The maximum number of records retrieved can be
14 * Revision 1.6 1995/02/22 08:51:34 adam
15 * Output function can be customized in fml, which is used to print
16 * the reply to reply_fd.
18 * Revision 1.5 1995/02/20 21:16:20 adam
19 * FML support. Bug fixes. Profile for drewdb.
21 * Revision 1.4 1995/02/17 17:06:16 adam
24 * Revision 1.3 1995/02/16 18:35:09 adam
25 * First use of Zdist library. Search requests are supported.
26 * Present requests are not supported yet.
28 * Revision 1.2 1995/02/16 13:21:00 adam
29 * Organization of resource files for targets and conversion
30 * language implemented.
32 * Revision 1.1 1995/02/15 17:45:29 adam
33 * First version of email gateway kernel. Email requests are read
34 * from stdin. The output is transferred to an MTA if 'From' is
35 * found in the header - or stdout if absent. No Z39.50 client is used.
46 FILE *reply_fd = stdout;
48 struct gw_kernel_info info;
50 int main (int argc, char **argv)
52 info.kernel_res = NULL;
53 info.default_res = "default.res";
54 info.override_res = NULL;
59 info.override_portno = NULL;
60 info.override_hostname = NULL;
61 info.databases = NULL;
68 info.kernel_res = gw_res_init ();
76 gw_log_level (GW_LOG_ALL);
80 strcpy (info.target, argv[0]+2);
84 strcpy (info.target, *++argv);
88 gw_log (GW_LOG_FATAL, "main", "missing target name");
94 info.lang = argv[0]+2;
102 gw_log (GW_LOG_FATAL, "main", "missing language name");
108 info.override_res = argv[0]+2;
112 info.override_res = *++argv;
116 gw_log (GW_LOG_FATAL, "main", "missing language name");
122 info.override_portno = argv[0]+2;
126 info.override_portno = *++argv;
130 gw_log (GW_LOG_FATAL, "main", "missing portno");
136 info.override_hostname = argv[0]+2;
140 info.override_hostname = *++argv;
144 gw_log (GW_LOG_FATAL, "main", "missing hostname");
150 gw_log_file (GW_LOG_ALL, argv[0]+2);
154 gw_log_file (GW_LOG_ALL, *++argv);
158 gw_log (GW_LOG_FATAL, "main", "missing log filename");
163 gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv);
168 info.default_res = *argv;
175 struct gw_user_set *user_set_add (const char *name, int hits)
177 struct gw_user_set *s;
179 s = malloc (sizeof (*s));
182 s->name = gw_strdup (name);
189 void user_set_init (void)
191 struct gw_user_set *s, *s1;
193 for (s = info.sets; s; s = s1)
202 struct gw_user_set *user_set_search (const char *name)
204 struct gw_user_set *s;
208 for (s = info.sets; s; s = s->prev)
209 if (!strcmp (s->name, name))
215 static void fml_inf_write (int ch)
219 static FILE *fml_inf;
221 static int fml_inf_read (void)
223 return getc (fml_inf);
227 void read_kernel_res (void)
229 char path_prefix[128];
233 char resource_name[256];
238 ccl_qual_rm (&info.bibset);
239 info.bibset = ccl_qual_mk ();
242 gw_res_close (info.kernel_res);
243 info.kernel_res = gw_res_init ();
245 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s",
248 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s",
251 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s",
254 if (gw_res_merge (info.kernel_res, info.default_res))
256 gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s",
260 strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
264 sprintf (resource_name, "gw.target.%s", info.target);
265 v = gw_res_get (info.kernel_res, resource_name, NULL);
268 sprintf (fname, "%s/%s", path_prefix, v);
269 gw_res_merge (info.kernel_res, fname);
274 sprintf (resource_name, "gw.lang.%s", info.lang);
275 v = gw_res_get (info.kernel_res, resource_name, NULL);
278 sprintf (fname, "%s/%s", path_prefix, v);
279 gw_res_merge (info.kernel_res, fname);
282 if (info.override_res)
284 sprintf (fname, "%s/%s", path_prefix, info.override_res);
285 gw_res_merge (info.kernel_res, fname);
287 v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
292 sprintf (fname, "%s/%s", path_prefix, v);
293 bib_inf = fopen (fname, "r");
295 gw_log (GW_LOG_WARN, "main", "cannot open %s", fname);
298 gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname);
299 ccl_qual_file (info.bibset, bib_inf);
303 sprintf (resource_name, "gw.target.%s", info.target);
304 if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
306 /* target is there, and there is no sub-resource for it... */
309 if ((split = strchr (info.target, ':')))
311 strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
313 info.port = atoi (split);
315 info.port = atoi (gw_res_get
316 (info.kernel_res, "gw.portno", "210"));
320 strncpy (info.hostname, gw_res_get (info.kernel_res,
321 "gw.hostname", "localhost"),
322 sizeof(info.hostname)-1);
323 info.port = atoi (gw_res_get (info.kernel_res,
324 "gw.portno", "210"));
327 free (info.databases);
328 v = gw_res_get (info.kernel_res, "gw.databases", "");
329 info.databases = gw_strdup (v);
330 for (cp = info.databases; (cp = strchr (cp, ' ')); cp++)
332 if (info.override_portno)
333 info.port = atoi (info.override_portno);
334 if (info.override_hostname)
335 strncpy (info.hostname, info.override_hostname,
336 sizeof(info.hostname)-1);
340 v = gw_res_get (info.kernel_res, "gw.fml", "default.fml");
341 sprintf (fname, "%s/%s", path_prefix, v);
342 fml_inf = fopen (fname, "r");
344 gw_log (GW_LOG_WARN, "main", "cannot open fml script %s", fname);
347 info.fml = fml_open ();
348 info.fml->read_func = fml_inf_read;
349 info.fml->write_func = fml_inf_write;
350 fml_preprocess (info.fml);