Skip to content

Commit

Permalink
Overhaul debug flags
Browse files Browse the repository at this point in the history
Replace debugflags_t and DEBUG_XXX bit masks with config schema "debug.xxx"
entries.

No more support for "debug.all".
  • Loading branch information
Andrew Bettison committed Dec 11, 2012
1 parent dc6d0da commit 5985df7
Show file tree
Hide file tree
Showing 43 changed files with 408 additions and 475 deletions.
72 changes: 36 additions & 36 deletions commandline.c

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ int cf_init()
cf_limbo = 1;
if (cf_dfl_config_main(&config) == CFERROR)
return -1;
debug = config.debug;
return 0;
}

Expand Down Expand Up @@ -211,7 +210,6 @@ static int load_and_parse(int permissive)
}
}
}
debug = config.debug;
if (result == CFOK)
return 0;
cf_limbo = 0; // let log messages out
Expand Down
4 changes: 2 additions & 2 deletions conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ struct pattern_list {
#undef VALUE_NODE_STRUCT
#undef END_ARRAY

int cf_opt_boolean(int *booleanp, const char *text);
int cf_opt_char_boolean(char *booleanp, const char *text);
int cf_opt_int_boolean(int *booleanp, const char *text);
int cf_opt_absolute_path(char *str, size_t len, const char *text);
int cf_opt_debugflags(debugflags_t *flagsp, const struct cf_om_node *node);
int cf_opt_rhizome_peer(struct config_rhizome_peer *, const struct cf_om_node *node);
int cf_opt_rhizome_peer_from_uri(struct config_rhizome_peer *, const char *uri);
int cf_opt_str(char *str, size_t len, const char *text);
Expand Down
62 changes: 10 additions & 52 deletions conf_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "strbuf_helpers.h"
#include "conf.h"

int cf_opt_boolean(int *booleanp, const char *text)
int cf_opt_char_boolean(char *booleanp, const char *text)
{
if (!strcasecmp(text, "true") || !strcasecmp(text, "yes") || !strcasecmp(text, "on") || !strcasecmp(text, "1")) {
*booleanp = 1;
Expand All @@ -45,6 +45,15 @@ int cf_opt_boolean(int *booleanp, const char *text)
return CFINVALID;
}

int cf_opt_int_boolean(int *booleanp, const char *text)
{
char b;
int ret = cf_opt_char_boolean(&b, text);
if (ret == CFOK)
*booleanp = b;
return ret;
}

int cf_opt_absolute_path(char *str, size_t len, const char *text)
{
if (text[0] != '/')
Expand All @@ -56,57 +65,6 @@ int cf_opt_absolute_path(char *str, size_t len, const char *text)
return CFOK;
}

int cf_opt_debugflags(debugflags_t *flagsp, const struct cf_om_node *node)
{
//DEBUGF("%s", __FUNCTION__);
//cf_dump_node(node, 1);
debugflags_t setmask = 0;
debugflags_t clearmask = 0;
int setall = 0;
int clearall = 0;
int result = CFEMPTY;
int i;
for (i = 0; i < node->nodc; ++i) {
const struct cf_om_node *child = node->nodv[i];
cf_warn_unsupported_children(child);
debugflags_t mask = debugFlagMask(child->key);
int flag = -1;
if (!mask)
cf_warn_unsupported_node(child);
else if (child->text) {
int ret = cf_opt_boolean(&flag, child->text);
switch (ret) {
case CFERROR: return CFERROR;
case CFOK:
result &= ~CFEMPTY;
if (mask == ~0) {
if (flag)
setall = 1;
else
clearall = 1;
} else {
if (flag)
setmask |= mask;
else
clearmask |= mask;
}
break;
default:
cf_warn_node_value(child, ret);
result |= ret;
break;
}
}
}
if (setall)
*flagsp = ~0;
else if (clearall)
*flagsp = 0;
*flagsp &= ~clearmask;
*flagsp |= setmask;
return result;
}

int cf_opt_protocol(char *str, size_t len, const char *text)
{
if (!str_is_uri_scheme(text))
Expand Down
55 changes: 43 additions & 12 deletions conf_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,47 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* @author Andrew Bettison <[email protected]>
*/

STRUCT(debug)
ATOM(char, verbose, 0, cf_opt_char_boolean,, "")
ATOM(char, dnaresponses, 0, cf_opt_char_boolean,, "")
ATOM(char, dnahelper, 0, cf_opt_char_boolean,, "")
ATOM(char, queues, 0, cf_opt_char_boolean,, "")
ATOM(char, timing, 0, cf_opt_char_boolean,, "")
ATOM(char, io, 0, cf_opt_char_boolean,, "")
ATOM(char, verbose_io, 0, cf_opt_char_boolean,, "")
ATOM(char, packetformats, 0, cf_opt_char_boolean,, "")
ATOM(char, gateway, 0, cf_opt_char_boolean,, "")
ATOM(char, keyring, 0, cf_opt_char_boolean,, "")
ATOM(char, security, 0, cf_opt_char_boolean,, "")
ATOM(char, mdprequests, 0, cf_opt_char_boolean,, "")
ATOM(char, peers, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayframes, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayabbreviations, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayrouting, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayroutemonitor, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayinterfaces, 0, cf_opt_char_boolean,, "")
ATOM(char, broadcasts, 0, cf_opt_char_boolean,, "")
ATOM(char, packettx, 0, cf_opt_char_boolean,, "")
ATOM(char, packetrx, 0, cf_opt_char_boolean,, "")
ATOM(char, packetconstruction, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_tx, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_rx, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_ads, 0, cf_opt_char_boolean,, "")
ATOM(char, manifests, 0, cf_opt_char_boolean,, "")
ATOM(char, vomp, 0, cf_opt_char_boolean,, "")
END_STRUCT

STRUCT(log)
STRING(256, file, "", cf_opt_absolute_path,, "Absolute path of log file")
ATOM(int, show_pid, 1, cf_opt_boolean,, "If true, all log lines contain PID of logging process")
ATOM(int, show_time, 1, cf_opt_boolean,, "If true, all log lines contain time stamp")
ATOM(int, show_pid, 1, cf_opt_int_boolean,, "If true, all log lines contain PID of logging process")
ATOM(int, show_time, 1, cf_opt_int_boolean,, "If true, all log lines contain time stamp")
END_STRUCT

STRUCT(server)
STRING(256, chdir, "/", cf_opt_absolute_path,, "Absolute path of chdir(2) for server process")
STRING(256, dummy_interface_dir, "", cf_opt_str_nonempty,, "Path of directory containing dummy interface files, either absolute or relative to instance directory")
ATOM(int, respawn_on_crash, 0, cf_opt_boolean,, "If true, server will exec(2) itself on fatal signals, eg SEGV")
ATOM(int, respawn_on_crash, 0, cf_opt_int_boolean,, "If true, server will exec(2) itself on fatal signals, eg SEGV")
END_STRUCT

STRUCT(monitor)
Expand All @@ -210,7 +241,7 @@ SUB_STRUCT(mdp_iftypelist, iftype,)
END_STRUCT

STRUCT(olsr)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, OLSR is used for mesh routing")
ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, OLSR is used for mesh routing")
ATOM(uint16_t, remote_port,4130, cf_opt_uint16_nonzero,, "Remote port number")
ATOM(uint16_t, local_port, 4131, cf_opt_uint16_nonzero,, "Local port number")
END_STRUCT
Expand Down Expand Up @@ -257,19 +288,19 @@ SUB_STRUCT(rhizome_api_addfile, addfile,)
END_STRUCT

STRUCT(rhizome_http)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome HTTP server is started")
ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome HTTP server is started")
END_STRUCT

STRUCT(rhizome_mdp)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome MDP server is started")
ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome MDP server is started")
END_STRUCT

STRUCT(rhizome_advertise)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome advertisements are sent")
ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome advertisements are sent")
END_STRUCT

STRUCT(rhizome)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, server opens Rhizome database when starting")
ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, server opens Rhizome database when starting")
STRING(256, datastore_path, "", cf_opt_absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory")
ATOM(uint64_t, database_size, 1000000, cf_opt_uint64_scaled,, "Size of database in bytes")
ATOM(uint32_t, fetch_delay_ms, 50, cf_opt_uint32_nonzero,, "Delay from receiving first bundle advert to initiating fetch")
Expand Down Expand Up @@ -297,17 +328,17 @@ VALUE_SUB_STRUCT(host)
END_ARRAY(32)

STRUCT(network_interface, vld_network_interface)
ATOM(int, exclude, 0, cf_opt_boolean,, "If true, do not use matching interfaces")
ATOM(int, exclude, 0, cf_opt_int_boolean,, "If true, do not use matching interfaces")
ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, cf_opt_pattern_list,, "Names that match network interface")
STRING(256, dummy, "", cf_opt_str_nonempty,, "Path of dummy file, absolute or relative to server.dummy_interface_dir")
ATOM(struct in_addr, dummy_address, (struct in_addr){htonl(0x7F000001)}, cf_opt_in_addr,, "Dummy interface address")
ATOM(struct in_addr, dummy_netmask, (struct in_addr){htonl(0xFFFFFF00)}, cf_opt_in_addr,, "Dummy interface netmask")
ATOM(int, dummy_filter_broadcasts, 0, cf_opt_boolean,, "If true, drop all incoming broadcast packets")
ATOM(int, dummy_filter_broadcasts, 0, cf_opt_int_boolean,, "If true, drop all incoming broadcast packets")
ATOM(short, type, OVERLAY_INTERFACE_WIFI, cf_opt_interface_type,, "Type of network interface")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_uint16_nonzero,, "Port number for network interface")
ATOM(uint64_t, speed, 1000000, cf_opt_uint64_scaled,, "Speed in bits per second")
ATOM(int, mdp_tick_ms, -1, cf_opt_int32_nonneg,, "Override MDP tick interval for this interface")
ATOM(int, default_route, 0, cf_opt_boolean,, "If true, use this interface as a default route")
ATOM(int, default_route, 0, cf_opt_int_boolean,, "If true, use this interface as a default route")
END_STRUCT

ARRAY(interface_list, SORTED NO_DUPLICATES)
Expand All @@ -323,7 +354,7 @@ SUB_STRUCT(server, server,)
SUB_STRUCT(monitor, monitor,)
SUB_STRUCT(mdp, mdp,)
SUB_STRUCT(dna, dna,)
NODE(debugflags_t, debug, 0, cf_opt_debugflags, USES_CHILDREN, "Debug flags")
SUB_STRUCT(debug, debug,)
SUB_STRUCT(rhizome, rhizome,)
SUB_STRUCT(directory, directory,)
SUB_STRUCT(olsr, olsr,)
Expand Down
Loading

0 comments on commit 5985df7

Please sign in to comment.