summaryrefslogtreecommitdiff
path: root/include/MESA/MESA_prof_load.h
blob: ecfc50f83f888d5c3362010bf0f2341c36193738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef SLIB_LOADPROF_H
#define SLIB_LOADPROF_H
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif


// Read in specified integer value
//
// Return:
//	   0 : success
//	<  0 : error, val is set to default
int MESA_load_profile_int_def(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	int *val,	// [OUT] returned value
	const int dval);	// [IN] default value



// Read in specified integer value
//
// Return:
//	0 : success
//	-1 : failed to get the key,may be have no thie section, key or the val which the key pointed error
//	-2 : error ,the val if out of range
int MESA_load_profile_int_nodef(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	int *val);	// [OUT] returned value




// Read in specified unsigned integer value
//
// Return:
//	   0 : success
//	<  0 : error, val is set to default
int MESA_load_profile_uint_def(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	unsigned int *val,	// [OUT] returned value
	const unsigned int dval);	// [IN] default value



// Read in specified unsigned integer value
//
// Return:
//	0 : success
//	-1 : failed to get the key,may be have no thie section, key or the val which the key pointed error
//	-2 : error ,the val if out of range
int MESA_load_profile_uint_nodef(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	unsigned int *val);	// [OUT] returned value



// Read in specified short integer value
//
// Return:
//	   0 : success
//	<  0 : error, val is set to default
int MESA_load_profile_short_def(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	short *val,	// [OUT] returned value
	const short dval);    // [IN] default value



// Read in specified short integer value
//
// Return:
//	0 : success
//	-1 : failed to get the key,may be have no thie section, key or the val which the key pointed error
//	-2 : error ,the val if out of range
int MESA_load_profile_short_nodef(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	short *val);	// [OUT] returned value



// Read in specified string value,
// if value string is too long to return, extra chars truncated.
// prefix/postfix space chars cutted,
// space chars: ' ', '\t' '\n' '\r'
//
// Return:
//	>= 0 : length of val
//	  -1 : failed to get the key,may be have no thie section, key or the val which the key pointed error

int MESA_load_profile_string_nodef(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	char *str,	// [OUT] returned string
	const size_t size);	// [IN] buffer size(bytes)



// Read in specified string value,
// if value string is too long to return, extra chars truncated.
// prefix/postfix space chars cutted,
// space chars: ' ', '\t' '\n' '\r'
//
// Return:
//	>= 0 : length of val
//	<  0 : error, str is set to default
int MESA_load_profile_string_def(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	char *str,	// [OUT] returned string
	const size_t size,	// [IN] buffer size(bytes)
	const char *dstr);	// [IN] default string

//read muti unint number from config file, e.g "1-3,5-9"
//return :
//  >=0 : success,return the number of uint read from file successfully
//  -1  : failed to get the key,may be have no thie section, key or the val which the key pointed error
//  -2  : error,invalid uint
int MESA_load_profile_uint_range(
    const char *file,   // [IN] initialization file path
    const char *section,    // [IN] section name in initialization file
    const char *key,    // [IN] keyword name in initialization file
    const size_t size,  // [IN] the number of unit memory out pointed
    unsigned int *out);   // [OUT] return ipset network bytes order

//read ips from config file
//return :
// 	>=0 : success,return the number of ip read from file successfully
// 	-1  : failed to get the key,may be have no thie section, key or the val which the key pointed error
//	-2  : error,invalid ip

#if 0
int MESA_load_profile_ipset(
	const char *file,	// [IN] initialization file path
	const char *section,	// [IN] section name in initialization file
	const char *key,	// [IN] keyword name in initialization file
	const size_t size,  // [IN] the size of memory ips point,it must equel or greater than ip_num*sizeof(unsigned int)
	unsigned int *ipset); 	// [OUT] return ipset network bytes order

// Write the a int into specified position of the config file,the position is decided by section and key
// Return:
//	>= 0 : success
//	  -1 : failed to write profile,maybe fopen failed, or malloc failed
int MESA_write_profile_int(
	const char *file,	// [IN] initialization file path
	const char *section,  // [IN] section name in initialization file
	const char *key,   // [IN] keyword name in initialization file
	const int value);    // [IN] the integer need write

// Write the a float into specified position of the config file,the position is decided by section and key
// Return:
//	>= 0 : success
//	  -1 : failed to write profile,maybe fopen failed, or malloc failed
int MESA_write_profile_float(
	const char *file,	// [IN] initialization file path
	const char *section,  // [IN] section name in initialization file
	const char *key,   // [IN] keyword name in initialization file
	const float value);    // [IN] the float need write

// Write the a string into specified position of the config file,the position is decided by section and key
// Return:
//	>= 0 : success
//	  -1 : failed to write profile,maybe fopen failed, or malloc failed
int MESA_write_profile_string(
	const char *file,	// [IN] initialization file path
	const char *section,  // [IN] section name in initialization file
	const char *key,   // [IN] keyword name in initialization file
	const char *value);    // [IN] the string need write
#endif
#ifdef __cplusplus
}
#endif

#endif /* #ifndef SLIB_LOADPROF_H */