Skip to content

Commit 7a28dba

Browse files
author
Joegen Baclor
committed
Implemented homer proxy plugin
1 parent c7cc363 commit 7a28dba

10 files changed

+217
-14
lines changed

Makefile.am

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ SUBDIRS = \
66
src \
77
include \
88
bin \
9-
config-plugin \
10-
webhomer-auth
9+
proxy-plugin \
10+
webhomer-auth \
11+
config-plugin

configure.ac

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ AC_PROG_CC
1313
AX_COMPILER_VENDOR
1414
SFAC_INIT_FLAGS
1515
SFAC_LIB_PORT
16+
SFAC_LIB_COMMSERVER
1617
CHECK_ODBC
1718

1819
# java projects - typical macros
@@ -28,7 +29,8 @@ AC_CONFIG_FILES([
2829
bin/Makefile
2930
src/Makefile
3031
include/Makefile
31-
config-plugin/Makefile
3232
webhomer-auth/Makefile
33+
config-plugin/Makefile
34+
proxy-plugin/Makefile
3335
])
3436
AC_OUTPUT

include/sipxhomer/HEPMessage.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ inline bool HEPMessage::parse(const std::string& message)
284284

285285
data.push_back(*iter);
286286

287-
std::size_t len = *(reinterpret_cast<std::size_t*>(chunkLength));
288-
std::size_t size = data.size();
289287
if (*(reinterpret_cast<std::size_t*>(chunkLength)) == data.size())
290288
{
291289
parserState = VendorIdParse;
@@ -300,8 +298,11 @@ inline bool HEPMessage::parse(const std::string& message)
300298
iter++;
301299
}
302300
break;
301+
case MessageEnd:
302+
break;
303303
}
304304
}
305+
return true;
305306
}
306307

307308
inline bool HEPMessage::setChunk(unsigned short vendorId, unsigned short typeId, const std::string& data)
@@ -479,6 +480,8 @@ inline bool HEPMessage::encode(std::ostream& strm)
479480
dataSize = _data.size();
480481
strm.write((const char*)&dataSize, sizeof(::uint16_t));
481482
strm.write(_data.c_str(), _data.size());
483+
484+
return true;
482485
}
483486

484487
inline const ::uint8_t& HEPMessage::getIpProtoFamily() const

proxy-plugin/Makefile.am

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
include $(top_srcdir)/config/project.am
3+
include $(top_srcdir)/config/utility.am
4+
## Process this file with automake to produce Makefile.in
5+
6+
sipXhomerProxyPlugin_COMMON_CXX_FLAGS = \
7+
-I$(top_builddir)/config \
8+
-I$(top_srcdir)/include
9+
10+
## Libtool version info - update only immediately before a release
11+
# Current - increment if any interfaces are added, removed, or changed
12+
version_Current=1
13+
# Revision - set to 0 if Current was incremented
14+
# increment if any implementation has changed
15+
version_Revision=0
16+
# Age - set to 0 of any interfaces have been removed
17+
# increment if any interfaces have been added
18+
version_Age=0
19+
20+
sipXhomerProxyPlugin_COMMON_LD_FLAGS = \
21+
-module \
22+
-version-info ${version_Current}:${version_Revision}:${version_Age}
23+
24+
sipXhomerProxyPlugin_LDADD = \
25+
-lsqaclient
26+
27+
nobase_lib_LTLIBRARIES = \
28+
transactionplugins/libsipXhomerProxyPlugin.la
29+
30+
transactionplugins_libsipXhomerProxyPlugin_la_SOURCES = \
31+
ProxyPlugin.h \
32+
ProxyPlugin.cpp
33+
34+
transactionplugins_libsipXhomerProxyPlugin_la_CXXFLAGS = \
35+
$(sipXhomerProxyPlugin_COMMON_CXX_FLAGS) \
36+
-DSIPX_CONFDIR=\"@SIPX_CONFDIR@\"
37+
38+
transactionplugins_libsipXhomerProxyPlugin_la_LDFLAGS = \
39+
$(sipXhomerProxyPlugin_COMMON_LD_FLAGS)
40+
41+
42+
transactionplugins_libsipXhomerProxyPlugin_la_LIBADD = \
43+
@SIPXCOMMSERVER_LIBS@
44+
45+
46+
47+
48+

proxy-plugin/ProxyPlugin.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "ProxyPlugin.h"
2+
#include <cassert>
3+
#include <utl/UtlString.h>
4+
#include <sys/time.h>
5+
#include <sstream>
6+
#include <net/NetBase64Codec.h>
7+
8+
/// Factory used by PluginHooks to dynamically link the plugin instance
9+
extern "C" SipBidirectionalProcessorPlugin* getTransactionPlugin(const UtlString& pluginName)
10+
{
11+
return new HomerProxyPlugin(pluginName);
12+
}
13+
14+
HomerProxyPlugin::HomerProxyPlugin(const UtlString& instanceName, int priority) :
15+
SipBidirectionalProcessorPlugin(instanceName, priority),
16+
_sqa("HomerProxyPlugin", 1),
17+
_localPort(0)
18+
{
19+
}
20+
21+
HomerProxyPlugin::~HomerProxyPlugin()
22+
{
23+
}
24+
25+
void HomerProxyPlugin::readConfig(OsConfigDb& configDb)
26+
{
27+
}
28+
29+
void HomerProxyPlugin::initialize()
30+
{
31+
assert(_pUserAgent);
32+
UtlString host;
33+
int port;
34+
if (_pUserAgent->getLocalAddress(&host, &port))
35+
{
36+
_localHost = host.data();
37+
_localPort = port;
38+
}
39+
}
40+
41+
void HomerProxyPlugin::handleIncoming(SipMessage& message, const char* address, int port)
42+
{
43+
struct timeval now;
44+
gettimeofday(&now, NULL);
45+
46+
std::string msg;
47+
msg = message.getBytes();
48+
HEPMessage hep;
49+
hep.setIpProtoFamily(HEPMessage::IpV4);
50+
hep.setIpProtoId(HEPMessage::TCP);
51+
hep.setIp4SrcAddress(address);
52+
hep.setIp4DestAddress(_localHost.c_str());
53+
hep.setSrcPort(port);
54+
hep.setDestPort(_localPort);
55+
hep.setTimeStamp(now.tv_sec);
56+
hep.setTimeStampMicroOffset(now.tv_usec);
57+
hep.setProtocolType(HEPMessage::SIP);
58+
hep.setData(msg);
59+
60+
std::ostringstream buff;
61+
hep.encode(buff);
62+
UtlString hepMsq;
63+
NetBase64Codec::encode(buff.str().size(), buff.str().data(), hepMsq);
64+
_sqa.publish("CAP", buff.str().c_str());
65+
}
66+
67+
void HomerProxyPlugin::handleOutgoing(SipMessage& message, const char* address, int port)
68+
{
69+
struct timeval now;
70+
gettimeofday(&now, NULL);
71+
72+
std::string msg;
73+
msg = message.getBytes();
74+
HEPMessage hep;
75+
hep.setIpProtoFamily(HEPMessage::IpV4);
76+
hep.setIpProtoId(HEPMessage::TCP);
77+
hep.setIp4SrcAddress(_localHost.c_str());
78+
hep.setIp4DestAddress(address);
79+
hep.setSrcPort(_localPort);
80+
hep.setDestPort(port);
81+
hep.setTimeStamp(now.tv_sec);
82+
hep.setTimeStampMicroOffset(now.tv_usec);
83+
hep.setProtocolType(HEPMessage::SIP);
84+
hep.setData(msg);
85+
86+
std::ostringstream buff;
87+
hep.encode(buff);
88+
UtlString hepMsq;
89+
NetBase64Codec::encode(buff.str().size(), buff.str().data(), hepMsq);
90+
_sqa.publish("CAP", buff.str().c_str());
91+
}
92+
93+

proxy-plugin/ProxyPlugin.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef HomerProxyPlugin_H_INCLUDED
2+
#define HomerProxyPlugin_H_INCLUDED
3+
4+
#include <net/SipBidirectionalProcessorPlugin.h>
5+
#include <sqa/sqaclient.h>
6+
#include <sipxhomer/HEPMessage.h>
7+
#include <string>
8+
9+
extern "C" SipBidirectionalProcessorPlugin* getTransactionPlugin(const UtlString& pluginName);
10+
11+
class HomerProxyPlugin : public SipBidirectionalProcessorPlugin
12+
{
13+
protected:
14+
HomerProxyPlugin(
15+
const UtlString& instanceName, ///< the configured name for this plugin instance
16+
int priority = 100
17+
);
18+
19+
public:
20+
/// destructor
21+
virtual ~HomerProxyPlugin();
22+
23+
virtual void initialize();
24+
25+
26+
/// Read (or re-read) whatever configuration the plugin requires.
27+
virtual void readConfig( OsConfigDb& configDb /**< a subhash of the individual configuration
28+
* parameters for this instance of this plugin. */
29+
);
30+
31+
///
32+
/// All incoming Sip Messages will be sent to this virtual function.
33+
/// Plugins that need to manipulate incoming Sip messages must do so here.
34+
virtual void handleIncoming(SipMessage& message, const char* address, int port);
35+
36+
///
37+
/// All outgoing Sip Messages will be sent to this virtual function.
38+
/// Plugins that need to manipulate outgoing Sip messages must do so here.
39+
virtual void handleOutgoing(SipMessage& message, const char* address, int port);
40+
41+
protected:
42+
SQAPublisher _sqa;
43+
std::string _localHost;
44+
int _localPort;
45+
friend SipBidirectionalProcessorPlugin* getTransactionPlugin(const UtlString& pluginName);
46+
};
47+
48+
#endif // HomerProxyPlugin_H_INCLUDED

src/HEPCaptureAgent.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
1212
// details.
1313

14+
#include <net/NetBase64Codec.h>
1415
#include "os/OsLogger.h"
1516
#include "sqa/ServiceOptions.h"
1617
#include "sqa/sqaclient.h"
1718
#include <boost/date_time.hpp>
1819
#include "sipxhomer/HEPCaptureAgent.h"
1920

21+
2022
using namespace resip;
2123

2224
HEPCaptureAgent::HEPCaptureAgent(ServiceOptions& options, HEPDao& dao) :
@@ -49,18 +51,21 @@ void HEPCaptureAgent::internalRun()
4951
std::string sqaAddress;
5052
std::string sqaPort;
5153

52-
_options.getOption("sqa-control-address", sqaAddress);
53-
_options.getOption("sqa-control-port", sqaPort);
54-
55-
_pWatcher = new SQAWatcher("HEPCaptureAgent", sqaAddress.c_str(), sqaPort.c_str(), "CAP", 1);
54+
55+
_pWatcher = new SQAWatcher("HEPCaptureAgent", "CAP", 1);
5656

5757
while(_isRunning)
5858
{
5959
SQAEvent* pEvent = _pWatcher->watch();
6060
if (pEvent)
6161
{
62-
pEvent->data;
63-
std::string data = pEvent->data;
62+
std::string buff = pEvent->data;
63+
64+
char decoded[8092];
65+
int decodedSize;
66+
NetBase64Codec::decode(buff.size(), buff.data(), decodedSize, decoded);
67+
std::string data(decoded, decodedSize);
68+
6469
HEPMessage message;
6570
if (message.parse(data))
6671
{

src/HEPTestDriver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ DEFINE_TEST(TestDriver, TestHEPParser)
233233
case UPDATE:
234234
cseqMethod = "UPDATE";
235235
break;
236+
default:
237+
break;
236238
}
237239
}
238240

src/Makefile.am

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ sipxhomer_LDADD = \
2020
-lcrypto \
2121
-lares \
2222
-lpthread \
23-
@ODBC_LDFLAGS@
23+
-lmongoclient \
24+
@ODBC_LDFLAGS@ \
25+
@SIPXCOMMSERVER_LIBS@
26+
2427

2528
sipxhomer_LDFLAGS = \
2629
-shared \

src/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ int main(int argc , char** argv)
2525
ServiceOptions service(argc, argv, "sipxhomer");
2626
service.addDaemonOptions();
2727

28-
service.addOptionString("sqa-control-port", ": Port where to send control commands.");
29-
service.addOptionString("sqa-control-address", ": Address where to send control commands.");
3028
service.addOptionFlag("test-driver", ": Run internal test for proper HEP v3 operations.");
3129

3230
if (!service.parseOptions())

0 commit comments

Comments
 (0)