std::string parse(const std::string& xml, const std::string& name, const std::string& url, const std::string& html, const std::string& htmlheader, std::vector<std::pair<std::string, std::string> >& attaches) { std::string ret(""); std::string pp = getParserPath(url); xsltStylesheetPtr xslt = xsltParseStylesheetFile(BAD_CAST pp.c_str()); htmlDocPtr doc = NULL; static std::string encoding("gb18030"); std::string mimetype = getMIMEType(htmlheader, html); if (!mimetype.empty() && mimetype == "text/xml") { doc = html.empty() ? NULL : xmlReadDoc(BAD_CAST html.c_str(), NULL, encoding.c_str(), XML_PARSE_RECOVER); } else { doc = html.empty() ? NULL : htmlParseDoc(BAD_CAST html.c_str(), encoding.c_str()); } if (doc != NULL) { const char *params[7] = {0}; size_t n_param = 0; params[n_param] = NULL; xmlDocPtr res = xsltApplyStylesheet(xslt, doc, params); //free_xslt_params(params, n_param); if (res != NULL) { xmlChar *s = NULL; int len = 0; if (xsltSaveResultToString(&s, &len, res, xslt) >= 0) { ret.assign((const char *)s, len); xmlFree(s); } xmlFreeDoc(res); } xmlFreeDoc(doc); } return ret; }
TextXmlParser::TextXmlParser(const char * xml) { xmlDoc_ = xmlReadDoc((xmlChar *) xml, NULL, NULL, 0); assert(xmlDoc_ != NULL); xpathCtx_ = xmlXPathNewContext(xmlDoc_); assert(xpathCtx_ != NULL); }
bool XMLWrapper::readXML(const char *xml) { cleanup(); mDocument = xmlReadDoc(BAD_CAST xml, "", NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_COMPACT | XML_PARSE_NOENT | XML_PARSE_NOCDATA); if (mDocument) { return true; } return false; }
bool cXmlDoc::read(const xmlChar* cur, const char* URL, const char* encoding, int options) { // DeInit(); #ifdef DUMP fprintf(stderr, "cXmlDoc::read (xmlChar)\n"); fflush(stderr); #endif Init(); claimErrors(); assignDoc(xmlReadDoc(cur, URL, encoding, options)); releaseErrors(); return ok(); }
static int init_state(struct xml_state *st, const char *xml) { memset(st, 0, sizeof(*st)); st->xml_doc = xmlReadDoc((const xmlChar *)xml, NULL, NULL, XML_PARSE_NONET); if (st->xml_doc == NULL) { return -1; } st->xpath_ctx = xmlXPathNewContext(st->xml_doc); if (st->xpath_ctx == NULL) { return -1; } return 0; }
static int parse_ticket_state(struct ticket_config *tk, FILE *p) { int rv = 0; GString *input = NULL; char line[CHUNK_SIZE]; xmlDocPtr doc = NULL; xmlErrorPtr errptr; int opts = XML_PARSE_COMPACT | XML_PARSE_NONET; /* skip first two lines of output */ if (fgets(line, CHUNK_SIZE-1, p) == NULL || fgets(line, CHUNK_SIZE-1, p) == NULL) { tk_log_error("crm_ticket xml output empty"); rv = ENODATA; goto out; } input = g_string_sized_new(CHUNK_SIZE); if (!input) { log_error("out of memory"); rv = -1; goto out; } while (fgets(line, CHUNK_SIZE-1, p) != NULL) { if (!g_string_append(input, line)) { log_error("out of memory"); rv = -1; goto out; } } doc = xmlReadDoc((const xmlChar *) input->str, NULL, NULL, opts); if (doc == NULL) { errptr = xmlGetLastError(); if (errptr) { tk_log_error("crm_ticket xml parse failed (domain=%d, level=%d, code=%d): %s", errptr->domain, errptr->level, errptr->code, errptr->message); } else { tk_log_error("crm_ticket xml parse failed"); } rv = -EINVAL; goto out; } rv = save_attributes(tk, doc); out: if (doc) xmlFreeDoc(doc); if (input) g_string_free(input, TRUE); return rv; }
int xml2lpc_set_xsd_string(xml2lpc_context* xmlCtx, const char *content) { xml2lpc_context_clear_logs(xmlCtx); xmlSetGenericErrorFunc(xmlCtx, xml2lpc_genericxml_error); if(xmlCtx->xsd != NULL) { xmlFreeDoc(xmlCtx->xsd); xmlCtx->xsd = NULL; } xmlCtx->xsd = xmlReadDoc((const unsigned char*)content, 0, NULL, 0); if(xmlCtx->xsd == NULL) { xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Can't parse string"); xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer); return -1; } return 0; }
static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList *list, const LinphoneContent *body, const char *first_part_body) { xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new(); xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error); xml_ctx->doc = xmlReadDoc((const unsigned char*)first_part_body, 0, NULL, 0); if (xml_ctx->doc != NULL) { char xpath_str[MAX_XPATH_LENGTH]; LinphoneFriend *friend; LinphoneContent *presence_part; xmlXPathObjectPtr resource_object; const char *version_str = NULL; const char *full_state_str = NULL; const char *uri = NULL; bool_t full_state = FALSE; int version; int i; if (linphone_create_xml_xpath_context(xml_ctx) < 0) goto end; xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar *)"rlmi", (const xmlChar *)"urn:ietf:params:xml:ns:rlmi"); version_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "version"); if (version_str == NULL) { ms_warning("rlmi+xml: No version attribute in list"); goto end; } version = atoi(version_str); linphone_free_xml_text_content(version_str); if (version < list->expected_notification_version) { ms_warning("rlmi+xml: Discarding received notification with version %d because %d was expected", version, list->expected_notification_version); linphone_friend_list_update_subscriptions(list, NULL, FALSE); /* Refresh subscription to get new full state notify. */ goto end; } full_state_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "fullState"); if (full_state_str == NULL) { ms_warning("rlmi+xml: No fullState attribute in list"); goto end; } if ((strcmp(full_state_str, "true") == 0) || (strcmp(full_state_str, "1") == 0)) { MSList *l = list->friends; for (; l != NULL; l = l->next) { friend = (LinphoneFriend *)l->data; linphone_friend_set_presence_model(friend, NULL); } full_state = TRUE; }
xmlNode* get_account_data(xmlNode* node){ // Expects <li> xmlChar* account = NULL; if(xmlStrcmp(node->name, BAD_CAST "li") == 0) { node = node->children; if(xmlStrcmp(node->name, BAD_CAST "stringvalue") == 0) { node = node->children; if(node && node->content) account = node->content; } } if(account) { node = xmlDocGetRootElement(xmlReadDoc(account, NULL, NULL, XML_PARSE_NOBLANKS)); } return node; }
struct babel_info *load_babel_info_from_blorb(z_file *infile, int length, char *filename, time_t last_mod_timestamp) { struct babel_info *result; char *xmlData = (char*)fizmo_malloc(length + 1); xmlDocPtr babel_doc; if (fsi->readchars(xmlData, length, infile) != (size_t)length) { free(xmlData); return NULL; } xmlData[length] = '\0'; babel_doc = xmlReadDoc( (xmlChar*)xmlData, NULL, NULL, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); free(xmlData); if (babel_doc == NULL) return NULL; result = (struct babel_info*)fizmo_malloc(sizeof(struct babel_info)); result->entries = NULL; result->entries_allocated = 0; result->nof_entries = 0; if (add_doc_to_babel_info(babel_doc, result, last_mod_timestamp, filename) != 0) { xmlFreeDoc(babel_doc); free(result); return NULL; } return result; }
static void parse_valid_xml_rpc_response(LinphoneXmlRpcRequest *request, const char *response_body) { xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new(); xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error); request->status = LinphoneXmlRpcStatusFailed; xml_ctx->doc = xmlReadDoc((const unsigned char*)response_body, 0, NULL, 0); if (xml_ctx->doc != NULL) { const char *response_str = NULL; if (linphone_create_xml_xpath_context(xml_ctx) < 0) goto end; switch (request->response.type) { case LinphoneXmlRpcArgInt: response_str = linphone_get_xml_text_content(xml_ctx, "/methodResponse/params/param/value/int"); if (response_str != NULL) { request->response.data.i = atoi(response_str); request->status = LinphoneXmlRpcStatusOk; } break; case LinphoneXmlRpcArgString: response_str = linphone_get_xml_text_content(xml_ctx, "/methodResponse/params/param/value/string"); if (response_str != NULL) { request->response.data.s = belle_sip_strdup(response_str); request->status = LinphoneXmlRpcStatusOk; } break; default: break; } if (response_str) linphone_free_xml_text_content(response_str); } else { ms_warning("Wrongly formatted XML-RPC response: %s", xml_ctx->errorBuffer); } end: linphone_xmlparsing_context_destroy(xml_ctx); if (request->callbacks->response != NULL) { request->callbacks->response(request); } }
static int refresh_lists (void) { int n; n = virConnectNumOfDomains (conn); if (n < 0) { VIRT_ERROR (conn, "reading number of domains"); return -1; } if (n > 0) { int i; int *domids; /* Get list of domains. */ domids = malloc (sizeof (*domids) * n); if (domids == NULL) { ERROR (PLUGIN_NAME " plugin: malloc failed."); return -1; } n = virConnectListDomains (conn, domids, n); if (n < 0) { VIRT_ERROR (conn, "reading list of domains"); sfree (domids); return -1; } free_block_devices (); free_interface_devices (); free_domains (); /* Fetch each domain and add it to the list, unless ignore. */ for (i = 0; i < n; ++i) { virDomainPtr dom = NULL; const char *name; char *xml = NULL; xmlDocPtr xml_doc = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr xpath_obj = NULL; int j; dom = virDomainLookupByID (conn, domids[i]); if (dom == NULL) { VIRT_ERROR (conn, "virDomainLookupByID"); /* Could be that the domain went away -- ignore it anyway. */ continue; } name = virDomainGetName (dom); if (name == NULL) { VIRT_ERROR (conn, "virDomainGetName"); goto cont; } if (il_domains && ignorelist_match (il_domains, name) != 0) goto cont; if (add_domain (dom) < 0) { ERROR (PLUGIN_NAME " plugin: malloc failed."); goto cont; } /* Get a list of devices for this domain. */ xml = virDomainGetXMLDesc (dom, 0); if (!xml) { VIRT_ERROR (conn, "virDomainGetXMLDesc"); goto cont; } /* Yuck, XML. Parse out the devices. */ xml_doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET); if (xml_doc == NULL) { VIRT_ERROR (conn, "xmlReadDoc"); goto cont; } xpath_ctx = xmlXPathNewContext (xml_doc); /* Block devices. */ xpath_obj = xmlXPathEval ((xmlChar *) "/domain/devices/disk/target[@dev]", xpath_ctx); if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) goto cont; for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) { xmlNodePtr node; char *path = NULL; node = xpath_obj->nodesetval->nodeTab[j]; if (!node) continue; path = (char *) xmlGetProp (node, (xmlChar *) "dev"); if (!path) continue; if (il_block_devices && ignore_device_match (il_block_devices, name, path) != 0) goto cont2; add_block_device (dom, path); cont2: if (path) xmlFree (path); } xmlXPathFreeObject (xpath_obj); /* Network interfaces. */ xpath_obj = xmlXPathEval ((xmlChar *) "/domain/devices/interface[target[@dev]]", xpath_ctx); if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) goto cont; xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval; for (j = 0; j < xml_interfaces->nodeNr; ++j) { char *path = NULL; char *address = NULL; xmlNodePtr xml_interface; xml_interface = xml_interfaces->nodeTab[j]; if (!xml_interface) continue; xmlNodePtr child = NULL; for (child = xml_interface->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE) continue; if (xmlStrEqual(child->name, (const xmlChar *) "target")) { path = (char *) xmlGetProp (child, (const xmlChar *) "dev"); if (!path) continue; } else if (xmlStrEqual(child->name, (const xmlChar *) "mac")) { address = (char *) xmlGetProp (child, (const xmlChar *) "address"); if (!address) continue; } } if (il_interface_devices && (ignore_device_match (il_interface_devices, name, path) != 0 || ignore_device_match (il_interface_devices, name, address) != 0)) goto cont3; add_interface_device (dom, path, address, j+1); cont3: if (path) xmlFree (path); if (address) xmlFree (address); } cont: if (xpath_obj) xmlXPathFreeObject (xpath_obj); if (xpath_ctx) xmlXPathFreeContext (xpath_ctx); if (xml_doc) xmlFreeDoc (xml_doc); sfree (xml); } sfree (domids); } return 0; }
static inline std::auto_ptr<SystemState> createSystemFromConfig(const char *filename, const XESector *configSector) { uint64_t length = configSector->getLength(); const scoped_array<char> buf(new char[length + 1]); if (!configSector->getData(buf.get())) { std::cerr << "Error reading config from \"" << filename << "\"" << std::endl; std::exit(1); } if (length < 8) { std::cerr << "Error unexpected config config sector length" << std::endl; std::exit(1); } length -= 8; buf[length] = '\0'; /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION xmlDoc *doc = xmlReadDoc((xmlChar*)buf.get(), "config.xml", NULL, 0); xmlRelaxNGParserCtxtPtr schemaContext = xmlRelaxNGNewMemParserCtxt(configSchema, sizeof(configSchema)); xmlRelaxNGPtr schema = xmlRelaxNGParse(schemaContext); xmlRelaxNGValidCtxtPtr validationContext = xmlRelaxNGNewValidCtxt(schema); if (xmlRelaxNGValidateDoc(validationContext, doc) != 0) { std::exit(1); } xmlNode *root = xmlDocGetRootElement(doc); xmlNode *system = findChild(root, "System"); xmlNode *nodes = findChild(system, "Nodes"); std::auto_ptr<SystemState> systemState(new SystemState); std::map<long,Node*> nodeNumberMap; for (xmlNode *child = nodes->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE || strcmp("Node", (char*)child->name) != 0) continue; systemState->addNode(createNodeFromConfig(child, nodeNumberMap)); } xmlNode *connections = findChild(system, "Connections"); for (xmlNode *child = connections->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE || strcmp("SLink", (char*)child->name) != 0) continue; long nodeID1, link1, nodeID2, link2; if (!parseXLinkEnd(findAttribute(child, "end1"), nodeID1, link1)) { std::cerr << "Failed to parse \"end1\" attribute" << std::endl; std::exit(1); } if (!parseXLinkEnd(findAttribute(child, "end2"), nodeID2, link2)) { std::cerr << "Failed to parse \"end2\" attribute" << std::endl; std::exit(1); } Node *node1 = lookupNodeChecked(nodeNumberMap, nodeID1); if (link1 >= node1->getNumXLinks()) { std::cerr << "Invalid sLink number " << link1 << std::endl; std::exit(1); } Node *node2 = lookupNodeChecked(nodeNumberMap, nodeID2); if (link2 >= node2->getNumXLinks()) { std::cerr << "Invalid sLink number " << link2 << std::endl; std::exit(1); } node1->connectXLink(link1, node2, link2); node2->connectXLink(link2, node1, link1); } xmlNode *jtag = findChild(system, "JtagChain"); unsigned jtagIndex = 0; for (xmlNode *child = jtag->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE || strcmp("Node", (char*)child->name) != 0) continue; long nodeID = readNumberAttribute(child, "id"); lookupNodeChecked(nodeNumberMap, nodeID)->setJtagIndex(jtagIndex++); } systemState->finalize(); xmlFreeDoc(doc); xmlCleanupParser(); return systemState; }
static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList *list, const LinphoneContent *body, const char *first_part_body) { xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new(); xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error); xml_ctx->doc = xmlReadDoc((const unsigned char*)first_part_body, 0, NULL, 0); if (xml_ctx->doc != NULL) { char xpath_str[MAX_XPATH_LENGTH]; LinphoneFriend *lf; LinphoneContent *presence_part; xmlXPathObjectPtr resource_object; const char *version_str = NULL; const char *full_state_str = NULL; const char *uri = NULL; bool_t full_state = FALSE; int version; int i; if (linphone_create_xml_xpath_context(xml_ctx) < 0) goto end; xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar *)"rlmi", (const xmlChar *)"urn:ietf:params:xml:ns:rlmi"); version_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "version"); if (version_str == NULL) { ms_warning("rlmi+xml: No version attribute in list"); goto end; } version = atoi(version_str); linphone_free_xml_text_content(version_str); if (version < list->expected_notification_version) { ms_warning("rlmi+xml: Discarding received notification with version %d because %d was expected", version, list->expected_notification_version); linphone_friend_list_update_subscriptions(list, NULL, FALSE); /* Refresh subscription to get new full state notify. */ goto end; } full_state_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "fullState"); if (full_state_str == NULL) { ms_warning("rlmi+xml: No fullState attribute in list"); goto end; } if ((strcmp(full_state_str, "true") == 0) || (strcmp(full_state_str, "1") == 0)) { bctbx_list_t *l = list->friends; for (; l != NULL; l = l->next) { lf = (LinphoneFriend *)l->data; linphone_friend_set_presence_model(lf, NULL); } full_state = TRUE; } linphone_free_xml_text_content(full_state_str); if ((list->expected_notification_version == 0) && (full_state == FALSE)) { ms_warning("rlmi+xml: Notification with version 0 is not full state, this is not valid"); goto end; } list->expected_notification_version = version + 1; resource_object = linphone_get_xml_xpath_object_for_node_list(xml_ctx, "/rlmi:list/rlmi:resource"); if ((resource_object != NULL) && (resource_object->nodesetval != NULL)) { for (i = 1; i <= resource_object->nodesetval->nodeNr; i++) { snprintf(xpath_str, sizeof(xpath_str), "/rlmi:list/rlmi:resource[%i]/@uri", i); uri = linphone_get_xml_text_content(xml_ctx, xpath_str); if (uri == NULL) continue; lf = linphone_friend_list_find_friend_by_uri(list, uri); if (lf != NULL) { const char *state = NULL; snprintf(xpath_str, sizeof(xpath_str),"/rlmi:list/rlmi:resource[%i]/rlmi:instance/@state", i); state = linphone_get_xml_text_content(xml_ctx, xpath_str); if ((state != NULL) && (strcmp(state, "active") == 0)) { const char *cid = NULL; snprintf(xpath_str, sizeof(xpath_str),"/rlmi:list/rlmi:resource[%i]/rlmi:instance/@cid", i); cid = linphone_get_xml_text_content(xml_ctx, xpath_str); if (cid != NULL) { presence_part = linphone_content_find_part_by_header(body, "Content-Id", cid); if (presence_part == NULL) { ms_warning("rlmi+xml: Cannot find part with Content-Id: %s", cid); } else { SalPresenceModel *presence = NULL; linphone_notify_parse_presence(linphone_content_get_type(presence_part), linphone_content_get_subtype(presence_part), linphone_content_get_string_buffer(presence_part), &presence); if (presence != NULL) { lf->presence_received = TRUE; linphone_friend_set_presence_model(lf, (LinphonePresenceModel *)presence); if (full_state == FALSE) { linphone_core_notify_notify_presence_received(list->lc, lf); } } linphone_content_unref(presence_part); } } if (cid != NULL) linphone_free_xml_text_content(cid); } if (state != NULL) linphone_free_xml_text_content(state); lf->subscribe_active = TRUE; } linphone_free_xml_text_content(uri); } } if (resource_object != NULL) xmlXPathFreeObject(resource_object); if (full_state == TRUE) { bctbx_list_t *l = list->friends; for (; l != NULL; l = l->next) { lf = (LinphoneFriend *)l->data; if (linphone_friend_is_presence_received(lf) == TRUE) { linphone_core_notify_notify_presence_received(list->lc, lf); } } } } else { ms_warning("Wrongly formatted rlmi+xml body: %s", xml_ctx->errorBuffer); } end: linphone_xmlparsing_context_destroy(xml_ctx); }
/** * @brief Initialize plugin after loaded and before any other functions are called. * This function should not apply any configuration data to the controlled device. If no * running is returned (it stays *NULL), complete startup configuration is consequently * applied via module callbacks. When a running configuration is returned, libnetconf * then applies (via module's callbacks) only the startup configuration data that * differ from the returned running configuration data. * Please note, that copying startup data to the running is performed only after the * libnetconf's system-wide close - see nc_close() function documentation for more * information. * @param[out] running Current configuration of managed device. * @return EXIT_SUCCESS or EXIT_FAILURE */ int netopeer_transapi_init(xmlDocPtr* UNUSED(running)) { xmlDocPtr doc; struct nc_err* error = NULL; const char* str_err; nc_verb_verbose("Setting the default configuration for the cfgnetopeer module..."); doc = xmlReadDoc(BAD_CAST "<netopeer xmlns=\"urn:cesnet:tmc:netopeer:1.0\"><hello-timeout>600</hello-timeout><idle-timeout>3600</idle-timeout><max-sessions>8</max-sessions><response-time>50</response-time><client-removal-time>10</client-removal-time></netopeer>", NULL, NULL, 0); if (doc == NULL) { nc_verb_error("Unable to parse the default cfgnetopeer configuration."); return EXIT_FAILURE; } if (callback_n_netopeer_n_hello_timeout(NULL, XMLDIFF_ADD, NULL, doc->children->children, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_idle_timeout(NULL, XMLDIFF_ADD, NULL, doc->children->children->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_max_sessions(NULL, XMLDIFF_ADD, NULL, doc->children->children->next->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_response_time(NULL, XMLDIFF_ADD, NULL, doc->children->children->next->next->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_client_removal_time(NULL, XMLDIFF_ADD, NULL, doc->children->children->next->next->next->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } xmlFreeDoc(doc); #ifdef NP_SSH if (ncds_feature_isenabled("cfgnetopeer", "ssh") && (netopeer_transapi_init_ssh() != EXIT_SUCCESS)) { return EXIT_FAILURE; } #endif #ifdef NP_TLS if (ncds_feature_isenabled("cfgnetopeer", "tls") && (netopeer_transapi_init_tls() != EXIT_SUCCESS)) { return EXIT_FAILURE; } #endif return EXIT_SUCCESS; }
int libvirt_open() { conn = virConnectOpenReadOnly("xen:///"); if(conn == NULL) { printf("libvirt connection open error on uri \n"); return 0; } int n; n = virConnectNumOfDomains(conn); if(n < 0) { printf("Error reading number of domains \n"); return -1; } int i; int *domids; domids = malloc(sizeof(int) * n); if(domids == 0) { printf("libvirt domain ids malloc failed"); return -1; } n = virConnectListDomains(conn, domids, n); if(n < 0) { printf("Error reading list of domains \n"); free(domids); return -1; } free_block_devices(); free_interface_devices(); free_domains(); for (i = 0; i < n ; ++i) { virDomainPtr dom = NULL; const char *name; char *xml = NULL; xmlDocPtr xml_doc = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr xpath_obj = NULL; int j; //printf("Publishing Domain Id : %d \n ", domids[i]); dom = virDomainLookupByID(conn, domids[i]); if(dom == NULL) { printf("Domain no longer active or moved away .. \n"); } name = virDomainGetName(dom); //printf("Publishing Domain Name : %s \n ", name); if(name == NULL) { printf("Domain name not valid .. \n"); goto cont; } if(add_domain(dom) < 0) { printf("libvirt plugin malloc failed .. \n"); goto cont; } xml = virDomainGetXMLDesc(dom, 0); if(!xml) { printf("Virt domain xml description error ..\n"); goto cont; } //printf("Publishing XML : \n %s \n ", xml); xml_doc = xmlReadDoc((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET); if(xml_doc == NULL) { printf("XML read doc error ..\n"); goto cont; } xpath_ctx = xmlXPathNewContext(xml_doc); xpath_obj = xmlXPathEval((xmlChar *) "/domain/devices/disk/target[@dev]", xpath_ctx); if(xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) { goto cont; } for(j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) { xmlNodePtr node; char *path = NULL; node = xpath_obj->nodesetval->nodeTab[j]; if(!node) continue; path = (char *) xmlGetProp (node, (xmlChar *) "dev"); if(!path) continue; add_block_device(dom, path); } xmlXPathFreeObject(xpath_obj); xpath_obj = xmlXPathEval((xmlChar *) "/domain/devices/interface/target[@dev]", xpath_ctx); if(xpath_obj == NULL || xpath_obj->type != XPATH_NODESET || xpath_obj->nodesetval == NULL) { goto cont; } for(j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) { xmlNodePtr node; char *path = NULL; node = xpath_obj->nodesetval->nodeTab[j]; if(!node) continue; path = (char *) xmlGetProp(node, (xmlChar *) "dev"); if(!path) continue; add_interface_device(dom, path); } cont: if(xpath_obj) xmlXPathFreeObject(xpath_obj); if(xpath_ctx) xmlXPathFreeContext(xpath_ctx); if(xml_doc) xmlFreeDoc(xml_doc); if(xml) free(xml); } free(domids); return 0; }
int netopeer_transapi_init_ssh(void) { xmlDocPtr doc; struct nc_err* error = NULL; const char* str_err; nc_verb_verbose("Setting the default configuration for the cfgnetopeer module SSH..."); netopeer_options.ssh_opts = calloc(1, sizeof(struct np_options_ssh)); pthread_mutex_init(&netopeer_options.ssh_opts->client_keys_lock, NULL); doc = xmlReadDoc(BAD_CAST "<netopeer xmlns=\"urn:cesnet:tmc:netopeer:1.0\"><ssh><server-keys><rsa-key>/etc/ssh/ssh_host_rsa_key</rsa-key></server-keys><password-auth-enabled>true</password-auth-enabled><auth-attempts>3</auth-attempts><auth-timeout>10</auth-timeout></ssh></netopeer>", NULL, NULL, 0); if (doc == NULL) { nc_verb_error("Unable to parse the default cfgnetopeer SSH configuration."); return EXIT_FAILURE; } if (callback_n_netopeer_n_ssh_n_server_keys_n_rsa_key(NULL, XMLDIFF_ADD, NULL, doc->children->children->children->children, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_ssh_n_password_auth_enabled(NULL, XMLDIFF_ADD, NULL, doc->children->children->children->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_ssh_n_auth_attempts(NULL, XMLDIFF_ADD, NULL, doc->children->children->children->next->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } if (callback_n_netopeer_n_ssh_n_auth_timeout(NULL, XMLDIFF_ADD, NULL, doc->children->children->children->next->next->next, &error) != EXIT_SUCCESS) { if (error != NULL) { str_err = nc_err_get(error, NC_ERR_PARAM_MSG); if (str_err != NULL) { nc_verb_error(str_err); } nc_err_free(error); } xmlFreeDoc(doc); return EXIT_FAILURE; } xmlFreeDoc(doc); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int i; int strings = 0; int usefile = 0; char *filename = NULL; for (i = 1; i < argc ; i++) { #if defined(LIBXML_XPTR_ENABLED) if ((!strcmp(argv[i], "-xptr")) || (!strcmp(argv[i], "--xptr"))) xptr++; else #endif if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) debug++; else if ((!strcmp(argv[i], "-valid")) || (!strcmp(argv[i], "--valid"))) valid++; else if ((!strcmp(argv[i], "-expr")) || (!strcmp(argv[i], "--expr"))) expr++; else if ((!strcmp(argv[i], "-tree")) || (!strcmp(argv[i], "--tree"))) tree++; else if ((!strcmp(argv[i], "-nocdata")) || (!strcmp(argv[i], "--nocdata"))) nocdata++; else if ((!strcmp(argv[i], "-i")) || (!strcmp(argv[i], "--input"))) filename = argv[++i]; else if ((!strcmp(argv[i], "-f")) || (!strcmp(argv[i], "--file"))) usefile++; } if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; xmlSubstituteEntitiesDefaultValue = 1; #ifdef LIBXML_SAX1_ENABLED if (nocdata != 0) { xmlDefaultSAXHandlerInit(); xmlDefaultSAXHandler.cdataBlock = NULL; } #endif if (document == NULL) { if (filename == NULL) document = xmlReadDoc(buffer,NULL,NULL,XML_PARSE_COMPACT); else document = xmlReadFile(filename,NULL,XML_PARSE_COMPACT); } for (i = 1; i < argc ; i++) { if ((!strcmp(argv[i], "-i")) || (!strcmp(argv[i], "--input"))) { i++; continue; } if (argv[i][0] != '-') { if (usefile) testXPathFile(argv[i]); else testXPath(argv[i]); strings ++; } } if (strings == 0) { printf("Usage : %s [--debug] [--copy] stringsorfiles ...\n", argv[0]); printf("\tParse the XPath strings and output the result of the parsing\n"); printf("\t--debug : dump a debug version of the result\n"); printf("\t--valid : switch on DTD support in the parser\n"); #if defined(LIBXML_XPTR_ENABLED) printf("\t--xptr : expressions are XPointer expressions\n"); #endif printf("\t--expr : debug XPath expressions only\n"); printf("\t--tree : show the compiled XPath tree\n"); printf("\t--nocdata : do not generate CDATA nodes\n"); printf("\t--input filename : or\n"); printf("\t-i filename : read the document from filename\n"); printf("\t--file : or\n"); printf("\t-f : read queries from files, args\n"); } if (document != NULL) xmlFreeDoc(document); xmlCleanupParser(); xmlMemoryDump(); return(0); }