From 134016c61e7b9fdb9653f864446ef2ac62fcbcf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= <rafael.carre@savoirfairelinux.com> Date: Wed, 27 Jul 2011 17:58:17 -0400 Subject: [PATCH] * #6540: yaml parser : remove std::string typedefs --- sflphone-common/src/account.h | 26 ++--- sflphone-common/src/config/yamlemitter.cpp | 2 +- sflphone-common/src/config/yamlemitter.h | 2 +- sflphone-common/src/config/yamlnode.cpp | 20 ++-- sflphone-common/src/config/yamlnode.h | 34 ++++--- sflphone-common/src/config/yamlparser.cpp | 18 ++-- sflphone-common/src/managerimpl.cpp | 16 ++-- sflphone-common/src/preferences.cpp | 2 +- sflphone-common/src/preferences.h | 106 ++++++++++----------- sflphone-common/src/sip/sipaccount.h | 76 +++++++-------- 10 files changed, 149 insertions(+), 153 deletions(-) diff --git a/sflphone-common/src/account.h b/sflphone-common/src/account.h index cd3588126c..56b7669eb6 100644 --- a/sflphone-common/src/account.h +++ b/sflphone-common/src/account.h @@ -135,19 +135,19 @@ typedef enum RegistrationState { // General configuration keys for accounts -const Conf::Key aliasKey ("alias"); -const Conf::Key typeKey ("type"); -const Conf::Key idKey ("id"); -const Conf::Key usernameKey ("username"); -const Conf::Key passwordKey ("password"); -const Conf::Key hostnameKey ("hostname"); -const Conf::Key accountEnableKey ("enable"); -const Conf::Key mailboxKey ("mailbox"); - -const Conf::Key codecsKey ("codecs"); // 0/9/110/111/112/ -const Conf::Key ringtonePathKey ("ringtonePath"); -const Conf::Key ringtoneEnabledKey ("ringtoneEnabled"); -const Conf::Key displayNameKey ("displayName"); +const std::string aliasKey ("alias"); +const std::string typeKey ("type"); +const std::string idKey ("id"); +const std::string usernameKey ("username"); +const std::string passwordKey ("password"); +const std::string hostnameKey ("hostname"); +const std::string accountEnableKey ("enable"); +const std::string mailboxKey ("mailbox"); + +const std::string codecsKey ("codecs"); // 0/9/110/111/112/ +const std::string ringtonePathKey ("ringtonePath"); +const std::string ringtoneEnabledKey ("ringtoneEnabled"); +const std::string displayNameKey ("displayName"); class Account : public Serializable { diff --git a/sflphone-common/src/config/yamlemitter.cpp b/sflphone-common/src/config/yamlemitter.cpp index 30eacbb9b9..7adf49263f 100644 --- a/sflphone-common/src/config/yamlemitter.cpp +++ b/sflphone-common/src/config/yamlemitter.cpp @@ -341,7 +341,7 @@ void YamlEmitter::serializeShortcutPreference (MappingNode *map) throw(YamlEmitt } -void YamlEmitter::addMappingItem (int mappingid, Key key, YamlNode *node) +void YamlEmitter::addMappingItem (int mappingid, std::string key, YamlNode *node) { if (node->getType() == SCALAR) { diff --git a/sflphone-common/src/config/yamlemitter.h b/sflphone-common/src/config/yamlemitter.h index b284072b58..8c45c3ab27 100644 --- a/sflphone-common/src/config/yamlemitter.h +++ b/sflphone-common/src/config/yamlemitter.h @@ -97,7 +97,7 @@ class YamlEmitter private: - void addMappingItem (int mappingid, Key key, YamlNode *node); + void addMappingItem (int mappingid, std::string key, YamlNode *node); std::string filename; diff --git a/sflphone-common/src/config/yamlnode.cpp b/sflphone-common/src/config/yamlnode.cpp index f61bc544fd..1eece93f91 100644 --- a/sflphone-common/src/config/yamlnode.cpp +++ b/sflphone-common/src/config/yamlnode.cpp @@ -92,16 +92,16 @@ void YamlDocument::deleteChildNodes() void MappingNode::addNode (YamlNode *node) { Mapping::iterator it = map.end(); - map.insert (it, std::pair<Key, YamlNode *> (tmpKey, node)); + map.insert (it, std::pair<std::string, YamlNode *> (tmpKey, node)); } -void MappingNode::setKeyValue (Key key, YamlNode *value) +void MappingNode::setKeyValue (std::string key, YamlNode *value) { Mapping::iterator it = map.end(); - map.insert (it, std::pair<Key, YamlNode *> (key, value)); + map.insert (it, std::pair<std::string, YamlNode *> (key, value)); } -void MappingNode::removeKeyValue (Key key) +void MappingNode::removeKeyValue (std::string key) { Mapping::iterator it = map.find (key); @@ -109,7 +109,7 @@ void MappingNode::removeKeyValue (Key key) } -YamlNode *MappingNode::getValue (Key key) +YamlNode *MappingNode::getValue (std::string key) { Mapping::iterator it = map.find (key); @@ -122,27 +122,27 @@ YamlNode *MappingNode::getValue (Key key) } } -void MappingNode::getValue (Key key, bool *b) +void MappingNode::getValue (std::string key, bool *b) { ScalarNode *node = (ScalarNode*)getValue(key); if (!node) return; - const Value &v = node->getValue(); + const std::string &v = node->getValue(); *b = v == "true"; } -void MappingNode::getValue (Key key, int *i) +void MappingNode::getValue (std::string key, int *i) { ScalarNode *node = (ScalarNode*)getValue(key); if (!node) return; - const Value &v = node->getValue(); + const std::string &v = node->getValue(); *i = atoi(v.c_str()); } -void MappingNode::getValue (Key key, Value *v) +void MappingNode::getValue (std::string key, std::string *v) { ScalarNode *node = (ScalarNode*)getValue(key); if (!node) diff --git a/sflphone-common/src/config/yamlnode.h b/sflphone-common/src/config/yamlnode.h index d36b662fb4..03ef54266f 100644 --- a/sflphone-common/src/config/yamlnode.h +++ b/sflphone-common/src/config/yamlnode.h @@ -42,10 +42,8 @@ namespace Conf class YamlNode; -typedef std::string Key; -typedef std::string Value; typedef std::list<YamlNode *> Sequence; -typedef std::map<Key, YamlNode *> Mapping; +typedef std::map<std::string, YamlNode *> Mapping; class YamlNodeException : public std::exception { @@ -160,18 +158,18 @@ class MappingNode : public YamlNode void addNode (YamlNode *node); - void setTmpKey (Key key) { + void setTmpKey (std::string key) { tmpKey = key; } - void setKeyValue (Key key, YamlNode *value); + void setKeyValue (std::string key, YamlNode *value); - void removeKeyValue (Key key); + void removeKeyValue (std::string key); - YamlNode *getValue (Key key); - void getValue (Key key, bool *b); - void getValue (Key key, int *i); - void getValue (Key key, Value *v); + YamlNode *getValue (std::string key); + void getValue (std::string key, bool *b); + void getValue (std::string key, int *i); + void getValue (std::string key, std::string *s); virtual void deleteChildNodes (void); @@ -179,7 +177,7 @@ class MappingNode : public YamlNode Mapping map; - Key tmpKey; + std::string tmpKey; }; @@ -189,24 +187,24 @@ class ScalarNode : public YamlNode public: - ScalarNode (Value v="", YamlNode *top=NULL) : YamlNode (SCALAR, top), val (v) {} - ScalarNode (bool b, YamlNode *top=NULL) : YamlNode (SCALAR, top), val (b ? "true" : "false") {} + ScalarNode (std::string s="", YamlNode *top=NULL) : YamlNode (SCALAR, top), str (s) {} + ScalarNode (bool b, YamlNode *top=NULL) : YamlNode (SCALAR, top), str (b ? "true" : "false") {} ~ScalarNode() {} - Value getValue() { - return val; + const std::string &getValue() { + return str; } - void setValue (Value v) { - val = v; + void setValue (const std::string &s) { + str = s; } virtual void deleteChildNodes (void) {} private: - Value val; + std::string str; }; diff --git a/sflphone-common/src/config/yamlparser.cpp b/sflphone-common/src/config/yamlparser.cpp index d8e49aa464..bbf92c49ce 100644 --- a/sflphone-common/src/config/yamlparser.cpp +++ b/sflphone-common/src/config/yamlparser.cpp @@ -413,9 +413,7 @@ void YamlParser::processMapping (YamlNode *topNode) throw(YamlParserException) if (events[eventIndex].type != YAML_SCALAR_EVENT) throw YamlParserException ("Mapping not followed by a key"); - char buffer[1000]; - snprintf (buffer, 1000, "%s", events[eventIndex].data.scalar.value); - map->setTmpKey (Key (buffer)); + map->setTmpKey (std::string ((const char *)events[eventIndex].data.scalar.value)); eventIndex++; @@ -494,13 +492,13 @@ void YamlParser::mainNativeDataMapping (MappingNode *map) throw(YamlParserExcept try { Mapping::iterator iter = map->getMapping()->begin(); - Key accounts ("accounts"); - Key addressbook ("addressbook"); - Key audio ("audio"); - Key hooks ("hooks"); - Key preferences ("preferences"); - Key voiplink ("voipPreferences"); - Key shortcuts ("shortcuts"); + std::string accounts ("accounts"); + std::string addressbook ("addressbook"); + std::string audio ("audio"); + std::string hooks ("hooks"); + std::string preferences ("preferences"); + std::string voiplink ("voipPreferences"); + std::string shortcuts ("shortcuts"); while (iter != map->getMapping()->end()) { diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 0f38bc1325..fca0282250 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -4206,7 +4206,7 @@ void ManagerImpl::loadIptoipProfile() Conf::SequenceNode *seq = parser->getAccountSequence(); Conf::Sequence::iterator iterIP2IP = seq->getSequence()->begin(); - Conf::Key accID ("id"); + std::string accID ("id"); // Iterate over every account maps while (iterIP2IP != seq->getSequence()->end()) { @@ -4214,7 +4214,7 @@ void ManagerImpl::loadIptoipProfile() Conf::MappingNode *map = (Conf::MappingNode *) (*iterIP2IP); // Get the account id - Conf::Value accountid; + std::string accountid; map->getValue (accID, &accountid); // if ID is IP2IP, unserialize @@ -4273,9 +4273,9 @@ short ManagerImpl::loadAccountMap() // Each element in sequence is a new account to create Conf::Sequence::iterator iterSeq = seq->getSequence()->begin(); - Conf::Key accTypeKey ("type"); - Conf::Key accID ("id"); - Conf::Key alias ("alias"); + std::string accTypeKey ("type"); + std::string accID ("id"); + std::string alias ("alias"); while (iterSeq != seq->getSequence()->end()) { @@ -4284,15 +4284,15 @@ short ManagerImpl::loadAccountMap() Conf::MappingNode *map = (Conf::MappingNode *) (*iterSeq); // Search for account types (IAX/IP2IP) - Conf::Value accountType = "SIP"; // Assume type is SIP if not specified + std::string accountType = "SIP"; // Assume type is SIP if not specified map->getValue (accTypeKey, &accountType); // search for account id - Conf::Value accountid; + std::string accountid; map->getValue (accID, &accountid); // search for alias (to get rid of the "ghost" account) - Conf::Value accountAlias; + std::string accountAlias; map->getValue (alias, &accountAlias); // do not insert in account map if id or alias is empty diff --git a/sflphone-common/src/preferences.cpp b/sflphone-common/src/preferences.cpp index 92978e5dd6..afcda7ab7a 100644 --- a/sflphone-common/src/preferences.cpp +++ b/sflphone-common/src/preferences.cpp @@ -116,7 +116,7 @@ void Preferences::unserialize (Conf::MappingNode *map) } map->getValue (orderKey, &_accountOrder); - Conf::Value audioApi; + std::string audioApi; map->getValue (audioApiKey, &audioApi); // 1 is pulseaudio, 0 is alsa _audioApi = (audioApi == "pulseaudio") ? 1 : 0; diff --git a/sflphone-common/src/preferences.h b/sflphone-common/src/preferences.h index aa03cb5018..9d3aad5f5f 100644 --- a/sflphone-common/src/preferences.h +++ b/sflphone-common/src/preferences.h @@ -34,69 +34,69 @@ #include "config/serializable.h" // general preferences -const Conf::Key orderKey ("order"); // : 1234/2345/ -const Conf::Key audioApiKey ("audioApi"); // : 0 -const Conf::Key historyLimitKey ("historyLimit"); // : 30 -const Conf::Key historyMaxCallsKey ("historyMaxCalls"); // : 20 -const Conf::Key notifyMailsKey ("notifyMails"); // : false -const Conf::Key zoneToneChoiceKey ("zoneToneChoice"); // : North America -const Conf::Key registrationExpireKey ("registrationExpire");// : 180 -const Conf::Key portNumKey ("portNum"); // : 5060 -const Conf::Key searchBarDisplayKey ("searchBarDisplay"); // : true -const Conf::Key zeroConfenableKey ("zeroConfenable"); // : false -const Conf::Key md5HashKey ("md5Hash"); // : false +const std::string orderKey ("order"); // : 1234/2345/ +const std::string audioApiKey ("audioApi"); // : 0 +const std::string historyLimitKey ("historyLimit"); // : 30 +const std::string historyMaxCallsKey ("historyMaxCalls"); // : 20 +const std::string notifyMailsKey ("notifyMails"); // : false +const std::string zoneToneChoiceKey ("zoneToneChoice"); // : North America +const std::string registrationExpireKey ("registrationExpire");// : 180 +const std::string portNumKey ("portNum"); // : 5060 +const std::string searchBarDisplayKey ("searchBarDisplay"); // : true +const std::string zeroConfenableKey ("zeroConfenable"); // : false +const std::string md5HashKey ("md5Hash"); // : false // voip preferences -const Conf::Key playDtmfKey ("playDtmf"); // true true -const Conf::Key playTonesKey ("playTones"); // true -const Conf::Key pulseLengthKey ("pulseLength"); //=250 -const Conf::Key symmetricRtpKey ("symmetric");// =true -const Conf::Key zidFileKey ("zidFile");// =sfl.zid +const std::string playDtmfKey ("playDtmf"); // true true +const std::string playTonesKey ("playTones"); // true +const std::string pulseLengthKey ("pulseLength"); //=250 +const std::string symmetricRtpKey ("symmetric");// =true +const std::string zidFileKey ("zidFile");// =sfl.zid // addressbook preferences -const Conf::Key photoKey ("photo");// false -const Conf::Key enabledKey ("enabled");// true -const Conf::Key listKey ("list");// 1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ -const Conf::Key maxResultsKey ("maxResults");// 25 -const Conf::Key businessKey ("business");// true -const Conf::Key homeKey ("home");// false -const Conf::Key mobileKey ("mobile");// false +const std::string photoKey ("photo");// false +const std::string enabledKey ("enabled");// true +const std::string listKey ("list");// 1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ +const std::string maxResultsKey ("maxResults");// 25 +const std::string businessKey ("business");// true +const std::string homeKey ("home");// false +const std::string mobileKey ("mobile");// false // hooks preferences -const Conf::Key iax2EnabledKey ("iax2Enabled");// : false -const Conf::Key numberAddPrefixKey ("numberAddPrefix");//: false -const Conf::Key numberEnabledKey ("numberEnabled"); //: false -const Conf::Key sipEnabledKey ("sipEnabled"); //: false -const Conf::Key urlCommandKey ("urlCommand"); //: x-www-browser -const Conf::Key urlSipFieldKey ("urlSipField"); //: X-sflphone-url +const std::string iax2EnabledKey ("iax2Enabled");// : false +const std::string numberAddPrefixKey ("numberAddPrefix");//: false +const std::string numberEnabledKey ("numberEnabled"); //: false +const std::string sipEnabledKey ("sipEnabled"); //: false +const std::string urlCommandKey ("urlCommand"); //: x-www-browser +const std::string urlSipFieldKey ("urlSipField"); //: X-sflphone-url // audio preferences -const Conf::Key alsamapKey ("alsa"); -const Conf::Key pulsemapKey ("pulse"); -const Conf::Key cardinKey ("cardIn");// : 0 -const Conf::Key cardoutKey ("cardOut");// 0 -const Conf::Key cardringKey ("cardRing");// : 0 -const Conf::Key framesizeKey ("frameSize");// : 20 -const Conf::Key pluginKey ("plugin"); //: default -const Conf::Key smplrateKey ("smplRate");//: 44100 -const Conf::Key devicePlaybackKey ("devicePlayback");//: -const Conf::Key deviceRecordKey ("deviceRecord");// : -const Conf::Key deviceRingtoneKey ("deviceRingtone");// : -const Conf::Key recordpathKey ("recordPath");//: /home/msavard/Bureau -const Conf::Key alwaysRecordingKey("alwaysRecording"); -const Conf::Key volumemicKey ("volumeMic");//: 100 -const Conf::Key volumespkrKey ("volumeSpkr");//: 100 -const Conf::Key noiseReduceKey ("noiseReduce"); -const Conf::Key echoCancelKey ("echoCancel"); -const Conf::Key echoTailKey ("echoTailLength"); -const Conf::Key echoDelayKey ("echoDelayLength"); +const std::string alsamapKey ("alsa"); +const std::string pulsemapKey ("pulse"); +const std::string cardinKey ("cardIn");// : 0 +const std::string cardoutKey ("cardOut");// 0 +const std::string cardringKey ("cardRing");// : 0 +const std::string framesizeKey ("frameSize");// : 20 +const std::string pluginKey ("plugin"); //: default +const std::string smplrateKey ("smplRate");//: 44100 +const std::string devicePlaybackKey ("devicePlayback");//: +const std::string deviceRecordKey ("deviceRecord");// : +const std::string deviceRingtoneKey ("deviceRingtone");// : +const std::string recordpathKey ("recordPath");//: /home/msavard/Bureau +const std::string alwaysRecordingKey("alwaysRecording"); +const std::string volumemicKey ("volumeMic");//: 100 +const std::string volumespkrKey ("volumeSpkr");//: 100 +const std::string noiseReduceKey ("noiseReduce"); +const std::string echoCancelKey ("echoCancel"); +const std::string echoTailKey ("echoTailLength"); +const std::string echoDelayKey ("echoDelayLength"); // shortcut preferences -const Conf::Key hangupShortKey ("hangUp"); -const Conf::Key pickupShortKey ("pickUp"); -const Conf::Key popupShortKey ("popupWindow"); -const Conf::Key toggleHoldShortKey ("toggleHold"); -const Conf::Key togglePickupHangupShortKey ("togglePickupHangup"); +const std::string hangupShortKey ("hangUp"); +const std::string pickupShortKey ("pickUp"); +const std::string popupShortKey ("popupWindow"); +const std::string toggleHoldShortKey ("toggleHold"); +const std::string togglePickupHangupShortKey ("togglePickupHangup"); class Preferences : public Serializable diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h index 58d1371ed8..fa30b0fe42 100644 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -53,50 +53,50 @@ enum DtmfType { OVERRTP, SIPINFO}; // SIP specific configuration keys -const Conf::Key expireKey ("expire"); -const Conf::Key interfaceKey ("interface"); -const Conf::Key portKey ("port"); -const Conf::Key publishAddrKey ("publishAddr"); -const Conf::Key publishPortKey ("publishPort"); -const Conf::Key sameasLocalKey ("sameasLocal"); -const Conf::Key resolveOnceKey ("resolveOnce"); -const Conf::Key dtmfTypeKey ("dtmfType"); -const Conf::Key serviceRouteKey ("serviceRoute"); +const std::string expireKey ("expire"); +const std::string interfaceKey ("interface"); +const std::string portKey ("port"); +const std::string publishAddrKey ("publishAddr"); +const std::string publishPortKey ("publishPort"); +const std::string sameasLocalKey ("sameasLocal"); +const std::string resolveOnceKey ("resolveOnce"); +const std::string dtmfTypeKey ("dtmfType"); +const std::string serviceRouteKey ("serviceRoute"); // TODO: write an object to store credential which implement serializable -const Conf::Key srtpKey ("srtp"); -const Conf::Key srtpEnableKey ("enable"); -const Conf::Key keyExchangeKey ("keyExchange"); -const Conf::Key rtpFallbackKey ("rtpFallback"); +const std::string srtpKey ("srtp"); +const std::string srtpEnableKey ("enable"); +const std::string keyExchangeKey ("keyExchange"); +const std::string rtpFallbackKey ("rtpFallback"); // TODO: wirte an object to store zrtp params wich implement serializable -const Conf::Key zrtpKey ("zrtp"); -const Conf::Key displaySasKey ("displaySas"); -const Conf::Key displaySasOnceKey ("displaySasOnce"); -const Conf::Key helloHashEnabledKey ("helloHashEnabled"); -const Conf::Key notSuppWarningKey ("notSuppWarning"); +const std::string zrtpKey ("zrtp"); +const std::string displaySasKey ("displaySas"); +const std::string displaySasOnceKey ("displaySasOnce"); +const std::string helloHashEnabledKey ("helloHashEnabled"); +const std::string notSuppWarningKey ("notSuppWarning"); // TODO: write an object to store tls params which implement serializable -const Conf::Key tlsKey ("tls"); -const Conf::Key tlsPortKey ("tlsPort"); -const Conf::Key certificateKey ("certificate"); -const Conf::Key calistKey ("calist"); -const Conf::Key ciphersKey ("ciphers"); -const Conf::Key tlsEnableKey ("enable"); -const Conf::Key methodKey ("method"); -const Conf::Key timeoutKey ("timeout"); -const Conf::Key tlsPasswordKey ("password"); -const Conf::Key privateKeyKey ("privateKey"); -const Conf::Key requireCertifKey ("requireCertif"); -const Conf::Key serverKey ("server"); -const Conf::Key verifyClientKey ("verifyClient"); -const Conf::Key verifyServerKey ("verifyServer"); - -const Conf::Key stunEnabledKey ("stunEnabled"); -const Conf::Key stunServerKey ("stunServer"); - -const Conf::Key credKey ("credential"); -const Conf::Key credentialCountKey ("count"); +const std::string tlsKey ("tls"); +const std::string tlsPortKey ("tlsPort"); +const std::string certificateKey ("certificate"); +const std::string calistKey ("calist"); +const std::string ciphersKey ("ciphers"); +const std::string tlsEnableKey ("enable"); +const std::string methodKey ("method"); +const std::string timeoutKey ("timeout"); +const std::string tlsPasswordKey ("password"); +const std::string privateKeyKey ("privateKey"); +const std::string requireCertifKey ("requireCertif"); +const std::string serverKey ("server"); +const std::string verifyClientKey ("verifyClient"); +const std::string verifyServerKey ("verifyServer"); + +const std::string stunEnabledKey ("stunEnabled"); +const std::string stunServerKey ("stunServer"); + +const std::string credKey ("credential"); +const std::string credentialCountKey ("count"); class SIPVoIPLink; -- GitLab