mirror of
https://github.com/LX3JL/xlxd.git
synced 2025-12-06 07:42:01 +01:00
Implement configuration file
This is a first step in implementing a configuration file for xlxd. It supports reflector callsign, listening IP, and ambe transcoder IP. It loads the configuration file from /xlxd/xlxd.config (unless redefine at compile time). It keeps backward compatibility with the command line parameters that will override the values in the config file. Gbp-Pq: Name 0006-Implement-configuration-file.patch
This commit is contained in:
parent
adec5c8d14
commit
1e6c57e989
|
|
@ -78,9 +78,9 @@ Please use the stable version listed above, we cannot support others.
|
|||
# cp ~/xlxd/scripts/xlxd /etc/init.d/xlxd
|
||||
```
|
||||
|
||||
###### Adapt the default startup parameters to your needs
|
||||
###### Adapt the default configuration to your needs
|
||||
```
|
||||
# pico /etc/init.d/xlxd
|
||||
# pico /xlxd/xlxd.config
|
||||
```
|
||||
###### Download the dmrid.dat from the XLXAPI server to your xlxd folder
|
||||
```
|
||||
|
|
|
|||
15
config/xlxd.config
Normal file
15
config/xlxd.config
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#########################################################################################
|
||||
# XLXD config file
|
||||
#
|
||||
# one line per entry
|
||||
# each entry specifies an option
|
||||
#
|
||||
#########################################################################################
|
||||
# the reflector callsign - default N0CALL
|
||||
callsign N0CALL
|
||||
|
||||
# listening IP address - default 0.0.0.0
|
||||
listen 0.0.0.0
|
||||
|
||||
# AMBE transcoder IP address - default 127.0.0.1
|
||||
transcoder 127.0.0.1
|
||||
|
|
@ -19,7 +19,6 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|||
# change below settings according to your system
|
||||
NAME="xlxd"
|
||||
DAEMON="/xlxd/xlxd"
|
||||
ARGUMENTS="XLX999 192.168.1.240 127.0.0.1"
|
||||
PIDFILE="/var/log/xlxd.pid"
|
||||
USER=root
|
||||
GROUP=root
|
||||
|
|
@ -31,7 +30,7 @@ start () {
|
|||
# start daemon
|
||||
|
||||
echo -n "Starting $NAME: "
|
||||
start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background -- $ARGUMENTS
|
||||
start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background
|
||||
RETVAL=$?
|
||||
echo
|
||||
sleep 4
|
||||
|
|
|
|||
104
src/cconfig.cpp
Executable file
104
src/cconfig.cpp
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// cconfig.cpp
|
||||
// xlxd
|
||||
//
|
||||
// Created by Alessio Caiazza (IU5BON) on 22/07/2022.
|
||||
// Copyright © 2022 Alessio Caiazza (IU5BON). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "main.h"
|
||||
#include "cconfig.h"
|
||||
#include "ccallsign.h"
|
||||
#include "cip.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
CConfig::CConfig() :
|
||||
m_Callsign("N0CALL"),
|
||||
m_ListenIp(CIp("0.0.0.0")),
|
||||
m_TranscoderIp(CIp("127.0.0.1"))
|
||||
{
|
||||
ReadOptions();
|
||||
}
|
||||
|
||||
|
||||
void CConfig::DumpConfig()
|
||||
{
|
||||
std::cout << "Configuration options" << std::endl;
|
||||
std::cout << "callsign " << GetCallsign() << std::endl;
|
||||
std::cout << "listen " << GetListenIp() << std::endl;
|
||||
std::cout << "transcoder " << GetTranscoderIp() << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// option helpers
|
||||
|
||||
char *CConfig::TrimWhiteSpaces(char *str)
|
||||
{
|
||||
char *end;
|
||||
while ((*str == ' ') || (*str == '\t')) str++;
|
||||
if (*str == 0)
|
||||
return str;
|
||||
end = str + strlen(str) - 1;
|
||||
while ((end > str) && ((*end == ' ') || (*end == '\t') || (*end == '\r'))) end --;
|
||||
*(end + 1) = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
void CConfig::ReadOptions(void)
|
||||
{
|
||||
char sz[256];
|
||||
|
||||
std::ifstream file(CONFIG_PATH);
|
||||
if (file.is_open())
|
||||
{
|
||||
while (file.getline(sz, sizeof(sz)).good())
|
||||
{
|
||||
char *szt = TrimWhiteSpaces(sz);
|
||||
char *szval;
|
||||
|
||||
if ((::strlen(szt) > 0) && szt[0] != '#')
|
||||
{
|
||||
if ((szt = ::strtok(szt, " ,\t")) != NULL)
|
||||
{
|
||||
if ((szval = ::strtok(NULL, " ,\t")) != NULL)
|
||||
{
|
||||
if (::strncmp(szt, "callsign", 8) == 0)
|
||||
{
|
||||
m_Callsign = CCallsign(szval);
|
||||
}
|
||||
else if (strncmp(szt, "listen", 5) == 0)
|
||||
{
|
||||
m_ListenIp = CIp(szval);
|
||||
}
|
||||
else if (strncmp(szt, "transcoder", 10) == 0)
|
||||
{
|
||||
m_TranscoderIp = CIp(szval);
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown option - ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/cconfig.h
Normal file
65
src/cconfig.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// cconfig.h
|
||||
// xlxd
|
||||
//
|
||||
// Created by Alessio Caiazza (IU5BON) on 22/07/2022.
|
||||
// Copyright © 2022 Alessio Caiazza (IU5BON). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef cconfig_h
|
||||
#define cconfig_h
|
||||
|
||||
#include <string>
|
||||
#include "cip.h"
|
||||
#include "ccallsign.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CConfig();
|
||||
|
||||
void DumpConfig();
|
||||
|
||||
// getters
|
||||
const CCallsign &GetCallsign(void) const { return m_Callsign; }
|
||||
const CIp &GetListenIp(void) const { return m_ListenIp; }
|
||||
const CIp &GetTranscoderIp(void) const { return m_TranscoderIp; }
|
||||
|
||||
// setters for bacward compatible CLI parameters
|
||||
void SetCallsign(const CCallsign &callsign) { m_Callsign = callsign; }
|
||||
void SetListenIp(const CIp &ip) { m_ListenIp = ip; }
|
||||
void SetTranscoderIp(const CIp &ip) { m_TranscoderIp = ip; }
|
||||
|
||||
protected:
|
||||
// config
|
||||
void ReadOptions(void);
|
||||
char* TrimWhiteSpaces(char *str);
|
||||
|
||||
protected:
|
||||
CCallsign m_Callsign;
|
||||
CIp m_ListenIp;
|
||||
CIp m_TranscoderIp;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif /* cconfig_h */
|
||||
22
src/main.cpp
22
src/main.cpp
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "creflector.h"
|
||||
#include "cconfig.h"
|
||||
|
||||
#include "syslog.h"
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -86,21 +87,34 @@ int main(int argc, const char * argv[])
|
|||
|
||||
#endif
|
||||
|
||||
CConfig conf = CConfig();
|
||||
|
||||
// check arguments
|
||||
if ( argc != 4 )
|
||||
if ( argc == 4 )
|
||||
{
|
||||
conf.SetCallsign(CCallsign(argv[1]));
|
||||
conf.SetListenIp(CIp(argv[2]));
|
||||
conf.SetTranscoderIp(CIp(argv[3]));
|
||||
}
|
||||
else if ( argc != 1 )
|
||||
{
|
||||
std::cout << "Usage: xlxd callsign xlxdip ambedip" << std::endl;
|
||||
std::cout << "example: xlxd XLX999 192.168.178.212 127.0.0.1" << std::endl;
|
||||
|
||||
std::cout << "Startup parameters can also be defined in " << CONFIG_PATH << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// splash
|
||||
std::cout << "Starting xlxd " << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_REVISION << std::endl << std::endl;
|
||||
|
||||
conf.DumpConfig();
|
||||
|
||||
// initialize reflector
|
||||
g_Reflector.SetCallsign(argv[1]);
|
||||
g_Reflector.SetListenIp(CIp(argv[2]));
|
||||
g_Reflector.SetTranscoderIp(CIp(CIp(argv[3])));
|
||||
g_Reflector.SetCallsign(conf.GetCallsign());
|
||||
g_Reflector.SetListenIp(conf.GetListenIp());
|
||||
g_Reflector.SetTranscoderIp(conf.GetTranscoderIp());
|
||||
|
||||
// and let it run
|
||||
if ( !g_Reflector.Start() )
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@
|
|||
|
||||
// system paths -------------------------------------------------
|
||||
|
||||
#ifndef CONFIG_PATH
|
||||
#define CONFIG_PATH "/xlxd/xlxd.config"
|
||||
#endif
|
||||
#define XML_PATH "/var/log/xlxd.xml"
|
||||
#define WHITELIST_PATH "/xlxd/xlxd.whitelist"
|
||||
#define BLACKLIST_PATH "/xlxd/xlxd.blacklist"
|
||||
|
|
|
|||
Loading…
Reference in a new issue