/** * xmlSecNodeSetAddList: * @nset: the pointer to currrent nodes set (or NULL). * @newNSet: the pointer to new nodes set. * @op: the operation type. * * Adds @newNSet to the @nset as child using operation @op. * * Returns the pointer to combined nodes set or NULL if an error * occurs. */ EXPORT_C xmlSecNodeSetPtr xmlSecNodeSetAddList(xmlSecNodeSetPtr nset, xmlSecNodeSetPtr newNSet, xmlSecNodeSetOp op) { xmlSecNodeSetPtr tmp1, tmp2; xmlSecAssert2(newNSet != NULL, NULL); tmp1 = xmlSecNodeSetCreate(newNSet->doc, NULL, xmlSecNodeSetList); if(tmp1 == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecNodeSetCreate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(NULL); } tmp1->children = newNSet; tmp2 = xmlSecNodeSetAdd(nset, tmp1, op); if(tmp2 == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecNodeSetAdd", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); xmlSecNodeSetDestroy(tmp1); return(NULL); } return(tmp2); }
static int xmlSecTransformVisa3DHackExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPtr transformCtx) { xmlChar** idPtr; xmlDocPtr doc; xmlAttrPtr attr; xmlNodeSetPtr nodeSet; xmlSecAssert2(xmlSecTransformVisa3DHackCheckId(transform), -1); xmlSecAssert2(transform->outNodes == NULL, -1); xmlSecAssert2(last != 0, -1); xmlSecAssert2(transformCtx != NULL, -1); idPtr = xmlSecVisa3DHackTransformGetIDPtr(transform); xmlSecAssert2(idPtr != NULL, -1); xmlSecAssert2((*idPtr) != NULL, -1); doc = (transform->inNodes != NULL) ? transform->inNodes->doc : transform->hereNode->doc; xmlSecAssert2(doc != NULL, -1); attr = xmlGetID(doc, (*idPtr)); if((attr == NULL) || (attr->parent == NULL)) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), "xmlGetID", XMLSEC_ERRORS_R_XML_FAILED, "id=\"%s\"", xmlSecErrorsSafeString((*idPtr))); return(-1); } nodeSet = xmlXPathNodeSetCreate(attr->parent); if(nodeSet == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), "xmlXPathNodeSetCreate", XMLSEC_ERRORS_R_XML_FAILED, "id=\"%s\"", xmlSecErrorsSafeString((*idPtr))); return(-1); } transform->outNodes = xmlSecNodeSetCreate(doc, nodeSet, xmlSecNodeSetTreeWithoutComments); if(transform->outNodes == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), "xmlSecNodeSetCreate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); xmlXPathFreeNodeSet(nodeSet); return(-1); } return(0); }
/** * xmlSecNodeSetGetChildren: * @doc: the pointer to an XML document. * @parent: the pointer to parent XML node or NULL if we want to include all document nodes. * @withComments: the flag include comments or not. * @invert: the "invert" flag. * * Creates a new nodes set that contains: * - if @withComments is not 0 and @invert is 0: * all nodes in the @parent subtree; * - if @withComments is 0 and @invert is 0: * all nodes in the @parent subtree except comment nodes; * - if @withComments is not 0 and @invert not is 0: * all nodes in the @doc except nodes in the @parent subtree; * - if @withComments is 0 and @invert is 0: * all nodes in the @doc except nodes in the @parent subtree * and comment nodes. * * Returns pointer to the newly created #xmlSecNodeSet structure * or NULL if an error occurs. */ EXPORT_C xmlSecNodeSetPtr xmlSecNodeSetGetChildren(xmlDocPtr doc, const xmlNodePtr parent, int withComments, int invert) { xmlNodeSetPtr nodes; xmlSecNodeSetType type; xmlSecNodeSetPtr result = NULL; xmlSecAssert2(doc != NULL, NULL); nodes = xmlXPathNodeSetCreate(parent); if(nodes == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlXPathNodeSetCreate", XMLSEC_ERRORS_R_XML_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(NULL); } /* if parent is NULL then we add all the doc children */ if(parent == NULL) { xmlNodePtr cur; for(cur = doc->children; cur != NULL; cur = cur->next) { if(withComments || (cur->type != XML_COMMENT_NODE)) { xmlXPathNodeSetAdd(nodes, cur); } } } if(withComments && invert) { type = xmlSecNodeSetTreeInvert; } else if(withComments && !invert) { type = xmlSecNodeSetTree; } else if(!withComments && invert) { type = xmlSecNodeSetTreeWithoutCommentsInvert; } else { /* if(!withComments && !invert) */ type = xmlSecNodeSetTreeWithoutComments; } result = xmlSecNodeSetCreate(doc, nodes, type); if ( !result ) { xmlXPathFreeNodeSet( nodes ); } return result; }
PyObject *xmlsec_NodeSetCreate(PyObject *self, PyObject *args) { PyObject *doc_obj, *nodes_obj; xmlDocPtr doc; xmlNodeSetPtr nodes; xmlSecNodeSetType type; if (CheckArgs(args, "OOI:nodeSetCreate")) { if (!PyArg_ParseTuple(args, "OOi:nodeSetCreate", &doc_obj, &nodes_obj, &type)) return NULL; } else return NULL; doc = xmlDocPtr_get(doc_obj); nodes = xmlNodeSetPtr_get(nodes_obj); return (wrap_xmlSecNodeSetPtr(xmlSecNodeSetCreate(doc, nodes, type))); }
static xmlSecNodeSetPtr xmlSecXPathDataExecute(xmlSecXPathDataPtr data, xmlDocPtr doc, xmlNodePtr hereNode) { xmlXPathObjectPtr xpathObj = NULL; xmlSecNodeSetPtr nodes; xmlSecAssert2(data != NULL, NULL); xmlSecAssert2(data->expr != NULL, NULL); xmlSecAssert2(data->ctx != NULL, NULL); xmlSecAssert2(doc != NULL, NULL); xmlSecAssert2(hereNode != NULL, NULL); /* do not forget to set the doc */ data->ctx->doc = doc; /* here function works only on the same document */ if(hereNode->doc == doc) { xmlXPathRegisterFunc(data->ctx, (xmlChar *)"here", xmlSecXPathHereFunction); data->ctx->here = hereNode; data->ctx->xptr = 1; } /* execute xpath or xpointer expression */ switch(data->type) { case xmlSecXPathDataTypeXPath: case xmlSecXPathDataTypeXPath2: xpathObj = xmlXPathEvalExpression(data->expr, data->ctx); if(xpathObj == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlXPathEvalExpression", XMLSEC_ERRORS_R_XML_FAILED, "expr=%s", xmlSecErrorsSafeString(data->expr)); return(NULL); } break; case xmlSecXPathDataTypeXPointer: xpathObj = xmlXPtrEval(data->expr, data->ctx); if(xpathObj == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlXPtrEval", XMLSEC_ERRORS_R_XML_FAILED, "expr=%s", xmlSecErrorsSafeString(data->expr)); return(NULL); } break; } /* sometime LibXML2 returns an empty nodeset or just NULL, we want to reserve NULL for our own purposes so we simply create an empty node set here */ if(xpathObj->nodesetval == NULL) { xpathObj->nodesetval = xmlXPathNodeSetCreate(NULL); if(xpathObj->nodesetval == NULL) { xmlXPathFreeObject(xpathObj); xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlXPathNodeSetCreate", XMLSEC_ERRORS_R_XML_FAILED, "expr=%s", xmlSecErrorsSafeString(data->expr)); return(NULL); } } nodes = xmlSecNodeSetCreate(doc, xpathObj->nodesetval, data->nodeSetType); if(nodes == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecNodeSetCreate", XMLSEC_ERRORS_R_XMLSEC_FAILED, "type=%d", data->nodeSetType); xmlXPathFreeObject(xpathObj); return(NULL); } xpathObj->nodesetval = NULL; xmlXPathFreeObject(xpathObj); return(nodes); }