oid_stash.h 3.0 KB

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