File: structfill.h

package info (click to toggle)
npadmin 0.8-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 524 kB
  • ctags: 792
  • sloc: cpp: 3,514; ansic: 1,176; sh: 327; makefile: 52
file content (61 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __STRUCTFILL_H__
#define __STRUCTFILL_H__

#include <stdarg.h>
#include <string.h>

#include "session.h"
#include "oidseq.h"

class TableEntry {
public:
  const char *oidstr;
  Tags type;
  unsigned int offset;

  struct TableEntry *next;

  TableEntry(const char *ostr,Tags thetype,unsigned int off,TableEntry *nxt);
  
  int operator==(const char *str){ return !strcmp(str,oidstr);}
};

class SNMP_structFiller{
  TableEntry *tabdef;
  OidSeq *oidseq;
  OidSeq *retseq;
  SNMP_session &session;

  SNMP_structFiller(SNMP_session &sess, unsigned int num, va_list args);
  int fillStruct(OidSeq *data,unsigned char *curstruct);
public:
  inline SNMP_structFiller(SNMP_session &sess): tabdef(NULL),oidseq(NULL),
    session(sess),retseq(NULL){}

  // untested possibly broken
  // SNMP_structFiller(SNMP_session &sess, unsigned int num ...); 

  ~SNMP_structFiller();

  void append(const char *oidstr,Tags tag,unsigned int offset);
  void remove(const char *oidstr);

  void *get(void *tobefilled);
  void *get_next(void *tobefilled);
};

class SNMP_table:public SNMP_structFiller{
  unsigned int structlen;
public:
  inline SNMP_table(SNMP_session &session, unsigned int slen):structlen(slen),
    SNMP_structFiller(session){}

  // untested possibly broken
  // SNMP_table(SNMP_session &session, unsigned int slen,unsigned int num ...);

  // returns a pointer to a vector of the type defined with the data elements 
  // filled in. needs to be freed.
  void *get(unsigned int &len);
};

#endif