]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
http_inspect: global complete!!
authorJosh <jrosenba@cisco.com>
Wed, 11 Jun 2014 20:15:47 +0000 (16:15 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 11 Jun 2014 20:16:16 +0000 (16:16 -0400)
18 files changed:
tools/snort2lua/conversion_state.h
tools/snort2lua/converter.cc
tools/snort2lua/converter.h
tools/snort2lua/data/conv_data.cc
tools/snort2lua/data/conv_data.h
tools/snort2lua/data/conv_option.cc
tools/snort2lua/data/conv_table.cc
tools/snort2lua/data/conv_table.h
tools/snort2lua/init_state.cc
tools/snort2lua/init_state.h
tools/snort2lua/keywords/config.cc
tools/snort2lua/keywords/include.cc
tools/snort2lua/keywords/output.cc
tools/snort2lua/keywords/preprocessor.cc
tools/snort2lua/keywords/suppress.cc
tools/snort2lua/keywords/var.cc
tools/snort2lua/preprocessor/http_inspect.cc
tools/snort2lua/snort2lua.cc

index d93d3812b781fefaa9640638dfc803cbdac12daa..726a0ffaf3a69ce6b909fb51277fa1bde8c0ac77 100644 (file)
@@ -33,8 +33,7 @@ class ConversionState
 public:
     ConversionState(Converter *cv){ converter = cv; }
     virtual ~ConversionState() {};
-    virtual bool convert(std::stringstream& data,
-                            std::ofstream& out)=0;
+    virtual bool convert(std::stringstream& data)=0;
 
 
 protected:
index 04dcde008489f739184a2bdd298168c5e8cdd3f6..ad0f5d563b34bedb11bff7fdbfb6b689eff76a9b 100644 (file)
@@ -55,22 +55,22 @@ void Converter::reset_state()
 }
 
 
-bool Converter::convert_line(std::stringstream& data, std::ofstream& out)
+bool Converter::convert_line(std::stringstream& data)
 {
     if ( state )
-        return state->convert(data, out);
+        return state->convert(data);
     return false;
 }
 
-bool Converter::open_table(std::string name)
+bool Converter::open_table(std::string table_name)
 {
     Table *t;
 
     // if no open tables, create a top-level table
     if (open_tables.size() > 0)
-        t = open_tables.top()->open_table(name);
+        t = open_tables.top()->open_table(table_name);
     else
-        t = data.add_table(name);
+        t = data.add_table(table_name);
 
     open_tables.push(t);
     return true;
@@ -83,13 +83,13 @@ bool Converter::close_table()
 }
 
 
-bool Converter::add_option_to_table(std::string name, std::string val)
+bool Converter::add_option_to_table(std::string option_name, std::string val)
 {
     Table *t = open_tables.top();
 
     if(t)
     {
-        t->add_option(name, val);
+        t->add_option(option_name, val);
         return true;
     }
     else
@@ -100,13 +100,13 @@ bool Converter::add_option_to_table(std::string name, std::string val)
 }
 
 
-bool Converter::add_option_to_table(std::string name, int val)
+bool Converter::add_option_to_table(std::string option_name, int val)
 {
     Table *t = open_tables.top();
 
     if(t)
     {
-        t->add_option(name, val);
+        t->add_option(option_name, val);
         return true;
     }
     else
@@ -116,13 +116,13 @@ bool Converter::add_option_to_table(std::string name, int val)
     }
 }
 
-bool Converter::add_option_to_table(std::string name, bool val)
+bool Converter::add_option_to_table(std::string option_name, bool val)
 {
     Table *t = open_tables.top();
 
     if(t)
     {
-        t->add_option(name, val);
+        t->add_option(option_name, val);
         return true;
     }
     else
@@ -132,6 +132,28 @@ bool Converter::add_option_to_table(std::string name, bool val)
     }
 }
 
+void Converter::add_comment_to_table(std::string error_string)
+{
+    if (open_tables.size() > 0)
+        open_tables.top()->add_comment(error_string);
+    else
+        log_error(error_string);
+}
+
+void Converter::add_comment_to_file(std::string comment)
+{
+    data.add_comment(comment);
+}
+
+void Converter::add_comment_to_file(std::string comment, std::stringstream& stream)
+{
+    int pos = stream.tellg();
+    std::ostringstream oss;
+    oss << stream.rdbuf();
+    comment += oss.str();
+    data.add_comment(comment);
+    stream.seekg(pos);
+}
 
 /*******************************
  *******  PRINTING FOO *********
@@ -139,8 +161,9 @@ bool Converter::add_option_to_table(std::string name, bool val)
 
 void Converter::log_error(std::string error_string)
 {
-    std::cout << "ERROR: Failed to convert:\t" << std::endl;
-    std::cout << "\t\t" << error_string << std::endl << std::endl;
+    data.add_error_comment(error_string);
+//    std::cout << "ERROR: Failed to convert:\t" << std::endl;
+//    std::cout << "\t\t" << error_string << std::endl << std::endl;
 }
 
 void Converter::print_line(std::stringstream& in)
index cf6ae5adfc3e78ee1dc044f67b0a705ea1dd327a..2570ae78bb1a2333278e1d06a01cddecc7b6226a 100644 (file)
@@ -39,7 +39,7 @@ public:
     Converter();
     virtual ~Converter() {};
     void reset_state();
-    bool convert_line(std::stringstream& data, std::ofstream& out);
+    bool convert_line(std::stringstream& data);
     void set_state(ConversionState* c);
     
     bool inline add_variable(std::string name, std::string v){ return data.add_variable(name, v); };
@@ -50,7 +50,10 @@ public:
     bool add_option_to_table(std::string name, std::string val);
     bool add_option_to_table(std::string name, int val);
     bool add_option_to_table(std::string name, bool val);
+    void add_comment_to_table(std::string comment);
 
+    void add_comment_to_file(std::string comment);
+    void add_comment_to_file(std::string comment, std::stringstream& stream);
     void log_error(std::string);
 
     void print_line(std::stringstream& in);
index 51d98670863f3014344e2a05de6b66a3cb2a657d..252ed9f96c50cac6201ff07f0639bc7bbd93932b 100644 (file)
@@ -51,17 +51,6 @@ ConversionData::~ConversionData()
         delete t;
 }
 
-std::ostream& operator<<( std::ostream &out, const ConversionData &data)
-{
-    for (Variable *v : data.vars)
-        out << (*v) << std::endl << std::endl;
-
-    for (Table *t : data.tables)
-        out << (*t) << std::endl << std::endl;
-
-    return out;
-}
-
 bool ConversionData::add_variable(std::string name, std::string value)
 {
     for (auto v : vars)
@@ -77,7 +66,6 @@ bool ConversionData::add_variable(std::string name, std::string value)
     return var->add_value(value);
 }
 
-
 Table* ConversionData::add_table(std::string name)
 {
     Table* t = find_table(tables, name);
@@ -90,6 +78,49 @@ Table* ConversionData::add_table(std::string name)
     return t;
 }
 
+void ConversionData::add_comment(std::string str)
+{
+    // leave at most one blank line between comments
+    if ( !(str.empty() && !comments.empty() && comments.back().empty()) )
+        comments.push_back(std::string(str, 0, 77) + "...");
+}
+
+void ConversionData::add_error_comment(std::string error_string)
+{
+    errors.push_back(std::string(error_string, 0, 77) + "...");
+}
+
+std::ostream& operator<<( std::ostream &out, const ConversionData &data)
+{
+    out << "--[[" << std::endl;
+    out << "--ERRORS:" << std::endl;
+    out << "    all of these occured during the attempted conversion:" << std::endl << std::endl;
+
+    for (std::string s : data.errors)
+        out << s << std::endl << std::endl;
+
+    out << "--]]" << std::endl << std::endl << std::endl;
+
+    for (Variable *v : data.vars)
+        out << (*v) << std::endl << std::endl;
+
+    for (Table *t : data.tables)
+        out << (*t) << std::endl << std::endl;
+
+
+    out << "--[[" << std::endl << std::endl;
+    out << "COMMENTS:" << std::endl;
+    out << "    these line were originally commented out or empty" << std::endl;
+    out << "    in the configuration file." << std::endl;
+    out << std::endl;
+
+    for (std::string s : data.comments)
+        out << s << std::endl;
+
+    out << "--]]" << std::endl;
+
+    return out;
+}
 #if 0
 bool ConversionData::add_option(std::string name, std::string value)
 {
index ea9be3a2fa8763fbab16aa2963eaef665c94b03f..6c220d673afdacd5592980574c41296a3d82da77 100644 (file)
@@ -39,6 +39,8 @@ public:
     friend std::ostream &operator<<( std::ostream&, const ConversionData &);
     bool add_variable(std::string name, std::string value);
     Table* add_table(std::string name);
+    void add_comment(std::string comment);
+    void add_error_comment(std::string comment);
 
 #if 0
     bool add_option(std::string name, std::string value);
@@ -49,6 +51,8 @@ public:
 private:
     std::vector<Variable*> vars;
     std::vector<Table*> tables;
+    std::vector<std::string> comments;
+    std::vector<std::string> errors;
 
 };
 
index 16ab05fc39e98ea6c7045628e017ef4e04adaf2d..7310ac7e612ce936c20a486f496811064a61a3de 100644 (file)
@@ -62,10 +62,10 @@ std::ostream &operator<<( std::ostream& out, const Option &o)
     switch(o.type)
     {
         case Option::OptionType::STRING:
-        case Option::OptionType::BOOL:
             out << '\'' << o.value << "',";
             break;
 
+        case Option::OptionType::BOOL:
         case Option::OptionType::INT:
             out << o.value << ',';
             break;
index 74a5e3a5ec5caa92bcad5bfe8c9c1a2c50fca060..36e30ba785e5fa6e47ac87edaceb2604ccd817cd 100644 (file)
@@ -24,7 +24,7 @@
 static inline Table* find_table(std::vector<Table*> vec, std::string name)
 {
     for( auto *t : vec)
-        if(name.compare(t->get_name()))
+        if(!name.compare(t->get_name()))
             return t;
 
     return nullptr;
@@ -111,6 +111,12 @@ bool Table::has_option(std::string name, std::string val)
     return false;
 }
 
+
+void Table::add_comment(std::string comment)
+{
+    comments.push_back(std::string(comment, 0, 77) + "...");
+}
+
 std::ostream &operator<<( std::ostream& out, const Table &t)
 {
     std::string whitespace = "";
@@ -121,6 +127,9 @@ std::ostream &operator<<( std::ostream& out, const Table &t)
     out << whitespace << t.name << " = " << std::endl;
     out << whitespace << '{' << std::endl;
 
+    for(std::string s : t.comments)
+        out << whitespace << "    --" << s << std::endl;
+
     for (Option* o : t.options)
         out << (*o) << std::endl;
 
index 33c2cda1ae56fbeca848572e70c11415d37273e0..2d7b656644b169dee2107f4e2fc7cb6a9f232e3e 100644 (file)
@@ -44,6 +44,7 @@ public:
     bool has_option(std::string name, int val);
     bool has_option(std::string name, bool val);
     bool has_option(std::string name, std::string val);
+    void add_comment(std::string comment);
 
     friend std::ostream &operator<<( std::ostream&, const Table &);
 
@@ -52,6 +53,7 @@ private:
     int depth;
     std::vector<Table*> tables;
     std::vector<Option*> options;
+    std::vector<std::string> comments;
 };
 
 #endif
index 4c570d2936a174ca06758f6b5ad3abfca3673309..b5e05b72889215c199207ad03d207aa880ace3a1 100644 (file)
@@ -30,7 +30,7 @@
 
 InitState::InitState(Converter* cv) : ConversionState(cv) {}
 
-bool InitState::convert(std::stringstream& data_stream, std::ofstream& out)
+bool InitState::convert(std::stringstream& data_stream)
 {
     std::string keyword;
 
@@ -41,9 +41,10 @@ bool InitState::convert(std::stringstream& data_stream, std::ofstream& out)
         if( keyword.front() == '#')
         {
             keyword.erase(keyword.begin());
-            std::ostringstream oss;
-            oss << data_stream.rdbuf();
-            out << "--" << keyword << oss.str() << std::endl;
+//            std::ostringstream oss;
+//            oss << data_stream.rdbuf();
+//            out << "--" << keyword << oss.str() << std::endl;
+            converter->add_comment_to_file(keyword, data_stream);
             data_stream.setstate(std::basic_ios<char>::eofbit);
             return true;
         }
@@ -59,7 +60,7 @@ bool InitState::convert(std::stringstream& data_stream, std::ofstream& out)
         }
     }
 
-    out << "--" << data_stream.str() << std::endl;
-    data_stream.setstate(std::basic_ios<char>::eofbit);
+//    out << "--" << data_stream.str() << std::endl;
+//    data_stream.setstate(std::basic_ios<char>::eofbit);
     return false;
 }
index 0050ef2474838ea5822cf84926b5975cccb320aa..245c7d800568b6e82386d18dbcd87350805b9757 100644 (file)
@@ -32,7 +32,7 @@ class InitState : public ConversionState
 public:
     InitState(Converter* cv);
     virtual ~InitState() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 
 };
 
index a8f1faec161f8dfaaa9877fde8177592a7573d59..8dcebf937458cfe547907b9cbd04c994ff84dcb7 100644 (file)
@@ -37,13 +37,13 @@ class Config : public ConversionState
 public:
     Config(Converter* cv)  : ConversionState(cv) {};
     virtual ~Config() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 };
 
 } // namespace
 
 
-bool Config::convert(std::stringstream& data_stream, std::ofstream&)
+bool Config::convert(std::stringstream& data_stream)
 {
 #if 0
     std::string keyword;
index b277c847923cff9295b1219741cb5419c66dcb7d..19eb2e82f11d2089998c9f83907167a3d637b565 100644 (file)
@@ -35,13 +35,13 @@ class Include : public ConversionState
 public:
     Include(Converter* cv)  : ConversionState(cv) {};
     virtual ~Include() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 };
 
 } // namespace
 
 
-bool Include::convert(std::stringstream& data_stream, std::ofstream&)
+bool Include::convert(std::stringstream& data_stream)
 {
 #if 0
     std::string keyword;
index 96781624a1fdf228491cf81634a8ad21a27cc62c..af672d524415142945019c9328f9a3b890e4ce00 100644 (file)
@@ -36,13 +36,13 @@ class Output : public ConversionState
 public:
     Output(Converter* cv)  : ConversionState(cv) {};
     virtual ~Output() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 };
 
 } // namespace
 
 
-bool Output::convert(std::stringstream& data_stream, std::ofstream&)
+bool Output::convert(std::stringstream& data_stream)
 {
     std::string keyword;
 
index 90a200b731e2d235b77dd844fb938e6096828e91..beba4739611f55afd7cb6516b047379dc65708e7 100644 (file)
@@ -35,13 +35,13 @@ class Preprocessor : public ConversionState
 public:
     Preprocessor(Converter* cv)  : ConversionState(cv) {};
     virtual ~Preprocessor() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 };
 
 } // namespace
 
 
-bool Preprocessor::convert(std::stringstream& data_stream, std::ofstream&)
+bool Preprocessor::convert(std::stringstream& data_stream)
 {
     std::string keyword;
 
index 80d16febcc8725f61254c38fb249651f2d5e7e2c..acaee91a40a75a897ba5b8492017c35f8fede932 100644 (file)
@@ -34,13 +34,13 @@ class Suppress : public ConversionState
 public:
     Suppress(Converter* cv)  : ConversionState(cv) {};
     virtual ~Suppress() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 };
 
 } // namespace
 
 
-bool Suppress::convert(std::stringstream& data_stream, std::ofstream&)
+bool Suppress::convert(std::stringstream& data_stream)
 {
 #if 0
     std::string keyword;
index 6cc625a29112356da8c132de626e0dfaaca88299..a797f9eed2507842f75ec0b8cba30e997b44749a 100644 (file)
@@ -35,7 +35,7 @@ class Var : public ConversionState
 public:
     Var(Converter* cv);
     virtual ~Var() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 
 private:
     bool first_line;
@@ -52,7 +52,7 @@ Var::Var(Converter* cv) : ConversionState(cv)
     is_port_list = false;
 }
 
-bool Var::convert(std::stringstream& data_stream, std::ofstream& out)
+bool Var::convert(std::stringstream& data_stream)
 {
     std::string ports;//    converter->print_line(data_stream);
 
index 7b5d090b68e8e6cfedd69579f54de8dad117ceaf..e91c5523c754d31acbb1264eb2922c869ffdd477 100644 (file)
@@ -35,9 +35,12 @@ class HttpInspect : public ConversionState
 public:
     HttpInspect(Converter* cv);
     virtual ~HttpInspect() {};
-    virtual bool convert(std::stringstream& data, std::ofstream&);
+    virtual bool convert(std::stringstream& data);
 
 private:
+    void add_decode_option(std::string opt_name, int val);
+    bool missing_arg_error(std::string error_string);
+
     bool first_line;
     bool correct_keyword;
 };
@@ -45,30 +48,32 @@ private:
 } // namespace
 
 
-HttpInspect::HttpInspect(Converter* cv)  : ConversionState(cv)
+bool HttpInspect::missing_arg_error(std::string arg)
 {
-    first_line = true;
+    converter->add_comment_to_table("snort.conf missing argument for " + arg);
+    return false;
 }
 
-bool HttpInspect::convert(std::stringstream& data_stream, std::ofstream&)
+HttpInspect::HttpInspect(Converter* cv)  : ConversionState(cv)
+{}
+
+bool HttpInspect::convert(std::stringstream& data_stream)
 {
     std::string keyword;
-    std::string value;
+    std::string s_value;
+    int i_value;
+
     bool retval = true;;
 
-    if (first_line)
+    if(data_stream >> keyword)
     {
-        if(data_stream >> keyword)
+        if(keyword.compare("global"))
         {
-            if(keyword.compare("global"))
-            {
-                converter->log_error("preprocessor httpinspect: requires the 'global' keyword");
-                return false;
-            }
+            converter->log_error("preprocessor httpinspect: requires the 'global' keyword");
+            return false;
         }
-        first_line = false;
-        converter->open_table("http_inspect");
     }
+    converter->open_table("http_inspect");
 
 
 
@@ -76,121 +81,110 @@ bool HttpInspect::convert(std::stringstream& data_stream, std::ofstream&)
     {
         if(!keyword.compare("compress_depth"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("compress_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                converter->add_option_to_table("compress_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global compress_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("compress_depth <int>");
         }
+        
         else if(!keyword.compare("decompress_depth")) 
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("decompress_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                converter->add_option_to_table("decompress_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global compress_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("decompress_depth <int>");
         }
-        else if(!keyword.compare("detect_anomalous_servers")) {}
+
+        else if(!keyword.compare("detect_anomalous_servers"))
+        {
+            converter->add_option_to_table("detect_anomalous_servers", true);
+        }
+
         else if(!keyword.compare("iis_unicode_map"))
         {
             std::string codemap;
-            if( (data_stream >> value) &&
-                (data_stream >> codemap))
+            if( (data_stream >> s_value) &&
+                (data_stream >> i_value))
             {
-                int code_map_i = std::stoi(codemap, nullptr);
                 converter->open_table("unicode_map");
-                converter->add_option_to_table("map_file", value);
-                converter->add_option_to_table("code_page", code_map_i);
+                converter->add_option_to_table("map_file", s_value);
+                converter->add_option_to_table("code_page", i_value);
                 converter->close_table();
             }
             else
             {
-                converter->log_error("Invalid argument: 'preprocessor http_inspect: global .. unicode_map");
-                retval = false;
+                retval = missing_arg_error("iis_unicode_map <filename> <codemap>");
             }
         }
-        else if(!keyword.compare("proxy_alert")) {}
-        else if(!keyword.compare("max_gzip_mem")) {}
-        else if(!keyword.compare("memcap")) {}
-        else if(!keyword.compare("disabled")) {}
+        else if(!keyword.compare("proxy_alert"))
+        {
+            converter->add_option_to_table("proxy_alert", true);
+        }
+
+        else if(!keyword.compare("max_gzip_mem"))
+        {
+            if(data_stream >> i_value)
+                converter->add_option_to_table("max_gzip_mem", i_value);
+            else
+                retval = missing_arg_error("max_gzip_mem <int>");
+        }
+        
+        else if(!keyword.compare("memcap"))
+        {
+            if(data_stream >> i_value)
+                converter->add_option_to_table("memcap", i_value);
+            else
+                retval = missing_arg_error("memcap <int>");
+        }
+        
+        else if(!keyword.compare("disabled"))
+        {
+            converter->add_comment_to_table("the option 'disabled' is deprecated");
+        }
+        
         else if(!keyword.compare("b64_decode_depth"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("b64_decode_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                add_decode_option("b64_decode_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global b64_decode_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("b64_decode_depth <int>");
         }
+
         else if(!keyword.compare("bitenc_decode_depth"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("bitenc_decode_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                add_decode_option("bitenc_decode_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global b64_decode_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("b64_decode_depth <int>");
         }
         else if(!keyword.compare("max_mime_mem"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("max_mime_mem", c_depth);
-            }
+            if(data_stream >> i_value)
+                add_decode_option("max_mime_mem", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global b64_decode_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("max_mime_mem <int>");
         }
+
         else if(!keyword.compare("qp_decode_depth"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("qp_decode_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                add_decode_option("qp_decode_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global b64_decode_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("qp_decode_depth <int>");
         }
+
         else if(!keyword.compare("uu_decode_depth"))
         {
-            if(data_stream >> value)
-            {
-                int c_depth = std::stoi(value);
-                converter->add_option_to_table("uu_decode_depth", c_depth);
-            }
+            if(data_stream >> i_value)
+                add_decode_option("uu_decode_depth", i_value);
             else
-            {
-                converter->log_error("unable to find argument for 'preprocessor http_inspect: global b64_decode_depth");
-                retval = false;
-            }
+                retval = missing_arg_error("uu_decode_depth <int>");
         }
+
         else
         {
-            converter->log_error("unknown word");
+            converter->log_error("'preprocessor http_inspect: global' --> Invalid argument!!");
+            retval = false;
         }
     }
 
@@ -198,6 +192,13 @@ bool HttpInspect::convert(std::stringstream& data_stream, std::ofstream&)
 }
 
 
+void HttpInspect::add_decode_option(std::string opt_name, int val)
+{
+    converter->open_table("decode");
+    converter->add_option_to_table(opt_name, val);
+    converter->close_table();
+}
+
 /**************************
  *******  A P I ***********
  **************************/
index f0a6bae6a07328295d67aba9099c51a23d5c51b3..b02955e2fe61ee9c8456b5cc8efe080d15786db1 100644 (file)
 static bool convert(std::ifstream& in, std::ofstream& out)
 {
     Converter cv;
-    bool skip_line = false;
     cv.reset_state();
-//    state->inititalize();
-//    Converter::reset_state();
+    std::string orig_text;
 
     while(!in.eof())
     {
-        std::string next_line;
-        bool last_line = true;
+        std::string tmp;
+        std::getline(in, tmp);
+        util::ltrim(tmp);
+        orig_text += ' ' + tmp;
+        util::rtrim(orig_text);
 
-        std::getline(in, next_line);
-        util::trim(next_line);
-
-        if (next_line.empty())
+        if (orig_text.empty())
         {
-            out << std::endl;
+            cv.add_comment_to_file("");
         }
-        else if(!skip_line)
+        else
         {
-            if (next_line.back() == '\\')
+            if (orig_text.front() != '#' && orig_text.back() == '\\')
             {
-                last_line = false;
-                next_line.pop_back();
-                util::rtrim(next_line);
+                orig_text.pop_back();
+                util::rtrim(orig_text);
             }
-
-            std::stringstream data_stream(next_line);
-            while(data_stream.tellg() != -1)
+            else
             {
-                if (!cv.convert_line(data_stream, out))
+                std::stringstream data_stream(orig_text);
+                while(data_stream.tellg() != -1)
                 {
-                    cv.log_error(next_line);
-                    data_stream.setstate(std::basic_ios<char>::eofbit);
-                    skip_line = true;
+                    if (!cv.convert_line(data_stream))
+                    {
+                        cv.log_error("Failed to entirely convert: " + orig_text);
+//                        data_stream.setstate(std::basic_ios<char>::eofbit);
+                        break;
+                    }
                 }
-            }
-        }
 
-        if (last_line)
-        {
-            cv.reset_state();
-            skip_line = false;
+                orig_text.clear();
+                cv.reset_state();
+            }
         }
     }
 
@@ -80,6 +76,7 @@ static bool convert(std::ifstream& in, std::ofstream& out)
     return true;
 }
 
+
 static void show_usage()
 {
     std::cout << "usage:  snort2lua <input_conf_file> <output_lua_file" << std::endl;