]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge branch 'snort2lua'
authorJosh <jrosenba@cisco.com>
Thu, 3 Jul 2014 19:12:02 +0000 (15:12 -0400)
committerJosh <jrosenba@cisco.com>
Thu, 3 Jul 2014 19:13:43 +0000 (15:13 -0400)
1  2 
src/main/modules.cc
tools/snort2lua/snort2lua.cc

Simple merge
index c7279c041be695c294a8f2f6c6b5ce1dd55d9b79,d2feaacf7357319176c37c70e5d28cca229b1640..f7acede8a17541757d6551d40d880c997cd13b5e
  #include <iostream>
  #include <fstream>
  
- #include "converter.h"
+ #include "util/converter.h"
  #include "init_state.h"
- #include "snort2lua_util.h"
+ #include "util/util.h"
+ #include "option_parser.h"
  
- static bool convert(std::ifstream& in, std::ofstream& out)
+ /****************************************************
+  ************  OPTION INFORMATION   *****************
+  ****************************************************/
+ namespace
  {
-     Converter cv;
-     cv.reset_state();
-     std::string orig_text;
  
-     while(!in.eof())
-     {
-         std::string tmp;
-         std::getline(in, tmp);
-         util::ltrim(tmp);
-         orig_text += ' ' + tmp;
-         util::trim(orig_text);
+ struct Arg: public option::Arg
+ {
+   static void printError(const char* msg1, const option::Option& opt, const char* msg2)
+   {
+     fprintf(stderr, "%s", msg1);
+     fwrite(opt.name, opt.namelen, 1, stderr);
+     fprintf(stderr, "%s", msg2);
+   }
+   static option::ArgStatus Unknown(const option::Option& option, bool msg)
+   {
+     if (msg) printError("Unknown option '", option, "'\n");
+     return option::ARG_ILLEGAL;
+   }
+   static option::ArgStatus Required(const option::Option& option, bool msg)
+   {
+     if (option.arg != 0)
+       return option::ARG_OK;
+     if (msg) printError("Option '", option, "' requires an argument\n");
+     return option::ARG_ILLEGAL;
+   }
+   static option::ArgStatus NonEmpty(const option::Option& option, bool msg)
+   {
+     if (option.arg != 0 && option.arg[0] != 0)
+       return option::ARG_OK;
+     if (msg) printError("Option '", option, "' requires a non-empty argument\n");
+     return option::ARG_ILLEGAL;
+   }
+   static option::ArgStatus Numeric(const option::Option& option, bool msg)
+   {
+     char* endptr = 0;
+     if (option.arg != 0 && strtol(option.arg, &endptr, 10)){};
+     if (endptr != option.arg && *endptr == 0)
+       return option::ARG_OK;
+     if (msg) printError("Option '", option, "' requires a numeric argument\n");
+     return option::ARG_ILLEGAL;
+   }
+ };
+ enum OptionType {
+     OPT_ENABLE,
+     OPT_DIABLE
+ };
+ enum OptionIndex {
+     INPUT_FILE,
+     OUTPUT_FILE,
+     HELP,
+     READ_INCLUDE_FILES,
+     UNKOWN,
+ };
+ const option::Descriptor usage[] =
+ {
+     {HELP, 0, "", "help", Arg::None, "  --help\t\tprint usage and exit"},
 -    {INPUT_FILE, 0, "c", "input", Arg::Required, "  -i --input-file, \t\tsnort configuration file. Specify as many files as you would like"},
++    {INPUT_FILE, 0, "c", "conf-file", Arg::Required, "  --conf-file, -c, \t\tsnort configuration file. Specify as many files as you would like"},
+     {OUTPUT_FILE, 0, "o", "output", Arg::Required, "  --output-file, -o \t\tThe new Snort++ configuration file name"},
+     {READ_INCLUDE_FILES, OPT_ENABLE, "", "enable-reading-includes", Arg::None, "  enable-reading-includes \t\t Every time the 'include' keywords appears, open and parse that file"},
+     {READ_INCLUDE_FILES, OPT_DIABLE, "", "disable-reading-includes", Arg::None, "  disable-reading-includes  \t\tEvery time the 'include' keywords appears, open and parse that file"},
+     {0,0,0,0,0,0}
+ };
  
-         if (orig_text.empty())
-         {
-             cv.add_comment_to_file("");
-         }
-         else if (orig_text.front() == '#')
-         {
-             orig_text.erase(orig_text.begin());
-             cv.add_comment_to_file(orig_text);
-             orig_text.clear();
-         }
-         else if ( orig_text.back() == '\\')
-         {
-             orig_text.pop_back();
-             util::rtrim(orig_text);
-         }
-         else
-         {
-             std::stringstream data_stream(orig_text);
-             while(data_stream.tellg() != -1)
-             {
-                 if (!cv.convert_line(data_stream))
-                 {
-                     cv.log_error("Failed to entirely convert: " + orig_text);
- //                  data_stream.setstate(std::basic_ios<char>::eofbit);
-                     break;
-                 }
-             }
-             orig_text.clear();
-             cv.reset_state();
-         }
-     }
+ } // anonymous
  
-     // finally, lets print the converter to file
-     out << "require(\"snort_config\")  -- for loading" << std::endl;
-     out << cv;
-     return true;
- }
  
+ /*********************************************
+  **************  MAIN FILES  *****************
+  *********************************************/
  
- static void show_usage()
- {
-     std::cout << "usage:  snort2lua <input_conf_file> <output_lua_file>" << std::endl;
- }
  
  int main (int argc, char* argv[])
  {