1 /*
2  *  read_config.h: reads configuration files for extensible sections.
3  *
4  */
5 #ifndef READ_CONFIG_H
6 #define READ_CONFIG_H
7 
8 #ifdef __cplusplus
9 extern          "C" {
10 #endif
11 
12 #define STRINGMAX 1024
13 
14 #define NORMAL_CONFIG 0
15 #define PREMIB_CONFIG 1
16 #define EITHER_CONFIG 2
17 
18 /*
19  * Value of 'type' parameter of various snmp_config calls,
20  * used by Net-SNMP client utilities.
21  */
22 #define NETSNMP_APPLICATION_CONFIG_TYPE "snmpapp"
23 
24 #include <net-snmp/config_api.h>
25 #include <net-snmp/library/netsnmp-attribute-format.h>
26 
27     /*
28      * Defines a set of file types and the parse and free functions
29      * which process the syntax following a given token in a given file.
30      */
31     struct config_files {
32         char           *fileHeader;     /* Label for entire file. */
33         struct config_line *start;
34         struct config_files *next;
35     };
36 
37     struct config_line {
38         char           *config_token;   /* Label for each line parser
39                                          * in the given file. */
40         void            (*parse_line) (const char *, char *);
41         void            (*free_func) (void);
42         struct config_line *next;
43         char            config_time;    /* {NORMAL,PREMIB,EITHER}_CONFIG */
44         char           *help;
45     };
46 
47     struct read_config_memory {
48         char           *line;
49         struct read_config_memory *next;
50     };
51 
52 
53     NETSNMP_IMPORT
54     int             netsnmp_config(char *);     /* parse a simple line: token=values */
55     NETSNMP_IMPORT
56     void            netsnmp_config_remember(char *);    /* process later, during snmp_init() */
57     void            netsnmp_config_process_memories(void);      /* run all memories through parser */
58     int             read_config(const char *, struct config_line *, int);
59     int             read_config_files(int);
60     NETSNMP_IMPORT
61     void            free_config(void);
62     NETSNMP_IMPORT
63     void            netsnmp_config_error(const char *, ...)
64 	NETSNMP_ATTRIBUTE_FORMAT(printf, 1, 2);
65     NETSNMP_IMPORT
66     void            netsnmp_config_warn(const char *, ...)
67 	NETSNMP_ATTRIBUTE_FORMAT(printf, 1, 2);
68 
69     NETSNMP_IMPORT
70     char           *skip_white(char *);
71     NETSNMP_IMPORT
72     const char     *skip_white_const(const char *);
73     NETSNMP_IMPORT
74     char           *skip_not_white(char *);
75     NETSNMP_IMPORT
76     const char     *skip_not_white_const(const char *);
77     NETSNMP_IMPORT
78     char           *skip_token(char *);
79     NETSNMP_IMPORT
80     const char     *skip_token_const(const char *);
81     NETSNMP_IMPORT
82     char           *copy_nword(char *, char *, int);
83     NETSNMP_IMPORT
84     const char     *copy_nword_const(const char *, char *, int);
85     NETSNMP_IMPORT
86     char           *copy_word(char *, char *);  /* do not use */
87     NETSNMP_IMPORT
88     int             read_config_with_type(const char *, const char *);
89     NETSNMP_IMPORT
90     char           *read_config_save_octet_string(char *saveto,
91                                                   const u_char * str,
92                                                   size_t len);
93     NETSNMP_IMPORT
94     char           *read_config_read_octet_string(const char *readfrom,
95                                                   u_char ** str,
96                                                   size_t * len);
97     NETSNMP_IMPORT
98     const char     *read_config_read_octet_string_const(const char *readfrom,
99                                                         u_char ** str,
100                                                         size_t * len);
101     NETSNMP_IMPORT
102     char           *read_config_read_objid(char *readfrom, oid ** objid,
103                                            size_t * len);
104     const char     *read_config_read_objid_const(const char *readfrom,
105                                                  oid ** objid,
106                                                  size_t * len);
107     NETSNMP_IMPORT
108     char           *read_config_save_objid(char *saveto, oid * objid,
109                                            size_t len);
110     NETSNMP_IMPORT
111     char           *read_config_read_data(int type, char *readfrom,
112                                           void *dataptr, size_t * len);
113     NETSNMP_IMPORT
114     char           *read_config_read_memory(int type, char *readfrom,
115                                             char *dataptr, size_t * len);
116     NETSNMP_IMPORT
117     char           *read_config_store_data(int type, char *storeto,
118                                            void *dataptr, size_t * len);
119     char           *read_config_store_data_prefix(char prefix, int type,
120                                                   char *storeto,
121                                                   void *dataptr, size_t len);
122     int  read_config_files_of_type(int when, struct config_files *ctmp);
123     NETSNMP_IMPORT
124     void            read_config_store(const char *type, const char *line);
125     NETSNMP_IMPORT
126     void            read_app_config_store(const char *line);
127     NETSNMP_IMPORT
128     void            snmp_save_persistent(const char *type);
129     NETSNMP_IMPORT
130     void            snmp_clean_persistent(const char *type);
131     struct config_line *read_config_get_handlers(const char *type);
132 
133     /*
134      * external memory list handlers
135      */
136     void            snmp_config_remember_in_list(char *line,
137                                                  struct read_config_memory
138                                                  **mem);
139     void            snmp_config_process_memory_list(struct
140                                                     read_config_memory
141                                                     **mem, int, int);
142     void            snmp_config_remember_free_list(struct
143                                                    read_config_memory
144                                                    **mem);
145 
146     void            set_configuration_directory(const char *dir);
147     NETSNMP_IMPORT
148     const char     *get_configuration_directory(void);
149     void            set_persistent_directory(const char *dir);
150     const char     *get_persistent_directory(void);
151     void            set_temp_file_pattern(const char *pattern);
152     NETSNMP_IMPORT
153     const char     *get_temp_file_pattern(void);
154     NETSNMP_IMPORT
155     void            handle_long_opt(const char *myoptarg);
156 
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 #endif                          /* READ_CONFIG_H */
162