summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-12-06 12:03:03 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2011-12-06 12:03:03 +0100
commitfbeee6710e4132a921ea3c7de15799a8eb681e97 (patch)
tree2910d925f1dfd414ce21a9be6ba19669c59aef8f /server
parent5e0afb2c9239fd8695ff338f92fe113d593b2bf0 (diff)
Force split values with dot ('.') in the names into groups.
Diffstat (limited to 'server')
-rw-r--r--server/src/luaquerymapper.cc46
1 files changed, 45 insertions, 1 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc
index 27dc21f..56ea1e9 100644
--- a/server/src/luaquerymapper.cc
+++ b/server/src/luaquerymapper.cc
@@ -109,9 +109,53 @@ LUAQueryMapper::~LUAQueryMapper()
if(L) lua_close(L);
}
+static QueryResult splitgroups(QueryResult r)
+{
+ QueryResult result;
+
+ result.timestamp = r.timestamp;
+ result.source = r.source;
+
+ std::map< std::string, QueryResult >::iterator gi = r.groups.begin();
+ while(gi != r.groups.end()) {
+ QueryResult child = splitgroups(gi->second);
+ result.groups[gi->first] = child;
+ gi++;
+ }
+
+ std::map< std::string, std::string >::iterator vi = r.values.begin();
+ while(vi != r.values.end()) {
+ std::string name = vi->first;
+
+ // Also insert in table with name containing '.'.
+ if(name.find(".") != std::string::npos) result.values[name] = vi->second;
+
+ QueryResult *ncurrent = &result;
+ while(name.find(".") != std::string::npos) {
+ DEBUG(splitgroups, "value name: %s\n", name.c_str());
+ QueryResult grp;
+ grp.timestamp = ncurrent->timestamp;
+ grp.source = ncurrent->source;
+ std::string grpname = name.substr(0, name.find("."));
+ ncurrent->groups[grpname] = grp;
+ ncurrent = &(ncurrent->groups[grpname]);
+ name = name.substr(name.find(".") + 1);
+ }
+ ncurrent->values[name] = vi->second;
+
+ vi++;
+ }
+
+ return result;
+}
+
+
void LUAQueryMapper::addQueryResult(QueryResult &result) throw(Exception)
{
- loadResult(L, result);
+ // Check for '.' in names and further split up into groups.
+ QueryResult splitted = splitgroups(result);
+
+ loadResult(L, splitted);
clean_top = lua_gettop(L);
}