5 * Revision 1.10 1995/03/01 14:32:25 adam
6 * Better diagnostics. Default is, that only one database selected when
9 * Revision 1.9 1995/02/23 08:32:17 adam
12 * Revision 1.7 1995/02/22 15:22:33 adam
13 * Much more checking of run-time state. Show command never retrieves
14 * more records than indicated by the previous search request. Help
15 * command available. The maximum number of records retrieved can be
18 * Revision 1.6 1995/02/22 08:51:34 adam
19 * Output function can be customized in fml, which is used to print
20 * the reply to reply_fd.
22 * Revision 1.5 1995/02/20 21:16:20 adam
23 * FML support. Bug fixes. Profile for drewdb.
25 * Revision 1.4 1995/02/17 17:06:16 adam
28 * Revision 1.3 1995/02/16 18:35:09 adam
29 * First use of Zdist library. Search requests are supported.
30 * Present requests are not supported yet.
32 * Revision 1.2 1995/02/16 13:21:00 adam
33 * Organization of resource files for targets and conversion
34 * language implemented.
36 * Revision 1.1 1995/02/15 17:45:29 adam
37 * First version of email gateway kernel. Email requests are read
38 * from stdin. The output is transferred to an MTA if 'From' is
39 * found in the header - or stdout if absent. No Z39.50 client is used.
50 FILE *reply_fd = stdout;
52 struct gw_kernel_info info;
54 int main (int argc, char **argv)
56 info.kernel_res = NULL;
57 info.default_res = "default.res";
58 info.override_res = NULL;
63 info.override_portno = NULL;
64 info.override_hostname = NULL;
65 info.databases = NULL;
73 info.kernel_res = gw_res_init ();
81 gw_log_level (GW_LOG_ALL);
85 strcpy (info.target, argv[0]+2);
89 strcpy (info.target, *++argv);
93 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing target name");
99 info.lang = argv[0]+2;
107 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing language name");
113 info.override_res = argv[0]+2;
117 info.override_res = *++argv;
121 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing language name");
127 info.override_portno = argv[0]+2;
131 info.override_portno = *++argv;
135 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing portno");
141 info.override_hostname = argv[0]+2;
145 info.override_hostname = *++argv;
149 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing hostname");
155 gw_log_file (GW_LOG_ALL, argv[0]+2);
159 gw_log_file (GW_LOG_ALL, *++argv);
163 gw_log (GW_LOG_FATAL, KERNEL_LOG, "missing log filename");
168 gw_log (GW_LOG_FATAL, KERNEL_LOG, "unknown option %s", *argv);
173 info.default_res = *argv;
180 struct gw_user_set *user_set_add (const char *name, int hits)
182 struct gw_user_set *s;
184 s = malloc (sizeof (*s));
187 s->name = gw_strdup (name);
194 void user_set_init (void)
196 struct gw_user_set *s, *s1;
198 for (s = info.sets; s; s = s1)
207 struct gw_user_set *user_set_search (const char *name)
209 struct gw_user_set *s;
213 for (s = info.sets; s; s = s->prev)
214 if (!strcmp (s->name, name))
220 static void fml_inf_write (int ch)
224 static FILE *fml_inf;
226 static int fml_inf_read (void)
228 return getc (fml_inf);
232 void read_kernel_res (void)
234 char path_prefix[128];
238 char resource_name[256];
243 ccl_qual_rm (&info.bibset);
244 info.bibset = ccl_qual_mk ();
247 gw_res_close (info.kernel_res);
248 info.kernel_res = gw_res_init ();
250 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading kernel resource, default %s",
253 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading kernel resource, target %s",
256 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading kernel resource, lang %s",
259 if (gw_res_merge (info.kernel_res, info.default_res))
261 gw_log (GW_LOG_WARN, KERNEL_LOG, "Couldn't read resource file %s",
265 strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
269 sprintf (resource_name, "gw.target.%s", info.target);
270 v = gw_res_get (info.kernel_res, resource_name, NULL);
273 sprintf (fname, "%s/%s", path_prefix, v);
274 gw_res_merge (info.kernel_res, fname);
279 sprintf (resource_name, "gw.lang.%s", info.lang);
280 v = gw_res_get (info.kernel_res, resource_name, NULL);
283 sprintf (fname, "%s/%s", path_prefix, v);
284 gw_res_merge (info.kernel_res, fname);
287 if (info.override_res)
289 sprintf (fname, "%s/%s", path_prefix, info.override_res);
290 gw_res_merge (info.kernel_res, fname);
292 v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
297 sprintf (fname, "%s/%s", path_prefix, v);
298 bib_inf = fopen (fname, "r");
300 gw_log (GW_LOG_WARN, KERNEL_LOG, "cannot open %s", fname);
303 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading bib file %s", fname);
304 ccl_qual_file (info.bibset, bib_inf);
308 sprintf (resource_name, "gw.target.%s", info.target);
309 if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
311 /* target is there, and there is no sub-resource for it... */
314 if ((split = strchr (info.target, ':')))
316 strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
318 info.port = atoi (split);
320 info.port = atoi (gw_res_get
321 (info.kernel_res, "gw.portno", "210"));
325 strncpy (info.hostname, gw_res_get (info.kernel_res,
326 "gw.hostname", "localhost"),
327 sizeof(info.hostname)-1);
328 info.port = atoi (gw_res_get (info.kernel_res,
329 "gw.portno", "210"));
332 free (info.databases);
334 free (info.database);
335 v = gw_res_get (info.kernel_res, "gw.databases", "");
336 info.databases = gw_strdup (v);
337 for (cp = info.databases; (cp = strchr (cp, ' ')); cp++)
339 v = gw_res_get (info.kernel_res, "gw.database", "");
340 if (*v == '\0' && *info.databases)
343 cp = strchr (info.databases, ',');
345 len = cp ? (cp-info.databases) : strlen (info.databases);
346 info.database = malloc (len+1);
347 assert (info.database);
348 memcpy (info.database, info.databases, len);
349 info.database[len] = '\0';
353 info.database = gw_strdup (v);
354 for (cp = info.database; (cp = strchr (cp, ' ')); cp++)
357 if (info.override_portno)
358 info.port = atoi (info.override_portno);
359 if (info.override_hostname)
360 strncpy (info.hostname, info.override_hostname,
361 sizeof(info.hostname)-1);
365 v = gw_res_get (info.kernel_res, "gw.fml", "default.fml");
366 sprintf (fname, "%s/%s", path_prefix, v);
367 fml_inf = fopen (fname, "r");
369 gw_log (GW_LOG_WARN, KERNEL_LOG,
370 "cannot open fml script %s", fname);
373 info.fml = fml_open ();
374 info.fml->read_func = fml_inf_read;
375 info.fml->write_func = fml_inf_write;
376 fml_preprocess (info.fml);