/* * get_op_id_from_doc -- * extracts an operation id through the given context ptr. * * ctext: context ptr for the original doc * * Returns an operation id if found or -1 otherwise. */ static int get_op_id_from_doc(xmlXPathContextPtr ctext) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; int i; for (i = 0; op_table[i].op_str != NULL; i++) { (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", op_table[i].op_str); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { isnslog(LOG_DEBUG, "get_op_id_from_doc ", "xpath obj->nodesetval->nodeNr: %d", xpath_obj->nodesetval->nodeNr); isnslog(LOG_DEBUG, "get_op_id_from_doc", "operation: %s id: %d", op_table[i].op_str, op_table[i].op_id); if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (op_table[i].op_id); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (-1); }
/* !DO NOT ALTER FUNCTION SIGNATURE! */ int callback_ofc_capable_switch_xdpd_mgmt_cross_connections_xdpd_mgmt_cross_connection (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error) { nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op); print_element_names(node, 0); uint64_t dpid_1 = 0; uint64_t dpid_2 = 0; uint64_t port_no1 = 0; uint64_t port_no2 = 0; if (XMLDIFF_ADD & op) { int i=0; xmlNodePtr lsi; for (lsi = node->children->next; NULL != lsi; lsi = lsi->next, ++i) { assert(xmlStrEqual(lsi->name, BAD_CAST "switch")); // resolve dpid char buf[255]; xmlStrPrintf(buf, sizeof(buf), "/ofc:capable-switch/ofc:logical-switches/ofc:switch[ofc:id='%s']", XML_GET_CONTENT(lsi->children->children)); xmlXPathObjectPtr xpath_obj_ptr = get_node(lsi->doc, namespace_mapping, buf); assert(xpath_obj_ptr); assert(xpath_obj_ptr->nodesetval); // there can only be one lsi with this id if (1 == xpath_obj_ptr->nodesetval->nodeNr) { xmlNodePtr dpid_node = find_element(BAD_CAST "datapath-id", xpath_obj_ptr->nodesetval->nodeTab[0]->children); assert(dpid_node); if (0 == i) { dpid_1 = parse_dpid(XML_GET_CONTENT(dpid_node->children)); } else { dpid_2 = parse_dpid(XML_GET_CONTENT(dpid_node->children)); } } else { // otherwise something is really screwed assert(0); } xmlXPathFreeObject(xpath_obj_ptr); xmlNodePtr requested_portnum = find_element(BAD_CAST "requested-of-port-number", lsi->children); if (NULL != requested_portnum) { if (0 == i) { port_no1 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10); } else { port_no2 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10); } } } nc_verb_verbose("dpid_1 = %lx, dpid_2 = %lx\n", dpid_1, dpid_2); lsi_cross_connect(ofc_state.xmp_client_handle, dpid_1, port_no1, dpid_2, port_no2); } return EXIT_SUCCESS; }
herror_t soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out) { xmlDocPtr env; xmlChar buffer[1054]; log_verbose2("URN = '%s'", urn); log_verbose2("Method = '%s'", method); if (!strcmp(urn, "")) { #ifdef USE_XMLSTRING xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_EMPTY_TARGET_, soap_env_ns, soap_env_enc, soap_xsi_ns, soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method); #else sprintf((char *)buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_, soap_env_ns, soap_env_enc, soap_xsi_ns, soap_xsd_ns, method, urn, method); #endif } else { #ifdef USE_XMLSTRING xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_, soap_env_ns, soap_env_enc, soap_xsi_ns, soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method); #else sprintf((char *)buffer, _SOAP_MSG_TEMPLATE_, soap_env_ns, soap_env_enc, soap_xsi_ns, soap_xsd_ns, method, urn, method); #endif } if (!(env = xmlParseDoc(buffer))) return herror_new("soap_env_new_with_method", XML_ERROR_PARSE, "Can not parse xml"); return soap_env_new_from_doc(env, out); }
/* * process_enumerate_request_from_doc -- * looks for the object through the context ptr and sets the * request with object type. * * ctext: context ptr for the original doc to parse request info. * req: request to be filled up. * * Returns 0 if successful or an error code otherwise. */ static int process_enumerate_request_from_doc(xmlXPathContextPtr ctext, request_t *req) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; int i; int obj = 0; isnslog(LOG_DEBUG, "process_enumerate_request_from_doc", "entered"); (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSOBJECTTYPE); xpath_obj = xmlXPathEvalExpression(expr, ctext); isnslog(LOG_DEBUG, "process_enumerate_request_from_doc", "xpath obj->nodesetval->nodeNR: %d", xpath_obj->nodesetval->nodeNr); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { for (i = 0; obj_table[i].obj_str != NULL; i++) { if (xmlStrncmp( xpath_obj->nodesetval->nodeTab[0]->children->content, (xmlChar *)obj_table[i].obj_str, xmlStrlen((xmlChar *) xpath_obj->nodesetval->nodeTab[0]->children->content)) == 0) { obj = obj_table[i].obj_id; break; } } } else { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_VALID_OBJECT_NOT_FOUND); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); if (obj == 0) { return (ERR_XML_VALID_OBJECT_NOT_FOUND); } req->op_info.obj = obj; if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) { ISNS_MGMT_OBJECT_TYPE(obj); } return (0); }
/** @brief Add an integer property to a XML node. * * If a property with this name already exists it is overwritten. * * @param cur Pointer to the XML node. * @param prop Name of the property. * @param value Value of the property. */ static void parser_newprop_int(xmlNodePtr cur, const xmlChar *prop, int value) { xmlChar *temp; temp=xmlGetProp(cur, prop); if(temp!=NULL) { xmlUnsetProp(cur, prop); } xmlFree(temp); temp=malloc(sizeof(*temp)*LINEBUFFSIZE); if(temp==NULL) fatal(_("Can't allocate memory")); xmlStrPrintf(temp, LINEBUFFSIZE, XMLCHAR "%d", value); xmlNewProp(cur, prop, temp); free(temp); }
static int consumeKeySetNode(KeySet *ks, const char *context, xmlTextReaderPtr reader) { xmlChar *nodeName=0; xmlChar *keySetNodeName=0; xmlChar *privateContext=0; xmlChar fullContext[800]=""; keySetNodeName=xmlTextReaderName(reader); if (!strcmp((char *)keySetNodeName,"keyset")) { int end=0; privateContext=xmlTextReaderGetAttribute(reader,(const xmlChar *)"parent"); if (context && privateContext) { xmlStrPrintf(fullContext,sizeof(fullContext), (const xmlChar *)"%s/%s", context, privateContext); } /* Parse everything else */ while (!end) { xmlTextReaderRead(reader); nodeName=xmlTextReaderName(reader); if (!strcmp((char *)nodeName,"key")) { if (privateContext) consumeKeyNode(ks,(char *)(*fullContext?fullContext:privateContext),reader); else consumeKeyNode(ks,context,reader); } else if (!strcmp((char *)nodeName,"keyset")) { /* A <keyset> can have nested <keyset>s */ if (xmlTextReaderNodeType(reader)==15) /* found a </keyset> */ end=1; else if (privateContext) consumeKeySetNode(ks, (char *)(*fullContext?fullContext:privateContext), reader); else consumeKeySetNode(ks, context, reader); } xmlFree(nodeName); } if (privateContext) xmlFree(privateContext),privateContext=0; } xmlFree (keySetNodeName); return 0; }
static void create_hex_node(u32 data, char * name, xmlNodePtr parent) { xmlChar buf[buf_len]; xmlStrPrintf(buf, buf_len, BAD_CAST "%x", data); xmlNewChild(parent, NULL, BAD_CAST name, buf); }
/* !DO NOT ALTER FUNCTION SIGNATURE! */ int callback_ofc_capable_switch_ofc_logical_switches_ofc_switch_ofc_resources_ofc_port (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error) { nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op); print_element_names(node, 0); // retrieve the dpid of this twig xmlNodePtr tmp = find_element(BAD_CAST "datapath-id", node->parent->parent->children); assert(tmp); uint64_t dpid = parse_dpid(tmp->children->content); int rv = EXIT_SUCCESS; // fixme depending on the erropt (e.g. NC_EDIT_ERROPT_ROLLBACK we might still have *data set) assert(data); if (NULL == *data) { *data = calloc(1, sizeof(struct lsi)); assert(*data); } if (XMLDIFF_ADD & op) { xmlChar buf[255]; // check if port is already attached xmlStrPrintf(buf, sizeof(buf), "/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:resources/ofc:port[text()='%s']", XML_GET_CONTENT(node->children)); xmlXPathObjectPtr xpath_obj_ptr = get_node(node->doc, namespace_mapping, buf); assert(xpath_obj_ptr); assert(xpath_obj_ptr->nodesetval); if (1 == xpath_obj_ptr->nodesetval->nodeNr) { if (NULL == LSI(data)->res.port_list_add) { LSI(data)->res.port_list_add = list_new(); assert(((struct lsi* )*data)->res.port_list_add); } struct port *p = calloc(1, sizeof(struct port)); p->resource_id = xmlNodeListGetString(node->doc, node->children, 1); p->op = ADD; p->dpid = dpid; list_append_data(LSI(data)->res.port_list_add, p); nc_verb_verbose("added to list: dpid=%lx port %s with op=%u\n", p->dpid, p->resource_id, p->op); } else { // nodeNr > 1 ==> already attached port nc_verb_verbose("attachment failed dpid=%lx port %s: port already attached.\n", dpid, XML_GET_CONTENT(node->children)); rv = EXIT_FAILURE; } xmlXPathFreeObject(xpath_obj_ptr); } else if (XMLDIFF_REM & op) { if (NULL == LSI(data)->res.port_list_del) { LSI(data)->res.port_list_del = list_new(); assert(((struct lsi* ) *data)->res.port_list_del); } struct port *p = calloc(1, sizeof(struct port)); p->resource_id = xmlNodeListGetString(node->doc, node->children, 1); p->op = DELETE; p->dpid = dpid; list_append_data(LSI(data)->res.port_list_del, p); nc_verb_verbose("added to list: dpid=%lx port %s with op=%u\n", p->dpid, p->resource_id, p->op); } else { // todo implement nc_verb_error("not implemented"); assert(0); } return rv; }
/* * build_mgmt_response -- sets an XML doc with a root and calls a porper * routine based on the request. If the called routine constructed * the response doc with the result element, this routine fills up * response buffer with raw XML doc. * * reponse: ptr to response buffer * req: request to be processed. * size: ptr to the response doc buffer */ static int build_mgmt_response(xmlChar **response, request_t req, int *size) { int ret; xmlDocPtr doc; xmlNodePtr root; xmlXPathContextPtr ctext = NULL; xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; isnslog(LOG_DEBUG, "build_mgmt_response", "entered"); doc = xmlNewDoc((uchar_t *)"1.0"); root = xmlNewNode(NULL, (xmlChar *)ISNSRESPONSE); (void) xmlDocSetRootElement(doc, root); if (xmlSetProp(root, (xmlChar *)XMLNSATTR, (xmlChar *)XMLNSATTRVAL) == NULL) { return (ERR_XML_SETPROP_FAILED); } switch (req.op_info.op) { case get_op: switch (req.op_info.obj) { case Node: ret = get_node_op(&req, doc); break; case DiscoveryDomain: ret = get_dd_op(&req, doc); break; case DiscoveryDomainSet: ret = get_ddset_op(&req, doc); break; case ServerConfig: ret = get_serverconfig_op(doc); break; default: ret = ERR_INVALID_MGMT_REQUEST; } break; case enumerate_op: isnslog(LOG_DEBUG, "build_mgmt_response", "enumerate_op"); switch (req.op_info.obj) { case Node: ret = enumerate_node_op(doc); break; case DiscoveryDomain: ret = enumerate_dd_op(doc); break; case DiscoveryDomainSet: ret = enumerate_ddset_op(doc); break; default: ret = ERR_INVALID_MGMT_REQUEST; } break; case getAssociated_op: switch (req.op_info.obj) { case DiscoveryDomainMember: if (req.assoc_req == container_to_member) { ret = getAssociated_dd_to_node_op(&req, doc); } else { ret = getAssociated_node_to_dd_op(&req, doc); } break; case DiscoveryDomainSetMember: if (req.assoc_req == container_to_member) { ret = getAssociated_ddset_to_dd_op(&req, doc); } else { ret = getAssociated_dd_to_ddset_op(&req, doc); } break; default: ret = ERR_INVALID_MGMT_REQUEST; } break; case createModify_op: switch (req.op_info.obj) { case DiscoveryDomain: case DiscoveryDomainSet: ret = createModify_dd_ddset_op(&req, doc); break; case DiscoveryDomainMember: case DiscoveryDomainSetMember: ret = create_ddmember_ddsetmember_op(&req, doc, req.op_info.obj); break; default: ret = ERR_INVALID_MGMT_REQUEST; } break; case delete_op: switch (req.op_info.obj) { case DiscoveryDomainMember: case DiscoveryDomainSetMember: ret = delete_ddmember_ddsetmember_op(&req, doc, req.op_info.obj); break; case DiscoveryDomain: case DiscoveryDomainSet: ret = delete_dd_ddset_op(&req, doc, req.op_info.obj); break; default: ret = ERR_INVALID_MGMT_REQUEST; } break; default: ret = ERR_INVALID_MGMT_REQUEST; } /* * if failed check to see the doc contains the result element. * if not, the response is set with only an error code. */ if (ret != ISNS_RSP_SUCCESSFUL) { ctext = xmlXPathNewContext(doc); if (ctext != NULL) { (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", RESULT); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj == NULL) || (xpath_obj->nodesetval == NULL) || (xpath_obj->nodesetval->nodeNr <= 0) || (xpath_obj->nodesetval->nodeTab == NULL)) { isnslog(LOG_DEBUG, "build_mgmt_response", "returning repsonse only with error code %d\n", ret); *response = malloc(sizeof (ret)); if (*response) **response = ret; *size = sizeof (ret); } else { xmlDocDumpMemory(doc, response, size); } } else { /* can't verify the xml doc. dump return the doc anyway. */ xmlDocDumpMemory(doc, response, size); } } else { xmlDocDumpMemory(doc, response, size); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); if (ctext) xmlXPathFreeContext(ctext); if (doc) xmlFreeDoc(doc); return (ret); }
/* * process_createModify_request_from_doc -- * first looks for the object through the context ptr and sets the * request with additional data. * For DD and DD set, the name is given. * For DD and DD set membership, container and member pairs are given. * * ctext: context ptr for the original doc to parse request info. * req: request to be filled up. * * Returns 0 if successful or an error code otherwise. */ static int process_createModify_request_from_doc(xmlXPathContextPtr ctext, request_t *req) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; xmlNodeSetPtr r_nodes = NULL; xmlAttrPtr attr = NULL; xmlChar *container = NULL, *member = NULL, *xml_id; int i, cnt; int obj = 0; isnslog(LOG_DEBUG, "process_createModify_request_from_doc", "entered"); for (i = 0; obj_table[i].obj_str != NULL; i++) { (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", obj_table[i].obj_str); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { obj = obj_table[i].obj_id; break; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); } if (obj == 0) { return (ERR_XML_VALID_OBJECT_NOT_FOUND); } req->op_info.obj = obj; if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) { ISNS_MGMT_OBJECT_TYPE(obj); } switch (obj) { case DiscoveryDomainMember: /* at least one object exists to get here. */ r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.pair = (assoc_pair_t **)malloc(sizeof (assoc_pair_t *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR, xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) { container = xmlNodeGetContent(attr->children); } if (xmlStrncmp(attr->name, (xmlChar *)NODENAMEATTR, xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) { member = xmlNodeGetContent(attr->children); } } if (container != NULL && member != NULL) { req->req_data.pair = NEW_REQPAIRARGV(req->req_data.pair, req->count); if (req->req_data.pair == (assoc_pair_t **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count] = (assoc_pair_t *) malloc(sizeof (assoc_pair_t)); if (req->req_data.pair[req->count] == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count]->container = container; req->req_data.pair[req->count]->member = member; req->req_data.data[++req->count] = NULL; } else { if (container != NULL) { xmlFree(container); } if (member != NULL) { xmlFree(member); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } container = member = NULL; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; case DiscoveryDomainSetMember: /* at least one object exists to get here. */ r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.pair = (assoc_pair_t **)malloc(sizeof (assoc_pair_t *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)DDSETNAMEATTR, xmlStrlen((xmlChar *)DDSETNAMEATTR)) == 0) { container = xmlNodeGetContent(attr->children); } if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR, xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) { member = xmlNodeGetContent(attr->children); } } if (container != NULL && member != NULL) { req->req_data.pair = NEW_REQPAIRARGV(req->req_data.pair, req->count); if (req->req_data.pair == (assoc_pair_t **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count] = (assoc_pair_t *) malloc(sizeof (assoc_pair_t)); if (req->req_data.pair[req->count] == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count]->container = container; req->req_data.pair[req->count]->member = member; req->req_data.data[++req->count] = NULL; } else { if (container != NULL) { xmlFree(container); } if (member != NULL) { xmlFree(member); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } container = member = NULL; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; case DiscoveryDomain: case DiscoveryDomainSet: /* at least one object exists to get here. */ r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.attrlist = (object_attrlist_t **)malloc(sizeof (object_attrlist_t *)); for (i = 0; i < cnt; i++) { req->req_data.attrlist = NEW_REQATTRLISTARGV(req->req_data.attrlist, req->count); if (req->req_data.attrlist == (object_attrlist_t **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.attrlist[req->count] = (object_attrlist_t *) malloc(sizeof (object_attrlist_t)); if (req->req_data.attrlist[req->count] == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.attrlist[req->count]->name = NULL; req->req_data.attrlist[req->count]->id = NULL; req->req_data.attrlist[req->count]->enabled = NULL; attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if ((xmlStrncmp(attr->name, (xmlChar *)NAMEATTR, xmlStrlen((xmlChar *)NAMEATTR))) == 0) { req->req_data.attrlist[req->count]->name = xmlNodeGetContent(attr->children); } if ((xmlStrncmp(attr->name, (xmlChar *)IDATTR, xmlStrlen((xmlChar *)IDATTR))) == 0) { req->req_data.attrlist[req->count]->id = (uint32_t *)calloc(1, sizeof (uint32_t)); if (req->req_data.attrlist[req->count]->id == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } xml_id = xmlNodeGetContent(attr->children); if (xml_id != NULL) { *(req->req_data.attrlist[req->count]->id) = atoi((const char *)xml_id); xmlFree(xml_id); } } } /* * check the enabled element. * Only one child element so check the children ptr. */ if (r_nodes->nodeTab[i]->children) { req->req_data.attrlist[req->count]->enabled = (boolean_t *)malloc(sizeof (boolean_t)); if (req->req_data.attrlist[req->count]->enabled == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } /* value is children of enabled. */ if (xmlStrncmp( r_nodes->nodeTab[i]->children->children->content, (xmlChar *)XMLTRUE, xmlStrlen((xmlChar *)XMLTRUE)) == 0) { *(req->req_data.attrlist[req->count]->enabled) = B_TRUE; } else { *(req->req_data.attrlist[req->count]->enabled) = B_FALSE; } } req->req_data.attrlist[++req->count] = NULL; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; default: if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } return (0); }
/* * process_getAssociated_request_from_doc -- * first looks for association type through the contexti and then * find out the given object. That will indicate the direction of * association, containter to member or vice versa. * Lastly it extract the object name form the doc that assocation * is requested. * * ctext: context ptr for the original doc to parse request info. * req: request to be filled up. * * Returns 0 if successful or an error code otherwise. */ static int process_getAssociated_request_from_doc(xmlXPathContextPtr ctext, request_t *req) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; xmlNodeSetPtr r_nodes = NULL; xmlAttrPtr attr = NULL; int i, cnt, obj = 0; isnslog(LOG_DEBUG, "process_getAssociated_request_from_doc", "entered"); (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ASSOCIATIONTYPE); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { for (i = 0; obj_table[i].obj_str != NULL; i++) { if (xmlStrncmp( xpath_obj->nodesetval->nodeTab[0]->children->content, (xmlChar *)obj_table[i].obj_str, xmlStrlen( xpath_obj->nodesetval->nodeTab[0]->children->content)) == 0) { obj = obj_table[i].obj_id; break; } } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); if (obj == 0) { return (ERR_XML_VALID_OBJECT_NOT_FOUND); } req->op_info.obj = obj; if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) { ISNS_MGMT_OBJECT_TYPE(obj); } switch (obj) { /* using the same algorithm for isns object */ case DiscoveryDomainMember: (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", NODEOBJECT); xpath_obj = xmlXPathEvalExpression(expr, ctext); r_nodes = xpath_obj->nodesetval; if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { req->assoc_req = member_to_container; } else { if (xpath_obj) xmlXPathFreeObject(xpath_obj); (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", DDOBJECT); xpath_obj = xmlXPathEvalExpression(expr, ctext); r_nodes = xpath_obj->nodesetval; if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { req->assoc_req = container_to_member; } else { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_VALID_OBJECT_NOT_FOUND); } } break; case DiscoveryDomainSetMember: (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", DDSETOBJECT); xpath_obj = xmlXPathEvalExpression(expr, ctext); r_nodes = xpath_obj->nodesetval; if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { req->assoc_req = container_to_member; } else { if (xpath_obj) xmlXPathFreeObject(xpath_obj); (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", DDOBJECT); xpath_obj = xmlXPathEvalExpression(expr, ctext); r_nodes = xpath_obj->nodesetval; if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { req->assoc_req = member_to_container; } else { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_VALID_OBJECT_NOT_FOUND); } } break; default: if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } /* now process the name attr */ cnt = r_nodes->nodeNr; req->count = 0; req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *)); /* for (i = cnt - 1; i >= 0; i--) { */ for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR, xmlStrlen((xmlChar *)NAMEATTR)) == 0) { req->req_data.data = NEW_REQARGV(req->req_data.data, req->count); if (req->req_data.data == (xmlChar **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.data[req->count++] = xmlNodeGetContent(attr->children); req->req_data.data[req->count] = NULL; } } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (0); }
/* * process_get_request_from_doc -- * looks for the object through the context ptr and gets the object * name. Possible object types are Node, DD, DD set and server-config. * * ctext: context ptr for the original doc to parse request info. * req: request to be filled up. * * Returns 0 if successful or an error code otherwise. */ static int process_get_request_from_doc(xmlXPathContextPtr ctext, request_t *req) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; xmlNodeSetPtr r_nodes = NULL; xmlAttrPtr attr = NULL; int i, cnt; int obj = 0; isnslog(LOG_DEBUG, "process_get_request_from_doc", "entered"); (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSOBJECT); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeTab) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab[0]->children) && (xpath_obj->nodesetval->nodeTab[0]->children->name)) { for (i = 0; obj_table[i].obj_str != NULL; i++) { /* * To handle DiscoveryDomain and DiscoveryDomainSet * searches isnsobject instead of the object directly. */ if (xmlStrncmp( xpath_obj->nodesetval->nodeTab[0]->children->name, (xmlChar *)obj_table[i].obj_str, xmlStrlen( xpath_obj->nodesetval->nodeTab[0]->children->name)) == 0) { obj = obj_table[i].obj_id; break; } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); } if (obj == 0) { /* check the server config request. */ (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSSERVER); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { for (i = 0; obj_table[i].obj_str != NULL; i++) { if (strncmp(ISNSSERVER, obj_table[i].obj_str, strlen(ISNSSERVER)) == 0) { obj = obj_table[i].obj_id; break; } } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); } if (obj == 0) { return (ERR_XML_VALID_OBJECT_NOT_FOUND); } req->op_info.obj = obj; if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) { ISNS_MGMT_OBJECT_TYPE(obj); } (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 12, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", obj_table[i].obj_str); xpath_obj = xmlXPathEvalExpression(expr, ctext); if (((xpath_obj == NULL) || (xpath_obj->nodesetval == NULL) || (xpath_obj->nodesetval->nodeNr <= 0) || (xpath_obj->nodesetval->nodeTab == NULL))) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_VALID_OBJECT_NOT_FOUND); } switch (obj) { /* using the same algorithm for isns object */ case Node: case DiscoveryDomain: case DiscoveryDomainSet: r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR, xmlStrlen((xmlChar *)NAMEATTR)) == 0) { req->req_data.data = NEW_REQARGV(req->req_data.data, req->count); if (req->req_data.data == (xmlChar **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.data[req->count] = xmlNodeGetContent(attr->children); req->req_data.data[++req->count] = NULL; } } } break; case ServerConfig: /* indication the obj type is sufficient. */ break; default: if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (0); }
/* Custom xslt loader */ static xmlDocPtr custom_loader(const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt, xsltLoadType type) { xmlDocPtr ret; xmlChar *rel_path, *fn, *final_URI = NULL; char *path_URI = NULL; xsltStylesheet *c; ice_config_t *config; switch (type) { /* In case an include is loaded */ case XSLT_LOAD_STYLESHEET: /* URI is an escaped URI, make an unescaped version */ path_URI = util_url_unescape((const char*)URI); /* Error if we can't unescape */ if (path_URI == NULL) return NULL; /* Not look in admindir if the include file exists */ if (access(path_URI, F_OK) == 0) { free(path_URI); break; } free(path_URI); c = (xsltStylesheet *) ctxt; /* Check if we actually have context/path */ if (ctxt == NULL || c->doc->URL == NULL) break; /* Construct the right path */ rel_path = xmlBuildRelativeURI(URI, c->doc->URL); if (rel_path != NULL && admin_path != NULL) { fn = xmlBuildURI(rel_path, admin_path); final_URI = fn; xmlFree(rel_path); } /* Fail if there was an error constructing the path */ if (final_URI == NULL) { if (rel_path) xmlFree(rel_path); return NULL; } break; /* In case a top stylesheet is loaded */ case XSLT_LOAD_START: config = config_get_config(); /* Admin path is cached, so that we don't need to get it from * the config every time we load a xsl include. * Whenever a new top stylesheet is loaded, we check here * if the path in the config has changed and adjust it, if needed. */ if (admin_path != NULL && strcmp(config->adminroot_dir, (char *)admin_path) != 0) { xmlFree(admin_path); admin_path = NULL; } /* Do we need to load the admin path? */ if (!admin_path) { size_t len = strlen(config->adminroot_dir); admin_path = xmlMalloc(len+2); if (!admin_path) return NULL; /* Copy over admin path and add a tailing slash. */ xmlStrPrintf(admin_path, len+2, XMLSTR("%s/"), XMLSTR(config->adminroot_dir)); } config_release_config(); break; /* Avoid warnings about other events we don't care for */ default: break; } /* Get the actual xmlDoc */ if (final_URI) { ret = xslt_loader(final_URI, dict, options, ctxt, type); xmlFree(final_URI); } else { ret = xslt_loader(URI, dict, options, ctxt, type); } return ret; }
static gboolean load_iso_entries (int iso, GFunc read_entry_func, gpointer user_data) { xmlTextReaderPtr reader; ParserState state = STATE_START; xmlChar iso_entries[32], iso_entry[32]; char *filename; int ret = -1; #ifdef WIN32 filename = g_strdup_printf (".\\share\\xml\\iso-codes\\iso_%d.xml", iso); #else filename = g_strdup_printf ("/usr/share/xml/iso-codes/iso_%d.xml", iso); #endif reader = xmlNewTextReaderFilename (filename); if (reader == NULL) goto out; xmlStrPrintf (iso_entries, sizeof (iso_entries), (xmlChar *)"iso_%d_entries", iso); xmlStrPrintf (iso_entry, sizeof (iso_entry), (xmlChar *)"iso_%d_entry", iso); ret = xmlTextReaderRead (reader); while (ret == 1) { const xmlChar *tag; xmlReaderTypes type; tag = xmlTextReaderConstName (reader); type = xmlTextReaderNodeType (reader); if (state == STATE_ENTRIES && type == XML_READER_TYPE_ELEMENT && xmlStrEqual (tag, iso_entry)) { read_entry_func (reader, user_data); } else if (state == STATE_START && type == XML_READER_TYPE_ELEMENT && xmlStrEqual (tag, iso_entries)) { state = STATE_ENTRIES; } else if (state == STATE_ENTRIES && type == XML_READER_TYPE_END_ELEMENT && xmlStrEqual (tag, iso_entries)) { state = STATE_STOP; } else if (type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE || type == XML_READER_TYPE_WHITESPACE || type == XML_READER_TYPE_TEXT || type == XML_READER_TYPE_COMMENT) { /* eat it */ } else { /* ignore it */ } ret = xmlTextReaderRead (reader); } xmlFreeTextReader (reader); out: if (ret < 0 || state != STATE_STOP) { /* This is not critical, we will fallback to our own code */ g_free (filename); return FALSE; } g_free (filename); return TRUE; }
/* * process_delete_request_from_doc -- * first looks for the object through the context ptr and sets the * request with additional data. * For DD and DD set, the name is given. * For DD and DD set membership, container and member pairs are given. * * ctext: context ptr for the original doc to parse request info. * req: request to be filled up. * * Returns 0 if successful or an error code otherwise. */ static int process_delete_request_from_doc(xmlXPathContextPtr ctext, request_t *req) { xmlChar expr[ISNS_MAX_LABEL_LEN + 13]; xmlXPathObjectPtr xpath_obj = NULL; xmlNodeSetPtr r_nodes = NULL; xmlAttrPtr attr = NULL; xmlChar *container = NULL, *member = NULL; int i, cnt; int obj = 0; isnslog(LOG_DEBUG, "process_delete_request_from_doc", "entered"); for (i = 0; obj_table[i].obj_str != NULL; i++) { (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13, XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", obj_table[i].obj_str); xpath_obj = xmlXPathEvalExpression(expr, ctext); if ((xpath_obj) && (xpath_obj->nodesetval) && (xpath_obj->nodesetval->nodeNr > 0) && (xpath_obj->nodesetval->nodeTab)) { obj = obj_table[i].obj_id; break; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); } if (obj == 0) { return (ERR_XML_VALID_OBJECT_NOT_FOUND); } req->op_info.obj = obj; if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) { ISNS_MGMT_OBJECT_TYPE(obj); } switch (obj) { case DiscoveryDomainMember: /* at least one object exists to get here. */ r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.pair = (assoc_pair_t **)malloc(sizeof (assoc_pair_t *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR, xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) { container = xmlNodeGetContent(attr->children); } if (xmlStrncmp(attr->name, (xmlChar *)NODENAMEATTR, xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) { member = xmlNodeGetContent(attr->children); } } if (container != NULL && member != NULL) { req->req_data.pair = NEW_REQPAIRARGV(req->req_data.pair, req->count); if (req->req_data.pair == (assoc_pair_t **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count] = (assoc_pair_t *) malloc(sizeof (assoc_pair_t)); if (req->req_data.pair[req->count] == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count]->container = container; req->req_data.pair[req->count]->member = member; req->req_data.data[++req->count] = NULL; } else { if (container != NULL) { xmlFree(container); } if (member != NULL) { xmlFree(member); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } container = NULL; member = NULL; } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; case DiscoveryDomainSetMember: /* at least one object exists to get here. */ r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.pair = (assoc_pair_t **)malloc(sizeof (assoc_pair_t *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)DDSETNAMEATTR, xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) { container = xmlNodeGetContent(attr->children); } if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR, xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) { member = xmlNodeGetContent(attr->children); } } if (container != NULL && member != NULL) { req->req_data.pair = NEW_REQPAIRARGV(req->req_data.pair, req->count); if (req->req_data.pair == (assoc_pair_t **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count] = (assoc_pair_t *) malloc(sizeof (assoc_pair_t)); if (req->req_data.pair[req->count] == NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.pair[req->count]->container = container; req->req_data.pair[req->count++]->member = member; req->req_data.data[req->count] = NULL; } else { if (container != NULL) { xmlFree(container); } if (member != NULL) { xmlFree(member); } if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; case DiscoveryDomain: case DiscoveryDomainSet: r_nodes = xpath_obj->nodesetval; cnt = r_nodes->nodeNr; req->count = 0; req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *)); for (i = 0; i < cnt; i++) { attr = r_nodes->nodeTab[i]->properties; for (; attr != NULL; attr = attr->next) { if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR, xmlStrlen((xmlChar *)NAMEATTR)) == 0) { req->req_data.data = NEW_REQARGV(req->req_data.data, req->count); if (req->req_data.data == (xmlChar **)NULL) { if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_MALLOC_FAILED); } req->req_data.data[req->count] = xmlNodeGetContent(attr->children); req->req_data.data[++req->count] = NULL; } } } if (xpath_obj) xmlXPathFreeObject(xpath_obj); break; default: if (xpath_obj) xmlXPathFreeObject(xpath_obj); return (ERR_XML_OP_FAILED); } return (0); }
static void load_iso_entries (int iso, GFunc read_entry_func, gpointer user_data) { xmlTextReaderPtr reader; ParserState state = STATE_START; xmlChar iso_entries[32], iso_entry[32]; char *filename; int ret = -1; cedit_debug_message (DEBUG_PLUGINS, "Loading ISO-%d codes", iso); filename = g_strdup_printf (ISO_CODES_PREFIX "/share/xml/iso-codes/iso_%d.xml", iso); reader = xmlNewTextReaderFilename (filename); if (reader == NULL) goto out; xmlStrPrintf (iso_entries, sizeof (iso_entries), (const xmlChar *)"iso_%d_entries", iso); xmlStrPrintf (iso_entry, sizeof (iso_entry), (const xmlChar *)"iso_%d_entry", iso); ret = xmlTextReaderRead (reader); while (ret == 1) { const xmlChar *tag; xmlReaderTypes type; tag = xmlTextReaderConstName (reader); type = xmlTextReaderNodeType (reader); if (state == STATE_ENTRIES && type == XML_READER_TYPE_ELEMENT && xmlStrEqual (tag, iso_entry)) { read_entry_func (reader, user_data); } else if (state == STATE_START && type == XML_READER_TYPE_ELEMENT && xmlStrEqual (tag, iso_entries)) { state = STATE_ENTRIES; } else if (state == STATE_ENTRIES && type == XML_READER_TYPE_END_ELEMENT && xmlStrEqual (tag, iso_entries)) { state = STATE_STOP; } else if (type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE || type == XML_READER_TYPE_WHITESPACE || type == XML_READER_TYPE_TEXT || type == XML_READER_TYPE_COMMENT) { /* eat it */ } else { /* ignore it */ } ret = xmlTextReaderRead (reader); } xmlFreeTextReader (reader); out: if (ret < 0 || state != STATE_STOP) { g_warning ("Failed to load ISO-%d codes from %s!\n", iso, filename); } g_free (filename); }
static int xmlSecTransformXPathNodeRead(xmlSecTransformPtr transform, xmlNodePtr node, xmlSecTransformCtxPtr transformCtx) { xmlSecPtrListPtr dataList; xmlSecXPathDataPtr data; xmlNodePtr cur; xmlChar* tmp; int tmpSize; int ret; xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformXPathId), -1); xmlSecAssert2(node != NULL, -1); xmlSecAssert2(transformCtx != NULL, -1); dataList = xmlSecXPathTransformGetDataList(transform); xmlSecAssert2(xmlSecPtrListCheckId(dataList, xmlSecXPathDataListId), -1); xmlSecAssert2(xmlSecPtrListGetSize(dataList) == 0, -1); /* there is only one required node */ cur = xmlSecGetNextElementNode(node->children); if((cur == NULL) || (!xmlSecCheckNodeName(cur, xmlSecNodeXPath, xmlSecDSigNs))) { xmlSecInvalidNodeError(cur, xmlSecNodeXPath, xmlSecTransformGetName(transform)); return(-1); } /* read information from the node */ data = xmlSecXPathDataCreate(xmlSecXPathDataTypeXPath); if(data == NULL) { xmlSecInternalError("xmlSecXPathDataCreate", xmlSecTransformGetName(transform)); return(-1); } ret = xmlSecXPathDataNodeRead(data, cur); if(ret < 0) { xmlSecInternalError("xmlSecXPathDataNodeRead", xmlSecTransformGetName(transform)); xmlSecXPathDataDestroy(data); return(-1); } /* append it to the list */ ret = xmlSecPtrListAdd(dataList, data); if(ret < 0) { xmlSecInternalError("xmlSecPtrListAdd", xmlSecTransformGetName(transform)); xmlSecXPathDataDestroy(data); return(-1); } /* create full XPath expression */ xmlSecAssert2(data->expr != NULL, -1); tmpSize = xmlStrlen(data->expr) + strlen(xpathPattern) + 1; tmp = (xmlChar*) xmlMalloc(sizeof(xmlChar) * tmpSize); if(tmp == NULL) { xmlSecMallocError(sizeof(xmlChar) * tmpSize, xmlSecTransformGetName(transform)); return(-1); } ret = xmlStrPrintf(tmp, tmpSize, xpathPattern, (char*)data->expr); if(ret < 0) { xmlSecXmlError("xmlStrPrintf", xmlSecTransformGetName(transform)); xmlFree(tmp); return(-1); } xmlFree(data->expr); data->expr = tmp; /* set correct node set type and operation */ data->nodeSetOp = xmlSecNodeSetIntersection; data->nodeSetType = xmlSecNodeSetNormal; /* check that we have nothing else */ cur = xmlSecGetNextElementNode(cur->next); if(cur != NULL) { xmlSecUnexpectedNodeError(cur, xmlSecTransformGetName(transform)); return(-1); } return(0); }