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;
uint32_t end;
};
-struct tr_blocklist
+struct tr_blocklistFile
{
bool isEnabled;
int fd;
};
static void
-blocklistClose (tr_blocklist * b)
+blocklistClose (tr_blocklistFile * b)
{
if (b->rules != NULL)
{
}
static void
-blocklistLoad (tr_blocklist * b)
+blocklistLoad (tr_blocklistFile * b)
{
int fd;
size_t byteCount;
}
static void
-blocklistEnsureLoaded (tr_blocklist * b)
+blocklistEnsureLoaded (tr_blocklistFile * b)
{
if (b->rules == NULL)
blocklistLoad (b);
}
static void
-blocklistDelete (tr_blocklist * b)
+blocklistDelete (tr_blocklistFile * b)
{
blocklistClose (b);
unlink (b->filename);
**** 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;
}
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);
}
int
-_tr_blocklistExists (const tr_blocklist * b)
+tr_blocklistFileExists (const tr_blocklistFile * b)
{
struct stat st;
}
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;
}
int
-_tr_blocklistSetContent (tr_blocklist * b, const char * filename)
+tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
{
FILE * in;
FILE * out;
#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
(TrListCompareFunc)strcmp))
{
tr_list_append (&list,
- _tr_blocklistNew (filename, isEnabled));
+ tr_blocklistFileNew (filename, isEnabled));
++binCount;
}
}
{
/* 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);
closeBlocklists (tr_session * session)
{
tr_list_free (&session->blocklists,
- (TrListForeachFunc)_tr_blocklistFree);
+ (TrListForeachFunc)tr_blocklistFileFree);
}
void
assert (tr_isSession (session));
for (l = session->blocklists; l; l = l->next)
- n += _tr_blocklistGetRuleCount (l->data);
+ n += tr_blocklistFileGetRuleCount (l->data);
return n;
}
session->isBlocklistEnabled = isEnabled != 0;
for (l=session->blocklists; l!=NULL; l=l->next)
- _tr_blocklistSetEnabled (l->data, isEnabled);
+ tr_blocklistFileSetEnabled (l->data, isEnabled);
}
bool
{
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;
}
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;
}