X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fzeerex.c;h=2340123271c5b763f661c3a5380fe79c97fb1245;hb=56d94019bbdff3b9823069b61f0f0ec6a671f923;hp=d2b7dc7636653ec4a5a90ded3322a5808c6c1de8;hpb=1c67f9fb6408afadc117241e01d4963c4ba7e8c1;p=pazpar2-moved-to-github.git diff --git a/src/zeerex.c b/src/zeerex.c index d2b7dc7..2340123 100644 --- a/src/zeerex.c +++ b/src/zeerex.c @@ -1,4 +1,6 @@ -/* $Id: zeerex.c,v 1.1 2007-01-29 03:19:25 quinn Exp $ */ +/* $Id: zeerex.c,v 1.4 2007-03-15 16:50:56 quinn Exp $ */ + +// Reads Zeerex records into a set of structures #include @@ -12,7 +14,7 @@ // Replace this with something that will take a callback static void fail(const char *s, xmlNode *n) { - yaz_log(YLOG_WARN, "Zeerex Err '%s' in elem '%s/%s'", s, n->parent->name, n->name); + yaz_log(YLOG_WARN, "Zeerex Err '%s'; elem '%s/%s'", s, n->parent->name, n->name); } // returns an nmem-allocated string if attr is present, or null @@ -107,6 +109,16 @@ static Zr_langstr *findlangstr(NMEM m, xmlNode *node, const char *name) return res; } +const char *zr_langstr(Zr_langstr *s, const char *lang) +{ + Zr_langstr *p; + for (p = s; p; p = p->next) + if ((!lang && p->primary == Zr_bool_true) || + (lang && p->lang && !strcmp(lang, p->lang))) + return p->str; + return s->str; +} + static struct zr_authentication *authentication(NMEM m, xmlNode *node) { xmlNode *n; @@ -141,10 +153,10 @@ static struct zr_serverInfo *serverInfo(NMEM m, xmlNode *node) struct zr_serverInfo *r = nmem_malloc(m, sizeof(*r)); memset(r, 0, sizeof(*r)); - r->protocol = attrtostr(m, n, "protocol"); - r->version = attrtostr(m, n, "version"); - r->transport = attrtostr(m, n, "transport"); - r->method = attrtostr(m, n, "method"); + r->protocol = attrtostr(m, node, "protocol"); + r->version = attrtostr(m, node, "version"); + r->transport = attrtostr(m, node, "transport"); + r->method = attrtostr(m, node, "method"); for (n = node->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) @@ -155,9 +167,11 @@ static struct zr_serverInfo *serverInfo(NMEM m, xmlNode *node) r->port = valuetoint(n); else if (!strcmp(n->name, "database")) r->database = valuetostr(m, n); - else if (!strcmp(n->name, "authentication") && !(r->authentication = - authentication(m, n))) - return 0; + else if (!strcmp(n->name, "authentication")) + { + if (!(r->authentication = authentication(m, n))) + return 0; + } else { fail("Unexpected element", n); @@ -203,9 +217,9 @@ static struct zr_implementation *implementation(NMEM m, xmlNode *node) struct zr_databaseInfo *databaseInfo(NMEM m, xmlNode *node) { + xmlNode *n; struct zr_databaseInfo *r = nmem_malloc(m, sizeof(*r)); memset(r, 0, sizeof(*r)); - xmlNode *n; r->title = findlangstr(m, node, "title"); r->description = findlangstr(m, node, "description"); @@ -237,15 +251,17 @@ struct zr_databaseInfo *databaseInfo(NMEM m, xmlNode *node) } } } - else if (!strcmp(n->name, "implementation") && - !(r->implementation = implementation(m, n))) - return 0; + else if (!strcmp(n->name, "implementation")) + { + if (!(r->implementation = implementation(m, n))) + return 0; + } else if (!strcmp(n->name, "links")) { xmlNode *n2; for (n2 = n->children; n2; n2 = n2->next) { - if (!n2->type != XML_ELEMENT_NODE) + if (n2->type != XML_ELEMENT_NODE) continue; if (!strcmp(n2->name, "link")) continue; @@ -278,7 +294,7 @@ struct zr_metaInfo *metaInfo(NMEM m, xmlNode *node) for (n = node->children; n; n = n->next) { - if (!n->type == XML_ELEMENT_NODE) + if (n->type != XML_ELEMENT_NODE) continue; if (!strcmp(n->name, "dateModified")) r->dateModified = valuetostr(m, n); @@ -389,7 +405,7 @@ static struct zr_configInfo *configInfo(NMEM m, xmlNode *node) return r; } -static struct zr_index *index(NMEM m, xmlNode *node) +static struct zr_index *parse_index(NMEM m, xmlNode *node) { xmlNode *n; struct zr_index *r = nmem_malloc(m, sizeof(*r)); @@ -403,6 +419,8 @@ static struct zr_index *index(NMEM m, xmlNode *node) for (n = node->children; n; n = n->next) { + if (n->type != XML_ELEMENT_NODE) + continue; if (!strcmp(n->name, "map")) { struct zr_map *new = map(m, n); @@ -411,8 +429,11 @@ static struct zr_index *index(NMEM m, xmlNode *node) new->next = r->maps; r->maps = new; } - else if (!strcmp(n->name, "configInfo") && !(r->configInfo = configInfo(m, n))) - return 0; + else if (!strcmp(n->name, "configInfo")) + { + if (!(r->configInfo = configInfo(m, n))) + return 0; + } else if (strcmp(n->name, "title")) { fail("Unknown child element", n); @@ -450,7 +471,7 @@ static struct zr_indexInfo *indexInfo(NMEM m , xmlNode *node) } else if (!strcmp(n->name, "index")) { - struct zr_index *new = index(m, n); + struct zr_index *new = parse_index(m, n); if (!new) return 0; new->next = r->indexes; @@ -464,8 +485,11 @@ static struct zr_indexInfo *indexInfo(NMEM m , xmlNode *node) new->next = r->sortKeywords; r->sortKeywords = new; } - else if (!strcmp(n->name, "sortKeyword") && !(r->configInfo = configInfo(m, n))) - return 0; + else if (!strcmp(n->name, "sortKeyword")) + { + if (!(r->configInfo = configInfo(m, n))) + return 0; + } else { fail("Unknown child element", n); @@ -489,9 +513,9 @@ static struct zr_recordSyntax *recordSyntax(NMEM m, xmlNode *node) { xmlNode *n; struct zr_recordSyntax *r = nmem_malloc(m, sizeof(*r)); - memset(r, 0, sizeof(*r)); struct zr_elementSet **elementp = &r->elementSets; + memset(r, 0, sizeof(*r)); r->name = attrtostr(m, node, "name"); r->identifier = attrtostr(m, node, "identifier"); for (n = node->children; n; n = n->next) @@ -517,9 +541,9 @@ static struct zr_recordInfo *recordInfo(NMEM m, xmlNode *node) { xmlNode *n; struct zr_recordInfo *r = nmem_malloc(m, sizeof(*r)); - memset(r, 0, sizeof(*r)); struct zr_recordSyntax **syntaxp = &r->recordSyntaxes; + memset(r, 0, sizeof(*r)); for (n = node->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) @@ -558,9 +582,9 @@ static struct zr_schemaInfo *schemaInfo(NMEM m, xmlNode *node) { xmlNode *n; struct zr_schemaInfo *r = nmem_malloc(m, sizeof(*r)); - memset(r, 0, sizeof(*r)); struct zr_schema **schemap = &r->schemas; + memset(r, 0, sizeof(*r)); for (n = node->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) @@ -590,23 +614,46 @@ static struct zr_explain *explain(NMEM m, xmlNode *node) { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp(n->name, "serverInfo") && !(r->serverInfo = serverInfo(m, n))) - return 0; - else if (!strcmp(n->name, "databaseInfo") && !(r->databaseInfo = databaseInfo(m, n))) - return 0; - else if (!strcmp(n->name, "metaInfo") && !(r->metaInfo = metaInfo(m, n))) - return 0; - else if (!strcmp(n->name, "indexInfo") && !(r->indexInfo = indexInfo(m, n))) - return 0; - else if (!strcmp(n->name, "recordInfo") && !(r->recordInfo = recordInfo(m, n))) - return 0; - else if (!strcmp(n->name, "schemaInfo") && !(r->schemaInfo = schemaInfo(m, n))) - return 0; - else if (!strcmp(n->name, "configInfo") && !(r->configInfo = configInfo(m, n))) - return 0; + if (!strcmp(n->name, "serverInfo")) + { + if (!(r->serverInfo = serverInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "databaseInfo")) + { + if (!(r->databaseInfo = databaseInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "metaInfo")) + { + if (!(r->metaInfo = metaInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "indexInfo")) + { + if (!(r->indexInfo = indexInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "recordInfo")) + { + if (!(r->recordInfo = recordInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "schemaInfo")) + { + if (!(r->schemaInfo = schemaInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "configInfo")) + { + if (!(r->configInfo = configInfo(m, n))) + return 0; + } + else if (!strcmp(n->name, "status")) + continue; else { - fail("Unknown child element", n); + fail("Unknown child element of root node", n); return 0; } }