mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
(libT) copyediting: rename the internal tr_blocklist class 'tr_blocklistFile' to distinguish the private per-file API from the public, global API in libtransmission.h
This commit is contained in:
@@ -39,44 +39,44 @@ testBlockList (void)
|
|||||||
const char * tmpfile_txt = TEMPFILE_TXT;
|
const char * tmpfile_txt = TEMPFILE_TXT;
|
||||||
const char * tmpfile_bin = TEMPFILE_BIN;
|
const char * tmpfile_bin = TEMPFILE_BIN;
|
||||||
struct tr_address addr;
|
struct tr_address addr;
|
||||||
tr_blocklist * b;
|
tr_blocklistFile * b;
|
||||||
|
|
||||||
remove (tmpfile_txt);
|
remove (tmpfile_txt);
|
||||||
remove (tmpfile_bin);
|
remove (tmpfile_bin);
|
||||||
|
|
||||||
b = _tr_blocklistNew (tmpfile_bin, true);
|
b = tr_blocklistFileNew (tmpfile_bin, true);
|
||||||
createTestBlocklist (tmpfile_txt);
|
createTestBlocklist (tmpfile_txt);
|
||||||
_tr_blocklistSetContent (b, tmpfile_txt);
|
tr_blocklistFileSetContent (b, tmpfile_txt);
|
||||||
|
|
||||||
/* now run some tests */
|
/* now run some tests */
|
||||||
check (tr_address_from_string (&addr, "216.16.1.143"));
|
check (tr_address_from_string (&addr, "216.16.1.143"));
|
||||||
check (!_tr_blocklistHasAddress (b, &addr));
|
check (!tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.144"));
|
check (tr_address_from_string (&addr, "216.16.1.144"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.145"));
|
check (tr_address_from_string (&addr, "216.16.1.145"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.146"));
|
check (tr_address_from_string (&addr, "216.16.1.146"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.147"));
|
check (tr_address_from_string (&addr, "216.16.1.147"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.148"));
|
check (tr_address_from_string (&addr, "216.16.1.148"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.149"));
|
check (tr_address_from_string (&addr, "216.16.1.149"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.150"));
|
check (tr_address_from_string (&addr, "216.16.1.150"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.151"));
|
check (tr_address_from_string (&addr, "216.16.1.151"));
|
||||||
check (_tr_blocklistHasAddress (b, &addr));
|
check (tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.152"));
|
check (tr_address_from_string (&addr, "216.16.1.152"));
|
||||||
check (!_tr_blocklistHasAddress (b, &addr));
|
check (!tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "216.16.1.153"));
|
check (tr_address_from_string (&addr, "216.16.1.153"));
|
||||||
check (!_tr_blocklistHasAddress (b, &addr));
|
check (!tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "217.0.0.1"));
|
check (tr_address_from_string (&addr, "217.0.0.1"));
|
||||||
check (!_tr_blocklistHasAddress (b, &addr));
|
check (!tr_blocklistFileHasAddress (b, &addr));
|
||||||
check (tr_address_from_string (&addr, "255.0.0.1"));
|
check (tr_address_from_string (&addr, "255.0.0.1"));
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
_tr_blocklistFree (b);
|
tr_blocklistFileFree (b);
|
||||||
remove (tmpfile_txt);
|
remove (tmpfile_txt);
|
||||||
remove (tmpfile_bin);
|
remove (tmpfile_bin);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ struct tr_ipv4_range
|
|||||||
uint32_t end;
|
uint32_t end;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tr_blocklist
|
struct tr_blocklistFile
|
||||||
{
|
{
|
||||||
bool isEnabled;
|
bool isEnabled;
|
||||||
int fd;
|
int fd;
|
||||||
@@ -64,7 +64,7 @@ struct tr_blocklist
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blocklistClose (tr_blocklist * b)
|
blocklistClose (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
if (b->rules != NULL)
|
if (b->rules != NULL)
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,7 @@ blocklistClose (tr_blocklist * b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blocklistLoad (tr_blocklist * b)
|
blocklistLoad (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
size_t byteCount;
|
size_t byteCount;
|
||||||
@@ -117,7 +117,7 @@ blocklistLoad (tr_blocklist * b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blocklistEnsureLoaded (tr_blocklist * b)
|
blocklistEnsureLoaded (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
if (b->rules == NULL)
|
if (b->rules == NULL)
|
||||||
blocklistLoad (b);
|
blocklistLoad (b);
|
||||||
@@ -135,7 +135,7 @@ compareAddressToRange (const void * va, const void * vb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blocklistDelete (tr_blocklist * b)
|
blocklistDelete (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
blocklistClose (b);
|
blocklistClose (b);
|
||||||
unlink (b->filename);
|
unlink (b->filename);
|
||||||
@@ -145,12 +145,12 @@ blocklistDelete (tr_blocklist * b)
|
|||||||
**** PACKAGE-VISIBLE
|
**** PACKAGE-VISIBLE
|
||||||
***/
|
***/
|
||||||
|
|
||||||
tr_blocklist *
|
tr_blocklistFile *
|
||||||
_tr_blocklistNew (const char * filename, bool isEnabled)
|
tr_blocklistFileNew (const char * filename, bool isEnabled)
|
||||||
{
|
{
|
||||||
tr_blocklist * b;
|
tr_blocklistFile * b;
|
||||||
|
|
||||||
b = tr_new0 (tr_blocklist, 1);
|
b = tr_new0 (tr_blocklistFile, 1);
|
||||||
b->fd = -1;
|
b->fd = -1;
|
||||||
b->filename = tr_strdup (filename);
|
b->filename = tr_strdup (filename);
|
||||||
b->isEnabled = isEnabled;
|
b->isEnabled = isEnabled;
|
||||||
@@ -159,13 +159,13 @@ _tr_blocklistNew (const char * filename, bool isEnabled)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
_tr_blocklistGetFilename (const tr_blocklist * b)
|
tr_blocklistFileGetFilename (const tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
return b->filename;
|
return b->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_tr_blocklistFree (tr_blocklist * b)
|
tr_blocklistFileFree (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
blocklistClose (b);
|
blocklistClose (b);
|
||||||
tr_free (b->filename);
|
tr_free (b->filename);
|
||||||
@@ -173,7 +173,7 @@ _tr_blocklistFree (tr_blocklist * b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_tr_blocklistExists (const tr_blocklist * b)
|
tr_blocklistFileExists (const tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
@@ -181,27 +181,27 @@ _tr_blocklistExists (const tr_blocklist * b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_tr_blocklistGetRuleCount (const tr_blocklist * b)
|
tr_blocklistFileGetRuleCount (const tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
blocklistEnsureLoaded ((tr_blocklist*)b);
|
blocklistEnsureLoaded ((tr_blocklistFile*)b);
|
||||||
|
|
||||||
return b->ruleCount;
|
return b->ruleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_tr_blocklistIsEnabled (tr_blocklist * b)
|
tr_blocklistFileIsEnabled (tr_blocklistFile * b)
|
||||||
{
|
{
|
||||||
return b->isEnabled;
|
return b->isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_tr_blocklistSetEnabled (tr_blocklist * b, bool isEnabled)
|
tr_blocklistFileSetEnabled (tr_blocklistFile * b, bool isEnabled)
|
||||||
{
|
{
|
||||||
b->isEnabled = isEnabled ? 1 : 0;
|
b->isEnabled = isEnabled ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_tr_blocklistHasAddress (tr_blocklist * b, const tr_address * addr)
|
tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr)
|
||||||
{
|
{
|
||||||
uint32_t needle;
|
uint32_t needle;
|
||||||
const struct tr_ipv4_range * range;
|
const struct tr_ipv4_range * range;
|
||||||
@@ -314,7 +314,7 @@ compareAddressRangesByFirstAddress (const void * va, const void * vb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_tr_blocklistSetContent (tr_blocklist * b, const char * filename)
|
tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
|
||||||
{
|
{
|
||||||
FILE * in;
|
FILE * in;
|
||||||
FILE * out;
|
FILE * out;
|
||||||
|
|||||||
@@ -18,28 +18,29 @@
|
|||||||
#define TR_BLOCKLIST_H
|
#define TR_BLOCKLIST_H
|
||||||
|
|
||||||
struct tr_address;
|
struct tr_address;
|
||||||
typedef struct tr_blocklist tr_blocklist;
|
|
||||||
|
|
||||||
tr_blocklist* _tr_blocklistNew (const char * filename,
|
typedef struct tr_blocklistFile tr_blocklistFile;
|
||||||
bool isEnabled);
|
|
||||||
|
|
||||||
int _tr_blocklistExists (const tr_blocklist * b);
|
tr_blocklistFile * tr_blocklistFileNew (const char * filename,
|
||||||
|
bool isEnabled);
|
||||||
|
|
||||||
const char* _tr_blocklistGetFilename (const tr_blocklist * b);
|
int tr_blocklistFileExists (const tr_blocklistFile * b);
|
||||||
|
|
||||||
int _tr_blocklistGetRuleCount (const tr_blocklist * b);
|
const char * tr_blocklistFileGetFilename (const tr_blocklistFile * b);
|
||||||
|
|
||||||
void _tr_blocklistFree (tr_blocklist *);
|
int tr_blocklistFileGetRuleCount (const tr_blocklistFile * b);
|
||||||
|
|
||||||
int _tr_blocklistIsEnabled (tr_blocklist * b);
|
void tr_blocklistFileFree (tr_blocklistFile * b);
|
||||||
|
|
||||||
void _tr_blocklistSetEnabled (tr_blocklist * b,
|
int tr_blocklistFileIsEnabled (tr_blocklistFile * b);
|
||||||
bool isEnabled);
|
|
||||||
|
|
||||||
int _tr_blocklistHasAddress (tr_blocklist * b,
|
void tr_blocklistFileSetEnabled (tr_blocklistFile * b,
|
||||||
const struct tr_address * addr);
|
bool isEnabled);
|
||||||
|
|
||||||
int _tr_blocklistSetContent (tr_blocklist * b,
|
int tr_blocklistFileHasAddress (tr_blocklistFile * b,
|
||||||
const char * filename);
|
const struct tr_address * addr);
|
||||||
|
|
||||||
|
int tr_blocklistFileSetContent (tr_blocklistFile * b,
|
||||||
|
const char * filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2215,7 +2215,7 @@ loadBlocklists (tr_session * session)
|
|||||||
(TrListCompareFunc)strcmp))
|
(TrListCompareFunc)strcmp))
|
||||||
{
|
{
|
||||||
tr_list_append (&list,
|
tr_list_append (&list,
|
||||||
_tr_blocklistNew (filename, isEnabled));
|
tr_blocklistFileNew (filename, isEnabled));
|
||||||
++binCount;
|
++binCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2223,15 +2223,15 @@ loadBlocklists (tr_session * session)
|
|||||||
{
|
{
|
||||||
/* strip out the file suffix, if there is one, and add ".bin"
|
/* strip out the file suffix, if there is one, and add ".bin"
|
||||||
instead */
|
instead */
|
||||||
tr_blocklist * b;
|
tr_blocklistFile * b;
|
||||||
const char * dot = strrchr (d->d_name, '.');
|
const char * dot = strrchr (d->d_name, '.');
|
||||||
const int len = dot ? dot - d->d_name
|
const int len = dot ? dot - d->d_name
|
||||||
: (int)strlen (d->d_name);
|
: (int)strlen (d->d_name);
|
||||||
char * tmp = tr_strdup_printf (
|
char * tmp = tr_strdup_printf (
|
||||||
"%s" TR_PATH_DELIMITER_STR "%*.*s.bin",
|
"%s" TR_PATH_DELIMITER_STR "%*.*s.bin",
|
||||||
dirname, len, len, d->d_name);
|
dirname, len, len, d->d_name);
|
||||||
b = _tr_blocklistNew (tmp, isEnabled);
|
b = tr_blocklistFileNew (tmp, isEnabled);
|
||||||
_tr_blocklistSetContent (b, filename);
|
tr_blocklistFileSetContent (b, filename);
|
||||||
tr_list_append (&list, b);
|
tr_list_append (&list, b);
|
||||||
++newCount;
|
++newCount;
|
||||||
tr_free (tmp);
|
tr_free (tmp);
|
||||||
@@ -2257,7 +2257,7 @@ static void
|
|||||||
closeBlocklists (tr_session * session)
|
closeBlocklists (tr_session * session)
|
||||||
{
|
{
|
||||||
tr_list_free (&session->blocklists,
|
tr_list_free (&session->blocklists,
|
||||||
(TrListForeachFunc)_tr_blocklistFree);
|
(TrListForeachFunc)tr_blocklistFileFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -2278,7 +2278,7 @@ tr_blocklistGetRuleCount (const tr_session * session)
|
|||||||
assert (tr_isSession (session));
|
assert (tr_isSession (session));
|
||||||
|
|
||||||
for (l = session->blocklists; l; l = l->next)
|
for (l = session->blocklists; l; l = l->next)
|
||||||
n += _tr_blocklistGetRuleCount (l->data);
|
n += tr_blocklistFileGetRuleCount (l->data);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2300,7 +2300,7 @@ tr_blocklistSetEnabled (tr_session * session, bool isEnabled)
|
|||||||
session->isBlocklistEnabled = isEnabled != 0;
|
session->isBlocklistEnabled = isEnabled != 0;
|
||||||
|
|
||||||
for (l=session->blocklists; l!=NULL; l=l->next)
|
for (l=session->blocklists; l!=NULL; l=l->next)
|
||||||
_tr_blocklistSetEnabled (l->data, isEnabled);
|
tr_blocklistFileSetEnabled (l->data, isEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -2316,24 +2316,24 @@ tr_blocklistSetContent (tr_session * session, const char * contentFilename)
|
|||||||
{
|
{
|
||||||
tr_list * l;
|
tr_list * l;
|
||||||
int ruleCount;
|
int ruleCount;
|
||||||
tr_blocklist * b;
|
tr_blocklistFile * b;
|
||||||
const char * defaultName = DEFAULT_BLOCKLIST_FILENAME;
|
const char * defaultName = DEFAULT_BLOCKLIST_FILENAME;
|
||||||
tr_sessionLock (session);
|
tr_sessionLock (session);
|
||||||
|
|
||||||
for (b = NULL, l = session->blocklists; !b && l; l = l->next)
|
for (b = NULL, l = session->blocklists; !b && l; l = l->next)
|
||||||
if (tr_stringEndsWith (_tr_blocklistGetFilename (l->data),
|
if (tr_stringEndsWith (tr_blocklistFileGetFilename (l->data),
|
||||||
defaultName))
|
defaultName))
|
||||||
b = l->data;
|
b = l->data;
|
||||||
|
|
||||||
if (!b)
|
if (!b)
|
||||||
{
|
{
|
||||||
char * path = tr_buildPath (session->configDir, "blocklists", defaultName, NULL);
|
char * path = tr_buildPath (session->configDir, "blocklists", defaultName, NULL);
|
||||||
b = _tr_blocklistNew (path, session->isBlocklistEnabled);
|
b = tr_blocklistFileNew (path, session->isBlocklistEnabled);
|
||||||
tr_list_append (&session->blocklists, b);
|
tr_list_append (&session->blocklists, b);
|
||||||
tr_free (path);
|
tr_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleCount = _tr_blocklistSetContent (b, contentFilename);
|
ruleCount = tr_blocklistFileSetContent (b, contentFilename);
|
||||||
tr_sessionUnlock (session);
|
tr_sessionUnlock (session);
|
||||||
return ruleCount;
|
return ruleCount;
|
||||||
}
|
}
|
||||||
@@ -2347,7 +2347,7 @@ tr_sessionIsAddressBlocked (const tr_session * session,
|
|||||||
assert (tr_isSession (session));
|
assert (tr_isSession (session));
|
||||||
|
|
||||||
for (l = session->blocklists; l; l = l->next)
|
for (l = session->blocklists; l; l = l->next)
|
||||||
if (_tr_blocklistHasAddress (l->data, addr))
|
if (tr_blocklistFileHasAddress (l->data, addr))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user