5 * Revision 1.3 1995/02/16 18:35:09 adam
6 * First use of Zdist library. Search requests are supported.
7 * Present requests are not supported yet.
9 * Revision 1.2 1995/02/16 13:21:00 adam
10 * Organization of resource files for targets and conversion
11 * language implemented.
13 * Revision 1.1 1995/02/15 17:45:29 adam
14 * First version of email gateway kernel. Email requests are read
15 * from stdin. The output is transferred to an MTA if 'From' is
16 * found in the header - or stdout if absent. No Z39.50 client is used.
27 FILE *reply_fd = stdout;
29 struct gw_kernel_info info;
31 int main (int argc, char **argv)
33 info.kernel_res = NULL;
34 info.default_res = "default.res";
35 info.override_res = NULL;
40 info.override_portno = NULL;
41 info.override_hostname = NULL;
42 info.databases = NULL;
45 info.kernel_res = gw_res_init ();
53 gw_log_level (GW_LOG_ALL);
57 strcpy (info.target, argv[0]+2);
61 strcpy (info.target, *++argv);
65 gw_log (GW_LOG_FATAL, "main", "missing target name");
71 info.lang = argv[0]+2;
79 gw_log (GW_LOG_FATAL, "main", "missing language name");
85 info.override_res = argv[0]+2;
89 info.override_res = *++argv;
93 gw_log (GW_LOG_FATAL, "main", "missing language name");
99 info.override_portno = argv[0]+2;
103 info.override_portno = *++argv;
107 gw_log (GW_LOG_FATAL, "main", "missing portno");
113 info.override_hostname = argv[0]+2;
117 info.override_hostname = *++argv;
121 gw_log (GW_LOG_FATAL, "main", "missing hostname");
126 gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv);
131 info.default_res = *argv;
138 void read_kernel_res (void)
140 char path_prefix[128];
144 char resource_name[256];
147 ccl_qual_rm (&info.bibset);
148 info.bibset = ccl_qual_mk ();
151 gw_res_close (info.kernel_res);
152 info.kernel_res = gw_res_init ();
154 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s",
157 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s",
160 gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s",
163 if (gw_res_merge (info.kernel_res, info.default_res))
165 gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s",
169 strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
173 sprintf (resource_name, "gw.target.%s", info.target);
174 v = gw_res_get (info.kernel_res, resource_name, NULL);
177 sprintf (fname, "%s/%s", path_prefix, v);
178 gw_res_merge (info.kernel_res, fname);
183 sprintf (resource_name, "gw.lang.%s", info.lang);
184 v = gw_res_get (info.kernel_res, resource_name, NULL);
187 sprintf (fname, "%s/%s", path_prefix, v);
188 gw_res_merge (info.kernel_res, fname);
191 if (info.override_res)
193 sprintf (fname, "%s/%s", path_prefix, info.override_res);
194 gw_res_merge (info.kernel_res, fname);
196 v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
201 sprintf (fname, "%s/%s", path_prefix, v);
202 bib_inf = fopen (fname, "r");
204 gw_log (GW_LOG_WARN, "main", "cannot open %s", fname);
207 gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname);
208 ccl_qual_file (info.bibset, bib_inf);
212 sprintf (resource_name, "gw.target.%s", info.target);
213 if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
215 /* target is there, and there is no sub-resource for it... */
218 if ((split = strchr (info.target, ':')))
220 strncpy (info.hostname, info.target, sizeof(info.hostname)-1);
222 info.port = atoi (split);
224 info.port = atoi (gw_res_get
225 (info.kernel_res, "gw.portno", "210"));
229 strncpy (info.hostname, gw_res_get (info.kernel_res,
230 "gw.hostname", "localhost"),
231 sizeof(info.hostname)-1);
232 info.port = atoi (gw_res_get (info.kernel_res,
233 "gw.portno", "210"));
236 free (info.databases);
237 v = gw_res_get (info.kernel_res, "gw.databases", "Default");
238 info.databases = malloc (1+strlen(v));
239 assert (info.databases);
240 strcpy (info.databases, v);
241 for (cp = info.databases; (cp = strchr (cp, ' ')); cp++)
243 if (info.override_portno)
244 info.port = atoi (info.override_portno);
245 if (info.override_hostname)
246 strncpy (info.hostname, info.override_hostname,
247 sizeof(info.hostname)-1);