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