table_dataset.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * table_iterator.h
  3. */
  4. #ifndef _TABLE_DATA_SET_HANDLER_H_
  5. #define _TABLE_DATA_SET_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. void netsnmp_init_table_dataset(void);
  17. #define TABLE_DATA_SET_NAME "netsnmp_table_data_set"
  18. /*
  19. * return SNMP_ERR_NOERROR or some SNMP specific protocol error id
  20. */
  21. typedef int (Netsnmp_Value_Change_Ok) (char *old_value,
  22. size_t old_value_len,
  23. char *new_value,
  24. size_t new_value_len,
  25. void *mydata);
  26. /*
  27. * stored within a given row
  28. */
  29. typedef struct netsnmp_table_data_set_storage_s {
  30. unsigned int column;
  31. /*
  32. * info about it?
  33. */
  34. char writable;
  35. Netsnmp_Value_Change_Ok *change_ok_fn;
  36. void *my_change_data;
  37. /*
  38. * data actually stored
  39. */
  40. u_char type;
  41. union { /* value of variable */
  42. void *voidp;
  43. long *integer;
  44. u_char *string;
  45. oid *objid;
  46. u_char *bitstring;
  47. struct counter64 *counter64;
  48. #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
  49. float *floatVal;
  50. double *doubleVal;
  51. #endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */
  52. } data;
  53. u_long data_len;
  54. struct netsnmp_table_data_set_storage_s *next;
  55. } netsnmp_table_data_set_storage;
  56. typedef struct netsnmp_table_data_set_s {
  57. netsnmp_table_data *table;
  58. netsnmp_table_data_set_storage *default_row;
  59. int allow_creation; /* set to 1 to allow creation of new rows */
  60. unsigned int rowstatus_column;
  61. } netsnmp_table_data_set;
  62. /* ============================
  63. * DataSet API: Table maintenance
  64. * ============================ */
  65. netsnmp_table_data_set *netsnmp_create_table_data_set(const char *);
  66. netsnmp_table_row *netsnmp_table_data_set_clone_row( netsnmp_table_row *row);
  67. void netsnmp_table_dataset_delete_all_data(
  68. netsnmp_table_data_set_storage *data);
  69. void netsnmp_table_dataset_delete_row(netsnmp_table_row *row);
  70. void netsnmp_table_dataset_add_row(netsnmp_table_data_set
  71. *table,
  72. netsnmp_table_row *row);
  73. void
  74. netsnmp_table_dataset_replace_row(netsnmp_table_data_set *table,
  75. netsnmp_table_row *origrow,
  76. netsnmp_table_row *newrow);
  77. void netsnmp_table_dataset_remove_row(netsnmp_table_data_set
  78. *table,
  79. netsnmp_table_row *row);
  80. void
  81. netsnmp_table_dataset_remove_and_delete_row(netsnmp_table_data_set
  82. *table,
  83. netsnmp_table_row *row);
  84. void netsnmp_delete_table_data_set(netsnmp_table_data_set *table_set);
  85. /* ============================
  86. * DataSet API: Default row operations
  87. * ============================ */
  88. /*
  89. * to set, add column, type, (writable) ? 1 : 0
  90. */
  91. /*
  92. * default value, if not NULL, is the default value used in row
  93. * creation. It is copied into the storage template (free your
  94. * calling argument).
  95. */
  96. int netsnmp_table_set_add_default_row(netsnmp_table_data_set *,
  97. unsigned int, int, int,
  98. void *default_value,
  99. size_t default_value_len);
  100. void netsnmp_table_set_multi_add_default_row(netsnmp_table_data_set *,
  101. ...);
  102. /* ============================
  103. * DataSet API: MIB maintenance
  104. * ============================ */
  105. netsnmp_mib_handler
  106. *netsnmp_get_table_data_set_handler(netsnmp_table_data_set *);
  107. Netsnmp_Node_Handler netsnmp_table_data_set_helper_handler;
  108. int netsnmp_register_table_data_set(netsnmp_handler_registration *,
  109. netsnmp_table_data_set *,
  110. netsnmp_table_registration_info *);
  111. netsnmp_table_data_set
  112. *netsnmp_extract_table_data_set(netsnmp_request_info *request);
  113. netsnmp_table_data_set_storage
  114. *netsnmp_extract_table_data_set_column(netsnmp_request_info *,
  115. unsigned int);
  116. netsnmp_oid_stash_node **
  117. netsnmp_table_dataset_get_or_create_stash(netsnmp_agent_request_info *ari,
  118. netsnmp_table_data_set *tds,
  119. netsnmp_table_request_info *tri);
  120. netsnmp_table_row *
  121. netsnmp_table_dataset_get_newrow(netsnmp_request_info *request,
  122. netsnmp_agent_request_info *reqinfo,
  123. int rootoid_len,
  124. netsnmp_table_data_set *datatable,
  125. netsnmp_table_request_info *table_info);
  126. /* ============================
  127. * DataSet API: Config-based operations
  128. * ============================ */
  129. void netsnmp_register_auto_data_table(netsnmp_table_data_set *table_set,
  130. char *registration_name);
  131. void netsnmp_unregister_auto_data_table(netsnmp_table_data_set *table_set,
  132. char *registration_name);
  133. void netsnmp_config_parse_table_set(const char *token, char *line);
  134. void netsnmp_config_parse_add_row( const char *token, char *line);
  135. /* ============================
  136. * DataSet API: Row operations
  137. * ============================ */
  138. netsnmp_table_row *netsnmp_table_data_set_get_first_row(netsnmp_table_data_set *table);
  139. netsnmp_table_row *netsnmp_table_data_set_get_next_row( netsnmp_table_data_set *table,
  140. netsnmp_table_row *row);
  141. int netsnmp_table_set_num_rows(netsnmp_table_data_set *table);
  142. /* ============================
  143. * DataSet API: Column operations
  144. * ============================ */
  145. netsnmp_table_data_set_storage
  146. *netsnmp_table_data_set_find_column(netsnmp_table_data_set_storage *,
  147. unsigned int);
  148. int netsnmp_mark_row_column_writable( netsnmp_table_row *row,
  149. int column, int writable);
  150. int netsnmp_set_row_column( netsnmp_table_row *,
  151. unsigned int, int, const void *,
  152. size_t);
  153. /* ============================
  154. * DataSet API: Index operations
  155. * ============================ */
  156. void netsnmp_table_dataset_add_index(netsnmp_table_data_set
  157. *table, u_char type);
  158. void netsnmp_table_set_add_indexes(netsnmp_table_data_set *tset, ...);
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #define netsnmp_table_row_add_column(row, type, value, value_len) snmp_varlist_add_variable(&row->indexes, NULL, 0, type, (u_char *) value, value_len)
  163. #endif /* _TABLE_DATA_SET_HANDLER_H_ */