Remove GetCharArg(). Organize CLI options file.

GetCharArg() was either a hack to keep from segfaulting when using
this botched option parser or it was old forgotten code - or both.

GetCharArg() was not needed because from_string() has std::string
overloaded and every GetCharArg() made its way to from_string().

Note: when using from_string() with std::string, it must be caught!
This commit is contained in:
anonimal 2015-11-14 16:13:08 +00:00
parent 1eff72d525
commit 5ae7e35e80
9 changed files with 60 additions and 46 deletions

View file

@ -42,8 +42,8 @@ namespace i2p
int port = i2p::util::config::GetArg("-port", 0);
if (!port)
port = m_Rnd.GenerateWord32 (9111, 30777); // I2P network ports range
routerInfo.AddSSUAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"), port, routerInfo.GetIdentHash ());
routerInfo.AddNTCPAddress (i2p::util::config::GetCharArg("-host", "127.0.0.1"), port);
routerInfo.AddSSUAddress (i2p::util::config::GetArg("-host", "127.0.0.1"), port, routerInfo.GetIdentHash ());
routerInfo.AddNTCPAddress (i2p::util::config::GetArg("-host", "127.0.0.1"), port);
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
routerInfo.SetProperty ("coreVersion", I2P_VERSION);

View file

@ -472,7 +472,7 @@ namespace data
s.write (str.c_str (), len);
}
void RouterInfo::AddNTCPAddress (const char * host, int port)
void RouterInfo::AddNTCPAddress (const std::string& host, int port)
{
Address addr;
addr.host = boost::asio::ip::address::from_string (host);
@ -485,7 +485,7 @@ namespace data
m_SupportedTransports |= addr.host.is_v6 () ? eNTCPV6 : eNTCPV4;
}
void RouterInfo::AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu)
void RouterInfo::AddSSUAddress (const std::string& host, int port, const uint8_t * key, int mtu)
{
Address addr;
addr.host = boost::asio::ip::address::from_string (host);

View file

@ -103,8 +103,8 @@ namespace data
const Address * GetSSUAddress (bool v4only = true) const;
const Address * GetSSUV6Address () const;
void AddNTCPAddress (const char * host, int port);
void AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu = 0);
void AddNTCPAddress (const std::string& host, int port);
void AddSSUAddress (const std::string& host, int port, const uint8_t * key, int mtu = 0);
bool AddIntroducer (const Address * address, uint32_t tag);
bool RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
void SetProperty (const std::string& key, const std::string& value); // called from RouterContext only

View file

@ -63,6 +63,7 @@ http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found */
namespace i2p {
namespace util {
// TODO: this will be replaced by a real option parser soon.
namespace config {
std::map<std::string, std::string> mapArgs;
std::map<std::string, std::vector<std::string> > mapMultiArgs;

View file

@ -38,12 +38,6 @@ namespace util
*/
std::string GetArg(const std::string& strArg, const std::string& strDefault);
/**
* @return a command line argument from config::mapArgs as a C-style string
* @param nDefault the default value to be returned
*/
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
/**
* @return true if the argument is set, false otherwise
*/