table_array.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * table_array.h
  3. * $Id$
  4. */
  5. #ifndef _TABLE_ARRAY_HANDLER_H_
  6. #define _TABLE_ARRAY_HANDLER_H_
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*
  11. * The table array helper is designed to simplify the task of
  12. * writing a table handler for the net-snmp agent when the data being
  13. * accessed is in an oid sorted form and must be accessed externally.
  14. *
  15. * Functionally, it is a specialized version of the more
  16. * generic table helper but easies the burden of GETNEXT processing by
  17. * retrieving the appropriate row for ead index through
  18. * function calls which should be supplied by the module that wishes
  19. * help. The module the table_array helps should, afterwards,
  20. * never be called for the case of "MODE_GETNEXT" and only for the GET
  21. * and SET related modes instead.
  22. */
  23. #include <net-snmp/library/container.h>
  24. #include <net-snmp/agent/table.h>
  25. #define TABLE_ARRAY_NAME "table_array"
  26. /*
  27. * group_item is to allow us to keep a list of requests without
  28. * disrupting the actual netsnmp_request_info list.
  29. */
  30. typedef struct netsnmp_request_group_item_s {
  31. netsnmp_request_info *ri;
  32. netsnmp_table_request_info *tri;
  33. struct netsnmp_request_group_item_s *next;
  34. } netsnmp_request_group_item;
  35. /*
  36. * structure to keep a list of requests for each unique index
  37. */
  38. typedef struct netsnmp_request_group_s {
  39. /*
  40. * index for this row. points to someone else's memory, so
  41. * don't free it!
  42. */
  43. netsnmp_index index;
  44. /*
  45. * container in which rows belong
  46. */
  47. netsnmp_container *table;
  48. /*
  49. * actual old and new rows
  50. */
  51. netsnmp_index *existing_row;
  52. netsnmp_index *undo_info;
  53. /*
  54. * flags
  55. */
  56. char row_created;
  57. char row_deleted;
  58. char fill1;
  59. char fill2;
  60. /*
  61. * requests for this row
  62. */
  63. netsnmp_request_group_item *list;
  64. int status;
  65. void *rg_void;
  66. } netsnmp_request_group;
  67. typedef int (Netsnmp_User_Row_Operation_c) (const void *lhs,
  68. const void *rhs);
  69. typedef int (Netsnmp_User_Row_Operation) (void *lhs, void *rhs);
  70. typedef int (Netsnmp_User_Get_Processor) (netsnmp_request_info *,
  71. netsnmp_index
  72. *,
  73. netsnmp_table_request_info
  74. *);
  75. typedef netsnmp_index
  76. *(UserRowMethod) (netsnmp_index *);
  77. typedef int (Netsnmp_User_Row_Action) (netsnmp_index *,
  78. netsnmp_index *,
  79. netsnmp_request_group *);
  80. typedef void (Netsnmp_User_Group_Method) (netsnmp_request_group *);
  81. /*
  82. * structure for array callbacks
  83. */
  84. typedef struct netsnmp_table_array_callbacks_s {
  85. Netsnmp_User_Row_Operation *row_copy;
  86. Netsnmp_User_Row_Operation_c *row_compare;
  87. Netsnmp_User_Get_Processor *get_value;
  88. Netsnmp_User_Row_Action *can_activate;
  89. Netsnmp_User_Row_Action *activated;
  90. Netsnmp_User_Row_Action *can_deactivate;
  91. Netsnmp_User_Row_Action *deactivated;
  92. Netsnmp_User_Row_Action *can_delete;
  93. UserRowMethod *create_row;
  94. UserRowMethod *duplicate_row;
  95. UserRowMethod *delete_row; /* always returns NULL */
  96. Netsnmp_User_Group_Method *set_reserve1;
  97. Netsnmp_User_Group_Method *set_reserve2;
  98. Netsnmp_User_Group_Method *set_action;
  99. Netsnmp_User_Group_Method *set_commit;
  100. Netsnmp_User_Group_Method *set_free;
  101. Netsnmp_User_Group_Method *set_undo;
  102. /** not callbacks, but this is a useful place for them... */
  103. netsnmp_container* container;
  104. char can_set;
  105. } netsnmp_table_array_callbacks;
  106. int
  107. netsnmp_table_container_register(netsnmp_handler_registration *reginfo,
  108. netsnmp_table_registration_info
  109. *tabreq,
  110. netsnmp_table_array_callbacks *cb,
  111. netsnmp_container *container,
  112. int group_rows);
  113. int netsnmp_table_array_register(netsnmp_handler_registration *reginfo,
  114. netsnmp_table_registration_info *tabreq,
  115. netsnmp_table_array_callbacks *cb,
  116. netsnmp_container *container,
  117. int group_rows);
  118. netsnmp_container * netsnmp_extract_array_context(netsnmp_request_info *);
  119. Netsnmp_Node_Handler netsnmp_table_array_helper_handler;
  120. int
  121. netsnmp_table_array_check_row_status(netsnmp_table_array_callbacks *cb,
  122. netsnmp_request_group *ag,
  123. long *rs_new, long *rs_old);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* _TABLE_ARRAY_HANDLER_H_ */