struct IP_MASK
{
IP_MASK() : ip(0), mask(0) {}
-IP_MASK(const IP_MASK & ipm) : ip(ipm.ip), mask(ipm.mask) {}
uint32_t ip;
uint32_t mask;
};
class USER_IPS
{
friend std::ostream & operator<< (std::ostream & o, const USER_IPS & i);
- //friend stringstream & operator<< (stringstream & s, const USER_IPS & i);
friend const USER_IPS StrToIPS(const std::string & ipsStr);
public:
typedef std::vector<IP_MASK> ContainerType;
typedef ContainerType::size_type IndexType;
- USER_IPS();
- USER_IPS(const USER_IPS &);
- USER_IPS & operator=(const USER_IPS &);
- const IP_MASK & operator[](IndexType idx) const;
+ const IP_MASK & operator[](IndexType idx) const { return ips[idx]; }
std::string GetIpStr() const;
bool IsIPInIPS(uint32_t ip) const;
bool OnlyOneIP() const;
bool IsAnyIP() const;
- size_t Count() const;
- void Add(const IP_MASK &im);
- void Erase();
+ size_t Count() const { return ips.size(); }
+ void Add(const IP_MASK &im) { ips.push_back(im); }
private:
uint32_t CalcMask(unsigned int msk) const;
};
//-------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-inline
-USER_IPS::USER_IPS()
- : ips()
-{}
-//-----------------------------------------------------------------------------
-inline
-USER_IPS::USER_IPS(const USER_IPS & i)
- : ips(i.ips)
-{}
-//-----------------------------------------------------------------------------
-inline
-USER_IPS & USER_IPS::operator=(const USER_IPS & i)
-{
-ips = i.ips;
-return *this;
-}
-//-----------------------------------------------------------------------------
-inline
-const IP_MASK & USER_IPS::operator[](IndexType idx) const
-{
-return ips[idx];
-}
//-----------------------------------------------------------------------------
inline
std::string USER_IPS::GetIpStr() const
}
//-----------------------------------------------------------------------------
inline
-size_t USER_IPS::Count() const
-{
-return ips.size();
-}
-//-----------------------------------------------------------------------------
-inline
uint32_t USER_IPS::CalcMask(unsigned int msk) const
{
if (msk > 32)
}
//-----------------------------------------------------------------------------
inline
-void USER_IPS::Add(const IP_MASK &im)
-{
-ips.push_back(im);
-}
-//-----------------------------------------------------------------------------
-inline
-void USER_IPS::Erase()
-{
-ips.erase(ips.begin(), ips.end());
-}
-//-----------------------------------------------------------------------------
-inline
std::ostream & operator<<(std::ostream & o, const USER_IPS & i)
{
return o << i.GetIpStr();
}
//-----------------------------------------------------------------------------
-/*inline
-stringstream & operator<<(std::stringstream & s, const USER_IPS & i)
-{
-s << i.GetIpStr();
-return s;
-}*/
-//-----------------------------------------------------------------------------
inline
const USER_IPS StrToIPS(const std::string & ipsStr)
{
tuples = PQntuples(result);
-conf->ips.Erase();
+USER_IPS ips;
for (int i = 0; i < tuples; ++i)
{
- IP_MASK ipm;
+ IP_MASK im;
- int ip, mask;
+ im.ip = inet_strington(PQgetvalue(result, i, 0));
- ip = inet_strington(PQgetvalue(result, i, 0));
-
- if (str2x(PQgetvalue(result, i, 1), mask))
+ if (str2x(PQgetvalue(result, i, 1), im.mask))
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreUserConf(): 'Failed to fetch mask'\n");
continue;
}
- ipm.ip = ip;
- ipm.mask = mask;
-
- conf->ips.Add(ipm);
+ ips.Add(im);
}
+conf->ips = ips;
PQclear(result);