Mercurial > sm-archive
diff src/context.cpp @ 13:75e1a9bcbc2e
gpl3, add removal option for original recipients
author | carl |
---|---|
date | Sat, 25 Aug 2007 11:14:49 -0700 |
parents | 61a4e8773e2e |
children | 8ebecad6530f |
line wrap: on
line diff
--- a/src/context.cpp Mon Mar 19 22:38:37 2007 -0700 +++ b/src/context.cpp Sat Aug 25 11:14:49 2007 -0700 @@ -1,8 +1,8 @@ /* -Copyright (c) 2004 Carl Byington - 510 Software Group, released under -the GPL version 2 or any later version at your choice available at -http://www.fsf.org/licenses/gpl.txt +Copyright (c) 2007 Carl Byington - 510 Software Group, released under +the GPL version 3 or any later version at your choice available at +http://www.gnu.org/licenses/gpl-3.0.txt */ @@ -15,6 +15,7 @@ char *token_lbrace; char *token_rbrace; char *token_rcptto; +char *token_remove; char *token_semi; string_set all_strings; // owns all the strings, only modified by the config loader thread @@ -31,6 +32,24 @@ } +bool CONFIG::find(char *needle, string_set &haystack) { + string_set::iterator i = haystack.find(needle); + if (i != haystack.end()) return true; // found user@domain.tld key + char *x = strchr(needle, '@'); + if (x) { + x++; + i = haystack.find(x); + if (i != haystack.end()) return true; // found domain.tld key + char y = *x; + *x = '\0'; + i = haystack.find(needle); + *x = y; + if (i != haystack.end()) return true; // found user@ key + } + return false; +} + + char *CONFIG::find(char *needle, string_map &haystack) { string_map::iterator i = haystack.find(needle); if (i != haystack.end()) return (*i).second; // found user@domain.tld key @@ -54,14 +73,17 @@ for (string_map::iterator i=rcpt_to.begin(); i!=rcpt_to.end(); i++) { char *to = (*i).first; char *target = (*i).second; - printf(" %s \t %s\n", to, target); + if (!target) target = "\"\""; + bool rem = find_remove(to); + printf(" %s \t %s%s;\n", to, target, (rem) ? " remove" : ""); } printf("};\n"); printf("env_from {\n"); for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) { char *from = (*i).first; char *target = (*i).second; - printf(" %s \t %s\n", from, target); + if (!target) target = "\"\""; + printf(" %s \t %s;\n", from, target); } printf("};\n"); } @@ -99,6 +121,14 @@ //////////////////////////////////////////////// +// clear all global strings, helper for valgrind checking +// +void clear_strings() { + discard(all_strings); +} + + +//////////////////////////////////////////////// // bool tsa(TOKEN &tok, char *token); bool tsa(TOKEN &tok, char *token) { @@ -118,12 +148,16 @@ char *have = tok.next(); if (!have) break; if (have == token_rbrace) break; - if (have == token_semi) { - // optional separators - } - else { char *target = tok.next(); dc.add_to(have, target); + target = tok.next(); + if (target == token_remove) { + dc.add_remove(have); + target = tok.next(); + } + if (target != token_semi) { + tok.token_error(token_semi, target); + break; } } return tsa(tok, token_semi); @@ -189,5 +223,6 @@ token_lbrace = register_string("{"); token_rbrace = register_string("}"); token_rcptto = register_string("rcpt_to"); + token_remove = register_string("remove"); token_semi = register_string(";"); }