table.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* Portions of this file are subject to the following copyright(s). See
  2. * the Net-SNMP's COPYING file for more details and other copyrights
  3. * that may apply:
  4. */
  5. /*
  6. * Portions of this file are copyrighted by:
  7. * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
  8. * Use is subject to license terms specified in the COPYING file
  9. * distributed with the Net-SNMP package.
  10. */
  11. /*
  12. * Portions of this file are copyrighted by:
  13. * Copyright (C) 2007 Apple, Inc. All rights reserved.
  14. * Use is subject to license terms specified in the COPYING file
  15. * distributed with the Net-SNMP package.
  16. */
  17. /**
  18. * @file table.h
  19. *
  20. * @addtogroup table
  21. *
  22. * @{
  23. */
  24. #ifndef _TABLE_HANDLER_H_
  25. #define _TABLE_HANDLER_H_
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * The table helper is designed to simplify the task of writing a
  31. * table handler for the net-snmp agent. You should create a normal
  32. * handler and register it using the netsnmp_register_table() function
  33. * instead of the netsnmp_register_handler() function.
  34. */
  35. /**
  36. * Notes:
  37. *
  38. * 1) illegal indexes automatically get handled for get/set cases.
  39. * Simply check to make sure the value is type ASN_NULL before
  40. * you answer a request.
  41. */
  42. /**
  43. * used as an index to parent_data lookups
  44. */
  45. #define TABLE_HANDLER_NAME "table"
  46. /** @typedef struct netsnmp_column_info_t netsnmp_column_info
  47. * Typedefs the netsnmp_column_info_t struct into netsnmp_column_info */
  48. /**
  49. * @struct netsnmp_column_info_t
  50. * column info struct. OVERLAPPING RANGES ARE NOT SUPPORTED.
  51. */
  52. typedef struct netsnmp_column_info_t {
  53. char isRange;
  54. /** only useful if isRange == 0 */
  55. char list_count;
  56. union {
  57. unsigned int range[2];
  58. unsigned int *list;
  59. } details;
  60. struct netsnmp_column_info_t *next;
  61. } netsnmp_column_info;
  62. /** @typedef struct netsnmp_table_registration_info_s netsnmp_table_registration_info
  63. * Typedefs the netsnmp_table_registration_info_s struct into
  64. * netsnmp_table_registration_info */
  65. /**
  66. * @struct netsnmp_table_registration_info_s
  67. * Table registration structure.
  68. */
  69. typedef struct netsnmp_table_registration_info_s {
  70. /** list of varbinds with only 'type' set */
  71. netsnmp_variable_list *indexes;
  72. /** calculated automatically */
  73. unsigned int number_indexes;
  74. /**
  75. * the minimum columns number. If there are columns
  76. * in-between which are not valid, use valid_columns to get
  77. * automatic column range checking.
  78. */
  79. unsigned int min_column;
  80. /** the maximum columns number */
  81. unsigned int max_column;
  82. /** more details on columns */
  83. netsnmp_column_info *valid_columns;
  84. } netsnmp_table_registration_info;
  85. /** @typedef struct netsnmp_table_request_info_s netsnmp_table_request_info
  86. * Typedefs the netsnmp_table_request_info_s struct into
  87. * netsnmp_table_request_info */
  88. /**
  89. * @struct netsnmp_table_request_info_s
  90. * The table request info structure.
  91. */
  92. typedef struct netsnmp_table_request_info_s {
  93. /** 0 if OID not long enough */
  94. unsigned int colnum;
  95. /** 0 if failure to parse any */
  96. unsigned int number_indexes;
  97. /** contents freed by helper upon exit */
  98. netsnmp_variable_list *indexes;
  99. oid index_oid[MAX_OID_LEN];
  100. size_t index_oid_len;
  101. netsnmp_table_registration_info *reg_info;
  102. } netsnmp_table_request_info;
  103. netsnmp_mib_handler
  104. *netsnmp_get_table_handler(netsnmp_table_registration_info
  105. *tabreq);
  106. void netsnmp_handler_owns_table_info(netsnmp_mib_handler *handler);
  107. void netsnmp_registration_owns_table_info(netsnmp_handler_registration *reg);
  108. int netsnmp_register_table( netsnmp_handler_registration *reginfo,
  109. netsnmp_table_registration_info *tabreq);
  110. int netsnmp_unregister_table(netsnmp_handler_registration *reginfo);
  111. int netsnmp_table_build_oid( netsnmp_handler_registration *reginfo,
  112. netsnmp_request_info *reqinfo,
  113. netsnmp_table_request_info *table_info);
  114. int
  115. netsnmp_table_build_oid_from_index(netsnmp_handler_registration
  116. *reginfo,
  117. netsnmp_request_info *reqinfo,
  118. netsnmp_table_request_info
  119. *table_info);
  120. int netsnmp_table_build_result(netsnmp_handler_registration
  121. *reginfo,
  122. netsnmp_request_info
  123. *reqinfo,
  124. netsnmp_table_request_info
  125. *table_info, u_char type,
  126. u_char * result,
  127. size_t result_len);
  128. int
  129. netsnmp_update_variable_list_from_index(netsnmp_table_request_info
  130. *);
  131. int
  132. netsnmp_update_indexes_from_variable_list
  133. (netsnmp_table_request_info *tri);
  134. netsnmp_table_registration_info
  135. *netsnmp_find_table_registration_info(netsnmp_handler_registration
  136. *reginfo);
  137. netsnmp_table_registration_info *
  138. netsnmp_table_registration_info_clone(netsnmp_table_registration_info *tri);
  139. void netsnmp_table_registration_info_free(netsnmp_table_registration_info *);
  140. netsnmp_index * netsnmp_table_index_find_next_row(netsnmp_container *c,
  141. netsnmp_table_request_info *tblreq);
  142. unsigned int netsnmp_closest_column(unsigned int current,
  143. netsnmp_column_info
  144. *valid_columns);
  145. Netsnmp_Node_Handler table_helper_handler;
  146. #define netsnmp_table_helper_add_index(tinfo, type) snmp_varlist_add_variable(&tinfo->indexes, NULL, 0, (u_char)type, NULL, 0);
  147. void
  148. netsnmp_table_helper_add_indexes(netsnmp_table_registration_info
  149. *tinfo, ...);
  150. int netsnmp_check_getnext_reply(netsnmp_request_info *request,
  151. oid * prefix, size_t prefix_len,
  152. netsnmp_variable_list * newvar,
  153. netsnmp_variable_list ** outvar);
  154. netsnmp_table_request_info
  155. *netsnmp_extract_table_info(netsnmp_request_info *);
  156. netsnmp_oid_stash_node
  157. **netsnmp_table_get_or_create_row_stash(netsnmp_agent_request_info
  158. *reqinfo,
  159. const u_char *
  160. storage_name);
  161. unsigned int
  162. netsnmp_table_next_column(netsnmp_table_request_info *table_info);
  163. int netsnmp_sparse_table_register(netsnmp_handler_registration *reginfo,
  164. netsnmp_table_registration_info *tabreq);
  165. netsnmp_mib_handler *netsnmp_sparse_table_handler_get(void);
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif /* _TABLE_HANDLER_H_ */
  170. /** @} */