18#include <libxml/parser.h>
19#include <libxml/tree.h>
29 int *error_code,
const char **addinfo)
31 if (ptr && ptr->type == XML_ELEMENT_NODE &&
32 !xmlStrcmp(ptr->name, BAD_CAST
"diagnostic"))
34 struct _xmlAttr *attr;
35 const char *code_str = 0;
36 const char *addinfo_str = 0;
37 for (attr = ptr->properties; attr; attr = attr->next)
39 if (!xmlStrcmp(attr->name, BAD_CAST
"code") &&
40 attr->children && attr->children->type == XML_TEXT_NODE)
41 code_str = (
const char *) attr->children->content;
42 else if (!xmlStrcmp(attr->name, BAD_CAST
"addinfo") &&
43 attr->children && attr->children->type == XML_TEXT_NODE)
44 addinfo_str = (
const char *) attr->children->content;
48 *addinfo =
"bad attribute for diagnostic element";
55 *addinfo =
"missing @code for diagnostic element";
58 *error_code = atoi(code_str);
71 const char *setname = 0;
82 xmlNodePtr node = xmlNewChild(parent, 0, BAD_CAST
"attr", 0);
85 xmlNewProp(node, BAD_CAST
"set", BAD_CAST setname);
88 xmlNewProp(node, BAD_CAST
"type", BAD_CAST formstr);
91 xmlNewProp(node, BAD_CAST
"value", BAD_CAST formstr);
98 xmlNodePtr node = xmlNewChild(parent, 0, BAD_CAST
"attr", 0);
101 xmlNewProp(node, BAD_CAST
"set", BAD_CAST setname);
104 xmlNewProp(node, BAD_CAST
"type", BAD_CAST formstr);
109 xmlNewProp(node, BAD_CAST
"value", BAD_CAST
117 xmlNewProp(node, BAD_CAST
"value", BAD_CAST formstr);
127 xmlNodePtr node = xmlNewChild(parent, 0, BAD_CAST
"term", 0);
129 const char *
type = 0;
140 t = xmlNewText(BAD_CAST formstr);
156 type =
"integerAndUnit";
165 xmlAddChild(node, t);
167 xmlNewProp(node, BAD_CAST
"type", BAD_CAST
type);
174 xmlNodePtr node = xmlNewChild(parent, 0, BAD_CAST
"apt", 0);
177 for (i = 0; i<num_attributes; i++)
187 const char *
type = 0;
205 xmlNewProp(node, BAD_CAST
"type", BAD_CAST
type);
214 xmlNewProp(node, BAD_CAST
"exclusion", BAD_CAST
"true");
216 xmlNewProp(node, BAD_CAST
"exclusion", BAD_CAST
"false");
219 xmlNewProp(node, BAD_CAST
"distance", BAD_CAST formstr);
222 xmlNewProp(node, BAD_CAST
"ordered", BAD_CAST
"true");
224 xmlNewProp(node, BAD_CAST
"ordered", BAD_CAST
"false");
227 xmlNewProp(node, BAD_CAST
"relationType", BAD_CAST formstr);
233 xmlNewProp(node, BAD_CAST
"knownProximityUnit",
238 xmlNewProp(node, BAD_CAST
"privateProximityUnit",
252 xmlNodePtr node = xmlNewChild(parent, 0, BAD_CAST
"operator", 0);
265 return xmlNewChild(parent, 0, BAD_CAST
"rset",
279 xmlNewProp(parent, BAD_CAST
"set", BAD_CAST setname);
310 xmlNodePtr top_node, q_node = 0, child_node = 0;
315 top_node = xmlNewNode(0, BAD_CAST
"query");
321 q_node = xmlNewChild(top_node, 0, BAD_CAST
"rpn", 0);
325 q_node = xmlNewChild(top_node, 0, BAD_CAST
"ccl", 0);
329 q_node = xmlNewChild(top_node, 0, BAD_CAST
"z39.58", 0);
335 q_node = xmlNewChild(top_node, 0, BAD_CAST
"cql", 0);
339 if (child_node && q_node)
341 *docp = xmlNewDoc(BAD_CAST
"1.0");
342 xmlDocSetRootElement(*docp, top_node);
347 xmlFreeNode(top_node);
353 if (*str ==
'\0' || strchr(
"0fF", *str))
365 int *error_code,
const char **addinfo)
371 *addinfo =
"no operator type";
375 if (!strcmp(
type,
"and"))
380 else if (!strcmp(
type,
"or"))
385 else if (!strcmp(
type,
"not"))
390 else if (!strcmp(
type,
"prox"))
392 struct _xmlAttr *attr;
406 for (attr = ptr->properties; attr; attr = attr->next)
408 const char *value = (
const char *) attr->children->content;
409 if (!xmlStrcmp(attr->name, BAD_CAST
"type"))
411 else if (!xmlStrcmp(attr->name, BAD_CAST
"exclusion"))
413 else if (!xmlStrcmp(attr->name, BAD_CAST
"distance"))
415 else if (!xmlStrcmp(attr->name, BAD_CAST
"ordered"))
417 else if (!xmlStrcmp(attr->name, BAD_CAST
"relationType"))
419 else if (!xmlStrcmp(attr->name, BAD_CAST
"knownProximityUnit"))
424 else if (!xmlStrcmp(attr->name, BAD_CAST
"privateProximityUnit"))
432 *addinfo =
"bad proximity attribute";
440 *addinfo =
"bad operator type";
447 const char **addinfo)
454 struct _xmlAttr *attr;
455 for (attr = ptr->properties; attr; attr = attr->next)
457 if (!xmlStrcmp(attr->name, BAD_CAST
"set") &&
458 attr->children && attr->children->type == XML_TEXT_NODE)
459 set = attr->children->content;
460 else if (!xmlStrcmp(attr->name, BAD_CAST
"type") &&
461 attr->children && attr->children->type == XML_TEXT_NODE)
462 type = attr->children->content;
463 else if (!xmlStrcmp(attr->name, BAD_CAST
"value") &&
464 attr->children && attr->children->type == XML_TEXT_NODE)
466 value = attr->children->content;
472 *addinfo =
"bad attribute for attr content";
479 *addinfo =
"missing type attribute for att content";
485 *addinfo =
"missing value attribute for att content";
496 (*elem)->attributeSet = 0;
500 for (i = 0; value[i] && value[i] >=
'0' && value[i] <=
'9'; i++)
502 if (num_values > 1 || value[i])
505 (*elem)->value.complex =
507 (*elem)->value.complex->num_list = num_values;
513 for (attr = ptr->properties; attr; attr = attr->next)
515 if (!xmlStrcmp(attr->name, BAD_CAST
"value") &&
516 attr->children && attr->children->type == XML_TEXT_NODE)
518 const char *val = (
const char *) attr->children->content;
519 assert (i < num_values);
522 (*elem)->value.complex->list[i]->which =
524 (*elem)->value.complex->list[i]->u.string =
529 (*elem)->value.complex->num_semanticAction = 0;
530 (*elem)->value.complex->semanticAction = 0;
535 (*elem)->value.numeric =
intVal(
odr, (
const char *) value);
545 int *error_code,
const char **addinfo)
548 struct _xmlAttr *attr;
549 char *cdata =
strVal(ptr->children,
odr);
551 for (attr = ptr->properties; attr; attr = attr->next)
553 if (!xmlStrcmp(attr->name, BAD_CAST
"type") &&
554 attr->children && attr->children->type == XML_TEXT_NODE)
555 type = attr->children->content;
559 *addinfo =
"bad attribute for attr content";
565 if (!
type || !xmlStrcmp(
type, BAD_CAST
"general"))
571 else if (!xmlStrcmp(
type, BAD_CAST
"numeric"))
576 else if (!xmlStrcmp(
type, BAD_CAST
"string"))
579 (*term)->u.characterString = cdata;
581 else if (!xmlStrcmp(
type, BAD_CAST
"oid"))
584 *addinfo =
"unhandled term type: oid";
586 else if (!xmlStrcmp(
type, BAD_CAST
"dateTime"))
589 *addinfo =
"unhandled term type: dateTime";
591 else if (!xmlStrcmp(
type, BAD_CAST
"integerAndUnit"))
594 *addinfo =
"unhandled term type: integerAndUnit";
596 else if (!xmlStrcmp(
type, BAD_CAST
"null"))
604 *addinfo =
"unhandled term type";
610 int *error_code,
const char **addinfo)
612 const xmlNode *ptr = ptr_apt->children;
623 for (; ptr; ptr = ptr->next)
624 if (ptr->type == XML_ELEMENT_NODE)
626 if (!xmlStrcmp(ptr->name, BAD_CAST
"attr"))
633 (*zapt)->
attributes->num_attributes = num_attr;
638 ptr = ptr_apt->children;
639 for (; ptr; ptr = ptr->next)
640 if (ptr->type == XML_ELEMENT_NODE)
642 if (!xmlStrcmp(ptr->name, BAD_CAST
"attr"))
645 ptr, &(*zapt)->attributes->attributes[i],
odr,
646 error_code, addinfo);
655 if (ptr && ptr->type == XML_ELEMENT_NODE)
657 if (!xmlStrcmp(ptr->name, BAD_CAST
"term"))
665 *addinfo =
"bad element in apt content";
671 *addinfo =
"missing term node in apt content";
676 ODR odr,
int *error_code,
const char **addinfo)
685 *addinfo =
"missing rset content";
691 int *error_code,
const char **addinfo)
693 while (ptr && ptr->type != XML_ELEMENT_NODE)
696 if (!ptr || ptr->type != XML_ELEMENT_NODE)
699 *addinfo =
"missing rpn operator, rset, apt node";
706 if (!xmlStrcmp(ptr->name, BAD_CAST
"operator"))
711 (*zs)->u.complex = zc;
716 while (ptr && ptr->type != XML_ELEMENT_NODE)
721 while (ptr && ptr->type != XML_ELEMENT_NODE)
730 if (!xmlStrcmp(ptr->name, BAD_CAST
"apt"))
734 odr, error_code, addinfo);
736 else if (!xmlStrcmp(ptr->name, BAD_CAST
"rset"))
740 odr, error_code, addinfo);
745 *addinfo =
"bad element: expected binary, apt or rset";
751 int *error_code,
const char **addinfo)
758 (*query)->attributeSetId =
765 odr, error_code, addinfo);
769 int *error_code,
const char **addinfo)
773 if (ptr && ptr->type == XML_ELEMENT_NODE &&
774 !xmlStrcmp(ptr->name, BAD_CAST
"query"))
778 while (ptr && ptr->type != XML_ELEMENT_NODE)
780 if (!ptr || ptr->type != XML_ELEMENT_NODE)
783 *addinfo =
"missing query content";
786 type = (
const char *) ptr->name;
793 error_code, addinfo);
795 else if (!strcmp(
type,
"ccl"))
798 *addinfo =
"ccl not supported yet";
800 else if (!strcmp(
type,
"z39.58"))
803 *addinfo =
"z39.58 not supported yet";
805 else if (!strcmp(
type,
"cql"))
808 *addinfo =
"cql not supported yet";
813 *addinfo =
"unsupported query type";
819 *addinfo =
"missing query element";
824 int *error_code,
const char **addinfo)
Header for Z39.50 Query Printing.
char * nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
Header for Nibble Memory functions + Libxml2 specific stuff.
Odr_null * odr_nullval(void)
Odr_oct * odr_create_Odr_oct(ODR o, const char *buf, int sz)
Odr_int * odr_intdup(ODR o, Odr_int v)
void * odr_malloc(ODR o, size_t size)
Odr_bool * odr_booldup(ODR o, Odr_bool v)
char * odr_strdup(ODR o, const char *str)
yaz_oid_db_t yaz_oid_std(void)
returns standard OID database
const char * yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf)
maps any OID to string (named or dot-notation)
Odr_oid * yaz_string_to_oid_odr(yaz_oid_db_t oid_list, oid_class oclass, const char *name, ODR o)
creates ODR malloc'ed OID from string
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Header for config file reading utilities.
Z_ComplexAttribute * complex
Z_AttributeSetId * attributeSet
union Z_AttributeElement::@260252174261265367116362007076255375270002041323 value
Z_AttributeElement ** attributes
Z_AttributeList * attributes
Z_StringOrNumeric ** list
union Z_External::@173112132151266201036013025012152147264102163302 u
Z_InternationalString * cql
Z_ResultSetId * resultSetId
Z_AttributesPlusTerm * attributesPlusTerm
union Z_Operand::@072322006164213251104156071070134267373322123052 u
Z_ProximityOperator * prox
union Z_Operator::@171225215357037113014354143242105145344254361002 u
union Z_ProximityOperator::@031336250334025346341060256205106006053041305237 u
union Z_Query::@270220245041066023256025363242165325012357336235 u
Z_AttributeSetId * attributeSetId
Z_RPNStructure * RPNStructure
union Z_RPNStructure::@272042053041255367154306203353273370010236313243 u
union Z_StringOrNumeric::@255321135104110073015132067151226017215302214211 u
Z_InternationalString * string
union Z_Term::@023217361022206241314262227377164117366363003164 u
Z_InternationalString * characterString
const char * yaz_xml_get_prop(const xmlNode *n, const char *fmt,...)
XML node getter/creation utilities.
static bool_t * boolVal(ODR odr, const char *str)
static void yaz_xml2query_attribute_element(const xmlNode *ptr, Z_AttributeElement **elem, ODR odr, int *error_code, const char **addinfo)
static int check_diagnostic(const xmlNode *ptr, ODR odr, int *error_code, const char **addinfo)
void yaz_query2xml(const Z_Query *q, xmlDocPtr *docp)
static void yaz_xml2query_rset(const xmlNode *ptr, Z_ResultSetId **rset, ODR odr, int *error_code, const char **addinfo)
static Odr_int * intVal(ODR odr, const char *str)
static xmlNodePtr yaz_query2xml_ccl(const Odr_oct *ccl, xmlNodePtr node)
static void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, ODR odr, int *error_code, const char **addinfo)
static void yaz_xml2query_(const xmlNode *ptr, Z_Query **query, ODR odr, int *error_code, const char **addinfo)
void yaz_rpnquery2xml(const Z_RPNQuery *rpn, xmlDocPtr *docp)
static char * strVal(const xmlNode *ptr_cdata, ODR odr)
static void yaz_xml2query_rpn(const xmlNode *ptr, Z_RPNQuery **query, ODR odr, int *error_code, const char **addinfo)
static void yaz_query2xml_attribute_element(const Z_AttributeElement *element, xmlNodePtr parent)
static xmlNodePtr yaz_query2xml_term(const Z_Term *term, xmlNodePtr parent)
static void yaz_query2xml_operator(Z_Operator *op, xmlNodePtr node)
static xmlNodePtr yaz_query2xml_cql(const char *cql, xmlNodePtr node)
static xmlNodePtr yaz_query2xml_z3958(const Odr_oct *ccl, xmlNodePtr node)
static void yaz_xml2query_term(const xmlNode *ptr, Z_Term **term, ODR odr, int *error_code, const char **addinfo)
static xmlNodePtr yaz_query2xml_rpnstructure(const Z_RPNStructure *zs, xmlNodePtr parent)
static xmlNodePtr yaz_query2xml_rpn(const Z_RPNQuery *rpn, xmlNodePtr parent)
static xmlNodePtr yaz_query2xml_apt(const Z_AttributesPlusTerm *zapt, xmlNodePtr parent)
void yaz_xml2query(const xmlNode *xmlnodep, Z_Query **query, ODR odr, int *error_code, const char **addinfo)
static void yaz_xml2query_apt(const xmlNode *ptr_apt, Z_AttributesPlusTerm **zapt, ODR odr, int *error_code, const char **addinfo)
static void yaz_xml2query_operator(const xmlNode *ptr, Z_Operator **op, ODR odr, int *error_code, const char **addinfo)
#define Z_AttributeValue_numeric
#define Z_Operator_and_not
#define Z_Term_characterString
#define Z_ProximityOperator_Prox_lessThanOrEqual
#define Z_ProximityOperator_private
#define Z_StringOrNumeric_numeric
#define Z_ProximityOperator_known
#define Z_AttributeValue_complex
#define Z_StringOrNumeric_string
#define Z_Operand_resultSetId
#define Z_RPNStructure_complex
Z_InternationalString Z_ResultSetId
#define Z_RPNStructure_simple
#define Z_Term_integerAndUnit