diff --git a/ChangeLog b/ChangeLog index 1673ac34..37ef8f46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 26 18:55:52 CEST 2001 Thomas Broyer + + * xpath.c include/libxml/xpath{,Internals}.h: added a function + lookup framework + Fri Jul 27 01:50:20 EDT 2001 Daniel Veillard * tree.c: fixed xmlCopyNode() for documents diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h index a3c925a7..8d921f85 100644 --- a/include/libxml/xpath.h +++ b/include/libxml/xpath.h @@ -231,6 +231,10 @@ struct _xmlXPathContext { /* 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 ca3943f4..63f36095 100644 --- a/include/libxml/xpathInternals.h +++ b/include/libxml/xpathInternals.h @@ -319,6 +319,18 @@ void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt, xmlXPathVariableLookupFunc f, 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 */ diff --git a/xpath.c b/xpath.c index fc661f89..7f256dd0 100644 --- a/xpath.c +++ b/xpath.c @@ -2309,6 +2309,24 @@ xmlXPathRegisterFuncNS(xmlXPathContextPtr ctxt, const xmlChar *name, return(xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, (void *) f)); } +/** + * 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 @@ -2321,6 +2339,17 @@ xmlXPathRegisterFuncNS(xmlXPathContextPtr ctxt, const xmlChar *name, */ 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 @@ xmlXPathFunctionLookupNS(xmlXPathContextPtr ctxt, const xmlChar *name, 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)); }