// dt_data.cc author Josh Rosenbaum <jrosenba@cisco.com>
#include "dt_data.h"
-#include "helpers/s2l_util.h"
+
+#include <algorithm>
+#include <cstring>
#include <iostream>
#include <sstream>
-#include <cstring>
#include "data/data_types/dt_table.h"
#include "data/data_types/dt_var.h"
#include "data/data_types/dt_comment.h"
#include "data/data_types/dt_rule.h"
#include "data/data_types/dt_include.h"
+#include "helpers/s2l_util.h"
DataApi::PrintMode DataApi::mode = DataApi::PrintMode::DEFAULT;
std::size_t DataApi::dev_warnings = 0;
std::size_t DataApi::errors_count = 0;
-DataApi::DataApi() : curr_data_bad(false)
+DataApi::DataApi()
{
comments = new Comments(start_comments, 0,
Comments::CommentType::MULTI_LINE);
if (strlen(p) >= 2)
{
varmodifier = *(p + 1);
- std::strncpy(varaux, p + 2, sizeof(varaux));
+ std::strncpy(varaux, p + 2, sizeof(varaux) - 1);
}
}
else
- std::strncpy(varname, rawvarname, sizeof(varname));
+ std::strncpy(varname, rawvarname, sizeof(varname) - 1);
std::memset((char*)varbuffer, 0, sizeof(varbuffer));
{
vars.swap(new_vars);
includes.swap(new_includes);
-
- Comments* tmp = new_comments;
- new_comments = comments;
- comments = tmp;
-
- tmp = new_unsupported;
- new_unsupported = unsupported;
- unsupported = tmp;
+ std::swap(comments, new_comments);
+ std::swap(unsupported, new_unsupported);
}
Comments* errors;
Comments* unsupported;
- bool curr_data_bad; // keep track whether current 'conversion' is already bad
- const std::string* current_file;
- unsigned current_line;
+ bool curr_data_bad = false; // keep track whether current 'conversion' is already bad
+ const std::string* current_file = nullptr;
+ unsigned current_line = 0;
std::string get_file_line();
};
// same criteria used for rtrim
// http://en.cppreference.com/w/cpp/string/byte/isspace
std::size_t first_non_white_char = tmp.find_first_not_of(" \f\n\r\t\v");
+ std::size_t last_non_space = tmp.find_last_not_of(' ');
bool comment = (tmp[first_non_white_char] == '#') or (tmp[first_non_white_char] == ';');
bool commented_rule = tmp.substr(0, 7) == "# alert";
}
data_api.add_comment(tmp);
}
- else if ( tmp[tmp.find_last_not_of(' ')] == '\\')
+ else if ( (last_non_space != std::string::npos) and
+ (tmp[last_non_space] == '\\') )
{
util::rtrim(tmp);
tmp.pop_back();
}
++p;
}
+ std::cout << std::resetiosflags(std::ios::adjustfield);
}
} // namespace parser
bool convert(std::istringstream& data) override;
private:
- std::istringstream* stream; // so I can call ld->failed_conversion
+ std::istringstream* stream = nullptr; // so I can call ld->failed_conversion
std::unordered_map<std::string, std::string> attr_map;
std::ifstream attr_file;
else if (keyword == "profile")
parse_deleted_option("profile", data_stream);
else if ( keyword == "xff_headers" )
- parse_bracketed_unsupported_list("xff_headers", data_stream);
+ tmpval = parse_bracketed_unsupported_list("xff_headers", data_stream);
else
{
tmpval = false;
table_api.add_deleted_comment("logfile");
}
else if (keyword == "memcap")
- tmpval = parse_option("memcap", data_stream) && retval;
+ tmpval = parse_option("memcap", data_stream);
else if (keyword == "proto")
{
table_api.add_diff_option_comment("proto", "protos");
- retval = parse_curly_bracket_list("protos", data_stream) && retval;
+ tmpval = parse_curly_bracket_list("protos", data_stream);
}
else if (keyword == "scan_type")
{
table_api.add_diff_option_comment("scan_type", "scan_types");
- tmpval = parse_curly_bracket_list("scan_types", data_stream) && retval;
+ tmpval = parse_curly_bracket_list("scan_types", data_stream);
}
else
tmpval = false;
// since we still can't be sure if we passed the base64_decode buffer,
// check the next option and ensure it matches
std::istringstream arg_stream(args);
- util::get_string(arg_stream, tmp, ", ");
-
- if (tmp == "bytes" ||
+ if (util::get_string(arg_stream, tmp, ", ") &&
+ (tmp == "bytes" ||
tmp == "offset" ||
- tmp == "relative")
+ tmp == "relative"))
{
rule_api.add_option("base64_decode", args);
}
// since we still can't be sure if we passed the resp buffer,
// check the next option and ensure it matches
std::istringstream arg_stream(args);
- util::get_string(arg_stream, tmp, ",");
-
- if (tmp == "msg" ||
+ if (util::get_string(arg_stream, tmp, ",") &&
+ (tmp == "msg" ||
tmp == "warn" ||
tmp == "block" ||
- !tmp.compare(0, 5, "proxy"))
+ !tmp.compare(0, 5, "proxy")))
{
// Now that we have confirmed this is a valid option, parse it!!
table_api.open_table("react");
// since we still can't be sure if we passed the resp buffer,
// check the next option and ensure it matches
std::istringstream arg_stream(args);
- util::get_string(arg_stream, tmp, ",");
-
- if (tmp == "reset_dest" ||
+ if (util::get_string(arg_stream, tmp, ",") &&
+ (tmp == "reset_dest" ||
tmp == "reset_both" ||
tmp == "rst_snd" ||
tmp == "rst_rcv" ||
tmp == "icmp_host" ||
tmp == "icmp_all" ||
tmp == "reset_source" ||
- tmp == "icmp_port")
+ tmp == "icmp_port"))
{
// Now that we have confirmed this is a valid option, parse it!!
table_api.open_table("reject");