From 63502022b1b6435bef4eab20250aecb5b178b9c1 Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Tue, 13 Aug 2013 16:14:56 -0400 Subject: [PATCH] * #28351: sipaccount: use range based for loops --- daemon/src/sip/sipaccount.cpp | 72 ++++++++++++++++------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 92b5b3f7b..5109d780e 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -165,8 +165,7 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter) SequenceNode videoCodecs(NULL); accountmap.setKeyValue(VIDEO_CODECS_KEY, &videoCodecs); - for (vector >::iterator i = videoCodecList_.begin(); i != videoCodecList_.end(); ++i) { - map &codec = *i; + for (auto &codec : videoCodecList_) { MappingNode *mapNode = new MappingNode(NULL); mapNode->setKeyValue(VIDEO_CODEC_NAME, new ScalarNode(codec[VIDEO_CODEC_NAME])); mapNode->setKeyValue(VIDEO_CODEC_BITRATE, new ScalarNode(codec[VIDEO_CODEC_BITRATE])); @@ -251,10 +250,8 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter) SequenceNode credentialseq(NULL); accountmap.setKeyValue(CRED_KEY, &credentialseq); - std::vector >::const_iterator it; - - for (it = credentials_.begin(); it != credentials_.end(); ++it) { - std::map cred = *it; + for (const auto &it : credentials_) { + std::map cred = it; MappingNode *map = new MappingNode(NULL); map->setKeyValue(CONFIG_ACCOUNT_USERNAME, new ScalarNode(cred[CONFIG_ACCOUNT_USERNAME])); map->setKeyValue(CONFIG_ACCOUNT_PASSWORD, new ScalarNode(cred[CONFIG_ACCOUNT_PASSWORD])); @@ -289,8 +286,8 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter) // Cleanup Sequence *credSeq = credentialseq.getSequence(); - for (Sequence::iterator seqit = credSeq->begin(); seqit != credSeq->end(); ++seqit) { - MappingNode *node = static_cast(*seqit); + for (const auto &seqit : *credSeq) { + MappingNode *node = static_cast(seqit); delete node->getValue(CONFIG_ACCOUNT_USERNAME); delete node->getValue(CONFIG_ACCOUNT_PASSWORD); delete node->getValue(CONFIG_ACCOUNT_REALM); @@ -300,8 +297,8 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter) #ifdef SFL_VIDEO Sequence *videoCodecSeq = videoCodecs.getSequence(); - for (Sequence::iterator i = videoCodecSeq->begin(); i != videoCodecSeq->end(); ++i) { - MappingNode *node = static_cast(*i); + for (auto &i : *videoCodecSeq) { + MappingNode *node = static_cast(i); delete node->getValue(VIDEO_CODEC_NAME); delete node->getValue(VIDEO_CODEC_BITRATE); delete node->getValue(VIDEO_CODEC_ENABLED); @@ -346,8 +343,8 @@ void SIPAccount::unserialize(const Conf::YamlNode &mapNode) } else { vector > videoCodecDetails; - for (Sequence::iterator it = seq->begin(); it != seq->end(); ++it) { - MappingNode *codec = static_cast(*it); + for (auto it : *seq) { + MappingNode *codec = static_cast(it); map codecMap; codec->getValue(VIDEO_CODEC_NAME, &codecMap[VIDEO_CODEC_NAME]); codec->getValue(VIDEO_CODEC_BITRATE, &codecMap[VIDEO_CODEC_BITRATE]); @@ -410,11 +407,10 @@ void SIPAccount::unserialize(const Conf::YamlNode &mapNode) */ if (credNode && credNode->getType() == SEQUENCE) { SequenceNode *credSeq = static_cast(credNode); - Sequence::iterator it; Sequence *seq = credSeq->getSequence(); - for (it = seq->begin(); it != seq->end(); ++it) { - MappingNode *cred = static_cast(*it); + for (auto it : *seq) { + MappingNode *cred = static_cast(it); std::string user; std::string pass; std::string realm; @@ -599,10 +595,9 @@ std::map SIPAccount::getAccountDetails() const a[CONFIG_ACCOUNT_PASSWORD] = ""; if (hasCredentials()) { - std::vector >::const_iterator vect_iter; - for (vect_iter = credentials_.begin(); vect_iter != credentials_.end(); vect_iter++) { - const std::string password = retrievePassword(*vect_iter, username_); + for (const auto &vect_iter : credentials_) { + const std::string password = retrievePassword(vect_iter, username_); if (not password.empty()) a[CONFIG_ACCOUNT_PASSWORD] = password; @@ -804,10 +799,8 @@ void SIPAccount::trimCiphers() // PJSIP aborts if our cipher list exceeds 1010 characters static const int MAX_CIPHERS_STRLEN = 1010; - CipherArray::const_iterator iter; - - for (iter = ciphers_.begin(); iter != ciphers_.end(); ++iter) { - sum += strlen(pj_ssl_cipher_name(*iter)); + for (const auto &iter : ciphers_) { + sum += strlen(pj_ssl_cipher_name(iter)); if (sum > MAX_CIPHERS_STRLEN) break; @@ -907,8 +900,8 @@ bool SIPAccount::userMatch(const std::string& username) const namespace { bool haveValueInCommon(const std::vector &a, const std::vector &b) { - for (std::vector::const_iterator i = a.begin(); i != a.end(); ++i) - if (std::find(b.begin(), b.end(), *i) != b.end()) + for (const auto &i : a) + if (std::find(b.begin(), b.end(), i) != b.end()) return true; return false; @@ -1121,13 +1114,13 @@ void SIPAccount::setCredentials(const std::vector >::iterator it = credentials_.begin(); it != credentials_.end(); ++it) { - map::const_iterator val = (*it).find(CONFIG_ACCOUNT_USERNAME); - const std::string username = val != (*it).end() ? val->second : ""; - val = (*it).find(CONFIG_ACCOUNT_REALM); - const std::string realm(val != (*it).end() ? val->second : ""); - val = (*it).find(CONFIG_ACCOUNT_PASSWORD); - const std::string password(val != (*it).end() ? val->second : ""); + for (auto &it : credentials_) { + map::const_iterator val = it.find(CONFIG_ACCOUNT_USERNAME); + const std::string username = val != it.end() ? val->second : ""; + val = it.find(CONFIG_ACCOUNT_REALM); + const std::string realm(val != it.end() ? val->second : ""); + val = it.find(CONFIG_ACCOUNT_PASSWORD); + const std::string password(val != it.end() ? val->second : ""); if (md5HashingEnabled) { // TODO: Fix this. @@ -1140,7 +1133,7 @@ void SIPAccount::setCredentials(const std::vector >::const_iterator iter = credentials_.begin(); - iter != credentials_.end(); ++iter) { - map::const_iterator val = (*iter).find(CONFIG_ACCOUNT_PASSWORD); - const std::string password = val != (*iter).end() ? val->second : ""; + for (const auto &iter : credentials_) { + map::const_iterator val = iter.find(CONFIG_ACCOUNT_PASSWORD); + const std::string password = val != iter.end() ? val->second : ""; int dataType = (md5HashingEnabled and password.length() == 32) ? PJSIP_CRED_DATA_DIGEST : PJSIP_CRED_DATA_PLAIN_PASSWD; - val = (*iter).find(CONFIG_ACCOUNT_USERNAME); + val = iter.find(CONFIG_ACCOUNT_USERNAME); - if (val != (*iter).end()) + if (val != iter.end()) cred_[i].username = pj_str((char*) val->second.c_str()); cred_[i].data = pj_str((char*) password.c_str()); - val = (*iter).find(CONFIG_ACCOUNT_REALM); + val = iter.find(CONFIG_ACCOUNT_REALM); - if (val != (*iter).end()) + if (val != iter.end()) cred_[i].realm = pj_str((char*) val->second.c_str()); cred_[i].data_type = dataType;