comparison src/context.cpp @ 272:a99b6c1f5f67

Code cleanup, increase minimum hostname length for uribl checking
author Carl Byington <carl@five-ten-sg.com>
date Mon, 09 Sep 2013 19:30:21 -0700
parents f92f24950bd3
children bdcf203e3f7b
comparison
equal deleted inserted replaced
271:93d1337fd5bc 272:a99b6c1f5f67
916 if ((rc == token_inherit) && parent) return parent->find_from(from); 916 if ((rc == token_inherit) && parent) return parent->find_from(from);
917 return (rc == token_inherit) ? token_unknown : rc; 917 return (rc == token_inherit) ? token_unknown : rc;
918 } 918 }
919 919
920 920
921 void CONTEXT::add_tld(const char *tld) {
922 int n = strlen(tld);
923 if ((n > 1) && (tld[0] == '*') && (tld[1] == '.')) content_tldwilds.insert(tld+1);
924 else if ((n > 0) && (tld[0] == '!')) content_tldnots.insert(tld+1);
925 else content_tlds.insert(tld);
926 }
927
928
929 CONTEXTP CONTEXT::find_context(const char *from) { 921 CONTEXTP CONTEXT::find_context(const char *from) {
930 context_map::iterator i = env_from_context.find(from); 922 context_map::iterator i = env_from_context.find(from);
931 if (i != env_from_context.end()) return (*i).second; // found user@domain key 923 if (i != env_from_context.end()) return (*i).second; // found user@domain key
932 const char *x = strchr(from, '@'); 924 const char *x = strchr(from, '@');
933 if (x) { 925 if (x) {
1433 if (have == token_rbrace) break; // done 1425 if (have == token_rbrace) break; // done
1434 if (have == token_bang) { 1426 if (have == token_bang) {
1435 have = tok.next(); 1427 have = tok.next();
1436 if (!have) break; 1428 if (!have) break;
1437 if (have == token_rbrace) break; // done 1429 if (have == token_rbrace) break; // done
1438 char buf[200]; 1430 me.add_tldnot(have);
1439 snprintf(buf, sizeof(buf), "!%s", have);
1440 me.add_tld(register_string(buf)); // leading !
1441 } 1431 }
1442 else if (have == token_asterisk) { 1432 else if (have == token_asterisk) {
1443 have = tok.next(); 1433 have = tok.next();
1444 if (!have) break; 1434 if (!have) break;
1445 if (have == token_rbrace) break; // done 1435 if (have == token_rbrace) break; // done
1446 if (have == token_period) { 1436 if (have == token_period) {
1447 have = tok.next(); 1437 have = tok.next();
1448 if (!have) break; 1438 if (!have) break;
1449 if (have == token_rbrace) break; // done 1439 if (have == token_rbrace) break; // done
1450 char buf[200]; 1440 me.add_tldwild(have);
1451 snprintf(buf, sizeof(buf), "*.%s", have);
1452 me.add_tld(register_string(buf)); // leading *.
1453 } 1441 }
1454 } 1442 }
1455 else me.add_tld(have); 1443 else me.add_tld(have);
1456 } 1444 }
1457 if (!tsa(tok, token_semi)) return false; 1445 if (!tsa(tok, token_semi)) return false;