/* * call-seq: * element_children * * Get the list of children for this node as a NodeSet. All nodes will be * element nodes. * * Example: * * @doc.root.element_children.all? { |x| x.element? } # => true */ static VALUE element_children(VALUE self) { xmlNodePtr node; xmlNodePtr child; xmlNodeSetPtr set; VALUE document; VALUE node_set; Data_Get_Struct(self, xmlNode, node); child = xmlFirstElementChild(node); set = xmlXPathNodeSetCreate(child); document = DOC_RUBY_OBJECT(node->doc); if(!child) return Nokogiri_wrap_xml_node_set(set, document); child = xmlNextElementSibling(child); while(NULL != child) { xmlXPathNodeSetAddUnique(set, child); child = xmlNextElementSibling(child); } node_set = Nokogiri_wrap_xml_node_set(set, document); return node_set; }
static NodeType findNextSibling(NodeType node, const std::string& name) { const xmlChar* convertedName = reinterpret_cast<const xmlChar*>(name.c_str()); NodeType sibling = xmlNextElementSibling(node); while (sibling) { if (xmlStrcmp(sibling->name, convertedName) == 0) break; else node = xmlNextElementSibling(sibling); } return sibling; }
static gint parse_radio_list(GString *data, GList **list) { gint result = 1; xmlDocPtr doc; if (data->str == NULL || data->len == 0) return 1; doc = xmlReadMemory(data->str, data->len, NULL, NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR); if (doc == NULL) return result; do { xmlNodePtr radioList; xmlNodePtr p; radioList = xmlDocGetRootElement(doc); if (radioList == NULL) break; for(p=xmlFirstElementChild(radioList); p; p=xmlNextElementSibling(p)) get_radio(p, list); result = 0; } while(0); xmlFreeDoc(doc); return result; }
/******************* FUNCTION *********************/ CMRXmlNode CMRXmlNode::getNext ( void ) { if (node == NULL) return CMRXmlNode(NULL); else return CMRXmlNode(xmlNextElementSibling(node)); }
xmlNode* XMLParser::getNext(xmlNodePtr cur) const { if(!cur) { fprintf(stderr,"Warning: Got Empty Node\n"); return NULL; } return xmlNextElementSibling(cur); }
std::list< ::fwRuntime::io::Substitute > XMLSubstitute::getSubstitutions( xmlNodePtr substitutionRules ) { // create the context for xpath xmlXPathContextPtr xpathCtx; xpathCtx = xmlXPathNewContext(substitutionRules->doc); SLM_ASSERT("xpathCtx not instanced", xpathCtx); std::list< ::fwRuntime::io::Substitute > result; xmlChar *xpathExpr= BAD_CAST "//Substitutions/substitute"; xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx); // xmlXPathObjectPtr::nodesetval : get set of node // xmlNodeSetPtr::nodeNr = nb element // xmlNodeSetPtr::nodeTab[i] : ith element : must be processed in reverse order SLM_ASSERT("xpathObj not instanced", xpathObj); int NbNodesFound = xpathObj->nodesetval->nodeNr; for (int i=0; i < NbNodesFound ; ++i ) { Substitute s; xmlNodePtr subNode = xpathObj->nodesetval->nodeTab[i]; xmlNodePtr element = xmlNextElementSibling(subNode->children); while (element ) { if ( xmlStrcmp( element->name, BAD_CAST "nodePath")==0 ) { s.xpath = (const char *)xmlNodeGetContent( element ); } if ( xmlStrcmp( element->name, BAD_CAST "replace")==0 ) { s.dictEntry = (const char *)xmlGetProp( element, BAD_CAST "dictEntry" ); s.status = (const char *)xmlGetProp( element, BAD_CAST "status" ); } element = xmlNextElementSibling(element); } assert( s.xpath.size() && s.dictEntry.size() && s.status.size() ); result.push_back( s ); } xmlXPathFreeObject(xpathObj ); return result; }
/* * call-seq: * next_element * * Returns the next Nokogiri::XML::Element type sibling node. */ static VALUE next_element(VALUE self) { xmlNodePtr node, sibling; Data_Get_Struct(self, xmlNode, node); sibling = xmlNextElementSibling(node); if(!sibling) return Qnil; return Nokogiri_wrap_xml_node(Qnil, sibling); }
/* create junction boxes */ int _create_jb_object(xmlNodePtr node, struct _zparser* parser) { xmlNodePtr _child = NULL; struct _zobject* _obj = NULL; struct _jb_dims { double x __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double y __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double width __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double height __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double depth __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double radius __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); double angle __attribute__ ((aligned (ZELIA_XML_TSTRUCT_ALIGN))); } _jb_dim; /* create notes object collection */ memset(&_jb_dim, 0, sizeof(struct _jb_dims)); _obj = (struct _zobject*) malloc(sizeof(struct _zobject)); _obj->type = zobject_item; _child = xmlFirstElementChild(node); _create_jb_object_helper(_child, (void*) &_jb_dim); /* create junction box object */ _obj->data._i = zjb_new(NULL, &parser->device, _jb_dim.x, _jb_dim.y, _jb_dim.width, _jb_dim.height, _jb_dim.depth, _jb_dim.angle); zjb_set_fillet_radius(Z_JB(_obj->data._i), _jb_dim.radius); while(_child) { if(strcmp((const char*) _child->name, ZPARSER_TERMINALS) == 0) _create_jb_object_terminals_helper(_child, _obj->data._i); else if(strcmp((const char*) _child->name, ZPARSER_GLAND) == 0) _create_jb_object_gland_helper(_child, _obj->data._i); _child = xmlNextElementSibling(_child); } /* call draw method */ zgeneric_draw(_obj->data._i); /* push to the collection */ blist_add_from_end(&parser->object_array, (void*) _obj); return ZELIA_OK; }
ValgrindResult* valgrindXML_evaluate(char *xml_path,int testing_framework) { char *docname; xmlDocPtr doc; xmlChar *xpath = (xmlChar*) "//errorcounts/pair/count"; xmlNodeSetPtr nodeset; xmlXPathObjectPtr result; int i; docname = xml_path; doc = getdoc(docname); result = getnodeset (doc, xpath); ValgrindResult *valgrindResult=NULL; //Get all the errors first if (result) { nodeset = result->nodesetval; if(nodeset->nodeNr==0){ //NO valgrind errors for this mutant return NULL; } valgrindResult= malloc(sizeof(ValgrindResult)); //Initialization of valgrindResult valgrindResult->valgrind_error_count=0; valgrindResult->unique_valgrind_error_count=0; //Capturing results in valgrindResult valgrindResult->unique_valgrind_error_count=nodeset->nodeNr; valgrindResult->valgrindErrors = malloc(nodeset->nodeNr*sizeof(ValgrindError)); for (i=0; i < nodeset->nodeNr; i++) { //Get <count></count> xmlNodePtr countNode = nodeset->nodeTab[i]; //Get <unique></unique> xmlNodePtr uniqueNode = xmlNextElementSibling(countNode); //Values for both of the nodes xmlChar *count_value = xmlNodeListGetString(doc, countNode->xmlChildrenNode, 1); xmlChar *unique_value = xmlNodeListGetString(doc, uniqueNode->xmlChildrenNode, 1); int error_count = (int)strtoumax((char*)count_value, NULL, 10); valgrindResult->valgrind_error_count+=error_count; //For each unique value, get all its error nodes evaluate_error_nodes(&valgrindResult->valgrindErrors[i],doc,error_count,unique_value,testing_framework); xmlFree(count_value); xmlFree(unique_value); } xmlXPathFreeObject (result); } xmlFreeDoc(doc); xmlCleanupParser(); return valgrindResult; }
xmlNodePtr XMLParser::getChildrenXMLElement (xmlNodePtr pNode) { std::set<int> ignoredNodeType; ignoredNodeType += XML_TEXT_NODE, XML_CDATA_SECTION_NODE, XML_COMMENT_NODE; xmlNodePtr childNode = pNode->children; if(!childNode || ignoredNodeType.find(childNode->type) != ignoredNodeType.end()) { childNode = xmlNextElementSibling( pNode->children ); } return childNode; }
int _create_label_object(xmlNodePtr node, struct _zparser* parser) { struct _zobject* _obj = NULL; xmlNodePtr _child = NULL; xmlChar* _content = NULL; xmlChar* _path = NULL; unsigned int _del_flg = 1; double _x = 0.0, _y = 0.0; _child = xmlFirstElementChild(node); while(_child) { _del_flg = 1; _content = xmlNodeGetContent(_child); if(strcmp((const char*) _child->name, ZPARSER_TEMPLATE_PATH) == 0) { _del_flg = 0; _path = _content; } else if(strcmp((const char*) _child->name, ZPARSER_COORD_X) == 0) _x = atof((const char*) _content); else if(strcmp((const char*) _child->name, ZPARSER_COORD_Y) == 0) _y = atof((const char*) _content); /* if delete flag is true delete and set the pointer to NULL */ if(_del_flg) { xmlFree(_content); _content = NULL; } _child = xmlNextElementSibling(_child); } if(_path == NULL) return ZELIA_NULL; /* create object */ _obj = (struct _zobject*) malloc(sizeof(struct _zobject)); _obj->type = zobject_item; _obj->data._i = zlabel_new(NULL, &parser->file, (const char*) _path, _x, _y); /* call draw method */ zgeneric_draw(_obj->data._i); /* push to the collection */ blist_add_from_end(&parser->object_array, (void*) _obj); return ZELIA_OK; }
static NodeType findFirstChild(NodeType node, const std::string& name) { const xmlChar* convertedName = reinterpret_cast<const xmlChar*>(name.c_str()); NodeType child = xmlFirstElementChild(node); while (child) { if (xmlStrcmp(child->name, convertedName) == 0) break; else child = xmlNextElementSibling(child); } return child; }
/** * Examine next sibling of node for a matching name and the sibling to * the output list if it matches. * * Returns a 0 (XQ_OK) on success, an error code otherwise */ xQStatusCode _xQ_findNextSiblingByName(xQ* context, xmlChar** args, xmlNodePtr node, xQNodeList* outList) { const xmlChar* name = args[0]; const xmlChar* ns = args[1]; xQStatusCode result = XQ_OK; xmlNodePtr sibling; nsLookup(context, ns); if (node->type == XML_ELEMENT_NODE && (sibling = xmlNextElementSibling(node))) { if ( (xmlStrcmp(name, sibling->name) == 0) && nsMatch(sibling, ns) ) result = xQNodeList_push(outList, sibling); } return result; }
int _create_file_object(xmlNodePtr node, struct _zparser* parser) { char* _save_path = NULL; char* _template_path = NULL; char* _sheet_size = NULL; zSheets _sheet_type = zSheetA4_Portrait; xmlNodePtr _child = NULL; int stat = 0; /* get first child node */ _child = xmlFirstElementChild(node); while(_child) { if(strcmp((const char*) _child->name, ZPARSER_TEMPLATE_PATH) == 0) _template_path = (char*) xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_SAVE_PATH) == 0) _save_path = (char*) xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_SHEET_SIZE) == 0) _sheet_size = (char*) xmlNodeGetContent(_child); _child = xmlNextElementSibling(_child); } /* if the paths were set we create the file object */ stat = zfile_create_file_from_template(&parser->file, _template_path, _save_path); if(stat != ZELIA_OK) ZELIA_LOG_MESSAGE("errors occured while creating a new file"); if(strcmp(_sheet_size, ZPARSER_SHEET_A4_PORT) == 0) _sheet_type = zSheetA4_Portrait; else if(strcmp(_sheet_size, ZPARSER_SHEET_A4_LAND) == 0) _sheet_type = zSheetA4_Landscape; else if(strcmp(_sheet_size, ZPARSER_SHEET_A3_PORT) == 0) _sheet_type = zSheetA3_Portrait; else _sheet_type = zSheetA3_Landscape; zdevice_new2(_sheet_type, 0, &parser->device); /* free memory */ free(_template_path); free(_save_path); free(_sheet_size); return ZELIA_OK; }
char *filter(char *str, Regexfilter *filterList) { xmlDocPtr doc; xmlNodePtr item_node, title_node; xmlChar *xmlbuff, *title_content; int buffersize; doc = xmlReadMemory(str, strlen(str), "noname.xml", NULL, 0); if (doc == NULL) { fprintf(stderr, "Failed to parse document\n"); return; } item_node = feed_first_item(doc); /* loop through items */ while (item_node != NULL) { title_node = xmlFirstElementChild(item_node); title_content = xmlNodeGetContent(title_node); if (!pattern_check((char *)title_content, filterList)) { /* remove <item> node and leftover space*/ feed_remove_node(&item_node); feed_remove_node(&item_node); } item_node = xmlNextElementSibling(item_node); } /* * Convert rss doc to string * and return. */ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize,1); xmlFreeDoc(doc); return xmlbuff; }
void removeDefaultNamespace(xmlNs *ns, xmlNode *node) { removeNamespace(&node->nsDef, ns); xmlAttr *attr; for (attr = node->properties; attr; attr = attr->next) { if (!attr->ns) continue; removeNamespace(&attr->ns, ns); } if (node->ns == ns) node->ns = NULL; xmlNode *child; for (child = xmlFirstElementChild(node); child; child = xmlNextElementSibling(child)) { removeDefaultNamespace(ns, child); } }
static gint parse_track_list_data(GString *data, GList **list) { gint result = 1; xmlDocPtr doc = NULL; doc = xmlReadMemory(data->str, data->len, NULL, NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR); if (doc == NULL) return result; do { xmlNodePtr root; xmlNodePtr track_list; xmlNodePtr p; root = xmlDocGetRootElement(doc); if (root == NULL) break; track_list = xml_first_child(root, BAD_CAST "trackList"); if (track_list == NULL) break; for(p = xmlFirstElementChild(track_list); p ; p = xmlNextElementSibling(p)) get_track(p, list); result = 0; } while(0); xmlFreeDoc(doc); return result; }
template <typename Traits> inline shared_ptr<typename detector_impl<Traits>::branch_type> detector_impl<Traits>::parse_branch(xmlNodePtr node) const { shared_ptr<branch_type> result(new branch_type()); for (xmlNodePtr n = xmlFirstElementChild(node); 0 != n; n = xmlNextElementSibling(n)) { if (disabled(n)) { continue; } else if (xmlStrncasecmp(n->name, (xmlChar const*) "match", sizeof("match")) == 0) { xml_elems elems(n, "pattern"); for (xml_elems::iterator i = elems.begin(), end = elems.end(); i != end; ++i) { if (disabled(*i)) { continue; } char const *type = xml_attr_text(*i, "type"); if (strncasecmp(type, "string", sizeof("string")) == 0) { result->add_match(xml_node_text(*i)); } else if (strncasecmp(type, "regex", sizeof("regex")) == 0) { result->add_regex_match(xml_node_text(*i)); } else { resource<xmlChar*, xml_string_traits> path(xmlGetNodePath(*i)); throw error("unknown pattern type %s in [%s]", type, (char const*) path.get()); } } } else if (xmlStrncasecmp(n->name, (xmlChar const*) "branch", sizeof("branch")) == 0) { result->add_child(parse_branch(n)); } else if (xmlStrncasecmp(n->name, (xmlChar const*) "define", sizeof("definition")) == 0) { result->add_definition(parse_definition(n)); } } return result; }
/* create leader object */ int _create_leader_object(xmlNodePtr node, struct _zparser* parser) { xmlChar* _content = NULL; xmlNodePtr _child = NULL; double _dim_dbl = 0.0, _x = 0.0, _y = 0.0, _ang = 0.0, _seg1 = 0.0, _seg2 = 0.0; struct _zobject* _obj = NULL; unsigned int _del_flg = 1; _obj = (struct _zobject*) malloc(sizeof(struct _zobject)); _obj->type = zobject_item; _child = xmlFirstElementChild(node); while(_child) { _content = xmlNodeGetContent(_child); if(_content != NULL) _dim_dbl = atof((char*) _content); _del_flg = 1; if(strcmp((const char*) _child->name, ZPARSER_COORD_X) == 0) _x = _dim_dbl; else if(strcmp((const char*) _child->name, ZPARSER_COORD_Y) == 0) _y = _dim_dbl; else if(strcmp((const char*) _child->name, ZPARSER_ANGLE) == 0) _ang = _dim_dbl; else if(strcmp((const char*) _child->name, ZPARSER_SEGMENT_1) == 0) _seg1 = _dim_dbl; else if(strcmp((const char*) _child->name, ZPARSER_SEGMENT_2) == 0) _seg2 = _dim_dbl; else if(strcmp((const char*) _child->name, ZPARSER_DESCRIPTION) == 0) _del_flg = 0; if(_del_flg) { xmlFree(_content); _content = NULL; } _child = xmlNextElementSibling(_child); } /* create a new leader object */ _obj->data._i = zleader_new(NULL, &parser->device, _x, _y, _seg1, _seg2, _ang, (char*) _content); /* call draw method */ zgeneric_draw(_obj->data._i); /* push to the collection */ blist_add_from_end(&parser->object_array, (void*) _obj); if(_content) xmlFree(_content); return ZELIA_OK; }
/** * get next sibling of a node * * @param n NftPrefsNode from which sibling should be fetched * @result sibling node or NULL */ NftPrefsNode *nft_prefs_node_get_next(NftPrefsNode * n) { return xmlNextElementSibling(n); }
/* create table object */ int _create_table_object(xmlNodePtr node, struct _zparser* parser) { xmlChar* _content = NULL, *_rows = NULL, *_cols = NULL; double _dim_dbl = 0.0; int _num_cols = 0, _num_rows = 0; struct _zobject* _obj = NULL; xmlNodePtr _child = NULL; /* create notes object collection */ _obj = (struct _zobject*) malloc(sizeof(struct _zobject)); _obj->type = zobject_item; /* create the table object */ _obj->data._i = ztable_new(NULL); if(_obj->data._i == NULL) { free(_obj); return ZELIA_NULL; } zgeneric_set_device(_obj->data._i, &parser->device); zgeneric_set_default_dev_context(_obj->data._i); /* set the reference flag this is so that retrieved values of xml to be freed */ if(!zgenerics_get_ref_flg(_obj->data._c)) { zgenerics_toggle_ref_flg(_obj->data._c); } _child = xmlFirstElementChild(node); while(_child) { _content = xmlNodeGetContent(_child); if(_content != NULL) _dim_dbl = atof((char*) _content); if(strcmp((const char*) _child->name, ZPARSER_COORD_X) == 0) zbase_set_base_coords_x(Z_BASE(_obj->data._i), _dim_dbl); else if(strcmp((const char*) _child->name, ZPARSER_COORD_Y) == 0) zbase_set_base_coords_y(Z_BASE(_obj->data._i), _dim_dbl); else if(strcmp((const char*) _child->name, ZPARSER_ROW_HEIGHT_ATTRIB) == 0) zbase_set_height(Z_BASE(_obj->data._i), _dim_dbl); else if(strcmp((const char*) _child->name, ZPARSER_COLUMN_WIDTH_ATTRIB) == 0) zbase_set_width(Z_BASE(_obj->data._i), _dim_dbl); else if(strcmp((const char*) _child->name, ZPARSER_TABLE_ROWS) == 0 && _rows == NULL) _rows = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_TABLE_COLUMNS) == 0 && _cols == NULL) _cols = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_TABLE_COLUMN) == 0) _create_table_object_dim(_child, _obj->data._i); else if(strcmp((const char*) _child->name, ZPARSER_CONTENT) == 0) _create_table_object_content(_child, _content, _obj->data._i); /* set numbeer of rows and columns */ if(_cols && _rows) { _num_rows = atoi((char*) _rows); _num_cols = atoi((char*) _cols); ztable_set_rows_and_cols(Z_TABLE(_obj->data._i), _num_rows, _num_cols); xmlFree(_rows); xmlFree(_cols); _cols = NULL; _rows = NULL; } /* free copy */ if(_content) xmlFree(_content); _content = NULL; _child = xmlNextElementSibling(_child); } /* call draw method */ zgeneric_draw(_obj->data._i); /* push to the collection */ blist_add_from_end(&parser->object_array, (void*) _obj); return ZELIA_OK; }
/* * Construct an iCalendar component from a XML element. */ static icalcomponent *xml_element_to_icalcomponent(xmlNodePtr xcomp) { icalcomponent_kind kind; icalcomponent *comp = NULL; xmlNodePtr node, xprop, xsub; if (!xcomp) return NULL; /* Get component type */ kind = icalenum_string_to_component_kind( ucase(icalmemory_tmp_copy((const char *) xcomp->name))); if (kind == ICAL_NO_COMPONENT) { syslog(LOG_WARNING, "Unknown xCal component type: %s", xcomp->name); return NULL; } /* Create new component */ comp = icalcomponent_new(kind); if (!comp) { syslog(LOG_ERR, "Creation of new %s component failed", xcomp->name); return NULL; } /* Add properties */ node = xmlFirstElementChild(xcomp); if (!node || xmlStrcmp(node->name, BAD_CAST "properties")) { syslog(LOG_WARNING, "Expected <properties> XML element, received %s", node->name); goto error; } for (xprop = xmlFirstElementChild(node); xprop; xprop = xmlNextElementSibling(xprop)) { icalproperty *prop = xml_element_to_icalproperty(xprop); if (!prop) goto error; icalcomponent_add_property(comp, prop); } /* Add sub-components */ if (!(node = xmlNextElementSibling(node))) return comp; if (xmlStrcmp(node->name, BAD_CAST "components")) { syslog(LOG_WARNING, "Expected <components> XML element, received %s", node->name); goto error; } for (xsub = xmlFirstElementChild(node); xsub; xsub = xmlNextElementSibling(xsub)) { icalcomponent *sub = xml_element_to_icalcomponent(xsub); if (!sub) goto error; icalcomponent_add_component(comp, sub); } /* Sanity check */ if ((node = xmlNextElementSibling(node))) { syslog(LOG_WARNING, "Unexpected XML element in component: %s", node->name); goto error; } return comp; error: icalcomponent_free(comp); return NULL; }
int xml_verify(char *filename) { xmlSecDSigCtxPtr dsig_ctx = NULL; xmlDocPtr doc = NULL; xmlNodePtr root_node; xmlNodePtr sign_node; xmlNodePtr cert_node; xmlNodePtr x509d_node; xmlNodePtr cur_node; int result = DCP_FATAL; xmlSecKeysMngrPtr key_manager; char cert[5000]; int cert_l; xmlsec_verify_init(); /* load doc file */ doc = xmlParseFile(filename); if (doc == NULL) { dcp_log(LOG_ERROR, "unable to parse file %s", filename); goto done; } /* find root node */ root_node = xmlDocGetRootElement(doc); if (root_node == NULL){ dcp_log(LOG_ERROR, "unable to find root node"); goto done; } /* find signature node */ sign_node = xmlSecFindNode(root_node, xmlSecNodeSignature, xmlSecDSigNs); if(sign_node == NULL) { dcp_log(LOG_ERROR, "signature node not found"); goto done; } /* create keys manager */ key_manager = load_certificates(); if (key_manager == NULL) { dcp_log(LOG_ERROR,"create key manager failed"); goto done; } /* find certificates */ cur_node = sign_node; while (x509d_node = xmlSecFindNode(cur_node, xmlSecNodeX509Data, xmlSecDSigNs)) { cert_node = xmlSecFindNode(x509d_node, xmlSecNodeX509Certificate, xmlSecDSigNs); if(cert_node == NULL) { dcp_log(LOG_ERROR, "X509certficate node not found"); goto done; } sprintf(cert,"-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----\n",xmlNodeGetContent(cert_node)); cert_l = strlen(cert); if (xmlSecCryptoAppKeysMngrCertLoadMemory(key_manager, cert, cert_l, xmlSecKeyDataFormatPem, xmlSecKeyDataTypeTrusted) < 0) { dcp_log(LOG_ERROR, "could read X509certificate node value"); goto done; } cur_node = xmlNextElementSibling(x509d_node); } /* create signature context */ dsig_ctx = xmlSecDSigCtxCreate(key_manager); if (dsig_ctx == NULL) { dcp_log(LOG_ERROR,"create signature opendcp failed"); goto done; } /* sign the template */ if (xmlSecDSigCtxVerify(dsig_ctx, sign_node) < 0) { dcp_log(LOG_ERROR,"signature verify failed"); goto done; } if (dsig_ctx->status != xmlSecDSigStatusSucceeded) { dcp_log(LOG_ERROR,"signature validation failed"); goto done; } /* success */ result = 0; done: /* destroy keys manager */ xmlSecKeysMngrDestroy(key_manager); /* destroy signature context */ if(dsig_ctx != NULL) { xmlSecDSigCtxDestroy(dsig_ctx); } /* destroy xml doc */ if(doc != NULL) { xmlFreeDoc(doc); } xmlsec_close(); return(result); }
/* * Construct an iCalendar property value from XML content. */ static icalvalue *xml_element_to_icalvalue(xmlNodePtr xtype, icalvalue_kind kind) { icalvalue *value = NULL; xmlNodePtr node; xmlChar *content = NULL; switch (kind) { case ICAL_GEO_VALUE: { struct icalgeotype geo; node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <latitude> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "latitude")) { syslog(LOG_WARNING, "Expected <latitude> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); geo.lat = atof((const char *) content); node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <longitude> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "longitude")) { syslog(LOG_WARNING, "Expected <longitude> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); geo.lon = atof((const char *) content); value = icalvalue_new_geo(geo); break; } case ICAL_PERIOD_VALUE: { struct icalperiodtype p; p.start = p.end = icaltime_null_time(); p.duration = icaldurationtype_from_int(0); node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <start> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "start")) { syslog(LOG_WARNING, "Expected <start> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); p.start = icaltime_from_string((const char *) content); if (icaltime_is_null_time(p.start)) break; node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <end> / <duration> XML element"); break; } else if (!xmlStrcmp(node->name, BAD_CAST "end")) { xmlFree(content); content = xmlNodeGetContent(node); p.end = icaltime_from_string((const char *) content); if (icaltime_is_null_time(p.end)) break; } else if (!xmlStrcmp(node->name, BAD_CAST "duration")) { xmlFree(content); content = xmlNodeGetContent(node); p.duration = icaldurationtype_from_string((const char *) content); if (icaldurationtype_as_int(p.duration) == 0) break; } else { syslog(LOG_WARNING, "Expected <end> / <duration> XML element, received %s", node->name); break; } value = icalvalue_new_period(p); break; } case ICAL_RECUR_VALUE: { struct buf rrule = BUF_INITIALIZER; struct hash_table byrules; struct icalrecurrencetype rt; char *sep = ""; construct_hash_table(&byrules, 10, 1); /* create an iCal RRULE string from xCal <recur> sub-elements */ for (node = xmlFirstElementChild(xtype); node; node = xmlNextElementSibling(node)) { content = xmlNodeGetContent(node); if (!xmlStrncmp(node->name, BAD_CAST "by", 2)) { /* BY* rules can have a list of values - assemble them using a hash table */ struct buf *vals = hash_lookup((const char *) node->name, &byrules); if (vals) { /* append this value to existing list */ buf_printf(vals, ",%s", (char *) content); } else { /* create new list with this valiue */ vals = xzmalloc(sizeof(struct buf)); buf_setcstr(vals, (char *) content); hash_insert((char *) node->name, vals, &byrules); } } else { /* single value rpart */ buf_printf(&rrule, "%s%s=%s", sep, ucase((char *) node->name), (char *) content); sep = ";"; } xmlFree(content); content = NULL; } /* append the BY* rules to RRULE buffer */ hash_enumerate(&byrules, (void (*)(const char*, void*, void*)) &append_byrule, &rrule); free_hash_table(&byrules, NULL); /* parse our iCal RRULE string */ rt = icalrecurrencetype_from_string(buf_cstring(&rrule)); buf_free(&rrule); if (rt.freq != ICAL_NO_RECURRENCE) value = icalvalue_new_recur(rt); break; } case ICAL_REQUESTSTATUS_VALUE: { struct icalreqstattype rst = { ICAL_UNKNOWN_STATUS, NULL, NULL }; short maj, min; node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <code> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "code")) { syslog(LOG_WARNING, "Expected <code> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); if (sscanf((const char *) content, "%hd.%hd", &maj, &min) == 2) { rst.code = icalenum_num_to_reqstat(maj, min); } if (rst.code == ICAL_UNKNOWN_STATUS) { syslog(LOG_WARNING, "Unknown request-status code"); break; } node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <description> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "description")) { syslog(LOG_WARNING, "Expected <description> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); rst.desc = (const char *) content; node = xmlNextElementSibling(node); if (node) { if (xmlStrcmp(node->name, BAD_CAST "data")) { syslog(LOG_WARNING, "Expected <data> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); rst.debug = (const char *) content; } value = icalvalue_new_requeststatus(rst); break; } case ICAL_UTCOFFSET_VALUE: { int n, utcoffset, hours, minutes, seconds = 0; char sign; content = xmlNodeGetContent(xtype); n = sscanf((const char *) content, "%c%02d:%02d:%02d", &sign, &hours, &minutes, &seconds); if (n < 3) { syslog(LOG_WARNING, "Unexpected utc-offset format"); break; } utcoffset = hours*3600 + minutes*60 + seconds; if (sign == '-') utcoffset = -utcoffset; value = icalvalue_new_utcoffset(utcoffset); break; } default: content = xmlNodeGetContent(xtype); value = icalvalue_new_from_string(kind, (const char *) content); break; } if (content) xmlFree(content); return value; }
/* * Construct an iCalendar property from a XML element. */ static icalproperty *xml_element_to_icalproperty(xmlNodePtr xprop) { const char *propname, *typestr; icalproperty_kind kind; icalproperty *prop = NULL; icalvalue_kind valkind; icalvalue *value; xmlNodePtr node; /* Get the property type */ propname = ucase(icalmemory_tmp_copy((const char *) xprop->name)); kind = icalenum_string_to_property_kind(propname); if (kind == ICAL_NO_PROPERTY) { syslog(LOG_WARNING, "Unknown xCal property type: %s", propname); return NULL; } /* Create new property */ prop = icalproperty_new(kind); if (!prop) { syslog(LOG_ERR, "Creation of new %s property failed", propname); return NULL; } if (kind == ICAL_X_PROPERTY) icalproperty_set_x_name(prop, propname); /* Add parameters */ node = xmlFirstElementChild(xprop); if (node && !xmlStrcmp(node->name, BAD_CAST "parameters")) { xmlNodePtr xparam; for (xparam = xmlFirstElementChild(node); xparam; xparam = xmlNextElementSibling(xparam)) { char *paramname = ucase(icalmemory_tmp_copy((const char *) xparam->name)); xmlChar *paramval = xmlNodeGetContent(xmlFirstElementChild(xparam)); /* XXX Need to handle multi-valued parameters */ icalproperty_set_parameter_from_string(prop, paramname, (const char *) paramval); xmlFree(paramval); } node = xmlNextElementSibling(node); } /* Get the value type */ if (!node) { syslog(LOG_WARNING, "Missing xCal value for %s property", propname); return NULL; } typestr = ucase(icalmemory_tmp_copy((const char *) node->name)); valkind = !strcmp(typestr, "UNKNOWN") ? ICAL_X_VALUE : icalenum_string_to_value_kind(typestr); if (valkind == ICAL_NO_VALUE) { syslog(LOG_WARNING, "Unknown xCal value type for %s property: %s", propname, typestr); return NULL; } else if (valkind == ICAL_TEXT_VALUE) { /* "text" also includes enumerated types - grab type from property */ valkind = icalproperty_kind_to_value_kind(kind); } /* Add value */ switch (kind) { case ICAL_CATEGORIES_PROPERTY: case ICAL_RESOURCES_PROPERTY: case ICAL_POLLPROPERTIES_PROPERTY: if (valkind == ICAL_TEXT_VALUE) { /* Handle multi-valued properties */ struct buf buf = BUF_INITIALIZER; xmlChar *content = NULL; content = xmlNodeGetContent(node); buf_setcstr(&buf, (const char *) content); free(content); while ((node = xmlNextElementSibling(node))) { buf_putc(&buf, ','); content = xmlNodeGetContent(node); buf_appendcstr(&buf, (const char *) content); free(content); } value = icalvalue_new_from_string(valkind, buf_cstring(&buf)); buf_free(&buf); break; } default: value = xml_element_to_icalvalue(node, valkind); if (!value) { syslog(LOG_ERR, "Parsing %s property value failed", propname); goto error; } } icalproperty_set_value(prop, value); /* Sanity check */ if ((node = xmlNextElementSibling(node))) { syslog(LOG_WARNING, "Unexpected XML element in property: %s", node->name); goto error; } return prop; error: icalproperty_free(prop); return NULL; }
int main(int argc, char **argv) { int opt, r = 0; char *alt_config = NULL, *pub = NULL, *ver = NULL, *winfile = NULL; char prefix[2048]; enum { REBUILD, WINZONES, NONE } op = NONE; if ((geteuid()) == 0 && (become_cyrus(/*ismaster*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:r:vw:")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'r': if (op == NONE) { op = REBUILD; pub = optarg; ver = strchr(optarg, ':'); if (ver) *ver++ = '\0'; else usage(); } else usage(); break; case 'v': verbose = 1; break; case 'w': if (op == NONE) { op = WINZONES; winfile = optarg; } else usage(); break; default: usage(); } } cyrus_init(alt_config, "ctl_zoneinfo", 0, 0); signals_set_shutdown(&shut_down); signals_add_handlers(0); snprintf(prefix, sizeof(prefix), "%s%s", config_dir, FNAME_ZONEINFODIR); switch (op) { case REBUILD: { struct hash_table tzentries; struct zoneinfo *info; struct txn *tid = NULL; char buf[1024]; FILE *fp; construct_hash_table(&tzentries, 500, 1); /* Add INFO record (overall lastmod and TZ DB source version) */ info = xzmalloc(sizeof(struct zoneinfo)); info->type = ZI_INFO; appendstrlist(&info->data, pub); appendstrlist(&info->data, ver); hash_insert(INFO_TZID, info, &tzentries); /* Add LEAP record (last updated and hash) */ snprintf(buf, sizeof(buf), "%s%s", prefix, FNAME_LEAPSECFILE); if (verbose) printf("Processing leap seconds file %s\n", buf); if (!(fp = fopen(buf, "r"))) { fprintf(stderr, "Could not open leap seconds file %s\n", buf); } else { struct zoneinfo *leap = xzmalloc(sizeof(struct zoneinfo)); leap->type = ZI_INFO; while(fgets(buf, sizeof(buf), fp)) { if (buf[0] == '#') { /* comment line */ if (buf[1] == '$') { /* last updated */ unsigned long last; sscanf(buf+2, "\t%lu", &last); leap->dtstamp = last - NIST_EPOCH_OFFSET; } else if (buf[1] == 'h') { /* hash */ char *p, *hash = buf+3 /* skip "#h\t" */; /* trim trailing whitespace */ for (p = hash + strlen(hash); isspace(*--p); *p = '\0'); appendstrlist(&leap->data, hash); } } } fclose(fp); hash_insert(LEAP_TZID, leap, &tzentries); info->dtstamp = leap->dtstamp; } /* Add ZONE/LINK records */ do_zonedir(prefix, &tzentries, info); zoneinfo_open(NULL); /* Store records */ hash_enumerate(&tzentries, &store_zoneinfo, &tid); zoneinfo_close(tid); free_hash_table(&tzentries, &free_zoneinfo); break; } case WINZONES: { xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr node; struct buf tzidbuf = BUF_INITIALIZER; struct buf aliasbuf = BUF_INITIALIZER; if (verbose) printf("Processing Windows Zone file %s\n", winfile); /* Parse the XML file */ ctxt = xmlNewParserCtxt(); if (!ctxt) { fprintf(stderr, "Failed to create XML parser context\n"); break; } doc = xmlCtxtReadFile(ctxt, winfile, NULL, 0); xmlFreeParserCtxt(ctxt); if (!doc) { fprintf(stderr, "Failed to parse XML document\n"); break; } node = xmlDocGetRootElement(doc); if (!node || xmlStrcmp(node->name, BAD_CAST "supplementalData")) { fprintf(stderr, "Incorrect root node\n"); goto done; } for (node = xmlFirstElementChild(node); node && xmlStrcmp(node->name, BAD_CAST "windowsZones"); node = xmlNextElementSibling(node)); if (!node) { fprintf(stderr, "Missing windowsZones node\n"); goto done; } node = xmlFirstElementChild(node); if (!node || xmlStrcmp(node->name, BAD_CAST "mapTimezones")) { fprintf(stderr, "Missing mapTimezones node\n"); goto done; } if (chdir(prefix)) { fprintf(stderr, "chdir(%s) failed\n", prefix); goto done; } for (node = xmlFirstElementChild(node); node; node = xmlNextElementSibling(node)) { if (!xmlStrcmp(node->name, BAD_CAST "mapZone") && !xmlStrcmp(xmlGetProp(node, BAD_CAST "territory"), BAD_CAST "001")) { const char *tzid, *alias; buf_setcstr(&tzidbuf, (const char *) xmlGetProp(node, BAD_CAST "type")); buf_appendcstr(&tzidbuf, ".ics"); tzid = buf_cstring(&tzidbuf); buf_setcstr(&aliasbuf, (const char *) xmlGetProp(node, BAD_CAST "other")); buf_appendcstr(&aliasbuf, ".ics"); alias = buf_cstring(&aliasbuf); if (verbose) printf("\tLINK: %s -> %s\n", alias, tzid); if (symlink(tzid, alias)) { if (errno == EEXIST) { struct stat sbuf; if (stat(alias, &sbuf)) { fprintf(stderr, "stat(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (sbuf.st_mode & S_IFLNK) { char link[MAX_MAILBOX_PATH+1]; int n = readlink(alias, link, MAX_MAILBOX_PATH); if (n == -1) { fprintf(stderr, "readlink(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (n == (int) strlen(tzid) && !strncmp(tzid, link, n)) { errno = 0; } } } if (errno) { fprintf(stderr, "symlink(%s, %s) failed: %s\n", tzid, alias, strerror(errno)); } } } } done: buf_free(&aliasbuf); buf_free(&tzidbuf); xmlFreeDoc(doc); break; } case NONE: r = 2; usage(); break; } cyrus_done(); return r; }
void SSDPParser::parseServiceList( xmlDocPtr doc, const xmlChar* ns, const xmlChar* udn, xmlNodeSetPtr serviceNodeSet, xmlBufferPtr configBuf) { int i; for (i = 0; i < serviceNodeSet->nodeNr; i++) { xmlNodePtr serviceNode = serviceNodeSet->nodeTab[i]; xmlNodePtr childNode = serviceNode->xmlChildrenNode; xmlNodePtr next = childNode; char* serviceType = 0; char* serviceId = 0; char* controlURL = 0; char* eventSubURL = 0; /* check namespace */ if (strcmp((const char*)serviceNode->ns->href, (const char*)ns)) continue; while (next) { char* value = (char*)xmlNodeListGetString(doc, next->xmlChildrenNode, 1); bool found = false; if (!strcmp((const char*)next->name, "serviceType")) { serviceType = value; found = true; } else if (!strcmp((const char*)next->name, "serviceId")) { serviceId = value; found = true; } else if (!strcmp((const char*)next->name, "controlURL")) { controlURL = value; found = true; } else if (!strcmp((const char*)next->name, "eventSubURL")) { eventSubURL = value; found = true; } if (!found) xmlFree(value); next = xmlNextElementSibling(next); } if (udn && serviceId && serviceType && controlURL) addService((const char*)udn, serviceId, serviceType, controlURL, (const char*)configBuf->content, eventSubURL); else LOG_ERROR("resolve failed for service id %s", serviceId); if (serviceType) xmlFree(serviceType); if (serviceId) xmlFree(serviceId); if (controlURL) xmlFree(controlURL); if (eventSubURL) xmlFree(eventSubURL); } }
inline __attribute__ ((always_inline)) static int _create_jb_object_helper(xmlNodePtr node, void* object) { xmlChar *_xs = NULL; xmlChar *_ys = NULL; xmlChar *_widths = NULL; xmlChar *_heights = NULL; xmlChar *_depths = NULL; xmlChar *_angles = NULL; xmlChar *_radiuss = NULL; double _x = 0.0, _y = 0.0, _width = 0.0, _height = 0.0, _depth = 0.0, _angle = 0.0, _radius = 0.0; double* _ptr = (double*) object; xmlNodePtr _child = NULL; _child = node; while(_child) { if(strcmp((const char*) _child->name, ZPARSER_COORD_X) == 0) _xs = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_COORD_Y) == 0) _ys = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_COLUMN_WIDTH_ATTRIB) == 0) _widths = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_ROW_HEIGHT_ATTRIB) == 0) _heights = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_DEPTH) == 0) _depths = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_RADIUS) == 0) _radiuss = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_ANGLE) == 0) _angles = xmlNodeGetContent(_child); /* if all variables are set we exit loop here, otherwise continue looking */ if(_xs && _ys && _widths && _heights && _depths && _radiuss && _angles) break; _child = xmlNextElementSibling(_child); } /* convert the variables and free the buffers */ if(_xs) { _x = atof((const char*) _xs); xmlFree(_xs); } if(_ys) { _y = atof((const char*) _ys); xmlFree(_ys); } if(_widths) { _width = atof((const char*) _widths); xmlFree(_widths); } if(_heights) { _height = atof((const char*) _heights); xmlFree(_heights); } if(_depths) { _depth = atof((const char*) _depths); xmlFree(_depths); } if(_radiuss) { _radius = atof((const char*) _radiuss); xmlFree(_radiuss); } if(_angles) { _angle = atof((const char*) _angles); xmlFree(_angles); } *_ptr = _x; _ptr++; *_ptr = _y; _ptr++; *_ptr = _width; _ptr++; *_ptr = _height; _ptr++; *_ptr = _depth; _ptr++; *_ptr = _radius; _ptr++; *_ptr = _angle; return ZELIA_OK; }
inline __attribute__ ((always_inline)) static int _create_jb_object_gland_helper(xmlNodePtr node, zgeneric* object) { xmlChar *_xs = NULL; xmlChar *_ys = NULL; xmlChar *_szs = NULL; xmlChar *_hexs = NULL; double _x = 0.0, _y = 0.0; zGlandSize _sz = zM16; int _hex = 0; xmlNodePtr _child = NULL; _child = xmlFirstElementChild(node); while(_child) { if(strcmp((const char*) _child->name, ZPARSER_COORD_X) == 0) _xs = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_COORD_Y) == 0) _ys = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_SIZE) == 0) _szs = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_HEX_FLG) == 0) _hexs = xmlNodeGetContent(_child); /* break if all interested variables are set */ if(_xs && _ys && _szs && _hexs) break; _child = xmlNextElementSibling(_child); } if(_xs) { _x = atof((const char*) _xs); xmlFree(_xs); } if(_ys) { _y = atof((const char*) _ys); xmlFree(_ys); } if(_szs) { if(strcmp((const char*) _szs, ZPARSER_GLAND_SZ_M16) == 0) _sz = zM16; else if(strcmp((const char*) _szs, ZPARSER_GLAND_SZ_M20) == 0) _sz = zM20; else _sz = zM25; xmlFree(_szs); } if(_hexs) { _hex = atoi((const char*) _hexs); xmlFree(_hexs); } /* add glands */ zjb_add_glands(Z_JB(object), _x, _y, _sz, _hex); return ZELIA_OK; }
inline __attribute__ ((always_inline)) static int _create_jb_object_terminals_helper(xmlNodePtr node, zgeneric* object) { xmlChar* _nums = NULL, *_widths = NULL, *_heights = NULL, *_links = NULL, *_enums = NULL; xmlChar* _annot = NULL; int _num = 0, _enum = 0; double _width = 0.0, _height = 0.0; xmlNodePtr _child = NULL; _child = xmlFirstElementChild(node); while(_child) { if(strcmp((const char*) _child->name, ZPARSER_TERMINALS_NUM) == 0) _nums = xmlNodeGetContent(_child); if(strcmp((const char*) _child->name, ZPARSER_ETERMINALS_NUM) == 0) _enums = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_COLUMN_WIDTH_ATTRIB) == 0) _widths = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_ROW_HEIGHT_ATTRIB) == 0) _heights = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_TERMINALS_LINKS) == 0) _links = xmlNodeGetContent(_child); else if(strcmp((const char*) _child->name, ZPARSER_TERMINAL_ANNOT) == 0) _annot = xmlNodeGetContent(_child); /* break from loop if we have obtained every thing */ if(_nums && _widths && _heights && _links) break; _child = xmlNextElementSibling(_child); } if(_nums) { _num = atoi((const char*) _nums); xmlFree(_nums); } if(_enums) { _enum = atoi((const char*) _enums); xmlFree(_enums); } if(_widths) { _width = atof((const char*) _widths); xmlFree(_widths); } if(_heights) { _height = atof((const char*) _heights); xmlFree(_heights); } /* check links pointer and add terminals */ zjb_add_with_earth_terminals(Z_JB(object), _num, _enum, _width, _height, _annot? (const char*) _annot : NULL, _links? (const char*) _links : NULL); if(_links) xmlFree(_links); if(_annot) xmlFree(_annot); return ZELIA_OK; }