|
1 /** |
|
2 * XML Security Library (http://www.aleksey.com/xmlsec). |
|
3 * |
|
4 * Common XML utility functions |
|
5 * |
|
6 * This is free software; see Copyright file in the source |
|
7 * distribution for preciese wording. |
|
8 * |
|
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> |
|
10 * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
11 */ |
|
12 #ifndef __XMLSEC_TREE_H__ |
|
13 #define __XMLSEC_TREE_H__ |
|
14 |
|
15 #ifdef __cplusplus |
|
16 extern "C" { |
|
17 #endif /* __cplusplus */ |
|
18 #include "xmlsec_config.h" |
|
19 #include <libxml2_tree.h> |
|
20 #include <libxml2_xpath.h> |
|
21 #include "xmlsec_xmlsec.h" |
|
22 |
|
23 /** |
|
24 * xmlSecNodeGetName: |
|
25 * @node: the pointer to node. |
|
26 * |
|
27 * Macro. Returns node's name. |
|
28 */ |
|
29 #define xmlSecNodeGetName(node) \ |
|
30 (((node)) ? ((const char*)((node)->name)) : NULL) |
|
31 |
|
32 XMLSEC_EXPORT const xmlChar* xmlSecGetNodeNsHref (const xmlNodePtr cur); |
|
33 XMLSEC_EXPORT int xmlSecCheckNodeName (const xmlNodePtr cur, |
|
34 const xmlChar *name, |
|
35 const xmlChar *ns); |
|
36 XMLSEC_EXPORT xmlNodePtr xmlSecGetNextElementNode(xmlNodePtr cur); |
|
37 XMLSEC_EXPORT xmlNodePtr xmlSecFindChild (const xmlNodePtr parent, |
|
38 const xmlChar *name, |
|
39 const xmlChar *ns); |
|
40 XMLSEC_EXPORT xmlNodePtr xmlSecFindParent (const xmlNodePtr cur, |
|
41 const xmlChar *name, |
|
42 const xmlChar *ns); |
|
43 XMLSEC_EXPORT xmlNodePtr xmlSecFindNode (const xmlNodePtr parent, |
|
44 const xmlChar *name, |
|
45 const xmlChar *ns); |
|
46 XMLSEC_EXPORT xmlNodePtr xmlSecAddChild (xmlNodePtr parent, |
|
47 const xmlChar *name, |
|
48 const xmlChar *ns); |
|
49 XMLSEC_EXPORT xmlNodePtr xmlSecAddChildNode (xmlNodePtr parent, |
|
50 xmlNodePtr child); |
|
51 XMLSEC_EXPORT xmlNodePtr xmlSecAddNextSibling (xmlNodePtr node, |
|
52 const xmlChar *name, |
|
53 const xmlChar *ns); |
|
54 XMLSEC_EXPORT xmlNodePtr xmlSecAddPrevSibling (xmlNodePtr node, |
|
55 const xmlChar *name, |
|
56 const xmlChar *ns); |
|
57 |
|
58 XMLSEC_EXPORT int xmlSecReplaceNode (xmlNodePtr node, |
|
59 xmlNodePtr newNode); |
|
60 XMLSEC_EXPORT int xmlSecReplaceContent (xmlNodePtr node, |
|
61 xmlNodePtr newNode); |
|
62 XMLSEC_EXPORT int xmlSecReplaceNodeBuffer (xmlNodePtr node, |
|
63 const xmlSecByte *buffer, |
|
64 xmlSecSize size); |
|
65 |
|
66 XMLSEC_EXPORT void xmlSecAddIDs (xmlDocPtr doc, |
|
67 xmlNodePtr cur, |
|
68 const xmlChar** ids); |
|
69 XMLSEC_EXPORT int xmlSecGenerateAndAddID (xmlNodePtr node, |
|
70 const xmlChar* attrName, |
|
71 const xmlChar* prefix, |
|
72 xmlSecSize len); |
|
73 XMLSEC_EXPORT xmlChar* xmlSecGenerateID (const xmlChar* prefix, |
|
74 xmlSecSize len); |
|
75 |
|
76 XMLSEC_EXPORT xmlDocPtr xmlSecCreateTree (const xmlChar* rootNodeName, |
|
77 const xmlChar* rootNodeNs); |
|
78 XMLSEC_EXPORT int xmlSecIsEmptyNode (xmlNodePtr node); |
|
79 XMLSEC_EXPORT int xmlSecIsEmptyString (const xmlChar* str); |
|
80 XMLSEC_EXPORT xmlChar* xmlSecGetQName (xmlNodePtr node, |
|
81 const xmlChar* href, |
|
82 const xmlChar* local); |
|
83 |
|
84 /** |
|
85 * xmlSecIsHex: |
|
86 * @c: the character. |
|
87 * |
|
88 * Macro. Returns 1 if @c is a hex digit or 0 other wise. |
|
89 */ |
|
90 #define xmlSecIsHex(c) \ |
|
91 (( (('0' <= (c)) && ((c) <= '9')) || \ |
|
92 (('a' <= (c)) && ((c) <= 'f')) || \ |
|
93 (('A' <= (c)) && ((c) <= 'F')) ) ? 1 : 0) |
|
94 |
|
95 /** |
|
96 * xmlSecGetHex: |
|
97 * @c: the character, |
|
98 * |
|
99 * Macro. Returns the hex value of the @c. |
|
100 */ |
|
101 #define xmlSecGetHex(c) \ |
|
102 ( (('0' <= (c)) && ((c) <= '9')) ? (c) - '0' : \ |
|
103 ( (('a' <= (c)) && ((c) <= 'f')) ? (c) - 'a' + 10 : \ |
|
104 ( (('A' <= (c)) && ((c) <= 'F')) ? (c) - 'A' + 10 : 0 ))) |
|
105 |
|
106 /************************************************************************* |
|
107 * |
|
108 * QName <-> Integer mapping |
|
109 * |
|
110 ************************************************************************/ |
|
111 typedef struct _xmlSecQName2IntegerInfo xmlSecQName2IntegerInfo, |
|
112 *xmlSecQName2IntegerInfoPtr; |
|
113 typedef const struct _xmlSecQName2IntegerInfo* xmlSecQName2IntegerInfoConstPtr; |
|
114 |
|
115 struct _xmlSecQName2IntegerInfo { |
|
116 const xmlChar* qnameHref; |
|
117 const xmlChar* qnameLocalPart; |
|
118 int intValue; |
|
119 }; |
|
120 XMLSEC_EXPORT xmlSecQName2IntegerInfoConstPtr xmlSecQName2IntegerGetInfo |
|
121 (xmlSecQName2IntegerInfoConstPtr info, |
|
122 int intValue); |
|
123 XMLSEC_EXPORT int xmlSecQName2IntegerGetInteger (xmlSecQName2IntegerInfoConstPtr info, |
|
124 const xmlChar* qnameHref, |
|
125 const xmlChar* qnameLocalPart, |
|
126 int* intValue); |
|
127 XMLSEC_EXPORT int xmlSecQName2IntegerGetIntegerFromString |
|
128 (xmlSecQName2IntegerInfoConstPtr info, |
|
129 xmlNodePtr node, |
|
130 const xmlChar* qname, |
|
131 int* intValue); |
|
132 XMLSEC_EXPORT xmlChar* xmlSecQName2IntegerGetStringFromInteger |
|
133 (xmlSecQName2IntegerInfoConstPtr info, |
|
134 xmlNodePtr node, |
|
135 int intValue); |
|
136 XMLSEC_EXPORT int xmlSecQName2IntegerNodeRead (xmlSecQName2IntegerInfoConstPtr info, |
|
137 xmlNodePtr node, |
|
138 int* intValue); |
|
139 XMLSEC_EXPORT int xmlSecQName2IntegerNodeWrite (xmlSecQName2IntegerInfoConstPtr info, |
|
140 xmlNodePtr node, |
|
141 const xmlChar* nodeName, |
|
142 const xmlChar* nodeNs, |
|
143 int intValue); |
|
144 XMLSEC_EXPORT int xmlSecQName2IntegerAttributeRead(xmlSecQName2IntegerInfoConstPtr info, |
|
145 xmlNodePtr node, |
|
146 const xmlChar* attrName, |
|
147 int* intValue); |
|
148 XMLSEC_EXPORT int xmlSecQName2IntegerAttributeWrite(xmlSecQName2IntegerInfoConstPtr info, |
|
149 xmlNodePtr node, |
|
150 const xmlChar* attrName, |
|
151 int intValue); |
|
152 XMLSEC_EXPORT void xmlSecQName2IntegerDebugDump (xmlSecQName2IntegerInfoConstPtr info, |
|
153 int intValue, |
|
154 const xmlChar* name, |
|
155 FILE* output); |
|
156 XMLSEC_EXPORT void xmlSecQName2IntegerDebugXmlDump(xmlSecQName2IntegerInfoConstPtr info, |
|
157 int intValue, |
|
158 const xmlChar* name, |
|
159 FILE* output); |
|
160 |
|
161 /************************************************************************* |
|
162 * |
|
163 * QName <-> Bits mask mapping |
|
164 * |
|
165 ************************************************************************/ |
|
166 typedef unsigned int xmlSecBitMask; |
|
167 typedef struct _xmlSecQName2BitMaskInfo xmlSecQName2BitMaskInfo, |
|
168 *xmlSecQName2BitMaskInfoPtr; |
|
169 typedef const struct _xmlSecQName2BitMaskInfo* xmlSecQName2BitMaskInfoConstPtr; |
|
170 |
|
171 struct _xmlSecQName2BitMaskInfo { |
|
172 const xmlChar* qnameHref; |
|
173 const xmlChar* qnameLocalPart; |
|
174 xmlSecBitMask mask; |
|
175 }; |
|
176 |
|
177 XMLSEC_EXPORT xmlSecQName2BitMaskInfoConstPtr xmlSecQName2BitMaskGetInfo |
|
178 (xmlSecQName2BitMaskInfoConstPtr info, |
|
179 xmlSecBitMask mask); |
|
180 XMLSEC_EXPORT int xmlSecQName2BitMaskGetBitMask (xmlSecQName2BitMaskInfoConstPtr info, |
|
181 const xmlChar* qnameLocalPart, |
|
182 const xmlChar* qnameHref, |
|
183 xmlSecBitMask* mask); |
|
184 XMLSEC_EXPORT int xmlSecQName2BitMaskNodesRead (xmlSecQName2BitMaskInfoConstPtr info, |
|
185 xmlNodePtr* node, |
|
186 const xmlChar* nodeName, |
|
187 const xmlChar* nodeNs, |
|
188 int stopOnUnknown, |
|
189 xmlSecBitMask* mask); |
|
190 XMLSEC_EXPORT int xmlSecQName2BitMaskGetBitMaskFromString |
|
191 (xmlSecQName2BitMaskInfoConstPtr info, |
|
192 xmlNodePtr node, |
|
193 const xmlChar* qname, |
|
194 xmlSecBitMask* mask); |
|
195 XMLSEC_EXPORT xmlChar* xmlSecQName2BitMaskGetStringFromBitMask |
|
196 (xmlSecQName2BitMaskInfoConstPtr info, |
|
197 xmlNodePtr node, |
|
198 xmlSecBitMask mask); |
|
199 XMLSEC_EXPORT int xmlSecQName2BitMaskNodesWrite (xmlSecQName2BitMaskInfoConstPtr info, |
|
200 xmlNodePtr node, |
|
201 const xmlChar* nodeName, |
|
202 const xmlChar* nodeNs, |
|
203 xmlSecBitMask mask); |
|
204 XMLSEC_EXPORT void xmlSecQName2BitMaskDebugDump (xmlSecQName2BitMaskInfoConstPtr info, |
|
205 xmlSecBitMask mask, |
|
206 const xmlChar* name, |
|
207 FILE* output); |
|
208 XMLSEC_EXPORT void xmlSecQName2BitMaskDebugXmlDump(xmlSecQName2BitMaskInfoConstPtr info, |
|
209 xmlSecBitMask mask, |
|
210 const xmlChar* name, |
|
211 FILE* output); |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 #ifdef __cplusplus |
|
217 } |
|
218 #endif /* __cplusplus */ |
|
219 |
|
220 #endif /* __XMLSEC_TREE_H__ */ |
|
221 |