comparison src/context.cpp @ 117:aa07452e641b

uribl patch from Jeff Evans <jeffe@tricab.com>
author carl
date Sun, 12 Mar 2006 10:15:39 -0800
parents 6ac7ba4a8312
children d9d2f8699621
comparison
equal deleted inserted replaced
116:0094678a16d0 117:aa07452e641b
48 char *token_rbrace; 48 char *token_rbrace;
49 char *token_semi; 49 char *token_semi;
50 char *token_soft; 50 char *token_soft;
51 char *token_substitute; 51 char *token_substitute;
52 char *token_tld; 52 char *token_tld;
53 char *token_cctld;
53 char *token_unknown; 54 char *token_unknown;
54 char *token_verify; 55 char *token_verify;
55 char *token_white; 56 char *token_white;
56 57
57 char *token_myhostname; 58 char *token_myhostname;
443 } 444 }
444 445
445 446
446 CONTEXTP CONFIG::find_context(char *to) { 447 CONTEXTP CONFIG::find_context(char *to) {
447 context_map::iterator i = env_to.find(to); 448 context_map::iterator i = env_to.find(to);
448 if (i != env_to.end()) return (*i).second; // found user@domain.tld key 449 if (i != env_to.end()) return (*i).second; // found user@domain key
449 char *x = strchr(to, '@'); 450 char *x = strchr(to, '@');
450 if (x) { 451 if (x) {
451 x++; 452 x++;
452 i = env_to.find(x); 453 i = env_to.find(x);
453 if (i != env_to.end()) return (*i).second; // found domain.tld key 454 if (i != env_to.end()) return (*i).second; // found domain key
454 char y = *x; 455 char y = *x;
455 *x = '\0'; 456 *x = '\0';
456 i = env_to.find(to); 457 i = env_to.find(to);
457 *x = y; 458 *x = y;
458 if (i != env_to.end()) return (*i).second; // found user@ key 459 if (i != env_to.end()) return (*i).second; // found user@ key
551 552
552 553
553 char *CONTEXT::find_from(char *from) { 554 char *CONTEXT::find_from(char *from) {
554 char *rc = token_inherit; 555 char *rc = token_inherit;
555 string_map::iterator i = env_from.find(from); 556 string_map::iterator i = env_from.find(from);
556 if (i != env_from.end()) rc = (*i).second; // found user@domain.tld key 557 if (i != env_from.end()) rc = (*i).second; // found user@domain key
557 else { 558 else {
558 char *x = strchr(from, '@'); 559 char *x = strchr(from, '@');
559 if (x) { 560 if (x) {
560 x++; 561 x++;
561 i = env_from.find(x); 562 i = env_from.find(x);
562 if (i != env_from.end()) rc = (*i).second; // found domain.tld key 563 if (i != env_from.end()) rc = (*i).second; // found domain key
563 else { 564 else {
564 char y = *x; 565 char y = *x;
565 *x = '\0'; 566 *x = '\0';
566 i = env_from.find(from); 567 i = env_from.find(from);
567 *x = y; 568 *x = y;
575 } 576 }
576 577
577 578
578 CONTEXTP CONTEXT::find_context(char *from) { 579 CONTEXTP CONTEXT::find_context(char *from) {
579 context_map::iterator i = env_from_context.find(from); 580 context_map::iterator i = env_from_context.find(from);
580 if (i != env_from_context.end()) return (*i).second; // found user@domain.tld key 581 if (i != env_from_context.end()) return (*i).second; // found user@domain key
581 char *x = strchr(from, '@'); 582 char *x = strchr(from, '@');
582 if (x) { 583 if (x) {
583 x++; 584 x++;
584 i = env_from_context.find(x); 585 i = env_from_context.find(x);
585 if (i != env_from_context.end()) return (*i).second; // found domain.tld key 586 if (i != env_from_context.end()) return (*i).second; // found domain key
586 char y = *x; 587 char y = *x;
587 *x = '\0'; 588 *x = '\0';
588 i = env_from_context.find(from); 589 i = env_from_context.find(from);
589 *x = y; 590 *x = y;
590 if (i != env_from_context.end()) return (*i).second; // found user@ key 591 if (i != env_from_context.end()) return (*i).second; // found user@ key
623 string_set& CONTEXT::get_content_host_ignore() { 624 string_set& CONTEXT::get_content_host_ignore() {
624 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); 625 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore();
625 return content_host_ignore; 626 return content_host_ignore;
626 } 627 }
627 628
629
630 string_set& CONTEXT::get_content_cctlds() {
631 if (content_cctlds.empty() && parent) return parent->get_content_cctlds();
632 return content_cctlds;
633 }
628 634
629 string_set& CONTEXT::get_content_tlds() { 635 string_set& CONTEXT::get_content_tlds() {
630 if (content_tlds.empty() && parent) return parent->get_content_tlds(); 636 if (content_tlds.empty() && parent) return parent->get_content_tlds();
631 return content_tlds; 637 return content_tlds;
632 } 638 }
690 printf("%s ignore { \n", indent); 696 printf("%s ignore { \n", indent);
691 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { 697 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) {
692 printf("%s %s; \n", indent, *i); 698 printf("%s %s; \n", indent, *i);
693 } 699 }
694 printf("%s }; \n", indent); 700 printf("%s }; \n", indent);
701 }
702 if (!content_cctlds.empty()) {
703 printf("%s cctld { \n", indent);
704 printf("%s ", indent);
705 for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) {
706 printf("%s; ", *i);
707 }
708 printf("\n%s }; \n", indent);
695 } 709 }
696 if (!content_tlds.empty()) { 710 if (!content_tlds.empty()) {
697 printf("%s tld { \n", indent); 711 printf("%s tld { \n", indent);
698 printf("%s ", indent); 712 printf("%s ", indent);
699 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { 713 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
885 if (have == token_rbrace) break; // done 899 if (have == token_rbrace) break; // done
886 me.add_ignore(have); 900 me.add_ignore(have);
887 } 901 }
888 if (!tsa(tok, token_semi)) return false; 902 if (!tsa(tok, token_semi)) return false;
889 } 903 }
904 else if (have == token_cctld) {
905 if (!tsa(tok, token_lbrace)) return false;
906 while (true) {
907 char *have = tok.next();
908 if (!have) break;
909 if (have == token_rbrace) break; // done
910 me.add_cctld(have);
911 }
912 if (!tsa(tok, token_semi)) return false;
913 }
890 else if (have == token_tld) { 914 else if (have == token_tld) {
891 if (!tsa(tok, token_lbrace)) return false; 915 if (!tsa(tok, token_lbrace)) return false;
892 while (true) { 916 while (true) {
893 char *have = tok.next(); 917 char *have = tok.next();
894 if (!have) break; 918 if (!have) break;
1226 //////////////////////////////////////////////// 1250 ////////////////////////////////////////////////
1227 // init the tokens 1251 // init the tokens
1228 // 1252 //
1229 void token_init() { 1253 void token_init() {
1230 token_black = register_string("black"); 1254 token_black = register_string("black");
1255 token_cctld = register_string("cctld");
1231 token_content = register_string("content"); 1256 token_content = register_string("content");
1232 token_context = register_string("context"); 1257 token_context = register_string("context");
1233 token_dccfrom = register_string("dcc_from"); 1258 token_dccfrom = register_string("dcc_from");
1234 token_dccto = register_string("dcc_to"); 1259 token_dccto = register_string("dcc_to");
1235 token_default = register_string("default"); 1260 token_default = register_string("default");