5 * Revision 1.6 1995/02/22 08:51:34 adam
6 * Output function can be customized in fml, which is used to print
7 * the reply to reply_fd.
9 * Revision 1.5 1995/02/20 21:16:20 adam
10 * FML support. Bug fixes. Profile for drewdb.
12 * Revision 1.4 1995/02/17 17:06:16 adam
15 * Revision 1.3 1995/02/16 18:35:09 adam
16 * First use of Zdist library. Search requests are supported.
17 * Present requests are not supported yet.
19 * Revision 1.2 1995/02/16 13:21:00 adam
20 * Organization of resource files for targets and conversion
21 * language implemented.
23 * Revision 1.1 1995/02/15 17:45:29 adam
24 * First version of email gateway kernel. Email requests are read
25 * from stdin. The output is transferred to an MTA if 'From' is
26 * found in the header - or stdout if absent. No Z39.50 client is used.
37 FILE *reply_fd = stdout;
39 struct gw_kernel_info info;
41 int main (int argc, char **argv)
43 info.kernel_res = NULL;
44 info.default_res = "default.res";
45 info.override_res = NULL;
50 info.override_portno = NULL;
51 info.override_hostname = NULL;
52 info.databases = NULL;
58 info.kernel_res = gw_res_init ();
66 gw_log_level (GW_LOG_ALL);
70 strcpy (info.target, argv[0]+2);
74 strcpy (info.target, *++argv);
78 gw_log (GW_LOG_FATAL, "main", "missing target name");
84 info.lang = argv[0]+2;
92 gw_log (GW_LOG_FATAL, "main", "missing language name");
98 info.override_res = argv[0]+2;
102 info.override_res = *++argv;
106 gw_log (GW_LOG_FATAL, "main", "missing language name");
112 info.override_portno = argv[0]+2;
116 info.override_portno = *++argv;
120 gw_log (GW_LOG_FATAL, "main", "missing portno");
126 info.override_hostname = argv[0]+2;
130 info.override_hostname = *++argv;
134 gw_log (GW_LOG_FATAL, "main", "missing hostname");
140 gw_log_file (GW_LOG_ALL, argv[0]+2);
144 gw_log_file (GW_LOG_ALL, *++argv);
148 gw_log (GW_LOG_FATAL, "main", "missing log filename");
153 gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv);
158 info.default_res = *argv;
165 static void fml_inf_write (int ch)
169 static FILE *fml_inf;
171 static int fml_inf_read (void)
173 return getc (fml_inf);
177 void read_kernel_res (void)
179 char path_prefix[128];
183 char resource_name[256];
186 ccl_qual_rm (&info.bibset);
187 info.bibset = ccl_qual_mk ();
190 gw_res_close (info.kernel_res);
191 info.kernel_res = gw_res_init ();
193 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s",
196 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s",
199 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s",
202 if (gw_res_merge (info.kernel_res, info.default_res))
204 gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s",
208 strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
212 sprintf (resource_name, "gw.target.%s", info.target);
213 v = gw_res_get (info.kernel_res, resource_name, NULL);
216 sprintf (fname, "%s/%s", path_prefix, v);
217 gw_res_merge (info.kernel_res, fname);
222 sprintf (resource_name, "gw.lang.%s", info.lang);
223 v = gw_res_get (info.kernel_res, resource_name, NULL);
226 sprintf (fname, "%s/%s", path_prefix, v);
227 gw_res_merge (info.kernel_res, fname);
230 if (info.override_res)
232 sprintf (fname, "%s/%s", path_prefix, info.override_res);
233 gw_res_merge (info.kernel_res, fname);
235 v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
240 sprintf (fname, "%s/%s", path_prefix, v);
241 bib_inf = fopen (fname, "r");
243 gw_log (GW_LOG_WARN, "main", "cannot open %s", fname);
246 gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname);
247 ccl_qual_file (info.bibset, bib_inf);
251 sprintf (resource_name, "gw.target.%s", info.target);
252 if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
254 /* target is there, and there is no sub-resource for it... */
257 if ((split = strchr (info.target, ':')))
259 strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
261 info.port = atoi (split);
263 info.port = atoi (gw_res_get
264 (info.kernel_res, "gw.portno", "210"));
268 strncpy (info.hostname, gw_res_get (info.kernel_res,
269 "gw.hostname", "localhost"),
270 sizeof(info.hostname)-1);
271 info.port = atoi (gw_res_get (info.kernel_res,
272 "gw.portno", "210"));
275 free (info.databases);
276 v = gw_res_get (info.kernel_res, "gw.databases", "");
277 info.databases = malloc (1+strlen(v));
278 assert (info.databases);
279 strcpy (info.databases, v);
280 for (cp = info.databases; (cp = strchr (cp, ' ')); cp++)
282 if (info.override_portno)
283 info.port = atoi (info.override_portno);
284 if (info.override_hostname)
285 strncpy (info.hostname, info.override_hostname,
286 sizeof(info.hostname)-1);
290 v = gw_res_get (info.kernel_res, "gw.fml", "default.fml");
291 sprintf (fname, "%s/%s", path_prefix, v);
292 fml_inf = fopen (fname, "r");
294 gw_log (GW_LOG_WARN, "main", "cannot open fml script %s", fname);
297 info.fml = fml_open ();
298 info.fml->read_func = fml_inf_read;
299 info.fml->write_func = fml_inf_write;
300 fml_preprocess (info.fml);