Refactoring to enable community flooding. Partially tested.
[trust_router.git] / include / tr_config.h
1 /*
2  * Copyright (c) 2012, 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_CONFIG_H
36 #define TR_CONFIG_H
37
38 #include <stdio.h>
39 #include <dirent.h>
40 #include <jansson.h>
41 #include <syslog.h>
42 #include <sys/time.h>
43 #include <talloc.h>
44
45 #include <tr_comm.h>
46 #include <tr_rp.h>
47 #include <tr_idp.h>
48 #include <trp_ptable.h>
49 #include <trp_internal.h>
50
51 #define TR_DEFAULT_MAX_TREE_DEPTH 12
52 #define TR_DEFAULT_TR_PORT 12308
53 #define TR_DEFAULT_TIDS_PORT 12309
54 #define TR_DEFAULT_TRPS_PORT 12310
55 #define TR_DEFAULT_LOG_THRESHOLD LOG_INFO
56 #define TR_DEFAULT_CONSOLE_THRESHOLD LOG_NOTICE
57 #define TR_DEFAULT_APC_EXPIRATION_INTERVAL 43200
58 #define TR_DEFAULT_TRP_CONNECT_INTERVAL 10
59 #define TR_DEFAULT_TRP_UPDATE_INTERVAL 120
60 #define TR_DEFAULT_TRP_SWEEP_INTERVAL 30
61
62 typedef enum tr_cfg_rc {
63   TR_CFG_SUCCESS = 0,   /* No error */
64   TR_CFG_ERROR,         /* General processing error */
65   TR_CFG_BAD_PARAMS,    /* Bad parameters passed to tr_config function */
66   TR_CFG_NOPARSE,       /* Parsing error */
67   TR_CFG_NOMEM,         /* Memory allocation error */
68 } TR_CFG_RC;
69
70 typedef struct tr_cfg_internal {
71   unsigned int max_tree_depth;
72   unsigned int tids_port;
73   unsigned int trps_port;
74   const char *hostname;
75   int log_threshold;
76   int console_threshold;
77   unsigned int cfg_poll_interval;
78   unsigned int cfg_settling_time;
79   unsigned int trp_sweep_interval;
80   unsigned int trp_update_interval;
81   unsigned int trp_connect_interval;
82 } TR_CFG_INTERNAL;
83
84 typedef struct tr_cfg {
85   TR_CFG_INTERNAL *internal;            /* internal trust router config */
86   TR_IDP_REALM *idp_realms;             /* locally associated IDP Realms */
87   TR_RP_REALM *rp_realms;
88   TR_RP_CLIENT *rp_clients;             /* locally associated RP Clients */
89   TRP_PTABLE *peers; /* TRP peer table */
90   TR_COMM_TABLE *comms; /* communities */
91   TR_AAA_SERVER *default_servers;       /* default server list */
92   /* TBD -- Global Filters */
93 } TR_CFG;
94
95 typedef struct tr_cfg_mgr {
96   TR_CFG *active;
97   TR_CFG *new;
98 } TR_CFG_MGR;
99
100 int tr_find_config_files (const char *config_dir, struct dirent ***cfg_files);
101 void tr_free_config_file_list(int n, struct dirent ***cfg_files);
102 TR_CFG_RC tr_parse_config (TR_CFG_MGR *cfg_mgr, const char *config_dir, int n, struct dirent **cfg_files);
103 TR_CFG_RC tr_cfg_parse_one_config_file(TR_CFG *cfg, const char *file_with_path);
104 TR_CFG_RC tr_apply_new_config (TR_CFG_MGR *cfg_mgr);
105 TR_CFG_RC tr_cfg_validate (TR_CFG *trc);
106 TR_CFG *tr_cfg_new(TALLOC_CTX *mem_ctx);
107 TR_CFG_MGR *tr_cfg_mgr_new(TALLOC_CTX *mem_ctx);
108 void tr_cfg_free(TR_CFG *cfg);
109 void tr_cfg_mgr_free(TR_CFG_MGR *cfg);
110
111 void tr_print_config(TR_CFG *cfg);
112 void tr_print_comms(TR_COMM_TABLE *ctab);
113 void tr_print_comm_idps(TR_COMM_TABLE *ctab, TR_COMM *comm);
114 void tr_print_comm_rps(TR_COMM_TABLE *ctab, TR_COMM *comm);
115
116 TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *cfg, TR_NAME *idp_id, TR_CFG_RC *rc);
117 TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *cfg, TR_NAME *rp_gss, TR_CFG_RC *rc);
118
119 #endif