CompatUtility: Fix host 2d_coords.

Fixes #5917
This commit is contained in:
Michael Friedrich 2014-04-02 14:43:40 +02:00
parent 9344399f44
commit a05c31cda2
3 changed files with 34 additions and 36 deletions

View File

@ -347,11 +347,6 @@ Value HostsTable::NotesUrlAccessor(const Value& row)
if (!host)
return Empty;
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
return Empty;
return CompatUtility::GetCustomAttributeConfig(host, "notes_url");
}
@ -1066,20 +1061,7 @@ Value HostsTable::X2dAccessor(const Value& row)
if (!host)
return Empty;
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
return Empty;
String coords = custom->Get("2d_coords");
std::vector<String> tokens;
boost::algorithm::split(tokens, coords, boost::is_any_of(","));
if (tokens.size() != 2)
return Empty;
return tokens[0];
return CompatUtility::GetHost2dCoordX(host);
}
Value HostsTable::Y2dAccessor(const Value& row)
@ -1089,20 +1071,7 @@ Value HostsTable::Y2dAccessor(const Value& row)
if (!host)
return Empty;
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
return Empty;
String coords = custom->Get("2d_coords");
std::vector<String> tokens;
boost::algorithm::split(tokens, coords, boost::is_any_of(","));
if (tokens.size() != 2)
return Empty;
return tokens[1];
return CompatUtility::GetHost2dCoordY(host);
}
Value HostsTable::LatencyAccessor(const Value& row)

View File

@ -111,11 +111,18 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host)
Host2dCoords bag;
if (custom) {
bag.have_2d_coords = (custom->Get("x_2d") && custom->Get("y_2d") ? 1 : 0);
String coords = custom->Get("2d_coords");
bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0);
std::vector<String> tokens;
boost::algorithm::split(tokens, coords, boost::is_any_of(","));
if (tokens.size() != 2)
bag.have_2d_coords = 0;
if (bag.have_2d_coords == 1) {
bag.x_2d = custom->Get("x_2d");
bag.y_2d = custom->Get("y_2d");
bag.x_2d = tokens[0];
bag.y_2d = tokens[1];
}
} else {
bag.have_2d_coords = 0;
@ -124,6 +131,26 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host)
return bag;
}
String CompatUtility::GetHost2dCoordX(const Host::Ptr& host)
{
Host2dCoords bag = GetHost2dCoords(host);
if (bag.have_2d_coords == 0)
return Empty;
return bag.x_2d;
}
String CompatUtility::GetHost2dCoordY(const Host::Ptr& host)
{
Host2dCoords bag = GetHost2dCoords(host);
if (bag.have_2d_coords == 0)
return Empty;
return bag.y_2d;
}
int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host)
{
ASSERT(host->OwnsLock());

View File

@ -59,6 +59,8 @@ public:
static String GetHostAddress(const Host::Ptr& host);
static String GetHostAddress6(const Host::Ptr& host);
static Host2dCoords GetHost2dCoords(const Host::Ptr& host);
static String GetHost2dCoordX(const Host::Ptr& host);
static String GetHost2dCoordY(const Host::Ptr& host);
static int GetHostNotifyOnDown(const Host::Ptr& host);
static int GetHostNotifyOnUnreachable(const Host::Ptr& host);