-int d1_check_xpath_predicate(data1_node *n, struct xpath_predicate *p) {
- int res = 1;
- char *attname;
- data1_xattr *attr;
-
- if (!p) {
- return (1);
- } else {
- if (p->which == XPATH_PREDICATE_RELATION) {
- if (p->u.relation.name[0]) {
- if (*p->u.relation.name != '@') {
- logf(LOG_WARN,
- " Only attributes (@) are supported in xelm xpath predicates");
- logf(LOG_WARN, "predicate %s ignored", p->u.relation.name);
- return (1);
- }
- attname = p->u.relation.name + 1;
- res = 0;
- /* looking for the attribute with a specified name */
- for (attr = n->u.tag.attributes; attr; attr = attr->next) {
- logf(LOG_DEBUG," - attribute %s <-> %s", attname, attr->name );
-
- if (!strcmp(attr->name, attname)) {
- if (p->u.relation.op[0]) {
- if (*p->u.relation.op != '=') {
- logf(LOG_WARN,
- "Only '=' relation is supported (%s)",p->u.relation.op);
- logf(LOG_WARN, "predicate %s ignored", p->u.relation.name);
- res = 1; break;
- } else {
- logf(LOG_DEBUG," - value %s <-> %s",
- p->u.relation.value, attr->value );
- if (!strcmp(attr->value, p->u.relation.value)) {
- res = 1; break;
- }
- }
- } else {
- /* attribute exists, no value specified */
- res = 1; break;
- }
- }
- }
- return (res);
- } else {
- return (1);
- }
- }
- else if (p->which == XPATH_PREDICATE_BOOLEAN) {
- if (!strcmp(p->u.boolean.op,"and")) {
- return (d1_check_xpath_predicate(n, p->u.boolean.left)
- && d1_check_xpath_predicate(n, p->u.boolean.right));
- }
- else if (!strcmp(p->u.boolean.op,"or")) {
- return (d1_check_xpath_predicate(n, p->u.boolean.left)
- || d1_check_xpath_predicate(n, p->u.boolean.right));
- } else {
- logf(LOG_WARN, "Unknown boolean relation %s, ignored",p->u.boolean.op);
- return (1);
- }
+int d1_check_xpath_predicate(data1_node *n, struct xpath_predicate *p)
+{
+ int res = 1;
+ char *attname;
+ data1_xattr *attr;
+
+ if (!p) {
+ return 1;
+ } else {
+ if (p->which == XPATH_PREDICATE_RELATION) {
+ if (p->u.relation.name[0]) {
+ if (*p->u.relation.name != '@') {
+ yaz_log(LOG_WARN,
+ " Only attributes (@) are supported in xelm xpath predicates");
+ yaz_log(LOG_WARN, "predicate %s ignored", p->u.relation.name);
+ return (1);
+ }
+ attname = p->u.relation.name + 1;
+ res = 0;
+ /* looking for the attribute with a specified name */
+ for (attr = n->u.tag.attributes; attr; attr = attr->next) {
+ yaz_log(LOG_DEBUG," - attribute %s <-> %s", attname, attr->name );
+
+ if (!strcmp(attr->name, attname)) {
+ if (p->u.relation.op[0]) {
+ if (*p->u.relation.op != '=') {
+ yaz_log(LOG_WARN,
+ "Only '=' relation is supported (%s)",p->u.relation.op);
+ yaz_log(LOG_WARN, "predicate %s ignored", p->u.relation.name);
+ res = 1; break;
+ } else {
+ yaz_log(LOG_DEBUG," - value %s <-> %s",
+ p->u.relation.value, attr->value );
+ if (!strcmp(attr->value, p->u.relation.value)) {
+ res = 1; break;
+ }
+ }
+ } else {
+ /* attribute exists, no value specified */
+ res = 1; break;
+ }
+ }
+ }
+ yaz_log(LOG_DEBUG, "return %d", res);
+ return res;
+ } else {
+ return 1;
+ }
+ }
+ else if (p->which == XPATH_PREDICATE_BOOLEAN) {
+ if (!strcmp(p->u.boolean.op,"and")) {
+ return d1_check_xpath_predicate(n, p->u.boolean.left)
+ && d1_check_xpath_predicate(n, p->u.boolean.right);
+ }
+ else if (!strcmp(p->u.boolean.op,"or")) {
+ return (d1_check_xpath_predicate(n, p->u.boolean.left)
+ || d1_check_xpath_predicate(n, p->u.boolean.right));
+ } else {
+ yaz_log(LOG_WARN, "Unknown boolean relation %s, ignored",p->u.boolean.op);
+ return 1;
+ }
+ }