+ struct _xmlAttr *attr;
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ attr = ptr->properties;
+ if (!strcmp((const char *) ptr->name, "listen"))
+ {
+ /*
+ <listen id="listenerid">tcp:@:9999</listen>
+ */
+ const char *id = 0;
+ const char *address =
+ nmem_dup_xml_content(gfs_nmem, ptr->children);
+ for ( ; attr; attr = attr->next)
+ if (!xmlStrcmp(attr->name, BAD_CAST "id")
+ && attr->children && attr->children->type == XML_TEXT_NODE)
+ id = nmem_dup_xml_content(gfs_nmem, attr->children);
+ if (address)
+ {
+ *gfslp = gfs_listen_new(id, address);
+ gfslp = &(*gfslp)->next;
+ *gfslp = 0; /* make listener list consistent for search */
+ }
+ }
+ else if (!strcmp((const char *) ptr->name, "server"))
+ {
+ xmlNodePtr ptr_server = ptr;
+ xmlNodePtr ptr;
+ const char *listenref = 0;
+ const char *id = 0;
+ struct gfs_server *gfs;
+
+ for ( ; attr; attr = attr->next)
+ if (!xmlStrcmp(attr->name, BAD_CAST "listenref")
+ && attr->children && attr->children->type == XML_TEXT_NODE)
+ listenref = nmem_dup_xml_content(gfs_nmem, attr->children);
+ else if (!xmlStrcmp(attr->name, BAD_CAST "id")
+ && attr->children
+ && attr->children->type == XML_TEXT_NODE)
+ id = nmem_dup_xml_content(gfs_nmem, attr->children);
+ else
+ yaz_log(YLOG_WARN, "Unknown attribute '%s' for server",
+ attr->name);
+ gfs = *gfsp = gfs_server_new(id);
+ gfs->server_node_ptr = ptr_server;
+ if (listenref)
+ {
+ char **refs;
+ int num, i;
+ nmem_strsplit(gfs_nmem, ",", listenref, &refs, &num);
+ gfs->listen_ref = (int*) nmem_malloc(gfs_nmem,
+ sizeof(int) * (num + 1));
+ for (i = 0; i < num; i++)
+ {
+ int id_no;
+ struct gfs_listen *gl = gfs_listen_list;
+ gfs->listen_ref[i] = 0;
+ for (id_no = 1; gl; gl = gl->next, id_no++)
+ if (gl->id && !strcmp(gl->id, refs[i]))
+ {
+ gfs->listen_ref[i] = id_no;
+ break;
+ }
+ if (!gl)
+ yaz_log(YLOG_WARN, "Non-existent listenref '%s' "
+ "in server config element", refs[i]);
+ }
+ gfs->listen_ref[i] = -1;
+ }
+ for (ptr = ptr_server->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) ptr->name, "host"))
+ {
+ gfs->host = nmem_dup_xml_content(gfs_nmem,
+ ptr->children);
+ }
+ else if (!strcmp((const char *) ptr->name, "config"))
+ {
+ char fpath[1024];
+ strcpy(gfs->cb.configname,
+ nmem_dup_xml_content(gfs_nmem, ptr->children));
+
+ if (yaz_filepath_resolve(gfs->cb.configname,
+ base_path, 0, fpath))
+ strcpy(gfs->cb.configname, fpath);
+ }
+ else if (!strcmp((const char *) ptr->name, "cql2rpn"))
+ {
+ char fpath[1024];
+ char *fname = nmem_dup_xml_content(gfs_nmem, ptr->children);
+ if (yaz_filepath_resolve(fname, base_path, 0, fpath))
+ fname = fpath;
+
+ gfs->cql_transform = cql_transform_open_fname(fname);
+ if (!gfs->cql_transform)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO,
+ "open CQL transform file '%s'", fname);
+ exit(1);
+ }
+ }
+ else if (!strcmp((const char *) ptr->name, "ccl2rpn"))
+ {
+ char *fname, fpath[1024];
+ FILE *f;
+
+ fname = nmem_dup_xml_content(gfs_nmem, ptr->children);
+ if (yaz_filepath_resolve(fname, base_path, 0, fpath))
+ fname = fpath;
+
+ if ((f = fopen(fname, "r")) == 0) {
+ yaz_log(YLOG_FATAL, "can't open CCL file '%s'", fname);
+ exit(1);
+ }
+ gfs->ccl_transform = ccl_qual_mk();
+ ccl_qual_file (gfs->ccl_transform, f);
+ fclose(f);
+ }
+ else if (!strcmp((const char *) ptr->name, "directory"))
+ {
+ gfs->directory =
+ nmem_dup_xml_content(gfs_nmem, ptr->children);
+ }
+ else if (!strcmp((const char *) ptr->name, "docpath"))
+ {
+ gfs->docpath =
+ nmem_dup_xml_content(gfs_nmem, ptr->children);
+ }
+ else if (!strcmp((const char *) ptr->name, "maximumrecordsize"))
+ {
+ gfs->cb.maxrecordsize = atoi(
+ nmem_dup_xml_content(gfs_nmem, ptr->children));
+ }
+ else if (!strcmp((const char *) ptr->name, "stylesheet"))
+ {
+ char *s = nmem_dup_xml_content(gfs_nmem, ptr->children);
+ gfs->stylesheet = (char *)
+ nmem_malloc(gfs_nmem, strlen(s) + 2);
+ sprintf(gfs->stylesheet, "/%s", s);
+ }
+ else if (!strcmp((const char *) ptr->name,
+ "client_query_charset"))
+ {
+ gfs->client_query_charset =
+ nmem_dup_xml_content(gfs_nmem, ptr->children);
+ }
+ else if (!strcmp((const char *) ptr->name, "explain"))
+ {
+ ; /* being processed separately */
+ }
+ else if (!strcmp((const char *) ptr->name, "retrievalinfo"))
+ {
+ if (base_path)
+ yaz_retrieval_set_path(gfs->retrieval, base_path);
+ if (yaz_retrieval_configure(gfs->retrieval, ptr))
+ {
+ yaz_log(YLOG_FATAL, "%s in config %s",
+ yaz_retrieval_get_error(gfs->retrieval),
+ control_block.xml_config);
+ exit(1);
+ }
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "Unknown element '%s' in config %s",
+ ptr->name, control_block.xml_config);
+ exit(1);
+ }
+ }
+ gfsp = &(*gfsp)->next;
+ }