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 ************
************************************/
--- /dev/null
--- /dev/null
++/*
++** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
++ * Copyright (C) 2002-2013 Sourcefire, Inc.
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License Version 2 as
++ * published by the Free Software Foundation. You may not use, modify or
++ * distribute this program under any other version of the GNU General
++ * Public License.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
++ */
++// rule_urilen.cc author Josh Rosenbaum <jorosenba@cisco.com>
++
++#include <sstream>
++#include <vector>
++
++#include "conversion_state.h"
++#include "util/converter.h"
++#include "rule_states/rule_api.h"
++#include "util/util.h"
++
++namespace rules
++{
++
++namespace {
++
++
++class Urilen : public ConversionState
++{
++public:
++ Urilen(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
++ virtual ~Urilen() {};
++ virtual bool convert(std::istringstream& data);
++};
++
++} // namespace
++
++bool Urilen::convert(std::istringstream& data_stream)
++{
++ std::string args;
++ std::string value;
++ bool retval = true;
++
++ args = util::get_rule_option_args(data_stream);
++ std::istringstream arg_stream(args);
++
++ // if there are no arguments, the option had a colon before a semicolon.
++ // we are therefore done with this rule.
++ if (util::get_string(arg_stream, value, ","))
++ {
++ retval = ld->add_rule_option("urilen", value);
++ ld->select_option("urilen");
++
++ if (util::get_string(arg_stream, value, ","))
++ {
++ bool tmpval = true;
++
++ if (!value.compare("raw"))
++ tmpval = ld->add_rule_option_before_selected("http_raw_uri");
++
++ else if (!value.compare("norm"))
++ tmpval = ld->add_rule_option_before_selected("http_uri");
++
++ else
++ ld->bad_rule("invalid arguments: " + args, data_stream);
++
++ if (retval && !tmpval)
++ retval = false;
++ }
++ }
++ else
++ {
++ ld->bad_rule("urilen: option required", data_stream);
++ }
++
++ ld->unselect_option();
++ return set_next_rule_state(data_stream) && retval;
++}
++
++/**************************
++ ******* A P I ***********
++ **************************/
++
++
++static ConversionState* ctor(Converter* cv, LuaData* ld)
++{
++ return new Urilen(cv, ld);
++}
++
++static const std::string urilen = "urilen";
++static const ConvertMap rule_urilen =
++{
++ "urilen",
++ ctor,
++};
++
++const ConvertMap* urilen_map = &rule_urilen;
++
++} // namespace rules
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