comparison src/scanner.cpp @ 12:6ac6d6b822ce stable-2-0

fix memory leak with duplicate url host names, document differences from sendmail.mc feature
author carl
date Fri, 23 Apr 2004 22:45:10 -0700
parents 2c206836b4cc
children 2ae8d953f1d0
comparison
equal deleted inserted replaced
11:2c206836b4cc 12:6ac6d6b822ce
818 0, // 0xff 818 0, // 0xff
819 }; 819 };
820 820
821 #define PENDING_LIMIT 100 821 #define PENDING_LIMIT 100
822 struct fsa { 822 struct fsa {
823 u_char pending[PENDING_LIMIT]; 823 u_char pending[PENDING_LIMIT];
824 int count; 824 int count;
825 state st; 825 state st;
826 state init; 826 state init;
827 fsa* next; 827 fsa* next;
828 string_set *urls; 828 string_set *hosts;
829 829
830 fsa(state init, fsa* next_, string_set *urls_); 830 fsa(state init, fsa* next_, string_set *hosts_);
831 void push(u_char *buf, int len); 831 void push(u_char *buf, int len);
832 }; 832 };
833 833
834 fsa::fsa(state init_, fsa *next_, string_set *urls_) { 834 fsa::fsa(state init_, fsa *next_, string_set *hosts_) {
835 count = 0; 835 count = 0;
836 st = init_; 836 st = init_;
837 init = init_; 837 init = init_;
838 next = next_; 838 next = next_;
839 urls = urls_; 839 hosts = hosts_;
840 } 840 }
841 841
842 void fsa::push(u_char *buf, int len) { 842 void fsa::push(u_char *buf, int len) {
843 for (int i=0; i<len; i++) { 843 for (int i=0; i<len; i++) {
844 u_char c = buf[i]; 844 u_char c = buf[i];
864 case u_reco: { 864 case u_reco: {
865 if (count > 12) { 865 if (count > 12) {
866 pending[count-1] = 0; 866 pending[count-1] = 0;
867 if (strncasecmp((const char *)pending, "http://", 7) == 0) { 867 if (strncasecmp((const char *)pending, "http://", 7) == 0) {
868 char *p = (char *)pending + 7; 868 char *p = (char *)pending + 7;
869 if (strchr(p, '.')) urls->insert(strdup(p)); // require at least one . in a dns name 869 if (strchr(p, '.')) register_string(*hosts, p); // require at least one . in a dns name
870 } 870 }
871 } 871 }
872 } // fall thru 872 } // fall thru
873 873
874 case u_init: { 874 case u_init: {
967 fsa *urls_parser; 967 fsa *urls_parser;
968 fsa *html_parser; 968 fsa *html_parser;
969 fsa *mime_parser; 969 fsa *mime_parser;
970 fsa *b64_parser; 970 fsa *b64_parser;
971 971
972 url_scanner(string_set *urls); 972 url_scanner(string_set *hosts);
973 ~url_scanner(); 973 ~url_scanner();
974 void scan(u_char *buffer, size_t length); 974 void scan(u_char *buffer, size_t length);
975 }; 975 };
976 976
977 url_scanner::url_scanner(string_set *urls) { 977 url_scanner::url_scanner(string_set *hosts) {
978 urls_parser = new fsa(u_init, NULL, urls); 978 urls_parser = new fsa(u_init, NULL, hosts);
979 html_parser = new fsa(e_init, urls_parser, NULL); 979 html_parser = new fsa(e_init, urls_parser, NULL);
980 mime_parser = new fsa(m_init, html_parser, NULL); 980 mime_parser = new fsa(m_init, html_parser, NULL);
981 b64_parser = new fsa(b_init, mime_parser, NULL); 981 b64_parser = new fsa(b_init, mime_parser, NULL);
982 } 982 }
983 983