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