diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..58dd0fa --- /dev/null +++ b/src/Makefile @@ -0,0 +1,109 @@ +# Copyright (c) 2020 by Thomas A. Early N7TAE +# +# 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, see . + +# locations for the executibles and other files are set here +# NOTE: IF YOU CHANGE THESE, YOU WILL NEED TO UPDATE THE service.* FILES AND +# if you change these locations, make sure the sgs.service file is updated! +# you will also break hard coded paths in the dashboard file, index.php. + +# if you make changed in these two variable, you'll need to change things +# in the main.h file as well as the systemd service file. +BINDIR=/usr/local/bin +CFGDIR=/usr/local/etc +DATADIR=/var/lib/xlxd + +################## This is the part you can safely edit ####################### +# uncomment the next line for debugging support +#DEBUG=true +# uncomment the next line for a DStar only xrf reflector (instead of xlx) +#NOXLX=true +# uncomment the next line for no G3 support +#NOG3=true +############################################################################### + +CC=g++ + +ifdef DEBUG +CFLAGS=-ggdb3 -c -std=c++11 -MMD -MD -c +else +CFLAGS=-c -std=c++11 -MMD -MD -c +endif +ifdef NOXLX +CFLAGS += -DNO_XLX +endif +ifdef NOG3 +CFLAGS += -DNO_G3 +endif + +LDFLAGS=-pthread + +XRFSRCS = cbuffer.cpp ccallsign.cpp ccallsignlist.cpp ccallsignlistitem.cpp cclient.cpp cclients.cpp cdcsclient.cpp cdcsprotocol.cpp cdextraclient.cpp cdextrapeer.cpp cdextraprotocol.cpp cdplusclient.cpp cdplusprotocol.cpp cdvframepacket.cpp cdvheaderpacket.cpp cdvlastframepacket.cpp cgatekeeper.cpp cip.cpp cnotification.cpp cpacket.cpp cpacketstream.cpp cpeercallsignlist.cpp cpeer.cpp cpeers.cpp cprotocol.cpp cprotocols.cpp creflector.cpp ctimepoint.cpp cudpsocket.cpp cuser.cpp cusers.cpp cversion.cpp main.cpp +XLXSRCS = cbmclient.cpp cbmpeer.cpp cbptc19696.cpp ccodecstream.cpp ccrc.cpp cdmriddir.cpp cdmriddirfile.cpp cdmriddirhttp.cpp cdmrmmdvmclient.cpp cdmrmmdvmprotocol.cpp cdmrplusclient.cpp cdmrplusprotocol.cpp cgolay2087.cpp cgolay24128.cpp chamming.cpp cqr1676.cpp crs129.cpp csemaphore.cpp ctranscoder.cpp cutils.cpp cwiresxcmd.cpp cwiresxcmdhandler.cpp cwiresxinfo.cpp cxlxclient.cpp cxlxprotocol.cpp cxlxpeer.cpp cysfclient.cpp cysfconvolution.cpp cysffich.cpp cysfnode.cpp cysfnodedir.cpp cysfnodedirfile.cpp cysfnodedirhttp.cpp cysfpayload.cpp cysfprotocol.cpp cysfutils.cpp +G3SRCS = cg3client.cpp cg3protocol.cpp crawsocket.cpp cudpmsgsocket.cpp + +SRCS = $(XRFSRCS) +ifndef NOXLX +SRCS += $(XLXSRCS) +endif +ifndef NOG3 +SRCS += $(G3SRCS) +endif + +OBJS = $(SRCS:.cpp=.o) +DEPS = $(SRCS:.cpp=.d) + +ifdef NOXLX +EXE=xrfd +else +EXE=xlxd +endif + +all : $(EXE) + +$(EXE) : $(OBJS) + $(CC) $^ -o $@ $(LDFLAGS) + +%.o : %.cpp + g++ $(CFLAGS) $< -o $@ + +clean : + $(RM) *.o *.d xlxd xrfd + +-include $(DEPS) + +install : $(EXE).blacklist $(EXE).whitelist $(EXE).interlink $(EXE).terminal $(EXE).service $(EXE) + ln -s $(shell pwd)/$(EXE).blacklist $(CFGDIR)/$(EXE).blacklist + ln -s $(shell pwd)/$(EXE).whitelist $(CFGDIR)/$(EXE).whitelist + ln -s $(shell pwd)/$(EXE).interlink $(CFGDIR)/$(EXE).interlink +ifndef NOG3 + ln -s $(shell pwd)/$(EXE).terminal $(CFGDIR)/$(EXE).terminal +endif + cp -f $(EXE).service /etc/systemd/system/ + cp -f $(EXE) $(BINDIR) + mkdir -p $(DATADIR) + systemctl enable $(EXE).service + systemctl daemon-reload + systemctl start $(EXE) + +uninstall : + rm -f $(CFGDIR)/$(EXE).blacklist + rm -f $(CFGDIR)/$(EXE).whitelist + rm -f $(CFGDIR)/$(EXE).interlink + rm -f $(CFGDIR)/$(EXE).terminal + systemctl stop $(EXE).service + rm -f $(CFGDIR)/dmrid.dat + systemctl disable $(EXE).service + rm -f /etc/systemd/system/xlxd.service + systemctl daemon-reload diff --git a/src/cbuffer.cpp b/src/cbuffer.cpp index 479abee..6603e5f 100644 --- a/src/cbuffer.cpp +++ b/src/cbuffer.cpp @@ -19,135 +19,128 @@ // 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 . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- -#include "main.h" #include -#include "cprotocol.h" +#include "cbuffer.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor -CBuffer::CBuffer(uint8 *buffer, int len) +CBuffer::CBuffer(uint8_t *buffer, int len) { - resize(len); - ::memcpy(data(), buffer, len); + m_data.resize(len); + ::memcpy(m_data.data(), buffer, len); } //////////////////////////////////////////////////////////////////////////////////////// // set -void CBuffer::Set(uint8 *buffer, int len) +void CBuffer::Set(uint8_t *buffer, int len) { - resize(len); - ::memcpy(data(), buffer, len); + m_data.resize(len); + ::memcpy(m_data.data(), buffer, len); } void CBuffer::Set(const char *sz) { - resize(::strlen(sz)+1); - ::strcpy((char *)data(), sz); + m_data.resize(::strlen(sz)+1); + ::strcpy((char *)m_data.data(), sz); } -void CBuffer::Append(uint8 *buffer, int len) +void CBuffer::Append(const uint8_t *buffer, int len) { - int n = (int)size(); - resize(n+len); - ::memcpy(&(data()[n]), buffer, len); + int n = (int)m_data.size(); + m_data.resize(n+len); + ::memcpy(&(m_data.data()[n]), buffer, len); } -void CBuffer::Append(uint8 ui, int len) +void CBuffer::Append(uint8_t ui, int len) { - int n = (int)size(); - resize(n+len); - ::memset(&(data()[n]), ui, len); + int n = (int)m_data.size(); + m_data.resize(n+len); + ::memset(&(m_data.data()[n]), ui, len); } -void CBuffer::Append(uint8 ui) +void CBuffer::Append(uint8_t ui) { - int n = (int)size(); - resize(n+sizeof(uint8)); - ::memcpy(&(data()[n]), &ui, sizeof(uint8)); + int n = (int)m_data.size(); + m_data.resize(n+sizeof(uint8_t)); + ::memcpy(&(m_data.data()[n]), &ui, sizeof(uint8_t)); } -void CBuffer::Append(uint16 ui) +void CBuffer::Append(uint16_t ui) { - int n = (int)size(); - resize(n+sizeof(uint16)); - ::memcpy(&(data()[n]), &ui, sizeof(uint16)); + int n = (int)m_data.size(); + m_data.resize(n+sizeof(uint16_t)); + ::memcpy(&(m_data.data()[n]), &ui, sizeof(uint16_t)); } -void CBuffer::Append(uint32 ui) +void CBuffer::Append(uint32_t ui) { - int n = (int)size(); - resize(n+sizeof(uint32)); - ::memcpy(&(data()[n]), &ui, sizeof(uint32)); + int n = (int)m_data.size(); + m_data.resize(n+sizeof(uint32_t)); + ::memcpy(&(m_data.data()[n]), &ui, sizeof(uint32_t)); } void CBuffer::Append(const char *sz) { - Append((uint8 *)sz, (int)strlen(sz)); - Append((uint8)0x00); + Append((uint8_t *)sz, (int)strlen(sz)); + Append((uint8_t)0x00); } -void CBuffer::ReplaceAt(int i, uint8 ui) +void CBuffer::ReplaceAt(int i, uint8_t ui) { - if ( size() < (i+sizeof(uint8)) ) - { - resize(i+sizeof(uint8)); - } - *(uint8 *)(&(data()[i])) = ui; + if ( m_data.size() < (i+sizeof(uint8_t)) ) { + m_data.resize(i+sizeof(uint8_t)); + } + *(uint8_t *)(&(m_data.data()[i])) = ui; } -void CBuffer::ReplaceAt(int i, uint16 ui) +void CBuffer::ReplaceAt(int i, uint16_t ui) { - if ( size() < (i+sizeof(uint16)) ) - { - resize(i+sizeof(uint16)); - } - *(uint16 *)(&(data()[i])) = ui; + if ( m_data.size() < (i+sizeof(uint16_t)) ) { + m_data.resize(i+sizeof(uint16_t)); + } + *(uint16_t *)(&(m_data.data()[i])) = ui; } -void CBuffer::ReplaceAt(int i, uint32 ui) +void CBuffer::ReplaceAt(int i, uint32_t ui) { - if ( size() < (i+sizeof(uint32)) ) - { - resize(i+sizeof(uint32)); - } - *(uint32 *)(&(data()[i])) = ui; + if ( m_data.size() < (i+sizeof(uint32_t)) ) { + m_data.resize(i+sizeof(uint32_t)); + } + *(uint32_t *)(&(m_data.data()[i])) = ui; } -void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len) +void CBuffer::ReplaceAt(int i, const uint8_t *ptr, int len) { - if ( size() < (i+len) ) - { - resize(i+len); - } - ::memcpy(&(data()[i]), ptr, len); + if ( m_data.size() < unsigned(i+len) ) { + m_data.resize(i+len); + } + ::memcpy(&(m_data.data()[i]), ptr, len); } //////////////////////////////////////////////////////////////////////////////////////// // operation -int CBuffer::Compare(uint8 *buffer, int len) const +int CBuffer::Compare(uint8_t *buffer, int len) const { - int result = -1; - if ( size() >= len ) - { - result = ::memcmp(data(), buffer, len); - } - return result; + int result = -1; + if ( m_data.size() >= unsigned(len) ) { + result = ::memcmp(m_data.data(), buffer, len); + } + return result; } -int CBuffer::Compare(uint8 *buffer, int off, int len) const +int CBuffer::Compare(uint8_t *buffer, int off, int len) const { - int result = -1; - if ( size() >= (off+len) ) - { - result = ::memcmp(&(data()[off]), buffer, len); - } - return result; + int result = -1; + if ( m_data.size() >= unsigned(off+len) ) { + result = ::memcmp(&(m_data.data()[off]), buffer, len); + } + return result; } @@ -156,25 +149,23 @@ int CBuffer::Compare(uint8 *buffer, int off, int len) const bool CBuffer::operator ==(const CBuffer &Buffer) const { - if ( size() == Buffer.size() ) - { - return (::memcmp((const char *)data(), (const char *)Buffer.data(), size()) == 0); - } - return false; + if ( m_data.size() == Buffer.m_data.size() ) { + return (::memcmp((const char *)m_data.data(), (const char *)Buffer.m_data.data(), m_data.size()) == 0); + } + return false; } bool CBuffer::operator ==(const char *sz) const { - if ( size() == ::strlen(sz) ) - { - return (::memcmp((const char *)data(), sz, size()) == 0); - } - return false; + if ( m_data.size() == ::strlen(sz) ) { + return (::memcmp((const char *)m_data.data(), sz, m_data.size()) == 0); + } + return false; } CBuffer::operator const char *() const { - return (const char *)data(); + return (const char *)m_data.data(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -182,47 +173,32 @@ CBuffer::operator const char *() const void CBuffer::DebugDump(std::ofstream &debugout) const { - // dump an hex line - for ( int i = 0; i < size(); i++ ) - { - char sz[16]; - //sprintf(sz, "%02X", data()[i]); - sprintf(sz, "0x%02X", data()[i]); - debugout << sz; - if ( i == size()-1 ) - { - debugout << std::endl; - } - else - { - debugout << ','; - } - } + // dump an hex line + for ( unsigned int i = 0; i < m_data.size(); i++ ) { + char sz[16]; + //sprintf(sz, "%02X", m_data.data()[i]); + sprintf(sz, "0x%02X", m_data.data()[i]); + debugout << sz; + if ( i == m_data.size()-1 ) { + debugout << std::endl; + } else { + debugout << ','; + } + } } void CBuffer::DebugDumpAscii(std::ofstream &debugout) const { - // dump an ascii line - for ( int i = 0; i < size(); i++ ) - { - char c = data()[i]; - if ( isascii(c) ) - { - debugout << c; - } - else - { - debugout << '.'; - } - if ( i == size()-1 ) - { - debugout << std::endl; - } - //else - //{ - // debugout << ','; - //} - } + // dump an ascii line + for ( unsigned int i = 0; i < m_data.size(); i++ ) { + char c = m_data.data()[i]; + if ( isascii(c) ) { + debugout << c; + } else { + debugout << '.'; + } + if ( i == m_data.size()-1 ) { + debugout << std::endl; + } + } } - - diff --git a/src/cbuffer.h b/src/cbuffer.h index ba4b967..2ceb109 100644 --- a/src/cbuffer.h +++ b/src/cbuffer.h @@ -4,6 +4,7 @@ // // Created by Jean-Luc Deltombe (LX3JL) on 02/11/2015. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// Copyright © 2020 Thomas A. Early, N7TAE // // ---------------------------------------------------------------------------- // This file is part of xlxd. @@ -19,50 +20,64 @@ // 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 . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- #ifndef cbuffer_h #define cbuffer_h +#include +#include +#include "main.h" + //////////////////////////////////////////////////////////////////////////////////////// -class CBuffer : public std::vector +class CBuffer { public: - // constructor - CBuffer() {}; - CBuffer(uint8 *, int); - - // destructor - virtual ~CBuffer() {}; - - // set - void Set(uint8 *, int); - void Set(const char *); - void Append(uint8 *, int); - void Append(uint8, int); - void Append(uint8); - void Append(uint16); - void Append(uint32); - void Append(const char *); - void ReplaceAt(int, uint8); - void ReplaceAt(int, uint16); - void ReplaceAt(int, uint32); - void ReplaceAt(int, const uint8 *, int); - - // operation - int Compare(uint8 *, int) const; - int Compare(uint8 *, int, int) const; - - // operator - bool operator ==(const CBuffer &) const; - bool operator ==(const char *) const; - operator const char *() const; - - // debug - void DebugDump(std::ofstream &) const; - void DebugDumpAscii(std::ofstream &) const; + CBuffer() {} + CBuffer(uint8_t *, int); + + // destructor + virtual ~CBuffer() {}; + + // set + void Set(uint8_t *, int); + void Set(const char *); + void Append(const uint8_t *, int); + void Append(uint8_t, int); + void Append(uint8_t); + void Append(uint16_t); + void Append(uint32_t); + void Append(const char *); + void ReplaceAt(int, uint8_t); + void ReplaceAt(int, uint16_t); + void ReplaceAt(int, uint32_t); + void ReplaceAt(int, const uint8_t *, int); + + // operation + int Compare(uint8_t *, int) const; + int Compare(uint8_t *, int, int) const; + + // operator + bool operator ==(const CBuffer &) const; + bool operator ==(const char *) const; + operator const char *() const; + + // debug + void DebugDump(std::ofstream &) const; + void DebugDumpAscii(std::ofstream &) const; + + // pass through + void clear() { m_data.clear(); } + std::vector::size_type size() const { return m_data.size(); } + uint8_t *data() { return m_data.data(); } + const uint8_t *data() const { return m_data.data(); } + void resize(std::vector::size_type len, uint8_t val = 0) { m_data.resize(len, val); } + uint8_t at(std::vector::size_type i) const { return m_data.at(i); } + +protected: + std::vector m_data; }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/makefile b/src/makefile deleted file mode 100644 index de1e0db..0000000 --- a/src/makefile +++ /dev/null @@ -1,30 +0,0 @@ -CC=g++ -CFLAGS=-c -std=c++11 -pthread -LDFLAGS=-std=c++11 -pthread -SOURCES=$(wildcard *.cpp) -OBJECTS=$(SOURCES:.cpp=.o) -EXECUTABLE=xlxd - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) -o $@ - -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ - -clean: - $(RM) $(EXECUTABLE) *.o - -install: - mkdir -p /xlxd - cp -f $(EXECUTABLE) /xlxd/ - [ -f /xlxd/xlxd.blacklist ] && \ - cp ../config/xlxd.blacklist /xlxd/xlxd.blacklist.sample || \ - cp ../config/xlxd.blacklist /xlxd/xlxd.blacklist - [ -f /xlxd/xlxd.whitelist ] && \ - cp ../config/xlxd.whitelist /xlxd/xlxd.whitelist.sample || \ - cp ../config/xlxd.whitelist /xlxd/xlxd.whitelist - [ -f /xlxd/xlxd.interlink ] && \ - cp ../config/xlxd.interlink /xlxd/xlxd.interlink.sample || \ - cp ../config/xlxd.interlink /xlxd/xlxd.interlink