void Triggerconf::createConfigElement (string module, string submodule, string configname) { if (rootnode == NULL) return; if (existsConfigElement (module, submodule, configname)) { resetError (); return; } DOMNode* currentSubmodule = selectSubmodule (module, submodule); if (currentSubmodule == NULL) return; XMLCh* xitemname = XMLString::transcode (ELEMENT_CONFIGITEM_NAME); DOMElement* node = rootnode->getOwnerDocument ()->createElement (xitemname); XMLString::release (&xitemname); XMLCh* xattrname = XMLString::transcode (ATTRIBUTE_NAME); XMLCh* xconfigname = XMLString::transcode (configname.c_str ()); node->setAttribute (xattrname, xconfigname); XMLString::release (&xattrname); XMLString::release (&xconfigname); currentSubmodule->appendChild (node); resetError (); }
void Triggerconf::createSubmodule (string module, string submodule) { if (rootnode == NULL) return; if (existsSubmodule (module, submodule)) { resetError (); return; } DOMNode* currentModule = selectModule (module); if (currentModule == NULL) return; XMLCh* xsubmodule = XMLString::transcode (ELEMENT_SUBMODULE_NAME); DOMElement* node = rootnode->getOwnerDocument ()->createElement (xsubmodule); XMLString::release (&xsubmodule); XMLCh* xattrname = XMLString::transcode (ATTRIBUTE_NAME); XMLCh* xsubmodulename = XMLString::transcode (submodule.c_str ()); node->setAttribute (xattrname, xsubmodulename); XMLString::release (&xattrname); XMLString::release (&xsubmodulename); currentModule->appendChild (node); resetError (); }
XmlNode addChild(const char *name) { XMLCh *tempStr = NULL; tempStr = XMLString::transcode(name); DOMElement *element = doc->createElement(tempStr); DOMNode *cnode = node->appendChild(element); XMLString::release(&tempStr); return XmlNode(cnode,doc); }
XmlNode addChild(const char *name, const char *value) { XMLCh *tempStr = NULL; tempStr = XMLString::transcode(name); DOMElement *element = doc->createElement(tempStr); DOMNode *cnode = node->appendChild(element); if (value != NULL) { tempStr = XMLString::transcode(value); element->setTextContent(tempStr); } XMLString::release(&tempStr); return XmlNode(cnode,doc); }
void DOMNodeImpl::setTextContent(const XMLCh* textContent){ DOMNode *thisNode = castToNode(this); switch (thisNode->getNodeType()) { case DOMNode::ELEMENT_NODE: case DOMNode::ENTITY_NODE: case DOMNode::ENTITY_REFERENCE_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: { if (isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); // Remove all childs DOMNode* current = thisNode->getFirstChild(); while (current != NULL) { thisNode->removeChild(current); current = thisNode->getFirstChild(); } if (textContent != NULL) { // Add textnode containing data current = ((DOMDocumentImpl*)thisNode->getOwnerDocument())->createTextNode(textContent); thisNode->appendChild(current); } } break; case DOMNode::ATTRIBUTE_NODE: case DOMNode::TEXT_NODE: case DOMNode::CDATA_SECTION_NODE: case DOMNode::COMMENT_NODE: case DOMNode::PROCESSING_INSTRUCTION_NODE: if (isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); thisNode->setNodeValue(textContent); break; case DOMNode::DOCUMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: case DOMNode::NOTATION_NODE: break; default: throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager); } }
void XercesUpdateFactory::applyInsertAsLast(const PendingUpdate &update, DynamicContext *context) { const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla); DOMNode *domnode = const_cast<DOMNode*>(nodeImpl->getDOMNode()); DOMDocument *doc = const_cast<DOMDocument*>(XPath2Utils::getOwnerDoc(domnode)); bool untyped = nodeImpl->dmNodeKind() == Node::element_string && XPath2Utils::equals(nodeImpl->getTypeName(), DocumentCache::g_szUntyped) && XPath2Utils::equals(nodeImpl->getTypeURI(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA); bool containsElementOrText = false; Result children = update.getValue(); Item::Ptr item; while((item = children->next(context)).notNull()) { const XercesNodeImpl *childImpl = (const XercesNodeImpl*)item->getInterface(Item::gXQilla); DOMNode *newChild = importNodeFix(doc, const_cast<DOMNode*>(childImpl->getDOMNode()), /*deep*/true); if(childImpl->dmNodeKind() == Node::element_string || childImpl->dmNodeKind() == Node::text_string) { containsElementOrText = true; } // If the type-name property of $target is xs:untyped, then upd:setToUntyped() is invoked on each // element or attribute node in $content. if(!untyped) setTypes(newChild, childImpl->getDOMNode()); // For each node in $content, the parent property is set to parent($target). // The children property of $target is modified to add the nodes in $content just before $target, // preserving their order. domnode->appendChild(newChild); } // If at least one of the nodes in $content is an element or text node, upd:removeType($target) is invoked. if(containsElementOrText) { removeType(domnode); } addToPutSet(update.getTarget(), &update, context); }
void DeltaApplyEngine::Subtree_Insert( DOMNode *insertSubtreeRoot, XID_t parentXID, int position, const char *xidmapStr ) { vddprintf(( " insert xidmap=%s at (parent=%d, pos=%d)\n", xidmapStr, (int)parentXID, position)); DOMNode* contentNode = xiddoc->importNode( insertSubtreeRoot, true ); DOMNode* parentNode = xiddoc->getXidMap().getNodeWithXID( parentXID ); if (parentNode==NULL) THROW_AWAY(("parent node with XID=%d not found",(int)parentXID)); int actual_pos = 1 ; if ((position!=1)&&(!parentNode->hasChildNodes())) THROW_AWAY(("parent has no children but position is %d",position)); DOMNode* brother = parentNode->getFirstChild(); while (actual_pos < position) { brother = brother->getNextSibling(); actual_pos++; if ((brother==NULL)&&(actual_pos<position)) THROW_AWAY(("parent has %d children but position is %d",actual_pos-1, position)); } // Add node to the tree if (brother==NULL) parentNode->appendChild( contentNode ); else parentNode->insertBefore( contentNode, brother ); xiddoc->getXidMap().mapSubtree( xidmapStr, contentNode ); }
void XMLSecurityTest::testSign() { xbemsg::header_t hdr("tests.xbe.foo.bar", "tests.xbe.foo.bar"); xbemsg::body_t body; body.any().push_back(body.dom_document().createElementNS(xml::string("http://www.xenbee.net/schema/2008/02/pingpong").c_str(), xml::string("Ping").c_str())); xbemsg::message_t msg(hdr,body); // serialize to DOMDocument xml_schema::dom::auto_ptr< ::xercesc::DOMDocument > doc = xbemsg::message(msg, XbeLibUtils::namespace_infomap()); ::xercesc::DOMElement *rootElem = doc->getDocumentElement(); XSECProvider prov; DSIGSignature *sig; xercesc::DOMElement *sigNode; sig = prov.newSignature(); sig->setDSIGNSPrefix(xml::string("dsig").c_str()); // sig->setECNSPrefix( NULL ); // sig->setXPFNSPrefix(NULL); // sig->setPrettyPrint(false); // Use it to create a blank signature DOM structure from the doc sigNode = sig->createBlankSignature(doc.get(), CANON_C14NE_NOC, SIGNATURE_HMAC, HASH_SHA1); // Insert the signature element at the right place within the document // find the header DOM node DOMNode *hdrNode = rootElem->getFirstChild(); CPPUNIT_ASSERT(hdrNode != 0); char *tmpNodeName = XMLString::transcode(hdrNode->getLocalName()); std::string nodeName(tmpNodeName); XMLString::release(&tmpNodeName); CPPUNIT_ASSERT_EQUAL(nodeName, std::string("header")); hdrNode->appendChild(sigNode); doc->normalizeDocument(); // Create an envelope reference for the text to be signed DSIGReference * ref = sig->createReference(xml::string("").c_str()); ref->appendEnvelopedSignatureTransform(); // Set the HMAC Key to be the string "secret" OpenSSLCryptoProvider cryptoProvider; XSECCryptoKeyHMAC *hmacKey = cryptoProvider.keyHMAC(); hmacKey->setKey((unsigned char *) "secret", strlen("secret")); sig->setSigningKey(hmacKey); // Add a KeyInfo element sig->appendKeyName(MAKE_UNICODE_STRING("The secret key is \"secret\"")); // Sign sig->sign(); xbemsg::message_t signed_msg(*rootElem); std::ostringstream oss; xbemsg::message(oss, signed_msg, XbeLibUtils::namespace_infomap()); // write to an xml file // { // std::ofstream ofs("sig-test-2.xml"); // ofs << oss.str(); // } XBE_LOG_DEBUG(oss.str()); // std::string expected_digest("6gEokD/uXFJHZdGdup83UEJAL7U=\n"); // std::string expected_sigval("t9LLbEU8GHtWrrx+qWTWWujTGEY=\n"); // CPPUNIT_ASSERT_EQUAL(expected_digest, // signed_msg.header().Signature().get().SignedInfo().Reference().begin()->DigestValue().encode()); // CPPUNIT_ASSERT_EQUAL(expected_sigval, // signed_msg.header().Signature().get().SignatureValue().encode()); }
void CTibiaItem::saveItemLists() { if (!xmlInitialised) { XMLPlatformUtils::Initialize(); xmlInitialised = 1; } XercesDOMParser *parser = new XercesDOMParser(); try { //int itemNr; char pathBuf[2048]; sprintf(pathBuf, "%s\\data\\tibiaauto-items.xml", CInstallPath::getInstallPath().c_str()); DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core")); xercesc::DOMDocument *doc = impl->createDocument(0, XMLString::transcode("item-definitions"), 0); doc->createComment((const unsigned short *)"<!-- Tibia Items for Tibia -->"); DOMElement *root = doc->getDocumentElement(); //ITEMS DOMNode *itemsNode = doc->createElement(XMLString::transcode("items")); root->appendChild(itemsNode); //recursively save data structure to XML saveItemsBranch(itemsNode, itemTree, doc); //FOOD DOMNode *foodNode = doc->createElement(XMLString::transcode("foods")); root->appendChild(foodNode); { int size = foodList.GetCount(); for (int i = 0; i < size; i++) { char buf[512]; DOMElement* itemElem = doc->createElement(XMLString::transcode("item")); foodNode->appendChild(itemElem); char* name = foodList.GetTextAtIndex(i); int id = foodList.GetValueAtIndex(i); int time = foodList.GetExtraInfoAtIndex(i); sprintf(buf, "0x%x", id); itemElem->setAttribute(XMLString::transcode("id"), XMLString::transcode(buf)); itemElem->setAttribute(XMLString::transcode("name"), XMLString::transcode(name)); sprintf(buf, "%d", time); itemElem->setAttribute(XMLString::transcode("time"), XMLString::transcode(buf)); } } //CONSTS /* never any need to save constants anymore DOMNode *constsNode = doc->createElement(XMLString::transcode("consts")); root->appendChild(constsNode); int size = constCodeList.GetCount(); for (int i=0;i<size;i++){ char buf[512]; DOMElement* itemElem = doc->createElement(XMLString::transcode("const")); constsNode->appendChild(itemElem); char* code=constCodeList.GetTextAtIndex(i); int value=constCodeList.GetValueAtIndex(i); sprintf(buf, "0x%x", value); itemElem->setAttribute(XMLString::transcode("value"), XMLString::transcode(buf)); itemElem->setAttribute(XMLString::transcode("code"), XMLString::transcode(code)); } */ XMLCh tempStr[100]; XMLString::transcode("LS", tempStr, 99); impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); DOMConfiguration* dc = theSerializer->getDomConfig(); if (dc->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); XMLFormatTarget *outFile = new LocalFileFormatTarget(pathBuf); DOMLSOutput *lsOut = ((DOMImplementationLS*)impl)->createLSOutput(); lsOut->setByteStream(outFile); theSerializer->write(doc, lsOut); theSerializer->release(); lsOut->release(); delete outFile; } catch (...) { AfxMessageBox("Unable to save item definitions!"); } delete parser; }
void CTibiaItem::saveItemLists() { if (!xmlInitialised) { XMLPlatformUtils::Initialize(); xmlInitialised = 1; } char installPath[1024] = { '\0' }; unsigned long installPathLen = 1023; HKEY hkey = NULL; if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Tibia Auto\\", 0, KEY_READ, &hkey)) { RegQueryValueEx(hkey, TEXT("Install_Dir"), NULL, NULL, (unsigned char *)installPath, &installPathLen); RegCloseKey(hkey); } if (!strlen(installPath)) { AfxMessageBox("ERROR! Unable to read TA install directory! Please reinstall!"); PostQuitMessage(-1); return; } XercesDOMParser *parser = new XercesDOMParser(); try { //int itemNr; char pathBuf[2048]; sprintf(pathBuf, "%s\\data\\tibiaauto-items.xml", installPath); DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core")); xercesc::DOMDocument *doc = impl->createDocument(0, XMLString::transcode("item-definitions"), 0); doc->createComment((const unsigned short *)"<!-- Tibia Items for Tibia -->"); DOMElement *root = doc->getDocumentElement(); //ITEMS DOMNode *itemsNode = doc->createElement(XMLString::transcode("items")); root->appendChild(itemsNode); //recursively save data structure to XML saveItemsBranch(itemsNode, itemTree, doc); //FOOD DOMNode *foodNode = doc->createElement(XMLString::transcode("foods")); root->appendChild(foodNode); { int size = foodList.GetCount(); for (int i = 0; i < size; i++) { char buf[512]; DOMElement* itemElem = doc->createElement(XMLString::transcode("item")); foodNode->appendChild(itemElem); char* name = foodList.GetTextAtIndex(i); int id = foodList.GetValueAtIndex(i); int time = foodList.GetExtraInfoAtIndex(i); sprintf(buf, "0x%x", id); itemElem->setAttribute(XMLString::transcode("id"), XMLString::transcode(buf)); itemElem->setAttribute(XMLString::transcode("name"), XMLString::transcode(name)); sprintf(buf, "%d", time); itemElem->setAttribute(XMLString::transcode("time"), XMLString::transcode(buf)); } } //CONSTS /* never any need to save constants anymore DOMNode *constsNode = doc->createElement(XMLString::transcode("consts")); root->appendChild(constsNode); int size = constCodeList.GetCount(); for (int i=0;i<size;i++){ char buf[512]; DOMElement* itemElem = doc->createElement(XMLString::transcode("const")); constsNode->appendChild(itemElem); char* code=constCodeList.GetTextAtIndex(i); int value=constCodeList.GetValueAtIndex(i); sprintf(buf, "0x%x", value); itemElem->setAttribute(XMLString::transcode("value"), XMLString::transcode(buf)); itemElem->setAttribute(XMLString::transcode("code"), XMLString::transcode(code)); } */ XMLCh tempStr[100]; XMLString::transcode("LS", tempStr, 99); impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); DOMConfiguration* dc = theSerializer->getDomConfig(); if (dc->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); XMLFormatTarget *outFile = new LocalFileFormatTarget(pathBuf); DOMLSOutput *lsOut = ((DOMImplementationLS*)impl)->createLSOutput(); lsOut->setByteStream(outFile); theSerializer->write(doc, lsOut); theSerializer->release(); lsOut->release(); delete outFile; } catch (...) { AfxMessageBox("Unable to save item definitions!"); } delete parser; }