1 /*
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  *
12  * The Original Code is the Sablotron XSLT Processor.
13  *
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  *
18  * Contributor(s):
19  *
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable
23  * instead of those above.  If you wish to allow use of your
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32 
33 #ifndef SXPathHIncl
34 #define SXPathHIncl
35 
36 /* basic types needed in sablot.h */
37 typedef void *SXP_Node;
38 typedef void *SXP_Document;
39 typedef void *SXP_NodeList;
40 typedef SXP_Node NodeHandle;
41 
42 #include "sablot.h"
43 
44 typedef enum
45 {
46     ELEMENT_NODE = 1,
47     ATTRIBUTE_NODE = 2,
48     TEXT_NODE = 3,
49     PROCESSING_INSTRUCTION_NODE = 7,
50     COMMENT_NODE = 8,
51     DOCUMENT_NODE = 9,
52     NAMESPACE_NODE = 13
53 } SXP_NodeType;
54 
55 typedef enum
56 {
57     SXP_NONE,
58     SXP_NUMBER,
59     SXP_STRING,
60     SXP_BOOLEAN,
61     SXP_NODESET
62 } SXP_ExpressionType;
63 
64 typedef char SXP_char;
65 
66 typedef void *QueryContext;
67 
68 /*option constants */
69 typedef enum
70 {
71   SXPF_DISPOSE_NAMES = 0x1,
72   SXPF_DISPOSE_VALUES = 0x2,
73   SXPF_SUPPORTS_UNPARSED_ENTITIES =0x4
74 } SXPFlags;
75 
76 /*
77  *    DOM handler functions
78  *    This handler is registered with the Situation rather than the Processor
79  */
80 
81 /*****************************************************************
82 DOMHandler
83 
84   Handler providing information about a DOM tree to the XPath
85   processor
86 *****************************************************************/
87 
88 typedef SXP_NodeType     DOMH_getNodeType(SXP_Node n);
89 typedef SXP_NodeType     DOMH_getNodeTypeExt(SXP_Node n, void *userData);
90 
91 typedef const SXP_char*  DOMH_getNodeName(SXP_Node n);
92 typedef const SXP_char*  DOMH_getNodeNameExt(SXP_Node n, void *userData);
93 
94 typedef const SXP_char*  DOMH_getNodeNameURI(SXP_Node n);
95 typedef const SXP_char*  DOMH_getNodeNameURIExt(SXP_Node n, void *userData);
96 
97 typedef const SXP_char*  DOMH_getNodeNameLocal(SXP_Node n);
98 typedef const SXP_char*  DOMH_getNodeNameLocalExt(SXP_Node n, void *userData);
99 
100 typedef const SXP_char*  DOMH_getNodeValue(SXP_Node n);
101 typedef const SXP_char*  DOMH_getNodeValueExt(SXP_Node n, void *userData);
102 
103 typedef SXP_Node         DOMH_getNextSibling(SXP_Node n);
104 typedef SXP_Node         DOMH_getNextSiblingExt(SXP_Node n, void *userData);
105 
106 typedef SXP_Node         DOMH_getPreviousSibling(SXP_Node n);
107 typedef SXP_Node         DOMH_getPreviousSiblingExt(SXP_Node n, void *userData);
108 
109 typedef SXP_Node         DOMH_getNextAttrNS(SXP_Node n);
110 typedef SXP_Node         DOMH_getNextAttrNSExt(SXP_Node n, void *userData);
111 
112 typedef SXP_Node         DOMH_getPreviousAttrNS(SXP_Node n);
113 typedef SXP_Node         DOMH_getPreviousAttrNSExt(SXP_Node n, void *userData);
114 
115 typedef int              DOMH_getChildCount(SXP_Node n);
116 typedef int              DOMH_getChildCountExt(SXP_Node n, void *userData);
117 
118 typedef int              DOMH_getAttributeCount(SXP_Node n);
119 typedef int              DOMH_getAttributeCountExt(SXP_Node n, void *userData);
120 
121 typedef int              DOMH_getNamespaceCount(SXP_Node n);
122 typedef int              DOMH_getNamespaceCountExt(SXP_Node n, void *userData);
123 
124 typedef SXP_Node         DOMH_getChildNo(SXP_Node n, int ndx);
125 typedef SXP_Node         DOMH_getChildNoExt(SXP_Node n, int ndx, void *userData);
126 
127 typedef SXP_Node         DOMH_getAttributeNo(SXP_Node n, int ndx);
128 typedef SXP_Node         DOMH_getAttributeNoExt(SXP_Node n, int ndx, void *userData);
129 
130 typedef SXP_Node         DOMH_getNamespaceNo(SXP_Node n, int ndx);
131 typedef SXP_Node         DOMH_getNamespaceNoExt(SXP_Node n, int ndx, void *userData);
132 
133 typedef SXP_Node         DOMH_getParent(SXP_Node n);
134 typedef SXP_Node         DOMH_getParentExt(SXP_Node n, void *userData);
135 
136 typedef SXP_Document     DOMH_getOwnerDocument(SXP_Node n);
137 typedef SXP_Document     DOMH_getOwnerDocumentExt(SXP_Node n, void *userData);
138 
139 typedef int              DOMH_compareNodes(SXP_Node n1, SXP_Node n2);
140 typedef int              DOMH_compareNodesExt(SXP_Node n1, SXP_Node n2, void *userData);
141 
142 typedef SXP_Document     DOMH_retrieveDocument(const SXP_char* uri,
143 					       void* udata);
144 typedef SXP_Document     DOMH_retrieveDocumentExt(const SXP_char* uri,
145 						 const SXP_char* baseUri,
146 					         void* udata);
147 
148 typedef SXP_Node         DOMH_getNodeWithID(SXP_Document doc, const SXP_char* id);
149 typedef SXP_Node         DOMH_getNodeWithIDExt(SXP_Document doc, const SXP_char* id, void *userData);
150 
151 typedef void             DOMH_freeBuffer(SXP_char *buff);
152 typedef void             DOMH_freeBufferExt(SXP_Node n, SXP_char *buff, void *userData);
153 
154 
155 typedef struct
156 {
157     DOMH_getNodeType         *getNodeType;
158     DOMH_getNodeName         *getNodeName;
159     DOMH_getNodeNameURI      *getNodeNameURI;
160     DOMH_getNodeNameLocal    *getNodeNameLocal;
161     DOMH_getNodeValue        *getNodeValue;
162     DOMH_getNextSibling      *getNextSibling;
163     DOMH_getPreviousSibling  *getPreviousSibling;
164     DOMH_getNextAttrNS       *getNextAttrNS;
165     DOMH_getPreviousAttrNS   *getPreviousAttrNS;
166     DOMH_getChildCount       *getChildCount;
167     DOMH_getAttributeCount   *getAttributeCount;
168     DOMH_getNamespaceCount   *getNamespaceCount;
169     DOMH_getChildNo          *getChildNo;
170     DOMH_getAttributeNo      *getAttributeNo;
171     DOMH_getNamespaceNo      *getNamespaceNo;
172     DOMH_getParent           *getParent;
173     DOMH_getOwnerDocument    *getOwnerDocument;
174     DOMH_compareNodes        *compareNodes;
175     DOMH_retrieveDocument    *retrieveDocument;
176     DOMH_getNodeWithID       *getNodeWithID;
177   /*optional entries - driven by sxpOptions */
178     DOMH_freeBuffer          *freeBuffer;
179 
180     DOMH_getNodeTypeExt         *getNodeTypeExt;
181     DOMH_getNodeNameExt         *getNodeNameExt;
182     DOMH_getNodeNameURIExt      *getNodeNameURIExt;
183     DOMH_getNodeNameLocalExt    *getNodeNameLocalExt;
184     DOMH_getNodeValueExt        *getNodeValueExt;
185     DOMH_getNextSiblingExt      *getNextSiblingExt;
186     DOMH_getPreviousSiblingExt  *getPreviousSiblingExt;
187     DOMH_getNextAttrNSExt       *getNextAttrNSExt;
188     DOMH_getPreviousAttrNSExt   *getPreviousAttrNSExt;
189     DOMH_getChildCountExt       *getChildCountExt;
190     DOMH_getAttributeCountExt   *getAttributeCountExt;
191     DOMH_getNamespaceCountExt   *getNamespaceCountExt;
192     DOMH_getChildNoExt          *getChildNoExt;
193     DOMH_getAttributeNoExt      *getAttributeNoExt;
194     DOMH_getNamespaceNoExt      *getNamespaceNoExt;
195     DOMH_getParentExt           *getParentExt;
196     DOMH_getOwnerDocumentExt    *getOwnerDocumentExt;
197     DOMH_compareNodesExt        *compareNodesExt;
198     DOMH_retrieveDocumentExt    *retrieveDocumentExt;
199     DOMH_getNodeWithIDExt       *getNodeWithIDExt;
200   /*optional entries - driven by sxpOptions */
201     DOMH_freeBufferExt          *freeBufferExt;
202 
203 } DOMHandler;
204 
205 Declare
206 (
207     void SXP_registerDOMHandler(SablotSituation S,
208 				DOMHandler *domh, void* udata);
209 )
210 
211 Declare
212 (
213     void SXP_unregisterDOMHandler(SablotSituation S);
214 )
215 
216 /*
217  *
218  *    QueryContext functions
219  *
220  */
221 
222 /*  options setter getter */
223 Declare
224 (
225     void SXP_setOptions(SablotSituation S, unsigned long options);
226 )
227 
228 Declare
229 (
230     void SXP_setMaskBit(SablotSituation S, int mask);
231 )
232 
233 Declare
234 (
235     unsigned long SXP_getOptions(SablotSituation S);
236 )
237 
238 Declare
239 (
240     int SXP_createQueryContext(SablotSituation S, QueryContext *Q);
241 )
242 
243 Declare
244 (
245     int SXP_addVariableBinding(QueryContext Q,
246         const SXP_char* name, QueryContext source);
247 )
248 
249 Declare
250 (
251     int SXP_addVariableNumber(QueryContext Q,
252         const SXP_char* name, double value);
253 )
254 
255 Declare
256 (
257     int SXP_addVariableString(QueryContext Q,
258         const SXP_char* name, const SXP_char* value);
259 )
260 
261 Declare
262 (
263     int SXP_addVariableBoolean(QueryContext Q,
264         const SXP_char* name, int value);
265 )
266 
267 Declare
268 (
269     int SXP_addNamespaceDeclaration(QueryContext Q,
270         const SXP_char* prefix, const SXP_char* uri);
271 )
272 
273 Declare
274 (
275     int SXP_query(QueryContext Q, const SXP_char* query,
276 		  SXP_Node n, int contextPosition, int contextSize);
277 )
278 
279 Declare
280 (
281     int SXP_destroyQueryContext(QueryContext Q);
282 )
283 
284 /*
285  *
286  *    Functions to retrieve the query result and its type
287  *
288  */
289 
290 Declare
291 (
292     int SXP_getResultType(QueryContext Q, SXP_ExpressionType *type);
293 )
294 
295 Declare
296 (
297     int SXP_getResultNumber(QueryContext Q, double *result);
298 )
299 
300 Declare
301 (
302     int SXP_getResultBool(QueryContext Q, int *result);
303 )
304 
305 Declare
306 (
307     int SXP_getResultString(QueryContext Q, const char **result);
308 )
309 
310 Declare
311 (
312     int SXP_getResultNodeset(QueryContext Q, SXP_NodeList *result);
313 )
314 
315 /*
316  *
317  *    NodeList manipulation
318  *
319  */
320 
321 Declare
322 (
323     int SXP_getNodeListLength(SXP_NodeList l);
324 )
325 
326 Declare
327 (
328     SXP_Node SXP_getNodeListItem(QueryContext Q, SXP_NodeList l, int index);
329 )
330 
331 
332 #endif /* SXPathHIncl */
333