4
Fork 0

Updated to support actual D-BUS interface

This commit is contained in:
R3ABM Artem 2016-04-04 23:22:28 +03:00
parent 660133c812
commit 9c4c356a3d
9 changed files with 103 additions and 34 deletions

View file

@ -24,19 +24,21 @@ int main(int argc, const char* argv[])
{ "expression", required_argument, NULL, 'e' },
{ "connection", required_argument, NULL, 'c' },
{ "identity", required_argument, NULL, 'i' },
{ "network", required_argument, NULL, 'n' },
{ "link", required_argument, NULL, 'l' },
{ NULL, 0, NULL, 0 }
};
pcre* expression = NULL;
const char* file = NULL;
uint32_t number = 10;
uint32_t network = 0;
uint32_t link = 10;
int position = 0;
const char* error = NULL;
int selection = 0;
while ((selection = getopt_long(argc, const_cast<char* const*>(argv), "e:c:l:", options, NULL)) != EOF)
while ((selection = getopt_long(argc, const_cast<char* const*>(argv), "e:c:n:l:", options, NULL)) != EOF)
switch (selection)
{
case 'e':
@ -51,8 +53,12 @@ int main(int argc, const char* argv[])
openlog(optarg, 0, LOG_USER);
break;
case 'n':
network = atoi(optarg);
break;
case 'l':
number = atoi(optarg);
link = atoi(optarg);
break;
}
@ -64,12 +70,14 @@ int main(int argc, const char* argv[])
}
if ((expression == NULL) ||
(network == 0) ||
(file == NULL))
{
printf(
"Usage: %s"
" --expression <regular expression>"
" --connection <path to configuration file>"
" --network <network number>"
" --link <link number>"
" [--identity <identity>]"
"\n",
@ -80,7 +88,7 @@ int main(int argc, const char* argv[])
// Main
UserDataStore store(file);
PatchCordProxy proxy(number);
PatchCordProxy proxy(network, link);
char* line = NULL;
size_t length = 0;

View file

@ -18,17 +18,19 @@
#define VALUE_CORD_OUTGOING_SOURCE_ID 1
#define VALUE_CORD_INCOMING_SOURCE_ID 4
PatchCordProxy::PatchCordProxy(uint32_t number) :
number(number),
banner(NULL)
PatchCordProxy::PatchCordProxy(uint32_t network, uint32_t link)
{
banner = NULL;
number = link;
asprintf(&path, OBJECT_PATH "/%d", network);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
}
PatchCordProxy::~PatchCordProxy()
{
free(banner);
dbus_connection_unref(connection);
free(banner);
free(path);
}
void PatchCordProxy::setTalkerID(uint32_t value)
@ -46,7 +48,7 @@ uint32_t PatchCordProxy::getTalkerID()
void PatchCordProxy::getContextBanner()
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "getContextList");
const char* name = AUTOPATCH_LINK_NAME;
@ -82,7 +84,7 @@ void PatchCordProxy::getContextBanner()
void PatchCordProxy::setVendorSpecificValue(uint32_t key, uint32_t value)
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "setVendorSpecificValue");
dbus_message_append_args(message,
@ -109,7 +111,7 @@ void PatchCordProxy::setVendorSpecificValue(uint32_t key, uint32_t value)
uint32_t PatchCordProxy::getVendorSpecificValue(uint32_t key)
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "getContextData");
dbus_message_append_args(message,

View file

@ -10,7 +10,7 @@ class PatchCordProxy
{
public:
PatchCordProxy(uint32_t number);
PatchCordProxy(uint32_t network, uint32_t link);
~PatchCordProxy();
void setTalkerID(uint32_t value);
@ -19,6 +19,8 @@ class PatchCordProxy
private:
DBusConnection* connection;
char* path;
uint32_t number;
char* banner;

View file

@ -19,3 +19,5 @@ LINK_IDLE_TIMEOUT=0
DESCRIPTION="You have connected to a DSTAR.SU DMR Bridge\n"
AUTOCON_ECHOLINK_ID=196189
AUTOCON_TIME=30
BRIDGE_PROXY=2501:10
BRIDGE_STORE=/opt/BrandMeister/Registry.cnf

View file

@ -6,34 +6,59 @@
#include <syslog.h>
#include <stdio.h>
#define ECHOLINK_DEFAULT_USER_CALL "N0CALL Unknown call"
#define ECHOLINK_DEFAULT_USER_NUMBER 1
#define ECHOLINK_DEFAULT_CORD_NUMBER 10
#define REGISTRY_CONFIGURATION_FILE "/opt/BrandMeister/Registry.cnf"
BrandMeisterBridge::BrandMeisterBridge() :
proxy(ECHOLINK_DEFAULT_CORD_NUMBER),
store(REGISTRY_CONFIGURATION_FILE),
talker(NULL)
#define DELETE(object) \
if (object) \
delete object;
BrandMeisterBridge::BrandMeisterBridge()
{
proxy = NULL;
store = NULL;
talker = NULL;
}
BrandMeisterBridge::~BrandMeisterBridge()
{
DELETE(proxy);
DELETE(store);
free(talker);
}
// Interface methods for ModuleEchoLink
void BrandMeisterBridge::setProxyConfiguration(const char* configuration)
{
char* pointer = const_cast<char*>(configuration);
uint32_t network = strtol(pointer + 0, &pointer, 10);
uint32_t link = strtol(pointer + 1, &pointer, 10);
proxy = new PatchCordProxy(network, link);
}
void BrandMeisterBridge::setStoreConfiguration(const char* configuration)
{
store = new UserDataStore(configuration);
}
const char* BrandMeisterBridge::getTalker()
{
if ((proxy == NULL) ||
(store == NULL))
{
syslog(LOG_ERR, "BrandMeister bridge is not configured");
return ECHOLINK_DEFAULT_USER_CALL;
}
free(talker);
uint32_t number = proxy.getTalkerID();
uint32_t number = proxy->getTalkerID();
char call[LONG_CALLSIGN_LENGTH];
char text[SLOW_DATA_TEXT_LENGTH];
if ((number != 0) &&
(store.getCredentialsForID(number, call, text)))
(store->getCredentialsForID(number, call, text)))
{
asprintf(&talker, "%s %s", call, text);
return talker;
@ -45,6 +70,13 @@ const char* BrandMeisterBridge::getTalker()
void BrandMeisterBridge::setTalker(const char* call, const char* name)
{
if ((proxy == NULL) ||
(store == NULL))
{
syslog(LOG_ERR, "BrandMeister bridge is not configured");
return;
}
if (*call == '*')
{
// Do not process conference call-sign
@ -61,12 +93,12 @@ void BrandMeisterBridge::setTalker(const char* call, const char* name)
call = buffer;
}
uint32_t number = store.getPrivateIDForCall(call);
uint32_t number = store->getPrivateIDForCall(call);
if (number == 0)
number = ECHOLINK_DEFAULT_USER_NUMBER;
syslog(LOG_INFO, "Set talker ID to %d for call-sign %s", number, call);
proxy.setTalkerID(number);
proxy->setTalkerID(number);
}
void BrandMeisterBridge::handleChatMessage(const char* text)
@ -76,6 +108,13 @@ void BrandMeisterBridge::handleChatMessage(const char* text)
// UB3AMO Moscow T I N A O
// ->UA0LQE-L USSURIISK
if ((proxy == NULL) ||
(store == NULL))
{
syslog(LOG_ERR, "BrandMeister bridge is not configured");
return;
}
if (strncmp(text, "CONF ", 5) == 0)
{
const char* delimiter = strstr(text, "\n->");
@ -88,7 +127,7 @@ void BrandMeisterBridge::handleChatMessage(const char* text)
{
uint32_t number = ECHOLINK_DEFAULT_USER_NUMBER;
syslog(LOG_INFO, "Set talker ID to %d (call-sign was not fit into chat message)", number);
proxy.setTalkerID(number);
proxy->setTalkerID(number);
}
}
}

View file

@ -13,14 +13,17 @@ class BrandMeisterBridge
BrandMeisterBridge();
~BrandMeisterBridge();
void setProxyConfiguration(const char* configuration);
void setStoreConfiguration(const char* configuration);
const char* getTalker();
void setTalker(const char* call, const char* name);
void handleChatMessage(const char* text);
private:
PatchCordProxy proxy;
UserDataStore store;
PatchCordProxy* proxy;
UserDataStore* store;
char* talker;
};

View file

@ -412,6 +412,15 @@ bool ModuleEchoLink::initialize(void)
return false;
}
if (cfg().getValue(cfgName(), "BRIDGE_PROXY", value))
{
bridge.setProxyConfiguration(value.c_str());
}
if (cfg().getValue(cfgName(), "BRIDGE_STORE", value))
{
bridge.setStoreConfiguration(value.c_str());
}
// Initialize directory server communication
dir = new Directory(servers, mycall, password, location, bind_addr);
dir->statusChanged.connect(mem_fun(*this, &ModuleEchoLink::onStatusChanged));

View file

@ -18,17 +18,19 @@
#define VALUE_CORD_OUTGOING_SOURCE_ID 1
#define VALUE_CORD_INCOMING_SOURCE_ID 4
PatchCordProxy::PatchCordProxy(uint32_t number) :
number(number),
banner(NULL)
PatchCordProxy::PatchCordProxy(uint32_t network, uint32_t link)
{
banner = NULL;
number = link;
asprintf(&path, OBJECT_PATH "/%d", network);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
}
PatchCordProxy::~PatchCordProxy()
{
free(banner);
dbus_connection_unref(connection);
free(banner);
free(path);
}
void PatchCordProxy::setTalkerID(uint32_t value)
@ -46,7 +48,7 @@ uint32_t PatchCordProxy::getTalkerID()
void PatchCordProxy::getContextBanner()
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "getContextList");
const char* name = AUTOPATCH_LINK_NAME;
@ -82,7 +84,7 @@ void PatchCordProxy::getContextBanner()
void PatchCordProxy::setVendorSpecificValue(uint32_t key, uint32_t value)
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "setVendorSpecificValue");
dbus_message_append_args(message,
@ -109,7 +111,7 @@ void PatchCordProxy::setVendorSpecificValue(uint32_t key, uint32_t value)
uint32_t PatchCordProxy::getVendorSpecificValue(uint32_t key)
{
DBusMessage* message = dbus_message_new_method_call(
SERVICE_NAME, OBJECT_PATH,
SERVICE_NAME, path,
INTERFACE_NAME, "getContextData");
dbus_message_append_args(message,

View file

@ -10,7 +10,7 @@ class PatchCordProxy
{
public:
PatchCordProxy(uint32_t number);
PatchCordProxy(uint32_t network, uint32_t link);
~PatchCordProxy();
void setTalkerID(uint32_t value);
@ -19,6 +19,8 @@ class PatchCordProxy
private:
DBusConnection* connection;
char* path;
uint32_t number;
char* banner;