1 /* 2 * XML Security Library (http://www.aleksey.com/xmlsec). 3 * 4 * Enchanced nodes Set 5 * 6 * This is free software; see Copyright file in the source 7 * distribution for preciese wording. 8 * 9 * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. 10 */ 11 #ifndef __XMLSEC_NODESET_H__ 12 #define __XMLSEC_NODESET_H__ 13 14 #include <libxml/tree.h> 15 #include <libxml/xpath.h> 16 17 #include <xmlsec/xmlsec.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif /* __cplusplus */ 22 23 typedef struct _xmlSecNodeSet xmlSecNodeSet, *xmlSecNodeSetPtr; 24 25 /** 26 * xmlSecNodeSetType: 27 * @xmlSecNodeSetNormal: nodes set = nodes in the list. 28 * @xmlSecNodeSetInvert: nodes set = all document nodes minus nodes in the list. 29 * @xmlSecNodeSetTree: nodes set = nodes in the list and all their subtress. 30 * @xmlSecNodeSetTreeWithoutComments: nodes set = nodes in the list and 31 * all their subtress but no comment nodes. 32 * @xmlSecNodeSetTreeInvert: nodes set = all document nodes minus nodes in the 33 * list and all their subtress. 34 * @xmlSecNodeSetTreeWithoutCommentsInvert: nodes set = all document nodes 35 * minus (nodes in the list and all their subtress 36 * plus all comment nodes). 37 * @xmlSecNodeSetList: nodes set = all nodes in the children list of nodes sets. 38 * 39 * The basic nodes sets types. 40 */ 41 typedef enum { 42 xmlSecNodeSetNormal = 0, 43 xmlSecNodeSetInvert, 44 xmlSecNodeSetTree, 45 xmlSecNodeSetTreeWithoutComments, 46 xmlSecNodeSetTreeInvert, 47 xmlSecNodeSetTreeWithoutCommentsInvert, 48 xmlSecNodeSetList 49 } xmlSecNodeSetType; 50 51 /** 52 * xmlSecNodeSetOp: 53 * @xmlSecNodeSetIntersection: intersection. 54 * @xmlSecNodeSetSubtraction: subtraction. 55 * @xmlSecNodeSetUnion: union. 56 * 57 * The simple nodes sets operations. 58 */ 59 typedef enum { 60 xmlSecNodeSetIntersection = 0, 61 xmlSecNodeSetSubtraction, 62 xmlSecNodeSetUnion 63 } xmlSecNodeSetOp; 64 65 /** 66 * xmlSecNodeSet: 67 * @nodes: the nodes list. 68 * @doc: the parent XML document. 69 * @destroyDoc: the flag: if set to 1 then @doc will 70 * be destroyed when node set is destroyed. 71 * @type: the nodes set type. 72 * @op: the operation type. 73 * @next: the next nodes set. 74 * @prev: the previous nodes set. 75 * @children: the children list (valid only if type 76 * equal to #xmlSecNodeSetList). 77 * 78 * The enchanced nodes set. 79 */ 80 struct _xmlSecNodeSet { 81 xmlNodeSetPtr nodes; 82 xmlDocPtr doc; 83 int destroyDoc; 84 xmlSecNodeSetType type; 85 xmlSecNodeSetOp op; 86 xmlSecNodeSetPtr next; 87 xmlSecNodeSetPtr prev; 88 xmlSecNodeSetPtr children; 89 }; 90 91 /** 92 * xmlSecNodeSetWalkCallback: 93 * @nset: the pointer to #xmlSecNodeSet structure. 94 * @cur: the pointer current XML node. 95 * @parent: the pointer to the @cur parent node. 96 * @data: the pointer to application specific data. 97 * 98 * The callback function called once per each node in the nodes set. 99 * 100 * Returns: 0 on success or a negative value if an error occurs 101 * an walk procedure should be interrupted. 102 */ 103 typedef int (*xmlSecNodeSetWalkCallback) (xmlSecNodeSetPtr nset, 104 xmlNodePtr cur, 105 xmlNodePtr parent, 106 void* data); 107 108 XMLSEC_EXPORT xmlSecNodeSetPtr xmlSecNodeSetCreate (xmlDocPtr doc, 109 xmlNodeSetPtr nodes, 110 xmlSecNodeSetType type); 111 XMLSEC_EXPORT void xmlSecNodeSetDestroy (xmlSecNodeSetPtr nset); 112 XMLSEC_EXPORT void xmlSecNodeSetDocDestroy (xmlSecNodeSetPtr nset); 113 XMLSEC_EXPORT int xmlSecNodeSetContains (xmlSecNodeSetPtr nset, 114 xmlNodePtr node, 115 xmlNodePtr parent); 116 XMLSEC_EXPORT xmlSecNodeSetPtr xmlSecNodeSetAdd (xmlSecNodeSetPtr nset, 117 xmlSecNodeSetPtr newNSet, 118 xmlSecNodeSetOp op); 119 XMLSEC_EXPORT xmlSecNodeSetPtr xmlSecNodeSetAddList (xmlSecNodeSetPtr nset, 120 xmlSecNodeSetPtr newNSet, 121 xmlSecNodeSetOp op); 122 XMLSEC_EXPORT xmlSecNodeSetPtr xmlSecNodeSetGetChildren(xmlDocPtr doc, 123 const xmlNodePtr parent, 124 int withComments, 125 int invert); 126 XMLSEC_EXPORT int xmlSecNodeSetWalk (xmlSecNodeSetPtr nset, 127 xmlSecNodeSetWalkCallback walkFunc, 128 void* data); 129 XMLSEC_EXPORT int xmlSecNodeSetDumpTextNodes(xmlSecNodeSetPtr nset, 130 xmlOutputBufferPtr out); 131 XMLSEC_EXPORT void xmlSecNodeSetDebugDump (xmlSecNodeSetPtr nset, 132 FILE *output); 133 134 #ifdef __cplusplus 135 } 136 #endif /* __cplusplus */ 137 138 #endif /* __XMLSEC_NODESET_H__ */ 139 140