add_library( config_states
+ config_alertfile.cc
config_binding.cc
config_checksums.cc
config_classification.cc
noinst_LIBRARIES = libconfig_states.a
libconfig_states_a_SOURCES = \
+config_alertfile.cc \
config_binding.cc \
config_checksums.cc \
config_classification.cc \
}
// get length (stringstream will not read spaces...which we want)
- const std::streamoff pos = stream.tellg();
- stream.seekg(0, stream.end);
- const std::streamoff length = stream.tellg() - pos;
- stream.seekg(pos);
+ std::string arg_s = util::get_remain_data(stream);
- // read argument
- char *arg_c = new char[length + 1];
- stream.read(arg_c, length);
- arg_c[length] = '\0';
- std::string arg_s(arg_c);
- delete[] arg_c;
- util::trim(arg_s);
+ if (arg_s.empty())
+ {
+ data_api.failed_conversion(stream, "<missing_argument>");
+ return false;
+ }
- bool retval;
table_api.open_table(*lua_table);
if((lua_option != nullptr) && snort_option->compare(*lua_option))
{
table_api.add_diff_option_comment("config " + *snort_option +
":", *lua_option);
- retval = table_api.add_option(*lua_option, arg_s);
+ table_api.add_option(*lua_option, arg_s);
}
else
{
- retval = table_api.add_option(*snort_option, arg_s);
+ table_api.add_option(*snort_option, arg_s);
}
table_api.close_table();
- return retval;
+ stream.setstate(std::ios::eofbit); // done parsing this line
+ return true;
}
private:
static const std::string output = "output";
-
-/*************************************************
- ****************** alert_file *****************
- *************************************************/
-
-static const std::string alertfile = "alertfile";
-static const std::string alert_file = "alert_file";
-static const ConvertMap alertfile_api =
-{
- alertfile,
- config_string_ctor<&alertfile, &alerts, &alert_file>,
-};
-
-const ConvertMap* alertfile_map = &alertfile_api;
-
/*************************************************
******************* bpf_file ******************
*************************************************/
if (!(arg_stream >> keyword))
tmpval = false;
+ else if (!keyword.compare("filename"))
+ {
+ table_api.add_deleted_comment("profile_*: filename ...");
+ }
+
else if (!keyword.compare("print"))
{
table_api.add_diff_option_comment("print", "count");
tmpval = table_api.add_option("sort", val);
}
- else if (!keyword.compare("filename"))
- {
- table_api.open_table("file");
- tmpval = parse_string_option("name", arg_stream);
-
- std::string append;
- if ((arg_stream >> append) &&
- (!append.compare("append")))
- {
- if (!table_api.add_option("append", true))
- tmpval = false;
- }
-
- table_api.close_table();
- }
-
else
{
tmpval = false;
}
- if (retval && !tmpval)
+ if (!tmpval)
+ {
+ data_api.failed_conversion(data_stream, keyword);
retval = false;
+ }
}
table_api.close_table();
Option(std::string name, std::string val, int depth);
virtual ~Option();
- inline std::string get_name(){ return name; };
+ inline std::string get_name()
+ { return name; };
// overloading operators
friend std::ostream &operator<<( std::ostream&, const Option &);
return var->add_value(next_elem);
}
+bool Table::has_option(const std::string opt_name)
+{
+ for (Option* o : options)
+ if (!opt_name.compare(o->get_name()))
+ return true;
+
+ return false;
+}
+
+
bool Table::has_option(Option opt)
{
for (Option* o : options)
bool add_option(std::string, std::string val);
bool add_list(std::string, std::string next_elem);
void add_comment(std::string comment);
+ bool has_option(const std::string);
friend std::ostream &operator<<( std::ostream&, const Table &);
return true;
}
+bool TableApi::option_exists(const std::string name)
+{
+ if (open_tables.size() == 0)
+ {
+ data_api.developer_error("Must open table before calling option_exists() !!");
+ return false;
+ }
+
+ return open_tables.top()->has_option(name);
+}
+
bool TableApi::add_diff_option_comment(std::string orig_var, std::string new_var)
{
std::string error_string = "option change: '" + orig_var + "' --> '"
bool empty()
{ return (tables.size() == 0); }
+
+/*
+ * Accessing and choosing specific tables.
+ */
+
// open a table at the topmost layer. i.e., the table will not be nested inside any other table.
void open_top_level_table(std::string name);
// open a nested named table --> 'name = {...}')
// close the nested table. go to previous table level
void close_table();
-// ADDING DATA AND FIELDS TO CURRENT TABLE
void swap_tables(std::vector<Table*>& new_tables);
+
+/*
+ * Adding/accessing data to the specific table chosen above!!
+ * These methods will all throw a developer warning if called without
+ * selecting a table!
+ */
+
// add an string, bool, or int option to the table. --> table = { name = var |'var'};
bool add_option(const std::string name, const std::string val);
bool add_option(const std::string name, const int val);
bool add_unsupported_comment(std::string unsupported_var);
+// return true if this name exists as an option name for the selected table
+bool option_exists(const std::string name);
+
private:
std::vector<Table*> tables;
}
}
+
+std::string get_remain_data(std::istringstream& stream)
+{
+ // get string length
+ const std::streamoff pos = stream.tellg();
+ stream.seekg(0, stream.end);
+ const std::streamoff length = stream.tellg() - pos;
+ stream.seekg(pos);
+
+ // read argument
+ char *arg_c = new char[length + 1];
+ stream.read(arg_c, length);
+ arg_c[length] = '\0';
+ std::string arg_s(arg_c);
+ delete[] arg_c;
+ util::trim(arg_s);
+ return arg_s;
+}
+
+
std::string get_rule_option_args(std::istringstream& stream)
{
std::string args = std::string();
bool file_exists(const std::string& name);
-/* Takes in a stream and a string of delimeters. The function will extract the charachters
+/*
+ * Takes in a stream and a string of delimeters. The function will extract the charachters
* from the stream until it hits one of the delimeters. The substring will be set to the
* third parameter. The stream itself will point to the chrachter after the first delim.
*
std::string& option,
const std::string delimeters);
+/*
+ * Returns the rest of the data_streams data as one argument.
+ * Usefule when parsing filenames with spaces or other
+ * characters which can get removed by c++ libraries
+ *
+ * NO SIDE EFFECTS
+ */
+std::string get_remain_data(std::istringstream& data_stream);
std::string get_rule_option_args(std::istringstream& data_stream);