Mercurial > syslog2iptables
diff src/tokenizer.cpp @ 48:ba0259c9e411 stable-1-0-11
Fixes to compile on Fedora 9 and for const correctness
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 29 May 2008 11:38:42 -0700 |
parents | d9ae11033b4b |
children | 60f59936fabb |
line wrap: on
line diff
--- a/src/tokenizer.cpp Sat Mar 22 11:34:56 2008 -0700 +++ b/src/tokenizer.cpp Thu May 29 11:38:42 2008 -0700 @@ -6,6 +6,11 @@ */ +// This version of the tokenizer does not force the config to lower +// case, to avoid lowercasing the iptables commands, which need some +// uppercase arguments. It also considers / to be a separate token +// since that is needed for the cidr style ignore statement. + #include "includes.h" const int maxlen = 1000; // used for snprintf buffers @@ -287,7 +292,7 @@ }; -TOKEN::TOKEN(char *fn, string_set *includes) { +TOKEN::TOKEN(const char *fn, string_set *includes) { pushed = false; include_files = includes; include(fn); @@ -301,7 +306,7 @@ void TOKEN::pop() { ifstream *is = streams.front(); - char *fn = filenames.front(); + const char *fn = filenames.front(); streams.pop_front(); filenamess.erase(fn); if (filenames.size() > 1) filenames.pop_front(); @@ -319,7 +324,6 @@ bool TOKEN::next_char(u_char &uc) { if (pushed) { - //uc = (u_char)tolower((char)pushed_char); uc = pushed_char; pushed = false; return true; @@ -335,12 +339,11 @@ int &line = linenumbers.front(); line++; } - //uc = (u_char)tolower((char)uc); return true; } -bool TOKEN::include(char *fn) { +bool TOKEN::include(const char *fn) { string_set::iterator i = filenamess.find(fn); if (i != filenamess.end()) { token_error("redundant or recursive include file detected"); @@ -364,15 +367,15 @@ } -char *TOKEN::next() { +const char *TOKEN::next() { if (!pending_tokens.empty()) { - char *t = pending_tokens.front(); + const char *t = pending_tokens.front(); pending_tokens.pop_front(); return t; } if (streams.empty()) return NULL; const int PENDING_LIMIT = 1000; - static u_char buffer[PENDING_LIMIT]; + u_char buffer[PENDING_LIMIT]; int count = 0; state st = s_init; while (true) { @@ -438,7 +441,7 @@ default: { token_error(); - token_error("unknown state %d %s \n", st, " "); + token_error("unknown state %d %s", st, " "); } break; } if (st == s_init) break; @@ -446,10 +449,10 @@ buffer[count] = '\0'; if (count == 0) return NULL; - char *t = register_string((char*)buffer); + const char *t = register_string((char*)buffer); if (t == token_include) { - char *f = next(); // should be file name - char *s = next(); // should be semicolon + const char *f = next(); // should be file name + const char *s = next(); // should be semicolon if (s == token_semi) { include(f); return next(); @@ -465,7 +468,7 @@ int TOKEN::nextint() { - char *t = next(); + const char *t = next(); char *e; long i = strtol(t, &e, 10); if (*e != '\0') { @@ -517,10 +520,10 @@ void TOKEN::token_error() { token_error("syntax error at line %d in file %s -- ", cur_line(), cur_fn()); line_list::iterator j = linenumbers.begin(); - string_list::iterator i = filenames.begin(); + string_list::const_iterator i = filenames.begin(); for (; i!=filenames.end(); i++,j++) { if (i != filenames.begin()) { - char *fn = (*i); + const char *fn = (*i); int li = (*j); token_error(" included from line %d in file %s -- ", li, fn); }