]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/README-config
Remove new bnet_sig
[bacula/bacula] / bacula / src / dird / README-config
1
2 To add a new resource -- as an example, the BAZ resource,
3   which will have foo record which is an integer,    
4   a storage record, which is the name of a storage
5   resource, and a special time field.
6
7  1. Define the Resource type (R_xxx) in dir_config.h
8     Be sure to update the R_LAST define.
9      #define R_BAZ 1011
10      update R_LAST to be R_BAZ
11
12  2. Add a new definition of the resource in dir_config.h
13     The first three are mandatory (will soon be changed
14     to a header structure).
15     struct s_res_baz {
16        char * name;
17        int rcode
18        struct s_res_baz *next;
19
20        int foo;
21        struct res_store *storage;
22        int time;
23     };
24
25  3. In dir_config.c add the new resource to the table
26     of resources (resources[])
27
28     {"baz",     baz_items,  R_BAZ,  NULL},
29
30  4. Create a baz_items, which defines the records that
31     can appear within the BAZ resource:
32
33     static struct res_items bas_items[] = {
34         name,   store sub,   where to store,   extra info
35        {"name", store_name, ITEM(res_baz.name), 0},    /* manditory */
36        {"foo",  store_int,  ITEM(res_baz.foo), 0}, 
37        {"storage", stor_res, ITEM(res_baz.storage), 0},
38        {"time",  store_time, ITME(res_baz.time), 0},
39     };
40
41  5. Update the dump_resource() subroutine to handle printing
42     your resource.
43
44  6. Update the free_resource() subroutine to handle releasing
45     any allocated memory.
46
47  7. Check for any special initialization in init_resource().
48     Normally, everything is just zeroed.
49
50  8. Update the new_resource() subroutine to handle the two
51     passes of the configurator to be able to create your
52     resource.  Pass 2 is used only for finding a reference
53     to a resource and stuffing its address. In the above example,
54     you will need to include the storage resource.  See the 
55     example for the Job Resource.
56     
57     Add an entry so that the correct size of your resource is
58     allocated for pass one.
59
60  9. Write any new store routines that you may need.  In this case,
61     we used the store_int and store_res, which are already defined,
62     but we need to add the new special routine store_time().
63     Note, the store subroutine gets control when the parser has
64     identified the record. Everything after the record name
65     must be scanned in the store routine.
66
67
68 To add a new resource record:
69
70   1. Add the new record definition to the resource structure definition.
71      See step 2 above. In this case, however, we only add a new field
72      to the existing structure.
73
74   2. Add the new record to the existing res_items structure.  See
75      step 4 above. In this case, however, we only add a new record
76      definition to the exising structure.
77
78   3. Update the dump_resource() routine to dump the new record.
79    
80   4. Update the free_resource() routine if you allocated any memory.
81
82   5. Update init_resource() if you have any special requirements (not
83      normally the case).
84
85   6. Update the new_resource() routine if necessary (not normally the
86      case).
87
88   7. Write any new store routine that you may have created to store
89      your record.
90      Note, the store subroutine gets control when the parser has
91      identified the record. Everything after the record name
92      must be scanned in the store routine.  See the examples of
93      store routines that exist.
94
95 Note, the core parsing code is in lib/parse_config.c and lib/parse_config.h.
96 lib/parse_config.c provides the following store routines:
97     
98       store_name   stores a resource name
99       store_str    stores a string
100       store_res    stores a resource
101       store_int    stores an integer
102
103 and the following utilities:
104
105       scan_to_eol  causes the lexical scanner to scan to the end of the line
106       scan_error   prints an error message
107       GetResWithName  returns the resource of a specified type and name
108       GetNextRes   returns the next resource of a specified type 
109       parse_config parses the configuration file
110       free_config_resources  frees all the resources allocated.
111
112 Note: when your store routine gets control, the parser will have already
113 scanned the record name (i.e. "baz =") before calling your routine.
114 The lexical scanner is by default in a mode where spaces will be
115 compressed out of unquoted strings. Consequently if you want to scan
116  
117      baz = full backup every sunday
118
119 and you do not want to get "full backup every sunday" as a single token
120 "fullbackupeverysunday", you must set the no identifier option in the
121 lexical scanner options field:
122
123    int options = lc->options;
124
125    lc->options |= LOPT_NO_IDENT;      /* don't eat spaces */
126      
127    get_token(lc) ...
128    ...
129
130    lc->options = options;
131    return;
132
133
134