void SIPAccount::unserialize (Conf::MappingNode *map) { Conf::MappingNode *srtpMap; Conf::MappingNode *tlsMap; Conf::MappingNode *zrtpMap; assert(map); map->getValue(aliasKey, &_alias); map->getValue(typeKey, &_type); map->getValue(usernameKey, &_username); map->getValue(hostnameKey, &_hostname); map->getValue(accountEnableKey, &_enabled); map->getValue(mailboxKey, &_mailBox); map->getValue(codecsKey, &_codecStr); // Update codec list which one is used for SDP offer setActiveCodecs (ManagerImpl::unserialize (_codecStr)); map->getValue(ringtonePathKey, &_ringtonePath); map->getValue(ringtoneEnabledKey, &_ringtoneEnabled); map->getValue(expireKey, &_registrationExpire); map->getValue(interfaceKey, &_interface); int port; map->getValue(portKey, &port); _localPort = port; map->getValue(publishAddrKey, &_publishedIpAddress); map->getValue(publishPortKey, &port); _publishedPort = port; map->getValue(sameasLocalKey, &_publishedSameasLocal); map->getValue(resolveOnceKey, &_resolveOnce); std::string dtmfType; map->getValue(dtmfTypeKey, &dtmfType); _dtmfType = (dtmfType == "overrtp") ? OVERRTP : SIPINFO; map->getValue(serviceRouteKey, &_serviceRoute); // stun enabled map->getValue(stunEnabledKey, &_stunEnabled); map->getValue(stunServerKey, &_stunServer); // Init stun server name with default server name _stunServerName = pj_str ( (char*) _stunServer.data()); map->getValue(displayNameKey, &_displayName); std::vector<std::map<std::string, std::string> > creds; Conf::YamlNode *credNode = map->getValue (credKey); /* We check if the credential key is a sequence * because it was a mapping in a previous version of * the configuration file. */ if (credNode && credNode->getType() == Conf::SEQUENCE) { Conf::SequenceNode *credSeq = (Conf::SequenceNode *) credNode; Conf::Sequence::iterator it; Conf::Sequence *seq = credSeq->getSequence(); for(it = seq->begin(); it != seq->end(); ++it) { Conf::MappingNode *cred = (Conf::MappingNode *) (*it); std::string user; std::string pass; std::string realm; cred->getValue(USERNAME, &user); cred->getValue(PASSWORD, &pass); cred->getValue(REALM, &realm); std::map<std::string, std::string> map; map[USERNAME] = user; map[PASSWORD] = pass; map[REALM] = realm; creds.push_back(map); } } if (creds.empty()) { // migration from old file format std::map<std::string, std::string> credmap; std::string password; map->getValue(passwordKey, &password); credmap[USERNAME] = _username; credmap[PASSWORD] = password; credmap[REALM] = "*"; creds.push_back(credmap); } setCredentials (creds); // get srtp submap srtpMap = (Conf::MappingNode *) (map->getValue (srtpKey)); if (srtpMap) { srtpMap->getValue(srtpEnableKey, &_srtpEnabled); srtpMap->getValue(keyExchangeKey, &_srtpKeyExchange); srtpMap->getValue(rtpFallbackKey, &_srtpFallback); } // get zrtp submap zrtpMap = (Conf::MappingNode *) (map->getValue (zrtpKey)); if (zrtpMap) { zrtpMap->getValue(displaySasKey, &_zrtpDisplaySas); zrtpMap->getValue(displaySasOnceKey, &_zrtpDisplaySasOnce); zrtpMap->getValue(helloHashEnabledKey, &_zrtpHelloHash); zrtpMap->getValue(notSuppWarningKey, &_zrtpNotSuppWarning); } // get tls submap tlsMap = (Conf::MappingNode *) (map->getValue (tlsKey)); if (tlsMap) { tlsMap->getValue(tlsEnableKey, &_tlsEnable); tlsMap->getValue(tlsPortKey, &_tlsPortStr); tlsMap->getValue(certificateKey, &_tlsCertificateFile); tlsMap->getValue(calistKey, &_tlsCaListFile); tlsMap->getValue(ciphersKey, &_tlsCiphers); tlsMap->getValue(methodKey, &_tlsMethod); tlsMap->getValue(tlsPasswordKey, &_tlsPassword); tlsMap->getValue(privateKeyKey, &_tlsPrivateKeyFile); tlsMap->getValue(requireCertifKey, &_tlsRequireClientCertificate); tlsMap->getValue(serverKey, &_tlsServerName); tlsMap->getValue(verifyClientKey, &_tlsVerifyServer); tlsMap->getValue(verifyServerKey, &_tlsVerifyClient); // FIXME tlsMap->getValue(timeoutKey, &_tlsNegotiationTimeoutSec); tlsMap->getValue(timeoutKey, &_tlsNegotiationTimeoutMsec); } }
void SIPAccount::unserialize(const Conf::MappingNode &map) { using namespace Conf; map.getValue(ALIAS_KEY, &alias_); map.getValue(TYPE_KEY, &type_); map.getValue(USERNAME_KEY, &username_); map.getValue(HOSTNAME_KEY, &hostname_); map.getValue(ACCOUNT_ENABLE_KEY, &enabled_); map.getValue(MAILBOX_KEY, &mailBox_); map.getValue(CODECS_KEY, &codecStr_); // Update codec list which one is used for SDP offer setActiveCodecs(ManagerImpl::split_string(codecStr_)); map.getValue(RINGTONE_PATH_KEY, &ringtonePath_); map.getValue(RINGTONE_ENABLED_KEY, &ringtoneEnabled_); map.getValue(Preferences::REGISTRATION_EXPIRE_KEY, ®istrationExpire_); map.getValue(INTERFACE_KEY, &interface_); int port = DEFAULT_SIP_PORT; map.getValue(PORT_KEY, &port); localPort_ = port; map.getValue(PUBLISH_ADDR_KEY, &publishedIpAddress_); map.getValue(PUBLISH_PORT_KEY, &port); publishedPort_ = port; map.getValue(SAME_AS_LOCAL_KEY, &publishedSameasLocal_); map.getValue(KEEP_ALIVE_ENABLED, &keepAliveEnabled_); std::string dtmfType; map.getValue(DTMF_TYPE_KEY, &dtmfType); dtmfType_ = dtmfType; map.getValue(SERVICE_ROUTE_KEY, &serviceRoute_); map.getValue(UPDATE_CONTACT_HEADER_KEY, &contactUpdateEnabled_); // stun enabled map.getValue(STUN_ENABLED_KEY, &stunEnabled_); map.getValue(STUN_SERVER_KEY, &stunServer_); // Init stun server name with default server name stunServerName_ = pj_str((char*) stunServer_.data()); map.getValue(DISPLAY_NAME_KEY, &displayName_); std::vector<std::map<std::string, std::string> > creds; YamlNode *credNode = map.getValue(CRED_KEY); /* We check if the credential key is a sequence * because it was a mapping in a previous version of * the configuration file. */ if (credNode && credNode->getType() == SEQUENCE) { SequenceNode *credSeq = static_cast<SequenceNode *>(credNode); Sequence::iterator it; Sequence *seq = credSeq->getSequence(); for (it = seq->begin(); it != seq->end(); ++it) { MappingNode *cred = static_cast<MappingNode *>(*it); std::string user; std::string pass; std::string realm; cred->getValue(CONFIG_ACCOUNT_USERNAME, &user); cred->getValue(CONFIG_ACCOUNT_PASSWORD, &pass); cred->getValue(CONFIG_ACCOUNT_REALM, &realm); std::map<std::string, std::string> credentialMap; credentialMap[CONFIG_ACCOUNT_USERNAME] = user; credentialMap[CONFIG_ACCOUNT_PASSWORD] = pass; credentialMap[CONFIG_ACCOUNT_REALM] = realm; creds.push_back(credentialMap); } } if (creds.empty()) { // migration from old file format std::map<std::string, std::string> credmap; std::string password; map.getValue(PASSWORD_KEY, &password); credmap[CONFIG_ACCOUNT_USERNAME] = username_; credmap[CONFIG_ACCOUNT_PASSWORD] = password; credmap[CONFIG_ACCOUNT_REALM] = "*"; creds.push_back(credmap); } setCredentials(creds); // get srtp submap MappingNode *srtpMap = static_cast<MappingNode *>(map.getValue(SRTP_KEY)); if (srtpMap) { srtpMap->getValue(SRTP_ENABLE_KEY, &srtpEnabled_); srtpMap->getValue(KEY_EXCHANGE_KEY, &srtpKeyExchange_); srtpMap->getValue(RTP_FALLBACK_KEY, &srtpFallback_); } // get zrtp submap MappingNode *zrtpMap = static_cast<MappingNode *>(map.getValue(ZRTP_KEY)); if (zrtpMap) { zrtpMap->getValue(DISPLAY_SAS_KEY, &zrtpDisplaySas_); zrtpMap->getValue(DISPLAY_SAS_ONCE_KEY, &zrtpDisplaySasOnce_); zrtpMap->getValue(HELLO_HASH_ENABLED_KEY, &zrtpHelloHash_); zrtpMap->getValue(NOT_SUPP_WARNING_KEY, &zrtpNotSuppWarning_); } // get tls submap MappingNode *tlsMap = static_cast<MappingNode *>(map.getValue(TLS_KEY)); if (tlsMap) { tlsMap->getValue(TLS_ENABLE_KEY, &tlsEnable_); std::string tlsPort; tlsMap->getValue(TLS_PORT_KEY, &tlsPort); tlsListenerPort_ = atoi(tlsPort.c_str()); tlsMap->getValue(CERTIFICATE_KEY, &tlsCertificateFile_); tlsMap->getValue(CALIST_KEY, &tlsCaListFile_); tlsMap->getValue(CIPHERS_KEY, &tlsCiphers_); tlsMap->getValue(METHOD_KEY, &tlsMethod_); tlsMap->getValue(TLS_PASSWORD_KEY, &tlsPassword_); tlsMap->getValue(PRIVATE_KEY_KEY, &tlsPrivateKeyFile_); tlsMap->getValue(REQUIRE_CERTIF_KEY, &tlsRequireClientCertificate_); tlsMap->getValue(SERVER_KEY, &tlsServerName_); tlsMap->getValue(VERIFY_CLIENT_KEY, &tlsVerifyServer_); tlsMap->getValue(VERIFY_SERVER_KEY, &tlsVerifyClient_); // FIXME tlsMap->getValue(TIMEOUT_KEY, &tlsNegotiationTimeoutSec_); tlsMap->getValue(TIMEOUT_KEY, &tlsNegotiationTimeoutMsec_); } }
void SIPAccount::serialize (Conf::YamlEmitter *emitter) { if(emitter == NULL) { _error("SIPAccount: Error: emitter is NULL in serialize"); return; } Conf::MappingNode accountmap (NULL); Conf::MappingNode srtpmap (NULL); Conf::MappingNode zrtpmap (NULL); Conf::MappingNode tlsmap (NULL); Conf::ScalarNode id (Account::_accountID); Conf::ScalarNode username (Account::_username); Conf::ScalarNode alias (Account::_alias); Conf::ScalarNode hostname (Account::_hostname); Conf::ScalarNode enable (_enabled); Conf::ScalarNode type (Account::_type); Conf::ScalarNode expire (_registrationExpire); Conf::ScalarNode interface (_interface); std::stringstream portstr; portstr << _localPort; Conf::ScalarNode port (portstr.str()); Conf::ScalarNode serviceRoute (_serviceRoute); Conf::ScalarNode mailbox (_mailBox); Conf::ScalarNode publishAddr (_publishedIpAddress); std::stringstream publicportstr; publicportstr << _publishedPort; Conf::ScalarNode publishPort (publicportstr.str()); Conf::ScalarNode sameasLocal (_publishedSameasLocal); Conf::ScalarNode resolveOnce (_resolveOnce); Conf::ScalarNode codecs (_codecStr); Conf::ScalarNode ringtonePath (_ringtonePath); Conf::ScalarNode ringtoneEnabled (_ringtoneEnabled); Conf::ScalarNode stunServer (_stunServer); Conf::ScalarNode stunEnabled (_stunEnabled); Conf::ScalarNode displayName (_displayName); Conf::ScalarNode dtmfType (_dtmfType==OVERRTP ? "overrtp" : "sipinfo"); std::stringstream countstr; countstr << 0; Conf::ScalarNode count (countstr.str()); Conf::ScalarNode srtpenabled (_srtpEnabled); Conf::ScalarNode keyExchange (_srtpKeyExchange); Conf::ScalarNode rtpFallback (_srtpFallback); Conf::ScalarNode displaySas (_zrtpDisplaySas); Conf::ScalarNode displaySasOnce (_zrtpDisplaySasOnce); Conf::ScalarNode helloHashEnabled (_zrtpHelloHash); Conf::ScalarNode notSuppWarning (_zrtpNotSuppWarning); Conf::ScalarNode tlsport (_tlsPortStr); Conf::ScalarNode certificate (_tlsCertificateFile); Conf::ScalarNode calist (_tlsCaListFile); Conf::ScalarNode ciphers (_tlsCiphers); Conf::ScalarNode tlsenabled (_tlsEnable); Conf::ScalarNode tlsmethod (_tlsMethod); Conf::ScalarNode timeout (_tlsNegotiationTimeoutSec); Conf::ScalarNode tlspassword (_tlsPassword); Conf::ScalarNode privatekey (_tlsPrivateKeyFile); Conf::ScalarNode requirecertif (_tlsRequireClientCertificate); Conf::ScalarNode server (_tlsServerName); Conf::ScalarNode verifyclient (_tlsVerifyServer); Conf::ScalarNode verifyserver (_tlsVerifyClient); accountmap.setKeyValue (aliasKey, &alias); accountmap.setKeyValue (typeKey, &type); accountmap.setKeyValue (idKey, &id); accountmap.setKeyValue (usernameKey, &username); accountmap.setKeyValue (hostnameKey, &hostname); accountmap.setKeyValue (accountEnableKey, &enable); accountmap.setKeyValue (mailboxKey, &mailbox); accountmap.setKeyValue (expireKey, &expire); accountmap.setKeyValue (interfaceKey, &interface); accountmap.setKeyValue (portKey, &port); accountmap.setKeyValue (stunServerKey, &stunServer); accountmap.setKeyValue (stunEnabledKey, &stunEnabled); accountmap.setKeyValue (publishAddrKey, &publishAddr); accountmap.setKeyValue (publishPortKey, &publishPort); accountmap.setKeyValue (sameasLocalKey, &sameasLocal); accountmap.setKeyValue (resolveOnceKey, &resolveOnce); accountmap.setKeyValue (serviceRouteKey, &serviceRoute); accountmap.setKeyValue (dtmfTypeKey, &dtmfType); accountmap.setKeyValue (displayNameKey, &displayName); accountmap.setKeyValue (codecsKey, &codecs); accountmap.setKeyValue (ringtonePathKey, &ringtonePath); accountmap.setKeyValue (ringtoneEnabledKey, &ringtoneEnabled); accountmap.setKeyValue (srtpKey, &srtpmap); srtpmap.setKeyValue (srtpEnableKey, &srtpenabled); srtpmap.setKeyValue (keyExchangeKey, &keyExchange); srtpmap.setKeyValue (rtpFallbackKey, &rtpFallback); accountmap.setKeyValue (zrtpKey, &zrtpmap); zrtpmap.setKeyValue (displaySasKey, &displaySas); zrtpmap.setKeyValue (displaySasOnceKey, &displaySasOnce); zrtpmap.setKeyValue (helloHashEnabledKey, &helloHashEnabled); zrtpmap.setKeyValue (notSuppWarningKey, ¬SuppWarning); Conf::SequenceNode credentialseq (NULL); accountmap.setKeyValue (credKey, &credentialseq); std::vector<std::map<std::string, std::string> >::const_iterator it; for (it = credentials_.begin(); it != credentials_.end(); ++it) { std::map<std::string, std::string> cred = *it; Conf::MappingNode *map = new Conf::MappingNode(NULL); map->setKeyValue(USERNAME, new Conf::ScalarNode(cred[USERNAME])); map->setKeyValue(PASSWORD, new Conf::ScalarNode(cred[PASSWORD])); map->setKeyValue(REALM, new Conf::ScalarNode(cred[REALM])); credentialseq.addNode(map); } accountmap.setKeyValue (tlsKey, &tlsmap); tlsmap.setKeyValue (tlsPortKey, &tlsport); tlsmap.setKeyValue (certificateKey, &certificate); tlsmap.setKeyValue (calistKey, &calist); tlsmap.setKeyValue (ciphersKey, &ciphers); tlsmap.setKeyValue (tlsEnableKey, &tlsenabled); tlsmap.setKeyValue (methodKey, &tlsmethod); tlsmap.setKeyValue (timeoutKey, &timeout); tlsmap.setKeyValue (tlsPasswordKey, &tlspassword); tlsmap.setKeyValue (privateKeyKey, &privatekey); tlsmap.setKeyValue (requireCertifKey, &requirecertif); tlsmap.setKeyValue (serverKey, &server); tlsmap.setKeyValue (verifyClientKey, &verifyclient); tlsmap.setKeyValue (verifyServerKey, &verifyserver); try { emitter->serializeAccount (&accountmap); } catch (Conf::YamlEmitterException &e) { _error ("ConfigTree: %s", e.what()); } Conf::Sequence *seq = credentialseq.getSequence(); Conf::Sequence::iterator seqit; for (seqit = seq->begin(); seqit != seq->end(); ++seqit) { Conf::MappingNode *node = (Conf::MappingNode*)*seqit; delete node->getValue(USERNAME); delete node->getValue(PASSWORD); delete node->getValue(REALM); delete node; } }