std::string DiscoInfoSerializer::serializePayload(boost::shared_ptr<DiscoInfo> discoInfo) const { XMLElement queryElement("query", "http://jabber.org/protocol/disco#info"); if (!discoInfo->getNode().empty()) { queryElement.setAttribute("node", discoInfo->getNode()); } foreach(const DiscoInfo::Identity& identity, discoInfo->getIdentities()) { boost::shared_ptr<XMLElement> identityElement(new XMLElement("identity")); if (!identity.getLanguage().empty()) { identityElement->setAttribute("xml:lang", identity.getLanguage()); } identityElement->setAttribute("category", identity.getCategory()); identityElement->setAttribute("name", identity.getName()); identityElement->setAttribute("type", identity.getType()); queryElement.addNode(identityElement); } foreach(const std::string& feature, discoInfo->getFeatures()) { boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature")); featureElement->setAttribute("var", feature); queryElement.addNode(featureElement); } foreach(const Form::ref extension, discoInfo->getExtensions()) { queryElement.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(extension))); } return queryElement.serialize(); }
OsStatus CallerAliasDB::store() { UtlString fileName = DbName + ".xml"; UtlString pathName = SipXecsService::Path(SipXecsService::DatabaseDirType, fileName.data()); // Create an empty document TiXmlDocument document; // Create a hard coded standalone declaration section document.Parse ("<?xml version=\"1.0\" standalone=\"yes\"?>"); // Create the root node container TiXmlElement itemsElement ( "items" ); itemsElement.SetAttribute( "type", sType.data() ); itemsElement.SetAttribute( "xmlns", sXmlNamespace.data() ); // Critical Section while actually opening and using the database { OsLock lock( sLockMutex ); if ( mpFastDB != NULL ) { // Thread Local Storage mpFastDB->attach(); // Search our memory for rows dbCursor< CallerAliasRow > cursor; // Select everything in the IMDB and add as item elements if present int rowNumber; int rows; for (rowNumber = 0, rows = cursor.select(); rowNumber < rows; rowNumber++, cursor.next() ) { // Create an item container TiXmlElement itemElement ("item"); if ( *cursor->identity ) { // Add an identity element and put the value in it TiXmlElement identityElement(IdentityKey.data()); TiXmlText identityValue(cursor->identity); identityElement.InsertEndChild(identityValue); itemElement.InsertEndChild(identityElement); } // add the domain element and put the value in it TiXmlElement domainElement(DomainKey.data()); TiXmlText domainValue(cursor->domain); domainElement.InsertEndChild(domainValue); itemElement.InsertEndChild(domainElement); // add the alias element and put the value in it TiXmlElement aliasElement(AliasKey.data()); TiXmlText aliasValue(cursor->alias); aliasElement.InsertEndChild(aliasValue); itemElement.InsertEndChild(aliasElement); // add this item (row) to the parent items container itemsElement.InsertEndChild ( itemElement ); } // Commit rows to memory - multiprocess workaround mpFastDB->detach(0); mTableLoaded = true; } } // release mutex around database use // Attach the root node to the document document.InsertEndChild ( itemsElement ); document.SaveFile ( pathName ); return OS_SUCCESS; }