text_utils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef NETSNMP_TEXT_UTILS_H
  2. #define NETSNMP_TEXT_UTILS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*------------------------------------------------------------------
  7. *
  8. * text file processing
  9. *
  10. */
  11. netsnmp_container *
  12. netsnmp_file_text_parse(netsnmp_file *f, netsnmp_container *cin,
  13. int parse_mode, u_int flags, void *context);
  14. #define PM_SAVE_EVERYTHING 1
  15. #define PM_INDEX_STRING_STRING 2
  16. #define PM_USER_FUNCTION 3
  17. #define PM_FLAG_NO_CONTAINER 0x00000001
  18. #define PM_FLAG_SKIP_WHITESPACE 0x00000002
  19. /*
  20. * line processing user function
  21. */
  22. struct netsnmp_line_process_info_s; /* fwd decl */
  23. typedef struct netsnmp_line_info_s {
  24. size_t index;
  25. char *line;
  26. size_t line_len;
  27. size_t line_max;
  28. char *start;
  29. size_t start_len;
  30. } netsnmp_line_info;
  31. typedef int (Netsnmp_Process_Text_Line)
  32. (netsnmp_line_info *line_info, void *mem,
  33. struct netsnmp_line_process_info_s* lpi);
  34. typedef struct netsnmp_line_process_info_s {
  35. size_t line_max; /* defaults to STRINGMAX if 0 */
  36. size_t mem_size;
  37. u_int flags;
  38. Netsnmp_Process_Text_Line *process;
  39. void *user_context;
  40. } netsnmp_line_process_info;
  41. /*
  42. * user function return codes
  43. */
  44. #define PMLP_RC_STOP_PROCESSING -1
  45. #define PMLP_RC_MEMORY_USED 0
  46. #define PMLP_RC_MEMORY_UNUSED 1
  47. /** ALLOC_LINE: wasteful, but fast */
  48. #define PMLP_FLAG_ALLOC_LINE 0x00000001
  49. /** STRDUP_LINE: slower if you don't keep memory in most cases */
  50. #define PMLP_FLAG_STRDUP_LINE 0x00000002
  51. /** don't strip trailing newlines */
  52. #define PMLP_FLAG_LEAVE_NEWLINE 0x00000004
  53. /** don't skip blank or comment lines */
  54. #define PMLP_FLAG_PROCESS_WHITESPACE 0x00000008
  55. /** just process line, don't save it */
  56. #define PMLP_FLAG_NO_CONTAINER 0x00000010
  57. /*
  58. * a few useful pre-defined helpers
  59. */
  60. typedef struct netsnmp_token_value_index_s {
  61. char *token;
  62. netsnmp_cvalue value;
  63. size_t index;
  64. } netsnmp_token_value_index;
  65. netsnmp_container *netsnmp_text_token_container_from_file(const char *file,
  66. u_int flags,
  67. netsnmp_container *c,
  68. void *context);
  69. /*
  70. * flags
  71. */
  72. #define NSTTC_FLAG_TYPE_CONTEXT_DIRECT 0x00000001
  73. #define PMLP_TYPE_UNSIGNED 1
  74. #define PMLP_TYPE_INTEGER 2
  75. #define PMLP_TYPE_STRING 3
  76. #define PMLP_TYPE_BOOLEAN 4
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* NETSNMP_TEXT_UTILS_H */