Mercurial > routeflapper
diff src/routeconfig.cpp @ 4:180d26aa2a17
Fedora 9 compile and const correctness.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 12 Jun 2008 17:51:33 -0700 |
parents | bb3f804f13a0 |
children |
line wrap: on
line diff
--- a/src/routeconfig.cpp Thu May 22 20:39:52 2008 -0700 +++ b/src/routeconfig.cpp Thu Jun 12 17:51:33 2008 -0700 @@ -20,21 +20,21 @@ #include <stdlib.h> #include <time.h> -char *token_announce; -char *token_file; -char *token_include; -char *token_index_ip; -char *token_index_length; -char *token_index_path; -char *token_index_value; -char *token_ip; -char *token_lbrace; -char *token_path; -char *token_rbrace; -char *token_reset; -char *token_semi; -char *token_slash; -char *token_withdraw; +const char *token_announce; +const char *token_file; +const char *token_include; +const char *token_index_ip; +const char *token_index_length; +const char *token_index_path; +const char *token_index_value; +const char *token_ip; +const char *token_lbrace; +const char *token_path; +const char *token_rbrace; +const char *token_reset; +const char *token_semi; +const char *token_slash; +const char *token_withdraw; const int training = 100; // need 100 hours uptime before using the statistics const float origin_threshold = 2.9; // a bit less than 1 + decay + decay^2 @@ -142,9 +142,9 @@ //////////////////////////////////////////////// // -char *suspicious_name(suspicion s) +const char *suspicious_name(suspicion s) { - char *ss = ""; + const char *ss = ""; switch (s) { case suspicious_none: ss = "none"; break; case suspicious_origin: ss = "origin"; break; @@ -191,7 +191,7 @@ ctime_r(&t, ctbuf); int ii = strlen(ctbuf); if (ii > 1) ctbuf[ii-1] = '\0'; // remove trailing newline - snprintf(buf, sizeof(buf), "*** smtp connection at %s from %s via prefix %s/%d being removed", ctbuf, adr, name(prefix_length).c_str(), prefix_length); + snprintf(buf, sizeof(buf), "*** smtp connection at %s from %s via prefix %s being removed", ctbuf, adr, name(prefix_length).c_str()); my_syslog(buf); } } @@ -480,7 +480,7 @@ if (!stable) return suspicious_none; suspicion rc = suspicious_none; route_prefix *r1 = NULL; - int pl; + int pl = 0; pthread_mutex_lock(&rib_mutex); for (int i=32; i>=0; i--) { route_prefixes &p = prefixes[i]; @@ -573,7 +573,7 @@ //////////////////////////////////////////////// // -ROUTECONFIG::ROUTECONFIG(TOKEN &tok, char *file_name_) { +ROUTECONFIG::ROUTECONFIG(TOKEN &tok, const char *file_name_) { tokp = &tok; file_name = file_name_; open(true); @@ -700,8 +700,8 @@ //////////////////////////////////////////////// // -int ip_address(char *have); -int ip_address(char *have) { +int ip_address(const char *have); +int ip_address(const char *have) { int ipaddr = 0; in_addr ip; if (inet_aton(have, &ip)) ipaddr = ip.s_addr; @@ -716,7 +716,7 @@ //////////////////////////////////////////////// // -PATTERN::PATTERN(TOKEN &tok, pattern_style style_, char *pattern_, int index1_, int index2_) +PATTERN::PATTERN(TOKEN &tok, pattern_style style_, const char *pattern_, int index1_, int index2_) { style = style_; pattern = pattern_; @@ -741,7 +741,7 @@ } -bool PATTERN::process(char *buf, CONFIG &con, char *file_name, int pattern_index) +bool PATTERN::process(char *buf, CONFIG &con, const char *file_name, int pattern_index) { if (pattern) { const int nmatch = max(index1, index2) + 1; @@ -811,7 +811,7 @@ } -void PATTERN::dump(int level, int index, char *token) +void PATTERN::dump(int level, int index, const char *token) { char indent[maxlen]; int i = min(maxlen-1, level*4); @@ -859,7 +859,7 @@ // void discard(string_set &s) { for (string_set::iterator i=s.begin(); i!=s.end(); i++) { - free(*i); + free((void*)*i); } s.clear(); } @@ -868,7 +868,7 @@ //////////////////////////////////////////////// // helper to register a string in a string set // -char* register_string(string_set &s, char *name) { +const char* register_string(string_set &s, const char *name) { string_set::iterator i = s.find(name); if (i != s.end()) return *i; char *x = strdup(name); @@ -880,7 +880,7 @@ //////////////////////////////////////////////// // register a global string // -char* register_string(char *name) { +const char* register_string(const char *name) { return register_string(all_strings, name); } @@ -903,9 +903,9 @@ //////////////////////////////////////////////// // -bool tsa(TOKEN &tok, char *token); -bool tsa(TOKEN &tok, char *token) { - char *have = tok.next(); +bool tsa(TOKEN &tok, const char *token); +bool tsa(TOKEN &tok, const char *token) { + const char *have = tok.next(); if (have == token) return true; tok.token_error(token, have); return false; @@ -914,13 +914,13 @@ //////////////////////////////////////////////// // -bool parse_path(TOKEN &tok, ROUTECONFIG &con, char *tokk, pattern_style style); -bool parse_path(TOKEN &tok, ROUTECONFIG &con, char *tokk, pattern_style style) { - char *pattern = tok.next(); +bool parse_path(TOKEN &tok, ROUTECONFIG &con, const char *tokk, pattern_style style); +bool parse_path(TOKEN &tok, ROUTECONFIG &con, const char *tokk, pattern_style style) { + const char *pattern = tok.next(); int index = 0; if (!tsa(tok, token_lbrace)) return false; while (true) { - char *have = tok.next(); + const char *have = tok.next(); if (!have) break; if (have == token_rbrace) break; if (have == tokk) { @@ -938,12 +938,12 @@ bool parse_announce_withdraw(TOKEN &tok, ROUTECONFIG &con, pattern_style style); bool parse_announce_withdraw(TOKEN &tok, ROUTECONFIG &con, pattern_style style) { - char *pattern = tok.next(); + const char *pattern = tok.next(); int index1 = 0; int index2 = 0; if (!tsa(tok, token_lbrace)) return false; while (true) { - char *have = tok.next(); + const char *have = tok.next(); if (!have) break; if (have == token_rbrace) break; if (have == token_index_value) { @@ -965,7 +965,7 @@ bool parse_routeconfig(TOKEN &tok, CONFIG &dc); bool parse_routeconfig(TOKEN &tok, CONFIG &dc) { - char *name = tok.next(); + const char *name = tok.next(); if (!tsa(tok, token_lbrace)) return false; ROUTECONFIGP con = new ROUTECONFIG(tok, name); if (con->failed()) { @@ -974,7 +974,7 @@ } dc.add_routeconfig(con); while (true) { - char *have = tok.next(); + const char *have = tok.next(); if (!have) break; if (have == token_rbrace) break; if (have == token_reset) { @@ -1005,11 +1005,11 @@ //////////////////////////////////////////////// // parse a config file // -bool load_conf(CONFIG &dc, char *fn) { +bool load_conf(CONFIG &dc, const char *fn) { int count = 0; TOKEN tok(fn, &dc.config_files); while (true) { - char *have = tok.next(); + const char *have = tok.next(); if (!have) break; if (have == token_file) { if (!parse_routeconfig(tok, dc)) return false;