5 * Revision 1.5 1995/02/20 21:16:20 adam
6 * FML support. Bug fixes. Profile for drewdb.
8 * Revision 1.4 1995/02/17 17:06:16 adam
11 * Revision 1.3 1995/02/16 18:35:09 adam
12 * First use of Zdist library. Search requests are supported.
13 * Present requests are not supported yet.
15 * Revision 1.2 1995/02/16 13:21:00 adam
16 * Organization of resource files for targets and conversion
17 * language implemented.
19 * Revision 1.1 1995/02/15 17:45:29 adam
20 * First version of email gateway kernel. Email requests are read
21 * from stdin. The output is transferred to an MTA if 'From' is
22 * found in the header - or stdout if absent. No Z39.50 client is used.
33 FILE *reply_fd = stdout;
35 struct gw_kernel_info info;
37 int main (int argc, char **argv)
39 info.kernel_res = NULL;
40 info.default_res = "default.res";
41 info.override_res = NULL;
46 info.override_portno = NULL;
47 info.override_hostname = NULL;
48 info.databases = NULL;
54 info.kernel_res = gw_res_init ();
62 gw_log_level (GW_LOG_ALL);
66 strcpy (info.target, argv[0]+2);
70 strcpy (info.target, *++argv);
74 gw_log (GW_LOG_FATAL, "main", "missing target name");
80 info.lang = argv[0]+2;
88 gw_log (GW_LOG_FATAL, "main", "missing language name");
94 info.override_res = argv[0]+2;
98 info.override_res = *++argv;
102 gw_log (GW_LOG_FATAL, "main", "missing language name");
108 info.override_portno = argv[0]+2;
112 info.override_portno = *++argv;
116 gw_log (GW_LOG_FATAL, "main", "missing portno");
122 info.override_hostname = argv[0]+2;
126 info.override_hostname = *++argv;
130 gw_log (GW_LOG_FATAL, "main", "missing hostname");
136 gw_log_file (GW_LOG_ALL, argv[0]+2);
140 gw_log_file (GW_LOG_ALL, *++argv);
144 gw_log (GW_LOG_FATAL, "main", "missing log filename");
149 gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv);
154 info.default_res = *argv;
161 static FILE *fml_inf;
163 static int fml_inf_read (void)
165 return getc (fml_inf);
169 void read_kernel_res (void)
171 char path_prefix[128];
175 char resource_name[256];
178 ccl_qual_rm (&info.bibset);
179 info.bibset = ccl_qual_mk ();
182 gw_res_close (info.kernel_res);
183 info.kernel_res = gw_res_init ();
185 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s",
188 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s",
191 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s",
194 if (gw_res_merge (info.kernel_res, info.default_res))
196 gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s",
200 strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
204 sprintf (resource_name, "gw.target.%s", info.target);
205 v = gw_res_get (info.kernel_res, resource_name, NULL);
208 sprintf (fname, "%s/%s", path_prefix, v);
209 gw_res_merge (info.kernel_res, fname);
214 sprintf (resource_name, "gw.lang.%s", info.lang);
215 v = gw_res_get (info.kernel_res, resource_name, NULL);
218 sprintf (fname, "%s/%s", path_prefix, v);
219 gw_res_merge (info.kernel_res, fname);
222 if (info.override_res)
224 sprintf (fname, "%s/%s", path_prefix, info.override_res);
225 gw_res_merge (info.kernel_res, fname);
227 v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
232 sprintf (fname, "%s/%s", path_prefix, v);
233 bib_inf = fopen (fname, "r");
235 gw_log (GW_LOG_WARN, "main", "cannot open %s", fname);
238 gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname);
239 ccl_qual_file (info.bibset, bib_inf);
243 sprintf (resource_name, "gw.target.%s", info.target);
244 if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
246 /* target is there, and there is no sub-resource for it... */
249 if ((split = strchr (info.target, ':')))
251 strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
253 info.port = atoi (split);
255 info.port = atoi (gw_res_get
256 (info.kernel_res, "gw.portno", "210"));
260 strncpy (info.hostname, gw_res_get (info.kernel_res,
261 "gw.hostname", "localhost"),
262 sizeof(info.hostname)-1);
263 info.port = atoi (gw_res_get (info.kernel_res,
264 "gw.portno", "210"));
267 free (info.databases);
268 v = gw_res_get (info.kernel_res, "gw.databases", "");
269 info.databases = malloc (1+strlen(v));
270 assert (info.databases);
271 strcpy (info.databases, v);
272 for (cp = info.databases; (cp = strchr (cp, ' ')); cp++)
274 if (info.override_portno)
275 info.port = atoi (info.override_portno);
276 if (info.override_hostname)
277 strncpy (info.hostname, info.override_hostname,
278 sizeof(info.hostname)-1);
282 v = gw_res_get (info.kernel_res, "gw.fml", "default.fml");
283 sprintf (fname, "%s/%s", path_prefix, v);
284 fml_inf = fopen (fname, "r");
286 gw_log (GW_LOG_WARN, "main", "cannot open fml script %s", fname);
289 info.fml = fml_open ();
290 info.fml->read_func = fml_inf_read;
291 fml_preprocess (info.fml);