Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use short-circuit evaluation in config.c #149

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 34 additions & 40 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ void read_FTLconf(void)
// defaults to: listen only local
config.socket_listenlocal = true;
buffer = parse_FTLconf(fp, "SOCKET_LISTENING");
if(buffer != NULL)
{
if(strcmp(buffer, "all") == 0)
config.socket_listenlocal = false;
}

if(buffer != NULL && strcmp(buffer, "all") == 0)
config.socket_listenlocal = false;

if(config.socket_listenlocal)
logg(" SOCKET_LISTENING: only local");
else
Expand All @@ -49,33 +48,31 @@ void read_FTLconf(void)
config.rolling_24h = true;
config.include_yesterday = true;
buffer = parse_FTLconf(fp, "TIMEFRAME");
if(buffer != NULL)

if(buffer != NULL && strcmp(buffer, "yesterday") == 0)
{
config.include_yesterday = true;
config.rolling_24h = false;
logg(" TIMEFRAME: Yesterday + Today");
}
else if(buffer != NULL && strcmp(buffer, "today") == 0)
{
if(strcmp(buffer, "yesterday") == 0)
{
config.include_yesterday = true;
config.rolling_24h = false;
logg(" TIMEFRAME: Yesterday + Today");
}
else if(strcmp(buffer, "today") == 0)
{
config.include_yesterday = false;
config.rolling_24h = false;
logg(" TIMEFRAME: Today");
}
config.include_yesterday = false;
config.rolling_24h = false;
logg(" TIMEFRAME: Today");
}

if(config.rolling_24h)
logg(" TIMEFRAME: Rolling 24h");

// QUERY_DISPLAY
// defaults to: Yes
config.query_display = true;
buffer = parse_FTLconf(fp, "QUERY_DISPLAY");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.query_display = false;
}

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.query_display = false;

if(config.query_display)
logg(" QUERY_DISPLAY: Show queries");
else
Expand All @@ -85,11 +82,10 @@ void read_FTLconf(void)
// defaults to: Yes
config.analyze_AAAA = true;
buffer = parse_FTLconf(fp, "AAAA_QUERY_ANALYSIS");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.analyze_AAAA = false;
}

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.analyze_AAAA = false;

if(config.analyze_AAAA)
logg(" AAAA_QUERY_ANALYSIS: Show AAAA queries");
else
Expand All @@ -99,13 +95,12 @@ void read_FTLconf(void)
// defaults to: 365 days
config.maxDBdays = 365;
buffer = parse_FTLconf(fp, "MAXDBDAYS");
if(buffer != NULL)
{
int value = 0;
if(sscanf(buffer, "%i", &value))
if(value >= 0)
config.maxDBdays = value;
}

int value = 0;
if(buffer != NULL && sscanf(buffer, "%i", &value))
if(value >= 0)
config.maxDBdays = value;

if(config.maxDBdays == 0)
logg(" MAXDBDAYS: --- (DB disabled)", config.maxDBdays);
else
Expand All @@ -115,11 +110,10 @@ void read_FTLconf(void)
// defaults to: Yes
config.resolveIPv6 = true;
buffer = parse_FTLconf(fp, "RESOLVE_IPV6");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.resolveIPv6 = false;
}

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.resolveIPv6 = false;

if(config.resolveIPv6)
logg(" RESOLVE_IPV6: Resolve IPv6 addresses");
else
Expand Down