|
| 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 | + |
0 commit comments