Initial import
This commit is contained in:
commit
660133c812
28 changed files with 3983 additions and 0 deletions
95
SVXLink/echolink/BrandMeisterBridge.cpp
Normal file
95
SVXLink/echolink/BrandMeisterBridge.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#include "BrandMeisterBridge.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BrandMeisterBridge::~BrandMeisterBridge()
|
||||
{
|
||||
free(talker);
|
||||
}
|
||||
|
||||
// Interface methods for ModuleEchoLink
|
||||
|
||||
const char* BrandMeisterBridge::getTalker()
|
||||
{
|
||||
free(talker);
|
||||
uint32_t number = proxy.getTalkerID();
|
||||
|
||||
char call[LONG_CALLSIGN_LENGTH];
|
||||
char text[SLOW_DATA_TEXT_LENGTH];
|
||||
if ((number != 0) &&
|
||||
(store.getCredentialsForID(number, call, text)))
|
||||
{
|
||||
asprintf(&talker, "%s %s", call, text);
|
||||
return talker;
|
||||
}
|
||||
|
||||
asprintf(&talker, "DMR ID: %d", number);
|
||||
return talker;
|
||||
}
|
||||
|
||||
void BrandMeisterBridge::setTalker(const char* call, const char* name)
|
||||
{
|
||||
if (*call == '*')
|
||||
{
|
||||
// Do not process conference call-sign
|
||||
return;
|
||||
}
|
||||
|
||||
const char* delimiter = strpbrk(call, " -\n");
|
||||
if (delimiter != NULL)
|
||||
{
|
||||
// Remove characters after call-sign
|
||||
size_t length = delimiter - call;
|
||||
char* buffer = (char*)alloca(length + 1);
|
||||
strncpy(buffer, call, length);
|
||||
call = buffer;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void BrandMeisterBridge::handleChatMessage(const char* text)
|
||||
{
|
||||
// CONF Russian Reflector, Open 24/7, Contacts: rv3dhc.link@qip.ru * Call CQ / Use pauses 2sec * [28/500]
|
||||
// R3ABM-L *DSTAR.SU DMR Bridge*
|
||||
// UB3AMO Moscow T I N A O
|
||||
// ->UA0LQE-L USSURIISK
|
||||
|
||||
if (strncmp(text, "CONF ", 5) == 0)
|
||||
{
|
||||
const char* delimiter = strstr(text, "\n->");
|
||||
if (delimiter != NULL)
|
||||
{
|
||||
const char* call = delimiter + 3;
|
||||
setTalker(call, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
28
SVXLink/echolink/BrandMeisterBridge.h
Normal file
28
SVXLink/echolink/BrandMeisterBridge.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#ifndef BRANDMEISTERBRIDGE_H
|
||||
#define BRANDMEISTERBRIDGE_H
|
||||
|
||||
#include "PatchCordProxy.h"
|
||||
#include "UserDataStore.h"
|
||||
|
||||
class BrandMeisterBridge
|
||||
{
|
||||
public:
|
||||
|
||||
BrandMeisterBridge();
|
||||
~BrandMeisterBridge();
|
||||
|
||||
const char* getTalker();
|
||||
void setTalker(const char* call, const char* name);
|
||||
void handleChatMessage(const char* text);
|
||||
|
||||
private:
|
||||
|
||||
PatchCordProxy proxy;
|
||||
UserDataStore store;
|
||||
char* talker;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
59
SVXLink/echolink/CMakeLists.txt
Normal file
59
SVXLink/echolink/CMakeLists.txt
Normal file
|
@ -0,0 +1,59 @@
|
|||
# The name of the module without the Module prefix
|
||||
set(MODNAME EchoLink)
|
||||
|
||||
# Module source code
|
||||
set(MODSRC QsoImpl.cpp)
|
||||
|
||||
# ***
|
||||
pkg_check_modules(DBUS dbus-1)
|
||||
include_directories(${DBUS_INCLUDE_DIRS})
|
||||
set(LIBS ${LIBS} ${DBUS_LIBRARIES} mysqlclient)
|
||||
set(MODSRC ${MODSRC} PatchCordProxy.cpp UserDataStore.cpp BrandMeisterBridge.cpp)
|
||||
# ***
|
||||
|
||||
# Project libraries to link to
|
||||
set(LIBS ${LIBS} echolib)
|
||||
|
||||
# Find the TCL library
|
||||
if(TCL_LIBRARY)
|
||||
set(TCL_LIBRARY_CACHED TRUE)
|
||||
endif(TCL_LIBRARY)
|
||||
find_package(TCL QUIET)
|
||||
if(TCL_FOUND)
|
||||
if (NOT TCL_LIBRARY_CACHED)
|
||||
message("-- Found TCL: ${TCL_LIBRARY}")
|
||||
endif(NOT TCL_LIBRARY_CACHED)
|
||||
else(TCL_FOUND)
|
||||
message(FATAL_ERROR "-- Could NOT find the TCL scripting language")
|
||||
endif(TCL_FOUND)
|
||||
set(LIBS ${LIBS} ${TCL_LIBRARY})
|
||||
include_directories(${TCL_INCLUDE_PATH})
|
||||
|
||||
# Find the GSM codec library and include directory
|
||||
find_package(GSM REQUIRED)
|
||||
if(NOT GSM_FOUND)
|
||||
message(FATAL_ERROR "libgsm not found")
|
||||
endif(NOT GSM_FOUND)
|
||||
include_directories(${GSM_INCLUDE_DIR})
|
||||
set(LIBS ${LIBS} ${GSM_LIBRARY})
|
||||
|
||||
string(TOUPPER MODULE_${MODNAME} VERNAME)
|
||||
|
||||
# Add targets for version files
|
||||
set(VERSION_DEPENDS)
|
||||
add_version_target(${VERNAME} VERSION_DEPENDS)
|
||||
add_version_target(SVXLINK VERSION_DEPENDS)
|
||||
|
||||
# Build the plugin
|
||||
add_library(Module${MODNAME} MODULE Module${MODNAME}.cpp ${MODSRC}
|
||||
${VERSION_DEPENDS}
|
||||
)
|
||||
set_target_properties(Module${MODNAME} PROPERTIES PREFIX "")
|
||||
target_link_libraries(Module${MODNAME} ${LIBS})
|
||||
|
||||
# Install targets
|
||||
install(TARGETS Module${MODNAME} DESTINATION ${SVX_MODULE_INSTALL_DIR})
|
||||
install(FILES ${MODNAME}.tcl DESTINATION ${SVX_SHARE_INSTALL_DIR}/events.d)
|
||||
install_if_not_exists(Module${MODNAME}.conf
|
||||
${SVX_SYSCONF_INSTALL_DIR}/svxlink.d
|
||||
)
|
2084
SVXLink/echolink/ModuleEchoLink.cpp
Normal file
2084
SVXLink/echolink/ModuleEchoLink.cpp
Normal file
File diff suppressed because it is too large
Load diff
276
SVXLink/echolink/ModuleEchoLink.h
Normal file
276
SVXLink/echolink/ModuleEchoLink.h
Normal file
|
@ -0,0 +1,276 @@
|
|||
/**
|
||||
@file ModuleEchoLink.h
|
||||
@brief A module that provides EchoLink connection possibility
|
||||
@author Tobias Blomberg / SM0SVX
|
||||
@date 2004-03-07
|
||||
|
||||
\verbatim
|
||||
A module (plugin) for the multi purpose tranciever frontend system.
|
||||
Copyright (C) 2004-2014 Tobias Blomberg / SM0SVX
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
\endverbatim
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MODULE_ECHOLINK_INCLUDED
|
||||
#define MODULE_ECHOLINK_INCLUDED
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* System Includes
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Project Includes
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <Module.h>
|
||||
#include <EchoLinkQso.h>
|
||||
#include <EchoLinkStationData.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Local Includes
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "version/SVXLINK.h"
|
||||
#include "BrandMeisterBridge.h"
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Forward declarations
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
namespace Async
|
||||
{
|
||||
class Timer;
|
||||
class AudioSplitter;
|
||||
class AudioValve;
|
||||
class AudioSelector;
|
||||
};
|
||||
namespace EchoLink
|
||||
{
|
||||
class Directory;
|
||||
class StationData;
|
||||
class Proxy;
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Namespace
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
//namespace MyNameSpace
|
||||
//{
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Forward declarations of classes inside of the declared namespace
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
class MsgHandler;
|
||||
class QsoImpl;
|
||||
class LocationInfo;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Defines & typedefs
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Exported Global Variables
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Class definitions
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
@brief A module for providing EchoLink connections
|
||||
@author Tobias Blomberg
|
||||
@date 2004-03-07
|
||||
*/
|
||||
class ModuleEchoLink : public Module
|
||||
{
|
||||
public:
|
||||
ModuleEchoLink(void *dl_handle, Logic *logic, const std::string& cfg_name);
|
||||
~ModuleEchoLink(void);
|
||||
bool initialize(void);
|
||||
const char *compiledForVersion(void) const { return SVXLINK_VERSION; }
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Notify the module that the logic core idle state has changed
|
||||
* @param is_idle Set to \em true if the logic core is idle or else
|
||||
* \em false.
|
||||
*
|
||||
* This function is called by the logic core when the idle state changes.
|
||||
*/
|
||||
virtual void logicIdleStateChanged(bool is_idle);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
BrandMeisterBridge bridge;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
STATE_NORMAL,
|
||||
STATE_CONNECT_BY_CALL,
|
||||
STATE_DISCONNECT_BY_CALL
|
||||
} State;
|
||||
typedef std::vector<EchoLink::StationData> StnList;
|
||||
struct NumConStn
|
||||
{
|
||||
unsigned num_con;
|
||||
struct timeval last_con;
|
||||
|
||||
NumConStn(unsigned num, struct timeval &t) : num_con(num), last_con(t) {}
|
||||
};
|
||||
typedef std::map<const std::string, NumConStn> NumConMap;
|
||||
|
||||
static const int DEFAULT_AUTOCON_TIME = 3*60*1000; // Three minutes
|
||||
|
||||
EchoLink::Directory *dir;
|
||||
Async::Timer *dir_refresh_timer;
|
||||
std::string mycall;
|
||||
std::string location;
|
||||
std::string sysop_name;
|
||||
std::string description;
|
||||
std::string allow_ip;
|
||||
bool remote_activation;
|
||||
int pending_connect_id;
|
||||
std::string last_message;
|
||||
std::vector<QsoImpl*> outgoing_con_pending;
|
||||
std::vector<QsoImpl*> qsos;
|
||||
unsigned max_connections;
|
||||
unsigned max_qsos;
|
||||
QsoImpl *talker;
|
||||
bool squelch_is_open;
|
||||
State state;
|
||||
StnList cbc_stns;
|
||||
Async::Timer *cbc_timer;
|
||||
Async::Timer *dbc_timer;
|
||||
regex_t *drop_incoming_regex;
|
||||
regex_t *reject_incoming_regex;
|
||||
regex_t *accept_incoming_regex;
|
||||
regex_t *reject_outgoing_regex;
|
||||
regex_t *accept_outgoing_regex;
|
||||
EchoLink::StationData last_disc_stn;
|
||||
Async::AudioSplitter *splitter;
|
||||
Async::AudioValve *listen_only_valve;
|
||||
Async::AudioSelector *selector;
|
||||
unsigned num_con_max;
|
||||
time_t num_con_ttl;
|
||||
time_t num_con_block_time;
|
||||
NumConMap num_con_map;
|
||||
Async::Timer *num_con_update_timer;
|
||||
bool reject_conf;
|
||||
int autocon_echolink_id;
|
||||
int autocon_time;
|
||||
Async::Timer *autocon_timer;
|
||||
EchoLink::Proxy *proxy;
|
||||
|
||||
void moduleCleanup(void);
|
||||
void activateInit(void);
|
||||
void deactivateCleanup(void);
|
||||
//bool dtmfDigitReceived(char digit, int duration);
|
||||
void dtmfCmdReceived(const std::string& cmd);
|
||||
void dtmfCmdReceivedWhenIdle(const std::string &cmd);
|
||||
void squelchOpen(bool is_open);
|
||||
int audioFromRx(float *samples, int count);
|
||||
void allMsgsWritten(void);
|
||||
|
||||
void onStatusChanged(EchoLink::StationData::Status status);
|
||||
void onStationListUpdated(void);
|
||||
void onError(const std::string& msg);
|
||||
void onIncomingConnection(const Async::IpAddress& ip,
|
||||
const std::string& callsign, const std::string& name,
|
||||
const std::string& priv);
|
||||
void onStateChange(QsoImpl *qso, EchoLink::Qso::State qso_state);
|
||||
void onChatMsgReceived(QsoImpl *qso, const std::string& msg);
|
||||
void onIsReceiving(bool is_receiving, QsoImpl *qso);
|
||||
void destroyQsoObject(QsoImpl *qso);
|
||||
|
||||
void getDirectoryList(Async::Timer *timer=0);
|
||||
|
||||
void createOutgoingConnection(const EchoLink::StationData &station);
|
||||
int audioFromRemote(float *samples, int count, QsoImpl *qso);
|
||||
void audioFromRemoteRaw(EchoLink::Qso::RawPacket *packet,
|
||||
QsoImpl *qso);
|
||||
QsoImpl *findFirstTalker(void) const;
|
||||
void broadcastTalkerStatus(void);
|
||||
void updateDescription(void);
|
||||
void updateEventVariables(void);
|
||||
void connectByCallsign(std::string cmd);
|
||||
void handleConnectByCall(const std::string& cmd);
|
||||
void cbcTimeout(Async::Timer *t);
|
||||
void disconnectByCallsign(const std::string &cmd);
|
||||
void handleDisconnectByCall(const std::string& cmd);
|
||||
void dbcTimeout(Async::Timer *t);
|
||||
int numConnectedStations(void);
|
||||
int listQsoCallsigns(std::list<std::string>& call_list);
|
||||
void handleCommand(const std::string& cmd);
|
||||
void commandFailed(const std::string& cmd);
|
||||
void connectByNodeId(int node_id);
|
||||
void checkIdle(void);
|
||||
void checkAutoCon(Async::Timer *timer=0);
|
||||
bool numConCheck(const std::string &callsign);
|
||||
void numConUpdate(void);
|
||||
void replaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to) const;
|
||||
|
||||
}; /* class ModuleEchoLink */
|
||||
|
||||
|
||||
//} /* namespace */
|
||||
|
||||
#endif /* MODULE_ECHOLINK_INCLUDED */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This file has not been truncated
|
||||
*/
|
154
SVXLink/echolink/PatchCordProxy.cpp
Normal file
154
SVXLink/echolink/PatchCordProxy.cpp
Normal file
|
@ -0,0 +1,154 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#include "PatchCordProxy.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define INTERFACE_NAME "me.burnaway.BrandMeister"
|
||||
#define SERVICE_NAME INTERFACE_NAME
|
||||
#define OBJECT_PATH "/me/burnaway/BrandMeister"
|
||||
|
||||
// From AutoPatch.cpp
|
||||
#define AUTOPATCH_LINK_NAME "AutoPatch"
|
||||
|
||||
// From PatchCord.h
|
||||
#define VALUE_CORD_OUTGOING_SOURCE_ID 1
|
||||
#define VALUE_CORD_INCOMING_SOURCE_ID 4
|
||||
|
||||
PatchCordProxy::PatchCordProxy(uint32_t number) :
|
||||
number(number),
|
||||
banner(NULL)
|
||||
{
|
||||
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
|
||||
}
|
||||
|
||||
PatchCordProxy::~PatchCordProxy()
|
||||
{
|
||||
free(banner);
|
||||
dbus_connection_unref(connection);
|
||||
}
|
||||
|
||||
void PatchCordProxy::setTalkerID(uint32_t value)
|
||||
{
|
||||
getContextBanner();
|
||||
setVendorSpecificValue(VALUE_CORD_OUTGOING_SOURCE_ID, value);
|
||||
}
|
||||
|
||||
uint32_t PatchCordProxy::getTalkerID()
|
||||
{
|
||||
getContextBanner();
|
||||
return getVendorSpecificValue(VALUE_CORD_INCOMING_SOURCE_ID);
|
||||
}
|
||||
|
||||
void PatchCordProxy::getContextBanner()
|
||||
{
|
||||
DBusMessage* message = dbus_message_new_method_call(
|
||||
SERVICE_NAME, OBJECT_PATH,
|
||||
INTERFACE_NAME, "getContextList");
|
||||
|
||||
const char* name = AUTOPATCH_LINK_NAME;
|
||||
|
||||
dbus_message_append_args(message,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_UINT32, &number,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
DBusPendingCall* pending;
|
||||
if (dbus_connection_send_with_reply(connection, message, &pending, -1))
|
||||
{
|
||||
dbus_connection_flush(connection);
|
||||
dbus_message_unref(message);
|
||||
dbus_pending_call_block(pending);
|
||||
message = dbus_pending_call_steal_reply(pending);
|
||||
char** array;
|
||||
int count;
|
||||
if ((dbus_message_get_args(message, NULL,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &count,
|
||||
DBUS_TYPE_INVALID)) &&
|
||||
(count > 0))
|
||||
{
|
||||
free(banner);
|
||||
banner = strdup(*array);
|
||||
dbus_free_string_array(array);
|
||||
}
|
||||
dbus_pending_call_unref(pending);
|
||||
}
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
void PatchCordProxy::setVendorSpecificValue(uint32_t key, uint32_t value)
|
||||
{
|
||||
DBusMessage* message = dbus_message_new_method_call(
|
||||
SERVICE_NAME, OBJECT_PATH,
|
||||
INTERFACE_NAME, "setVendorSpecificValue");
|
||||
|
||||
dbus_message_append_args(message,
|
||||
DBUS_TYPE_STRING, &banner,
|
||||
DBUS_TYPE_UINT32, &key,
|
||||
DBUS_TYPE_UINT32, &value,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
DBusPendingCall* pending;
|
||||
if (dbus_connection_send_with_reply(connection, message, &pending, -1))
|
||||
{
|
||||
dbus_connection_flush(connection);
|
||||
dbus_message_unref(message);
|
||||
dbus_pending_call_block(pending);
|
||||
message = dbus_pending_call_steal_reply(pending);
|
||||
dbus_pending_call_unref(pending);
|
||||
}
|
||||
dbus_message_unref(message);
|
||||
|
||||
// Each call of dbus_message_unref removes banner from the heap
|
||||
banner = NULL;
|
||||
}
|
||||
|
||||
uint32_t PatchCordProxy::getVendorSpecificValue(uint32_t key)
|
||||
{
|
||||
DBusMessage* message = dbus_message_new_method_call(
|
||||
SERVICE_NAME, OBJECT_PATH,
|
||||
INTERFACE_NAME, "getContextData");
|
||||
|
||||
dbus_message_append_args(message,
|
||||
DBUS_TYPE_STRING, &banner,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
DBusPendingCall* pending;
|
||||
if (dbus_connection_send_with_reply(connection, message, &pending, -1))
|
||||
{
|
||||
dbus_connection_flush(connection);
|
||||
dbus_message_unref(message);
|
||||
dbus_pending_call_block(pending);
|
||||
message = dbus_pending_call_steal_reply(pending);
|
||||
const char* name;
|
||||
const char* address;
|
||||
dbus_uint32_t type;
|
||||
dbus_uint32_t state;
|
||||
dbus_uint32_t number;
|
||||
dbus_uint32_t* values;
|
||||
int count;
|
||||
if (dbus_message_get_args(message, NULL,
|
||||
DBUS_TYPE_STRING, &banner,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_UINT32, &type,
|
||||
DBUS_TYPE_UINT32, &number,
|
||||
DBUS_TYPE_STRING, &address,
|
||||
DBUS_TYPE_UINT32, &state,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &values, &count,
|
||||
DBUS_TYPE_INVALID))
|
||||
value = values[key];
|
||||
dbus_pending_call_unref(pending);
|
||||
}
|
||||
|
||||
dbus_message_unref(message);
|
||||
|
||||
// Each call of dbus_message_unref removes banner from the heap
|
||||
banner = NULL;
|
||||
|
||||
return value;
|
||||
}
|
31
SVXLink/echolink/PatchCordProxy.h
Normal file
31
SVXLink/echolink/PatchCordProxy.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#ifndef PATCHCORDPROXY_H
|
||||
#define PATCHCORDPROXY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
class PatchCordProxy
|
||||
{
|
||||
public:
|
||||
|
||||
PatchCordProxy(uint32_t number);
|
||||
~PatchCordProxy();
|
||||
|
||||
void setTalkerID(uint32_t value);
|
||||
uint32_t getTalkerID();
|
||||
|
||||
private:
|
||||
|
||||
DBusConnection* connection;
|
||||
uint32_t number;
|
||||
char* banner;
|
||||
|
||||
void getContextBanner();
|
||||
void setVendorSpecificValue(uint32_t key, uint32_t value);
|
||||
uint32_t getVendorSpecificValue(uint32_t key);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
137
SVXLink/echolink/UserDataStore.cpp
Normal file
137
SVXLink/echolink/UserDataStore.cpp
Normal file
|
@ -0,0 +1,137 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#include "UserDataStore.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#define GET_ID_FOR_CALL 0
|
||||
#define GET_CREDENTIALS_FOR_ID 1
|
||||
|
||||
UserDataStore::UserDataStore(const char* file) :
|
||||
connection(NULL)
|
||||
{
|
||||
const char* queries[] =
|
||||
{
|
||||
// GET_ID_FOR_CALL
|
||||
"SELECT `ID`"
|
||||
" FROM Users"
|
||||
" WHERE `Call` = ?"
|
||||
" ORDER BY `Priority`"
|
||||
" LIMIT 1",
|
||||
// GET_CREDENTIALS_FOR_ID
|
||||
"SELECT `Call`, `Text`"
|
||||
" FROM Users"
|
||||
" WHERE `ID` = ?",
|
||||
};
|
||||
|
||||
connection = mysql_init(NULL);
|
||||
|
||||
mysql_options(connection, MYSQL_READ_DEFAULT_FILE, realpath(file, NULL));
|
||||
mysql_real_connect(connection, NULL, NULL, NULL, NULL, 0, NULL, CLIENT_REMEMBER_OPTIONS);
|
||||
|
||||
my_bool active = true;
|
||||
mysql_options(connection, MYSQL_OPT_RECONNECT, &active);
|
||||
|
||||
for (size_t index = 0; index < PREPARED_STATEMENT_COUNT; index ++)
|
||||
{
|
||||
const char* query = queries[index];
|
||||
statements[index] = mysql_stmt_init(connection);
|
||||
mysql_stmt_prepare(statements[index], query, strlen(query));
|
||||
}
|
||||
|
||||
const char* error = mysql_error(connection);
|
||||
if ((error != NULL) && (*error != '\0'))
|
||||
syslog(LOG_CRIT, "MySQL error: %s\n", error);
|
||||
}
|
||||
|
||||
UserDataStore::~UserDataStore()
|
||||
{
|
||||
for (size_t index = 0; index < PREPARED_STATEMENT_COUNT; index ++)
|
||||
mysql_stmt_close(statements[index]);
|
||||
|
||||
mysql_close(connection);
|
||||
}
|
||||
|
||||
// Public methods
|
||||
|
||||
uint32_t UserDataStore::getPrivateIDForCall(const char* call)
|
||||
{
|
||||
uint32_t number;
|
||||
size_t length = strlen(call);
|
||||
|
||||
return
|
||||
execute(GET_ID_FOR_CALL, 1, 1,
|
||||
MYSQL_TYPE_STRING, call, length,
|
||||
MYSQL_TYPE_LONG, &number) *
|
||||
number;
|
||||
}
|
||||
|
||||
|
||||
bool UserDataStore::getCredentialsForID(uint32_t number, char* call, char* text)
|
||||
{
|
||||
return
|
||||
execute(GET_CREDENTIALS_FOR_ID, 1, 2,
|
||||
MYSQL_TYPE_LONG, &number,
|
||||
MYSQL_TYPE_STRING, call, LONG_CALLSIGN_LENGTH + 1,
|
||||
MYSQL_TYPE_STRING, text, SLOW_DATA_TEXT_LENGTH + 1);
|
||||
}
|
||||
|
||||
// Internals
|
||||
|
||||
MYSQL_BIND* UserDataStore::bind(int count, va_list* arguments)
|
||||
{
|
||||
MYSQL_BIND* bindings = NULL;
|
||||
if (count > 0)
|
||||
{
|
||||
bindings = (MYSQL_BIND*)calloc(count, sizeof(MYSQL_BIND));
|
||||
for (int index = 0; index < count; index ++)
|
||||
{
|
||||
int type = va_arg(*arguments, int);
|
||||
bindings[index].buffer_type = (enum_field_types)type;
|
||||
bindings[index].buffer = va_arg(*arguments, void*);
|
||||
if ((type == MYSQL_TYPE_STRING) ||
|
||||
(type == MYSQL_TYPE_DATETIME))
|
||||
{
|
||||
bindings[index].buffer_length = va_arg(*arguments, int);
|
||||
bindings[index].length = &bindings[index].buffer_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bindings;
|
||||
}
|
||||
|
||||
bool UserDataStore::execute(int index, int count1, int count2, ...)
|
||||
{
|
||||
bool result = true;
|
||||
MYSQL_STMT* statement = statements[index];
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, count2);
|
||||
MYSQL_BIND* parameters = bind(count1, &arguments);
|
||||
MYSQL_BIND* columns = bind(count2, &arguments);
|
||||
va_end(arguments);
|
||||
|
||||
if ((parameters && mysql_stmt_bind_param(statement, parameters)) ||
|
||||
(columns && mysql_stmt_bind_result(statement, columns)) ||
|
||||
mysql_stmt_execute(statement) ||
|
||||
(columns && mysql_stmt_store_result(statement)))
|
||||
{
|
||||
const char* error = mysql_stmt_error(statement);
|
||||
syslog(LOG_CRIT, "MySQL error while processing statement %d: %s\n", index, error);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result && columns)
|
||||
{
|
||||
result = !mysql_stmt_fetch(statement);
|
||||
mysql_stmt_free_result(statement);
|
||||
}
|
||||
|
||||
free(columns);
|
||||
free(parameters);
|
||||
return result;
|
||||
}
|
||||
|
35
SVXLink/echolink/UserDataStore.h
Normal file
35
SVXLink/echolink/UserDataStore.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2015 by Artem Prilutskiy
|
||||
|
||||
#ifndef USERDATASTORE_H
|
||||
#define USERDATASTORE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
#define PREPARED_STATEMENT_COUNT 2
|
||||
|
||||
#define LONG_CALLSIGN_LENGTH 8
|
||||
#define SLOW_DATA_TEXT_LENGTH 20
|
||||
|
||||
class UserDataStore
|
||||
{
|
||||
public:
|
||||
|
||||
UserDataStore(const char* file);
|
||||
~UserDataStore();
|
||||
|
||||
uint32_t getPrivateIDForCall(const char* call);
|
||||
bool getCredentialsForID(uint32_t number, char* call, char* text);
|
||||
|
||||
protected:
|
||||
|
||||
MYSQL* connection;
|
||||
MYSQL_STMT* statements[PREPARED_STATEMENT_COUNT];
|
||||
|
||||
MYSQL_BIND* bind(int count, va_list* arguments);
|
||||
bool execute(int index, int count1, int count2, ...);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue