diff --git a/include/AutonomousSystem.h b/include/AutonomousSystem.h index c51c0cedf9..9758178390 100644 --- a/include/AutonomousSystem.h +++ b/include/AutonomousSystem.h @@ -65,8 +65,14 @@ class AutonomousSystem : public GenericHashEntry, public GenericTrafficElement, bool idle(); void lua(lua_State* vm, DetailsLevel details_level, bool asListElement); - inline void deserialize(json_object *obj) { GenericTrafficElement::deserialize(obj, iface); } - inline void serialize(json_object *obj, DetailsLevel details_level) { GenericTrafficElement::getJSONObject(obj, iface); } + inline void deserialize(json_object *obj) { + GenericHashEntry::deserialize(obj); + GenericTrafficElement::deserialize(obj, iface); + } + inline void serialize(json_object *obj, DetailsLevel details_level) { + GenericHashEntry::getJSONObject(obj, details_level); + GenericTrafficElement::getJSONObject(obj, iface); + } inline char* getSerializationKey(char *buf, uint bufsize) { snprintf(buf, bufsize, AS_SERIALIZED_KEY, iface->get_id(), asn); return(buf); } }; diff --git a/include/GenericHashEntry.h b/include/GenericHashEntry.h index a9133a3bd6..06b0607835 100644 --- a/include/GenericHashEntry.h +++ b/include/GenericHashEntry.h @@ -101,6 +101,9 @@ class GenericHashEntry { void incUses() { num_uses++; } void decUses() { num_uses--; } u_int16_t getUses() { return num_uses; } + + virtual void deserialize(json_object *obj); + virtual void getJSONObject(json_object *obj, DetailsLevel details_level); }; #endif /* _GENERIC_HASH_ENTRY_H_ */ diff --git a/include/Vlan.h b/include/Vlan.h index 11a870a798..241ac05f28 100644 --- a/include/Vlan.h +++ b/include/Vlan.h @@ -60,8 +60,14 @@ class Vlan : public GenericHashEntry, public GenericTrafficElement, public Seria bool idle(); void lua(lua_State* vm, DetailsLevel details_level, bool asListElement); - inline void deserialize(json_object *obj) { GenericTrafficElement::deserialize(obj, iface); } - inline void serialize(json_object *obj, DetailsLevel details_level) { GenericTrafficElement::getJSONObject(obj, iface); } + inline void deserialize(json_object *obj) { + GenericHashEntry::deserialize(obj); + GenericTrafficElement::deserialize(obj, iface); + } + inline void serialize(json_object *obj, DetailsLevel details_level) { + GenericHashEntry::getJSONObject(obj, details_level); + GenericTrafficElement::getJSONObject(obj, iface); + } inline char* getSerializationKey(char *buf, uint bufsize) { snprintf(buf, bufsize, VLAN_SERIALIZED_KEY, iface->get_id(), vlan_id); return(buf); } }; diff --git a/src/Country.cpp b/src/Country.cpp index 83805719ce..e32eb0e1fb 100644 --- a/src/Country.cpp +++ b/src/Country.cpp @@ -101,6 +101,7 @@ bool Country::equal(const char *country) { void Country::deserialize(json_object *o) { json_object *obj; + GenericHashEntry::deserialize(o); if(json_object_object_get_ex(o, "traffic", &obj)) sent.deserialize(obj); if(json_object_object_get_ex(o, "dirstats", &obj)) @@ -111,6 +112,7 @@ void Country::deserialize(json_object *o) { void Country::serialize(json_object *o, DetailsLevel details_level) { json_object *obj; + GenericHashEntry::getJSONObject(o, details_level); if((obj = sent.getJSONObject()) != NULL) json_object_object_add(o, "traffic", obj); diff --git a/src/GenericHashEntry.cpp b/src/GenericHashEntry.cpp index 9c3c2e3d3e..c68d89f18c 100644 --- a/src/GenericHashEntry.cpp +++ b/src/GenericHashEntry.cpp @@ -67,3 +67,19 @@ bool GenericHashEntry::isIdle(u_int max_idleness) { return(will_be_purged || (((u_int)(iface->getTimeLastPktRcvd()) > (last_seen+max_idleness)) ? true : false)); } + +/* ***************************************** */ + +void GenericHashEntry::deserialize(json_object *o) { + json_object *obj; + + if(json_object_object_get_ex(o, "seen.first", &obj)) first_seen = json_object_get_int64(obj); + if(json_object_object_get_ex(o, "seen.last", &obj)) last_seen = json_object_get_int64(obj); +} + +/* ***************************************** */ + +void GenericHashEntry::getJSONObject(json_object *my_object, DetailsLevel details_level) { + json_object_object_add(my_object, "seen.first", json_object_new_int64(first_seen)); + json_object_object_add(my_object, "seen.last", json_object_new_int64(last_seen)); +} diff --git a/src/Host.cpp b/src/Host.cpp index d9aff83e4f..32713d0145 100644 --- a/src/Host.cpp +++ b/src/Host.cpp @@ -815,8 +815,7 @@ void Host::serialize(json_object *my_object, DetailsLevel details_level) { json_object_object_add(my_object, "ifid", json_object_new_int(iface->get_id())); if(details_level >= details_high) { - json_object_object_add(my_object, "seen.first", json_object_new_int64(first_seen)); - json_object_object_add(my_object, "seen.last", json_object_new_int64(last_seen)); + GenericHashEntry::getJSONObject(my_object, details_level); json_object_object_add(my_object, "last_stats_reset", json_object_new_int64(last_stats_reset)); json_object_object_add(my_object, "asn", json_object_new_int(asn)); diff --git a/src/LocalHost.cpp b/src/LocalHost.cpp index 2fc6ae6169..3948630303 100644 --- a/src/LocalHost.cpp +++ b/src/LocalHost.cpp @@ -149,8 +149,7 @@ void LocalHost::deserialize(json_object *o) { ntop->getTrace()->traceEvent(TRACE_WARNING, "Internal error: NULL mac. Are you running out of memory or MAC hash is full?"); } - if(json_object_object_get_ex(o, "seen.first", &obj)) first_seen = json_object_get_int64(obj); - if(json_object_object_get_ex(o, "seen.last", &obj)) last_seen = json_object_get_int64(obj); + GenericHashEntry::deserialize(o); if(json_object_object_get_ex(o, "last_stats_reset", &obj)) last_stats_reset = json_object_get_int64(obj); if(json_object_object_get_ex(o, "broadcastDomainHost", &obj) && json_object_get_boolean(obj)) setBroadcastDomainHost();