1 //--------------------------------------------------------------------------
2 // Copyright (C) 2015-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // user_module.cc author Russ Combs <rucombs@cisco.com>
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "user_module.h"
25 
26 #include "stream_user.h"
27 #include "trace/trace.h"
28 
29 using namespace snort;
30 using namespace std;
31 
32 THREAD_LOCAL const Trace* stream_user_trace = nullptr;
33 
34 //-------------------------------------------------------------------------
35 // stream_user module
36 //-------------------------------------------------------------------------
37 
38 static const Parameter s_params[] =
39 {
40     { "session_timeout", Parameter::PT_INT, "1:max31", "60",
41       "session tracking timeout" },
42 
43     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
44 };
45 
StreamUserModule()46 StreamUserModule::StreamUserModule() : Module(MOD_NAME, MOD_HELP, s_params)
47 { config = nullptr; }
48 
~StreamUserModule()49 StreamUserModule::~StreamUserModule()
50 { delete config; }
51 
get_data()52 StreamUserConfig* StreamUserModule::get_data()
53 {
54     StreamUserConfig* temp = config;
55     config = nullptr;
56     return temp;
57 }
58 
set_trace(const Trace * trace) const59 void StreamUserModule::set_trace(const Trace* trace) const
60 { stream_user_trace = trace; }
61 
get_trace_options() const62 const TraceOption* StreamUserModule::get_trace_options() const
63 {
64 #ifndef DEBUG_MSGS
65     return nullptr;
66 #else
67     static const TraceOption stream_user_trace_options(nullptr, 0, nullptr);
68     return &stream_user_trace_options;
69 #endif
70 }
71 
set(const char *,Value & v,SnortConfig *)72 bool StreamUserModule::set(const char*, Value& v, SnortConfig*)
73 {
74     assert(v.is("session_timeout"));
75     config->session_timeout = v.get_uint32();
76     return true;
77 }
78 
begin(const char *,int,SnortConfig *)79 bool StreamUserModule::begin(const char*, int, SnortConfig*)
80 {
81     if ( !config )
82         config = new StreamUserConfig;
83 
84     return true;
85 }
86 
87