1: /*************************************************************************
2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
6: * $Id: aitcfg.h,v 1.3 2009/10/19 15:00:10 misho Exp $
7: *
8: *************************************************************************/
9: #ifndef __AITCFG_H
10: #define __AITCFG_H
11:
12:
13: struct tagPair {
14: unsigned int uLine;
15: unsigned char *psSection;
16: unsigned char *psAttribute;
17: unsigned char *psValue;
18: struct tagPair *sle_next;
19: };
20:
21: struct tagHead {
22: struct tagPair *slh_first;
23: };
24: typedef struct tagHead sl_config;
25:
26:
27: /*
28: * InitConfig() Head initializing function for config
29: * @cfg = New head element for init
30: * return: 0 ok; -1 error:: new head element is null
31: */
32: inline int InitConfig(sl_config * __restrict cfg);
33: /*
34: * cfg_CreateConfig() Create config file from memory without whitespaces!
35: * @csConfigName = New config filename
36: * @cfg = Head list element
37: * return: 0 ok; -1 error:: can`t save new config
38: */
39: int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
40: /*
41: * CreateConfig() Create config file from memory
42: * @csConfigName = New config filename
43: * @cfg = Head list element
44: * return: 0 ok; -1 error:: can`t save new config
45: */
46: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
47: /*
48: * LoadConfig() Load config from file
49: * @csConfigName = Filename of config
50: * @cfg = Head list element
51: * return: 0 ok; -1 error:: can`t load config
52: */
53: int LoadConfig(const char *csConfigName, sl_config * __restrict cfg);
54: /*
55: * UnloadConfig() Unload config from memory and free resources
56: * @cfg = Head list element
57: */
58: void UnloadConfig(sl_config * __restrict cfg);
59:
60:
61: // cfg_GetErrno() Get error code of last operation
62: inline int cfg_GetErrno();
63: // cfg_GetError() Get error text of last operation
64: inline const char *cfg_GetError();
65:
66:
67: /*
68: * ReadConfig() Read from file and add new item to config list
69: * @f = file resource
70: * @cfg = Head list element
71: * return: 0 ok; -1 error:: can`t allocate memory
72: */
73: int ReadConfig(FILE *f, sl_config * __restrict cfg);
74: /*
75: * WriteConfig() Write to file from items in config list
76: * @f = file resource
77: * @cfg = Head list element
78: * return: 0 ok; -1 error:: can`t write to file
79: */
80: int WriteConfig(FILE *f, sl_config * __restrict cfg);
81:
82: /*
83: * cfg_WriteConfig() Write to file from items in config list without whitespaces!
84: * @f = file resource
85: * @cfg = Head list element
86: * return: 0 ok; -1 error:: can`t write to file
87: */
88: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
89:
90: /*
91: * ConcatConfig() Concat two list in one
92: * @cfg = Head list element of main list
93: * @add_cfg = Head list element of added list
94: * return: 0 ok; -1 error:: can`t concat lists
95: */
96: int ConcatConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
97:
98: /*
99: * MergeConfig() Marge two list in one cfg and destroy add_cfg
100: * @cfg = Head list element of main list
101: * @add_cfg = Head list element of merged list (destroy after all!)
102: * return: 0 ok; -1 error:: can`t merge lists
103: */
104: int MergeConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
105:
106:
107: /*
108: * cfg_FindAttribute() Find attribute position in config list
109: * @cfg = Head list element
110: * @csSec = Config section //[{csSec}]
111: * @csAttr = Config attribute //{csAttr} = ...
112: * return: 0 not found item; -1 error: null parameters; >0 position in list
113: */
114: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
115: /*
116: * cfg_SetAttribute() Set item in config list or add new item if not exists
117: * @cfg = Head list element
118: * @csSec = Config section //[{csSec}], if NULL set in *default* section
119: * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
120: * @csVal = Config value //... = {csVal} to setup
121: * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
122: */
123: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
124: /*
125: * cfg_UnsetAttribute() Unset item from config list and free resources
126: * @cfg = Head list element
127: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
128: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
129: * return: 0 item not found, -1 error: null parameters; >0 position in list
130: */
131: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
132: /*
133: * cfg_GetAttribute() Get item from config list and return his value
134: * @cfg = Head list element
135: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
136: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
137: * return: NULL item not found or null parameters; !=NULL value const string
138: */
139: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
140:
141: /*
142: * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
143: * @cfg = Head list element
144: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
145: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
146: * @psVal = Return buffer for item Value //... = {psVal}
147: * @ValLen = Length of buffer //{psVal} for return
148: * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
149: * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
150: */
151: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr,
152: u_char * __restrict psVal, int ValLen, const char *csDefValue);
153:
154:
155: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>