From 8358b29b488a3ce5121c8887424adb5f410d5520 Mon Sep 17 00:00:00 2001 From: Gerald Begumisa Date: Fri, 10 Jul 2009 15:38:59 +0000 Subject: Implemented a localpartymap feature whereby a local party value may be swapped for another value. To use this feature, the mappings should be added to a file called localpartymap.csv, placed in /etc/orkaudio or in the directory where the orkaudio executable is. The format of localpartymap.csv should be oldlocalparty, newlocalparty - with only one mapping entry per line. git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@625 09dcff7a-b715-0410-9601-b79a96267cd0 --- orkaudio/audiocaptureplugins/voip/RtpSession.cpp | 78 +++++++++++---- orkaudio/audiocaptureplugins/voip/RtpSession.h | 3 + orkaudio/audiocaptureplugins/voip/VoIp.cpp | 115 +++++++++++++++++++++++ 3 files changed, 177 insertions(+), 19 deletions(-) diff --git a/orkaudio/audiocaptureplugins/voip/RtpSession.cpp b/orkaudio/audiocaptureplugins/voip/RtpSession.cpp index ec1f37a..7ade769 100644 --- a/orkaudio/audiocaptureplugins/voip/RtpSession.cpp +++ b/orkaudio/audiocaptureplugins/voip/RtpSession.cpp @@ -109,7 +109,7 @@ void RtpSession::ReportRtcpSrcDescription(RtcpSrcDescriptionPacketInfoRef& rtcpI } else { - m_localParty = rtcpInfo->m_cnameUsername; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(rtcpInfo->m_cnameUsername); } LOG4CXX_INFO(m_log, "[" + m_trackingId + "] Set local party to RTCP CNAME:" + m_localParty); @@ -257,7 +257,8 @@ void RtpSession::ProcessMetadataRawRtp(RtpPacketInfoRef& rtpPacket) } else { - m_localParty = szSourceIp; + CStdString lp(szSourceIp); + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(lp); } } if(!m_rtcpRemoteParty) @@ -282,7 +283,8 @@ void RtpSession::ProcessMetadataRawRtp(RtpPacketInfoRef& rtpPacket) } else { - m_localParty = szDestIp; + CStdString lp(szDestIp); + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(lp); } } if(!m_rtcpRemoteParty) @@ -330,7 +332,7 @@ void RtpSession::ProcessMetadataSipIncoming() { if((DLLCONFIG.m_sipRequestUriAsLocalParty == true) && (m_invite->m_requestUri.CompareNoCase(m_invite->m_to) != 0)) { - m_localParty = m_invite->m_requestUri; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_invite->m_requestUri); m_remoteParty = m_invite->m_from; m_direction = CaptureEvent::DirIn; m_localEntryPoint = m_invite->m_to; @@ -338,7 +340,7 @@ void RtpSession::ProcessMetadataSipIncoming() else { m_remoteParty = m_invite->m_from; - m_localParty = m_invite->m_to; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_invite->m_to); m_direction = CaptureEvent::DirIn; } @@ -368,7 +370,7 @@ void RtpSession::ProcessMetadataSipOutgoing() { if((DLLCONFIG.m_sipRequestUriAsLocalParty == true) && (m_invite->m_requestUri.CompareNoCase(m_invite->m_to) != 0)) { - m_localParty = m_invite->m_requestUri; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_invite->m_requestUri); m_remoteParty = m_invite->m_from; m_direction = CaptureEvent::DirIn; m_localEntryPoint = m_invite->m_to; @@ -376,7 +378,7 @@ void RtpSession::ProcessMetadataSipOutgoing() else { m_remoteParty = m_invite->m_to; - m_localParty = m_invite->m_from; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_invite->m_from); m_direction = CaptureEvent::DirOut; } @@ -465,7 +467,7 @@ void RtpSession::UpdateMetadataSip(RtpPacketInfoRef& rtpPacket, bool sourceRtpAd // Update session metadata with INVITE info if((DLLCONFIG.m_sipRequestUriAsLocalParty == true) && (m_invite->m_requestUri.CompareNoCase(m_invite->m_to) != 0)) { - m_localParty = m_invite->m_requestUri; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_invite->m_requestUri); m_remoteParty = m_invite->m_from; m_direction = CaptureEvent::DirIn; m_localEntryPoint = m_invite->m_to; @@ -473,7 +475,7 @@ void RtpSession::UpdateMetadataSip(RtpPacketInfoRef& rtpPacket, bool sourceRtpAd else { m_remoteParty = invite->m_from; - m_localParty = invite->m_to; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(invite->m_to); } m_remotePartyName = m_invite->m_fromName; @@ -671,7 +673,8 @@ void RtpSession::ReportMetadata() if(DLLCONFIG.m_localPartyForceLocalIp) { - m_localParty = szLocalIp; + CStdString lp(szLocalIp); + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(lp); } // Check if we don't have the local party based on the endpoint IP address else if(m_localParty.IsEmpty()) @@ -681,7 +684,7 @@ void RtpSession::ReportMetadata() EndpointInfoRef endpointInfo = RtpSessionsSingleton::instance()->GetEndpointInfo(m_endPointIp); if(endpointInfo.get()) { - m_localParty = endpointInfo->m_extension; + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(endpointInfo->m_extension); } } } @@ -695,7 +698,8 @@ void RtpSession::ReportMetadata() } else { - m_localParty = szLocalIp; + CStdString lp(szLocalIp); + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(lp); } } @@ -703,6 +707,7 @@ void RtpSession::ReportMetadata() { m_localParty = ""; MemMacToHumanReadable((unsigned char*)m_localMac, m_localParty); + m_localParty = RtpSessionsSingleton::instance()->GetLocalPartyMap(m_localParty); } // Report Local party @@ -1519,22 +1524,26 @@ void RtpSessions::ReportSipBye(SipByeInfo bye) void RtpSessions::UpdateSessionWithCallInfo(SkCallInfoStruct* callInfo, RtpSessionRef& session) { session->m_skinnyLineInstance = callInfo->lineInstance; + CStdString lp; switch(callInfo->callType) { case SKINNY_CALL_TYPE_INBOUND: case SKINNY_CALL_TYPE_FORWARD: - session->m_localParty = callInfo->calledParty; + lp = callInfo->calledParty; + session->m_localParty = GetLocalPartyMap(lp); session->m_remoteParty = callInfo->callingParty; session->m_direction = CaptureEvent::DirIn; break; case SKINNY_CALL_TYPE_OUTBOUND: - session->m_localParty = callInfo->callingParty; + lp = callInfo->callingParty; + session->m_localParty = GetLocalPartyMap(lp); session->m_remoteParty = callInfo->calledParty; session->m_direction = CaptureEvent::DirOut; break; default: - session->m_localParty = callInfo->calledParty; + lp = callInfo->calledParty; + session->m_localParty = GetLocalPartyMap(lp); session->m_remoteParty = callInfo->callingParty; } } @@ -1919,11 +1928,12 @@ void RtpSessions::ReportSkinnyOpenReceiveChannelAck(SkOpenReceiveChannelAckStruc if(endpoint.get()) { - session->m_localParty = endpoint->m_extension; + session->m_localParty = GetLocalPartyMap(endpoint->m_extension); } else { - session->m_localParty = szEndpointIp; + CStdString lp(szEndpointIp); + session->m_localParty = GetLocalPartyMap(lp); } m_byIpAndPort.erase(ipAndPort); @@ -1984,11 +1994,12 @@ void RtpSessions::ReportSkinnyStartMediaTransmission(SkStartMediaTransmissionStr if(endpoint.get()) { - session->m_localParty = endpoint->m_extension; + session->m_localParty = GetLocalPartyMap(endpoint->m_extension); } else { - session->m_localParty = szEndpointIp; + CStdString lp(szEndpointIp); + session->m_localParty = GetLocalPartyMap(lp); } m_byIpAndPort.erase(ipAndPort); @@ -2673,6 +2684,35 @@ void RtpSessions::PauseCaptureOrkuid(CStdString& orkuid) LOG4CXX_INFO(m_log, logMsg); } +void RtpSessions::SaveLocalPartyMap(char *oldparty, char *newparty) +{ + CStdString oldp; + CStdString newp; + + oldp = oldparty; + newp = newparty; + + m_localPartyMap.insert(std::make_pair(oldparty, newparty)); + LOG4CXX_DEBUG(m_log, "Saved map oldparty:" + oldp + " newparty:" + newp); +} + +CStdString RtpSessions::GetLocalPartyMap(CStdString& oldlocalparty) +{ + CStdString newlocalparty; + std::map::iterator pair; + + newlocalparty = oldlocalparty; + + pair = m_localPartyMap.find(oldlocalparty); + if(pair != m_localPartyMap.end()) + { + newlocalparty = pair->second; + LOG4CXX_DEBUG(m_log, "Mapped oldparty:" + oldlocalparty + " to newparty:" + newlocalparty); + } + + return newlocalparty; +} + //========================================================== SipInviteInfo::SipInviteInfo() { diff --git a/orkaudio/audiocaptureplugins/voip/RtpSession.h b/orkaudio/audiocaptureplugins/voip/RtpSession.h index 221c771..42fe9e7 100644 --- a/orkaudio/audiocaptureplugins/voip/RtpSession.h +++ b/orkaudio/audiocaptureplugins/voip/RtpSession.h @@ -267,6 +267,8 @@ public: void StartCaptureOrkuid(CStdString& orkuid); void PauseCapture(CStdString& party); void PauseCaptureOrkuid(CStdString& orkuid); + void SaveLocalPartyMap(char *oldparty, char *newparty); + CStdString GetLocalPartyMap(CStdString& oldlocalparty); private: RtpSessionRef findByEndpointIp(struct in_addr endpointIpAddr, int passThruPartyId = 0); @@ -281,6 +283,7 @@ private: std::map m_byIpAndPort; std::map m_byCallId; std::map m_endpoints; + std::map m_localPartyMap; LoggerPtr m_log; AlphaCounter m_alphaCounter; }; diff --git a/orkaudio/audiocaptureplugins/voip/VoIp.cpp b/orkaudio/audiocaptureplugins/voip/VoIp.cpp index aa0d811..3045501 100644 --- a/orkaudio/audiocaptureplugins/voip/VoIp.cpp +++ b/orkaudio/audiocaptureplugins/voip/VoIp.cpp @@ -74,6 +74,8 @@ VoIpConfigTopObjectRef g_VoIpConfigTopObjectRef; #define DLLCONFIG g_VoIpConfigTopObjectRef.get()->m_config #define PROMISCUOUS 1 +#define LOCAL_PARTY_MAP_FILE "localpartymap.csv" +#define ETC_LOCAL_PARTY_MAP_FILE "/etc/orkaudio/localpartymap.csv" //======================================================== class VoIp @@ -93,6 +95,10 @@ public: void AddPcapDeviceToMap(CStdString& deviceName, pcap_t* pcapHandle); void RemovePcapDeviceFromMap(pcap_t* pcapHandle); CStdString GetPcapDeviceName(pcap_t* pcapHandle); + void ProcessLocalPartyMap(char *line, int ln); + void LoadPartyMaps(); + void TrimCString(char **s); + private: void OpenDevices(); void OpenPcapFile(CStdString& filename); @@ -3287,6 +3293,113 @@ void VoIp::OpenDevices() } } +void VoIp::TrimCString(char **s) +{ + char *x = NULL; + char *y = NULL; + + if(*s == NULL || !strlen(*s)) + { + *s = ""; + return; + } + + x = *s; + y = *s+strlen(*s); + + while(x < y && isblank(*x)) + { + x += 1; + } + + if(!strlen(x)) + { + *s = x; + return; + } + + y -= 1; + while(y >= x && isblank(*y)) + { + *y = '\0'; + y -= 1; + } + + *s = x; + return; + +} + +void VoIp::ProcessLocalPartyMap(char *line, int ln) +{ + char *oldparty = NULL; + char *newparty = NULL; + CStdString logMsg; + + oldparty = line; + newparty = strchr(line, ','); + + if(!newparty || !oldparty) + { + logMsg.Format("ProcessLocalPartyMap: invalid format of line:%d in the local party maps file", ln); + LOG4CXX_WARN(s_packetLog, logMsg); + + return; + } + + *(newparty++) = '\0'; + + TrimCString(&oldparty); + TrimCString(&newparty); + + RtpSessionsSingleton::instance()->SaveLocalPartyMap(oldparty, newparty); +} + +void VoIp::LoadPartyMaps() +{ + FILE *maps = NULL; + char buf[1024]; + int i = 0; + int ln = 0; + CStdString logMsg; + + memset(buf, 0, sizeof(buf)); + maps = fopen(LOCAL_PARTY_MAP_FILE, "r"); + if(!maps) + { + logMsg.Format("LoadPartyMaps: Could not open file:%s -- trying:%s now", LOCAL_PARTY_MAP_FILE, ETC_LOCAL_PARTY_MAP_FILE); + LOG4CXX_WARN(s_packetLog, logMsg); + + maps = fopen(ETC_LOCAL_PARTY_MAP_FILE, "r"); + if(!maps) + { + logMsg.Format("LoadPartyMaps: Could not open file:%s either -- giving up", ETC_LOCAL_PARTY_MAP_FILE); + LOG4CXX_INFO(s_packetLog, logMsg); + + return; + } + } + + while(fgets(buf, sizeof(buf), maps)) + { + ln += 1; + + // Minimum line of x,y\n + if(strlen(buf) > 4) + { + if(buf[strlen(buf)-1] == '\n') + { + buf[strlen(buf)-1] = '\0'; + } + + ProcessLocalPartyMap(buf, ln); + } + } + + fclose(maps); + + return; +} void VoIp::Initialize() { @@ -3331,6 +3444,8 @@ void VoIp::Initialize() OpenDevices(); s_liveCapture = true; } + + LoadPartyMaps(); } void VoIp::ReportPcapStats() -- cgit v1.2.3