diff options
author | Gerald Begumisa <ben_g@users.sourceforge.net> | 2009-07-10 15:38:59 +0000 |
---|---|---|
committer | Gerald Begumisa <ben_g@users.sourceforge.net> | 2009-07-10 15:38:59 +0000 |
commit | 8358b29b488a3ce5121c8887424adb5f410d5520 (patch) | |
tree | 6c99c6e54ff1cf5cd244864dc900a4fa65217d4e /orkaudio/audiocaptureplugins/voip/VoIp.cpp | |
parent | 37af020b54aea14ebb12cfe5aafd612c10e23214 (diff) |
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
Diffstat (limited to 'orkaudio/audiocaptureplugins/voip/VoIp.cpp')
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/VoIp.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
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() |