PeerToFinderPeerLocationFindResultPtr PeerToFinderPeerLocationFindResult::create(ElementPtr root) { PeerToFinderPeerLocationFindResultPtr ret(new message::PeerToFinderPeerLocationFindResult); ret->mID = IMessageHelper::getAttributeID(root); ret->mTime = IMessageHelper::getAttributeEpoch(root); ElementPtr locs = root->findFirstChildElement("locations"); if (locs) { LocationList ll; ElementPtr loc = locs->findFirstChildElement("location"); while (loc) { Location l = MessageHelper::createLocation(loc->findFirstChildElement("details")); l.mID = IMessageHelper::getAttributeID(loc); ll.push_back(l); loc = loc->getNextSiblingElement(); } if (ll.size() > 0) ret->mLocations = ll; } return ret; }
//--------------------------------------------------------------------- SessionDeleteResultPtr SessionDeleteResult::create( ElementPtr root, IMessageSourcePtr messageSource ) { SessionDeleteResultPtr ret(new SessionDeleteResult); IMessageHelper::fill(*ret, root, messageSource); ElementPtr locations = root->findFirstChildElement("locations"); if(locations) { StringList ll; ElementPtr loc = locations->findFirstChildElement("location"); while (loc) { ll.push_back(IMessageHelper::getAttributeID(loc)); loc = loc->getNextSiblingElement(); } if (ll.size() > 0) ret->mLocations = ll; } return ret; }
//--------------------------------------------------------------------- LockboxAccessResultPtr LockboxAccessResult::create( ElementPtr rootEl, IMessageSourcePtr messageSource ) { LockboxAccessResultPtr ret(new LockboxAccessResult); IMessageHelper::fill(*ret, rootEl, messageSource); ret->mLockboxInfo = MessageHelper::createLockbox(rootEl->findFirstChildElement("lockbox")); ret->mNamespaceGrantChallengeInfo = MessageHelper::createNamespaceGrantChallenge(rootEl->findFirstChildElement("namespaceGrantChallenge")); ElementPtr identitiesEl = rootEl->findFirstChildElement("identities"); if (identitiesEl) { ElementPtr identityEl = identitiesEl->findFirstChildElement("identity"); while (identityEl) { IdentityInfo info = MessageHelper::createIdentity(identityEl); if (info.hasData()) { ret->mIdentities.push_back(info); } identityEl = identityEl->findNextSiblingElement("identity"); } } return ret; }
PeerToFinderSessionDeleteResultPtr PeerToFinderSessionDeleteResult::create(ElementPtr root) { PeerToFinderSessionDeleteResultPtr ret(new message::PeerToFinderSessionDeleteResult); ret->mID = IMessageHelper::getAttributeID(root); ret->mTime = IMessageHelper::getAttributeEpoch(root); ElementPtr locations = root->findFirstChildElement("locations"); if(locations) { StringList ll; ElementPtr loc = locations->findFirstChildElement("location"); while (loc) { ll.push_back(IMessageHelper::getAttributeID(loc)); loc = loc->getNextSiblingElement(); } if (ll.size() > 0) ret->mLocations = ll; } return ret; }
PeerToPeerPeerIdentifyRequestPtr PeerToPeerPeerIdentifyRequest::create(ElementPtr root) { PeerToPeerPeerIdentifyRequestPtr ret(new message::PeerToPeerPeerIdentifyRequest); if (root) { try { ElementPtr el; ElementPtr proofEl = root->findFirstChildElementChecked("proofBundle")->findFirstChildElementChecked("proof"); ret->mID = IMessageHelper::getAttributeID(root); ret->mProofID = IMessageHelper::getAttributeID(proofEl); ret->mLocationID = IMessageHelper::getAttributeID(proofEl->findFirstChildElement("location")); ret->mFindSecret = IMessageHelper::getElementText(proofEl->findFirstChildElement("findSecret")); ret->mOneTimeKey = IMessageHelper::getAttributeID(proofEl->findFirstChildElement("oneTimeKey")); ret->mExpires = IMessageHelper::stringToTime(IMessageHelper::getElementText(proofEl->findFirstChildElement("expires"))); ret->mUserAgent = IMessageHelper::getElementTextAndEntityDecode(proofEl->findFirstChildElement("userAgent")); ret->mPeerFilePublic = IPeerFilePublic::loadFromXML(proofEl->findFirstChildElement("peer")); } catch (Exceptions::CheckFailed &e) {} } return ret; }
//--------------------------------------------------------------------- NamespaceGrantCompleteNotifyPtr NamespaceGrantCompleteNotify::create( ElementPtr rootEl, IMessageSourcePtr messageSource ) { NamespaceGrantCompleteNotifyPtr ret(new NamespaceGrantCompleteNotify); IMessageHelper::fill(*ret, rootEl, messageSource); ElementPtr namespaceGranthallengeBundlesEl = rootEl->findFirstChildElement("namespaceGrantChallengeBundles"); if (namespaceGranthallengeBundlesEl) { ElementPtr namespaceGranthallengeBundleEl = namespaceGranthallengeBundlesEl->findFirstChildElement("namespaceGrantChallengeBundle"); while (namespaceGranthallengeBundleEl) { ret->mBundles.push_back(namespaceGranthallengeBundleEl->clone()->toElement()); namespaceGranthallengeBundleEl = namespaceGranthallengeBundleEl->findNextSiblingElement("namespaceGrantChallengeBundle"); } } return ret; }
//--------------------------------------------------------------------- IdentityAccessWindowRequestPtr IdentityAccessWindowRequest::create( ElementPtr root, IMessageSourcePtr messageSource ) { IdentityAccessWindowRequestPtr ret(new IdentityAccessWindowRequest); MessageHelper::fill(*ret, root, messageSource); ElementPtr browserEl = root->findFirstChildElement("browser"); if (browserEl) { String ready = IMessageHelper::getElementText(browserEl->findFirstChildElement("ready")); if (!ready.isEmpty()) { ret->mReady = ("true" == ready ? 1 : 0); } String visibility = IMessageHelper::getElementText(browserEl->findFirstChildElement("visibility")); if (!visibility.isEmpty()) { ret->mVisible = ("true" == visibility ? 1 : 0); } } return ret; }
//--------------------------------------------------------------------- bool PeerContactProfile::setPublicProfile(ElementPtr newProfileElement) { AutoRecursiveLock lock(mLock); if (!mDocument) return false; PeerFilesPtr outer = mPeerFiles.lock(); if (!outer) return false; IPeerFilePrivatePtr privatePeer = outer->getPrivate(); if (!privatePeer) return false; try { ElementPtr contactProfileElement = getContactProfileElement(); if (!contactProfileElement) return false; ElementPtr publicElement = contactProfileElement->findFirstChildElement("public"); ElementPtr profileElement; if (publicElement) profileElement = publicElement->findFirstChildElementChecked("profile"); if (!newProfileElement) { // erasing the profile element to clean newProfileElement = Element::create(); newProfileElement->setValue("profile"); } if (profileElement) { profileElement->adoptAsNextSibling(newProfileElement); profileElement->orphan(); } else { if (!publicElement) { publicElement = Element::create(); publicElement->setValue("public"); contactProfileElement->adoptAsFirstChild(publicElement); } publicElement->adoptAsLastChild(newProfileElement); } // upgrade the document version number UINT version = getVersionNumber(); ++version; contactProfileElement->setAttribute("version", Stringize<UINT>(version).string()); if (!isExternal()) { // now this this must be signed privatePeer->signElement(contactProfileElement); } } catch (zsLib::XML::Exceptions::CheckFailed &) { return false; } return true; }
//--------------------------------------------------------------------- LockboxIdentitiesUpdateResultPtr LockboxIdentitiesUpdateResult::create( ElementPtr root, IMessageSourcePtr messageSource ) { LockboxIdentitiesUpdateResultPtr ret(new LockboxIdentitiesUpdateResult); IMessageHelper::fill(*ret, root, messageSource); ElementPtr identitiesEl = root->findFirstChildElement("identities"); if (identitiesEl) { ElementPtr identityEl = identitiesEl->findFirstChildElement("identity"); while (identityEl) { IdentityInfo info = MessageHelper::createIdentity(identityEl); if (info.hasData()) { ret->mIdentities.push_back(info); } identityEl = identityEl->findNextSiblingElement("identity"); } } return ret; }
//----------------------------------------------------------------------- //----------------------------------------------------------------------- //----------------------------------------------------------------------- //----------------------------------------------------------------------- ElementPtr PeerContactProfile::getContactProfileElement() const { if (!mDocument) return ElementPtr(); ElementPtr contactProfileBundleElement = mDocument->findFirstChildElement("contactProfileBundle"); if (!contactProfileBundleElement) { ElementPtr contactProfileElement = mDocument->findFirstChildElement("contactProfile"); if (contactProfileElement) return contactProfileElement; return ElementPtr(); } return contactProfileBundleElement->findFirstChildElement("contactProfile"); }
//--------------------------------------------------------------------- PeerKeepAliveResultPtr PeerKeepAliveResult::create( ElementPtr root, IMessageSourcePtr messageSource ) { PeerKeepAliveResultPtr ret(new PeerKeepAliveResult); ret->mID = IMessageHelper::getAttributeID(root); ret->mTime = IMessageHelper::getAttributeEpoch(root); ret->mExpires = IHelper::stringToTime(IMessageHelper::getElementText(root->findFirstChildElement("expires"))); return ret; }
//--------------------------------------------------------------------- RolodexContactsGetResultPtr RolodexContactsGetResult::create( ElementPtr rootEl, IMessageSourcePtr messageSource ) { RolodexContactsGetResultPtr ret(new RolodexContactsGetResult); IMessageHelper::fill(*ret, rootEl, messageSource); ElementPtr identitiesEl = rootEl->findFirstChildElement("identities"); if (identitiesEl) { ElementPtr identityEl = identitiesEl->findFirstChildElement("identity"); while (identityEl) { IdentityInfo info = MessageHelper::createIdentity(identityEl); if (info.hasData()) { #define OPENPEER_STACK_MESSAGE_ROLODEX_IMPROPER_FACEBOOK_URL "identity://facebook/" #define OPENPEER_STACK_MESSAGE_ROLODEX_ROPER_FACEBOOK_URL "identity://facebook.com/" #define HORRIBLE_HACK_TO_PREVENT_INVALID_FORMED_FACEBOOK_URIS 1 if (info.mURI.hasData()) { if (0 == info.mURI.compare(0, strlen(OPENPEER_STACK_MESSAGE_ROLODEX_IMPROPER_FACEBOOK_URL), OPENPEER_STACK_MESSAGE_ROLODEX_IMPROPER_FACEBOOK_URL)) { ZS_LOG_WARNING(Detail, String("RolodexContactsGetResult [") + ret->mID + "] Fixed imporer facebook identity URI. Please contact rolodex admin to repair rolodex service. URI=" + info.mURI) info.mURI = OPENPEER_STACK_MESSAGE_ROLODEX_ROPER_FACEBOOK_URL + info.mURI.substr(strlen(OPENPEER_STACK_MESSAGE_ROLODEX_IMPROPER_FACEBOOK_URL)); } } #define HORRIBLE_HACK_TO_PREVENT_INVALID_FORMED_FACEBOOK_URIS 2 ret->mIdentities.push_back(info); } identityEl = identityEl->findNextSiblingElement("identity"); } } ret->mRolodexInfo = MessageHelper::createRolodex(rootEl->findFirstChildElement("rolodex")); return ret; }
//--------------------------------------------------------------------- ServicesGetResultPtr ServicesGetResult::create( ElementPtr root, IMessageSourcePtr messageSource ) { ServicesGetResultPtr ret(new ServicesGetResult); IMessageHelper::fill(*ret, root, messageSource); ElementPtr servicesEl = root->findFirstChildElement("services"); if (!servicesEl) return ret; ElementPtr serviceEl = servicesEl->findFirstChildElement("service"); while (serviceEl) { Service service = MessageHelper::createService(serviceEl); if (service.hasData()) { ret->mServices[service.mID] = service; ret->mServicesByType[service.mType] = service; } serviceEl = serviceEl->findNextSiblingElement("service"); } return ret; }
PeerToFinderPeerLocationFindRequestPtr PeerToFinderPeerLocationFindRequest::create(ElementPtr root) { PeerToFinderPeerLocationFindRequestPtr ret(new message::PeerToFinderPeerLocationFindRequest); if (root) { ret->mID = IMessageHelper::getAttributeID(root); ElementPtr routes = root->findFirstChildElement("routes"); if (routes) { RouteList routeLst; ElementPtr route = routes->findFirstChildElement("route"); while (route) { String id = IMessageHelper::getAttributeID(route); routeLst.push_back(id); route = route->getNextSiblingElement(); } if (routeLst.size() > 0) ret->mRoutes = routeLst; } ElementPtr exclude = root->findFirstChildElement("exclude"); if (exclude) { ElementPtr locations = root->findFirstChildElement("locations"); if (locations) { message::PeerToFinderPeerLocationFindRequest::ExcludedLocationList exclLst; ElementPtr loc = locations->findFirstChildElement("location"); while (loc) { String id = IMessageHelper::getAttributeID(loc); exclLst.push_back(id); loc = loc->getNextSiblingElement(); } if (exclLst.size() > 0) ret->mExcludedLocations = exclLst; } } ElementPtr location = root->findFirstChildElement("location"); if (location) { ret->mLocation = MessageHelper::createLocation(location); } } return ret; }
OAuthLoginWebpageResultPtr OAuthLoginWebpageResult::create(ElementPtr root) { OAuthLoginWebpageResultPtr ret(new message::OAuthLoginWebpageResult); ret->mID = IMessageHelper::getAttributeID(root); ret->mTime = IMessageHelper::getAttributeEpoch(root); String createdStr = IMessageHelper::getChildElementText(root, "created"); if (!createdStr.isEmpty()) { try { bool val = Numeric<bool>(createdStr); ret->mCreated = (val ? 1 : 0); } catch (Numeric<bool>::ValueOutOfRange &) { ret->mCreated = -1; } } ret->mUserID = IMessageHelper::getChildElementText(root, "userID"); ret->mAccountSalt = IMessageHelper::getChildElementText(root, "accountSalt"); ret->mAccessKey = IMessageHelper::getChildElementText(root, "accessKey"); ret->mAccessSecret = IMessageHelper::getChildElementText(root, "accessSecret"); ret->mLastProfileUpdateTimestamp = IMessageHelper::stringToTime(IMessageHelper::getChildElementText(root, "lastProfileUpdateTimestamp")); ret->mName = IMessageHelper::getChildElementText(root, "name"); ElementPtr propertiesEl = root->findFirstChildElement("properties"); if (propertiesEl) { ret->mNetworkURI = IMessageHelper::getChildElementText(propertiesEl, "networkURI"); ret->mTURNServer = IMessageHelper::getChildElementText(propertiesEl, "turnServer"); ret->mTURNUsername = IMessageHelper::getChildElementText(propertiesEl, "turnUsername"); ret->mTURNPassword = IMessageHelper::getChildElementText(propertiesEl, "turnPassword"); ret->mSTUNServer = IMessageHelper::getChildElementText(propertiesEl, "stunServer"); } ret->mProviderType = provisioning::IAccount::toIdentity(IMessageHelper::getChildElementText(root, "providerType")); ret->mProviderUniqueID = IMessageHelper::getChildElementText(root, "providerUniqueID"); ret->mProviderOAuthAccessToken = IMessageHelper::getChildElementText(root, "providerOAuthAccessToken"); ret->mProviderEncryptedOAuthAccessSecret = IMessageHelper::getChildElementText(root, "providerEncryptedOAuthAccessSecret"); return ret; }
PeerToFinderSessionCreateResultPtr PeerToFinderSessionCreateResult::create(ElementPtr root) { PeerToFinderSessionCreateResultPtr ret(new message::PeerToFinderSessionCreateResult); ret->mID = IMessageHelper::getAttributeID(root); ret->mTime = IMessageHelper::getAttributeEpoch(root); ret->mExpires = IMessageHelper::stringToTime(IMessageHelper::getElementText(root->findFirstChildElement("expires"))); return ret; }
//--------------------------------------------------------------------- bool PeerContactProfile::setPrivateProfile(ElementPtr newProfileElement) { AutoRecursiveLock lock(mLock); if (!mDocument) return false; PeerFilesPtr outer; IPeerFilePrivatePtr privatePeer; if (!isExternal()) { outer = mPeerFiles.lock(); if (!outer) return false; privatePeer = outer->getPrivate(); if (!privatePeer) return false; } try { ElementPtr contactProfileElement = getContactProfileElement(); if (!contactProfileElement) return false; ElementPtr privateElement = contactProfileElement->findFirstChildElementChecked("private"); ElementPtr encryptedProfileElement = privateElement->findFirstChildElement("encryptedProfile"); ElementPtr saltElement = privateElement->findFirstChildElementChecked("salt"); String saltAsBase64 = saltElement->getText(true); if (!newProfileElement) { // erasing the profile element to clean newProfileElement = Element::create(); newProfileElement->setValue("profile"); } DocumentPtr tempDoc = Document::create(); tempDoc->adoptAsLastChild(newProfileElement->clone()); // write out the new value boost::shared_array<char> output = tempDoc->write(); // encrypt it String encryptedProfileAsBase64 = encryptToBase64( "profile", mContactProfileSecret.c_str(), saltAsBase64, (const BYTE *)(output.get()), strlen(output.get()) ); ElementPtr tempNewEncryptedProfileElement = Element::create(); tempNewEncryptedProfileElement->setValue("encryptedProfile"); TextPtr encryptedProfileText = Text::create(); encryptedProfileText->setValue(encryptedProfileAsBase64); tempNewEncryptedProfileElement->adoptAsLastChild(encryptedProfileText); if (encryptedProfileElement) { encryptedProfileElement->adoptAsNextSibling(tempNewEncryptedProfileElement); encryptedProfileElement->orphan(); } else { privateElement->adoptAsLastChild(tempNewEncryptedProfileElement); } // upgrade the document version number UINT version = getVersionNumber(); ++version; contactProfileElement->setAttribute("version", Stringize<UINT>(version).string()); if (!isExternal()) { // now this this must be signed privatePeer->signElement(contactProfileElement); } } catch (zsLib::XML::Exceptions::CheckFailed &) { return false; } return true; }