blocklist cleanup: use bool instead of int where appropriate, use tr_fileExists() instead of stat()
This commit is contained in:
parent
e0acd2dcc3
commit
eff3b75586
|
@ -173,12 +173,10 @@ tr_blocklistFileFree (tr_blocklistFile * b)
|
||||||
tr_free (b);
|
tr_free (b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
tr_blocklistFileExists (const tr_blocklistFile * b)
|
tr_blocklistFileExists (const tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
struct stat st;
|
return tr_fileExists (b->filename, NULL);
|
||||||
|
|
||||||
return !stat (b->filename, &st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -189,7 +187,7 @@ tr_blocklistFileGetRuleCount (const tr_blocklistFile * b)
|
||||||
return b->ruleCount;
|
return b->ruleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
tr_blocklistFileIsEnabled (tr_blocklistFile * b)
|
tr_blocklistFileIsEnabled (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
return b->isEnabled;
|
return b->isEnabled;
|
||||||
|
@ -204,7 +202,7 @@ tr_blocklistFileSetEnabled (tr_blocklistFile * b, bool isEnabled)
|
||||||
b->isEnabled = isEnabled;
|
b->isEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr)
|
tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr)
|
||||||
{
|
{
|
||||||
uint32_t needle;
|
uint32_t needle;
|
||||||
|
@ -213,12 +211,12 @@ tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr)
|
||||||
assert (tr_address_is_valid (addr));
|
assert (tr_address_is_valid (addr));
|
||||||
|
|
||||||
if (!b->isEnabled || addr->type == TR_AF_INET6)
|
if (!b->isEnabled || addr->type == TR_AF_INET6)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
blocklistEnsureLoaded (b);
|
blocklistEnsureLoaded (b);
|
||||||
|
|
||||||
if (!b->rules || !b->ruleCount)
|
if (!b->rules || !b->ruleCount)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
needle = ntohl (addr->addr.addr4.s_addr);
|
needle = ntohl (addr->addr.addr4.s_addr);
|
||||||
|
|
||||||
|
@ -300,7 +298,7 @@ parseLine2 (const char * line, struct tr_ipv4_range * range)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
parseLine (const char * line, struct tr_ipv4_range * range)
|
parseLine (const char * line, struct tr_ipv4_range * range)
|
||||||
{
|
{
|
||||||
return parseLine1 (line, range)
|
return parseLine1 (line, range)
|
||||||
|
|
|
@ -24,7 +24,7 @@ typedef struct tr_blocklistFile tr_blocklistFile;
|
||||||
tr_blocklistFile * tr_blocklistFileNew (const char * filename,
|
tr_blocklistFile * tr_blocklistFileNew (const char * filename,
|
||||||
bool isEnabled);
|
bool isEnabled);
|
||||||
|
|
||||||
int tr_blocklistFileExists (const tr_blocklistFile * b);
|
bool tr_blocklistFileExists (const tr_blocklistFile * b);
|
||||||
|
|
||||||
const char * tr_blocklistFileGetFilename (const tr_blocklistFile * b);
|
const char * tr_blocklistFileGetFilename (const tr_blocklistFile * b);
|
||||||
|
|
||||||
|
@ -32,12 +32,12 @@ int tr_blocklistFileGetRuleCount (const tr_blocklistFile * b);
|
||||||
|
|
||||||
void tr_blocklistFileFree (tr_blocklistFile * b);
|
void tr_blocklistFileFree (tr_blocklistFile * b);
|
||||||
|
|
||||||
int tr_blocklistFileIsEnabled (tr_blocklistFile * b);
|
bool tr_blocklistFileIsEnabled (tr_blocklistFile * b);
|
||||||
|
|
||||||
void tr_blocklistFileSetEnabled (tr_blocklistFile * b,
|
void tr_blocklistFileSetEnabled (tr_blocklistFile * b,
|
||||||
bool isEnabled);
|
bool isEnabled);
|
||||||
|
|
||||||
int tr_blocklistFileHasAddress (tr_blocklistFile * b,
|
bool tr_blocklistFileHasAddress (tr_blocklistFile * b,
|
||||||
const struct tr_address * addr);
|
const struct tr_address * addr);
|
||||||
|
|
||||||
int tr_blocklistFileSetContent (tr_blocklistFile * b,
|
int tr_blocklistFileSetContent (tr_blocklistFile * b,
|
||||||
|
|
Loading…
Reference in New Issue