Mercurial > dnsbl
comparison src/context.cpp @ 270:f92f24950bd3 stable-6-0-35
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 09 Sep 2013 15:15:53 -0700 |
parents | f941563c2a95 |
children | a99b6c1f5f67 |
comparison
equal
deleted
inserted
replaced
269:6d2a11f0ae41 | 270:f92f24950bd3 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under | 3 Copyright (c) 2013 Carl Byington - 510 Software Group, released under |
4 the GPL version 3 or any later version at your choice available at | 4 the GPL version 3 or any later version at your choice available at |
5 http://www.gnu.org/licenses/gpl-3.0.txt | 5 http://www.gnu.org/licenses/gpl-3.0.txt |
6 | 6 |
7 */ | 7 */ |
8 | 8 |
18 #include <sys/stat.h> | 18 #include <sys/stat.h> |
19 #include <sys/un.h> | 19 #include <sys/un.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 #include <climits> | 21 #include <climits> |
22 | 22 |
23 const char *token_asterisk; | |
23 const char *token_autowhite; | 24 const char *token_autowhite; |
25 const char *token_bang; | |
24 const char *token_black; | 26 const char *token_black; |
25 const char *token_cctld; | |
26 const char *token_content; | 27 const char *token_content; |
27 const char *token_context; | 28 const char *token_context; |
28 const char *token_dccbulk; | 29 const char *token_dccbulk; |
29 const char *token_dccfrom; | 30 const char *token_dccfrom; |
30 const char *token_dccgrey; | 31 const char *token_dccgrey; |
50 const char *token_no; | 51 const char *token_no; |
51 const char *token_off; | 52 const char *token_off; |
52 const char *token_ok; | 53 const char *token_ok; |
53 const char *token_ok2; | 54 const char *token_ok2; |
54 const char *token_on; | 55 const char *token_on; |
56 const char *token_period; | |
55 const char *token_rate; | 57 const char *token_rate; |
56 const char *token_rbrace; | 58 const char *token_rbrace; |
57 const char *token_require; | 59 const char *token_require; |
58 const char *token_requirerdns; | 60 const char *token_requirerdns; |
59 const char *token_semi; | 61 const char *token_semi; |
914 if ((rc == token_inherit) && parent) return parent->find_from(from); | 916 if ((rc == token_inherit) && parent) return parent->find_from(from); |
915 return (rc == token_inherit) ? token_unknown : rc; | 917 return (rc == token_inherit) ? token_unknown : rc; |
916 } | 918 } |
917 | 919 |
918 | 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 | |
919 CONTEXTP CONTEXT::find_context(const char *from) { | 929 CONTEXTP CONTEXT::find_context(const char *from) { |
920 context_map::iterator i = env_from_context.find(from); | 930 context_map::iterator i = env_from_context.find(from); |
921 if (i != env_from_context.end()) return (*i).second; // found user@domain key | 931 if (i != env_from_context.end()) return (*i).second; // found user@domain key |
922 const char *x = strchr(from, '@'); | 932 const char *x = strchr(from, '@'); |
923 if (x) { | 933 if (x) { |
991 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); | 1001 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); |
992 return content_host_ignore; | 1002 return content_host_ignore; |
993 } | 1003 } |
994 | 1004 |
995 | 1005 |
996 string_set& CONTEXT::get_content_cctlds() { | |
997 if (content_cctlds.empty() && parent) return parent->get_content_cctlds(); | |
998 return content_cctlds; | |
999 } | |
1000 | |
1001 string_set& CONTEXT::get_content_tlds() { | 1006 string_set& CONTEXT::get_content_tlds() { |
1002 if (content_tlds.empty() && parent) return parent->get_content_tlds(); | 1007 if (content_tlds.empty() && parent) return parent->get_content_tlds(); |
1003 return content_tlds; | 1008 return content_tlds; |
1009 } | |
1010 | |
1011 | |
1012 string_set& CONTEXT::get_content_tldwilds() { | |
1013 if (content_tldwilds.empty() && parent) return parent->get_content_tldwilds(); | |
1014 return content_tldwilds; | |
1015 } | |
1016 | |
1017 | |
1018 string_set& CONTEXT::get_content_tldnots() { | |
1019 if (content_tldnots.empty() && parent) return parent->get_content_tldnots(); | |
1020 return content_tldnots; | |
1004 } | 1021 } |
1005 | 1022 |
1006 | 1023 |
1007 string_set& CONTEXT::get_html_tags() { | 1024 string_set& CONTEXT::get_html_tags() { |
1008 if (html_tags.empty() && parent) return parent->get_html_tags(); | 1025 if (html_tags.empty() && parent) return parent->get_html_tags(); |
1102 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { | 1119 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { |
1103 printf("%s %s; \n", indent, *i); | 1120 printf("%s %s; \n", indent, *i); |
1104 } | 1121 } |
1105 printf("%s }; \n", indent); | 1122 printf("%s }; \n", indent); |
1106 } | 1123 } |
1107 if (!content_cctlds.empty()) { | 1124 if (!content_tlds.empty() || !content_tldwilds.empty() || !content_tldnots.empty()) { |
1108 printf("%s cctld { \n", indent); | |
1109 printf("%s ", indent); | |
1110 for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) { | |
1111 printf("%s; ", *i); | |
1112 } | |
1113 printf("\n%s }; \n", indent); | |
1114 } | |
1115 if (!content_tlds.empty()) { | |
1116 printf("%s tld { \n", indent); | 1125 printf("%s tld { \n", indent); |
1117 printf("%s ", indent); | 1126 printf("%s ", indent); |
1118 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { | 1127 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { |
1119 printf("%s; ", *i); | 1128 printf("%s; ", *i); |
1129 } | |
1130 for (string_set::iterator i=content_tldwilds.begin(); i!=content_tldwilds.end(); i++) { | |
1131 printf("*%s; ", *i); | |
1132 } | |
1133 for (string_set::iterator i=content_tldnots.begin(); i!=content_tldnots.end(); i++) { | |
1134 printf("!%s; ", *i); | |
1120 } | 1135 } |
1121 printf("\n%s }; \n", indent); | 1136 printf("\n%s }; \n", indent); |
1122 } | 1137 } |
1123 if (!html_tags.empty()) { | 1138 if (!html_tags.empty()) { |
1124 printf("%s html_tags { \n", indent); | 1139 printf("%s html_tags { \n", indent); |
1414 if (!tsa(tok, token_lbrace)) return false; | 1429 if (!tsa(tok, token_lbrace)) return false; |
1415 while (true) { | 1430 while (true) { |
1416 const char *have = tok.next(); | 1431 const char *have = tok.next(); |
1417 if (!have) break; | 1432 if (!have) break; |
1418 if (have == token_rbrace) break; // done | 1433 if (have == token_rbrace) break; // done |
1419 me.add_tld(have); | 1434 if (have == token_bang) { |
1420 } | 1435 have = tok.next(); |
1421 if (!tsa(tok, token_semi)) return false; | 1436 if (!have) break; |
1422 } | 1437 if (have == token_rbrace) break; // done |
1423 else if (have == token_cctld) { | 1438 char buf[200]; |
1424 if (!tsa(tok, token_lbrace)) return false; | 1439 snprintf(buf, sizeof(buf), "!%s", have); |
1425 while (true) { | 1440 me.add_tld(register_string(buf)); // leading ! |
1426 const char *have = tok.next(); | 1441 } |
1427 if (!have) break; | 1442 else if (have == token_asterisk) { |
1428 if (have == token_rbrace) break; // done | 1443 have = tok.next(); |
1429 me.add_cctld(have); | 1444 if (!have) break; |
1445 if (have == token_rbrace) break; // done | |
1446 if (have == token_period) { | |
1447 have = tok.next(); | |
1448 if (!have) break; | |
1449 if (have == token_rbrace) break; // done | |
1450 char buf[200]; | |
1451 snprintf(buf, sizeof(buf), "*.%s", have); | |
1452 me.add_tld(register_string(buf)); // leading *. | |
1453 } | |
1454 } | |
1455 else me.add_tld(have); | |
1430 } | 1456 } |
1431 if (!tsa(tok, token_semi)) return false; | 1457 if (!tsa(tok, token_semi)) return false; |
1432 } | 1458 } |
1433 else if (have == token_html_tags) { | 1459 else if (have == token_html_tags) { |
1434 if (!tsa(tok, token_lbrace)) return false; | 1460 if (!tsa(tok, token_lbrace)) return false; |
1862 | 1888 |
1863 //////////////////////////////////////////////// | 1889 //////////////////////////////////////////////// |
1864 // init the tokens | 1890 // init the tokens |
1865 // | 1891 // |
1866 void token_init() { | 1892 void token_init() { |
1893 token_asterisk = register_string("*"); | |
1867 token_autowhite = register_string("autowhite"); | 1894 token_autowhite = register_string("autowhite"); |
1895 token_bang = register_string("!"); | |
1868 token_black = register_string("black"); | 1896 token_black = register_string("black"); |
1869 token_cctld = register_string("cctld"); | |
1870 token_content = register_string("content"); | 1897 token_content = register_string("content"); |
1871 token_context = register_string("context"); | 1898 token_context = register_string("context"); |
1872 token_dccbulk = register_string("dcc_bulk_threshold"); | 1899 token_dccbulk = register_string("dcc_bulk_threshold"); |
1873 token_dccfrom = register_string("dcc_from"); | 1900 token_dccfrom = register_string("dcc_from"); |
1874 token_dccgrey = register_string("dcc_greylist"); | 1901 token_dccgrey = register_string("dcc_greylist"); |
1894 token_no = register_string("no"); | 1921 token_no = register_string("no"); |
1895 token_off = register_string("off"); | 1922 token_off = register_string("off"); |
1896 token_ok = register_string("ok"); | 1923 token_ok = register_string("ok"); |
1897 token_ok2 = register_string("ok2"); | 1924 token_ok2 = register_string("ok2"); |
1898 token_on = register_string("on"); | 1925 token_on = register_string("on"); |
1926 token_period = register_string("."); | |
1899 token_rate = register_string("rate_limit"); | 1927 token_rate = register_string("rate_limit"); |
1900 token_rbrace = register_string("}"); | 1928 token_rbrace = register_string("}"); |
1901 token_require = register_string("require_match"); | 1929 token_require = register_string("require_match"); |
1902 token_requirerdns = register_string("require_rdns"); | 1930 token_requirerdns = register_string("require_rdns"); |
1903 token_semi = register_string(";"); | 1931 token_semi = register_string(";"); |