1 #ifndef OID_STASH_H 2 #define OID_STASH_H 3 4 /* 5 * designed to store/retrieve information associated with a given oid. 6 * Storage is done in an efficient tree manner for fast lookups. 7 */ 8 9 #define OID_STASH_CHILDREN_SIZE 31 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 struct netsnmp_oid_stash_node_s; 16 17 /* args: buffer, sizeof(buffer), yourdata, stashnode */ 18 typedef int (NetSNMPStashDump) (char *, size_t, 19 void *, 20 struct netsnmp_oid_stash_node_s *); 21 22 typedef void (NetSNMPStashFreeNode) (void *); 23 24 typedef struct netsnmp_oid_stash_node_s { 25 oid value; 26 struct netsnmp_oid_stash_node_s **children; /* array of children */ 27 size_t children_size; 28 struct netsnmp_oid_stash_node_s *next_sibling; /* cache too small links */ 29 struct netsnmp_oid_stash_node_s *prev_sibling; 30 struct netsnmp_oid_stash_node_s *parent; 31 32 void *thedata; 33 } netsnmp_oid_stash_node; 34 35 typedef struct netsnmp_oid_stash_save_info_s { 36 const char *token; 37 netsnmp_oid_stash_node **root; 38 NetSNMPStashDump *dumpfn; 39 } netsnmp_oid_stash_save_info; 40 41 NETSNMP_IMPORT 42 int netsnmp_oid_stash_add_data(netsnmp_oid_stash_node **root, 43 const oid * lookup, 44 size_t lookup_len, 45 void *mydata); 46 SNMPCallback netsnmp_oid_stash_store_all; 47 48 49 netsnmp_oid_stash_node 50 *netsnmp_oid_stash_get_node(netsnmp_oid_stash_node *root, 51 const oid * lookup, size_t lookup_len); 52 NETSNMP_IMPORT 53 void *netsnmp_oid_stash_get_data(netsnmp_oid_stash_node *root, 54 const oid * lookup, 55 size_t lookup_len); 56 NETSNMP_IMPORT 57 netsnmp_oid_stash_node * 58 netsnmp_oid_stash_getnext_node(netsnmp_oid_stash_node *root, 59 oid * lookup, size_t lookup_len); 60 61 netsnmp_oid_stash_node *netsnmp_oid_stash_create_sized_node(size_t 62 mysize); 63 netsnmp_oid_stash_node *netsnmp_oid_stash_create_node(void); /* returns a malloced node */ 64 65 void netsnmp_oid_stash_store(netsnmp_oid_stash_node *root, 66 const char *tokenname, 67 NetSNMPStashDump *dumpfn, 68 oid *curoid, size_t curoid_len); 69 70 /* frees all data in the stash and cleans it out. Sets root = NULL */ 71 NETSNMP_IMPORT 72 void netsnmp_oid_stash_free(netsnmp_oid_stash_node **root, 73 NetSNMPStashFreeNode *freefn); 74 75 76 /* a noop function that can be passed to netsnmp_oid_stash_node to 77 NOT free the data */ 78 NetSNMPStashFreeNode netsnmp_oid_stash_no_free; 79 #ifdef __cplusplus 80 } 81 #endif 82 #endif /* OID_STASH_H */ 83