32b7905cafb23681af4b5c48c68fcc6f295e975a
[egate.git] / include / gw-res.h
1 /*
2  * gw-res.h: Resource management.
3  *
4  * Europagate, 1994-1995.
5  *
6  * $Log: gw-res.h,v $
7  * Revision 1.5  1995/05/03 07:36:29  adam
8  * New functions: gw_res_bool and gw_res_int.
9  *
10  * Revision 1.4  1995/04/19  12:12:02  adam
11  * Resource system uses only one log debug level.
12  *
13  * Revision 1.3  1995/02/23  08:32:12  adam
14  * Changed header.
15  *
16  * Revision 1.1.1.1  1995/02/09  17:27:12  adam
17  * Initial version of email gateway under CVS control.
18  *
19  * Initial:       Dec  7, 94 (Adam Dickmeiss)
20  */
21 #ifndef GW_RES_H
22 #define GW_RES_H
23
24 #define RES_DEBUG GW_LOG_DEBUGN(8)
25
26 typedef struct Gw_res_info *GwRes;   /* Gateway resource handle */
27
28 GwRes gw_res_init (void);
29 /*
30     A resource handle is returned by this function describing
31     the empty resource.
32  */
33
34 void gw_res_close (GwRes id);
35 /*
36     The resources described by 'id' are freed. No further references
37     to 'id' are allowed.
38  */
39
40 int gw_res_merge (GwRes id, const char *filename);
41 /*
42     The resources described by 'id' are merged by the contents of 
43     'filename'. If a resource is duplicated (in both resources 'id' and
44     the file) the resource is set to the value specified in 'filename'.
45
46     This function returns 0 on success; -1 on failure ('filename'
47     could not be read)
48  */
49
50 const char *gw_res_get (GwRes id, const char *name, const char *def);
51 /*
52     The resource with name 'name' is checked in the resources represented
53     by 'id'. If the resource is present a pointer to the value (null-
54     terminated string) is returned. If the value is not present the 
55     value of 'def' is returned.
56  */
57
58 int gw_res_put (GwRes id, const char *name, const char *value, 
59                 const char *fname);
60 /*
61     Change a resource - modify if it exists - add if not already
62     there. The resource will have impact on the file name 'fname'.
63     Use gw_res_commit (see below) to actually write to the
64     resource file.
65  */
66
67 int gw_res_commit (GwRes id, const char *fname);
68 /*
69     Rewrite the resource file 'fname'. If resources are modified/added
70     then these will be written now.
71  */
72
73
74 int gw_res_trav (GwRes id, const char *fname, void (*tf)(const char *name,
75                                                         const char *value));
76 /*
77     Traverse resources associated with file 'fname'. For each resource
78     the handler 'tf' is invoked with name and value.
79  */
80
81 int gw_res_bool (GwRes res, const char *name, int def_val);
82 /*
83     Return true(1) or false(0) depending on setting for name. If
84     name doesn't exist, def_val is returned
85  */
86
87 int gw_res_int (GwRes res, const char *name, int def_val);
88 /*
89     Treat value of name as integer. Issue warning (GW_LOG_WARN) if the value
90     cannot be read as integer. If name doesn't exist, def_val is returned
91  */
92 /*
93    GwRes file format.
94
95    A resource name must begin on column 0 on a  line. The name is followed 
96    by colon. The value of the resource comes after the colon. A value may 
97    span over several lines. Subsequent value lines are preceeded by one or 
98    more blanks (tab/space). Empty/blank lines are ignored. Lines beginning 
99    with # are treated as comments. 
100
101    Example
102     # Comment. Ignored
103    
104     # Single line resource
105     MaxSize: 1000
106     # Multi line resource
107     FatalMsg: A serious error
108      occured. Aborting.
109     # Yet another (danish):
110     Warning: Advarsel, taenk
111          dig om - inden du foretager dig noget.
112
113    The FatalMsg resource has the value "A serious error occured. Aborting.", 
114    and the Warning resource has the value 
115    "Advarsel, taenk dig om - inden du foretager dig noget." Note
116    that all blanks used to separate subsequent lines are treated as exactly 
117    one blank.
118 */
119 #endif