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