Added support of iconv
This commit is contained in:
parent
030902d745
commit
dd0a950616
4 changed files with 76 additions and 30 deletions
|
@ -22,3 +22,4 @@ AUTOCON_TIME=30
|
||||||
|
|
||||||
BRIDGE_DEFAULT=9504
|
BRIDGE_DEFAULT=9504
|
||||||
BRIDGE_PROXY=2501:10
|
BRIDGE_PROXY=2501:10
|
||||||
|
BRIDGE_ENCOFING=cp1251
|
||||||
|
|
|
@ -16,18 +16,25 @@
|
||||||
BrandMeisterBridge::BrandMeisterBridge()
|
BrandMeisterBridge::BrandMeisterBridge()
|
||||||
{
|
{
|
||||||
proxy = NULL;
|
proxy = NULL;
|
||||||
|
handle = NULL;
|
||||||
talker = NULL;
|
talker = NULL;
|
||||||
unknown = ECHOLINK_DEFAULT_USER_NUMBER;
|
unknown = ECHOLINK_DEFAULT_USER_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrandMeisterBridge::~BrandMeisterBridge()
|
BrandMeisterBridge::~BrandMeisterBridge()
|
||||||
{
|
{
|
||||||
|
iconv_close(handle);
|
||||||
DELETE(proxy);
|
DELETE(proxy);
|
||||||
free(talker);
|
free(talker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface methods for ModuleEchoLink
|
// Interface methods for ModuleEchoLink
|
||||||
|
|
||||||
|
void BrandMeisterBridge::setEncodingConfiguration(const char* configuration)
|
||||||
|
{
|
||||||
|
handle = iconv_open("UTF-8", configuration);
|
||||||
|
}
|
||||||
|
|
||||||
void BrandMeisterBridge::setDefaultConfiguration(const char* configuration)
|
void BrandMeisterBridge::setDefaultConfiguration(const char* configuration)
|
||||||
{
|
{
|
||||||
unknown = strtol(configuration, NULL, 10);
|
unknown = strtol(configuration, NULL, 10);
|
||||||
|
@ -76,39 +83,16 @@ void BrandMeisterBridge::setTalker(const char* call, const char* name)
|
||||||
|
|
||||||
if (*call == '*')
|
if (*call == '*')
|
||||||
{
|
{
|
||||||
// Do not process conference call-sign
|
// Do not handle conference call-sign
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* delimiter1 = strpbrk(call, " -\n");
|
size_t length = strlen(call) + strlen(name);
|
||||||
const char* delimiter2 = strpbrk(name, "\n");
|
char* buffer = (char*)alloca(length + sizeof(uint32_t));
|
||||||
|
|
||||||
if (delimiter1 != NULL)
|
sprintf(buffer, "%s %s", call, name);
|
||||||
{
|
|
||||||
// Remove characters after call-sign
|
|
||||||
size_t length = delimiter1 - call;
|
|
||||||
char* buffer = (char*)alloca(length + sizeof(uint32_t));
|
|
||||||
strncpy(buffer, call, length);
|
|
||||||
buffer[length] = '\0';
|
|
||||||
call = buffer;
|
|
||||||
}
|
|
||||||
if (delimiter2 != NULL)
|
|
||||||
{
|
|
||||||
// Remove characters after talker name
|
|
||||||
size_t length = delimiter2 - name;
|
|
||||||
char* buffer = (char*)alloca(length + sizeof(uint32_t));
|
|
||||||
strncpy(buffer, name, length);
|
|
||||||
buffer[length] = '\0';
|
|
||||||
name = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t number = proxy->getPrivateIDForCall(call);
|
setTalkerData(call, buffer);
|
||||||
if (number == 0)
|
|
||||||
number = unknown;
|
|
||||||
|
|
||||||
syslog(LOG_INFO, "Set talker ID to %d for call-sign %s (%s)", number, call, name);
|
|
||||||
proxy->setTalkerID(number);
|
|
||||||
proxy->setTalkerAlias(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrandMeisterBridge::handleChatMessage(const char* text)
|
void BrandMeisterBridge::handleChatMessage(const char* text)
|
||||||
|
@ -130,14 +114,65 @@ void BrandMeisterBridge::handleChatMessage(const char* text)
|
||||||
if (delimiter != NULL)
|
if (delimiter != NULL)
|
||||||
{
|
{
|
||||||
const char* call = delimiter + 3;
|
const char* call = delimiter + 3;
|
||||||
setTalker(call, call);
|
setTalkerData(call, call);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Set talker ID to %d (call-sign was not fit into chat message)", unknown);
|
syslog(LOG_INFO, "Set talker ID to %d (call-sign is not present in chat message)", unknown);
|
||||||
proxy->setTalkerID(unknown);
|
proxy->setTalkerID(unknown);
|
||||||
proxy->setTalkerAlias("");
|
proxy->setTalkerAlias("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrandMeisterBridge::setTalkerData(const char* call, const char* name)
|
||||||
|
{
|
||||||
|
const char* delimiter1 = strpbrk(call, " -\n");
|
||||||
|
const char* delimiter2 = strchr(name, '\n');
|
||||||
|
|
||||||
|
if (delimiter1 != NULL)
|
||||||
|
{
|
||||||
|
// Remove characters after call-sign
|
||||||
|
size_t length = delimiter1 - call;
|
||||||
|
char* buffer = (char*)alloca(length + sizeof(uint32_t));
|
||||||
|
strncpy(buffer, call, length);
|
||||||
|
buffer[length] = '\0';
|
||||||
|
call = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delimiter2 != NULL)
|
||||||
|
{
|
||||||
|
// Remove characters after talker name
|
||||||
|
size_t length = delimiter2 - name;
|
||||||
|
char* buffer = (char*)alloca(length + sizeof(uint32_t));
|
||||||
|
strncpy(buffer, name, length);
|
||||||
|
buffer[length] = '\0';
|
||||||
|
name = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle != NULL)
|
||||||
|
{
|
||||||
|
// Convert name to UTF8
|
||||||
|
size_t length1 = strlen(name);
|
||||||
|
size_t length2 = length1 * 3;
|
||||||
|
char* buffer = (char*)alloca(length2);
|
||||||
|
char* pointer1 = const_cast<char*>(name);
|
||||||
|
char* pointer2 = buffer;
|
||||||
|
iconv(handle, &pointer1, &length1, &pointer2, &length2);
|
||||||
|
*pointer2 = '\0';
|
||||||
|
name = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t number = proxy->getPrivateIDForCall(call);
|
||||||
|
|
||||||
|
if (number == 0)
|
||||||
|
{
|
||||||
|
// Use default value instead if ID not found
|
||||||
|
number = unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy->setTalkerID(number);
|
||||||
|
proxy->setTalkerAlias(name);
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "Set talker ID to %d for call-sign %s (%s)", number, call, name);
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#ifndef BRANDMEISTERBRIDGE_H
|
#ifndef BRANDMEISTERBRIDGE_H
|
||||||
#define BRANDMEISTERBRIDGE_H
|
#define BRANDMEISTERBRIDGE_H
|
||||||
|
|
||||||
|
#include <iconv.h>
|
||||||
|
|
||||||
#include "PatchCord.h"
|
#include "PatchCord.h"
|
||||||
|
|
||||||
class BrandMeisterBridge
|
class BrandMeisterBridge
|
||||||
|
@ -12,6 +14,7 @@ class BrandMeisterBridge
|
||||||
BrandMeisterBridge();
|
BrandMeisterBridge();
|
||||||
~BrandMeisterBridge();
|
~BrandMeisterBridge();
|
||||||
|
|
||||||
|
void setEncodingConfiguration(const char* configuration);
|
||||||
void setDefaultConfiguration(const char* configuration);
|
void setDefaultConfiguration(const char* configuration);
|
||||||
void setProxyConfiguration(const char* configuration);
|
void setProxyConfiguration(const char* configuration);
|
||||||
|
|
||||||
|
@ -22,9 +25,12 @@ class BrandMeisterBridge
|
||||||
private:
|
private:
|
||||||
|
|
||||||
PatchCord* proxy;
|
PatchCord* proxy;
|
||||||
|
iconv_t handle;
|
||||||
char* talker;
|
char* talker;
|
||||||
int unknown;
|
int unknown;
|
||||||
|
|
||||||
|
void setTalkerData(const char* call, const char* name);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -420,6 +420,10 @@ bool ModuleEchoLink::initialize(void)
|
||||||
{
|
{
|
||||||
bridge.setDefaultConfiguration(value.c_str());
|
bridge.setDefaultConfiguration(value.c_str());
|
||||||
}
|
}
|
||||||
|
if (cfg().getValue(cfgName(), "BRIDGE_ENCODING", value))
|
||||||
|
{
|
||||||
|
bridge.setEncodingConfiguration(value.c_str());
|
||||||
|
}
|
||||||
if (cfg().getValue(cfgName(), "BRIDGE_PROXY", value))
|
if (cfg().getValue(cfgName(), "BRIDGE_PROXY", value))
|
||||||
{
|
{
|
||||||
bridge.setProxyConfiguration(value.c_str());
|
bridge.setProxyConfiguration(value.c_str());
|
||||||
|
|
Loading…
Add table
Reference in a new issue