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

general/bool: Remove TRUE/FALSE and boolean-style uses with int types #9804

Closed
wants to merge 11 commits into from
4 changes: 2 additions & 2 deletions src/alert-debuglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ static OutputInitResult AlertDebugLogInitCtx(ConfNode *conf)
return result;
}

static int AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
static bool AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt ? TRUE : FALSE);
return (p->alerts.cnt > 0);
}

static int AlertDebugLogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
Expand Down
6 changes: 3 additions & 3 deletions src/alert-fastlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TmEcode AlertFastLogThreadDeinit(ThreadVars *, void *);
void AlertFastLogRegisterTests(void);
static void AlertFastLogDeInitCtx(OutputCtx *);

int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p);
static bool AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p);
int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p);

void AlertFastLogRegister(void)
Expand All @@ -87,9 +87,9 @@ typedef struct AlertFastLogThread_ {
LogFileCtx* file_ctx;
} AlertFastLogThread;

int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
static bool AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt ? TRUE : FALSE);
return (p->alerts.cnt > 0);
}

static inline void AlertFastLogOutputAlert(AlertFastLogThread *aft, char *buffer,
Expand Down
4 changes: 2 additions & 2 deletions src/alert-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ static TmEcode AlertSyslogDecoderEvent(ThreadVars *tv, const Packet *p, void *da
return TM_ECODE_OK;
}

static int AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
static bool AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt > 0 ? TRUE : FALSE);
return (p->alerts.cnt > 0);
}

static int AlertSyslogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-htp-libhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* \param uri_include_all boolean to indicate if scheme, username/password,
hostname and port should be part of the buffer
*/
bstr *SCHTPGenerateNormalizedUri(htp_tx_t *tx, htp_uri_t *uri, int uri_include_all)
bstr *SCHTPGenerateNormalizedUri(htp_tx_t *tx, htp_uri_t *uri, bool uri_include_all)
{
if (uri == NULL)
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-htp-libhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@

#include "suricata-common.h"

bstr *SCHTPGenerateNormalizedUri(htp_tx_t *tx, htp_uri_t *uri, int uri_include_all);
bstr *SCHTPGenerateNormalizedUri(htp_tx_t *tx, htp_uri_t *uri, bool uri_include_all);

#endif /* __APP_LAYER_HTP_LIBHTP__H__ */
4 changes: 2 additions & 2 deletions src/app-layer-htp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,7 @@ static int HTPCallbackResponseHeaderData(htp_tx_data_t *tx_data)
*/
static void HTPConfigSetDefaultsPhase1(HTPCfgRec *cfg_prec)
{
cfg_prec->uri_include_all = FALSE;
cfg_prec->uri_include_all = false;
cfg_prec->request.body_limit = HTP_CONFIG_DEFAULT_REQUEST_BODY_LIMIT;
cfg_prec->response.body_limit = HTP_CONFIG_DEFAULT_RESPONSE_BODY_LIMIT;
cfg_prec->request.inspect_min_size = HTP_CONFIG_DEFAULT_REQUEST_INSPECT_MIN_SIZE;
Expand Down Expand Up @@ -2785,7 +2785,7 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s,
HTP_DECODER_URL_PATH,
ConfValIsTrue(p->val));
} else if (strcasecmp("uri-include-all", p->name) == 0) {
cfg_prec->uri_include_all = ConfValIsTrue(p->val);
cfg_prec->uri_include_all = (1 == ConfValIsTrue(p->val));
SCLogDebug("uri-include-all %s",
cfg_prec->uri_include_all ? "enabled" : "disabled");
} else if (strcasecmp("query-plusspace-decode", p->name) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/app-layer-htp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ typedef struct HTPCfgRec_ {
htp_cfg_t *cfg;
struct HTPCfgRec_ *next;

int uri_include_all; /**< use all info in uri (bool) */

/** max size of the client body we inspect */
int randomize;
int randomize_range;
Expand All @@ -171,6 +169,8 @@ typedef struct HTPCfgRec_ {

HTPCfgDir request;
HTPCfgDir response;

bool uri_include_all; /**< use all info in uri (bool) */
} HTPCfgRec;

/** Struct used to hold chunks of a body on a request */
Expand Down
6 changes: 2 additions & 4 deletions src/app-layer-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,16 +1184,14 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f,
SCReturnCT(active_id, "uint64_t");
}

int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
{
// Custom case for only signature-only protocol so far
if (alproto == ALPROTO_HTTP) {
return AppLayerParserSupportsFiles(ipproto, ALPROTO_HTTP1) ||
AppLayerParserSupportsFiles(ipproto, ALPROTO_HTTP2);
}
if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxFiles != NULL)
return TRUE;
return FALSE;
return alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxFiles != NULL;
}

AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *

uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto);

int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto);
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto);

AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx);
uint64_t AppLayerParserGetTxDetectFlags(AppLayerTxData *txd, const uint8_t dir);
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int SSHRegisterPatternsForProtocolDetection(void)
return 0;
}

int SSHTxLogCondition(ThreadVars * tv, const Packet * p, void *state, void *tx, uint64_t tx_id)
bool SSHTxLogCondition(ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
{
return rs_ssh_tx_get_log_condition(tx);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-ssh.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
void RegisterSSHParsers(void);
void SSHParserRegisterTests(void);

int SSHTxLogCondition(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);
bool SSHTxLogCondition(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);

#endif /* __APP_LAYER_SSH_H__ */

48 changes: 24 additions & 24 deletions src/detect-engine-address.c
Original file line number Diff line number Diff line change
Expand Up @@ -1842,12 +1842,12 @@ DetectAddress *DetectAddressLookupInHead(const DetectAddressHead *gh, Address *a

#ifdef UNITTESTS

static int UTHValidateDetectAddress(DetectAddress *ad, const char *one, const char *two)
static bool UTHValidateDetectAddress(DetectAddress *ad, const char *one, const char *two)
{
char str1[46] = "", str2[46] = "";

if (ad == NULL)
return FALSE;
return false;

switch(ad->ip.family) {
case AF_INET:
Expand All @@ -1858,15 +1858,15 @@ static int UTHValidateDetectAddress(DetectAddress *ad, const char *one, const ch

if (strcmp(str1, one) != 0) {
SCLogInfo("%s != %s", str1, one);
return FALSE;
return false;
}

if (strcmp(str2, two) != 0) {
SCLogInfo("%s != %s", str2, two);
return FALSE;
return false;
}

return TRUE;
return true;
break;

case AF_INET6:
Expand All @@ -1877,19 +1877,19 @@ static int UTHValidateDetectAddress(DetectAddress *ad, const char *one, const ch

if (strcmp(str1, one) != 0) {
SCLogInfo("%s != %s", str1, one);
return FALSE;
return false;
}

if (strcmp(str2, two) != 0) {
SCLogInfo("%s != %s", str2, two);
return FALSE;
return false;
}

return TRUE;
return true;
break;
}

return FALSE;
return false;
}

typedef struct UTHValidateDetectAddressHeadRange_ {
Expand All @@ -1903,7 +1903,7 @@ static int UTHValidateDetectAddressHead(DetectAddressHead *gh, int nranges, UTHV
int have = 0;

if (gh == NULL)
return FALSE;
return false;

DetectAddress *ad = NULL;
ad = gh->ipv4_head;
Expand All @@ -1912,17 +1912,17 @@ static int UTHValidateDetectAddressHead(DetectAddressHead *gh, int nranges, UTHV
while (have < expect) {
if (ad == NULL) {
printf("bad head: have %d ranges, expected %d: ", have, expect);
return FALSE;
return false;
}

if (UTHValidateDetectAddress(ad, expectations[have].one, expectations[have].two) == FALSE)
return FALSE;
if (!UTHValidateDetectAddress(ad, expectations[have].one, expectations[have].two))
return false;

ad = ad->next;
have++;
}

return TRUE;
return true;
}

static int AddressTestParse01(void)
Expand Down Expand Up @@ -4130,7 +4130,7 @@ static int AddressTestAddressGroupSetup38(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "![192.168.0.0/16,!192.168.14.0/24]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 3, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 3, expectations))
result = 1;
}

Expand All @@ -4151,7 +4151,7 @@ static int AddressTestAddressGroupSetup39(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[![192.168.0.0/16,!192.168.14.0/24]]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 3, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 3, expectations))
result = 1;
}

Expand All @@ -4171,7 +4171,7 @@ static int AddressTestAddressGroupSetup40(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[![192.168.0.0/16,[!192.168.14.0/24]]]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 3, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 3, expectations))
result = 1;
}

Expand All @@ -4191,7 +4191,7 @@ static int AddressTestAddressGroupSetup41(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[![192.168.0.0/16,![192.168.14.0/24]]]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 3, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 3, expectations))
result = 1;
}

Expand All @@ -4209,7 +4209,7 @@ static int AddressTestAddressGroupSetup42(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[2001::/3]");
if (r == 0) {
if (UTHValidateDetectAddressHead(gh, 1, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 1, expectations))
result = 1;
}

Expand All @@ -4228,7 +4228,7 @@ static int AddressTestAddressGroupSetup43(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[2001::/3,!3000::/5]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 2, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 2, expectations))
result = 1;
}

Expand All @@ -4246,7 +4246,7 @@ static int AddressTestAddressGroupSetup44(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "3ffe:ffff:7654:feda:1245:ba98:3210:4562/96");
if (r == 0) {
if (UTHValidateDetectAddressHead(gh, 1, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 1, expectations))
result = 1;
}

Expand Down Expand Up @@ -4282,7 +4282,7 @@ static int AddressTestAddressGroupSetup46(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[![192.168.0.0/16,![192.168.1.0/24,192.168.3.0/24]]]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 4, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 4, expectations))
result = 1;
}

Expand All @@ -4305,7 +4305,7 @@ static int AddressTestAddressGroupSetup47(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[![192.168.0.0/16,![192.168.1.0/24,192.168.3.0/24],!192.168.5.0/24]]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 5, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 5, expectations))
result = 1;
}

Expand All @@ -4327,7 +4327,7 @@ static int AddressTestAddressGroupSetup48(void)
if (gh != NULL) {
int r = DetectAddressParse(NULL, gh, "[192.168.0.0/16,![192.168.1.0/24,192.168.3.0/24],!192.168.5.0/24]");
if (r == 1) {
if (UTHValidateDetectAddressHead(gh, 4, expectations) == TRUE)
if (UTHValidateDetectAddressHead(gh, 4, expectations))
result = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/detect-engine-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static int ProcessSigFiles(DetectEngineCtx *de_ctx, char *pattern,
* \param sig_file_exclusive File passed in 'sig_file' should be loaded exclusively.
* \retval -1 on error
*/
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_exclusive)
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
{
SCEnter();

Expand All @@ -293,7 +293,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
}

/* ok, let's load signature files from the general config */
if (!(sig_file != NULL && sig_file_exclusive == TRUE)) {
if (!(sig_file != NULL && sig_file_exclusive)) {
rule_files = ConfGetNode(varname);
if (rule_files != NULL) {
if (!ConfNodeIsSequence(rule_files)) {
Expand Down
6 changes: 3 additions & 3 deletions src/detect-engine-prefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
el->pectx = NULL; // e now owns the ctx
e->gid = el->gid;
if (el->next == NULL) {
e->is_last = TRUE;
e->is_last = true;
}
e++;
}
Expand All @@ -477,7 +477,7 @@ void PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
el->pectx = NULL; // e now owns the ctx
e->gid = el->gid;
if (el->next == NULL) {
e->is_last = TRUE;
e->is_last = true;
}
e++;
}
Expand Down Expand Up @@ -579,7 +579,7 @@ void PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
el->pectx = NULL; // e now owns the ctx
e->gid = el->gid;
if (el->next == NULL) {
e->is_last = TRUE;
e->is_last = true;
}
e++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,7 @@ static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id, const char *fil
goto error;
}

if (SigLoadSignatures(de_ctx, NULL, 0) < 0) {
if (SigLoadSignatures(de_ctx, NULL, false) < 0) {
SCLogError("Loading signatures failed.");
goto error;
}
Expand Down Expand Up @@ -3918,7 +3918,7 @@ static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id, const char *f
goto error;
}

if (SigLoadSignatures(new_de_ctx, NULL, 0) < 0) {
if (SigLoadSignatures(new_de_ctx, NULL, false) < 0) {
SCLogError("Loading signatures failed.");
goto error;
}
Expand Down
Loading
Loading