diff options
-rw-r--r-- | server/src/luaquerymapper.cc | 46 |
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); } |