Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/snmp_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,17 +993,12 @@ snmpAddNode(oid * name, int len, oid_ParseFn * parsefunction, instance_Fn * inst
MemBuf tmp;
debugs(49, 6, "snmpAddNode: Children : " << children << ", Oid : " << snmpDebugOid(name, len, tmp));

const auto entry = static_cast<mib_tree_entry *>(xmalloc(sizeof(mib_tree_entry)));
entry->name = name;
entry->len = len;
const auto entry = new mib_tree_entry(name, len, aggrType);
entry->parsefunction = parsefunction;
entry->instancefunction = instancefunction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reasons for not including parsefunction and instancefunction in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplicity for now. Later refactor steps will change them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does done look like with the later refactor steps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does done look like with the later refactor steps?

I suspect there will be two mib_tree_entry constructors, one setting (constant) parse/instance functions and one prohibiting them. Or two C++ class types to differentiate the two use cases. Or perhaps a lot more classes, with those functions converted to class methods. Delaying that non-trivial refactoring may be the right decision, but I have not studied all the necessary details to be sure.

entry->children = children;
entry->leaves = nullptr;
entry->parent = nullptr;
entry->aggrType = aggrType;

if (children > 0) {
entry->children = children;
entry->leaves = static_cast<mib_tree_entry **>(xmalloc(sizeof(mib_tree_entry *) * children));

va_list args;
Expand Down
28 changes: 17 additions & 11 deletions src/snmp_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,27 @@ class MemBuf;
#define MAX_PROTOSTAT 5

typedef variable_list *(oid_ParseFn) (variable_list *, snint *);
typedef struct _mib_tree_entry mib_tree_entry;
class mib_tree_entry;
typedef oid *(instance_Fn) (oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn);
typedef enum {atNone = 0, atSum, atAverage, atMax, atMin} AggrType;

struct _mib_tree_entry {
oid *name;
int len;
oid_ParseFn *parsefunction;
instance_Fn *instancefunction;
int children;

struct _mib_tree_entry **leaves;
class mib_tree_entry
{
MEMPROXY_CLASS(mib_tree_entry);
public:
mib_tree_entry(oid *aName, int aLen, AggrType type) : name(aName), len(aLen), aggrType(type) {}
~mib_tree_entry() = delete;

struct _mib_tree_entry *parent;
AggrType aggrType;
public:
oid * const name;
const int len;
oid_ParseFn *parsefunction = nullptr;
instance_Fn *instancefunction = nullptr;
int children = 0;

mib_tree_entry **leaves = nullptr;
mib_tree_entry *parent = nullptr;
const AggrType aggrType;
};

struct snmp_pdu* snmpAgentResponse(struct snmp_pdu* PDU);
Expand Down