cluster: STABLE3 - config: Make rng2ldif handle 'ref' properly
Lon Hohberger
lon at fedoraproject.org
Thu Nov 19 18:22:53 UTC 2009
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=f19ed05b99f431c3be75e061b637a9da4ced478a
Commit: f19ed05b99f431c3be75e061b637a9da4ced478a
Parent: 7b432e653a5cf8bba7162b096f225a9ed01e3449
Author: Lon Hohberger <lhh at redhat.com>
AuthorDate: Thu Nov 19 12:18:00 2009 -0500
Committer: Lon Hohberger <lhh at redhat.com>
CommitterDate: Thu Nov 19 12:18:00 2009 -0500
config: Make rng2ldif handle 'ref' properly
Signed-off-by: Lon Hohberger <lhh at redhat.com>
---
config/tools/ldap/rng2ldif/tree.c | 70 +++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/config/tools/ldap/rng2ldif/tree.c b/config/tools/ldap/rng2ldif/tree.c
index 85a02ce..69fa139 100644
--- a/config/tools/ldap/rng2ldif/tree.c
+++ b/config/tools/ldap/rng2ldif/tree.c
@@ -3,6 +3,8 @@
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <assert.h>
#include "zalloc.h"
#include "value-list.h"
@@ -141,6 +143,43 @@ find_obj(struct ldap_object_node *objs, const char *name)
}
+static xmlNodePtr
+find_ref(xmlNodePtr curr_node)
+{
+ xmlNodePtr n;
+ char *name;
+ char *tmp_name;
+
+ dbg_printf("Trying to parse ref tag\n");
+ name = (char *)xmlGetProp(curr_node, (xmlChar *)"name");
+
+ n = xmlDocGetRootElement(curr_node->doc);
+ n = n->xmlChildrenNode;
+ for (; n; n = n->next) {
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (strcasecmp((char *)n->name, "define"))
+ continue;
+
+ tmp_name = (char *)xmlGetProp(n, "name");
+ if (!tmp_name)
+ continue;
+ if (strcmp(tmp_name, name))
+ continue;
+
+ break;
+ }
+
+ if (!n) {
+ fprintf(stderr, "Error in RelaxNG schema!\n");
+ fprintf(stderr, "Unterminated reference: %s\n",
+ name);
+ exit(1);
+ }
+
+ return n->xmlChildrenNode;
+}
+
static int
find_optional_attributes(xmlNodePtr curr_node, int in_block,
@@ -162,6 +201,10 @@ find_optional_attributes(xmlNodePtr curr_node, int in_block,
for (node = curr_node; node; node = node->next) {
if (node->type != XML_ELEMENT_NODE)
continue;
+ if (!strcasecmp((char *)node->name, "ref")) {
+ find_optional_attributes(
+ find_ref(node), 1, curr_obj, attrs, ids);
+ }
if (!strcasecmp((char *)node->name, "choice")) {
find_optional_attributes(node->xmlChildrenNode, 1,
curr_obj,
@@ -315,6 +358,33 @@ parse_element_tag(xmlNodePtr curr_node,
}
+#if 0
+static struct ldap_object_node *
+parse_ref_tag(xmlNodePtr curr_node,
+ struct ldap_object_node **objs,
+ struct ldap_attr_node **attrs,
+ struct idinfo *ids)
+{
+ xmlXPathObjectPtr xobj;
+ xmlXPathContextPtr xctx;
+ char query[1024];
+ char *n;
+
+ dbg_printf("Trying to parse ref tag\n");
+ n = (char *)xmlGetProp(curr_node, (xmlChar *)"name");
+
+ snprintf(query, sizeof(query), "//define[@name=\"%s\"]", n);
+ xctx = xmlXPathNewContext(curr_node->doc);
+ assert(xctx);
+ xobj = xmlXPathEvalExpression((xmlChar *)query, xctx);
+
+ printf("%d nodes match %s\n", xobj->nodesetval->nodeNr, query);
+
+ assert(0);
+ return NULL;
+}
+#endif
+
int
find_objects(xmlNodePtr curr_node,
struct ldap_object_node **objs,
More information about the cluster-commits
mailing list