From 2d5fe739695564fd7433fa6720df393c0bee880d Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 21 Jan 2013 17:48:36 +0000 Subject: [PATCH] (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 --- libtransmission/blocklist-test.c | 32 ++++++++++++++-------------- libtransmission/blocklist.c | 36 ++++++++++++++++---------------- libtransmission/blocklist.h | 29 ++++++++++++------------- libtransmission/session.c | 24 ++++++++++----------- 4 files changed, 61 insertions(+), 60 deletions(-) diff --git a/libtransmission/blocklist-test.c b/libtransmission/blocklist-test.c index ce56eeefd..9b2b80884 100644 --- a/libtransmission/blocklist-test.c +++ b/libtransmission/blocklist-test.c @@ -39,44 +39,44 @@ testBlockList (void) const char * tmpfile_txt = TEMPFILE_TXT; const char * tmpfile_bin = TEMPFILE_BIN; struct tr_address addr; - tr_blocklist * b; + tr_blocklistFile * b; remove (tmpfile_txt); remove (tmpfile_bin); - b = _tr_blocklistNew (tmpfile_bin, true); + b = tr_blocklistFileNew (tmpfile_bin, true); createTestBlocklist (tmpfile_txt); - _tr_blocklistSetContent (b, tmpfile_txt); + tr_blocklistFileSetContent (b, tmpfile_txt); /* now run some tests */ 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_blocklistHasAddress (b, &addr)); + check (tr_blocklistFileHasAddress (b, &addr)); 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_blocklistHasAddress (b, &addr)); + check (tr_blocklistFileHasAddress (b, &addr)); 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_blocklistHasAddress (b, &addr)); + check (tr_blocklistFileHasAddress (b, &addr)); 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_blocklistHasAddress (b, &addr)); + check (tr_blocklistFileHasAddress (b, &addr)); 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_blocklistHasAddress (b, &addr)); + check (!tr_blocklistFileHasAddress (b, &addr)); 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_blocklistHasAddress (b, &addr)); + check (!tr_blocklistFileHasAddress (b, &addr)); check (tr_address_from_string (&addr, "255.0.0.1")); /* cleanup */ - _tr_blocklistFree (b); + tr_blocklistFileFree (b); remove (tmpfile_txt); remove (tmpfile_bin); return 0; diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index 513bf510f..c88f1b7cb 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -53,7 +53,7 @@ struct tr_ipv4_range uint32_t end; }; -struct tr_blocklist +struct tr_blocklistFile { bool isEnabled; int fd; @@ -64,7 +64,7 @@ struct tr_blocklist }; static void -blocklistClose (tr_blocklist * b) +blocklistClose (tr_blocklistFile * b) { if (b->rules != NULL) { @@ -78,7 +78,7 @@ blocklistClose (tr_blocklist * b) } static void -blocklistLoad (tr_blocklist * b) +blocklistLoad (tr_blocklistFile * b) { int fd; size_t byteCount; @@ -117,7 +117,7 @@ blocklistLoad (tr_blocklist * b) } static void -blocklistEnsureLoaded (tr_blocklist * b) +blocklistEnsureLoaded (tr_blocklistFile * b) { if (b->rules == NULL) blocklistLoad (b); @@ -135,7 +135,7 @@ compareAddressToRange (const void * va, const void * vb) } static void -blocklistDelete (tr_blocklist * b) +blocklistDelete (tr_blocklistFile * b) { blocklistClose (b); unlink (b->filename); @@ -145,12 +145,12 @@ blocklistDelete (tr_blocklist * b) **** PACKAGE-VISIBLE ***/ -tr_blocklist * -_tr_blocklistNew (const char * filename, bool isEnabled) +tr_blocklistFile * +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->filename = tr_strdup (filename); b->isEnabled = isEnabled; @@ -159,13 +159,13 @@ _tr_blocklistNew (const char * filename, bool isEnabled) } const char* -_tr_blocklistGetFilename (const tr_blocklist * b) +tr_blocklistFileGetFilename (const tr_blocklistFile * b) { return b->filename; } void -_tr_blocklistFree (tr_blocklist * b) +tr_blocklistFileFree (tr_blocklistFile * b) { blocklistClose (b); tr_free (b->filename); @@ -173,7 +173,7 @@ _tr_blocklistFree (tr_blocklist * b) } int -_tr_blocklistExists (const tr_blocklist * b) +tr_blocklistFileExists (const tr_blocklistFile * b) { struct stat st; @@ -181,27 +181,27 @@ _tr_blocklistExists (const tr_blocklist * b) } int -_tr_blocklistGetRuleCount (const tr_blocklist * b) +tr_blocklistFileGetRuleCount (const tr_blocklistFile * b) { - blocklistEnsureLoaded ((tr_blocklist*)b); + blocklistEnsureLoaded ((tr_blocklistFile*)b); return b->ruleCount; } int -_tr_blocklistIsEnabled (tr_blocklist * b) +tr_blocklistFileIsEnabled (tr_blocklistFile * b) { return b->isEnabled; } void -_tr_blocklistSetEnabled (tr_blocklist * b, bool isEnabled) +tr_blocklistFileSetEnabled (tr_blocklistFile * b, bool isEnabled) { b->isEnabled = isEnabled ? 1 : 0; } int -_tr_blocklistHasAddress (tr_blocklist * b, const tr_address * addr) +tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr) { uint32_t needle; const struct tr_ipv4_range * range; @@ -314,7 +314,7 @@ compareAddressRangesByFirstAddress (const void * va, const void * vb) } int -_tr_blocklistSetContent (tr_blocklist * b, const char * filename) +tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename) { FILE * in; FILE * out; diff --git a/libtransmission/blocklist.h b/libtransmission/blocklist.h index 90dbf9ffa..f3a64a1ac 100644 --- a/libtransmission/blocklist.h +++ b/libtransmission/blocklist.h @@ -18,28 +18,29 @@ #define TR_BLOCKLIST_H struct tr_address; -typedef struct tr_blocklist tr_blocklist; -tr_blocklist* _tr_blocklistNew (const char * filename, - bool isEnabled); +typedef struct tr_blocklistFile tr_blocklistFile; -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, - bool isEnabled); +int tr_blocklistFileIsEnabled (tr_blocklistFile * b); -int _tr_blocklistHasAddress (tr_blocklist * b, - const struct tr_address * addr); +void tr_blocklistFileSetEnabled (tr_blocklistFile * b, + bool isEnabled); -int _tr_blocklistSetContent (tr_blocklist * b, - const char * filename); +int tr_blocklistFileHasAddress (tr_blocklistFile * b, + const struct tr_address * addr); + +int tr_blocklistFileSetContent (tr_blocklistFile * b, + const char * filename); #endif diff --git a/libtransmission/session.c b/libtransmission/session.c index b6709177f..b1a451336 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -2215,7 +2215,7 @@ loadBlocklists (tr_session * session) (TrListCompareFunc)strcmp)) { tr_list_append (&list, - _tr_blocklistNew (filename, isEnabled)); + tr_blocklistFileNew (filename, isEnabled)); ++binCount; } } @@ -2223,15 +2223,15 @@ loadBlocklists (tr_session * session) { /* strip out the file suffix, if there is one, and add ".bin" instead */ - tr_blocklist * b; + tr_blocklistFile * b; const char * dot = strrchr (d->d_name, '.'); const int len = dot ? dot - d->d_name : (int)strlen (d->d_name); char * tmp = tr_strdup_printf ( "%s" TR_PATH_DELIMITER_STR "%*.*s.bin", dirname, len, len, d->d_name); - b = _tr_blocklistNew (tmp, isEnabled); - _tr_blocklistSetContent (b, filename); + b = tr_blocklistFileNew (tmp, isEnabled); + tr_blocklistFileSetContent (b, filename); tr_list_append (&list, b); ++newCount; tr_free (tmp); @@ -2257,7 +2257,7 @@ static void closeBlocklists (tr_session * session) { tr_list_free (&session->blocklists, - (TrListForeachFunc)_tr_blocklistFree); + (TrListForeachFunc)tr_blocklistFileFree); } void @@ -2278,7 +2278,7 @@ tr_blocklistGetRuleCount (const tr_session * session) assert (tr_isSession (session)); for (l = session->blocklists; l; l = l->next) - n += _tr_blocklistGetRuleCount (l->data); + n += tr_blocklistFileGetRuleCount (l->data); return n; } @@ -2300,7 +2300,7 @@ tr_blocklistSetEnabled (tr_session * session, bool isEnabled) session->isBlocklistEnabled = isEnabled != 0; for (l=session->blocklists; l!=NULL; l=l->next) - _tr_blocklistSetEnabled (l->data, isEnabled); + tr_blocklistFileSetEnabled (l->data, isEnabled); } bool @@ -2316,24 +2316,24 @@ tr_blocklistSetContent (tr_session * session, const char * contentFilename) { tr_list * l; int ruleCount; - tr_blocklist * b; + tr_blocklistFile * b; const char * defaultName = DEFAULT_BLOCKLIST_FILENAME; tr_sessionLock (session); 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)) b = l->data; if (!b) { 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_free (path); } - ruleCount = _tr_blocklistSetContent (b, contentFilename); + ruleCount = tr_blocklistFileSetContent (b, contentFilename); tr_sessionUnlock (session); return ruleCount; } @@ -2347,7 +2347,7 @@ tr_sessionIsAddressBlocked (const tr_session * session, assert (tr_isSession (session)); for (l = session->blocklists; l; l = l->next) - if (_tr_blocklistHasAddress (l->data, addr)) + if (tr_blocklistFileHasAddress (l->data, addr)) return true; return false; } -- 2.40.0