snmp_parse_args.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef SNMP_PARSE_ARGS_H
  2. #define SNMP_PARSE_ARGS_H
  3. /**
  4. * @file snmp_parse_args.h
  5. *
  6. * Support for initializing variables of type netsnmp_session from command
  7. * line arguments
  8. */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** Don't enable any logging even if there is no -L argument */
  13. #define NETSNMP_PARSE_ARGS_NOLOGGING 0x0001
  14. /** Don't zero out sensitive arguments as they are not on the command line
  15. * anyway, typically used when the function is called from an internal
  16. * config-line handler
  17. */
  18. #define NETSNMP_PARSE_ARGS_NOZERO 0x0002
  19. /**
  20. * Parsing of command line arguments succeeded and application is expected
  21. * to continue with normal operation.
  22. */
  23. #define NETSNMP_PARSE_ARGS_SUCCESS 0
  24. /**
  25. * Parsing of command line arguments succeeded, but the application is expected
  26. * to exit with zero exit code. For example, '-V' parameter has been found.
  27. */
  28. #define NETSNMP_PARSE_ARGS_SUCCESS_EXIT -2
  29. /**
  30. * Parsing of command line arguments failed and application is expected to show
  31. * usage (i.e. list of parameters) and exit with nozero exit code.
  32. */
  33. #define NETSNMP_PARSE_ARGS_ERROR_USAGE -1
  34. /**
  35. * Parsing of command line arguments failed and application is expected to exit
  36. * with nozero exit code. netsnmp_parse_args() has already printed what went
  37. * wrong.
  38. */
  39. #define NETSNMP_PARSE_ARGS_ERROR -3
  40. /**
  41. * Parse an argument list and initialize netsnmp_session from it.
  42. * @param argc Number of elements in argv
  43. * @param argv string array of at least argc elements
  44. * @param session
  45. * @param localOpts Additional option characters to accept
  46. * @param proc function pointer used to process any unhandled arguments
  47. * @param flags flags directing how to handle the string
  48. *
  49. * @retval 0 (= #NETSNMP_PARSE_ARGS_SUCCESS) on success
  50. * @retval #NETSNMP_PARSE_ARGS_SUCCESS_EXIT when the application is expected
  51. * to exit with zero exit code (e.g. '-V' option was found)
  52. * @retval #NETSNMP_PARSE_ARGS_ERROR_USAGE when the function failed to parse
  53. * the command line and the application is expected to show it's usage
  54. * @retval #NETSNMP_PARSE_ARGS_ERROR when the function failed to parse
  55. * the command line and it has already printed enough information for the user
  56. * and no other output is needed
  57. *
  58. * The proc function is called with argc, argv and the currently processed
  59. * option as arguments
  60. */
  61. NETSNMP_IMPORT int
  62. netsnmp_parse_args(int argc, char **argv, netsnmp_session *session,
  63. const char *localOpts, void (*proc)(int, char *const *, int),
  64. int flags);
  65. /**
  66. * Calls \link netsnmp_parse_args()
  67. * netsnmp_parse_args(argc, argv, session, localOpts, proc, 0)\endlink
  68. */
  69. NETSNMP_IMPORT
  70. int
  71. snmp_parse_args(int argc, char **argv, netsnmp_session *session,
  72. const char *localOpts, void (*proc)(int, char *const *, int));
  73. NETSNMP_IMPORT
  74. void
  75. snmp_parse_args_descriptions(FILE *);
  76. NETSNMP_IMPORT
  77. void
  78. snmp_parse_args_usage(FILE *);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif