2 * Copyright (c) 2012-2018, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
38 #include <tr_config.h>
39 #include <tr_cfgwatch.h>
42 * Parse internal configuration JSON
44 * @param trc configuration structure to fill in
45 * @param jint internal configuration JSON object
46 * @return TR_CFG_SUCCESS or an error code
48 TR_CFG_RC tr_cfg_parse_internal(TR_CFG *trc, json_t *jint)
51 json_t *jtidsp = NULL;
52 json_t *jtrpsp = NULL;
53 json_t *jhname = NULL;
55 json_t *jconthres = NULL;
56 json_t *jlogthres = NULL;
57 json_t *jcfgpoll = NULL;
58 json_t *jcfgsettle = NULL;
59 json_t *jroutesweep = NULL;
60 json_t *jrouteupdate = NULL;
61 json_t *jtidreq_timeout = NULL;
62 json_t *jtidresp_numer = NULL;
63 json_t *jtidresp_denom = NULL;
64 json_t *jrouteconnect = NULL;
66 if ((!trc) || (!jint))
67 return TR_CFG_BAD_PARAMS;
69 if (NULL == trc->internal) {
70 if (NULL == (trc->internal = talloc_zero(trc, TR_CFG_INTERNAL)))
74 if (NULL != (jmtd = json_object_get(jint, "max_tree_depth"))) {
75 if (json_is_number(jmtd)) {
76 trc->internal->max_tree_depth = json_integer_value(jmtd);
78 tr_debug("tr_cfg_parse_internal: Parsing error, max_tree_depth is not a number.");
79 return TR_CFG_NOPARSE;
82 /* If not configured, use the default */
83 trc->internal->max_tree_depth = TR_DEFAULT_MAX_TREE_DEPTH;
85 if (NULL != (jtidsp = json_object_get(jint, "tids_port"))) {
86 if (json_is_number(jtidsp)) {
87 trc->internal->tids_port = json_integer_value(jtidsp);
89 tr_debug("tr_cfg_parse_internal: Parsing error, tids_port is not a number.");
90 return TR_CFG_NOPARSE;
93 /* If not configured, use the default */
94 trc->internal->tids_port = TR_DEFAULT_TIDS_PORT;
96 if (NULL != (jtrpsp = json_object_get(jint, "trps_port"))) {
97 if (json_is_number(jtrpsp)) {
98 trc->internal->trps_port = json_integer_value(jtrpsp);
100 tr_debug("tr_cfg_parse_internal: Parsing error, trps_port is not a number.");
101 return TR_CFG_NOPARSE;
104 /* If not configured, use the default */
105 trc->internal->trps_port = TR_DEFAULT_TRPS_PORT;
107 if (NULL != (jhname = json_object_get(jint, "hostname"))) {
108 if (json_is_string(jhname)) {
109 trc->internal->hostname = talloc_strdup(trc->internal, json_string_value(jhname));
111 tr_debug("tr_cfg_parse_internal: Parsing error, hostname is not a string.");
112 return TR_CFG_NOPARSE;
115 if (NULL != (jcfgpoll = json_object_get(jint, "cfg_poll_interval"))) {
116 if (json_is_number(jcfgpoll)) {
117 trc->internal->cfg_poll_interval = json_integer_value(jcfgpoll);
119 tr_debug("tr_cfg_parse_internal: Parsing error, cfg_poll_interval is not a number.");
120 return TR_CFG_NOPARSE;
123 trc->internal->cfg_poll_interval = TR_CFGWATCH_DEFAULT_POLL;
126 if (NULL != (jcfgsettle = json_object_get(jint, "cfg_settling_time"))) {
127 if (json_is_number(jcfgsettle)) {
128 trc->internal->cfg_settling_time = json_integer_value(jcfgsettle);
130 tr_debug("tr_cfg_parse_internal: Parsing error, cfg_settling_time is not a number.");
131 return TR_CFG_NOPARSE;
134 trc->internal->cfg_settling_time = TR_CFGWATCH_DEFAULT_SETTLE;
137 if (NULL != (jrouteconnect = json_object_get(jint, "trp_connect_interval"))) {
138 if (json_is_number(jrouteconnect)) {
139 trc->internal->trp_connect_interval = json_integer_value(jrouteconnect);
141 tr_debug("tr_cfg_parse_internal: Parsing error, trp_connect_interval is not a number.");
142 return TR_CFG_NOPARSE;
145 /* if not configured, use the default */
146 trc->internal->trp_connect_interval=TR_DEFAULT_TRP_CONNECT_INTERVAL;
149 if (NULL != (jroutesweep = json_object_get(jint, "trp_sweep_interval"))) {
150 if (json_is_number(jroutesweep)) {
151 trc->internal->trp_sweep_interval = json_integer_value(jroutesweep);
153 tr_debug("tr_cfg_parse_internal: Parsing error, trp_sweep_interval is not a number.");
154 return TR_CFG_NOPARSE;
157 /* if not configured, use the default */
158 trc->internal->trp_sweep_interval=TR_DEFAULT_TRP_SWEEP_INTERVAL;
161 if (NULL != (jrouteupdate = json_object_get(jint, "trp_update_interval"))) {
162 if (json_is_number(jrouteupdate)) {
163 trc->internal->trp_update_interval = json_integer_value(jrouteupdate);
165 tr_debug("tr_cfg_parse_internal: Parsing error, trp_update_interval is not a number.");
166 return TR_CFG_NOPARSE;
169 /* if not configured, use the default */
170 trc->internal->trp_update_interval=TR_DEFAULT_TRP_UPDATE_INTERVAL;
173 if (NULL != (jtidreq_timeout = json_object_get(jint, "tid_request_timeout"))) {
174 if (json_is_number(jtidreq_timeout)) {
175 trc->internal->tid_req_timeout = json_integer_value(jtidreq_timeout);
177 tr_debug("tr_cfg_parse_internal: Parsing error, tid_request_timeout is not a number.");
178 return TR_CFG_NOPARSE;
181 /* if not configured, use the default */
182 trc->internal->tid_req_timeout=TR_DEFAULT_TID_REQ_TIMEOUT;
185 if (NULL != (jtidresp_numer = json_object_get(jint, "tid_response_numerator"))) {
186 if (json_is_number(jtidresp_numer)) {
187 trc->internal->tid_resp_numer = json_integer_value(jtidresp_numer);
189 tr_debug("tr_cfg_parse_internal: Parsing error, tid_response_numerator is not a number.");
190 return TR_CFG_NOPARSE;
193 /* if not configured, use the default */
194 trc->internal->tid_resp_numer=TR_DEFAULT_TID_RESP_NUMER;
197 if (NULL != (jtidresp_denom = json_object_get(jint, "tid_response_denominator"))) {
198 if (json_is_number(jtidresp_denom)) {
199 trc->internal->tid_resp_denom = json_integer_value(jtidresp_denom);
201 tr_debug("tr_cfg_parse_internal: Parsing error, tid_response_denominator is not a number.");
202 return TR_CFG_NOPARSE;
205 /* if not configured, use the default */
206 trc->internal->tid_resp_denom=TR_DEFAULT_TID_RESP_DENOM;
209 if (NULL != (jlog = json_object_get(jint, "logging"))) {
210 if (NULL != (jlogthres = json_object_get(jlog, "log_threshold"))) {
211 if (json_is_string(jlogthres)) {
212 trc->internal->log_threshold = str2sev(json_string_value(jlogthres));
214 tr_debug("tr_cfg_parse_internal: Parsing error, log_threshold is not a string.");
215 return TR_CFG_NOPARSE;
218 /* If not configured, use the default */
219 trc->internal->log_threshold = TR_DEFAULT_LOG_THRESHOLD;
222 if (NULL != (jconthres = json_object_get(jlog, "console_threshold"))) {
223 if (json_is_string(jconthres)) {
224 trc->internal->console_threshold = str2sev(json_string_value(jconthres));
226 tr_debug("tr_cfg_parse_internal: Parsing error, console_threshold is not a string.");
227 return TR_CFG_NOPARSE;
230 /* If not configured, use the default */
231 trc->internal->console_threshold = TR_DEFAULT_CONSOLE_THRESHOLD;
234 /* If not configured, use the default */
235 trc->internal->console_threshold = TR_DEFAULT_CONSOLE_THRESHOLD;
236 trc->internal->log_threshold = TR_DEFAULT_LOG_THRESHOLD;
239 tr_debug("tr_cfg_parse_internal: Internal config parsed.");
240 return TR_CFG_SUCCESS;