Annotation of libaitcfg/inc/aitcfg.h, revision 1.2.2.3
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.2.2.3 ! misho 6: * $Id: aitcfg.h,v 1.2.2.2 2009/09/09 10:44:41 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: /*
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: /*
1.2.2.2 misho 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: /*
1.1 misho 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:
1.2.2.1 misho 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:
1.2.2.3 ! misho 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:
1.1 misho 98:
99: /*
100: * cfg_FindAttribute() Find attribute position in config list
101: * @cfg = Head list element
102: * @csSec = Config section //[{csSec}]
103: * @csAttr = Config attribute //{csAttr} = ...
104: * return: 0 not found item; -1 error: null parameters; >0 position in list
105: */
106: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
107: /*
108: * cfg_SetAttribute() Set item in config list or add new item if not exists
109: * @cfg = Head list element
110: * @csSec = Config section //[{csSec}], if NULL set in *default* section
111: * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
112: * @csVal = Config value //... = {csVal} to setup
113: * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
114: */
115: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
116: /*
117: * cfg_UnsetAttribute() Unset item from config list and free resources
118: * @cfg = Head list element
119: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
120: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
121: * return: 0 item not found, -1 error: null parameters; >0 position in list
122: */
123: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
124: /*
125: * cfg_GetAttribute() Get item from config list and return his value
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: NULL item not found or null parameters; !=NULL value const string
130: */
131: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
132:
133: /*
134: * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
135: * @cfg = Head list element
136: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
137: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
138: * @psVal = Return buffer for item Value //... = {psVal}
139: * @ValLen = Length of buffer //{psVal} for return
140: * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
141: * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
142: */
143: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr,
144: u_char * __restrict psVal, int ValLen, const char *csDefValue);
145:
146:
147: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>