snmp_enum.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef SNMP_ENUM_H
  2. #define SNMP_ENUM_H
  3. /*
  4. * Portions of this file are copyrighted by:
  5. * Copyright (c) 2016 VMware, Inc. All rights reserved.
  6. * Use is subject to license terms specified in the COPYING file
  7. * distributed with the Net-SNMP package.
  8. */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. struct snmp_enum_list {
  13. struct snmp_enum_list *next;
  14. int value;
  15. char *label;
  16. };
  17. #define SE_MAX_IDS 5
  18. #define SE_MAX_SUBIDS 32 /* needs to be a multiple of 8 */
  19. /*
  20. * begin storage definitions
  21. */
  22. /*
  23. * These definitions correspond with the "storid" argument to the API
  24. */
  25. #define SE_LIBRARY_ID 0
  26. #define SE_MIB_ID 1
  27. #define SE_APPLICATION_ID 2
  28. #define SE_ASSIGNED_ID 3
  29. /*
  30. * library specific enum locations
  31. */
  32. /*
  33. * error codes
  34. */
  35. #define SE_OK 0
  36. #define SE_NOMEM 1
  37. #define SE_ALREADY_THERE 2
  38. #define SE_DNE -2
  39. int init_snmp_enum(const char *type);
  40. struct snmp_enum_list *se_find_list(unsigned int major,
  41. unsigned int minor);
  42. struct snmp_enum_list *se_find_slist(const char *listname);
  43. int se_store_in_list(struct snmp_enum_list *,
  44. unsigned int major, unsigned int minor);
  45. int se_find_value(unsigned int major, unsigned int minor,
  46. const char *label);
  47. int se_find_free_value(unsigned int major, unsigned int minor);
  48. char *se_find_label(unsigned int major, unsigned int minor,
  49. int value);
  50. /**
  51. * Add the pair (label, value) to the list (major, minor). Transfers
  52. * ownership of the memory pointed to by label to the list:
  53. * clear_snmp_enum() deallocates that memory.
  54. */
  55. int se_add_pair(unsigned int major, unsigned int minor,
  56. char *label, int value);
  57. /*
  58. * finds a list of enums in a list of enum structs associated by a name.
  59. */
  60. /*
  61. * find a list, and then operate on that list
  62. * ( direct methods further below if you already have the list pointer)
  63. */
  64. NETSNMP_IMPORT
  65. char *se_find_label_in_slist(const char *listname,
  66. int value);
  67. NETSNMP_IMPORT
  68. int se_find_value_in_slist(const char *listname,
  69. const char *label);
  70. NETSNMP_IMPORT
  71. int se_find_casevalue_in_slist(const char *listname,
  72. const char *label);
  73. int se_find_free_value_in_slist(const char *listname);
  74. /**
  75. * Add the pair (label, value) to the slist with name listname. Transfers
  76. * ownership of the memory pointed to by label to the list:
  77. * clear_snmp_enum() deallocates that memory.
  78. */
  79. NETSNMP_IMPORT
  80. int se_add_pair_to_slist(const char *listname, char *label,
  81. int value);
  82. /*
  83. * operates directly on a possibly external list
  84. */
  85. char *se_find_label_in_list(struct snmp_enum_list *list,
  86. int value);
  87. int se_find_value_in_list(struct snmp_enum_list *list,
  88. const char *label);
  89. int se_find_casevalue_in_list(struct snmp_enum_list *list,
  90. const char *label);
  91. int se_find_free_value_in_list(struct snmp_enum_list *list);
  92. int se_add_pair_to_list(struct snmp_enum_list **list,
  93. char *label, int value);
  94. /*
  95. * Persistent enumeration lists
  96. */
  97. void se_store_enum_list(struct snmp_enum_list *new_list,
  98. const char *token, const char *type);
  99. void se_store_list(unsigned int major, unsigned int minor,
  100. const char *type);
  101. void se_clear_slist(const char *listname);
  102. void se_store_slist(const char *listname, const char *type);
  103. int se_store_slist_callback(int majorID, int minorID,
  104. void *serverargs, void *clientargs);
  105. void se_read_conf(const char *word, const char *cptr);
  106. /**
  107. * Deallocate the memory allocated by init_snmp_enum(): remove all key/value
  108. * pairs stored by se_add_*() calls.
  109. */
  110. NETSNMP_IMPORT
  111. void clear_snmp_enum(void);
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif /* SNMP_ENUM_H */