table_tdata.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * table_tdata.h
  3. */
  4. #ifndef _TABLE_TDATA_HANDLER_H_
  5. #define _TABLE_TDATA_HANDLER_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*
  10. * This helper is designed to completely automate the task of storing
  11. * tables of data within the agent that are not tied to external data
  12. * sources (like the kernel, hardware, or other processes, etc). IE,
  13. * all rows within a table are expected to be added manually using
  14. * functions found below.
  15. */
  16. #define TABLE_TDATA_NAME "table_tdata"
  17. #define TABLE_TDATA_ROW "table_tdata"
  18. #define TABLE_TDATA_TABLE "table_tdata_table"
  19. #define TDATA_FLAG_NO_STORE_INDEXES 0x01
  20. #define TDATA_FLAG_NO_CONTAINER 0x02 /* user will provide container */
  21. /*
  22. * The (table-independent) per-row data structure
  23. * This is a wrapper round the table-specific per-row data
  24. * structure, which is referred to as a "table entry"
  25. *
  26. * It should be regarded as an opaque, private data structure,
  27. * and shouldn't be accessed directly.
  28. */
  29. typedef struct netsnmp_tdata_row_s {
  30. netsnmp_index oid_index; /* table_container index format */
  31. netsnmp_variable_list *indexes; /* stored permanently if store_indexes = 1 */
  32. void *data; /* the data to store */
  33. } netsnmp_tdata_row;
  34. /*
  35. * The data structure to hold a complete table.
  36. *
  37. * This should be regarded as an opaque, private data structure,
  38. * and shouldn't be accessed directly.
  39. */
  40. typedef struct netsnmp_tdata_s {
  41. netsnmp_variable_list *indexes_template; /* containing only types */
  42. char *name; /* if !NULL, it's registered globally */
  43. int flags; /* This field may legitimately be accessed by external code */
  44. netsnmp_container *container;
  45. } netsnmp_tdata;
  46. /* Backwards compatability with the previous (poorly named) data structures */
  47. typedef struct netsnmp_tdata_row_s netsnmp_table_data2row;
  48. typedef struct netsnmp_tdata_s netsnmp_table_data2;
  49. /* ============================
  50. * TData API: Table maintenance
  51. * ============================ */
  52. netsnmp_tdata *netsnmp_tdata_create_table(const char *name, long flags);
  53. void netsnmp_tdata_delete_table(netsnmp_tdata *table);
  54. netsnmp_tdata_row *netsnmp_tdata_create_row(void);
  55. netsnmp_tdata_row *netsnmp_tdata_clone_row( netsnmp_tdata_row *row);
  56. int netsnmp_tdata_copy_row( netsnmp_tdata_row *dst_row,
  57. netsnmp_tdata_row *src_row);
  58. void *netsnmp_tdata_delete_row( netsnmp_tdata_row *row);
  59. int netsnmp_tdata_add_row( netsnmp_tdata *table,
  60. netsnmp_tdata_row *row);
  61. void netsnmp_tdata_replace_row( netsnmp_tdata *table,
  62. netsnmp_tdata_row *origrow,
  63. netsnmp_tdata_row *newrow);
  64. netsnmp_tdata_row *netsnmp_tdata_remove_row(netsnmp_tdata *table,
  65. netsnmp_tdata_row *row);
  66. void *netsnmp_tdata_remove_and_delete_row(netsnmp_tdata *table,
  67. netsnmp_tdata_row *row);
  68. /* ============================
  69. * TData API: MIB maintenance
  70. * ============================ */
  71. netsnmp_mib_handler *netsnmp_get_tdata_handler(netsnmp_tdata *table);
  72. int netsnmp_tdata_register( netsnmp_handler_registration *reginfo,
  73. netsnmp_tdata *table,
  74. netsnmp_table_registration_info *table_info);
  75. int netsnmp_tdata_unregister(netsnmp_handler_registration *reginfo);
  76. netsnmp_tdata *netsnmp_tdata_extract_table( netsnmp_request_info *);
  77. netsnmp_container *netsnmp_tdata_extract_container(netsnmp_request_info *);
  78. netsnmp_tdata_row *netsnmp_tdata_extract_row( netsnmp_request_info *);
  79. void *netsnmp_tdata_extract_entry( netsnmp_request_info *);
  80. void netsnmp_insert_tdata_row(netsnmp_request_info *, netsnmp_tdata_row *);
  81. void netsnmp_remove_tdata_row(netsnmp_request_info *, netsnmp_tdata_row *);
  82. /* ============================
  83. * TData API: Row operations
  84. * ============================ */
  85. void * netsnmp_tdata_row_entry( netsnmp_tdata_row *row );
  86. netsnmp_tdata_row *netsnmp_tdata_row_first(netsnmp_tdata *table);
  87. netsnmp_tdata_row *netsnmp_tdata_row_get( netsnmp_tdata *table,
  88. netsnmp_tdata_row *row);
  89. netsnmp_tdata_row *netsnmp_tdata_row_next( netsnmp_tdata *table,
  90. netsnmp_tdata_row *row);
  91. netsnmp_tdata_row *netsnmp_tdata_row_get_byidx(netsnmp_tdata *table,
  92. netsnmp_variable_list *indexes);
  93. netsnmp_tdata_row *netsnmp_tdata_row_get_byoid(netsnmp_tdata *table,
  94. oid *searchfor,
  95. size_t searchfor_len);
  96. netsnmp_tdata_row *netsnmp_tdata_row_next_byidx(netsnmp_tdata *table,
  97. netsnmp_variable_list *indexes);
  98. netsnmp_tdata_row *netsnmp_tdata_row_next_byoid(netsnmp_tdata *table,
  99. oid *searchfor,
  100. size_t searchfor_len);
  101. int netsnmp_tdata_row_count(netsnmp_tdata *table);
  102. /* ============================
  103. * TData API: Index operations
  104. * ============================ */
  105. #define netsnmp_tdata_add_index(thetable, type) snmp_varlist_add_variable(&thetable->indexes_template, NULL, 0, type, NULL, 0)
  106. #define netsnmp_tdata_row_add_index(row, type, value, value_len) snmp_varlist_add_variable(&row->indexes, NULL, 0, type, (const u_char *) value, value_len)
  107. int netsnmp_tdata_compare_idx( netsnmp_tdata_row *row,
  108. netsnmp_variable_list *indexes);
  109. int netsnmp_tdata_compare_oid( netsnmp_tdata_row *row,
  110. oid *compareto, size_t compareto_len);
  111. int netsnmp_tdata_compare_subtree_idx(netsnmp_tdata_row *row,
  112. netsnmp_variable_list *indexes);
  113. int netsnmp_tdata_compare_subtree_oid(netsnmp_tdata_row *row,
  114. oid *compareto, size_t compareto_len);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* _TABLE_TDATA_HANDLER_H_ */