table_iterator.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * @file table_iterator.h
  13. * @addtogroup table_iterator
  14. * @{
  15. */
  16. #ifndef _TABLE_ITERATOR_HANDLER_H_
  17. #define _TABLE_ITERATOR_HANDLER_H_
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct netsnmp_iterator_info_s;
  22. typedef netsnmp_variable_list *
  23. (Netsnmp_First_Data_Point) (void **loop_context,
  24. void **data_context,
  25. netsnmp_variable_list *,
  26. struct netsnmp_iterator_info_s *);
  27. typedef netsnmp_variable_list *
  28. (Netsnmp_Next_Data_Point) (void **loop_context,
  29. void **data_context,
  30. netsnmp_variable_list *,
  31. struct netsnmp_iterator_info_s *);
  32. typedef void *(Netsnmp_Make_Data_Context) (void *loop_context,
  33. struct netsnmp_iterator_info_s *);
  34. typedef void (Netsnmp_Free_Loop_Context) (void *,
  35. struct netsnmp_iterator_info_s *);
  36. typedef void (Netsnmp_Free_Data_Context) (void *,
  37. struct netsnmp_iterator_info_s *);
  38. /** @typedef struct netsnmp_iterator_info_s netsnmp_iterator_info
  39. * Typedefs the netsnmp_iterator_info_s struct into netsnmp_iterator_info */
  40. /** @struct netsnmp_iterator_info_s
  41. * Holds iterator information containing functions which should be
  42. called by the iterator_handler to loop over your data set and
  43. sort it in a SNMP specific manner.
  44. The netsnmp_iterator_info typedef can be used instead of directly calling this struct if you would prefer.
  45. */
  46. typedef struct netsnmp_iterator_info_s {
  47. /** Number of handlers that own this data structure. */
  48. int refcnt;
  49. /** Responsible for: returning the first set of "index" data, a
  50. loop-context pointer, and optionally a data context
  51. pointer */
  52. Netsnmp_First_Data_Point *get_first_data_point;
  53. /** Given the previous loop context, this should return the
  54. next loop context, associated index set and optionally a
  55. data context */
  56. Netsnmp_Next_Data_Point *get_next_data_point;
  57. /** If a data context wasn't supplied by the
  58. get_first_data_point or get_next_data_point functions and
  59. the make_data_context pointer is defined, it will be called
  60. to convert a loop context into a data context. */
  61. Netsnmp_Make_Data_Context *make_data_context;
  62. /** A function which should free the loop context. This
  63. function is called at *each* iteration step, which is
  64. not-optimal for speed purposes. The use of
  65. free_loop_context_at_end instead is strongly
  66. encouraged. This can be set to NULL to avoid its usage. */
  67. Netsnmp_Free_Loop_Context *free_loop_context;
  68. /** Frees a data context. This will be called at any time a
  69. data context needs to be freed. This may be at the same
  70. time as a correspondng loop context is freed, or much much
  71. later. Multiple data contexts may be kept in existence at
  72. any time. */
  73. Netsnmp_Free_Data_Context *free_data_context;
  74. /** Frees a loop context at the end of the entire iteration
  75. sequence. Generally, this would free the loop context
  76. allocated by the get_first_data_point function (which would
  77. then be updated by each call to the get_next_data_point
  78. function). It is not called until the get_next_data_point
  79. function returns a NULL */
  80. Netsnmp_Free_Loop_Context *free_loop_context_at_end;
  81. /** This can be used by client handlers to store any
  82. information they need */
  83. void *myvoid;
  84. int flags;
  85. #define NETSNMP_ITERATOR_FLAG_SORTED 0x01
  86. #define NETSNMP_HANDLER_OWNS_IINFO 0x02
  87. /** A pointer to the netsnmp_table_registration_info object
  88. this iterator is registered along with. */
  89. netsnmp_table_registration_info *table_reginfo;
  90. /* Experimental extension - Use At Your Own Risk
  91. (these two fields may change/disappear without warning) */
  92. Netsnmp_First_Data_Point *get_row_indexes;
  93. netsnmp_variable_list *indexes;
  94. } netsnmp_iterator_info;
  95. #define TABLE_ITERATOR_NAME "table_iterator"
  96. /* ============================
  97. * Iterator API: Table maintenance
  98. * ============================ */
  99. /* N/A */
  100. /* ============================
  101. * Iterator API: MIB maintenance
  102. * ============================ */
  103. void netsnmp_handler_owns_iterator_info(netsnmp_mib_handler *h);
  104. netsnmp_mib_handler
  105. *netsnmp_get_table_iterator_handler(netsnmp_iterator_info *iinfo);
  106. int netsnmp_register_table_iterator(netsnmp_handler_registration *reginfo,
  107. netsnmp_iterator_info *iinfo);
  108. void netsnmp_iterator_delete_table(netsnmp_iterator_info *iinfo);
  109. void *netsnmp_extract_iterator_context(netsnmp_request_info *);
  110. void netsnmp_insert_iterator_context(netsnmp_request_info *, void *);
  111. Netsnmp_Node_Handler netsnmp_table_iterator_helper_handler;
  112. #define netsnmp_register_table_iterator2(reginfo, iinfo) \
  113. (((iinfo)->flags |= NETSNMP_HANDLER_OWNS_IINFO), \
  114. netsnmp_register_table_iterator((reginfo), (iinfo)))
  115. /* ============================
  116. * Iterator API: Row operations
  117. * ============================ */
  118. void *netsnmp_iterator_row_first( netsnmp_iterator_info *);
  119. void *netsnmp_iterator_row_get( netsnmp_iterator_info *, void *);
  120. void *netsnmp_iterator_row_next( netsnmp_iterator_info *, void *);
  121. void *netsnmp_iterator_row_get_byidx( netsnmp_iterator_info *,
  122. netsnmp_variable_list *);
  123. void *netsnmp_iterator_row_next_byidx( netsnmp_iterator_info *,
  124. netsnmp_variable_list *);
  125. void *netsnmp_iterator_row_get_byoid( netsnmp_iterator_info *, oid *, size_t);
  126. void *netsnmp_iterator_row_next_byoid( netsnmp_iterator_info *, oid *, size_t);
  127. int netsnmp_iterator_row_count( netsnmp_iterator_info *);
  128. /* ============================
  129. * Iterator API: Index operations
  130. * ============================ */
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif /* _TABLE_ITERATOR_HANDLER_H_ */
  135. /** @} */