Changeset 13824
- Timestamp:
- Jan 21, 2013, 5:48:36 PM (8 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/blocklist-test.c
r13667 r13824 40 40 const char * tmpfile_bin = TEMPFILE_BIN; 41 41 struct tr_address addr; 42 tr_blocklist * b;42 tr_blocklistFile * b; 43 43 44 44 remove (tmpfile_txt); 45 45 remove (tmpfile_bin); 46 46 47 b = _tr_blocklistNew (tmpfile_bin, true);47 b = tr_blocklistFileNew (tmpfile_bin, true); 48 48 createTestBlocklist (tmpfile_txt); 49 _tr_blocklistSetContent (b, tmpfile_txt);49 tr_blocklistFileSetContent (b, tmpfile_txt); 50 50 51 51 /* now run some tests */ 52 52 check (tr_address_from_string (&addr, "216.16.1.143")); 53 check (! _tr_blocklistHasAddress (b, &addr));53 check (!tr_blocklistFileHasAddress (b, &addr)); 54 54 check (tr_address_from_string (&addr, "216.16.1.144")); 55 check ( _tr_blocklistHasAddress (b, &addr));55 check (tr_blocklistFileHasAddress (b, &addr)); 56 56 check (tr_address_from_string (&addr, "216.16.1.145")); 57 check ( _tr_blocklistHasAddress (b, &addr));57 check (tr_blocklistFileHasAddress (b, &addr)); 58 58 check (tr_address_from_string (&addr, "216.16.1.146")); 59 check ( _tr_blocklistHasAddress (b, &addr));59 check (tr_blocklistFileHasAddress (b, &addr)); 60 60 check (tr_address_from_string (&addr, "216.16.1.147")); 61 check ( _tr_blocklistHasAddress (b, &addr));61 check (tr_blocklistFileHasAddress (b, &addr)); 62 62 check (tr_address_from_string (&addr, "216.16.1.148")); 63 check ( _tr_blocklistHasAddress (b, &addr));63 check (tr_blocklistFileHasAddress (b, &addr)); 64 64 check (tr_address_from_string (&addr, "216.16.1.149")); 65 check ( _tr_blocklistHasAddress (b, &addr));65 check (tr_blocklistFileHasAddress (b, &addr)); 66 66 check (tr_address_from_string (&addr, "216.16.1.150")); 67 check ( _tr_blocklistHasAddress (b, &addr));67 check (tr_blocklistFileHasAddress (b, &addr)); 68 68 check (tr_address_from_string (&addr, "216.16.1.151")); 69 check ( _tr_blocklistHasAddress (b, &addr));69 check (tr_blocklistFileHasAddress (b, &addr)); 70 70 check (tr_address_from_string (&addr, "216.16.1.152")); 71 check (! _tr_blocklistHasAddress (b, &addr));71 check (!tr_blocklistFileHasAddress (b, &addr)); 72 72 check (tr_address_from_string (&addr, "216.16.1.153")); 73 check (! _tr_blocklistHasAddress (b, &addr));73 check (!tr_blocklistFileHasAddress (b, &addr)); 74 74 check (tr_address_from_string (&addr, "217.0.0.1")); 75 check (! _tr_blocklistHasAddress (b, &addr));75 check (!tr_blocklistFileHasAddress (b, &addr)); 76 76 check (tr_address_from_string (&addr, "255.0.0.1")); 77 77 78 78 /* cleanup */ 79 _tr_blocklistFree (b);79 tr_blocklistFileFree (b); 80 80 remove (tmpfile_txt); 81 81 remove (tmpfile_bin); -
trunk/libtransmission/blocklist.c
r13823 r13824 54 54 }; 55 55 56 struct tr_blocklist 56 struct tr_blocklistFile 57 57 { 58 58 bool isEnabled; … … 65 65 66 66 static void 67 blocklistClose (tr_blocklist * b)67 blocklistClose (tr_blocklistFile * b) 68 68 { 69 69 if (b->rules != NULL) … … 79 79 80 80 static void 81 blocklistLoad (tr_blocklist * b)81 blocklistLoad (tr_blocklistFile * b) 82 82 { 83 83 int fd; … … 118 118 119 119 static void 120 blocklistEnsureLoaded (tr_blocklist * b)120 blocklistEnsureLoaded (tr_blocklistFile * b) 121 121 { 122 122 if (b->rules == NULL) … … 136 136 137 137 static void 138 blocklistDelete (tr_blocklist * b)138 blocklistDelete (tr_blocklistFile * b) 139 139 { 140 140 blocklistClose (b); … … 146 146 ***/ 147 147 148 tr_blocklist *149 _tr_blocklistNew (const char * filename, bool isEnabled)150 { 151 tr_blocklist * b;152 153 b = tr_new0 (tr_blocklist , 1);148 tr_blocklistFile * 149 tr_blocklistFileNew (const char * filename, bool isEnabled) 150 { 151 tr_blocklistFile * b; 152 153 b = tr_new0 (tr_blocklistFile, 1); 154 154 b->fd = -1; 155 155 b->filename = tr_strdup (filename); … … 160 160 161 161 const char* 162 _tr_blocklistGetFilename (const tr_blocklist* b)162 tr_blocklistFileGetFilename (const tr_blocklistFile * b) 163 163 { 164 164 return b->filename; … … 166 166 167 167 void 168 _tr_blocklistFree (tr_blocklist* b)168 tr_blocklistFileFree (tr_blocklistFile * b) 169 169 { 170 170 blocklistClose (b); … … 174 174 175 175 int 176 _tr_blocklistExists (const tr_blocklist* b)176 tr_blocklistFileExists (const tr_blocklistFile * b) 177 177 { 178 178 struct stat st; … … 182 182 183 183 int 184 _tr_blocklistGetRuleCount (const tr_blocklist* b)185 { 186 blocklistEnsureLoaded ((tr_blocklist *)b);184 tr_blocklistFileGetRuleCount (const tr_blocklistFile * b) 185 { 186 blocklistEnsureLoaded ((tr_blocklistFile*)b); 187 187 188 188 return b->ruleCount; … … 190 190 191 191 int 192 _tr_blocklistIsEnabled (tr_blocklist* b)192 tr_blocklistFileIsEnabled (tr_blocklistFile * b) 193 193 { 194 194 return b->isEnabled; … … 196 196 197 197 void 198 _tr_blocklistSetEnabled (tr_blocklist* b, bool isEnabled)198 tr_blocklistFileSetEnabled (tr_blocklistFile * b, bool isEnabled) 199 199 { 200 200 b->isEnabled = isEnabled ? 1 : 0; … … 202 202 203 203 int 204 _tr_blocklistHasAddress (tr_blocklist* b, const tr_address * addr)204 tr_blocklistFileHasAddress (tr_blocklistFile * b, const tr_address * addr) 205 205 { 206 206 uint32_t needle; … … 315 315 316 316 int 317 _tr_blocklistSetContent (tr_blocklist* b, const char * filename)317 tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename) 318 318 { 319 319 FILE * in; -
trunk/libtransmission/blocklist.h
r13625 r13824 19 19 20 20 struct tr_address; 21 typedef struct tr_blocklist tr_blocklist;22 21 23 tr_blocklist* _tr_blocklistNew (const char * filename, 24 bool isEnabled); 22 typedef struct tr_blocklistFile tr_blocklistFile; 25 23 26 int _tr_blocklistExists (const tr_blocklist * b); 24 tr_blocklistFile * tr_blocklistFileNew (const char * filename, 25 bool isEnabled); 27 26 28 const char* _tr_blocklistGetFilename (const tr_blocklist* b);27 int tr_blocklistFileExists (const tr_blocklistFile * b); 29 28 30 int _tr_blocklistGetRuleCount (const tr_blocklist* b);29 const char * tr_blocklistFileGetFilename (const tr_blocklistFile * b); 31 30 32 void _tr_blocklistFree (tr_blocklist *);31 int tr_blocklistFileGetRuleCount (const tr_blocklistFile * b); 33 32 34 int _tr_blocklistIsEnabled (tr_blocklist* b);33 void tr_blocklistFileFree (tr_blocklistFile * b); 35 34 36 void _tr_blocklistSetEnabled (tr_blocklist * b, 37 bool isEnabled); 35 int tr_blocklistFileIsEnabled (tr_blocklistFile * b); 38 36 39 int _tr_blocklistHasAddress (tr_blocklist* b,40 const struct tr_address * addr);37 void tr_blocklistFileSetEnabled (tr_blocklistFile * b, 38 bool isEnabled); 41 39 42 int _tr_blocklistSetContent (tr_blocklist * b, 43 const char * filename); 40 int tr_blocklistFileHasAddress (tr_blocklistFile * b, 41 const struct tr_address * addr); 42 43 int tr_blocklistFileSetContent (tr_blocklistFile * b, 44 const char * filename); 44 45 45 46 #endif -
trunk/libtransmission/session.c
r13710 r13824 2216 2216 { 2217 2217 tr_list_append (&list, 2218 _tr_blocklistNew (filename, isEnabled));2218 tr_blocklistFileNew (filename, isEnabled)); 2219 2219 ++binCount; 2220 2220 } … … 2224 2224 /* strip out the file suffix, if there is one, and add ".bin" 2225 2225 instead */ 2226 tr_blocklist * b;2226 tr_blocklistFile * b; 2227 2227 const char * dot = strrchr (d->d_name, '.'); 2228 2228 const int len = dot ? dot - d->d_name … … 2231 2231 "%s" TR_PATH_DELIMITER_STR "%*.*s.bin", 2232 2232 dirname, len, len, d->d_name); 2233 b = _tr_blocklistNew (tmp, isEnabled);2234 _tr_blocklistSetContent (b, filename);2233 b = tr_blocklistFileNew (tmp, isEnabled); 2234 tr_blocklistFileSetContent (b, filename); 2235 2235 tr_list_append (&list, b); 2236 2236 ++newCount; … … 2258 2258 { 2259 2259 tr_list_free (&session->blocklists, 2260 (TrListForeachFunc) _tr_blocklistFree);2260 (TrListForeachFunc)tr_blocklistFileFree); 2261 2261 } 2262 2262 … … 2279 2279 2280 2280 for (l = session->blocklists; l; l = l->next) 2281 n += _tr_blocklistGetRuleCount (l->data);2281 n += tr_blocklistFileGetRuleCount (l->data); 2282 2282 return n; 2283 2283 } … … 2301 2301 2302 2302 for (l=session->blocklists; l!=NULL; l=l->next) 2303 _tr_blocklistSetEnabled (l->data, isEnabled);2303 tr_blocklistFileSetEnabled (l->data, isEnabled); 2304 2304 } 2305 2305 … … 2317 2317 tr_list * l; 2318 2318 int ruleCount; 2319 tr_blocklist * b;2319 tr_blocklistFile * b; 2320 2320 const char * defaultName = DEFAULT_BLOCKLIST_FILENAME; 2321 2321 tr_sessionLock (session); 2322 2322 2323 2323 for (b = NULL, l = session->blocklists; !b && l; l = l->next) 2324 if (tr_stringEndsWith ( _tr_blocklistGetFilename (l->data),2324 if (tr_stringEndsWith (tr_blocklistFileGetFilename (l->data), 2325 2325 defaultName)) 2326 2326 b = l->data; … … 2329 2329 { 2330 2330 char * path = tr_buildPath (session->configDir, "blocklists", defaultName, NULL); 2331 b = _tr_blocklistNew (path, session->isBlocklistEnabled);2331 b = tr_blocklistFileNew (path, session->isBlocklistEnabled); 2332 2332 tr_list_append (&session->blocklists, b); 2333 2333 tr_free (path); 2334 2334 } 2335 2335 2336 ruleCount = _tr_blocklistSetContent (b, contentFilename);2336 ruleCount = tr_blocklistFileSetContent (b, contentFilename); 2337 2337 tr_sessionUnlock (session); 2338 2338 return ruleCount; … … 2348 2348 2349 2349 for (l = session->blocklists; l; l = l->next) 2350 if ( _tr_blocklistHasAddress (l->data, addr))2350 if (tr_blocklistFileHasAddress (l->data, addr)) 2351 2351 return true; 2352 2352 return false;
Note: See TracChangeset
for help on using the changeset viewer.