comparison src/context.cpp @ 249:15bf4f68a0b2

Add dnswl support
author Carl Byington <carl@five-ten-sg.com>
date Sun, 08 Apr 2012 11:42:59 -0700
parents ef97c7cd4a6e
children d6d5c50b9278
comparison
equal deleted inserted replaced
248:b0738685bf51 249:15bf4f68a0b2
30 const char *token_dccgrey; 30 const char *token_dccgrey;
31 const char *token_dccto; 31 const char *token_dccto;
32 const char *token_default; 32 const char *token_default;
33 const char *token_dnsbl; 33 const char *token_dnsbl;
34 const char *token_dnsbll; 34 const char *token_dnsbll;
35 const char *token_dnswl;
36 const char *token_dnswll;
35 const char *token_envfrom; 37 const char *token_envfrom;
36 const char *token_envto; 38 const char *token_envto;
37 const char *token_filter; 39 const char *token_filter;
38 const char *token_generic; 40 const char *token_generic;
39 const char *token_host_limit; 41 const char *token_host_limit;
595 (strcmp(suffix, rhs.suffix) == 0) && 597 (strcmp(suffix, rhs.suffix) == 0) &&
596 (strcmp(message, rhs.message) == 0); 598 (strcmp(message, rhs.message) == 0);
597 } 599 }
598 600
599 601
602 DNSWL::DNSWL(const char *n, const char *s, const int l) {
603 name = n;
604 suffix = s;
605 level = l;
606 }
607
608
609 bool DNSWL::operator==(const DNSWL &rhs) {
610 return (strcmp(name, rhs.name) == 0) &&
611 (strcmp(suffix, rhs.suffix) == 0) &&
612 (level == rhs.level);
613 }
614
615
600 CONFIG::CONFIG() { 616 CONFIG::CONFIG() {
601 reference_count = 0; 617 reference_count = 0;
602 generation = 0; 618 generation = 0;
603 load_time = 0; 619 load_time = 0;
604 default_context = NULL; 620 default_context = NULL;
917 if (parent) return parent->find_dnsbl(name); 933 if (parent) return parent->find_dnsbl(name);
918 return NULL; 934 return NULL;
919 } 935 }
920 936
921 937
938 DNSWLP CONTEXT::find_dnswl(const char *name) {
939 dnswlp_map::iterator i = dnswl_names.find(name);
940 if (i != dnswl_names.end()) return (*i).second;
941 if (parent) return parent->find_dnswl(name);
942 return NULL;
943 }
944
945
922 const char* CONTEXT::get_content_suffix() { 946 const char* CONTEXT::get_content_suffix() {
923 if (!content_suffix && parent) return parent->get_content_suffix(); 947 if (!content_suffix && parent) return parent->get_content_suffix();
924 return content_suffix; 948 return content_suffix;
925 } 949 }
926 950
967 991
968 992
969 dnsblp_list& CONTEXT::get_dnsbl_list() { 993 dnsblp_list& CONTEXT::get_dnsbl_list() {
970 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list(); 994 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list();
971 return dnsbl_list; 995 return dnsbl_list;
996 }
997
998
999 dnswlp_list& CONTEXT::get_dnswl_list() {
1000 if (dnswl_list.empty() && parent) return parent->get_dnswl_list();
1001 return dnswl_list;
972 } 1002 }
973 1003
974 1004
975 bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) { 1005 bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) {
976 if (spamassassin_limit && (score > spamassassin_limit)) { 1006 if (spamassassin_limit && (score > spamassassin_limit)) {
1010 const char *n = (*i).first; 1040 const char *n = (*i).first;
1011 DNSBL &d = *(*i).second; 1041 DNSBL &d = *(*i).second;
1012 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message); 1042 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
1013 } 1043 }
1014 1044
1045 for (dnswlp_map::iterator i=dnswl_names.begin(); i!=dnswl_names.end(); i++) {
1046 const char *n = (*i).first;
1047 DNSWL &d = *(*i).second;
1048 printf("%s dnswl %s %s %d; \n", indent, n, d.suffix, d.level);
1049 }
1050
1051 {
1015 dnsblp_list dl = get_dnsbl_list(); 1052 dnsblp_list dl = get_dnsbl_list();
1016 if (!dl.empty()) { 1053 if (!dl.empty()) {
1017 printf("%s dnsbl_list", indent); 1054 printf("%s dnsbl_list", indent);
1018 for (dnsblp_list::iterator i=dl.begin(); i!=dl.end(); i++) { 1055 for (dnsblp_list::iterator i=dl.begin(); i!=dl.end(); i++) {
1019 DNSBL &d = *(*i); 1056 DNSBL &d = *(*i);
1020 printf(" %s", d.name); 1057 printf(" %s", d.name);
1021 } 1058 }
1022 printf("; \n"); 1059 printf("; \n");
1023 } 1060 }}
1061
1062 {
1063 dnswlp_list dl = get_dnswl_list();
1064 if (!dl.empty()) {
1065 printf("%s dnswl_list", indent);
1066 for (dnswlp_list::iterator i=dl.begin(); i!=dl.end(); i++) {
1067 DNSWL &d = *(*i);
1068 printf(" %s", d.name);
1069 }
1070 printf("; \n");
1071 }}
1024 1072
1025 if (content_filtering) { 1073 if (content_filtering) {
1026 printf("%s content on { \n", indent); 1074 printf("%s content on { \n", indent);
1027 if (content_suffix) { 1075 if (content_suffix) {
1028 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message); 1076 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message);
1220 } 1268 }
1221 1269
1222 1270
1223 //////////////////////////////////////////////// 1271 ////////////////////////////////////////////////
1224 // 1272 //
1273 bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1274 bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1275 const char *name = tok.next();
1276 const char *suf = tok.next();
1277 const int lev = tok.nextint();
1278 if (!tsa(tok, token_semi)) return false;
1279 DNSWLP dnsnew = new DNSWL(name, suf, lev);
1280 DNSWLP dnsold = me.find_dnswl(name);
1281 if (dnsold && (*dnsold == *dnsnew)) {
1282 // duplicate redefinition, ignore it
1283 delete dnsnew;
1284 return true;
1285 }
1286 me.add_dnswl(name, dnsnew);
1287 return true;
1288 }
1289
1290
1291 ////////////////////////////////////////////////
1292 //
1225 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me); 1293 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1226 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { 1294 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1227 while (true) { 1295 while (true) {
1228 const char *have = tok.next(); 1296 const char *have = tok.next();
1229 if (!have) break; 1297 if (!have) break;
1232 if (dns) { 1300 if (dns) {
1233 me.add_dnsbl(dns); 1301 me.add_dnsbl(dns);
1234 } 1302 }
1235 else { 1303 else {
1236 tok.token_error("dnsbl name", have); 1304 tok.token_error("dnsbl name", have);
1305 return false;
1306 }
1307 }
1308 return true;
1309 }
1310
1311
1312 ////////////////////////////////////////////////
1313 //
1314 bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1315 bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1316 while (true) {
1317 const char *have = tok.next();
1318 if (!have) break;
1319 if (have == token_semi) break;
1320 DNSWLP dns = me.find_dnswl(have);
1321 if (dns) {
1322 me.add_dnswl(dns);
1323 }
1324 else {
1325 tok.token_error("dnswl name", have);
1237 return false; 1326 return false;
1238 } 1327 }
1239 } 1328 }
1240 return true; 1329 return true;
1241 } 1330 }
1648 if (!parse_dnsbl(tok, dc, *con)) return false; 1737 if (!parse_dnsbl(tok, dc, *con)) return false;
1649 } 1738 }
1650 else if (have == token_dnsbll) { 1739 else if (have == token_dnsbll) {
1651 if (!parse_dnsbll(tok, dc, *con)) return false; 1740 if (!parse_dnsbll(tok, dc, *con)) return false;
1652 } 1741 }
1742 else if (have == token_dnswl) {
1743 if (!parse_dnswl(tok, dc, *con)) return false;
1744 }
1745 else if (have == token_dnswll) {
1746 if (!parse_dnswll(tok, dc, *con)) return false;
1747 }
1653 else if (have == token_content) { 1748 else if (have == token_content) {
1654 if (!parse_content(tok, dc, *con)) return false; 1749 if (!parse_content(tok, dc, *con)) return false;
1655 } 1750 }
1656 else if (have == token_envto) { 1751 else if (have == token_envto) {
1657 if (!parse_envto(tok, dc, *con)) return false; 1752 if (!parse_envto(tok, dc, *con)) return false;
1734 token_dccgrey = register_string("dcc_greylist"); 1829 token_dccgrey = register_string("dcc_greylist");
1735 token_dccto = register_string("dcc_to"); 1830 token_dccto = register_string("dcc_to");
1736 token_default = register_string("default"); 1831 token_default = register_string("default");
1737 token_dnsbl = register_string("dnsbl"); 1832 token_dnsbl = register_string("dnsbl");
1738 token_dnsbll = register_string("dnsbl_list"); 1833 token_dnsbll = register_string("dnsbl_list");
1834 token_dnswl = register_string("dnswl");
1835 token_dnswll = register_string("dnswl_list");
1739 token_envfrom = register_string("env_from"); 1836 token_envfrom = register_string("env_from");
1740 token_envto = register_string("env_to"); 1837 token_envto = register_string("env_to");
1741 token_filter = register_string("filter"); 1838 token_filter = register_string("filter");
1742 token_generic = register_string("generic"); 1839 token_generic = register_string("generic");
1743 token_host_limit = register_string("host_limit"); 1840 token_host_limit = register_string("host_limit");