Use json_is_true() in place of json_boolean_value() for compatibility
[trust_router.git] / include / tr_cfgwatch.h
1 /*
2  * Copyright (c) 2016, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef TR_CFGWATCH_H
36 #define TR_CFGWATCH_H
37
38 #include <talloc.h>
39 #include <time.h>
40 #include <sys/time.h>
41
42 #include <tr_config.h>
43 #include <tr_event.h>
44 /* interval in seconds */
45 #define TR_CFGWATCH_DEFAULT_POLL 1
46 #define TR_CFGWATCH_DEFAULT_SETTLE 5
47 /* note: settling time is minimum - only checked on poll intervals */
48
49 struct tr_fstat {
50   char *name;
51   struct timespec mtime;
52 };
53
54 typedef struct tr_cfgwatch_data {
55   struct timeval poll_interval; /* how often should we check for updates? */
56   struct timeval settling_time; /* how long should we wait for changes to settle before updating? */
57   char *config_dir; /* what directory are we watching? */
58   struct tr_fstat *fstat_list; /* file names and mtimes */
59   int n_files; /* number of files in fstat_list */
60   int change_detected; /* have we detected a change? */
61   struct timeval last_change_detected; /* when did we last note a changed mtime? */
62   TR_CFG_MGR *cfg_mgr; /* what trust router config are we updating? */
63   void (*update_cb)(TR_CFG *new_cfg, void *cookie); /* callback after config updated */
64   void *update_cookie; /* data for the update_cb() */
65 } TR_CFGWATCH;
66
67
68 /* prototypes */
69 TR_CFGWATCH *tr_cfgwatch_create(TALLOC_CTX *mem_ctx);
70 int tr_read_and_apply_config(TR_CFGWATCH *cfgwatch);
71 int tr_cfgwatch_event_init(struct event_base *base, TR_CFGWATCH *cfg_status, struct event **cfgwatch_ev);
72
73 #endif /* TR_CFGWATCH_H */