HRESULT dt_validate(XDR_DT dt, xmlChar const* content) { xmlDocPtr tmp_doc; xmlNodePtr node; xmlNsPtr ns; HRESULT hr; TRACE("(dt:%s, %s)\n", dt_to_str(dt), wine_dbgstr_a((char const*)content)); if (!datatypes_schema) { xmlSchemaParserCtxtPtr spctx; assert(datatypes_src != NULL); spctx = xmlSchemaNewMemParserCtxt((char const*)datatypes_src, datatypes_len); datatypes_schema = Schema_parse(spctx); xmlSchemaFreeParserCtxt(spctx); } switch (dt) { case DT_INVALID: return E_FAIL; case DT_BIN_BASE64: case DT_BIN_HEX: case DT_BOOLEAN: case DT_CHAR: case DT_DATE: case DT_DATE_TZ: case DT_DATETIME: case DT_DATETIME_TZ: case DT_FIXED_14_4: case DT_FLOAT: case DT_I1: case DT_I2: case DT_I4: case DT_I8: case DT_INT: case DT_NMTOKEN: case DT_NMTOKENS: case DT_NUMBER: case DT_R4: case DT_R8: case DT_STRING: case DT_TIME: case DT_TIME_TZ: case DT_UI1: case DT_UI2: case DT_UI4: case DT_UI8: case DT_URI: case DT_UUID: if (!datatypes_schema) { ERR("failed to load schema for urn:schemas-microsoft-com:datatypes, " "you're probably using an old version of libxml2: " LIBXML_DOTTED_VERSION "\n"); /* Hopefully they don't need much in the way of XDR datatypes support... */ return S_OK; } if (content && xmlStrlen(content)) { tmp_doc = xmlNewDoc(NULL); node = xmlNewChild((xmlNodePtr)tmp_doc, NULL, dt_to_str(dt), content); ns = xmlNewNs(node, DT_nsURI, BAD_CAST "dt"); xmlSetNs(node, ns); xmlDocSetRootElement(tmp_doc, node); hr = Schema_validate_tree(datatypes_schema, (xmlNodePtr)tmp_doc); xmlFreeDoc(tmp_doc); } else { /* probably the node is being created manually and has no content yet */ hr = S_OK; } return hr; default: FIXME("need to handle dt:%s\n", dt_to_str(dt)); return S_OK; } }
//! //! Encodes instance metadata (contained in ncInstance struct) in XML //! and writes it to file instance->xmlFilePath (/path/to/instance/instance.xml) //! That file gets processed through tools/libvirt.xsl (/etc/eucalyptus/libvirt.xsl) //! to produce /path/to/instance/libvirt.xml file that is passed to libvirt create. //! //! @param[in] instance a pointer to the instance to generate XML from //! //! @return EUCA_OK if the operation is successful. Known error code returned include EUCA_ERROR. //! //! @see write_xml_file() //! int gen_instance_xml(const ncInstance * instance) { int ret = EUCA_ERROR; int i = 0; int j = 0; char *path = NULL; char cores_s[10] = ""; char memory_s[10] = ""; char bitness[4] = ""; char root_uuid[64] = ""; char devstr[SMALL_CHAR_BUFFER_SIZE] = ""; xmlNodePtr disk = NULL; xmlDocPtr doc = NULL; xmlNodePtr instanceNode = NULL; xmlNodePtr hypervisor = NULL; xmlNodePtr backing = NULL; xmlNodePtr root = NULL; xmlNodePtr key = NULL; xmlNodePtr os = NULL; xmlNodePtr disks = NULL; xmlNodePtr rootNode = NULL; xmlNodePtr nics = NULL; xmlNodePtr nic = NULL; const virtualBootRecord *vbr = NULL; INIT(); pthread_mutex_lock(&xml_mutex); { doc = xmlNewDoc(BAD_CAST "1.0"); instanceNode = xmlNewNode(NULL, BAD_CAST "instance"); xmlDocSetRootElement(doc, instanceNode); // hypervisor-related specs hypervisor = xmlNewChild(instanceNode, NULL, BAD_CAST "hypervisor", NULL); _ATTRIBUTE(hypervisor, "type", instance->hypervisorType); _ATTRIBUTE(hypervisor, "capability", hypervsorCapabilityTypeNames[instance->hypervisorCapability]); snprintf(bitness, 4, "%d", instance->hypervisorBitness); _ATTRIBUTE(hypervisor, "bitness", bitness); //! backing specification (@todo maybe expand this with device maps or whatnot?) backing = xmlNewChild(instanceNode, NULL, BAD_CAST "backing", NULL); root = xmlNewChild(backing, NULL, BAD_CAST "root", NULL); assert(instance->params.root); _ATTRIBUTE(root, "type", ncResourceTypeName[instance->params.root->type]); _ELEMENT(instanceNode, "name", instance->instanceId); _ELEMENT(instanceNode, "uuid", instance->uuid); _ELEMENT(instanceNode, "reservation", instance->reservationId); _ELEMENT(instanceNode, "user", instance->userId); _ELEMENT(instanceNode, "dnsName", instance->dnsName); _ELEMENT(instanceNode, "privateDnsName", instance->privateDnsName); _ELEMENT(instanceNode, "instancePath", instance->instancePath); if (instance->params.kernel) { path = instance->params.kernel->backingPath; if (path_check(path, "kernel")) goto free; // sanity check _ELEMENT(instanceNode, "kernel", path); } if (instance->params.ramdisk) { path = instance->params.ramdisk->backingPath; if (path_check(path, "ramdisk")) goto free; // sanity check _ELEMENT(instanceNode, "ramdisk", path); } _ELEMENT(instanceNode, "consoleLogPath", instance->consoleFilePath); _ELEMENT(instanceNode, "userData", instance->userData); _ELEMENT(instanceNode, "launchIndex", instance->launchIndex); snprintf(cores_s, sizeof(cores_s), "%d", instance->params.cores); _ELEMENT(instanceNode, "cores", cores_s); snprintf(memory_s, sizeof(memory_s), "%d", instance->params.mem * 1024); _ELEMENT(instanceNode, "memoryKB", memory_s); // SSH-key related key = _NODE(instanceNode, "key"); _ATTRIBUTE(key, "isKeyInjected", _BOOL(instance->do_inject_key)); _ATTRIBUTE(key, "sshKey", instance->keyName); // OS-related specs os = _NODE(instanceNode, "os"); _ATTRIBUTE(os, "platform", instance->platform); _ATTRIBUTE(os, "virtioRoot", _BOOL(config_use_virtio_root)); _ATTRIBUTE(os, "virtioDisk", _BOOL(config_use_virtio_disk)); _ATTRIBUTE(os, "virtioNetwork", _BOOL(config_use_virtio_net)); // disks specification disks = _NODE(instanceNode, "disks"); // the first disk should be the root disk (at least for Windows) for (j = 1; j >= 0; j--) { for (i = 0; ((i < EUCA_MAX_VBRS) && (i < instance->params.virtualBootRecordLen)); i++) { vbr = &(instance->params.virtualBootRecord[i]); // skip empty entries, if any if (vbr == NULL) continue; // do EMI on the first iteration of the outer loop if (j && vbr->type != NC_RESOURCE_IMAGE) continue; // ignore EMI on the second iteration of the outer loop if (!j && vbr->type == NC_RESOURCE_IMAGE) continue; // skip anything without a device on the guest, e.g., kernel and ramdisk if (!strcmp("none", vbr->guestDeviceName)) continue; // for Linux instances on Xen, partitions can be used directly, so disks can be skipped unless booting from EBS if (strstr(instance->platform, "linux") && strstr(instance->hypervisorType, "xen")) { if ((vbr->partitionNumber == 0) && (vbr->type == NC_RESOURCE_IMAGE)) { continue; } } else { // on all other os + hypervisor combinations, disks are used, so partitions must be skipped if (vbr->partitionNumber > 0) { continue; } } disk = _ELEMENT(disks, "diskPath", vbr->backingPath); _ATTRIBUTE(disk, "targetDeviceType", libvirtDevTypeNames[vbr->guestDeviceType]); _ATTRIBUTE(disk, "targetDeviceName", vbr->guestDeviceName); snprintf(devstr, SMALL_CHAR_BUFFER_SIZE, "%s", vbr->guestDeviceName); if (config_use_virtio_root) { devstr[0] = 'v'; _ATTRIBUTE(disk, "targetDeviceNameVirtio", devstr); _ATTRIBUTE(disk, "targetDeviceBusVirtio", "virtio"); } _ATTRIBUTE(disk, "targetDeviceBus", libvirtBusTypeNames[vbr->guestDeviceBus]); _ATTRIBUTE(disk, "sourceType", libvirtSourceTypeNames[vbr->backingType]); if (j) { rootNode = _ELEMENT(disks, "root", NULL); _ATTRIBUTE(rootNode, "device", devstr); if (get_blkid(vbr->backingPath, root_uuid, sizeof(root_uuid)) == 0) { assert(strlen(root_uuid)); _ATTRIBUTE(rootNode, "uuid", root_uuid); } } } if (strlen(instance->floppyFilePath)) { _ELEMENT(disks, "floppyPath", instance->floppyFilePath); } } if (instance->params.nicType != NIC_TYPE_NONE) { // NIC specification nics = _NODE(instanceNode, "nics"); nic = _NODE(nics, "nic"); _ATTRIBUTE(nic, "bridgeDeviceName", instance->params.guestNicDeviceName); _ATTRIBUTE(nic, "mac", instance->ncnet.privateMac); } ret = write_xml_file(doc, instance->instanceId, instance->xmlFilePath, "instance"); free: xmlFreeDoc(doc); } pthread_mutex_unlock(&xml_mutex); return (ret); }
/** * @brief Retrieve state data from device and return them as XML document * * @param model Device data model. libxml2 xmlDocPtr. * @param running Running datastore content. libxml2 xmlDocPtr. * @param[out] err Double pointer to error structure. Fill error when some occurs. * @return State data as libxml2 xmlDocPtr or NULL in case of error. */ xmlDocPtr get_state_data (xmlDocPtr model, xmlDocPtr running, struct nc_err **err) { nc_verb_verbose("get_state_data\n"); nc_verb_verbose("erropt=%u\n", erropt); xmlDocPtr state; xmlNodePtr root; xmlNsPtr ns; state = xmlNewDoc(BAD_CAST "1.0"); root = xmlNewDocNode(state, NULL, BAD_CAST "capable-switch", NULL); xmlDocSetRootElement(state, root); ns = xmlNewNs(root, BAD_CAST "urn:onf:of111:config:yang", NULL); xmlSetNs(root, ns); // state that should be queried here // ### base // #/ofc:capable-switch/ofc:config-version xmlNewChild(root, ns, BAD_CAST "config-version", BAD_CAST "1.1.1"); // // ### configuration points // // ### Resources // xmlNodePtr resources = xmlNewChild(root, NULL, BAD_CAST "resources", NULL); // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:number // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:current-rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:max-rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:oper-state // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:blocked // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:live // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:pause // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:pause // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:pause get_port_info(ofc_state.xmp_client_handle, resources, running); xmlNodePtr lsis = xmlNewChild(root, NULL, BAD_CAST "logical-switches", NULL); // ### LSIs // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-buffered-packets // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-tables // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-ports // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:flow-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:table-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:port-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:queue-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reassemble-ip-fragments // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:block-looping-ports // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reserved-port-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reserved-port-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-capabilities // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-capabilities/ofc:capability // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:action-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:action-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:instruction-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:instruction-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:connection-state // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:current-version // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:supported-versions // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:local-ip-address-in-use // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:local-port-in-use get_lsi_info(ofc_state.xmp_client_handle, lsis, running); return state; }
int winfo2xmpp(str* to_uri, str* body, str* id) { xmlAttrPtr attr= NULL; str xmpp_msg; char* watcher= NULL ; str from_uri = {0, 0}; xmlDocPtr notify_doc= NULL; xmlDocPtr doc= NULL; xmlNodePtr pidf_root= NULL; xmlNodePtr root_node= NULL; xmlNodePtr node= NULL; xmlBufferPtr buffer= NULL; str watcher_str; LM_DBG("start...\n"); notify_doc= xmlParseMemory(body->s, body->len); if(notify_doc== NULL) { LM_ERR("while parsing xml memory\n"); return -1; } pidf_root= XMLDocGetNodeByName(notify_doc, "watcherinfo", NULL); if(pidf_root== NULL) { LM_ERR("while extracting 'presence' node\n"); goto error; } node = XMLNodeGetNodeByName(pidf_root, "watcher", NULL); for (; node!=NULL; node = node->next) { if( xmlStrcasecmp(node->name,(unsigned char*)"watcher")) continue; watcher= (char*)xmlNodeGetContent(node->children); if(watcher== NULL) { LM_ERR("while extracting watcher node content\n"); goto error; } watcher_str.s = watcher; watcher_str.len = strlen(watcher); from_uri.s = xmpp_uri_sip2xmpp(&watcher_str); if(from_uri.s == NULL) { LM_ERR("Failed to transform uri from sip to xmpp\n"); goto error; } from_uri.len = strlen(from_uri.s); xmlFree(watcher); watcher= NULL; doc= xmlNewDoc( 0 ); if(doc== NULL) { LM_ERR("when creating new xml doc\n"); goto error; } root_node = xmlNewNode(NULL, BAD_CAST "presence"); if(root_node== NULL) { LM_ERR("when adding new node\n"); goto error; } xmlDocSetRootElement(doc, root_node); attr= xmlNewProp(root_node, BAD_CAST "to", BAD_CAST to_uri->s); if(attr== NULL) { LM_ERR("while adding attribute to_uri\n"); goto error; } attr= xmlNewProp(root_node, BAD_CAST "from", BAD_CAST from_uri.s); if(attr== NULL) { LM_ERR("while adding attribute from_uri\n"); goto error; } attr= xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "subscribe"); if(attr== NULL) { LM_ERR("while adding attribute type\n"); goto error; } buffer= xmlBufferCreate(); if(buffer== NULL) { LM_ERR("while adding creating new buffer\n"); goto error; } xmpp_msg.len= xmlNodeDump(buffer, doc, root_node, 1,1); if(xmpp_msg.len== -1) { LM_ERR("while dumping node\n"); goto error; } xmpp_msg.s= (char*)xmlBufferContent( buffer); if(xmpp_msg.s== NULL) { LM_ERR("while extracting buffer content\n"); goto error; } LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s); if( xmpp_subscribe(&from_uri, to_uri, &xmpp_msg, id)< 0) { LM_ERR("while sending xmpp_subscribe\n"); goto error; } xmlBufferFree(buffer); buffer= NULL; xmlFreeDoc(doc); doc= NULL; } xmlFreeDoc(notify_doc); xmlCleanupParser(); xmlMemoryDump(); return 0; error: if(doc) xmlFreeDoc(doc); if(notify_doc) xmlFreeDoc(notify_doc); if(watcher) xmlFree(watcher); if(buffer) xmlBufferFree(buffer); xmlCleanupParser(); xmlMemoryDump(); return -1; }
void Settings::save() { XOJ_CHECK_TYPE(Settings); if (this->timeoutId) { g_source_remove(this->timeoutId); this->timeoutId = 0; } xmlDocPtr doc; xmlNodePtr root; xmlNodePtr xmlNode; xmlIndentTreeOutput = TRUE; doc = xmlNewDoc((const xmlChar*) "1.0"); if (doc == NULL) { return; } saveButtonConfig(); /* Create metadata root */ root = xmlNewDocNode(doc, NULL, (const xmlChar*) "settings", NULL); xmlDocSetRootElement(doc, root); xmlNodePtr com = xmlNewComment((const xmlChar*) "The Xournal++ settings file. Do not edit this file! " "The most settings are available in the Settings dialog, " "the others are commented in this file, but handle with care!"); xmlAddPrevSibling(root, com); WRITE_BOOL_PROP(useXinput); WRITE_BOOL_PROP(presureSensitivity); WRITE_BOOL_PROP(ignoreCoreEvents); WRITE_STRING_PROP(selectedToolbar); WRITE_STRING_PROP(lastSavePath); WRITE_STRING_PROP(lastImagePath); WRITE_INT_PROP(displayDpi); WRITE_INT_PROP(mainWndWidth); WRITE_INT_PROP(mainWndHeight); WRITE_BOOL_PROP(maximized); WRITE_BOOL_PROP(showSidebar); WRITE_INT_PROP(sidebarWidth); WRITE_BOOL_PROP(sidebarOnRight); WRITE_BOOL_PROP(scrollbarOnLeft); WRITE_BOOL_PROP(showTwoPages); WRITE_BOOL_PROP(presentationMode); WRITE_STRING_PROP(fullscreenHideElements); WRITE_COMMENT("Which gui elements are hidden if you are in Fullscreen mode, separated by a colon (,)"); WRITE_STRING_PROP(presentationHideElements); WRITE_COMMENT("Which gui elements are hidden if you are in Presentation mode, separated by a colon (,)"); WRITE_BOOL_PROP(showBigCursor); if (this->scrollbarHideType == SCROLLBAR_HIDE_BOTH) { saveProperty((const char*) "scrollbarHideType", "both", root); } else if (this->scrollbarHideType == SCROLLBAR_HIDE_HORIZONTAL) { saveProperty((const char*) "scrollbarHideType", "horizontal", root); } else if (this->scrollbarHideType == SCROLLBAR_HIDE_VERTICAL) { saveProperty((const char*) "scrollbarHideType", "vertical", root); } else { saveProperty((const char*) "scrollbarHideType", "none", root); } WRITE_BOOL_PROP(autoloadPdfXoj); WRITE_COMMENT("Hides scroolbars in the main window, allowed values: \"none\", \"horizontal\", \"vertical\", \"both\""); WRITE_STRING_PROP(defaultSaveName); WRITE_STRING_PROP(visiblePageFormats); WRITE_COMMENT("This paper format is visible in the paper format dialog, separated by a colon"); WRITE_BOOL_PROP(autosaveEnabled); WRITE_INT_PROP(autosaveTimeout); WRITE_BOOL_PROP(addHorizontalSpace); WRITE_BOOL_PROP(addVerticalSpace); WRITE_BOOL_PROP(fixXinput); WRITE_BOOL_PROP(enableLeafEnterWorkaround); WRITE_COMMENT("If Xournal crashes if you e.g. unplug your mouse set this to true. If you have input problems, you can turn it of with false."); String pageInsertType = pageInsertTypeToString(this->pageInsertType); WRITE_STRING_PROP(pageInsertType); WRITE_INT_PROP(pageBackgroundColor); WRITE_INT_PROP(selectionColor); WRITE_INT_PROP(pdfPageCacheSize); WRITE_COMMENT("The count of rendered PDF pages which will be cached."); WRITE_DOUBLE_PROP(widthMinimumMultiplier); WRITE_COMMENT("The multiplier for the pressure sensitivity of the pen"); WRITE_DOUBLE_PROP(widthMaximumMultiplier); WRITE_COMMENT("The multiplier for the pressure sensitivity of the pen"); xmlNodePtr xmlFont; xmlFont = xmlNewChild(root, NULL, (const xmlChar*) "property", NULL); xmlSetProp(xmlFont, (const xmlChar*) "name", (const xmlChar*) "font"); xmlSetProp(xmlFont, (const xmlChar*) "font", (const xmlChar*) this->font.getName().c_str()); gchar* sSize = g_strdup_printf("%0.1lf", this->font.getSize()); xmlSetProp(xmlFont, (const xmlChar*) "size", (const xmlChar*) sSize); g_free(sSize); std::map<String, SElement>::iterator it; for (it = data.begin(); it != data.end(); it++) { saveData(root, (*it).first, (*it).second); } xmlSaveFormatFile(filename.c_str(), doc, 1); xmlFreeDoc(doc); }
static void mtev_capabilities_tobuff(mtev_capsvc_closure_t *cl, eventer_func_t curr) { const char **mod_names; struct utsname utsn; char vbuff[128], bwstr[4]; mtev_hash_table *lc; mtev_hash_iter iter = MTEV_HASH_ITER_ZERO; const char *k; int klen, i, nmods; void *data; struct timeval now; struct dso_type *t; xmlDocPtr xmldoc; xmlNodePtr root, cmds, bi, ri, mods, feat; /* fill out capabilities */ /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)capabilities_namespace, NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ mtev_build_version(vbuff, sizeof(vbuff)); xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); snprintf(bwstr, sizeof(bwstr), "%d", (int)sizeof(void *)*8); /* Build info */ bi = xmlNewNode(NULL, (xmlChar *)"unameBuild"); xmlSetProp(bi, (xmlChar *)"bitwidth", (xmlChar *)bwstr); xmlAddChild(root, bi); xmlNewTextChild(bi, NULL, (xmlChar *)"sysname", (xmlChar *)UNAME_S); xmlNewTextChild(bi, NULL, (xmlChar *)"nodename", (xmlChar *)UNAME_N); xmlNewTextChild(bi, NULL, (xmlChar *)"release", (xmlChar *)UNAME_R); xmlNewTextChild(bi, NULL, (xmlChar *)"version", (xmlChar *)UNAME_V); xmlNewTextChild(bi, NULL, (xmlChar *)"machine", (xmlChar *)UNAME_M); /* Run info */ ri = xmlNewNode(NULL, (xmlChar *)"unameRun"); xmlSetProp(ri, (xmlChar *)"bitwidth", (xmlChar *)bwstr); xmlAddChild(root, ri); if(uname(&utsn) < 0) { xmlNewTextChild(ri, NULL, (xmlChar *)"error", (xmlChar *)strerror(errno)); } else { xmlNewTextChild(ri, NULL, (xmlChar *)"sysname", (xmlChar *)utsn.sysname); xmlNewTextChild(ri, NULL, (xmlChar *)"nodename", (xmlChar *)utsn.nodename); xmlNewTextChild(ri, NULL, (xmlChar *)"release", (xmlChar *)utsn.release); xmlNewTextChild(ri, NULL, (xmlChar *)"version", (xmlChar *)utsn.version); xmlNewTextChild(ri, NULL, (xmlChar *)"machine", (xmlChar *)utsn.machine); } /* features */ feat = xmlNewNode(NULL, (xmlChar *)"features"); xmlAddChild(root, feat); if(mtev_hash_size(&features)) { mtev_hash_iter iter2 = MTEV_HASH_ITER_ZERO; void *vfv; const char *f; int flen; while(mtev_hash_next(&features, &iter2, &f, &flen, &vfv)) { xmlNodePtr featnode; featnode = xmlNewNode(NULL, (xmlChar *)"feature"); xmlSetProp(featnode, (xmlChar *)"name", (xmlChar *)f); if(vfv) xmlSetProp(featnode, (xmlChar *)"version", (xmlChar *)vfv); xmlAddChild(feat, featnode); } } /* time (poor man's time check) */ gettimeofday(&now, NULL); snprintf(vbuff, sizeof(vbuff), "%llu.%03d", (unsigned long long)now.tv_sec, (int)(now.tv_usec / 1000)); xmlNewTextChild(root, NULL, (xmlChar *)"current_time", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = mtev_listener_commands(); while(mtev_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; mtev_hash_table *sc = (mtev_hash_table *)data; mtev_hash_iter sc_iter = MTEV_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == curr) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(mtev_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } mods = xmlNewNode(NULL, (xmlChar *)"modules"); xmlAddChild(root, mods); #define list_modules(func, name) do { \ nmods = func(&mod_names); \ for(i=0; i<nmods; i++) { \ xmlNodePtr pnode; \ pnode = xmlNewNode(NULL, (xmlChar *)"module"); \ xmlSetProp(pnode, (xmlChar *)"type", (xmlChar *)name); \ xmlSetProp(pnode, (xmlChar *)"name", (xmlChar *)mod_names[i]); \ xmlAddChild(mods, pnode); \ } \ if(mod_names) free(mod_names); \ } while(0) for(t = mtev_dso_get_types(); t; t = t->next) list_modules(t->list, t->name); /* Write it out to a buffer and copy it for writing */ cl->buff = mtev_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); }
int main(const int argc, const char ** const argv) { xmlDocPtr doc, request; xmlNodePtr root, topic_level, topic, request_node; xmlChar *out; size_t len; int ret; const char *path; void *context; void *topic_storage; char *income; size_t msg_size; char endpoint[FIELD_SIZE]; char field[FIELD_SIZE]; FILE *fp; /**** ****/ if (argc != 2) { printf("usage: topic_loader file.xml\n"); return OK; } printf(">>> [TopicLoader]: selected file: %s\n", argv[1]); path = argv[1]; /**** ****/ fp = fopen("topic_loader.ini", "r"); if (fp == NULL) { printf(">>> [TopicLoader]: IO ERROR. can't open \"topic_loader.ini\"\n"); return 1; } fscanf(fp,"%s %*s %s", field, endpoint); printf(">>> [TopicLoader]: field: %s; value: %s;\n", field, endpoint); fclose(fp); context = zmq_init(1); topic_storage = zmq_socket(context, ZMQ_REQ); zmq_connect(topic_storage, endpoint); ret = OK; doc = NULL; root = NULL; topic_level = NULL; request = NULL; doc = xmlReadFile(path, NULL, 0); if (!doc) { printf(">>> [TopicLoader]: libxml couldn't open the file\n"); return FAIL; } root = xmlDocGetRootElement(doc); if (!root) { printf(">>> [TopicLoader]: libxml couldn't get root element\n"); return FAIL; } topic_level = root->children; while (topic_level) { if (strcmp(topic_level->name, "topic")) { topic_level = topic_level->next; continue; } topic = NULL; request = NULL; out = NULL; request = NULL; request_node = NULL; topic = malloc(sizeof(xmlNode)); memcpy(topic, topic_level, sizeof(xmlNode)); topic->next = NULL; request = xmlNewDoc("1.0"); request_node = xmlNewNode(NULL, "request"); xmlNewProp(request_node, "type", "add_topic"); request_node->children = topic; xmlDocSetRootElement(request, request_node); xmlDocDumpFormatMemoryEnc(request, &out, &len, "UTF-8", 1); printf("%s\n", (char *)out); s_send(topic_storage, (char *)out, strlen((char *)out) + 1); income = s_recv(topic_storage, &msg_size); printf(">>> [TopicLoader]: TS responsed: %s\n", income); if (request_node) xmlFree(request_node); if (topic) free(topic); if (out) xmlFree(out); topic_level = topic_level->next; } /* if (doc) xmlFreeDoc(doc); */ return OK; }
/** * testXmlwriterTree: * @file: the output file * * test the xmlWriter interface when writing to a subtree */ void testXmlwriterTree(const char *file) { int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlNodePtr node; xmlChar *tmp; /* Create a new XML DOM tree, to which the XML document will be * written */ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); if (doc == NULL) { printf ("testXmlwriterTree: Error creating the xml document tree\n"); return; } /* Create a new XML node, to which the XML document will be * appended */ node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL); if (node == NULL) { printf("testXmlwriterTree: Error creating the xml node\n"); return; } /* Make ELEMENT the root node of the tree */ xmlDocSetRootElement(doc, node); /* Create a new XmlWriter for DOM tree, with no compression. */ writer = xmlNewTextWriterTree(doc, node, 0); if (writer == NULL) { printf("testXmlwriterTree: Error creating the xml writer\n"); return; } /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartDocument\n"); return; } /* Write a comment as child of EXAMPLE. * Please observe, that the input to the xmlTextWriter functions * HAS to be in UTF-8, even if the output XML is encoded * in iso-8859-1 */ tmp = ConvertInput("This is a comment with special chars: <äöü>", MY_ENCODING); rc = xmlTextWriterWriteComment(writer, tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "ORDER" as child of EXAMPLE. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Add an attribute with name "version" and value "1.0" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Add an attribute with name "xml:lang" and value "de" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", BAD_CAST "de"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Write a comment as child of ORDER */ tmp = ConvertInput("<äöü>", MY_ENCODING); rc = xmlTextWriterWriteFormatComment(writer, "This is another comment with special chars: %s", tmp); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "HEADER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "X_ORDER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID", "%010d", 53535L); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "CUSTOMER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID", "%d", 1010); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "NAME_1" as child of HEADER. */ tmp = ConvertInput("Müller", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Write an element named "NAME_2" as child of HEADER. */ tmp = ConvertInput("Jörg", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriter
int noit_capabilities_handler(eventer_t e, int mask, void *closure, struct timeval *now) { int newmask = EVENTER_WRITE | EVENTER_EXCEPTION; acceptor_closure_t *ac = closure; noit_capsvc_closure_t *cl = ac->service_ctx; if(mask & EVENTER_EXCEPTION) { socket_error: /* Exceptions cause us to simply snip the connection */ cleanup_shutdown: eventer_remove_fd(e->fd); e->opset->close(e->fd, &newmask, e); if(cl) { if(cl->buff) free(cl->buff); free(cl); } if(ac) acceptor_closure_free(ac); return 0; } if(!ac->service_ctx) { char vbuff[128]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; xmlDocPtr xmldoc; xmlNodePtr root, cmds; cl = ac->service_ctx = calloc(1, sizeof(*cl)); /* fill out capabilities */ noit_build_version(vbuff, sizeof(vbuff)); /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noit_capabilities", NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == ac->dispatch) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } /* Write it out to a buffer and copy it for writing */ cl->buff = noit_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); } while(cl->towrite > cl->written) { int len; while((len = e->opset->write(e->fd, cl->buff + cl->written, cl->towrite - cl->written, &newmask, e)) == -1 && errno == EINTR); if(len < 0) { if(errno == EAGAIN) return newmask | EVENTER_EXCEPTION; goto socket_error; } cl->written += len; } goto cleanup_shutdown; }
void write_tasks_entries (void) { gint i; xmlDocPtr doc; xmlNodePtr main_node, node, note_node; xmlAttrPtr attr; gchar temp[BUFFER_SIZE]; GtkTreeIter iter; gboolean *done; gchar *priority, *category, *summary, *desc; guint32 due_date_julian, start_date_julian; doc = xmlNewDoc((const xmlChar *) "1.0"); attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8"); main_node = xmlNewNode(NULL, (const xmlChar *) TASKS_NAME); xmlDocSetRootElement(doc, main_node); node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_CATEGORY_ENTRIES_NAME, (xmlChar *) NULL); i = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(tasks_category_store), &iter, NULL, i++)) { gtk_tree_model_get(GTK_TREE_MODEL(tasks_category_store), &iter, 0, &category, -1); xmlNewChild(node, NULL, (const xmlChar *) "name", (xmlChar *) category); } node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_ENTRIES_NAME, (xmlChar *) NULL); i = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(tasks_list_store), &iter, NULL, i++)) { gtk_tree_model_get(GTK_TREE_MODEL(tasks_list_store), &iter, COLUMN_DONE, &done, COLUMN_DUE_DATE_JULIAN, &due_date_julian, COLUMN_START_DATE_JULIAN, &start_date_julian, COLUMN_PRIORITY, &priority, COLUMN_CATEGORY, &category, COLUMN_SUMMARY, &summary, COLUMN_DESCRIPTION, &desc, -1); note_node = xmlNewChild(node, NULL, (const xmlChar *) "entry", (xmlChar *) NULL); sprintf(temp, "%d", (gint) done); xmlNewChild(note_node, NULL, (const xmlChar *) "status", (xmlChar *) temp); sprintf(temp, "%d", (guint32) due_date_julian); xmlNewChild(note_node, NULL, (const xmlChar *) "due_date", (xmlChar *) temp); sprintf(temp, "%d", (guint32) start_date_julian); xmlNewChild(note_node, NULL, (const xmlChar *) "start_date", (xmlChar *) temp); xmlNewChild(note_node, NULL, (const xmlChar *) "priority", (xmlChar *) priority); xmlNewChild(note_node, NULL, (const xmlChar *) "category", (xmlChar *) category); xmlNewChild(note_node, NULL, (const xmlChar *) "summary", (xmlChar *) summary); xmlNewChild(note_node, NULL, (const xmlChar *) "description", (xmlChar *) desc); } xmlSaveFormatFileEnc(prefs_get_config_filename(TASKS_ENTRIES_FILENAME), doc, "utf-8", 1); xmlFreeDoc(doc); }
static int rest_show_check(noit_http_rest_closure_t *restc, int npats, char **pats) { noit_http_session_ctx *ctx = restc->http_ctx; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; xmlDocPtr doc = NULL; xmlNodePtr node, root, attr, config, state, tmp, anode; uuid_t checkid; noit_check_t *check; char xpath[1024], *uuid_conf, *module, *value; int rv, cnt, error_code = 500; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; noit_hash_table *configh; if(npats != 2) goto error; rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]); if(rv == 0) goto not_found; if(rv < 0) goto error; noit_conf_xml_xpath(NULL, &xpath_ctxt); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET || xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto not_found; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt != 1) goto error; node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); if(!uuid_conf || uuid_parse(uuid_conf, checkid)) goto error; doc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL); xmlDocSetRootElement(doc, root); #define MYATTR(node,a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b)) #define INHERIT(node,a,n,b) \ _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b)) #define SHOW_ATTR(parent, node, a) do { \ xmlNodePtr anode = NULL; \ char *value = NULL; \ INHERIT(node, a, anode, value); \ if(value != NULL) { \ int clen, plen;\ const char *cpath, *apath; \ xmlNodePtr child; \ cpath = node ? (char *)xmlGetNodePath(node) : ""; \ apath = anode ? (char *)xmlGetNodePath(anode) : ""; \ clen = strlen(cpath); \ plen = strlen("/noit/checks"); \ child = xmlNewNode(NULL, (xmlChar *)#a); \ xmlNodeAddContent(child, (xmlChar *)value); \ if(!strncmp(cpath, apath, clen) && apath[clen] == '/') { \ } \ else { \ xmlSetProp(child, (xmlChar *)"inherited", (xmlChar *)apath+plen); \ } \ xmlAddChild(parent, child); \ } \ } while(0) attr = xmlNewNode(NULL, (xmlChar *)"attributes"); xmlAddChild(root, attr); SHOW_ATTR(attr,node,uuid); /* Name is odd, it falls back transparently to module */ if(!INHERIT(node, module, tmp, module)) module = NULL; xmlAddChild(attr, (tmp = xmlNewNode(NULL, (xmlChar *)"name"))); if(MYATTR(node, name, anode, value)) xmlNodeAddContent(tmp, (xmlChar *)value); else if(module) xmlNodeAddContent(tmp, (xmlChar *)module); SHOW_ATTR(attr,node,module); SHOW_ATTR(attr,node,target); SHOW_ATTR(attr,node,period); SHOW_ATTR(attr,node,timeout); SHOW_ATTR(attr,node,oncheck); SHOW_ATTR(attr,node,filterset); SHOW_ATTR(attr,node,disable); /* Add the config */ config = xmlNewNode(NULL, (xmlChar *)"config"); configh = noit_conf_get_hash(node, "config"); while(noit_hash_next(configh, &iter, &k, &klen, &data)) NODE_CONTENT(config, k, data); noit_hash_destroy(configh, free, free); free(configh); xmlAddChild(root, config); /* Add the state */ check = noit_poller_lookup(checkid); if(!check) { state = xmlNewNode(NULL, (xmlChar *)"state"); xmlSetProp(state, (xmlChar *)"error", (xmlChar *)"true"); } else state = noit_check_state_as_xml(check); xmlAddChild(root, state); noit_http_response_ok(ctx, "text/xml"); noit_http_response_xml(ctx, doc); noit_http_response_end(ctx); goto cleanup; not_found: noit_http_response_not_found(ctx, "text/html"); noit_http_response_end(ctx); goto cleanup; error: noit_http_response_standard(ctx, error_code, "ERROR", "text/html"); noit_http_response_end(ctx); goto cleanup; cleanup: if(pobj) xmlXPathFreeObject(pobj); if(doc) xmlFreeDoc(doc); return 0; }
str* build_offline_presence(str* pres_uri) { xmlDocPtr pres_doc = NULL; xmlNodePtr root_node, tuple_node, node; char* entity; str* body = NULL; pres_doc= xmlNewDoc(BAD_CAST "1.0"); if(pres_doc== NULL) { LM_ERR("allocating new xml doc\n"); goto error; } root_node = xmlNewNode(NULL, BAD_CAST "presence"); if(root_node== NULL) { LM_ERR("Failed to create xml node\n"); goto error; } xmlDocSetRootElement(pres_doc, root_node); xmlNewProp(root_node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:pidf"); xmlNewProp(root_node, BAD_CAST "xmlns:dm", BAD_CAST "urn:ietf:params:xml:ns:pidf:data-model"); xmlNewProp(root_node, BAD_CAST "xmlns:rpid", BAD_CAST "urn:ietf:params:xml:ns:pidf:rpid" ); xmlNewProp(root_node, BAD_CAST "xmlns:c", BAD_CAST "urn:ietf:params:xml:ns:pidf:cipid"); entity= (char*)pkg_malloc(pres_uri->len + 1); if(entity == NULL) { LM_ERR("No more memory\n"); goto error; } memcpy(entity, pres_uri->s, pres_uri->len); entity[pres_uri->len] = '\0'; xmlNewProp(root_node, BAD_CAST "entity", BAD_CAST entity); pkg_free(entity); tuple_node =xmlNewChild(root_node, NULL, BAD_CAST "tuple", NULL) ; if(tuple_node == NULL) { LM_ERR("while adding child\n"); goto error; } xmlNewProp(tuple_node, BAD_CAST "id", BAD_CAST "tuple_mixingid"); node = xmlNewChild(tuple_node, NULL, BAD_CAST "status", NULL) ; if(node == NULL) { LM_ERR("while adding child\n"); goto error; } node = xmlNewChild(node, NULL, BAD_CAST "basic", BAD_CAST "closed") ; if(node ==NULL) { LM_ERR("while adding child\n"); goto error; } body = (str*)pkg_malloc(sizeof(str)); if(body == NULL) { LM_ERR("No more memory\n"); goto error; } xmlDocDumpMemory(pres_doc,(xmlChar**)(void*)&body->s, &body->len); LM_DBG("Generated dialog body: %.*s\n", body->len, body->s); error: if(pres_doc) xmlFreeDoc(pres_doc); xmlCleanupParser(); xmlMemoryDump(); return body; }
str* xml_dialog_gen_presence(str* pres_uri, int dlg_state) { char* pres_note; xmlDocPtr pres_doc; xmlNodePtr node, root_node; xmlNodePtr tuple_node, person_node; str* dialog_body = NULL; char* entity; LM_DBG("dlg_state = %d\n", dlg_state); pres_note = presence_notes[dlg_state]; /* if state is terminated, do not add anything */ if(pres_note && strlen(pres_note) == 0) { LM_DBG("NULL pres note\n"); return FAKED_BODY; } pres_doc= xmlNewDoc(BAD_CAST "1.0"); if(pres_doc== NULL) { LM_ERR("allocating new xml doc\n"); goto error; } root_node = xmlNewNode(NULL, BAD_CAST "presence"); if(root_node== NULL) { LM_ERR("Failed to create xml node\n"); goto error; } xmlDocSetRootElement(pres_doc, root_node); xmlNewProp(root_node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:pidf"); xmlNewProp(root_node, BAD_CAST "xmlns:dm", BAD_CAST "urn:ietf:params:xml:ns:pidf:data-model"); xmlNewProp(root_node, BAD_CAST "xmlns:rpid", BAD_CAST "urn:ietf:params:xml:ns:pidf:rpid" ); xmlNewProp(root_node, BAD_CAST "xmlns:c", BAD_CAST "urn:ietf:params:xml:ns:pidf:cipid"); entity= (char*)pkg_malloc(pres_uri->len + 1); if(entity == NULL) { LM_ERR("No more memory\n"); goto error; } memcpy(entity, pres_uri->s, pres_uri->len); entity[pres_uri->len] = '\0'; xmlNewProp(root_node, BAD_CAST "entity", BAD_CAST entity); pkg_free(entity); tuple_node =xmlNewChild(root_node, NULL, BAD_CAST "tuple", NULL) ; if(tuple_node == NULL) { LM_ERR("while adding child\n"); goto error; } xmlNewProp(tuple_node, BAD_CAST "id", BAD_CAST "tuple_mixingid"); node = xmlNewChild(tuple_node, NULL, BAD_CAST "status", NULL) ; if(node == NULL) { LM_ERR("while adding child\n"); goto error; } node = xmlNewChild(node, NULL, BAD_CAST "basic", BAD_CAST "open") ; if(node ==NULL) { LM_ERR("while adding child\n"); goto error; } if(pres_note && strlen(pres_note)) { node = xmlNewChild(root_node, NULL, BAD_CAST "note", BAD_CAST pres_note) ; if(node ==NULL) { LM_ERR("while adding child\n"); goto error; } /* put also the person node - to get status indication */ person_node = xmlNewChild(root_node, 0, BAD_CAST "dm:person", NULL) ; if(person_node == NULL) { LM_ERR("while adding child\n"); goto error; } /* now put the id for tuple and person */ xmlNewProp(person_node, BAD_CAST "id", BAD_CAST "pers_mixingid"); node = xmlNewChild(person_node, 0, BAD_CAST "rpid:activities", NULL) ; if(node == NULL) { LM_ERR("Failed to add person activities node\n"); goto error; } if(xmlNewChild(node, 0, BAD_CAST "rpid:on-the-phone", NULL) == NULL) { LM_ERR("Failed to add activities child\n"); goto error; } if(xmlNewChild(person_node, 0, BAD_CAST "dm:note", BAD_CAST pres_note) == NULL) { LM_ERR("Failed to add activities child\n"); goto error; } } dialog_body = (str*)pkg_malloc(sizeof(str)); if(dialog_body == NULL) { LM_ERR("No more memory\n"); goto error; } xmlDocDumpMemory(pres_doc,(xmlChar**)(void*)&dialog_body->s, &dialog_body->len); LM_DBG("Generated dialog body: %.*s\n", dialog_body->len, dialog_body->s); error: if(pres_doc) xmlFreeDoc(pres_doc); xmlCleanupParser(); xmlMemoryDump(); return dialog_body; }
/** * Build outgoing message * @param[in] msg full message to send * @param[out] outbuf output buffer/XATMI allocated * @param[out] olen output buffer len * @return SUCCEED/FAIL */ int msg_build(Message_t *msg, char **outbuf, long *olen) { int ret = SUCCEED; msgbuilder_t *p = M_msgflds; short *p_short; long *p_long; void *fld_ptr; char *p_string_el; char tmpbuf[64]; char tmpbuf2[64]; xmlDocPtr newDoc; xmlNodePtr rootNode; short *p_items; int i; xmlChar *xmlDocInMemory = NULL; int size = 0; /* Alloc STRING into obuf */ if (NULL==*outbuf) { *outbuf = tpalloc("STRING", NULL, MAX_BUFSZ); } if (NULL==*outbuf) { TP_LOG(log_error, "Failed to alloc %d bytes: %s", MAX_BUFSZ, tpstrerror(tperrno)); ret=FAIL; goto out; } /* start libxml2 XML doc */ newDoc = xmlNewDoc( BAD_CAST XML_VERSION ); rootNode = xmlNewNode(NULL, BAD_CAST "user"); xmlDocSetRootElement(newDoc, rootNode); while (0!=p->tag[0]) { fld_ptr = (char *)msg + p->msgoffs + p->elmoffs; switch (p->elmtyp) { case MSG_SHORT: p_short = (short *)fld_ptr; snprintf(tmpbuf, sizeof(tmpbuf), "%hd", *p_short); xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, BAD_CAST tmpbuf ); break; case MSG_LONG: p_long = (long *)fld_ptr; snprintf(tmpbuf, sizeof(tmpbuf), "%ld", *p_long); xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, BAD_CAST tmpbuf ); break; case MSG_STRING: xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, BAD_CAST ((char *)fld_ptr) ); break; case MSG_ARRAY_SHORT: p_items = (short *)((char *)msg + p->msgoffs + p->itmoffs); for (i=0; i<*p_items; i++) { p_short = (short *)( (char *)fld_ptr + i*sizeof(short)); snprintf(tmpbuf, sizeof(tmpbuf), "%hd", *p_short); snprintf(tmpbuf2, sizeof(tmpbuf), "%s_%d", p->tag, i); xmlNewTextChild( rootNode, NULL, BAD_CAST tmpbuf2, BAD_CAST tmpbuf ); } break; case MSG_ARRAY_STRING: p_items = (short *)((char *)msg + p->msgoffs + p->itmoffs); for (i=0; i<*p_items; i++) { /* calculate string array element location */ p_string_el = (char *)fld_ptr + i*MAX_STR; snprintf(tmpbuf2, sizeof(tmpbuf), "%s_%d", p->tag, i); xmlNewTextChild( rootNode, NULL, BAD_CAST tmpbuf2, BAD_CAST p_string_el ); } break; default: TP_LOG(log_error, "Unknown element type %d tag: [%s]!", p->elmtyp, p->tag); ret=FAIL; goto out; break; } p++; } /* build xmldoc, copy to outbuf, specify size */ xmlDocDumpMemory( newDoc, &xmlDocInMemory, &size ); strncpy(*outbuf, xmlDocInMemory, size); (*outbuf)[size] = 0; *olen = size+1; xmlFree(xmlDocInMemory); TP_LOG(log_debug, "got XML [%s]", *outbuf); out: if (NULL != newDoc) { xmlFreeDoc( newDoc ); } return ret; }
int EBC_Provider_MkEuZipDoc_A005(AB_PROVIDER *pro, AB_USER *u, const char *requestType, const uint8_t *pMsg, uint32_t lMsg, GWEN_BUFFER *sbuf) { int rv; xmlDocPtr doc; xmlNodePtr root_node; xmlNodePtr node; xmlNsPtr ns; GWEN_BUFFER *tbuf; GWEN_BUFFER *bbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=EBC_Provider_EuSign_A005(pro, u, requestType, pMsg, lMsg, tbuf); if (rv) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return rv; } bbuf=GWEN_Buffer_new(0, (GWEN_Buffer_GetUsedBytes(tbuf)*3)/2, 0, 1); rv=GWEN_Base64_Encode((const uint8_t *)GWEN_Buffer_GetStart(tbuf), GWEN_Buffer_GetUsedBytes(tbuf), bbuf, 0); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bbuf); GWEN_Buffer_free(tbuf); return rv; } GWEN_Buffer_free(tbuf); doc=xmlNewDoc(BAD_CAST "1.0"); root_node=xmlNewNode(NULL, BAD_CAST "UserSignatureData"); xmlDocSetRootElement(doc, root_node); ns=xmlNewNs(root_node, BAD_CAST "http://www.ebics.org/S001", NULL); assert(ns); ns=xmlNewNs(root_node, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", BAD_CAST "xsi"); xmlNewNsProp(root_node, ns, BAD_CAST "schemaLocation", /* xsi:schemaLocation */ BAD_CAST "http://www.ebics.org/S001 " "http://www.ebics.org/S001/ebics_signature.xsd"); node=xmlNewChild(root_node, NULL, BAD_CAST "OrderSignatureData", NULL); xmlNewTextChild(node, NULL, BAD_CAST "SignatureVersion", BAD_CAST "A005"); xmlNewTextChild(node, NULL, BAD_CAST "SignatureValue", BAD_CAST GWEN_Buffer_GetStart(bbuf)); GWEN_Buffer_free(bbuf); xmlNewTextChild(node, NULL, BAD_CAST "PartnerID", BAD_CAST AB_User_GetCustomerId(u)); xmlNewTextChild(node, NULL, BAD_CAST "UserID", BAD_CAST AB_User_GetUserId(u)); rv=EB_Xml_CompressDoc(doc, sbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); xmlFreeDoc(doc); return rv; } xmlFreeDoc(doc); return 0; }
HRESULT dt_validate(XDR_DT dt, xmlChar const* content) { xmlDocPtr tmp_doc; xmlNodePtr node; xmlNsPtr ns; HRESULT hr; TRACE("(dt:%s, %s)\n", dt_to_str(dt), wine_dbgstr_a((char const*)content)); if (!datatypes_schema) { xmlSchemaParserCtxtPtr spctx; assert(datatypes_src != NULL); spctx = xmlSchemaNewMemParserCtxt((char const*)datatypes_src, datatypes_len); datatypes_schema = Schema_parse(spctx); xmlSchemaFreeParserCtxt(spctx); } switch (dt) { case DT_INVALID: return E_FAIL; case DT_BIN_BASE64: case DT_BIN_HEX: case DT_BOOLEAN: case DT_CHAR: case DT_DATE: case DT_DATE_TZ: case DT_DATETIME: case DT_DATETIME_TZ: case DT_FIXED_14_4: case DT_FLOAT: case DT_I1: case DT_I2: case DT_I4: case DT_I8: case DT_INT: case DT_NMTOKEN: case DT_NMTOKENS: case DT_NUMBER: case DT_R4: case DT_R8: case DT_STRING: case DT_TIME: case DT_TIME_TZ: case DT_UI1: case DT_UI2: case DT_UI4: case DT_UI8: case DT_URI: case DT_UUID: assert(datatypes_schema != NULL); if (content && xmlStrlen(content)) { tmp_doc = xmlNewDoc(NULL); node = xmlNewChild((xmlNodePtr)tmp_doc, NULL, dt_to_str(dt), content); ns = xmlNewNs(node, DT_nsURI, BAD_CAST "dt"); xmlSetNs(node, ns); xmlDocSetRootElement(tmp_doc, node); hr = Schema_validate_tree(datatypes_schema, (xmlNodePtr)tmp_doc); xmlFreeDoc(tmp_doc); } else { /* probably the node is being created manually and has no content yet */ hr = S_OK; } return hr; default: FIXME("need to handle dt:%s\n", dt_to_str(dt)); return S_OK; } }
static void noit_capabilities_tobuff(noit_capsvc_closure_t *cl, eventer_func_t curr) { char vbuff[128]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; struct timeval now; xmlDocPtr xmldoc; xmlNodePtr root, cmds; /* fill out capabilities */ /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noit_capabilities", NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ noit_build_version(vbuff, sizeof(vbuff)); xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); /* time (poor man's time check) */ gettimeofday(&now, NULL); snprintf(vbuff, sizeof(vbuff), "%llu.%03d", (unsigned long long)now.tv_sec, (int)(now.tv_usec / 1000)); xmlNewTextChild(root, NULL, (xmlChar *)"current_time", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == curr) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } /* Write it out to a buffer and copy it for writing */ cl->buff = noit_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); }
static int rest_set_filter(noit_http_rest_closure_t *restc, int npats, char **pats) { noit_http_session_ctx *ctx = restc->http_ctx; xmlDocPtr doc = NULL, indoc = NULL; xmlNodePtr node, parent, root, newfilter; char xpath[1024]; int error_code = 500, complete = 0, mask = 0; const char *error = "internal error"; if(npats != 2) goto error; indoc = rest_get_xml_upload(restc, &mask, &complete); if(!complete) return mask; if(indoc == NULL) FAIL("xml parse error"); snprintf(xpath, sizeof(xpath), "//filtersets%sfilterset[@name=\"%s\"]", pats[0], pats[1]); node = noit_conf_get_section(NULL, xpath); if(!node && noit_filter_exists(pats[1])) { /* It's someone else's */ error_code = 403; goto error; } if((newfilter = validate_filter_post(indoc)) == NULL) goto error; xmlSetProp(newfilter, (xmlChar *)"name", (xmlChar *)pats[1]); parent = make_conf_path(pats[0]); if(!parent) FAIL("invalid path"); if(node) { xmlUnlinkNode(node); xmlFreeNode(node); } xmlUnlinkNode(newfilter); xmlAddChild(parent, newfilter); CONF_DIRTY(newfilter); noit_conf_mark_changed(); if(noit_conf_write_file(NULL) != 0) noitL(noit_error, "local config write failed\n"); noit_filter_compile_add(newfilter); if(restc->call_closure_free) restc->call_closure_free(restc->call_closure); restc->call_closure_free = NULL; restc->call_closure = NULL; restc->fastpath = rest_show_filter; return restc->fastpath(restc, restc->nparams, restc->params); error: noit_http_response_standard(ctx, error_code, "ERROR", "text/html"); doc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(doc, NULL, (xmlChar *)"error", NULL); xmlDocSetRootElement(doc, root); xmlNodeAddContent(root, (xmlChar *)error); noit_http_response_xml(ctx, doc); noit_http_response_end(ctx); goto cleanup; cleanup: if(doc) xmlFreeDoc(doc); return 0; }
void ags_select_acceleration_dialog_apply(AgsApplicable *applicable) { AgsSelectAccelerationDialog *select_acceleration_dialog; AgsWindow *window; AgsAutomationEditor *automation_editor; AgsMachine *machine; AgsNotebook *notebook; AgsAudio *audio; xmlDoc *clipboard; xmlNode *audio_node, *automation_node; GList *start_list_automation, *list_automation; GList *port, *port_start; GList *list; gchar **specifier; xmlChar *buffer; gchar *str; GType channel_type; gdouble gui_y; gdouble c_y0, c_y1; gdouble val; gdouble upper, lower, range, step; gdouble c_upper, c_lower, c_range; int size; guint x0, y0; guint x1, y1; guint i; gint line; gboolean copy_selection; select_acceleration_dialog = AGS_SELECT_ACCELERATION_DIALOG(applicable); window = (AgsWindow *) select_acceleration_dialog->main_window; automation_editor = window->automation_window->automation_editor; machine = automation_editor->selected_machine; if(machine == NULL || automation_editor->focused_automation_edit == NULL){ return; } notebook = NULL; if(automation_editor->focused_automation_edit->channel_type == G_TYPE_NONE){ notebook = NULL; channel_type = G_TYPE_NONE; }else if(automation_editor->focused_automation_edit->channel_type == AGS_TYPE_OUTPUT){ notebook = automation_editor->output_notebook; channel_type = AGS_TYPE_OUTPUT; }else if(automation_editor->focused_automation_edit->channel_type == AGS_TYPE_INPUT){ notebook = automation_editor->input_notebook; channel_type = AGS_TYPE_INPUT; } audio = machine->audio; g_object_get(audio, "automation", &start_list_automation, NULL); /* get some values */ copy_selection = gtk_toggle_button_get_active((GtkToggleButton *) select_acceleration_dialog->copy_selection); x0 = (AGS_SELECT_ACCELERATION_DEFAULT_WIDTH / 16) * gtk_spin_button_get_value_as_int(select_acceleration_dialog->select_x0); x1 = (AGS_SELECT_ACCELERATION_DEFAULT_WIDTH / 16) * gtk_spin_button_get_value_as_int(select_acceleration_dialog->select_x1); /* select acceleration */ port = port_start = gtk_container_get_children((GtkContainer *) select_acceleration_dialog->port); specifier = NULL; if(copy_selection){ /* create document */ clipboard = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); /* create root node */ audio_node = xmlNewNode(NULL, BAD_CAST "audio"); xmlDocSetRootElement(clipboard, audio_node); } for(i = 0; port != NULL;){ list = gtk_container_get_children((GtkContainer *) port->data); str = gtk_combo_box_text_get_active_text(list->data); g_list_free(list); if(specifier != NULL && g_strv_contains(specifier, str)){ port = port->next; continue; } if(specifier == NULL){ specifier = (gchar **) malloc(2 * sizeof(gchar *)); }else{ specifier = (gchar **) realloc(specifier, (i + 2) * sizeof(gchar *)); } specifier[i] = str; specifier[i + 1] = NULL; line = 0; while((line = ags_notebook_next_active_tab(notebook, line)) != -1){ list_automation = start_list_automation; while((list_automation = ags_automation_find_specifier_with_type_and_line(list_automation, specifier[i], channel_type, line)) != NULL){ AgsAutomation *current_automation; AgsPort *current_port; AgsConversion *conversion; AgsTimestamp *timestamp; current_automation = list_automation->data; g_object_get(current_automation, "timestamp", ×tamp, NULL); g_object_unref(timestamp); if(ags_timestamp_get_ags_offset(timestamp) + AGS_AUTOMATION_DEFAULT_OFFSET < x0){ list_automation = list_automation->next; continue; } if(ags_timestamp_get_ags_offset(timestamp) > x1){ break; } g_object_get(current_automation, "port", ¤t_port, "upper", &upper, "lower", &lower, NULL); g_object_get(current_port, "conversion", &conversion, NULL); range = upper - lower; if(conversion != NULL){ c_upper = ags_conversion_convert(conversion, upper, FALSE); c_lower = ags_conversion_convert(conversion, lower, FALSE); c_range = c_upper - c_lower; g_object_unref(conversion); }else{ c_upper = upper; c_lower = lower; c_range = range; } g_object_unref(current_port); if(range == 0.0){ list_automation = list_automation->next; g_warning("ags_select_acceleration_dialog.c - range = 0.0"); continue; } /* check steps */ g_object_get(current_automation, "steps", &gui_y, NULL); val = c_lower + (gui_y * (c_range / gui_y)); c_y0 = val; /* conversion */ if(conversion != NULL){ c_y0 = ags_conversion_convert(conversion, c_y0, TRUE); } /* check steps */ gui_y = 0; val = c_lower + (gui_y * (c_range / gui_y)); c_y1 = val; /* conversion */ if(conversion != NULL){ c_y1 = ags_conversion_convert(conversion, c_y1, TRUE); } /* select */ ags_automation_add_region_to_selection(current_automation, x0 * AGS_SELECT_ACCELERATION_DEFAULT_WIDTH, c_y0, x1 * AGS_SELECT_ACCELERATION_DEFAULT_WIDTH, c_y1, TRUE); if(copy_selection){ automation_node = ags_automation_copy_selection(list_automation->data); xmlAddChild(audio_node, automation_node); } list_automation = list_automation->next; } line++; } port = port->next; i++; } g_strfreev(specifier); g_list_free_full(start_list_automation, g_object_unref); g_list_free(port_start); /* write to clipboard */ if(copy_selection){ xmlDocDumpFormatMemoryEnc(clipboard, &buffer, &size, "UTF-8", TRUE); gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, size); gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); xmlFreeDoc(clipboard); } }
/* build an XML doc containing information about currently running sources. * If a mountpoint is passed then that source will not be added to the XML * doc even if the source is running */ xmlDocPtr admin_build_sourcelist (const char *mount) { avl_node *node; source_t *source; xmlNodePtr xmlnode, srcnode; xmlDocPtr doc; char buf[22]; time_t now = time(NULL); doc = xmlNewDoc(XMLSTR("1.0")); xmlnode = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL); xmlDocSetRootElement(doc, xmlnode); if (mount) { xmlNewChild(xmlnode, NULL, XMLSTR("current_source"), XMLSTR(mount)); } node = avl_get_first(global.source_tree); while(node) { source = (source_t *)node->key; if (mount && strcmp (mount, source->mount) == 0) { node = avl_get_next (node); continue; } thread_mutex_lock (&source->lock); if (source_available (source)) { ice_config_t *config; mount_proxy *mountinfo; srcnode = xmlNewChild (xmlnode, NULL, XMLSTR("source"), NULL); xmlSetProp (srcnode, XMLSTR("mount"), XMLSTR(source->mount)); snprintf (buf, sizeof(buf), "%lu", source->listeners); xmlNewChild (srcnode, NULL, XMLSTR("listeners"), XMLSTR(buf)); config = config_get_config(); mountinfo = config_find_mount (config, source->mount); if (mountinfo) { if (mountinfo->auth) { xmlNewChild (srcnode, NULL, XMLSTR("authenticator"), XMLSTR(mountinfo->auth->type)); } if (mountinfo->fallback_mount) xmlNewChild (srcnode, NULL, XMLSTR("fallback"), XMLSTR(mountinfo->fallback_mount)); } config_release_config(); if (source_running (source)) { if (source->client) { snprintf (buf, sizeof(buf), "%lu", (unsigned long)(now - source->client->connection.con_time)); xmlNewChild (srcnode, NULL, XMLSTR("Connected"), XMLSTR(buf)); } xmlNewChild (srcnode, NULL, XMLSTR("content-type"), XMLSTR(source->format->contenttype)); } } thread_mutex_unlock (&source->lock); node = avl_get_next(node); } return(doc); }
int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id, int is_terminated) { xmlDocPtr sip_doc= NULL; xmlDocPtr doc= NULL; xmlNodePtr xmpp_root= NULL; xmlNodePtr sip_root= NULL; xmlNodePtr new_node= NULL; xmlNodePtr node = NULL; xmlBufferPtr buffer= NULL; xmlAttrPtr attr= NULL; char* basic= NULL, *priority= NULL, *note= NULL; str xmpp_msg; LM_DBG("start...\n"); /* creating the xml doc for the xmpp message*/ doc= xmlNewDoc(0); if(doc== NULL) { LM_ERR("when creating new xml doc\n"); goto error; } xmpp_root = xmlNewNode(NULL, BAD_CAST "presence"); if(xmpp_root==0) { LM_ERR("when adding new node- presence\n"); goto error; } xmlDocSetRootElement(doc, xmpp_root); attr= xmlNewProp(xmpp_root, BAD_CAST "to", BAD_CAST to_uri->s); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } attr= xmlNewProp(xmpp_root, BAD_CAST "from", BAD_CAST from_uri->s); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } if(is_terminated) { attr= xmlNewProp(xmpp_root, BAD_CAST "type", BAD_CAST "unsubscribed"); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } goto done; } if(body->s== NULL) { attr= xmlNewProp(xmpp_root, BAD_CAST "type", BAD_CAST "unavailable"); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } goto done; } /*extractiong the information from the sip message body*/ sip_doc= xmlParseMemory(body->s, body->len); if(sip_doc== NULL) { LM_ERR("while parsing xml memory\n"); return -1; } sip_root= XMLDocGetNodeByName(sip_doc, "presence", NULL); if(sip_root== NULL) { LM_ERR("while extracting 'presence' node\n"); goto error; } node = XMLNodeGetNodeByName(sip_root, "basic", NULL); if(node== NULL) { LM_ERR("while extracting status basic node\n"); goto error; } basic= (char*)xmlNodeGetContent(node); if(basic== NULL) { LM_ERR("while extracting status basic node content\n"); goto error; } if(xmlStrcasecmp( (unsigned char*)basic,(unsigned char*) "closed")==0 ) { attr= xmlNewProp(xmpp_root, BAD_CAST "type", BAD_CAST "unavailable"); if(attr== NULL) { LM_ERR("while adding node attr\n"); xmlFree(basic); goto error; } xmlFree(basic); goto done; }/* else the status is open so no type attr should be added */ xmlFree(basic); /* addind show node */ node= XMLNodeGetNodeByName(sip_root, "note", NULL); if(node== NULL) { LM_DBG("No note node found\n"); node= XMLNodeGetNodeByName(sip_root, "person", NULL); if(node== NULL) { LM_DBG("No person node found\n"); goto done; } node= XMLNodeGetNodeByName(node, "note", NULL); if(node== NULL) { LM_DBG("Person node has no note node\n"); goto done; } } note= (char*)xmlNodeGetContent(node); if(note== NULL) { LM_ERR("while extracting note node content\n"); goto error; } if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"away")== 0) { new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "away"); if(new_node== NULL) { LM_ERR("while adding node show: away\n"); goto error; } } else if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"busy")== 0) { new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show" , BAD_CAST "xa"); if(new_node== NULL) { LM_ERR("while adding node show: away\n"); goto error; } } /* if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"on the phone")== 0) { new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "chat"); if(new_node== NULL) { LM_ERR("while adding node show: chat\n"); goto error; } } else if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"idle")== 0) { new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "idle"); if(new_node== NULL) { LM_ERR("while adding node: idle\n"); goto error; } } else */ if((xmlStrcasecmp((unsigned char*)note, (unsigned char*)"dnd")== 0)|| (xmlStrcasecmp((unsigned char*)note, (unsigned char*)"do not disturb")== 0)) { new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "dnd"); if(new_node== NULL) { LM_ERR("while adding node show: dnd\n"); goto error; } } /* adding status node */ new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "status", BAD_CAST note); if(new_node== NULL) { LM_ERR("while adding node status\n"); goto error; } xmlFree(note); note= NULL; /* adding priotity node*/ node= XMLNodeGetNodeByName(sip_root, "contact", NULL); if(node== NULL) { LM_DBG("No contact node found\n"); } else { priority= XMLNodeGetAttrContentByName(node, "priority"); if(priority== NULL) LM_DBG("No priority attribute found\n"); else { new_node= xmlNewChild(xmpp_root, NULL, BAD_CAST "priority", BAD_CAST priority); if(sip_root== NULL) { LM_ERR("while adding node\n"); xmlFree(priority); goto error; } xmlFree(priority); } } done: buffer= xmlBufferCreate(); if(buffer== NULL) { LM_ERR("while adding creating new buffer\n"); goto error; } xmpp_msg.len= xmlNodeDump(buffer, doc, xmpp_root, 1,1); if(xmpp_msg.len== -1) { LM_ERR("while dumping node\n"); goto error; } xmpp_msg.s= (char*)xmlBufferContent( buffer); if(xmpp_msg.s== NULL) { LM_ERR("while extracting buffer content\n"); goto error; } LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s); if( xmpp_notify(from_uri, to_uri, &xmpp_msg, id)< 0) { LM_ERR("while sending xmpp_notify\n"); goto error; } xmlBufferFree(buffer); xmlCleanupParser(); xmlMemoryDump(); if(sip_doc) xmlFreeDoc(sip_doc); if(doc) xmlFreeDoc(doc); return 0; error: if(sip_doc) xmlFreeDoc(sip_doc); if(note) xmlFree(note); if(buffer) xmlBufferFree(buffer); xmlCleanupParser(); xmlMemoryDump(); return -1; }
static int command_manageauth (client_t *client, source_t *source, int response) { xmlDocPtr doc; xmlNodePtr node, srcnode, msgnode; const char *action = NULL; const char *username = NULL; const char *message = NULL; int ret = AUTH_OK; ice_config_t *config = config_get_config (); mount_proxy *mountinfo = config_find_mount (config, source->mount); do { if (mountinfo == NULL || mountinfo->auth == NULL) { WARN1 ("manage auth request for %s but no facility available", source->mount); break; } COMMAND_OPTIONAL (client, "action", action); COMMAND_OPTIONAL (client, "username", username); if (action == NULL) action = "list"; if (!strcmp(action, "add")) { const char *password = NULL; COMMAND_OPTIONAL (client, "password", password); if (username == NULL || password == NULL) { WARN1 ("manage auth request add for %s but no user/pass", source->mount); break; } ret = mountinfo->auth->adduser(mountinfo->auth, username, password); if (ret == AUTH_FAILED) { message = "User add failed - check the icecast error log"; } if (ret == AUTH_USERADDED) { message = "User added"; } if (ret == AUTH_USEREXISTS) { message = "User already exists - not added"; } } if (!strcmp(action, "delete")) { if (username == NULL) { WARN1 ("manage auth request delete for %s but no username", source->mount); break; } ret = mountinfo->auth->deleteuser(mountinfo->auth, username); if (ret == AUTH_FAILED) { message = "User delete failed - check the icecast error log"; } if (ret == AUTH_USERDELETED) { message = "User deleted"; } } doc = xmlNewDoc(XMLSTR "1.0"); node = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL); srcnode = xmlNewChild(node, NULL, XMLSTR("source"), NULL); xmlSetProp(srcnode, XMLSTR "mount", XMLSTR(source->mount)); thread_mutex_unlock (&source->lock); if (message) { msgnode = xmlNewChild(node, NULL, XMLSTR("iceresponse"), NULL); xmlNewChild(msgnode, NULL, XMLSTR "message", XMLSTR(message)); } xmlDocSetRootElement(doc, node); if (mountinfo && mountinfo->auth && mountinfo->auth->listuser) mountinfo->auth->listuser (mountinfo->auth, srcnode); config_release_config (); return admin_send_response (doc, client, response, "manageauth.xsl"); } while (0); thread_mutex_unlock (&source->lock); config_release_config (); return client_send_400 (client, "missing parameter"); }
int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg) { /* named according to the direction of the message in xmpp*/ str from_uri; str to_uri; xmlDocPtr doc= NULL; xmlNodePtr root_node= NULL, node = NULL; xmlAttrPtr attr= NULL; str xmpp_msg; int code; str reason; char* err_reason= NULL; xmlBufferPtr buffer= NULL; char buf_to[256]; LM_DBG("*** Entered the callback\n"); URI_ADD_NULL_TERM(to_uri, buf_to, hentity->watcher_uri); from_uri.s = xmpp_uri_sip2xmpp(hentity->pres_uri); if(from_uri.s == NULL) { LM_ERR("Failed to traslate sip uri to xmpp uri\n"); return -1; } from_uri.len= strlen(from_uri.s); doc= xmlNewDoc(BAD_CAST "1.0"); if(doc==0) goto error; root_node = xmlNewNode(NULL, BAD_CAST "presence"); if(root_node==0) goto error; xmlDocSetRootElement(doc, root_node); attr= xmlNewProp(root_node, BAD_CAST "to", BAD_CAST to_uri.s); if(attr== NULL) { LM_ERR("while adding attribute to\n"); goto error; } attr= xmlNewProp(root_node, BAD_CAST "from", BAD_CAST from_uri.s); if(attr== NULL) { LM_ERR("while adding attribute from\n"); goto error; } if(msg== FAKED_REPLY) { code = 408; reason.s= "Request Timeout"; reason.len= strlen(reason.s)- 1; } else { code= msg->first_line.u.reply.statuscode; reason= msg->first_line.u.reply.reason; } LM_DBG("SIP reply code=%d ; to_uri= %s ; from_uri= %s\n", code, to_uri.s, from_uri.s); if(code>=300) { err_reason= get_error_reason(code, &reason); if(err_reason== NULL) { LM_ERR("couldn't get response phrase\n"); goto error; } attr= xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "error"); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } node= xmlNewChild(root_node, 0, BAD_CAST "error", 0 ); if(node== NULL) { LM_ERR("while adding new node\n"); goto error; } node= xmlNewChild(node, 0, BAD_CAST err_reason, 0 ); if(node== NULL) { LM_ERR("while adding new node\n"); goto error; } attr= xmlNewProp(node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:xmpp-stanzas"); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } } else { if(code>=200 ) { attr= xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "subscribed"); if(attr== NULL) { LM_ERR("while adding new attribute\n"); goto error; } } } buffer= xmlBufferCreate(); if(buffer== NULL) { LM_ERR("while adding creating new buffer\n"); goto error; } xmpp_msg.len= xmlNodeDump(buffer, doc, root_node, 1,1); if(xmpp_msg.len== -1) { LM_ERR("while dumping node\n"); goto error; } xmpp_msg.s= (char*)xmlBufferContent( buffer); if(xmpp_msg.s== NULL) { LM_ERR("while extracting buffer content\n"); goto error; } LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s); if(xmpp_packet(&from_uri, &to_uri, &xmpp_msg, &hentity->to_tag)< 0) { LM_ERR("while sending xmpp_reply_to_subscribe\n"); goto error; } if(err_reason) pkg_free(err_reason); xmlFreeDoc(doc); return 0; error: if(doc) xmlFreeDoc(doc); if(err_reason) pkg_free(err_reason); return -1; }
static int command_metadata (client_t *client, source_t *source, int response) { const char *song, *title, *artist, *artwork, *charset, *url; format_plugin_t *plugin; xmlDocPtr doc; xmlNodePtr node; int same_ip = 1; doc = xmlNewDoc(XMLSTR("1.0")); node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL); xmlDocSetRootElement(doc, node); DEBUG0("Got metadata update request"); COMMAND_OPTIONAL(client, "song", song); COMMAND_OPTIONAL(client, "title", title); COMMAND_OPTIONAL(client, "artist", artist); COMMAND_OPTIONAL(client, "url", url); COMMAND_OPTIONAL(client, "artwork", artwork); COMMAND_OPTIONAL(client, "charset", charset); plugin = source->format; if (source_running (source)) if (strcmp (client->connection.ip, source->client->connection.ip) != 0) if (response == RAW && connection_check_admin_pass (client->parser) == 0) same_ip = 0; do { if (same_ip == 0 || plugin == NULL) break; if (artwork) stats_event (source->mount, "artwork", artwork); if (plugin->set_tag) { if (url) { plugin->set_tag (plugin, "url", url, charset); INFO2 ("Metadata url on %s set to \"%s\"", source->mount, url); } if (song) { plugin->set_tag (plugin, "artist", NULL, NULL); plugin->set_tag (plugin, "title", song, charset); INFO2("Metadata song on %s set to \"%s\"", source->mount, song); } if (artist) { plugin->set_tag (plugin, "artist", artist, charset); INFO2 ("Metadata artist on %s changed to \"%s\"", source->mount, artist); } if (title) { plugin->set_tag (plugin, "title", title, charset); INFO2 ("Metadata title on %s changed to \"%s\"", source->mount, title); } /* updates are now done, let them be pushed into the stream */ plugin->set_tag (plugin, NULL, NULL, charset); } else { break; } thread_mutex_unlock (&source->lock); xmlNewChild(node, NULL, XMLSTR("message"), XMLSTR("Metadata update successful")); xmlNewChild(node, NULL, XMLSTR("return"), XMLSTR("1")); return admin_send_response(doc, client, response, "response.xsl"); } while (0); INFO1 ("Metadata on mountpoint %s prevented", source->mount); thread_mutex_unlock (&source->lock); xmlNewChild(node, NULL, XMLSTR("message"), XMLSTR("Mountpoint will not accept this URL update")); xmlNewChild(node, NULL, XMLSTR("return"), XMLSTR("1")); return admin_send_response(doc, client, response, "response.xsl"); }
/* {{{ proto DOMDocument dom_domimplementation_create_document(string namespaceURI, string qualifiedName, DOMDocumentType doctype); URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocument Since: DOM Level 2 */ PHP_METHOD(domimplementation, createDocument) { zval *node = NULL; xmlDoc *docp; xmlNode *nodep; xmlDtdPtr doctype = NULL; xmlNsPtr nsptr = NULL; int ret, uri_len = 0, name_len = 0, errorcode = 0; char *uri = NULL, *name = NULL; char *prefix = NULL, *localname = NULL; dom_object *doctobj; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssO", &uri, &uri_len, &name, &name_len, &node, dom_documenttype_class_entry) == FAILURE) { return; } if (node != NULL) { DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj); if (doctype->type == XML_DOCUMENT_TYPE_NODE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object"); RETURN_FALSE; } if (doctype->doc != NULL) { php_dom_throw_error(WRONG_DOCUMENT_ERR, 1 TSRMLS_CC); RETURN_FALSE; } } else { doctobj = NULL; } if (name_len > 0) { errorcode = dom_check_qname(name, &localname, &prefix, 1, name_len); if (errorcode == 0 && uri_len > 0 && ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL)) { errorcode = NAMESPACE_ERR; } } if (prefix != NULL) { xmlFree(prefix); } if (errorcode != 0) { if (localname != NULL) { xmlFree(localname); } php_dom_throw_error(errorcode, 1 TSRMLS_CC); RETURN_FALSE; } /* currently letting libxml2 set the version string */ docp = xmlNewDoc(NULL); if (!docp) { if (localname != NULL) { xmlFree(localname); } RETURN_FALSE; } if (doctype != NULL) { docp->intSubset = doctype; doctype->parent = docp; doctype->doc = docp; docp->children = (xmlNodePtr) doctype; docp->last = (xmlNodePtr) doctype; } if (localname != NULL) { nodep = xmlNewDocNode (docp, nsptr, localname, NULL); if (!nodep) { if (doctype != NULL) { docp->intSubset = NULL; doctype->parent = NULL; doctype->doc = NULL; docp->children = NULL; docp->last = NULL; } xmlFreeDoc(docp); xmlFree(localname); /* Need some type of error here */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error"); RETURN_FALSE; } nodep->nsDef = nsptr; xmlDocSetRootElement(docp, nodep); xmlFree(localname); } DOM_RET_OBJ((xmlNodePtr) docp, &ret, NULL); if (doctobj != NULL) { doctobj->document = ((dom_object *)((php_libxml_node_ptr *)docp->_private)->_private)->document; php_libxml_increment_doc_ref((php_libxml_node_object *)doctobj, docp TSRMLS_CC); } }
static int EBC_Provider_XchgHpbRequest_H003(AB_PROVIDER *pro, GWEN_HTTP_SESSION *sess, AB_USER *u) { EBC_PROVIDER *dp; int rv; GWEN_CRYPT_TOKEN *ct; const GWEN_CRYPT_TOKEN_CONTEXT *ctx; uint32_t keyId; xmlNsPtr ns; EB_MSG *msg; EB_MSG *mRsp; EB_RC rc; xmlDocPtr doc; xmlNodePtr root_node = NULL; xmlNodePtr node = NULL; xmlNodePtr sigNode = NULL; GWEN_BUFFER *tbuf; const char *s; assert(pro); dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro); assert(dp); /* get crypt token and context */ rv=EBC_Provider_MountToken(pro, u, &ct, &ctx); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); return rv; } /* create request */ msg=EB_Msg_new(); doc=EB_Msg_GetDoc(msg); root_node=xmlNewNode(NULL, BAD_CAST "ebicsNoPubKeyDigestsRequest"); xmlDocSetRootElement(doc, root_node); ns=xmlNewNs(root_node, BAD_CAST "http://www.ebics.org/H003", NULL); assert(ns); ns=xmlNewNs(root_node, BAD_CAST "http://www.w3.org/2000/09/xmldsig#", BAD_CAST "ds"); assert(ns); ns=xmlNewNs(root_node, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", BAD_CAST "xsi"); xmlNewNsProp(root_node, ns, BAD_CAST "schemaLocation", /* xsi:schemaLocation */ BAD_CAST "http://www.ebics.org/H003 " "http://www.ebics.org/H003/ebics_keymgmt_request.xsd"); xmlNewProp(root_node, BAD_CAST "Version", BAD_CAST "H003"); xmlNewProp(root_node, BAD_CAST "Revision", BAD_CAST "1"); /* header */ node=xmlNewChild(root_node, NULL, BAD_CAST "header", NULL); xmlNewProp(node, BAD_CAST "authenticate", BAD_CAST "true"); xmlNewChild(node, NULL, BAD_CAST "static", NULL); xmlNewChild(node, NULL, BAD_CAST "mutable", NULL); sigNode=xmlNewChild(root_node, NULL, BAD_CAST "AuthSignature", NULL); /* body */ node=xmlNewChild(root_node, NULL, BAD_CAST "body", NULL); /* fill */ s=EBC_User_GetPeerId(u); if (s) EB_Msg_SetCharValue(msg, "header/static/HostID", s); /* generate Nonce */ tbuf=GWEN_Buffer_new(0, 128, 0, 1); rv=EBC_Provider_GenerateNonce(pro, tbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); EB_Msg_free(msg); return rv; } EB_Msg_SetCharValue(msg, "header/static/Nonce", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_Reset(tbuf); /* generate timestamp */ rv=EBC_Provider_GenerateTimeStamp(pro, u, tbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); EB_Msg_free(msg); return rv; } EB_Msg_SetCharValue(msg, "header/static/Timestamp", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); s=AB_User_GetCustomerId(u); if (s) EB_Msg_SetCharValue(msg, "header/static/PartnerID", s); EB_Msg_SetCharValue(msg, "header/static/UserID", AB_User_GetUserId(u)); EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderType", "HPB"); EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderAttribute", "DZHNN"); EB_Msg_SetCharValue(msg, "header/static/SecurityMedium", "0000"); /* sign */ rv=EBC_Provider_SignMessage(pro, msg, u, sigNode); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); EB_Msg_free(msg); return rv; } /* exchange requests */ rv=EBC_Dialog_ExchangeMessages(sess, msg, &mRsp); if (rv<0 || rv>=300) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv); EB_Msg_free(msg); return rv; } EB_Msg_free(msg); /* check response */ assert(mRsp); /* log results */ EBC_Provider_LogRequestResults(pro, mRsp, NULL); rc=EB_Msg_GetResultCode(mRsp); if ((rc & 0xff0000)==0x090000 || (rc & 0xff0000)==0x060000) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc); EB_Msg_free(mRsp); return AB_ERROR_SECURITY; } rc=EB_Msg_GetBodyResultCode(mRsp); if (rc) { if ((rc & 0xff0000)==0x090000 || (rc & 0xff0000)==0x060000) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc); EB_Msg_free(mRsp); if ((rc & 0xfff00)==0x091300 || (rc & 0xfff00)==0x091200) return AB_ERROR_SECURITY; else return GWEN_ERROR_GENERIC; } } if (1) { xmlDocPtr orderDoc=NULL; xmlNodePtr root_node=NULL; xmlNodePtr node=NULL; GWEN_CRYPT_KEY *skey=NULL; GWEN_BUFFER *buf1; GWEN_BUFFER *buf2; const char *s; /* extract keys and store them */ node=EB_Xml_GetNode(EB_Msg_GetRootNode(mRsp), "body/DataTransfer/DataEncryptionInfo", GWEN_PATH_FLAGS_NAMEMUSTEXIST); if (node==NULL) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Bad message from server: Missing session key"); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } rv=EBC_Provider_ExtractSessionKey(pro, u, node, &skey); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); EB_Msg_free(mRsp); return rv; } s=EB_Msg_GetCharValue(mRsp, "body/DataTransfer/OrderData", NULL); if (!s) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Bad message from server: Missing OrderData"); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } buf1=GWEN_Buffer_new(0, strlen(s), 0, 1); rv=GWEN_Base64_Decode((const uint8_t*)s, 0, buf1); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "Could not decode OrderData (%d)", rv); GWEN_Buffer_free(buf1); EB_Msg_free(mRsp); return rv; } /* decode data */ buf2=GWEN_Buffer_new(0, GWEN_Buffer_GetUsedBytes(buf1), 0, 1); rv=EBC_Provider_DecryptData(pro, u, skey, (const uint8_t*)GWEN_Buffer_GetStart(buf1), GWEN_Buffer_GetUsedBytes(buf1), buf2); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "Could not decrypt OrderData (%d)", rv); GWEN_Buffer_free(buf2); GWEN_Buffer_free(buf1); return rv; } /* parse XML document */ rv=EB_Xml_DocFromBuffer(GWEN_Buffer_GetStart(buf2), GWEN_Buffer_GetUsedBytes(buf2), &orderDoc); GWEN_Buffer_free(buf2); GWEN_Buffer_free(buf1); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); EB_Msg_free(mRsp); return rv; } /* get keys */ root_node=xmlDocGetRootElement(orderDoc); /* get auth key */ node=EB_Xml_GetNode(root_node, "AuthenticationPubKeyInfo", GWEN_PATH_FLAGS_NAMEMUSTEXIST); if (node==NULL) { DBG_ERROR(AQEBICS_LOGDOMAIN, "No authentication key found"); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } else { const GWEN_CRYPT_TOKEN_KEYINFO *cki; GWEN_CRYPT_TOKEN_KEYINFO *ki; keyId=GWEN_Crypt_Token_Context_GetAuthVerifyKeyId(ctx); cki=GWEN_Crypt_Token_GetKeyInfo(ct, keyId, 0, 0); if (cki) ki=GWEN_Crypt_Token_KeyInfo_dup(cki); else ki=GWEN_Crypt_Token_KeyInfo_new(keyId, GWEN_Crypt_CryptAlgoId_Rsa, 128); GWEN_Crypt_Token_KeyInfo_SetFlags(ki, 0); rc=EB_Key_Info_ReadXml(ki, node); if (rc) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%06x)", rc); GWEN_Crypt_Token_KeyInfo_free(ki); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } rv=GWEN_Crypt_Token_SetKeyInfo(ct, keyId, ki, 0); GWEN_Crypt_Token_KeyInfo_free(ki); if (rv) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return rv; } DBG_NOTICE(AQEBICS_LOGDOMAIN, "Auth key stored"); } /* get crypt key */ node=EB_Xml_GetNode(root_node, "EncryptionPubKeyInfo", GWEN_PATH_FLAGS_NAMEMUSTEXIST); if (node==NULL) { DBG_ERROR(AQEBICS_LOGDOMAIN, "No encryption key found"); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } else { const GWEN_CRYPT_TOKEN_KEYINFO *cki; GWEN_CRYPT_TOKEN_KEYINFO *ki; keyId=GWEN_Crypt_Token_Context_GetEncipherKeyId(ctx); cki=GWEN_Crypt_Token_GetKeyInfo(ct, keyId, 0, 0); if (cki) ki=GWEN_Crypt_Token_KeyInfo_dup(cki); else ki=GWEN_Crypt_Token_KeyInfo_new(keyId, GWEN_Crypt_CryptAlgoId_Rsa, 128); GWEN_Crypt_Token_KeyInfo_SetFlags(ki, 0); rc=EB_Key_Info_ReadXml(ki, node); if (rc) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%06x)", rc); GWEN_Crypt_Token_KeyInfo_free(ki); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return GWEN_ERROR_BAD_DATA; } rv=GWEN_Crypt_Token_SetKeyInfo(ct, keyId, ki, 0); GWEN_Crypt_Token_KeyInfo_free(ki); if (rv) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); xmlFreeDoc(orderDoc); EB_Msg_free(mRsp); return rv; } DBG_NOTICE(AQEBICS_LOGDOMAIN, "Crypt key stored"); } xmlFreeDoc(orderDoc); } EB_Msg_free(mRsp); /* adjust user status and flags */ DBG_NOTICE(AQEBICS_LOGDOMAIN, "Adjusting user flags"); if ((EBC_User_GetFlags(u) & (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA)) == (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA)) EBC_User_SetStatus(u, EBC_UserStatus_Enabled); return 0; }
cXmlNode cXmlDoc::root(cXmlNode& newroot) { if (!m_doc) throw eXmlInvalid("Tried to set root for bad document"); return cXmlNode(xmlDocSetRootElement(m_doc.get(), newroot.getRaw(m_doc)), true); }
/* * 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); }
/** * testXmlwriterTree: * @file: the output file * * test the xmlWriter interface when writing to a subtree */ void testXmlwriterTree(const char *file) { int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlNodePtr node; xmlChar *tmp; /* Create a new XML DOM tree, to which the XML document will be * written */ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); if (doc == NULL) { printf ("testXmlwriterTree: Error creating the xml document tree\n"); return; } /* Create a new XML node, to which the XML document will be * appended */ node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL); if (node == NULL) { printf("testXmlwriterTree: Error creating the xml node\n"); return; } /* Make ELEMENT the root node of the tree */ xmlDocSetRootElement(doc, node); /* Create a new XmlWriter for DOM tree, with no compression. */ writer = xmlNewTextWriterTree(doc, node, 0); if (writer == NULL) { printf("testXmlwriterTree: Error creating the xml writer\n"); return; } /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartDocument\n"); return; } /* Write a comment as child of EXAMPLE. * Please observe, that the input to the xmlTextWriter functions * HAS to be in UTF-8, even if the output XML is encoded * in iso-8859-1 */ tmp = ConvertInput("This is a comment with special chars: <äöü>", MY_ENCODING); rc = xmlTextWriterWriteComment(writer, tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "ORDER" as child of EXAMPLE. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Add an attribute with name "version" and value "1.0" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Add an attribute with name "xml:lang" and value "de" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", BAD_CAST "de"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Write a comment as child of ORDER */ tmp = ConvertInput("<äöü>", MY_ENCODING); rc = xmlTextWriterWriteFormatComment(writer, "This is another comment with special chars: %s", tmp); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "HEADER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "X_ORDER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID", "%010d", 53535); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "CUSTOMER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID", "%d", 1010); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "NAME_1" as child of HEADER. */ tmp = ConvertInput("Müller", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Write an element named "NAME_2" as child of HEADER. */ tmp = ConvertInput("Jörg", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Close the element named HEADER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRIES" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test>"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 10); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test 2>"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 20); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Close the element named ENTRIES. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "FOOTER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "TEXT" as child of FOOTER. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT", BAD_CAST "This is a text."); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Close the element named FOOTER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Here we could close the elements ORDER and EXAMPLE using the * function xmlTextWriterEndElement, but since we do not want to * write any other elements, we simply call xmlTextWriterEndDocument, * which will do all the work. */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndDocument\n"); return; } xmlFreeTextWriter(writer); xmlSaveFileEnc(file, doc, MY_ENCODING); xmlFreeDoc(doc); }
xmlNode *oval_definition_model_to_dom(struct oval_definition_model *definition_model, xmlDocPtr doc, xmlNode * parent) { xmlNodePtr root_node = NULL; if (parent) { /* result file */ root_node = xmlNewTextChild(parent, NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS, NULL); } else { /* definitions file, we are the root */ root_node = xmlNewNode(NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS); xmlDocSetRootElement(doc, root_node); } xmlNewProp(root_node, BAD_CAST "xsi:schemaLocation", BAD_CAST definition_model->schema); xmlNs *ns_common = xmlNewNs(root_node, OVAL_COMMON_NAMESPACE, BAD_CAST "oval"); xmlNs *ns_xsi = xmlNewNs(root_node, OVAL_XMLNS_XSI, BAD_CAST "xsi"); xmlNs *ns_unix = xmlNewNs(root_node, OVAL_DEFINITIONS_UNIX_NS, BAD_CAST "unix-def"); xmlNs *ns_ind = xmlNewNs(root_node, OVAL_DEFINITIONS_IND_NS, BAD_CAST "ind-def"); xmlNs *ns_lin = xmlNewNs(root_node, OVAL_DEFINITIONS_LIN_NS, BAD_CAST "lin-def"); xmlNs *ns_defntns = xmlNewNs(root_node, OVAL_DEFINITIONS_NAMESPACE, NULL); xmlSetNs(root_node, ns_common); xmlSetNs(root_node, ns_xsi); xmlSetNs(root_node, ns_unix); xmlSetNs(root_node, ns_ind); xmlSetNs(root_node, ns_lin); xmlSetNs(root_node, ns_defntns); /* Always report the generator */ oval_generator_to_dom(definition_model->generator, doc, root_node); /* Report definitions */ struct oval_definition_iterator *definitions = oval_definition_model_get_definitions(definition_model); if (oval_definition_iterator_has_more(definitions)) { xmlNode *definitions_node = NULL; while(oval_definition_iterator_has_more(definitions)) { struct oval_definition *definition = oval_definition_iterator_next(definitions); if (definitions_node == NULL) { definitions_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "definitions", NULL); } oval_definition_to_dom(definition, doc, definitions_node); } } oval_definition_iterator_free(definitions); /* Report tests */ struct oval_test_iterator *tests = oval_definition_model_get_tests(definition_model); if (oval_test_iterator_has_more(tests)) { xmlNode *tests_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "tests", NULL); while (oval_test_iterator_has_more(tests)) { struct oval_test *test = oval_test_iterator_next(tests); oval_test_to_dom(test, doc, tests_node); } } oval_test_iterator_free(tests); /* Report objects */ struct oval_object_iterator *objects = oval_definition_model_get_objects(definition_model); if (oval_object_iterator_has_more(objects)) { xmlNode *objects_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "objects", NULL); while(oval_object_iterator_has_more(objects)) { struct oval_object *object = oval_object_iterator_next(objects); if (oval_object_get_base_obj(object)) /* Skip internal objects */ continue; oval_object_to_dom(object, doc, objects_node); } } oval_object_iterator_free(objects); /* Report states */ struct oval_state_iterator *states = oval_definition_model_get_states(definition_model); if (oval_state_iterator_has_more(states)) { xmlNode *states_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "states", NULL); while (oval_state_iterator_has_more(states)) { struct oval_state *state = oval_state_iterator_next(states); oval_state_to_dom(state, doc, states_node); } } oval_state_iterator_free(states); /* Report variables */ struct oval_variable_iterator *variables = oval_definition_model_get_variables(definition_model); if (oval_variable_iterator_has_more(variables)) { xmlNode *variables_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "variables", NULL); while (oval_variable_iterator_has_more(variables)) { struct oval_variable *variable = oval_variable_iterator_next(variables); oval_variable_to_dom(variable, doc, variables_node); } } oval_variable_iterator_free(variables); return root_node; }