]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
config_binding.cc refactor. Removing duplicate code && global api's
authorJosh <jrosenba@cisco.com>
Fri, 10 Oct 2014 18:40:37 +0000 (13:40 -0500)
committerJosh <jrosenba@cisco.com>
Fri, 10 Oct 2014 18:40:37 +0000 (13:40 -0500)
99 files changed:
tools/snort2lua/config_states/config_alertfile.cc
tools/snort2lua/config_states/config_binding.cc
tools/snort2lua/config_states/config_checksums.cc
tools/snort2lua/config_states/config_classification.cc
tools/snort2lua/config_states/config_decode_esp.cc
tools/snort2lua/config_states/config_default_rule_state.cc
tools/snort2lua/config_states/config_deleted.cc
tools/snort2lua/config_states/config_detection.cc
tools/snort2lua/config_states/config_event_queue.cc
tools/snort2lua/config_states/config_event_trace.cc
tools/snort2lua/config_states/config_file.cc
tools/snort2lua/config_states/config_ignore_ports.cc
tools/snort2lua/config_states/config_ipv6_frag.cc
tools/snort2lua/config_states/config_memcaps.cc
tools/snort2lua/config_states/config_mpls_payload_type.cc
tools/snort2lua/config_states/config_no_option.cc
tools/snort2lua/config_states/config_one_int_option.cc
tools/snort2lua/config_states/config_one_string_option.cc
tools/snort2lua/config_states/config_order.cc
tools/snort2lua/config_states/config_paf_max.cc
tools/snort2lua/config_states/config_ppm.cc
tools/snort2lua/config_states/config_profile.cc
tools/snort2lua/config_states/config_reference.cc
tools/snort2lua/config_states/config_response.cc
tools/snort2lua/config_states/config_tunnel_verdicts.cc
tools/snort2lua/conversion_defines.h
tools/snort2lua/conversion_state.h
tools/snort2lua/data/data_types/dt_comment.cc
tools/snort2lua/data/data_types/dt_comment.h
tools/snort2lua/data/data_types/dt_rule.cc
tools/snort2lua/data/data_types/dt_table.cc
tools/snort2lua/data/data_types/dt_var.cc
tools/snort2lua/data/data_types/dt_var.h
tools/snort2lua/data/dt_data.cc
tools/snort2lua/data/dt_data.h
tools/snort2lua/data/dt_rule_api.cc
tools/snort2lua/data/dt_rule_api.h
tools/snort2lua/data/dt_table_api.cc
tools/snort2lua/data/dt_table_api.h
tools/snort2lua/init_state.cc
tools/snort2lua/init_state.h
tools/snort2lua/keyword_states/kws_attribute_table.cc
tools/snort2lua/keyword_states/kws_config.cc
tools/snort2lua/keyword_states/kws_event_filter.cc
tools/snort2lua/keyword_states/kws_file.cc
tools/snort2lua/keyword_states/kws_include.cc
tools/snort2lua/keyword_states/kws_output.cc
tools/snort2lua/keyword_states/kws_paths.cc
tools/snort2lua/keyword_states/kws_preprocessor.cc
tools/snort2lua/keyword_states/kws_rate_filter.cc
tools/snort2lua/keyword_states/kws_rule.cc
tools/snort2lua/keyword_states/kws_rule_state.cc
tools/snort2lua/keyword_states/kws_ruletype.cc
tools/snort2lua/keyword_states/kws_suppress.cc
tools/snort2lua/keyword_states/kws_var.cc
tools/snort2lua/output_states/out_csv.cc
tools/snort2lua/output_states/out_fast.cc
tools/snort2lua/output_states/out_full.cc
tools/snort2lua/output_states/out_null.cc
tools/snort2lua/output_states/out_syslog.cc
tools/snort2lua/output_states/out_tcpdump.cc
tools/snort2lua/output_states/out_test.cc
tools/snort2lua/output_states/out_unified2.cc
tools/snort2lua/output_states/out_unixsock.cc
tools/snort2lua/preprocessor_states/pps_arpspoof.cc
tools/snort2lua/preprocessor_states/pps_bo.cc
tools/snort2lua/preprocessor_states/pps_frag3_engine.cc
tools/snort2lua/preprocessor_states/pps_frag3_global.cc
tools/snort2lua/preprocessor_states/pps_ftp_telnet.cc
tools/snort2lua/preprocessor_states/pps_ftp_telnet_protocol.cc
tools/snort2lua/preprocessor_states/pps_gtp.cc
tools/snort2lua/preprocessor_states/pps_http_inspect.cc
tools/snort2lua/preprocessor_states/pps_http_inspect_server.cc
tools/snort2lua/preprocessor_states/pps_normalizers.cc
tools/snort2lua/preprocessor_states/pps_perfmonitor.cc
tools/snort2lua/preprocessor_states/pps_rpc_decode.cc
tools/snort2lua/preprocessor_states/pps_sfportscan.cc
tools/snort2lua/preprocessor_states/pps_stream5_global.cc
tools/snort2lua/preprocessor_states/pps_stream5_ip.cc
tools/snort2lua/preprocessor_states/pps_stream5_tcp.cc
tools/snort2lua/preprocessor_states/pps_stream5_udp.cc
tools/snort2lua/rule_states/rule_base64_decode.cc
tools/snort2lua/rule_states/rule_content.cc
tools/snort2lua/rule_states/rule_file_data.cc
tools/snort2lua/rule_states/rule_http_encode.cc
tools/snort2lua/rule_states/rule_metadata.cc
tools/snort2lua/rule_states/rule_pcre.cc
tools/snort2lua/rule_states/rule_react.cc
tools/snort2lua/rule_states/rule_resp.cc
tools/snort2lua/rule_states/rule_threshold.cc
tools/snort2lua/rule_states/rule_unchanged.cc
tools/snort2lua/rule_states/rule_urilen.cc
tools/snort2lua/snort2lua.cc
tools/snort2lua/utils/converter.cc
tools/snort2lua/utils/converter.h
tools/snort2lua/utils/parse_cmd_line.cc
tools/snort2lua/utils/parse_cmd_line.h
tools/snort2lua/utils/util_binder.cc
tools/snort2lua/utils/util_binder.h

index e0583ab967b9adab99ba1b055f2b5b4a17ee5185..0593c571ec6a00af46980cf62225d1fcca99f054 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Alertfile : public ConversionState
 {
 public:
-    Alertfile() : ConversionState() {};
+    Alertfile(Converter& c) : ConversionState(c) {};
     virtual ~Alertfile() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -90,8 +90,8 @@ bool Alertfile::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
-{ return new Alertfile(); }
+static ConversionState* ctor(Converter& c)
+{ return new Alertfile(c); }
 
 
 static const ConvertMap alertfile_api =
index e3c7cfec4f07d2f33d92fea7a8f6ca49ab869e04..efa6f0c973c1b36931595646f70eb78318fa2d9a 100644 (file)
@@ -37,7 +37,7 @@ namespace {
 class Binding : public ConversionState
 {
 public:
-    Binding() : ConversionState() {};
+    Binding(Converter& c) : ConversionState(c) {};
     virtual ~Binding() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -45,9 +45,6 @@ private:
     void add_vlan(const std::string& vlan, Binder&);
     void add_policy_id(const std::string& id, Binder&);
     void add_net(const std::string& net, Binder&);
-
-    // FIXIT-M  Remove this functino after refactor
-    bool parse_file(std::string file_name);
 };
 
 } // namespace
@@ -156,7 +153,7 @@ bool Binding::convert(std::istringstream& data_stream)
     if (!util::get_string(data_stream, val, ","))
         return false;
 
-    Binder bind;
+    Binder bind(table_api);
     bool rc = true;
 
     do
@@ -192,7 +189,14 @@ bool Binding::convert(std::istringstream& data_stream)
 
         // if we still can't find this file, add it as a snort file
         if (util::file_exists(full_path))
+        {
+            Converter cv;
+
+            if (cv.convert(input_file, input_file + ".lua") < 0)
+                rc = false;
+
             parse_file(full_path);
+        }
     }
 
     // FIXIT-L  J  this file extension shoudl not be hardcoded
@@ -200,74 +204,13 @@ bool Binding::convert(std::istringstream& data_stream)
     return rc;
 }
 
-
-// FIXIT-M J  because the other refactor comments don't indicate how repetitive this code is
-bool Binding::parse_file(std::string input_file)
-{
-    std::vector<Variable*> vars;
-    std::vector<Table*> tables;
-    std::vector<Rule*> rules;
-    std::vector<Include*> includes;
-    Comments comment("This file is a binding!!", 0,
-                Comments::CommentType::MULTI_LINE);
-    Comments* comment_ptr = &comment;
-    bool rc = false;
-
-    data_api.swap_conf_data(vars, includes, comment_ptr);
-    table_api.swap_tables(tables);
-    rule_api.swap_rules(rules);
-
-
-
-    if (cv.convert_file(input_file) < 0)
-        rc = true; // return a negative number to main snort2lua method
-
-
-    if (!rule_api.empty())
-    {
-        table_api.open_top_level_table("ips");
-        table_api.add_option("rules", "$default_rules");
-        table_api.close_table();
-    }
-
-
-    // print configuration file
-    if (!table_api.empty() || data_api.empty() || !rule_api.empty())
-    {
-
-
-        table_api.open_top_level_table("binder");
-        table_api.close_table();
-
-
-        std::ofstream out;
-        out.open(input_file + ".lua");
-
-
-        out << "require(\"snort_config\")\n\n";
-        data_api.print_data(out);
-        rule_api.print_rules(out, false);
-        table_api.print_tables(out);
-        data_api.print_comments(out);
-        out << std::endl;
-        out.close();
-
-    }
-
-
-    data_api.swap_conf_data(vars, includes, comment_ptr);
-    table_api.swap_tables(tables);
-    rule_api.swap_rules(rules);
-    return rc;
-}
-
 /**************************
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Binding();
+    return new Binding(c);
 }
 
 static const ConvertMap binding_api =
index 062ef4b9d8953d2421b2b92ba8acea13969f839c..a2854cf70a903d3205d8cd580173b22ced249346 100644 (file)
@@ -34,10 +34,11 @@ namespace {
 class ConfigChecksum : public ConversionState
 {
 public:
-    ConfigChecksum( const std::string* snort_option,
+    ConfigChecksum( Converter& c,
+                    const std::string* snort_option,
                     const std::string* lua_table,
                     const std::string* lua_option) :
-            ConversionState(),
+            ConversionState(c),
             snort_option(snort_option),
             lua_table(lua_table),
             lua_option(lua_option)
@@ -82,9 +83,9 @@ private:
 template<const std::string *snort_option,
          const std::string *lua_name,
          const std::string *lua_option = nullptr>
-static ConversionState* config_checksum_ctor()
+static ConversionState* config_checksum_ctor(Converter& c)
 {
-    return new ConfigChecksum(snort_option, lua_name, lua_option);
+    return new ConfigChecksum(c, snort_option, lua_name, lua_option);
 }
 
 
index 89aadc7d09ab7363ee9131edb506681579f4841b..5910d374f26a85fbce69e2cb10d816de6e3359b1 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Classification : public ConversionState
 {
  public:
-    Classification() : ConversionState() {}
+    Classification(Converter& c) : ConversionState(c) {}
     virtual ~Classification() {}
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -75,9 +75,9 @@ bool Classification::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Classification();
+    return new Classification(c);
 }
 
 static const ConvertMap classification_api =
index d6b75d5e5de39d165c240571597c1e67b5d483cb..64ea17e2a2014e6c4751d7eaf9962f037b434742 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class DecodeEsp : public ConversionState
 {
 public:
-    DecodeEsp() : ConversionState() {};
+    DecodeEsp(Converter& c) : ConversionState(c) {};
     virtual ~DecodeEsp() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -85,9 +85,9 @@ bool DecodeEsp::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new DecodeEsp();
+    return new DecodeEsp(c);
 }
 
 static const ConvertMap decode_esp_api =
index 17e5af3b2e9a5c84ea00c5183e54739beaa31f1e..ec8f0f6c86ae32e1e8806b640c127fa3c3375349 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class DefaultRuleState : public ConversionState
 {
 public:
-    DefaultRuleState() : ConversionState() {};
+    DefaultRuleState(Converter& c) : ConversionState(c) {};
     virtual ~DefaultRuleState() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -67,9 +67,9 @@ bool DefaultRuleState::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new DefaultRuleState();
+    return new DefaultRuleState(c);
 }
 
 static const ConvertMap default_rule_state_api =
index 9d4d39b8930a3af4655a530b639f0e55bbb64b1f..7ec995fb334af6d9fa015a0d68713564ca0a4bf8 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Deleted : public ConversionState
 {
 public:
-    Deleted() : ConversionState() {};
+    Deleted(Converter& c) : ConversionState(c) {};
     virtual ~Deleted() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -50,17 +50,17 @@ bool Deleted::convert(std::istringstream& data_stream)
 }
 
 template<const std::string *snort_option>
-static ConversionState* deleted_ctor()
+static ConversionState* deleted_ctor(Converter& c)
 {
     // set here since not all deleted configs have options
-    if (!data_api.is_quiet_mode())
+    if (!DataApi::is_quiet_mode())
     {
-        table_api.open_table("deleted_snort_config_options");
-        table_api.add_deleted_comment("config " + *snort_option + "[:.*]");
-        table_api.close_table();
+        c.get_table_api().open_table("deleted_snort_config_options");
+        c.get_table_api().add_deleted_comment("config " + *snort_option + "[:.*]");
+        c.get_table_api().close_table();
     }
 
-    return new Deleted();
+    return new Deleted(c);
 }
 
 /*************************************************
index 2e4afae525e209e7cefdf2b67428cde5f6cd67c2..6e8712fdac8de142ade8ff6e3b9c0d1e06f6d284 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Detection : public ConversionState
 {
 public:
-    Detection() : ConversionState() {};
+    Detection(Converter& c) : ConversionState(c) {};
     virtual ~Detection() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -283,9 +283,9 @@ bool Detection::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Detection();
+    return new Detection(c);
 }
 
 static const ConvertMap detection_api =
index 1e73689791486c927c6ca1e23741ef13ee00d309..9723ad63630fd5b81a246e29d9595fa43e22a4ae 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class EventQueue : public ConversionState
 {
 public:
-    EventQueue() : ConversionState() {};
+    EventQueue(Converter& c) : ConversionState(c) {};
     virtual ~EventQueue() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -99,9 +99,9 @@ bool EventQueue::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new EventQueue();
+    return new EventQueue(c);
 }
 
 static const ConvertMap event_queue_api =
index 22bd8f0d6329b1fdd564a9a231427f1ee559dd37..63202d1cbf591e02c2f5ee80887c2f46800722ee 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class EventTrace : public ConversionState
 {
 public:
-    EventTrace() : ConversionState() {};
+    EventTrace(Converter& c) : ConversionState(c) {};
     virtual ~EventTrace() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -78,9 +78,9 @@ bool EventTrace::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new EventTrace();
+    return new EventTrace(c);
 }
 
 static const ConvertMap event_trace_api =
index 456f0eac9a8f108552f49d562a2723195ea7e21d..96d5ed4d56967652320300c491af23034c4016a3 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class File : public ConversionState
 {
 public:
-    File() : ConversionState() {};
+    File(Converter& c) : ConversionState(c) {};
     virtual ~File() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -124,9 +124,9 @@ bool File::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new File();
+    return new File(c);
 }
 
 static const ConvertMap file_api =
index b889dcbe13476408a05e843d885467a7446f6bf6..22ade07327ea123d7daf61c7579d5d5a84ebf3ee 100644 (file)
@@ -38,7 +38,7 @@ constexpr uint16_t MAX_PORTS = 0xFFFF; // == 65535
 class IgnorePorts : public ConversionState
 {
 public:
-    IgnorePorts() : ConversionState() {};
+    IgnorePorts(Converter& c) : ConversionState(c) {};
     virtual ~IgnorePorts() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -48,7 +48,7 @@ public:
 
 bool IgnorePorts::convert(std::istringstream& data_stream)
 {
-    Binder bind;
+    Binder bind(table_api);
     bool retval = true;
     std::string keyword;
     std::string port;
@@ -138,9 +138,9 @@ bool IgnorePorts::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new IgnorePorts();
+    return new IgnorePorts(c);
 }
 
 static const ConvertMap config_ignore_ports =
index d1ef1ca6633ea9bd3a356d9da993c6bf82e2cb02..0a73e4e401d10f71b362151f8ea1b363fe0fac66 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Ipv6Frag : public ConversionState
 {
 public:
-    Ipv6Frag() : ConversionState() {};
+    Ipv6Frag(Converter& c) : ConversionState(c) {};
     virtual ~Ipv6Frag() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -47,7 +47,7 @@ private:
 void Ipv6Frag::add_deleted_option(std::string dlt_opt)
 {
     // see comment in Ipv6Frag::convert
-    if (!data_api.is_quiet_mode())
+    if (!DataApi::is_quiet_mode())
         table_api.add_deleted_comment("config ipv6_frag: " + dlt_opt);
 }
 
@@ -58,7 +58,7 @@ bool Ipv6Frag::convert(std::istringstream& data_stream)
 
     // I'm checking here because I do not want to create this
     // table in quiet mode
-    if (!data_api.is_quiet_mode())
+    if (!DataApi::is_quiet_mode())
         table_api.open_table("deleted_snort_config_options");
 
     while (util::get_string(data_stream, arg, ","))
@@ -105,9 +105,9 @@ bool Ipv6Frag::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Ipv6Frag();
+    return new Ipv6Frag(c);
 }
 
 static const ConvertMap ipv6_frag_api =
index 8dc76953e4ebe3ed8b3cc770cbbc37de9e82d44c..fd84eaece5da4b12f05bd9b35957209f5456a52f 100644 (file)
@@ -38,7 +38,7 @@ template<const std::string *snort_option,
 class Memcap : public ConversionState
 {
 public:
-    Memcap() : ConversionState() {};
+    Memcap(Converter& c) : ConversionState(c) {};
     virtual ~Memcap() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -70,9 +70,9 @@ bool Memcap<snort_option, lua_table, lua_option>::convert(std::istringstream& da
 template<const std::string *snort_option,
         const std::string* lua_table,
         const std::string* lua_option>
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Memcap<snort_option, lua_table, lua_option>();
+    return new Memcap<snort_option, lua_table, lua_option>(c);
 }
 
 
index 64d820f5de3890846732340ed2ebb048d6d21b48..4314396eb1163669a47b7cb755069df1eba47682 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class MplsPayloadType : public ConversionState
 {
 public:
-    MplsPayloadType() : ConversionState() {};
+    MplsPayloadType(Converter& c) : ConversionState(c) {};
     virtual ~MplsPayloadType() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -82,9 +82,9 @@ bool MplsPayloadType::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new MplsPayloadType();
+    return new MplsPayloadType(c);
 }
 
 static const ConvertMap mpls_payload_type_api =
index b44fb5df855e15a35a5ca94d32d283c84e548c37..96175fa2818723b0367f791f922c69dcf946f555 100644 (file)
@@ -34,7 +34,7 @@ namespace
 class DeadCode : public ConversionState
 {
 public:
-    DeadCode() : ConversionState() {}
+    DeadCode(Converter& c) : ConversionState(c) {}
     virtual ~DeadCode() {}
     virtual bool convert(std::istringstream& data_stream)
     {
@@ -48,52 +48,55 @@ public:
 template<const std::string* snort_option,
          const std::string* lua_table,
          const std::string* lua_option>
-static ConversionState* config_true_no_opt_ctor()
+static ConversionState* config_true_no_opt_ctor(Converter& c)
 {
-    table_api.open_table(*lua_table);
+    c.get_table_api().open_table(*lua_table);
 
     if (snort_option->compare(*lua_option))
-        table_api.add_diff_option_comment("config " + *snort_option + ":", *lua_option);
+    {
+        c.get_table_api().add_diff_option_comment(
+            "config " + *snort_option + ":", *lua_option);
+    }
 
-    table_api.add_option(*lua_option, true);
-    table_api.close_table();
-    return new DeadCode();
+    c.get_table_api().add_option(*lua_option, true);
+    c.get_table_api().close_table();
+    return new DeadCode(c);
 }
 
 template<const std::string* snort_option,
          const std::string* lua_table>
-static ConversionState* config_true_no_opt_ctor()
+static ConversionState* config_true_no_opt_ctor(Converter& c)
 {
-    table_api.open_table(*lua_table);
-    table_api.add_option(*snort_option, true);
-    table_api.close_table();
-    return new DeadCode();
+    c.get_table_api().open_table(*lua_table);
+    c.get_table_api().add_option(*snort_option, true);
+    c.get_table_api().close_table();
+    return new DeadCode(c);
 }
 
 template<const std::string* snort_option,
          const std::string* lua_table,
          const std::string* lua_option>
-static ConversionState* config_false_no_opt_ctor()
+static ConversionState* config_false_no_opt_ctor(Converter& c)
 {
-    table_api.open_table(*lua_table);
+    c.get_table_api().open_table(*lua_table);
 
     // WARNING:  THIS WILL SEGFAULT if any variable is nullptr!!
     if (snort_option->compare(*lua_option))
-        table_api.add_diff_option_comment("config " + *snort_option + ":", *lua_option);
+        c.get_table_api().add_diff_option_comment("config " + *snort_option + ":", *lua_option);
 
-    table_api.add_option(*lua_option, false);
-    table_api.close_table();
-    return new DeadCode();
+    c.get_table_api().add_option(*lua_option, false);
+    c.get_table_api().close_table();
+    return new DeadCode(c);
 }
 
 template<const std::string* snort_option,
          const std::string* lua_table>
-static ConversionState* config_false_no_opt_ctor()
+static ConversionState* config_false_no_opt_ctor(Converter& c)
 {
-    table_api.open_table(*lua_table);
-    table_api.add_option(*snort_option, false);
-    table_api.close_table();
-    return new DeadCode();
+    c.get_table_api().open_table(*lua_table);
+    c.get_table_api().add_option(*snort_option, false);
+    c.get_table_api().close_table();
+    return new DeadCode(c);
 }
 
 } // namespace
index 769dfaa9cad9ea5619a5fb7f7aa062545cacbe9c..17673f6d5853d97213f33fa182fb116eb3b0f147 100644 (file)
@@ -41,10 +41,11 @@ namespace
 class ConfigIntOption : public ConversionState
 {
 public:
-    ConfigIntOption( const std::string* snort_option,
-                        const std::string* lua_table,
-                        const std::string* lua_option) :
-            ConversionState(),
+    ConfigIntOption(Converter& c,
+                    const std::string* snort_option,
+                    const std::string* lua_table,
+                    const std::string* lua_option) :
+            ConversionState(c),
             snort_option(snort_option),
             lua_table(lua_table),
             lua_option(lua_option)
@@ -59,7 +60,7 @@ public:
             (lua_table == nullptr)||
             (lua_table->empty()))
         {
-            data_api.developer_error("Invalid Option!!  Missing either the Snort Option"
+            DataApi::developer_error("Invalid Option!!  Missing either the Snort Option"
                 " or the corresponding lua table!!");
             return false;
         }
@@ -94,9 +95,10 @@ private:
 template<const std::string *snort_option,
         const std::string *lua_table,
         const std::string *lua_option = nullptr>
-static ConversionState* config_int_ctor()
+static ConversionState* config_int_ctor(Converter& c)
 {
-    return new ConfigIntOption( snort_option,
+    return new ConfigIntOption( c,
+                                snort_option,
                                 lua_table,
                                 lua_option);
 }
index 717d12390246ea8083735fd10aa1f1d7fbed47e4..887e919c28b8cb646f786554c253b3518c29452c 100644 (file)
@@ -36,10 +36,11 @@ namespace
 class ConfigStringOption : public ConversionState
 {
 public:
-    ConfigStringOption( const std::string* snort_option,
+    ConfigStringOption( Converter& c,
+                        const std::string* snort_option,
                         const std::string* lua_table,
                         const std::string* lua_option) :
-            ConversionState(),
+            ConversionState(c),
             snort_option(snort_option),
             lua_table(lua_table),
             lua_option(lua_option)
@@ -95,9 +96,10 @@ private:
 template<const std::string *snort_option,
         const std::string *lua_table,
         const std::string *lua_option = nullptr>
-static ConversionState* config_string_ctor()
+static ConversionState* config_string_ctor(Converter& c)
 {
-    return new ConfigStringOption(  snort_option,
+    return new ConfigStringOption(  c,
+                                    snort_option,
                                     lua_table,
                                     lua_option);
 }
index 7d7abdd9562bad67834e61dc8d795579c0621952..73754ff06875751af01e85bcb839a6ad99e11b43 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Order : public ConversionState
 {
 public:
-    Order() : ConversionState() {};
+    Order(Converter& c) : ConversionState(c) {};
     virtual ~Order() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -64,9 +64,9 @@ bool Order::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Order();
+    return new Order(c);
 }
 
 static const ConvertMap order_api =
index 1a9059b581f3446e8487acdce95b9f174e746c7c..0db541c5af69169d6150eda2685ae32152b6b40d 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class PafMax : public ConversionState
 {
 public:
-    PafMax() : ConversionState() {};
+    PafMax(Converter& c) : ConversionState(c) {};
     virtual ~PafMax() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -51,12 +51,12 @@ bool PafMax::convert(std::istringstream& data_stream)
     if (data_stream >> val)
     {
         if (val < 1460)
-            retval = table_api.add_diff_option_comment("paf_max [0:63780]", "paf_max [1460:63780]");
+            table_api.add_diff_option_comment("paf_max [0:63780]", "max_pdu [1460:63780]");
         else
-            retval = table_api.add_option("paf_max", val);
+            retval = table_api.add_option("max_pdu", val);
     }
     else
-        retval = false;
+        data_api.failed_conversion(data_stream);
 
     table_api.close_table();
     return retval;
@@ -66,10 +66,8 @@ bool PafMax::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new PafMax();
-}
+static ConversionState* ctor(Converter& c)
+{ return new PafMax(c); }
 
 static const ConvertMap paf_max_api =
 {
index 52a1559b326398d6626839dc35e97fe314a5cfbb..716851bbca0ced30c782ab26bffab89ab3f97d60 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Ppm : public ConversionState
 {
 public:
-    Ppm() : ConversionState() {};
+    Ppm(Converter& c) : ConversionState(c) {};
     virtual ~Ppm() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -167,9 +167,9 @@ bool Ppm::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Ppm();
+    return new Ppm(c);
 }
 
 static const ConvertMap config_ppm_api =
index 171d4aa32a235b4acafb7b4daacf1a1e739dcb3d..319ea98e95f9c28d3afad5a0198caf2ab38056b8 100644 (file)
@@ -36,7 +36,7 @@ template<const std::string* table_name>
 class Profilers : public ConversionState
 {
 public:
-    Profilers() : ConversionState() {};
+    Profilers(Converter& c) : ConversionState(c) {};
     virtual ~Profilers() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -121,9 +121,9 @@ bool Profilers<table_name>::convert(std::istringstream& data_stream)
 }
 
 template<const std::string* table_name>
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Profilers<table_name>();
+    return new Profilers<table_name>(c);
 }
 
 /**************************
index 540dfb5e67f01fe5215adabdd3e5d4d4d7a5d272..b6ca7b327b836a360004669e0f0716434f688d08 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Reference : public ConversionState
 {
 public:
-    Reference() : ConversionState() {};
+    Reference(Converter& c) : ConversionState(c) {};
     virtual ~Reference() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -62,9 +62,9 @@ bool Reference::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Reference();
+    return new Reference(c);
 }
 
 static const ConvertMap reference_api =
index 9f3e11bf35b37cc86a611a017f37657f854cf400..eac96e6a67664a855d28ed9f32037b0ded2ffaa8 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Response : public ConversionState
 {
 public:
-    Response() : ConversionState() {};
+    Response(Converter& c) : ConversionState(c) {};
     virtual ~Response() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -80,9 +80,9 @@ bool Response::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Response();
+    return new Response(c);
 }
 
 static const ConvertMap response_api =
index ea36d5ccae0408ea0bc21991516f812d8b8bc367..a22775a7793ed56f365dd9759a115aa22a80ace1 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class TunnelVerdicts : public ConversionState
 {
 public:
-    TunnelVerdicts() : ConversionState() {};
+    TunnelVerdicts(Converter& c) : ConversionState(c) {};
     virtual ~TunnelVerdicts() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -63,9 +63,9 @@ bool TunnelVerdicts::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new TunnelVerdicts();
+    return new TunnelVerdicts(c);
 }
 
 static const ConvertMap tunnel_verdicts_api =
index ef5fac733e56a7a0302cca32a1ba0ecbde4c5e0e..cf7fcfa8df1c22bdb4957f98c335c219576c61d6 100644 (file)
@@ -30,7 +30,8 @@
  */
 
 class ConversionState;
-typedef ConversionState* (*conv_new_f)(void);
+class Converter;
+typedef ConversionState* (*conv_new_f)(Converter&);
 
 struct ConvertMap
 {
index a3c9f5ebcb5c9757a1808e9fff667eb653ba690c..a2e1c8928072d1e05479b06272b026423f6857fb 100644 (file)
@@ -29,6 +29,8 @@
 #include <iostream>
 
 #include "data/dt_data.h"
+#include "data/dt_table_api.h"
+#include "data/dt_rule_api.h"
 
 // the following three files are for the function 'set_next_rule_state'
 #include "utils/s2l_util.h"
 #include "utils/converter.h"
 #include "conversion_defines.h"
 
+class DataApi;
+class RuleApi;
+class TableApi;
 
 class ConversionState
 {
 
 public:
-    ConversionState() {}
-
+    ConversionState(Converter& c) : cv(c),
+                                    data_api(c.get_data_api()),
+                                    table_api(c.get_table_api()),
+                                    rule_api(c.get_rule_api())
+    { }
     virtual ~ConversionState() {};
     virtual bool convert(std::istringstream& data)=0;
 
+
 protected:
+    Converter& cv;
+    DataApi& data_api;
+    TableApi& table_api;
+    RuleApi& rule_api;
 
 #if 0
     Forward declaration fo parsing methods. Since these are all inline,
@@ -259,7 +272,7 @@ protected:
             if (map)
             {
                 rule_api.unselect_option(); // reset option data...just in case.
-                cv.set_state(map->ctor());
+                cv.set_state(map->ctor(cv));
                 break;
             }
             else
@@ -275,14 +288,14 @@ protected:
             }
         }
 
-        // This is definitely a special case to always return true, I have
-        // already taken corrective action by signifyig this is a 'bad rule'.
-        // Additionally, I don't return false earlier becasue, when possible,
-        // I want to parse the entire rule. If I only return false when the
-        // last option was invalid, this would lead to an incosistant and
-        // unreliable return value.  Bottom line, I'm consistant by returning
-        // true and handling "bad" values and directly signifgying to Data
-        // classes this is a bad rule.
+        /*
+         * The reason this function always returns true is because if the
+         * function returned false, the main conversion loop would stop
+         * converting.  However, every part of the rule which can be
+         * converted, should be converted.  Therefore, this function
+         * takes its own invalid conversion action by calling bad_rule(),
+         * and then returns true.
+         */
         return true;
     }
 
index f26186aed0e66da2b51f52d97a3ab7557adf654f..0c7d92d8c661626d7310d5aacbc3f2f331dedb6b 100644 (file)
@@ -53,9 +53,7 @@ Comments::~Comments()
 
 void Comments::add_text(std::string text)
 {
-    // if this line is not an empty string
-    // OR the previous line was not an empty string
-    if (!text.empty() || !prev_empty)
+    if ( !(text.empty() && prev_empty) )
     {
         comment.push_back(std::string(text));
         prev_empty = text.empty();
@@ -79,7 +77,7 @@ void Comments::add_sorted_text(std::string new_text)
     comment.push_back(new_text);
 }
 
-bool Comments::empty()
+bool Comments::empty() const
 {
     return ((comment.size() == 0) ||
             (comment.size() == 1 && header));
index 0c86e4840f674e13990e5d5f33ddfbb7f60dda55..cbec8ff68483ded045e1442df0cbdfe88a5d2607 100644 (file)
@@ -30,7 +30,7 @@
 static const std::string start_comments =
     "\nCOMMENTS:\n"
     "    these line were commented "
-    "in the configuration file.";
+    "in the configuration file.\n\n";
 
 static const std::string start_errors =
     "\nERRORS:\n"
@@ -60,7 +60,7 @@ public:
     // insert this string before the first lexigraphically larger string.
     // will not add duplicates.
     void add_sorted_text(std::string new_text);
-    bool empty();
+    bool empty() const;
 
     // overloading operators
     friend std::ostream &operator<<( std::ostream&, const Comments &);
index 83089c9a44632c8ebf3989a276cb20f4cc3565c4..0713b40e56abb20617eeba712560b5899eef1653 100644 (file)
@@ -112,7 +112,7 @@ std::ostream &operator<<( std::ostream& out, const Rule &rule)
     bool first_line = true;
 
     // don't print comment and tag in quiet mode
-    if (!data_api.is_quiet_mode())
+    if (!DataApi::is_quiet_mode())
     {
         if (rule.is_bad_rule)
             out << "#FAILED TO CONVERT THE FOLLOWING RULE:" << "\n";
index 3c3673df3edc0f939707b21d2bd9bc9692d69a2c..23cecb5b1c22ef1d73ff74c3cb9705efbc2b33ee 100644 (file)
@@ -191,11 +191,11 @@ std::ostream &operator<<( std::ostream& out, const Table &t)
         out << whitespace << t.name << " =" << std::endl;
     out << whitespace << '{' << std::endl;
 
-    if (!t.comments->empty() && !data_api.is_quiet_mode())
+    if (!t.comments->empty() && !DataApi::is_quiet_mode())
         out << (*t.comments) << std::endl;
 
     // if we only want differences, don't print data
-    if (!data_api.is_difference_mode())
+    if (!DataApi::is_difference_mode())
     {
         for (Option* o : t.options)
             out << (*o) << ",\n";
index 1559e2c33ecbdfff09a5f632a0fbbd5740f546bf..838d8cf6bda20f1b5d29c845583cac56c287d4c1 100644 (file)
@@ -38,7 +38,7 @@ Variable::Variable(std::string name)
 Variable::~Variable(){}
 
 
-std::string Variable::get_value(LuaData* ld)
+std::string Variable::get_value(DataApi* ld)
 {
     std::string variable = "";
     bool first_line = true;
index b43e72a31e4fd4c9dcac5d6efae449f687189d71..8e45ef620321acc4b829f55855dad7b2e6510daa 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef DATA_DATA_TYPES_DT_VAR_H
 #define DATA_DATA_TYPES_DT_VAR_H
 
-class LuaData;
+class DataApi;
 
 class Variable
 {
@@ -36,7 +36,7 @@ public:
     virtual ~Variable();
 
     inline std::string get_name(){ return name; };
-    std::string get_value(LuaData*);
+    std::string get_value(DataApi*);
     bool add_value(std::string);
     friend std::ostream &operator<<( std::ostream&, const Variable &);
 
index 3ff3a074c2cec30c5e2bebc257a0ed324d15b3cb..ac770acdc9a21f6867a597a0aa36c37c82c33aa9 100644 (file)
 #include "data/data_types/dt_rule.h"
 #include "data/data_types/dt_include.h"
 
-LuaData data_api;
+DataApi::PrintMode DataApi::mode = DataApi::PrintMode::DEFAULT;
+unsigned int DataApi::dev_warnings = 0;
 
-
-LuaData::LuaData()
-    :   mode(LuaData::PrintMode::QUIET),
-        curr_data_bad(false)
+DataApi::DataApi() : curr_data_bad(false)
 {
     comments = new Comments(start_comments, 0,
                     Comments::CommentType::MULTI_LINE);
@@ -44,7 +42,7 @@ LuaData::LuaData()
                     Comments::CommentType::MULTI_LINE);
 }
 
-LuaData::~LuaData()
+DataApi::~DataApi()
 {
     for (auto v : vars)
         delete v;
@@ -58,7 +56,7 @@ LuaData::~LuaData()
 
 
 
-std::string LuaData::translate_variable(const std::string& var_name)
+std::string DataApi::translate_variable(const std::string& var_name)
 {
     for (auto v : vars)
         if (!var_name.compare(v->get_name()))
@@ -77,7 +75,7 @@ std::string LuaData::translate_variable(const std::string& var_name)
  * Given a Snort style string to expand, this funcion will return
  * the expanded string
  */
-std::string LuaData::expand_vars(const std::string &string)
+std::string DataApi::expand_vars(const std::string &string)
 {
     std::string estring;
     estring.resize(1024, '\0');
@@ -233,10 +231,10 @@ std::string LuaData::expand_vars(const std::string &string)
     return estring;
 }
 
-bool LuaData::failed_conversions()
-{ return !errors->empty(); }
+bool DataApi::failed_conversions() const
+{ return !errors->empty() || dev_warnings > 0; }
 
-void LuaData::failed_conversion(const std::istringstream& stream)
+void DataApi::failed_conversion(const std::istringstream& stream)
 {
     // we only need to go through this once.
     if (!curr_data_bad)
@@ -248,7 +246,7 @@ void LuaData::failed_conversion(const std::istringstream& stream)
     }
 }
 
-void LuaData::failed_conversion(const std::istringstream& stream,
+void DataApi::failed_conversion(const std::istringstream& stream,
                                 const std::string unkown_option)
 {
     // we only need to go through this once.
@@ -263,7 +261,7 @@ void LuaData::failed_conversion(const std::istringstream& stream,
 }
 
 
-bool LuaData::add_variable(std::string name, std::string value)
+bool DataApi::add_variable(std::string name, std::string value)
 {
     for (auto v : vars)
         if (!name.compare(v->get_name()))
@@ -275,12 +273,12 @@ bool LuaData::add_variable(std::string name, std::string value)
 }
 
 
-void LuaData::reset_state()
+void DataApi::reset_state()
 {
     curr_data_bad = false;
 }
 
-bool LuaData::add_include_file(std::string file_name)
+bool DataApi::add_include_file(std::string file_name)
 {
 
     Include* incl = new Include(file_name);
@@ -292,16 +290,17 @@ bool LuaData::add_include_file(std::string file_name)
     return true;
 }
 
-void LuaData::developer_error(std::string error_string)
+void DataApi::developer_error(std::string error_string)
 {
+    dev_warnings++;
     std::cout << "RUNTIME ERROR: " << error_string << std::endl;
 }
 
-void LuaData::add_comment(std::string c)
+void DataApi::add_comment(std::string c)
 { comments->add_text(c); }
 
 
-void LuaData::print_errors(std::ostream& out)
+void DataApi::print_errors(std::ostream& out)
 {
     if (is_default_mode() &&
         !errors->empty())
@@ -310,7 +309,7 @@ void LuaData::print_errors(std::ostream& out)
     }
 }
 
-void LuaData::print_data(std::ostream& out)
+void DataApi::print_data(std::ostream& out)
 {
     for (Variable* v : vars)
         out << (*v) << "\n\n";
@@ -321,14 +320,14 @@ void LuaData::print_data(std::ostream& out)
 }
 
 
-void LuaData::print_comments(std::ostream& out)
+void DataApi::print_comments(std::ostream& out)
 {
     if (is_default_mode() &&
         !comments->empty())
         out << (*comments) << "\n";
 }
 
-void LuaData::swap_conf_data(std::vector<Variable*>& new_vars,
+void DataApi::swap_conf_data(std::vector<Variable*>& new_vars,
                                 std::vector<Include*>& new_includes,
                                 Comments*& new_comments)
 {
index 972a12b7f872ed39fa5bd59df18a3bceb70cd351..c3fa46839d2d0ce6335d45505d288690d2d4e519 100644 (file)
@@ -47,9 +47,9 @@
  * creating new convesion states.  There are comments in
  * in all caps which show the seperate the sections.
  *
- * The first section of this file is really LuaData creation
+ * The first section of this file is really DataApi creation
  * and initialization, and adding miscelaneous objects
- * to the LuaData data.  The second section is for creating
+ * to the DataApi data.  The second section is for creating
  * tables and their options.  The third section is for
  * creating rules.
  */
 class Include;
 class Variable;
 class Comments;
-class LuaData;
-extern LuaData data_api;
+class DataApi;
 
-class LuaData
+class DataApi
 {
 
 public:
-    LuaData();
-    virtual ~LuaData();
+    DataApi();
+    virtual ~DataApi();
 
     // set and retrieve various pieces of information from this Data object
     // getters are for other data classes.
-    inline void set_default_print() {mode = PrintMode::DEFAULT; }
-    inline bool is_default_mode() { return mode == PrintMode::DEFAULT; }
-    inline void set_quiet_print() {mode = PrintMode::QUIET; }
-    inline bool is_quiet_mode() { return mode == PrintMode::QUIET; }
-    inline void set_difference_print() {mode = PrintMode::DIFFERENCES; }
-    inline bool is_difference_mode() { return mode == PrintMode::DIFFERENCES; }
+    inline static void set_default_print() {mode = PrintMode::DEFAULT; }
+    inline static bool is_default_mode() { return mode == PrintMode::DEFAULT; }
+    inline static void set_quiet_print() {mode = PrintMode::QUIET; }
+    inline static bool is_quiet_mode() { return mode == PrintMode::QUIET; }
+    inline static void set_difference_print() {mode = PrintMode::DIFFERENCES; }
+    inline static bool is_difference_mode() { return mode == PrintMode::DIFFERENCES; }
+
+    // For problems with the Snort2Lua code, NOT with the snort configuration
+    static void developer_error(std::string comment);
 
     // given a Snort-style string, replace all of the variables with their values.
     std::string expand_vars(const std::string&);
@@ -90,11 +92,9 @@ public:
     void print_errors(std::ostream&);
     void print_data(std::ostream&);
     void print_comments(std::ostream& out);
-    // For problems with the Snort2Lua code, NOT with the snort configuration
-    void developer_error(std::string comment);
 
     // have there been any failed conversion?
-    bool failed_conversions();
+    bool failed_conversions() const;
     // is there any actual data to print?
     bool empty()
     { return (vars.size() != 0 || includes.size() != 0);}
@@ -137,7 +137,9 @@ private:
     };
 
     // actual configuration information
-    PrintMode mode;
+    static PrintMode mode;
+    static unsigned int dev_warnings;
+
     std::vector<Variable*> vars;
     std::vector<Include*> includes;
     Comments* comments;
index 6291b4eeb8febef768f4f61b89139070a15ca9eb..5941089d4fc32c526bd39dcd9e878ec48f03c067 100644 (file)
@@ -32,8 +32,6 @@
 #include "data/data_types/dt_rule_suboption.h"
 
 
-RuleApi rule_api;
-
 RuleApi::RuleApi()
     :   curr_rule(nullptr),
         curr_data_bad(false)
@@ -57,7 +55,7 @@ void RuleApi::reset_state()
     curr_data_bad = false;
 }
 
-bool RuleApi::failed_conversions()
+bool RuleApi::failed_conversions() const
 { return !bad_rules->empty(); }
 
 void RuleApi::begin_rule()
@@ -140,7 +138,7 @@ bool RuleApi::add_rule_option_before_selected(std::string keyword,
 
     if (!curr_rule_opt)
     {
-        data_api.developer_error("Select an option before placing a "
+        DataApi::developer_error("Select an option before placing a "
                 "new option before selected option");
         return false;
     }
@@ -153,7 +151,7 @@ bool RuleApi::add_suboption(std::string keyword)
     if (curr_rule_opt)
         return curr_rule_opt->add_suboption(keyword);
 
-    data_api.developer_error("Select an option before adding a suboption!!");
+    DataApi::developer_error("Select an option before adding a suboption!!");
     return false;
 }
 
@@ -163,7 +161,7 @@ bool RuleApi::add_suboption(std::string keyword,
     if (curr_rule_opt)
         return curr_rule_opt->add_suboption(keyword, val);
 
-    data_api.developer_error("Select an option before adding a suboption!!");
+    DataApi::developer_error("Select an option before adding a suboption!!");
     return false;
 }
 
@@ -176,11 +174,11 @@ bool RuleApi::select_option(std::string opt_name)
         if (curr_rule_opt != nullptr)
             return true;
         else
-            data_api.developer_error("Option " + opt_name + "never created for following rule:");
+            DataApi::developer_error("Option " + opt_name + "never created for following rule:");
     }
     else
     {
-        data_api.developer_error("Must begin a rule before selecting an option!");
+        DataApi::developer_error("Must begin a rule before selecting an option!");
     }
 
     return false;
@@ -201,7 +199,7 @@ void RuleApi::add_comment_to_rule(std::string comment)
 
 std::ostream& operator<<( std::ostream &out, const RuleApi& data)
 {
-    if (data_api.is_default_mode())
+    if (DataApi::is_default_mode())
     {
         if (!data.bad_rules->empty())
             out << (*data.bad_rules) << "\n";
@@ -232,7 +230,7 @@ void RuleApi::print_rules(std::ostream& out, bool in_rule_file)
 
 void RuleApi::print_rejects(std::ostream& out)
 {
-    if (data_api.is_default_mode())
+    if (DataApi::is_default_mode())
     {
         if (!bad_rules->empty())
             out << (*bad_rules) << "\n\n";
index beeee6534f96cc1b3cf328e0c4b512186ceb5bdf..c1b55d79f4e0782263bf066aab4f42cdba11496c 100644 (file)
@@ -38,9 +38,9 @@
  * creating new convesion states.  There are comments in
  * in all caps which show the seperate the sections.
  *
- * The first section of this file is really LuaData creation
+ * The first section of this file is really DataApi creation
  * and initialization, and adding miscelaneous objects
- * to the LuaData data.  The second section is for creating
+ * to the DataApi data.  The second section is for creating
  * tables and their options.  The third section is for
  * creating rules.
  */
@@ -49,8 +49,6 @@ class Rule;
 class RuleOption;
 class Comments;
 class RuleApi;
-extern RuleApi rule_api;
-
 
 
 class RuleApi
@@ -61,7 +59,7 @@ public:
     virtual ~RuleApi();
 
 
-    bool failed_conversions();
+    bool failed_conversions() const;
 
     inline bool empty()
     { return (rules.size() == 0); }
index 43f0fd6dab3070da4a192b2f51d38417d97dee7c..42aa315a54fae9af308d8f14a23d13a93833502b 100644 (file)
@@ -35,9 +35,6 @@
 
 
 
-TableApi table_api;
-
-
 
 TableApi::TableApi() :  curr_data_bad(false) {}
 
@@ -97,7 +94,7 @@ void TableApi::open_table()
     // if no open tables, create a top-level table
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("A nameless table must be nested inside a table!!");
+        DataApi::developer_error("A nameless table must be nested inside a table!!");
     }
     else
     {
@@ -109,7 +106,7 @@ void TableApi::open_table()
 void TableApi::close_table()
 {
     if (open_tables.size() == 0)
-        data_api.developer_error("No open tables to close!!");
+        DataApi::developer_error("No open tables to close!!");
     else
         open_tables.pop();
 }
@@ -119,7 +116,7 @@ bool TableApi::add_option(const std::string option_name, const std::string val)
 {
     if(open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding an option!!: " +
+        DataApi::developer_error("Must open table before adding an option!!: " +
             option_name + " = " + val);
         return false;
     }
@@ -133,7 +130,7 @@ bool TableApi::add_option(const std::string option_name, const int val)
 {
     if(open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding an option!!: " +
+        DataApi::developer_error("Must open table before adding an option!!: " +
             option_name + " = " + std::to_string(val));
         return false;
     }
@@ -147,7 +144,7 @@ bool TableApi::add_option(const std::string option_name, const bool val)
 {
     if(open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding an option!!: " +
+        DataApi::developer_error("Must open table before adding an option!!: " +
             option_name + " = " + std::to_string(val));
         return false;
     }
@@ -166,7 +163,7 @@ bool TableApi::add_list(std::string list_name, std::string next_elem)
 {
     if(open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding an option!!: " +
+        DataApi::developer_error("Must open table before adding an option!!: " +
             list_name + " = " + next_elem);
         return false;
     }
@@ -180,7 +177,7 @@ bool TableApi::add_list(std::string list_name, std::string next_elem)
     }
     else
     {
-        data_api.developer_error("Must open table before adding an list!!: " +
+        DataApi::developer_error("Must open table before adding an list!!: " +
             list_name + " += " + next_elem);
         return false;
     }
@@ -190,10 +187,10 @@ bool TableApi::add_comment(std::string comment)
 {
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding comment !!: '" +
+        DataApi::developer_error("Must open table before adding comment !!: '" +
             comment + "'");
-        data_api.developer_error("comment added to as a general lua comment");
-        data_api.add_comment(comment);
+        DataApi::developer_error("comment added to as a general lua comment");
+//        data_api.add_comment(comment);
         return false;
     }
 
@@ -205,7 +202,7 @@ bool TableApi::option_exists(const std::string name)
 {
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before calling option_exists() !!");
+        DataApi::developer_error("Must open table before calling option_exists() !!");
         return false;
     }
 
@@ -219,7 +216,7 @@ bool TableApi::add_diff_option_comment(std::string orig_var, std::string new_var
 
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("Must open table before adding an option!!: " +
+        DataApi::developer_error("Must open table before adding an option!!: " +
             orig_var + " = " + new_var);
         return false;
     }
@@ -235,7 +232,7 @@ bool TableApi::add_deleted_comment(std::string dep_var)
 
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("Must open a table before adding "
+        DataApi::developer_error("Must open a table before adding "
             "deprecated comment!!: " + dep_var);
         return false;
     }
@@ -251,7 +248,7 @@ bool TableApi::add_unsupported_comment(std::string unsupported_var)
 
     if (open_tables.size() == 0)
     {
-        data_api.developer_error("Must open a tablebefore adding an "
+        DataApi::developer_error("Must open a tablebefore adding an "
             "'unsupported' comment");
         return false;
     }
index 403bea5fe7cac2ec8ec97d2268dcf442ae29daae..47be76655a592762ee69f596e5392f491e6fe6ab 100644 (file)
@@ -39,9 +39,9 @@
 * creating new convesion states.  There are comments in
 * in all caps which show the seperate the sections.
 *
-* The first section of this file is really LuaData creation
+* The first section of this file is really DataApi creation
 * and initialization, and adding miscelaneous objects
-* to the LuaData data.  The second section is for creating
+* to the DataApi data.  The second section is for creating
 * tables and their options.  The third section is for
 * creating rules.
 */
@@ -49,7 +49,6 @@
 
 class Table;
 class TableApi;
-extern TableApi table_api;
 
 class TableApi
 {
index e99f904ba303190b85fdad0b5f8cedcbfd2c0955..dff4d2dab6878066eb743e12cd9a14250ebbc4f8 100644 (file)
@@ -30,7 +30,7 @@
 #include "data/dt_data.h"
 
 
-InitState::InitState() : ConversionState() {}
+InitState::InitState(Converter& c) : ConversionState(c) {}
 
 bool InitState::convert(std::istringstream& data_stream)
 {
@@ -41,7 +41,7 @@ bool InitState::convert(std::istringstream& data_stream)
         const ConvertMap *map = util::find_map(keywords::keywords_api, keyword);
         if (map)
         {
-            cv.set_state(map->ctor());
+            cv.set_state(map->ctor(cv));
             return true;
         }
 
index 329ead3ecefaff6a7b088140cfd480198b9344df..471e928a333c83e3fa5476a242e9c87f9963aa23 100644 (file)
 class InitState : public ConversionState
 {
 public:
-    InitState();
+    InitState(Converter&);
     virtual ~InitState() {};
     virtual bool convert(std::istringstream& data);
 
 };
 
 
-static inline ConversionState* init_state_ctor()
+static inline ConversionState* init_state_ctor(Converter& c)
 {
-    return new InitState();
+    return new InitState(c);
 }
 
 #endif
index 6d755ecdd6c165bd87a3b1ce58636094dbfb409f..db955a874c823e8f80305b49f43b0e8ab208d72b 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class AttributeTable : public ConversionState
 {
 public:
-    AttributeTable() : ConversionState() {};
+    AttributeTable(Converter& c) : ConversionState(c) {};
     virtual ~AttributeTable() {};
     virtual bool convert(std::istringstream& data);
 
@@ -474,10 +474,8 @@ bool AttributeTable::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new AttributeTable();
-}
+static ConversionState* ctor(Converter& c)
+{ return new AttributeTable(c); }
 
 static const ConvertMap attribute_table_api =
 {
index 19a74e2af4adcadbe54c57f866646d92237aa734..02c569d2de6e558a9298405f520b4d7bc4f3bcd3 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Config : public ConversionState
 {
 public:
-    Config() : ConversionState() {};
+    Config(Converter& c) : ConversionState(c) {};
     virtual ~Config() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -56,7 +56,7 @@ bool Config::convert(std::istringstream& data_stream)
         const ConvertMap* map = util::find_map(config::config_api, keyword);
         if (map)
         {
-            cv.set_state(map->ctor());
+            cv.set_state(map->ctor(cv));
             return true;
         }
 
@@ -74,10 +74,8 @@ bool Config::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Config();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Config(c); }
 
 static const ConvertMap keyword_config = 
 {
index 3225be778804a50bf965cf47aaef4954d8ef4e9c..a8719a6a93fd11e8739861dfebb2be32528d5181 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class EventFilter : public ConversionState
 {
 public:
-    EventFilter() : ConversionState() {};
+    EventFilter(Converter& c) : ConversionState(c) {};
     virtual ~EventFilter() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -105,10 +105,8 @@ bool EventFilter::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new EventFilter();
-}
+static ConversionState* ctor(Converter& c)
+{ return new EventFilter(c); }
 
 static const ConvertMap event_filter_api =
 {
index ca8e34f9823aeac850746e9c4393119f1a79ee26..e3a3ddb312ab1c1c86bf9cc2889e025cd1fde7f4 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class File : public ConversionState
 {
 public:
-    File() : ConversionState() {};
+    File(Converter& c) : ConversionState(c) {};
     virtual ~File() {};
     virtual bool convert(std::istringstream& data);
 
@@ -69,10 +69,8 @@ bool File::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new File();
-}
+static ConversionState* ctor(Converter& c)
+{ return new File(c); }
 
 static const ConvertMap keyword_file =
 {
index fe409c8211cd1426a4097b149d07b6bbed8e71b1..3e7a2e2b4bd632c65edbe3045c4105643ecdce5d 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Include : public ConversionState
 {
 public:
-    Include() : ConversionState() {};
+    Include(Converter& c) : ConversionState(c) {};
     virtual ~Include() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -83,10 +83,8 @@ bool Include::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Include();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Include(c); }
 
 static const ConvertMap keyword_include = 
 {
index 278a18d12f7349011346ec1cc68621dce2dc38f9..8565163dd936c5df8624f70298f6a63730048aeb 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Output : public ConversionState
 {
 public:
-    Output() : ConversionState() {};
+    Output(Converter& c) : ConversionState(c) {};
     virtual ~Output() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -55,7 +55,7 @@ bool Output::convert(std::istringstream& data_stream)
         const ConvertMap* map = util::find_map(output::output_api, keyword);
         if (map)
         {
-            cv.set_state(map->ctor());
+            cv.set_state(map->ctor(cv));
             return true;
         }
     }
@@ -67,10 +67,8 @@ bool Output::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Output();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Output(c); }
 
 static const ConvertMap keyword_output = 
 {
index f2c49b03425bd2d1fdad909570059543dcc9c1d7..3b1d21d96991539857a46087de3d23154783dbf1 100644 (file)
@@ -36,7 +36,7 @@ template<const std::string *snort_option>
 class Paths : public ConversionState
 {
 public:
-    Paths() : ConversionState() {};
+    Paths(Converter& c) : ConversionState(c) {};
 
     virtual ~Paths() {};
     virtual bool convert(std::istringstream& data_stream)
@@ -82,10 +82,8 @@ public:
 
 
 template<const std::string *snort_option>
-static ConversionState* paths_ctor()
-{
-    return new Paths<snort_option>();
-}
+static ConversionState* paths_ctor(Converter& c)
+{ return new Paths<snort_option>(c); }
 
 } // namespace
 
index 2ee47f045cd731f5467cad393175711da13e0bbe..e12820597608a665698d843a0ef6151546d420e9 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Preprocessor : public ConversionState
 {
 public:
-    Preprocessor() : ConversionState() {};
+    Preprocessor(Converter& c) : ConversionState(c) {};
     virtual ~Preprocessor() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -53,7 +53,7 @@ bool Preprocessor::convert(std::istringstream& data_stream)
         const ConvertMap* map = util::find_map(preprocessors::preprocessor_api, keyword);
         if (map)
         {
-            cv.set_state(map->ctor());
+            cv.set_state(map->ctor(cv));
             return true;
         }
         data_api.failed_conversion(data_stream, keyword);
@@ -70,10 +70,8 @@ bool Preprocessor::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Preprocessor();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Preprocessor(c); }
 
 static const ConvertMap keyword_preprocessor = 
 {
index 32ed2608b4b4bdaa9e9b45bc6ce088f3979fb631..acb945679a733b29fc0cc2fae053a7c78ffec7e3 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class RateFilter : public ConversionState
 {
 public:
-    RateFilter() : ConversionState() {};
+    RateFilter(Converter& c) : ConversionState(c) {};
     virtual ~RateFilter() {};
     virtual bool convert(std::istringstream& data);
 
@@ -151,10 +151,8 @@ bool RateFilter::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new RateFilter();
-}
+static ConversionState* ctor(Converter& c)
+{ return new RateFilter(c); }
 
 static const ConvertMap keyword_rate_filter =
 {
index 60c7044021ef1c0b582fcc2a49a1ebfff03242f0..f56ba6634cbaeaf0c4e43b075422d9e9189be7a5 100644 (file)
@@ -38,7 +38,7 @@ namespace
 class RuleHeader : public ConversionState
 {
 public:
-    explicit RuleHeader() : ConversionState() {};
+    explicit RuleHeader(Converter& c) : ConversionState(c) {};
     virtual ~RuleHeader() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -79,19 +79,19 @@ bool RuleHeader::convert(std::istringstream& data_stream)
  ********************************/
 
 template<const std::string *name>
-static ConversionState* rule_ctor()
+static ConversionState* rule_ctor(Converter& c)
 {
-    rule_api.add_hdr_data(*name);
-    return new RuleHeader();
+    c.get_rule_api().add_hdr_data(*name);
+    return new RuleHeader(c);
 }
 
 template<const std::string *name>
-static ConversionState* dep_rule_ctor()
+static ConversionState* dep_rule_ctor(Converter& c)
 {
-    rule_api.add_hdr_data(*name);
-    rule_api.make_rule_a_comment();
-    rule_api.add_comment_to_rule("The '" + *name + "' ruletype is no longer supported");
-    return new RuleHeader();
+    c.get_rule_api().add_hdr_data(*name);
+    c.get_rule_api().make_rule_a_comment();
+    c.get_rule_api().add_comment_to_rule("The '" + *name + "' ruletype is no longer supported");
+    return new RuleHeader(c);
 }
 
 static const std::string alert = "alert";
index e32a7e14d748afc6e6f5964678a8b2ee4a9167ae..95585207337f7545d1cde083b20fafa799e6ea96 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class RuleState : public ConversionState
 {
 public:
-    RuleState() : ConversionState() {};
+    RuleState(Converter& c) : ConversionState(c) {};
     virtual ~RuleState() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -101,10 +101,8 @@ bool RuleState::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new RuleState();
-}
+static ConversionState* ctor(Converter& c)
+{ return new RuleState(c); }
 
 static const ConvertMap rule_state_api =
 {
index 00c272fded66fcc439345ea8e1c50b2321958a4d..56276ed793215912217d9a5b1e4f624e3aebca6c 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class RuleType : public ConversionState
 {
 public:
-    RuleType() : ConversionState() {};
+    RuleType(Converter& c) : ConversionState(c) {};
     virtual ~RuleType() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -68,10 +68,8 @@ bool RuleType::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new RuleType();
-}
+static ConversionState* ctor(Converter& c)
+{ return new RuleType(); }
 
 static const ConvertMap keyword_ruletype = 
 {
index 25334cd310e8e333bace2cf19ab213d36b283e1c..be5f50fe7983d076388e62d1f49ac5af37671cde 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Suppress : public ConversionState
 {
 public:
-    Suppress() : ConversionState() {};
+    Suppress(Converter& c) : ConversionState(c) {};
     virtual ~Suppress() {};
     virtual bool convert(std::istringstream& data);
 
@@ -135,10 +135,8 @@ bool Suppress::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Suppress();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Suppress(c); }
 
 static const ConvertMap keyword_supress =
 {
index fb6ea451085ecd73f9ed4705a3fe67a65c47e891..33c94d9c8d7d42cb1e186a570de376eaa26d02e5 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class Var : public ConversionState
 {
 public:
-    Var() : ConversionState(){}
+    Var(Converter& c) : ConversionState(c){}
     virtual ~Var() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -87,10 +87,8 @@ bool Var::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
-{
-    return new Var();
-}
+static ConversionState* ctor(Converter& c)
+{ return new Var(c); }
 
 static const ConvertMap keyword_portvar = 
 {
index 81710a060e811f4170391c77633007239e130d33..fef1a9bf95d9c636f3adbeec08914ed8021438b3 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class AlertCsv : public ConversionState
 {
 public:
-    AlertCsv() : ConversionState() {};
+    AlertCsv(Converter& c) : ConversionState(c) {};
     virtual ~AlertCsv() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -246,11 +246,11 @@ bool AlertCsv::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("alert_csv"); // in case there are no arguments
-    table_api.close_table();
-    return new AlertCsv();
+    c.get_table_api().open_top_level_table("alert_csv"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new AlertCsv(c);
 }
 
 static const ConvertMap alert_csv_api =
index 7e455c128c2bc36a1c4b41a77e12b37df997e2e1..5c8df19f61b004d41a8ba581fbddec34878f2df7 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class AlertFast : public ConversionState
 {
 public:
-    AlertFast() : ConversionState() {};
+    AlertFast(Converter& c) : ConversionState(c) {};
     virtual ~AlertFast() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -101,11 +101,11 @@ bool AlertFast::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("alert_fast"); // in case there are no arguments
-    table_api.close_table();
-    return new AlertFast();
+    c.get_table_api().open_top_level_table("alert_fast"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new AlertFast(c);
 }
 
 static const ConvertMap alert_fast_api =
index 6f8df7c342d7118adcf71b7354d212d740bb4abc..802fe503a285324a24b8beb2db4ca5c79c5136ac 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class AlertFull : public ConversionState
 {
 public:
-    AlertFull() : ConversionState() {};
+    AlertFull(Converter& c) : ConversionState(c) {};
     virtual ~AlertFull() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -86,11 +86,11 @@ bool AlertFull::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("alert_full"); // in case there are no arguments
-    table_api.close_table();
-    return new AlertFull();
+    c.get_table_api().open_top_level_table("alert_full"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new AlertFull(c);
 }
 
 static const ConvertMap alert_full_api =
index f2a205b8ba886de828d8f0fde4d5128a6be82947..4a7b217f47e4f12328821ebfce33f36b1ef77950 100644 (file)
 namespace output
 {
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_table("alert_null"); // in case there are no arguments
-    table_api.close_table();
+    c.get_table_api().open_table("alert_null");
+    c.get_table_api().close_table();
     return nullptr;
 }
 
index 99ca77fc1472d0664e20a9ad2f8013797537edde..c2a1d8162a44ce032e42d28c9af16429653f1bf9 100644 (file)
@@ -36,7 +36,7 @@ namespace
 class AlertSyslog : public ConversionState
 {
 public:
-    AlertSyslog() : ConversionState() {};
+    AlertSyslog(Converter& c) : ConversionState(c) {};
     virtual ~AlertSyslog() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -240,11 +240,11 @@ bool AlertSyslog::convert(std::istringstream& data_stream)
 }
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("alert_syslog"); // in case there are no arguments
-    table_api.close_table();
-    return new AlertSyslog();
+    c.get_table_api().open_top_level_table("alert_syslog"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new AlertSyslog(c);
 }
 
 
index c79a62d17b8847351d814ef27b15f3b98e598c9b..b5557f800235575871f92d351cb43d250abc2813 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class LogTcpDump : public ConversionState
 {
 public:
-    LogTcpDump() : ConversionState() {};
+    LogTcpDump(Converter& c) : ConversionState(c) {};
     virtual ~LogTcpDump() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -86,11 +86,11 @@ bool LogTcpDump::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("log_tcpdump"); // in case there are no arguments
-    table_api.close_table();
-    return new LogTcpDump();
+    c.get_table_api().open_top_level_table("log_tcpdump"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new LogTcpDump(c);
 }
 
 static const ConvertMap log_tcpdump_api =
index a2f5fa3ea041563c73d4a8cf24628eabd575bc2c..4a7e3856749e80cc4611bd6d58d6adaeacea34a5 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class AlertTest : public ConversionState
 {
 public:
-    AlertTest() : ConversionState() {};
+    AlertTest(Converter& c) : ConversionState(c) {};
     virtual ~AlertTest() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -98,11 +98,11 @@ bool AlertTest::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_top_level_table("alert_test"); // in case there are no arguments
-    table_api.close_table();
-    return new AlertTest();
+    c.get_table_api().open_top_level_table("alert_test"); // in case there are no arguments
+    c.get_table_api().close_table();
+    return new AlertTest(c);
 }
 
 static const ConvertMap alert_test_api =
index 50accef79e72e859b9039bdbb8f941ed6a2c6e63..e6a9d275a9074ab09dbaefaca8c94dc80c114b42 100644 (file)
@@ -36,7 +36,7 @@ template<const std::string* output_name>
 class Unified2 : public ConversionState
 {
 public:
-    Unified2() : ConversionState() {};
+    Unified2(Converter& c) : ConversionState(c) {};
     virtual ~Unified2() {};
 
     virtual bool convert(std::istringstream& data_stream)
@@ -90,11 +90,11 @@ public:
 };
 
 template<const std::string* output_name>
-static ConversionState* unified2_ctor()
+static ConversionState* unified2_ctor(Converter& c)
 {
-    table_api.open_top_level_table("unified2"); // create table in case there are no arguments
-    table_api.close_table();
-    return new Unified2<output_name>();
+    c.get_table_api().open_top_level_table("unified2"); // create table in case there are no arguments
+    c.get_table_api().close_table();
+    return new Unified2<output_name>(c);
 }
 
 } // namespace
index 435b25aac45e2afb43e16e8fb99b1dae9329fb5f..a15ebfde92f7368d8f95655c1165a7339a40a73e 100644 (file)
 namespace output
 {
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    table_api.open_table("alert_unixsock"); // in case there are no arguments
-    table_api.close_table();
+    c.get_table_api().open_table("alert_unixsock");
+    c.get_table_api().close_table();
     return nullptr;
 }
 
index 626de0a64167016c569cb7759fae9780b13f9225..aac4a0f1b90505d97e9d96c5ca8cf0e302a5f6f9 100644 (file)
@@ -33,7 +33,7 @@ namespace {
 class ArpSpoof : public ConversionState
 {
 public:
-    ArpSpoof() : ConversionState() {};
+    ArpSpoof(Converter& c) : ConversionState(c) {};
     virtual ~ArpSpoof() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -70,9 +70,9 @@ bool ArpSpoof::convert(std::istringstream& data_stream)
 
 /*******  A P I ***********/
 
-static ConversionState* arpspoof_ctor()
+static ConversionState* arpspoof_ctor(Converter& c)
 {
-    return new ArpSpoof();
+    return new ArpSpoof(c);
 }
 
 static const ConvertMap preprocessor_arpspoof = 
@@ -95,7 +95,7 @@ namespace {
 class ArpSpoofHost : public ConversionState
 {
 public:
-    ArpSpoofHost() : ConversionState() {};
+    ArpSpoofHost(Converter& c) : ConversionState(c) {};
     virtual ~ArpSpoofHost() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -131,9 +131,9 @@ bool ArpSpoofHost::convert(std::istringstream& data_stream)
 
 /*******  A P I ***********/
 
-static ConversionState* arpspoof_host_ctor()
+static ConversionState* arpspoof_host_ctor(Converter& c)
 {
-    return new ArpSpoofHost();
+    return new ArpSpoofHost(c);
 }
 
 static const ConvertMap preprocessor_arpspoof_host = 
index b658443b4c4f6405f3d9f1ffdf5d4417d488601b..57d8ec8fa73509e0aa9c2d862075a999284a57e2 100644 (file)
 namespace preprocessors
 {
 
-static ConversionState* bo_ctor()
+static ConversionState* bo_ctor(Converter& c)
 {
-    table_api.open_table("bo");
-    table_api.close_table();
+    c.get_table_api().open_table("bo");
+    c.get_table_api().close_table();
     return nullptr;
 }
 
index fe825f8e721fae189d2c73dac7f17b49d3e15edb..30bd8ae18365e83d0086021ed79beb1c4b202a65 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Frag3Engine : public ConversionState
 {
 public:
-    explicit Frag3Engine() : ConversionState() {};
+    explicit Frag3Engine(Converter& c) : ConversionState(c) {};
     virtual ~Frag3Engine() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -179,9 +179,9 @@ bool Frag3Engine::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Frag3Engine();
+    return new Frag3Engine(c);
 }
 
 static const ConvertMap preprocessor_frag3_engine =
index 9e4bc06ce3c566f631ad90f508a330176fb00122..df0986493943a7b4de18821f968a3eb216c3499a 100644 (file)
@@ -32,7 +32,7 @@ namespace {
 class Frag3Global : public ConversionState
 {
 public:
-    Frag3Global() : ConversionState() {};
+    Frag3Global(Converter& c) : ConversionState(c) {};
     virtual ~Frag3Global() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -90,9 +90,9 @@ bool Frag3Global::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Frag3Global();
+    return new Frag3Global(c);
 }
 
 static const ConvertMap preprocessor_frag3_global =
index 7936ef2d0a51e4227edca31607c68faf6b666033..39061f5483b1fa3d84fee267cf5359a1fdf7f694 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class FtpTelnet : public ConversionState
 {
 public:
-    FtpTelnet() : ConversionState() {};
+    FtpTelnet(Converter& c) : ConversionState(c) {};
     virtual ~FtpTelnet() {};
     virtual bool convert(std::istringstream& data_stream);
 private:
@@ -129,9 +129,9 @@ bool FtpTelnet::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new FtpTelnet();
+    return new FtpTelnet(c);
 }
 
 static const ConvertMap preprocessor_ftptelnet = 
index 2ea46c56b370720bbf4d5c4c95d9e0bca57dd54e..291ed83a3a4aab6a9cbb8a4297b8ea1b53082412 100644 (file)
@@ -39,8 +39,8 @@ namespace {
 class FtpServer : public ConversionState
 {
 public:
-    FtpServer();
-    virtual ~FtpServer() {};
+    FtpServer(Converter& c) : ConversionState(c) { }
+    virtual ~FtpServer() { }
     virtual bool convert(std::istringstream& data_stream);
 private:
     struct Command
@@ -73,9 +73,6 @@ private:
 int FtpServer::ftpsever_binding_id = 1;
 
 
-FtpServer::FtpServer() : ConversionState()
-{}
-
 std::vector<FtpServer::Command>::iterator FtpServer::get_command(
                             std::string cmd_name,
                             std::vector<FtpServer::Command>::iterator it)
@@ -189,7 +186,7 @@ bool FtpServer::convert(std::istringstream& data_stream)
 {
     std::string keyword;
     bool retval = true;
-    Binder bind;
+    Binder bind(table_api);
     bind.set_use_type("ftp_server");
     bind.set_when_proto("tcp");
 
@@ -352,7 +349,7 @@ namespace
 class FtpClient : public ConversionState
 {
 public:
-    FtpClient() : ConversionState() {};
+    FtpClient(Converter& c) : ConversionState(c) {};
     virtual ~FtpClient() {};
     virtual bool convert(std::istringstream& data_stream);
 private:
@@ -367,7 +364,7 @@ bool FtpClient::convert(std::istringstream& data_stream)
 {
     std::string keyword;
     bool retval = true;
-    Binder bind;
+    Binder bind(table_api);
     bind.set_use_type("ftp_client");
     bind.set_when_proto("tcp");
 
@@ -491,7 +488,7 @@ namespace
 class Telnet : public ConversionState
 {
 public:
-    Telnet() : ConversionState() {};
+    Telnet(Converter& c) : ConversionState(c) {};
     virtual ~Telnet() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -503,7 +500,7 @@ bool Telnet::convert(std::istringstream& data_stream)
     std::string keyword;
     int i_val;
     bool retval = true;
-    Binder bind;
+    Binder bind(table_api);
 
     bind.set_when_proto("tcp");
     bind.set_use_type("telnet");
@@ -561,7 +558,7 @@ namespace {
 class FtpTelnetProtocol : public ConversionState
 {
 public:
-    FtpTelnetProtocol() : ConversionState() {};
+    FtpTelnetProtocol(Converter& c) : ConversionState(c) {};
     virtual ~FtpTelnetProtocol() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -577,17 +574,17 @@ bool FtpTelnetProtocol::convert(std::istringstream& data_stream)
     {
         if(!protocol.compare("telnet"))
         {
-            cv.set_state(new Telnet());
+            cv.set_state(new Telnet(cv));
         }
         else if (!protocol.compare("ftp"))
         {
             if(data_stream >> protocol)
             {
                 if(!protocol.compare("client"))
-                    cv.set_state(new FtpClient());
+                    cv.set_state(new FtpClient(cv));
 
                 else if (!protocol.compare("server"))
-                    cv.set_state(new FtpServer());
+                    cv.set_state(new FtpServer(cv));
 
                 else
                     return false;
@@ -604,9 +601,9 @@ bool FtpTelnetProtocol::convert(std::istringstream& data_stream)
 
 /*******  PUBLIC API ************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new FtpTelnetProtocol();
+    return new FtpTelnetProtocol(c);
 }
 
 static const ConvertMap ftptelnet_protocol_preprocessor = 
index dfdf535b5a3222f693fb8025c8427fb5239bf768..5f1237d330640d6e1748bf07488067cc49c70055 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class Gtp : public ConversionState
 {
 public:
-    Gtp() : ConversionState() {};
+    Gtp(Converter& c) : ConversionState(c) {};
     virtual ~Gtp() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -85,9 +85,9 @@ bool Gtp::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Gtp();
+    return new Gtp(c);
 }
 
 static const ConvertMap preprocessor_gtp =
index 199688ca878f27b20740c77ea5576213032d03a0..ba83409d70db5f9e6f9e419442eafa84f3a2857a 100644 (file)
@@ -35,8 +35,8 @@ namespace {
 class HttpInspect : public ConversionState
 {
 public:
-    HttpInspect();
-    virtual ~HttpInspect() {};
+    HttpInspect(Converter& c) : ConversionState(c) { }
+    virtual ~HttpInspect() {}
     virtual bool convert(std::istringstream& data);
 
 private:
@@ -45,10 +45,6 @@ private:
 
 } // namespace
 
-
-HttpInspect::HttpInspect() : ConversionState()
-{}
-
 bool HttpInspect::convert(std::istringstream& data_stream)
 {
     std::string keyword;
@@ -170,9 +166,9 @@ bool HttpInspect::add_decode_option(std::string opt_name,  std::istringstream& s
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new HttpInspect();
+    return new HttpInspect(c);
 }
 
 static const ConvertMap preprocessor_httpinspect = 
index 8a3aac5bbadda61bd641e3a175dac24f78dd8d1d..5848453d395b7dbd34a23da98e645aacb0759a2f 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class HttpInspectServer : public ConversionState
 {
 public:
-    HttpInspectServer() : ConversionState() {};
+    HttpInspectServer(Converter& c) : ConversionState(c) {};
     virtual ~HttpInspectServer() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -58,7 +58,7 @@ bool HttpInspectServer::convert(std::istringstream& data_stream)
 {
     std::string keyword;
     bool retval = true;
-    Binder bind;
+    Binder bind(table_api);
 
     bind.set_when_proto("tcp");
     bind.set_use_type("http_server");
@@ -341,22 +341,14 @@ bool HttpInspectServer::convert(std::istringstream& data_stream)
     return retval;
 }
 
-#if 0
-// check in confg
-
-
-#* decompress_swf { deflate lzma } *
-#* decompress_pdf { deflate } *
-
-#endif
 
 /**************************
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new HttpInspectServer();
+    return new HttpInspectServer(c);
 }
 
 static const ConvertMap preprocessor_httpinsepct_server = 
index 93f2f5c86d2e0013cdf3a2a440ca0f1cae9401eb..ce017d674408f05a5675aca0305746e18461afb9 100644 (file)
@@ -32,12 +32,12 @@ namespace preprocessors
 
 
 template<const std::string *norm_option>
-static ConversionState* norm_sans_options_ctor()
+static ConversionState* norm_sans_options_ctor(Converter& c)
 {
-    table_api.open_table("normalize");
-    table_api.add_diff_option_comment("preprocessor normalize_" + *norm_option, *norm_option + " = <bool>");
-    table_api.add_option(*norm_option, true);
-    table_api.close_table();
+    c.get_table_api().open_table("normalize");
+    c.get_table_api().add_diff_option_comment("preprocessor normalize_" + *norm_option, *norm_option + " = <bool>");
+    c.get_table_api().add_option(*norm_option, true);
+    c.get_table_api().close_table();
     return nullptr;
 }
 
@@ -91,7 +91,7 @@ namespace {
 class Ip4Normalizer : public ConversionState
 {
 public:
-    Ip4Normalizer() : ConversionState() {};
+    Ip4Normalizer(Converter& c) : ConversionState(c) {};
     virtual ~Ip4Normalizer() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -138,9 +138,9 @@ bool Ip4Normalizer::convert(std::istringstream& data_stream)
 
 /*******  A P I ***********/
 
-static ConversionState* ip4_ctor()
+static ConversionState* ip4_ctor(Converter& c)
 {
-    return new Ip4Normalizer();
+    return new Ip4Normalizer(c);
 }
 
 static const ConvertMap preprocessor_norm_ip4 = 
@@ -160,7 +160,7 @@ namespace {
 class TcpNormalizer : public ConversionState
 {
 public:
-    TcpNormalizer() : ConversionState() {};
+    TcpNormalizer(Converter& c) : ConversionState(c) {};
     virtual ~TcpNormalizer() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -312,9 +312,9 @@ bool TcpNormalizer::convert(std::istringstream& data_stream)
 
 /*******  A P I ***********/
 
-static ConversionState* tcp_ctor()
+static ConversionState* tcp_ctor(Converter& c)
 {
-    return new TcpNormalizer();
+    return new TcpNormalizer(c);
 }
 
 static const ConvertMap preprocessor_norm_tcp = 
index 914a95f50a97169b2732458df4a33e8efc98464c..7f56c156788b332351ccd0c9f7fab41dc2300bba 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class PerfMonitor : public ConversionState
 {
 public:
-    PerfMonitor() : ConversionState() {};
+    PerfMonitor(Converter& c) : ConversionState(c) {};
     virtual ~PerfMonitor() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -183,9 +183,9 @@ bool PerfMonitor::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new PerfMonitor();
+    return new PerfMonitor(c);
 }
 
 static const ConvertMap keyword_perfmonitor = 
index 52c6fa207c8d08ab824f6818696771803ccd5dde..8a4df8140b3e23e31016ab8167515b442e1f6f8f 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class RpcDecode : public ConversionState
 {
 public:
-    RpcDecode() : ConversionState() {};
+    RpcDecode(Converter& c) : ConversionState(c) {};
     virtual ~RpcDecode() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -49,7 +49,7 @@ bool RpcDecode::convert(std::istringstream& data_stream)
     std::string keyword;
 
     // adding the binder entry
-    Binder bind;
+    Binder bind(table_api);
     bind.set_when_proto("tcp");
     bind.set_use_type("rpc_decode");
     std::string port_list = std::string();
@@ -92,9 +92,9 @@ bool RpcDecode::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new RpcDecode();
+    return new RpcDecode(c);
 }
 
 static const ConvertMap preprocessor_rpc_decode =
index fcb5bfd33bd58fe66ebf6f4ba2b9dd3b2cb1298e..a1a5c8e0f057e544549d6d9bad8e490f7e27a41d 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class PortScan : public ConversionState
 {
 public:
-    PortScan() : ConversionState() {};
+    PortScan(Converter& c) : ConversionState(c) {};
     virtual ~PortScan() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -192,9 +192,9 @@ bool PortScan::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new PortScan();
+    return new PortScan(c);
 }
 
 static const ConvertMap preprocessor_sfportscan = 
index 9a4683496c106dc8d7a7b865a69b3d0c3b02fc00..a63d001e2a300cf86a44ff2a11b7da917d0858c0 100644 (file)
@@ -35,7 +35,7 @@ namespace {
 class StreamGlobal : public ConversionState
 {
 public:
-    StreamGlobal() : ConversionState() {};
+    StreamGlobal(Converter& c) : ConversionState(c) {};
     virtual ~StreamGlobal() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -211,9 +211,9 @@ bool StreamGlobal::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new StreamGlobal();
+    return new StreamGlobal(c);
 }
 
 static const ConvertMap preprocessor_stream_global = 
index fb75e6f744f999824559f041e1ad269a515aff84..b4a980178f6c799cc22f4d4da2d05eacbeb02986 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class StreamIp : public ConversionState
 {
 public:
-    StreamIp() : ConversionState() {};
+    StreamIp(Converter& c) : ConversionState(c) {};
     virtual ~StreamIp() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -82,9 +82,9 @@ bool StreamIp::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new StreamIp();
+    return new StreamIp(c);
 }
 
 static const ConvertMap preprocessor_stream_ip =
index bff24d8252af188e7cbd75773ea5b95a894d6ab9..6d417446a6ce63e5393a1e1245ef36ed6a3c4bb2 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class StreamTcp : public ConversionState
 {
 public:
-    StreamTcp();
+    StreamTcp(Converter&);
     virtual ~StreamTcp() {};
     virtual bool convert(std::istringstream& data_stream);
 
@@ -57,7 +57,7 @@ private:
 
 } // namespace
 
-StreamTcp::StreamTcp() : ConversionState()
+StreamTcp::StreamTcp(Converter& c) : ConversionState(c)
 {
     bind_client = nullptr;
     bind_server = nullptr;
@@ -264,9 +264,9 @@ bool StreamTcp::convert(std::istringstream& data_stream)
     std::string keyword;
     bool retval = true;
 
-    Binder client;
-    Binder server;
-    Binder any;
+    Binder client(table_api);
+    Binder server(table_api);
+    Binder any(table_api);
 
     // by default, only print one binding
     client.print_binding(true);
@@ -515,9 +515,9 @@ bool StreamTcp::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new StreamTcp();
+    return new StreamTcp(c);
 }
 
 static const ConvertMap preprocessor_stream_tcp = 
index f4032df19cd82007de95aef9086326fc7df769b7..17d5b24053b0cbfdb5cba206a39c5f1667ee930e 100644 (file)
@@ -34,7 +34,7 @@ namespace {
 class StreamUdp : public ConversionState
 {
 public:
-    StreamUdp() : ConversionState() {};
+    StreamUdp(Converter& c) : ConversionState(c) {};
     virtual ~StreamUdp() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -82,9 +82,9 @@ bool StreamUdp::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new StreamUdp();
+    return new StreamUdp(c);
 }
 
 static const ConvertMap preprocessor_stream_udp =
index 7807298c06c218b39198f677c96b181e6d27c442..edeb6906a721fe19b6087e83ae2cd49931d3d09e 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Base64Decode : public ConversionState
 {
 public:
-    Base64Decode() : ConversionState() {};
+    Base64Decode(Converter& c) : ConversionState(c) {};
     virtual ~Base64Decode() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -91,9 +91,9 @@ bool Base64Decode::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& cv)
 {
-    return new Base64Decode();
+    return new Base64Decode(cv);
 }
 
 static const std::string base64_decode = "base64_decode";
index af8fdb4855c8dde59d94e7cce31ea1c93d74ff2a..52528ebaeadaa85912d8b50075b850a54f547b7b 100644 (file)
@@ -37,7 +37,7 @@ template<const std::string *option_name>
 class Content : public ConversionState
 {
 public:
-    Content() : ConversionState() {};
+    Content(Converter& c) : ConversionState(c) {};
     virtual ~Content() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -194,9 +194,9 @@ bool Content<option_name>::convert(std::istringstream& data_stream)
 
 
 template<const std::string *rule_name>
-static ConversionState* content_ctor()
+static ConversionState* content_ctor(Converter& c)
 {
-    return new Content<rule_name>();
+    return new Content<rule_name>(c);
 }
 
 static const std::string content = "content";
@@ -206,11 +206,11 @@ static const std::string uricontent = "uricontent";
 
 //  Uricontent:"foo" --> http_uti; content:"foo".
 //  So, just add the 'http_uri' option first, then parse as if content
-static ConversionState* uricontent_ctor()
+static ConversionState* uricontent_ctor(Converter& c)
 {
-    rule_api.add_rule_option("http_uri");
-    rule_api.add_comment_to_rule("uricontent deprecated --> 'http_uri: content:'foo'");
-    return new Content<&content>();
+    c.get_rule_api().add_rule_option("http_uri");
+    c.get_rule_api().add_comment_to_rule("uricontent deprecated --> 'http_uri: content:'foo'");
+    return new Content<&content>(c);
 }
 
 
index 1d4d56528acb5da3a5b668af46e6e65119985462..157519120fe670cf85cdbe13dff85c308f9a532a 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class FileData : public ConversionState
 {
 public:
-    FileData() : ConversionState() {};
+    FileData(Converter& c) : ConversionState(c) {};
     virtual ~FileData() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -82,9 +82,9 @@ bool FileData::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* file_data_ctor()
+static ConversionState* file_data_ctor(Converter& c)
 {
-    return new FileData();
+    return new FileData(c);
 }
 
 static const ConvertMap rule_file_data =
index 100a517c066f176a12dc749d70a841b9603e3f6c..89dd2ba0ee8dd9c83194a5df67f1fddb80329880 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class HttpEncode : public ConversionState
 {
 public:
-    HttpEncode() : ConversionState() {};
+    HttpEncode(Converter& c) : ConversionState(c) {};
     virtual ~HttpEncode() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -56,9 +56,9 @@ bool HttpEncode::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new HttpEncode();
+    return new HttpEncode(c);
 }
 
 static const std::string http_encode = "http_encode";
index 6fd6f4c6522a31747aa85125a5f9e351ea6aa0bb..27f6f73cd1c489e0d607134c27bb8ea2cf788e5d 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Metadata : public ConversionState
 {
 public:
-    Metadata() : ConversionState() {};
+    Metadata(Converter& c) : ConversionState(c) {};
     virtual ~Metadata() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -115,9 +115,9 @@ bool Metadata::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Metadata();
+    return new Metadata(c);
 }
 
 static const std::string metadata = "metadata";
index cbbed391a82793f84468bb441039ccad1b1b53f8..20cda7bfd8f5e30ac5d2e56aa6bec7e1a37a2c20 100644 (file)
@@ -37,7 +37,7 @@ namespace {
 class Pcre : public ConversionState
 {
 public:
-    Pcre() : ConversionState() {};
+    Pcre(Converter& c) : ConversionState(c) {};
     virtual ~Pcre() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -121,9 +121,9 @@ bool Pcre::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Pcre();
+    return new Pcre(c);
 }
 
 
index a7d7adb9f738c792abb5fce3e364bd3980431284..a74a4273c58617e041bebba0ab8cea5668d588c4 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class React : public ConversionState
 {
 public:
-    React() : ConversionState() {};
+    React(Converter& c) : ConversionState(c) {};
     virtual ~React() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -147,8 +147,8 @@ bool React::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
-{ return new React(); }
+static ConversionState* ctor(Converter& c)
+{ return new React(c); }
 
 static const ConvertMap rule_react =
 {
index 6b4d79d984001be084a3ee65b1767e76501bcd2d..b73408a154b712efbcdd2038294a8b2e7cd80f3a 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Resp : public ConversionState
 {
 public:
-    Resp() : ConversionState() {};
+    Resp(Converter& c) : ConversionState(c) {};
     virtual ~Resp() {};
     virtual bool convert(std::istringstream& data);
 private:
@@ -189,8 +189,8 @@ bool Resp::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
-{ return new Resp(); }
+static ConversionState* ctor(Converter& c)
+{ return new Resp(c); }
 
 static const ConvertMap rule_resp =
 {
index 622f58a846a5da9459af553ade5475e26e561374..c4d27d2ca1877b565d0e0dcb1a1e99472e2cd27c 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Threshold : public ConversionState
 {
 public:
-    Threshold() : ConversionState() {};
+    Threshold(Converter& c) : ConversionState(c) {};
     virtual ~Threshold() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -152,9 +152,9 @@ bool Threshold::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Threshold();
+    return new Threshold(c);
 }
 
 static const ConvertMap rule_threshold =
index c46cc98e55d73f1331bdff926d9fe90145c7a4c8..ce2fee0bc203dbfe42faa93ed40868a4394551b4 100644 (file)
@@ -41,7 +41,7 @@ template<const std::string* rule_name, bool has_suboptions>
 class UnchangedRuleOption : public ConversionState
 {
 public:
-    UnchangedRuleOption() : ConversionState() {};
+    UnchangedRuleOption(Converter& c) : ConversionState(c) {};
     virtual ~UnchangedRuleOption() {};
     
     virtual bool convert(std::istringstream& stream)
@@ -64,9 +64,9 @@ public:
 
 
 template<const std::string *rule_name,  bool has_suboptions = true>
-static ConversionState* unchanged_rule_ctor()
+static ConversionState* unchanged_rule_ctor(Converter& c)
 {
-    return new UnchangedRuleOption<rule_name, has_suboptions>();
+    return new UnchangedRuleOption<rule_name, has_suboptions>(c);
 }
 
 /****************************************
index dde03b0d3be656d287e513cf7c1f666d2afe72bc..65705d86aced44b37177715c51c2bc6a0c41946a 100644 (file)
@@ -36,7 +36,7 @@ namespace {
 class Urilen : public ConversionState
 {
 public:
-    Urilen() : ConversionState() {};
+    Urilen(Converter& c) : ConversionState(c) {};
     virtual ~Urilen() {};
     virtual bool convert(std::istringstream& data);
 };
@@ -90,9 +90,9 @@ bool Urilen::convert(std::istringstream& data_stream)
  **************************/
 
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new Urilen();
+    return new Urilen(c);
 }
 
 static const std::string urilen = "urilen";
index 8a496376ff45121a5a2f51575ddfdeb976341e48..6d37b9d49037c7b13bb932f8fe80a2fa5931bdbd 100644 (file)
@@ -34,7 +34,7 @@
 
 static void print_line(std::string s)
 {
-    if (!data_api.is_quiet_mode())
+    if (!DataApi::is_quiet_mode())
         std::cout << s << std::endl;
 }
 
@@ -64,112 +64,15 @@ int main (int argc, char* argv[])
     }
 
     // MAIN CONVERSION FUNCTION!!
-    cv.initialize(&init_state_ctor);
-    if (cv.convert_file(conf_file) < 0)
+    Converter cv;
+    if (cv.convert(conf_file, output_file, rule_file, error_file) < 0)
     {
         print_line("Failed Conversion of file " + conf_file);
         fail = true;
     }
 
-    // keep track whether we're printing rules into a seperate file.
-    bool rule_file_specifed = false;
 
-
-    if (!rule_api.empty())
-    {
-        if (!rule_file.compare(output_file))
-        {
-            std::string s = std::string("$default_rules");
-            rule_file_specifed = false;
-
-            table_api.open_top_level_table("ips");
-            table_api.add_option("rules", s);
-            table_api.close_table();
-        }
-        else
-        {
-            rule_file_specifed = true;
-
-            table_api.open_top_level_table("ips");
-            table_api.add_option("include", rule_file);
-            table_api.close_table();
-        }
-    }
-
-
-    // Snort++ requires a binder table to be instantiated,
-    // although not necessarily filled.  So, just add this table.
-    // If its already added, these lines won't have any effect
-    table_api.open_top_level_table("binder");
-    table_api.close_table();
-
-    // finally, lets print the converter to file
-    std::ofstream out;
-    out.open(output_file,  std::ifstream::out);
-    out << "require(\"snort_config\")  -- for loading\n\n";
-
-    if (!rule_file_specifed)
-    {
-        data_api.print_data(out);
-        rule_api.print_rules(out, rule_file_specifed);
-        table_api.print_tables(out);
-        data_api.print_comments(out);
-
-
-        out << std::endl;
-
-        if ((data_api.failed_conversions() || rule_api.failed_conversions()) &&
-            !data_api.is_quiet_mode())
-        {
-            std::ofstream rejects;  // in this case, rejects are regular configuration options
-            rejects.open(error_file, std::ifstream::out);
-
-            if (data_api.failed_conversions())
-                data_api.print_errors(rejects);
-
-            if (rule_api.failed_conversions())
-                rule_api.print_rejects(rejects);
-
-            rejects << std::endl;
-            rejects.close();
-        }
-    }
-    else
-    {
-        std::ofstream rules;
-        rules.open(rule_file, std::ifstream::out);
-
-        data_api.print_data(out);
-        rule_api.print_rules(rules, rule_file_specifed);
-        table_api.print_tables(out);
-        data_api.print_comments(out);
-
-        // flush all data
-        out << std::endl;
-        rules << std::endl;
-        rules.close();
-
-        if ((data_api.failed_conversions() || rule_api.failed_conversions()) &&
-            !data_api.is_quiet_mode())
-        {
-            std::ofstream rejects;  // in this case, rejects are regular configuration options
-            rejects.open(error_file, std::ifstream::out);
-
-            if (data_api.failed_conversions())
-                data_api.print_errors(rejects);
-
-            if (rule_api.failed_conversions())
-                rule_api.print_rejects(rejects);
-
-            rejects << std::endl;
-            rejects.close();
-        }
-    }
-
-
-    out.close();
-
-    if (fail || data_api.failed_conversions() || rule_api.failed_conversions())
+    if (fail || cv.failed_conversions())
         return -2;
     return 0;
 }
index a910c2d7ca592134058ee9534a56316424a94bda..c389ff8d2f477090c521062b4239dd9393d0fd4e 100644 (file)
 #include "conversion_state.h"
 #include "data/data_types/dt_comment.h"
 #include "utils/s2l_util.h"
+#include "init_state.h"
+
+
+
+bool Converter::parse_includes = true;
+bool Converter::convert_rules_mult_files = true;
+bool Converter::convert_conf_mult_files = true;
 
-Converter cv;
 
 Converter::Converter()
     :   state(nullptr),
-        init_state_ctor(nullptr),
-        parse_includes(true),
-        convert_rules_mult_files(true),
-        convert_conf_mult_files(true),
         error(false)
 {
 }
@@ -42,20 +44,6 @@ Converter::~Converter()
         delete state;
 }
 
-bool Converter::initialize(conv_new_f func)
-{
-    init_state_ctor = func;
-    state = init_state_ctor();
-
-    if (state == nullptr)
-    {
-        data_api.developer_error("Failed Converter initialization!");
-        return false;
-    }
-
-    return true;
-}
-
 void Converter::set_state(ConversionState* c)
 {
     delete state;
@@ -67,7 +55,7 @@ void Converter::reset_state()
     if (state)
         delete state;
 
-    state = init_state_ctor();
+    state = new InitState(*this);
     data_api.reset_state();
     table_api.reset_state();
     rule_api.reset_state();
@@ -98,7 +86,7 @@ void Converter::parse_include_file(std::string input_file)
 
 
 
-    if (convert_file(input_file) < 0)
+    if (parse_file(input_file) < 0)
         error = true; // return a negative number to main snort2lua method
 
 
@@ -140,7 +128,7 @@ void Converter::parse_include_file(std::string input_file)
     }
 }
 
-int Converter::convert_file(std::string input_file)
+int Converter::parse_file(std::string input_file)
 {
     std::ifstream in;
     std::string orig_text;
@@ -203,3 +191,120 @@ int Converter::convert_file(std::string input_file)
     // this is set by parse_include_file
     return error ? -3 : 0;
 }
+
+bool Converter::initialize()
+{
+    state = new InitState(*this);
+
+    if (state == nullptr)
+    {
+        DataApi::developer_error("Failed Converter initialization!");
+        return false;
+    }
+
+    return true;
+}
+
+int Converter::convert(std::string input,
+                        std::string output_file,
+                        std::string rule_file,
+                        std::string error_file)
+{
+    int rc;
+    initialize();
+
+    rc = parse_file(input);
+
+    if (rc < 0)
+        return rc;
+
+
+    // keep track whether we're printing rules into a seperate file.
+    bool rule_file_specifed = false;
+
+
+    if (!rule_api.empty())
+    {
+        std::cout << "rule_file" << rule_file << std::endl;
+        std::cout << "out_file " << output_file << std::endl;
+        if (rule_file.empty() || !rule_file.compare(output_file))
+        {
+            std::string s = std::string("$default_rules");
+            rule_file_specifed = false;
+
+            table_api.open_top_level_table("ips");
+            table_api.add_option("rules", s);
+            table_api.close_table();
+        }
+        else
+        {
+            rule_file_specifed = true;
+
+            table_api.open_top_level_table("ips");
+            table_api.add_option("include", rule_file);
+            table_api.close_table();
+        }
+    }
+
+
+    // Snort++ requires a binder table to be instantiated,
+    // although not necessarily filled.  So, just add this table.
+    // If its already added, these lines won't have any effect
+    table_api.open_top_level_table("binder");
+    table_api.close_table();
+
+    // finally, lets print the converter to file
+    std::ofstream out;
+    out.open(output_file,  std::ifstream::out);
+
+    out << "require(\"snort_config\")  -- for loading\n\n";
+    data_api.print_data(out);
+
+
+    if (!rule_file_specifed)
+    {
+        rule_api.print_rules(out, rule_file_specifed);
+    }
+    else
+    {
+        std::ofstream rules;
+        rules.open(rule_file, std::ifstream::out);
+        rule_api.print_rules(rules, rule_file_specifed);
+        rules.close();
+    }
+
+
+    table_api.print_tables(out);
+    data_api.print_comments(out);
+
+
+
+    if ((failed_conversions()) && !DataApi::is_quiet_mode())
+    {
+        if (error_file.empty())
+        {
+            if (data_api.failed_conversions())
+                data_api.print_errors(out);
+
+            if (rule_api.failed_conversions())
+                rule_api.print_rejects(out);
+        }
+        else
+        {
+            std::ofstream rejects;  // in this case, rejects are regular configuration options
+            rejects.open(error_file, std::ifstream::out);
+
+            if (data_api.failed_conversions())
+                data_api.print_errors(rejects);
+
+            if (rule_api.failed_conversions())
+                rule_api.print_rejects(rejects);
+
+            rejects.close();
+        }
+    }
+
+
+    out.close();
+    return rc;
+}
index 4ed7f9b0ca5f45b52d4babbba7048f6546bdb3c5..f22d3a769f8a14c72d8c0f792f06ef829af2caf1 100644 (file)
@@ -1,22 +1,21 @@
 /*
 ** 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.
- */
+**
+** 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.
+*/
 // converter.h author Josh Rosenbaum <jrosenba@cisco.com>
 
 #ifndef UTILS_CONVERTER_H
@@ -24,9 +23,9 @@
 
 #include <string>
 #include "conversion_defines.h"
-
-class Converter;
-extern Converter cv;
+#include "data/dt_data.h"
+#include "data/dt_table_api.h"
+#include "data/dt_rule_api.h"
 
 class Converter
 {
@@ -34,37 +33,68 @@ class Converter
 public:
     Converter();
     virtual ~Converter();
-    // initialize data class
-    bool initialize(conv_new_f init_state_func);
-    // set the next parsing state.
-    void set_state(ConversionState* c);
+
+
     // tells this class whether to parse include files.
-    inline void set_parse_includes(bool val) { parse_includes = val; }
+    inline static void set_parse_includes(bool val)
+    { parse_includes = val; }
     // tells this class whether to convert a file inline or pull all data into one file.
-    inline void create_mult_rule_files(bool var) { convert_rules_mult_files = var; }
+    inline static void create_mult_rule_files(bool var)
+    { convert_rules_mult_files = var; }
     // tells this class whether to convert a file inline or pull all data into one file.
-    inline void create_mult_conf_files(bool var) { convert_conf_mult_files = var; }
+    inline static void create_mult_conf_files(bool var)
+    { convert_conf_mult_files = var; }
+
+
+    int convert(std::string input,
+                std::string output,
+                std::string rules = "", // defaults to output_file
+                std::string errors = ""); // defaults to output_file
+
+
+    // set the next parsing state.
+    void set_state(ConversionState* c);
     // reset the current parsing state
     void reset_state();
-    // convert the following file from a snort.conf into a lua.conf
-    int convert_file(std::string input_file);
     // parse an include file.  Use this function to ensure all set options are properly
     void parse_include_file(std::string file);
+
+    bool failed_conversions() const
+    { return data_api.failed_conversions() || rule_api.failed_conversions(); }
+
+
     // Should we parse an include file?
-    inline bool should_convert_includes() { return parse_includes; }
+    inline bool should_convert_includes() const
+    { return parse_includes; }
+
+    inline DataApi& get_data_api()
+    { return data_api; }
+
+    inline TableApi& get_table_api()
+    { return table_api; }
+
+    inline RuleApi& get_rule_api()
+    { return rule_api; }
+
 
 private:
+    static bool parse_includes;
+    static bool convert_rules_mult_files;
+    static bool convert_conf_mult_files;
+
+    DataApi data_api;
+    TableApi table_api;
+    RuleApi rule_api;
+
     // the current parsing state.
     ConversionState* state;
-    // the data which will be printed into the new lua file
-    // the init_state constructor
-    conv_new_f init_state_ctor;
-
-    bool parse_includes;
-    bool convert_rules_mult_files;
-    bool convert_conf_mult_files;
     bool error;
 
+
+    // convert the following file from a snort.conf into a lua.conf
+    int parse_file(std::string input_file);
+    // initialize data class
+    bool initialize();
 };
 
 
index 49619c1ed81525ce23999d4e639a1ee3a33a68d1..1237a6ec22c34af46b86dd34d7b949ee4f8da891 100644 (file)
@@ -63,6 +63,7 @@ const std::string get_rule_file()
 { return rule_file.empty() ? get_out_file() : rule_file; }
 
 static void help_args(const char* pfx);
+static void help_usage();
 
 
 //-------------------------------------------------------------------------
@@ -251,22 +252,22 @@ static void parse_rule_file(const char* key, const char* val)
 }
 
 static void print_all(const char* /*key*/, const char* /*val*/)
-{ data_api.set_default_print(); }
+{ DataApi::set_default_print(); }
 
 static void print_quiet(const char* /*key*/, const char* /*val*/)
-{ data_api.set_quiet_print(); }
+{ DataApi::set_quiet_print(); }
 
 static void print_differences(const char* /*key*/, const char* /*val*/)
-{ data_api.set_difference_print(); }
+{ DataApi::set_difference_print(); }
 
 static void sing_rule_files(const char* /*key*/, const char* /*val*/)
-{ cv.create_mult_rule_files(false); }
+{ Converter::create_mult_rule_files(false); }
 
 static void sing_conf_files(const char* /*key*/, const char* /*val*/)
-{ cv.create_mult_conf_files(false); }
+{ Converter::create_mult_conf_files(false); }
 
 static void dont_parse_includes(const char* /*key*/, const char* /*val*/)
-{ cv.set_parse_includes(false); }
+{ Converter::set_parse_includes(false); }
 
 
 typedef void (*ParseConfigFunc)(const char*, const char* val);
@@ -354,10 +355,47 @@ static ConfigFunc basic_opts[] =
     { nullptr, nullptr, nullptr }
 };
 
+#if 0
+FIXIT-H J delete!!
+SnortConfig* parse_cmd_line(int argc, char* argv[])
+{
+    ArgList al(argc, argv);
+    const char* key, *val;
+    unsigned c = 0;
+
+    // get special options first
+    while ( al.get_arg(key, val) )
+    {
+        ::set(key, val, sc, false);
+        c++;
+    }
+
+    // now get the rest
+    al.reset();
+
+    while ( al.get_arg(key, val) )
+    {
+        ::set(key, val, sc, true);
+        c++;
+    }
+
+    if ( !c )
+        help_usage(sc, argv[0]);
+    else
+        check_flags(sc);
+
+    if ( int k = get_parse_errors() )
+        FatalError("see prior %d errors\n", k);
+
+    return sc;
+}
+#endif
+
 bool parse_cmd_line(int argc, char* argv[])
 {
     ArgList al(argc, argv);
     const char *key, *val;
+    bool found_opt = false;
 
     while ( al.get_arg(key, val) )
     {
@@ -374,11 +412,26 @@ bool parse_cmd_line(int argc, char* argv[])
         {
             p->parse_func(key, val);
         }
+
+        found_opt = true;
     }
 
+    if (!found_opt)
+        help_usage();
+
+
     return true;
 }
 
+static void help_usage()
+{
+    fprintf(stdout, "usage:\n");
+    fprintf(stdout, "    -?: list options\n");
+    fprintf(stdout, "    -V: output version\n");
+    fprintf(stdout, "    --help: help summary\n");
+    exit(1);
+}
+
 
 static void help_args(const char* pfx)
 {
index d5ac2125d8941f3a858f0271806bbbf374f0e1b6..95cbb1b9d0f0aa32fee5e757c774cae23fae6fb5 100644 (file)
@@ -42,4 +42,3 @@ const std::string get_rule_file();
 } // namespace parser
 
 #endif
-
index 71e54b477c6dfa6f64247931d2a13d4c93b9de9e..24f42e5efb8d6c57ec57980f9491a8d02a05c9c7 100644 (file)
 #include "data/dt_table_api.h"
 
 
-Binder::Binder() : printed(false), when_policy_id(-1) {}
+Binder::Binder(TableApi& t) :   table_api(t),
+                                printed(false),
+                                when_policy_id(-1)
+{ }
 
 Binder::~Binder()
 {
index 8e0c21dffcb4167dfd596f1bc776947cf6c92650..469fa5dffe6ded5d2636bc9d6081e59327ead8d2 100644 (file)
 #include <string>
 #include <vector>
 
+class TableApi;
 
 // If the user never adds add_to_configuration,
 //  the destructor will call the method
 class Binder
 {
 public:
-    Binder();
+    Binder(TableApi&);
     ~Binder();
 
     void add_to_configuration();
@@ -58,6 +59,7 @@ public:
 
 
 private:
+    TableApi& table_api;
     bool printed; // ensures that the binding is added once,
                   // by either the destructor or user