inline bool set_next_rule_state(std::istringstream& stream)
{
std::string keyword;
-
int pos = stream.tellg();
- std::getline(stream, keyword, ':');
- util::trim(keyword);
-
- if (keyword.empty())
- return true;
- // std::getline(stream, keyword, ':');
- // if (keyword.find_first_not_of(' ') == std::string::npos)
- // return true;
-
- do
+ while(std::getline(stream, keyword, ':'))
{
- util::trim(keyword);
- int semi_colon_pos = keyword.find(';');
+ std::size_t semi_colon_pos = keyword.find(';');
if (semi_colon_pos != std::string::npos)
{
- // found a nested option without a colon
- // 2 == last charachter of option + semi_colon
- stream.seekg(pos + semi_colon_pos +2);
+ // found an option without a colon, so set stream
+ // to semi-colon
+ std::streamoff off = 1 + (std::streamoff)(pos) +
+ (std::streamoff)(semi_colon_pos);
+ stream.seekg(off);
keyword = keyword.substr(0, semi_colon_pos);
}
if (str.size() == 0)
out << "\n";
- util::sanitize_multi_line_string(util::ltrim(str));
+ else if (c.type == Comments::CommentType::MULTI_LINE)
++ util::sanitize_lua_string(util::ltrim(str));
+
while(!str.empty())
{
- int substr_len = max_line_length;
+ std::size_t substr_len = max_line_length;
// determine the first space before 80 charachters
// if there are no spaces, print the entire string
#include "data/dt_rule.h"
+#include "data/dt_data.h" // included for print mode
++#include "util/util.h"
Rule::Rule() : num_hdr_data(0),
else
out << " ";
-- out << rule.hdr_data[i];
++ std::string tmp = rule.hdr_data[i];
++ out << util::sanitize_lua_string(tmp);
}
- out << " (";
- first_line = true;
-
- for (auto* r : rule.options)
+ if (!rule.options.empty())
{
- if (first_line)
- first_line = false;
- else
- out << ";";
- out << " " << (*r);
- }
+ out << " (";
+ first_line = true;
- out << " )";
+ for (auto* r : rule.options)
+ {
+ if (first_line)
+ first_line = false;
+ else
+ out << ";";
+ out << " " << (*r);
+ }
+ out << " )";
+ }
return out;
}
print_newline(out, count, whitespace);
-- util::sanitize_multi_line_string(v->data);
++ util::sanitize_lua_string(v->data);
out << "[[ ";
count += 3;
rule_metadata.cc
rule_pcre.cc
rule_unchanged.cc
++ rule_urilen.cc
rule_api.cc
rule_api.h
)
const ConvertMap* threshold_map = &rule_threshold;
--/************************************
-- ************* URILEN *************
-- ************************************/
--
--static const std::string urilen = "urilen";
--static const ConvertMap rule_urilen =
--{
-- urilen,
-- unchanged_rule_ctor<&urilen>,
--};
--
--const ConvertMap* urilen_map = &rule_urilen;
-
-
-/************************************
- *********** FILE_DATA ************
- ************************************/
-
-static const std::string file_data = "file_data";
-static const ConvertMap rule_file_data =
-{
- file_data,
- unchanged_rule_ctor<&file_data, false>,
-};
-
-const ConvertMap* file_data_map = &rule_file_data;
--
/************************************
*********** BYTE_TEST ************
************************************/
return nullptr;
}
--std::string &sanitize_multi_line_string(std::string &s)
++std::string &sanitize_lua_string(std::string &s)
{
- int found = s.find("]]");
+ std::size_t found = s.find("]]");
while (found != std::string::npos)
{
s.insert(found + 1, " ");
return ltrim(rtrim(s));
}
+
+// return true if this file exists. False otherwise.
+bool file_exists (const std::string& name);
+
+/* 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.
+ *
+ * PARAMS:
+ * data_stream - the data stream from which to find a substring.
+ * delimeters - The string of delimeters.
+ * options - The found substring will be place in this parameter. If the
+ * stream is empty or no charachters have been extracted, then
+ * this parameter wil be set to an empty string.
+ * RETURNS:
+ * True - when the string is found.
+ * False - whenma substing was unable to be extracted.
+ */
+bool get_string(std::istringstream& data_stream, std::string& option, std::string delimeters);
+
+
std::string get_rule_option_args(std::istringstream& data_stream);
-// remove any ']]' from this string.
-std::string &sanitize_multi_line_string(std::string &s);
+
+// remove any ']]' and double spaces from this string.
- std::string &sanitize_multi_line_string(std::string &s);
++std::string &sanitize_lua_string(std::string &s);
+
// find the location of the first space before max_str_lenght.
// if no space exists before max_str_length, return the first space
// after max_length. Otherwise, return std::string::npos