added a function lookup framework
* xpath.c include/libxml/xpath{,Internals}.h: added a function
lookup framework
diff --git a/ChangeLog b/ChangeLog
index 1673ac3..37ef8f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jul 26 18:55:52 CEST 2001 Thomas Broyer <tbroyer@ltgt.net>
+
+ * xpath.c include/libxml/xpath{,Internals}.h: added a function
+ lookup framework
+
Fri Jul 27 01:50:20 EDT 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tree.c: fixed xmlCopyNode() for documents
diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h
index a3c925a..8d921f8 100644
--- a/include/libxml/xpath.h
+++ b/include/libxml/xpath.h
@@ -231,6 +231,10 @@
/* The function name and URI when calling a function */
const xmlChar *function;
const xmlChar *functionURI;
+
+ /* function lookup function and data */
+ void *funcLookupFunc; /* function lookup func */
+ void *funcLookupData; /* function lookup data */
};
/*
diff --git a/include/libxml/xpathInternals.h b/include/libxml/xpathInternals.h
index ca3943f..63f3609 100644
--- a/include/libxml/xpathInternals.h
+++ b/include/libxml/xpathInternals.h
@@ -320,6 +320,18 @@
void *varCtxt);
/*
+ * Function Lookup forwarding
+ */
+typedef xmlXPathFunction
+ (*xmlXPathFuncLookupFunc) (void *ctxt,
+ const xmlChar *name,
+ const xmlChar *ns_uri);
+
+void xmlXPathRegisterFuncLookup (xmlXPathContextPtr ctxt,
+ xmlXPathFuncLookupFunc f,
+ void *funcCtxt);
+
+/*
* Error reporting
*/
void xmlXPatherror (xmlXPathParserContextPtr ctxt,
diff --git a/xpath.c b/xpath.c
index fc661f8..7f256dd 100644
--- a/xpath.c
+++ b/xpath.c
@@ -2310,6 +2310,24 @@
}
/**
+ * xmlXPathRegisterFuncLookup:
+ * @ctxt: the XPath context
+ * @f: the lookup function
+ * @data: the lookup data
+ *
+ * Registers an external mecanism to do function lookup.
+ */
+void
+xmlXPathRegisterFuncLookup (xmlXPathContextPtr ctxt,
+ xmlXPathFuncLookupFunc f,
+ void *funcCtxt) {
+ if (ctxt == NULL)
+ return;
+ ctxt->funcLookupFunc = (void *) f;
+ ctxt->funcLookupData = funcCtxt;
+}
+
+/**
* xmlXPathFunctionLookup:
* @ctxt: the XPath context
* @name: the function name
@@ -2321,6 +2339,17 @@
*/
xmlXPathFunction
xmlXPathFunctionLookup(xmlXPathContextPtr ctxt, const xmlChar *name) {
+ if (ctxt == NULL)
+ return (NULL);
+
+ if (ctxt->funcLookupFunc != NULL) {
+ xmlXPathFunction ret;
+
+ ret = ((xmlXPathFuncLookupFunc) ctxt->funcLookupFunc)
+ (ctxt->funcLookupData, name, NULL);
+ if (ret != NULL)
+ return(ret);
+ }
return(xmlXPathFunctionLookupNS(ctxt, name, NULL));
}
@@ -2340,11 +2369,21 @@
const xmlChar *ns_uri) {
if (ctxt == NULL)
return(NULL);
- if (ctxt->funcHash == NULL)
- return(NULL);
if (name == NULL)
return(NULL);
+ if (ctxt->funcLookupFunc != NULL) {
+ xmlXPathFunction ret;
+
+ ret = ((xmlXPathFuncLookupFunc) ctxt->funcLookupFunc)
+ (ctxt->funcLookupData, name, ns_uri);
+ if (ret != NULL)
+ return(ret);
+ }
+
+ if (ctxt->funcHash == NULL)
+ return(NULL);
+
return((xmlXPathFunction) xmlHashLookup2(ctxt->funcHash, name, ns_uri));
}