├── .github └── workflows │ └── cmake-multi-platform.yml ├── API ├── Dockerfile ├── LICENSE ├── Makefile ├── Makefile.inc ├── README ├── README.md ├── examples ├── nfourl.sh ├── rescan.py └── skiplist ├── misc ├── create_redistributable_tgz.sh └── start_with_gdb.sh └── src ├── Makefile ├── address.cpp ├── address.h ├── buildinfo.cpp ├── buildinfo.h ├── commandowner.h ├── connstatetracker.cpp ├── connstatetracker.h ├── core ├── Makefile ├── asynctask.cpp ├── asynctask.h ├── asyncworker.cpp ├── asyncworker.h ├── blockingqueue.h ├── datablock.cpp ├── datablock.h ├── datablockpool.cpp ├── datablockpool.h ├── event.cpp ├── event.h ├── eventreceiver.cpp ├── eventreceiver.h ├── iomanager.cpp ├── iomanager.h ├── logger.cpp ├── logger.h ├── polling.h ├── pollingepoll.h ├── pollingkqueue.h ├── pollingpoll.h ├── prio.h ├── semaphore.h ├── signal.cpp ├── signal.h ├── signalevents.cpp ├── signalevents.h ├── socketinfo.h ├── sslmanager.cpp ├── sslmanager.h ├── threading.cpp ├── threading.h ├── tickpoke.cpp ├── tickpoke.h ├── tickpoketarget.cpp ├── tickpoketarget.h ├── types.cpp ├── types.h ├── util.cpp ├── util.h ├── workmanager.cpp └── workmanager.h ├── crypto.cpp ├── crypto.h ├── datafilehandler.cpp ├── datafilehandler.h ├── datafilehandlermethod.h ├── delayedcommand.cpp ├── delayedcommand.h ├── downloadfiledata.cpp ├── downloadfiledata.h ├── encoding.cpp ├── encoding.h ├── engine.cpp ├── engine.h ├── eventlog.cpp ├── eventlog.h ├── eventreceiverproxyintermediate.cpp ├── eventreceiverproxyintermediate.h ├── ext ├── Makefile ├── json.hpp ├── picohttpparser.c └── picohttpparser.h ├── externalscripts.cpp ├── externalscripts.h ├── externalscriptsmanager.cpp ├── externalscriptsmanager.h ├── file.cpp ├── file.h ├── filelist.cpp ├── filelist.h ├── filelistdata.cpp ├── filelistdata.h ├── filesystem.cpp ├── filesystem.h ├── ftpconn.cpp ├── ftpconn.h ├── ftpconnect.cpp ├── ftpconnect.h ├── ftpconnectowner.h ├── globalcontext.cpp ├── globalcontext.h ├── hourlyalltracking.cpp ├── hourlyalltracking.h ├── http ├── Makefile ├── message.cpp ├── message.h ├── parser.cpp ├── parser.h ├── request.cpp ├── request.h ├── requestparser.cpp ├── requestparser.h ├── response.cpp ├── response.h ├── responseparser.cpp └── responseparser.h ├── httpconn.cpp ├── httpconn.h ├── httpserver.cpp ├── httpserver.h ├── joblist.h ├── loadmonitor.cpp ├── loadmonitor.h ├── loadmonitorcallback.h ├── localdownload.cpp ├── localdownload.h ├── localfile.cpp ├── localfile.h ├── localfilelist.cpp ├── localfilelist.h ├── localpathinfo.cpp ├── localpathinfo.h ├── localstorage.cpp ├── localstorage.h ├── localstoragerequestdata.cpp ├── localstoragerequestdata.h ├── localtransfer.cpp ├── localtransfer.h ├── localupload.cpp ├── localupload.h ├── logmanager.cpp ├── logmanager.h ├── main.cpp ├── path.cpp ├── path.h ├── pendingtransfer.cpp ├── pendingtransfer.h ├── potentialelement.cpp ├── potentialelement.h ├── potentiallistelement.cpp ├── potentiallistelement.h ├── potentialtracker.cpp ├── potentialtracker.h ├── preparedrace.cpp ├── preparedrace.h ├── proxy.cpp ├── proxy.h ├── proxymanager.cpp ├── proxymanager.h ├── proxysession.cpp ├── proxysession.h ├── race.cpp ├── race.h ├── racestatus.h ├── rawbuffer.cpp ├── rawbuffer.h ├── rawbuffercallback.h ├── recursivecommandlogic.cpp ├── recursivecommandlogic.h ├── refreshgovernor.cpp ├── refreshgovernor.h ├── remotecommandhandler.cpp ├── remotecommandhandler.h ├── requestcallback.h ├── restapi.cpp ├── restapi.h ├── restapicallback.h ├── scoreboard.cpp ├── scoreboard.h ├── scoreboardelement.cpp ├── scoreboardelement.h ├── section.cpp ├── section.h ├── sectionmanager.cpp ├── sectionmanager.h ├── sectionutil.cpp ├── sectionutil.h ├── settingsloadersaver.cpp ├── settingsloadersaver.h ├── site.cpp ├── site.h ├── sitelogic.cpp ├── sitelogic.h ├── sitelogicmanager.cpp ├── sitelogicmanager.h ├── sitelogicrequest.cpp ├── sitelogicrequest.h ├── sitelogicrequestready.cpp ├── sitelogicrequestready.h ├── sitemanager.cpp ├── sitemanager.h ├── siterace.cpp ├── siterace.h ├── sitetransferjob.cpp ├── sitetransferjob.h ├── sizelocationtrack.cpp ├── sizelocationtrack.h ├── skiplist.cpp ├── skiplist.h ├── skiplistitem.cpp ├── skiplistitem.h ├── statistics.cpp ├── statistics.h ├── subprocessmanager.cpp ├── subprocessmanager.h ├── timereference.cpp ├── timereference.h ├── tools ├── datafilecat.cpp ├── datafiletoolfuncs.h └── datafilewrite.cpp ├── transferjob.cpp ├── transferjob.h ├── transfermanager.cpp ├── transfermanager.h ├── transfermonitor.cpp ├── transfermonitor.h ├── transferpairing.cpp ├── transferpairing.h ├── transferpairingitem.cpp ├── transferpairingitem.h ├── transferprotocol.cpp ├── transferprotocol.h ├── transferstatus.cpp ├── transferstatus.h ├── transferstatuscallback.h ├── ui ├── Makefile ├── braillegraph.cpp ├── braillegraph.h ├── chardraw.cpp ├── chardraw.h ├── commandhistory.cpp ├── commandhistory.h ├── externalfileviewing.cpp ├── externalfileviewing.h ├── fmtstring.cpp ├── fmtstring.h ├── focusablearea.cpp ├── focusablearea.h ├── infowindow.cpp ├── infowindow.h ├── keybinds.cpp ├── keybinds.h ├── legendprinter.cpp ├── legendprinter.h ├── legendprinterkeybinds.cpp ├── legendprinterkeybinds.h ├── legendprinterspreadjob.cpp ├── legendprinterspreadjob.h ├── legendprintertransferjob.cpp ├── legendprintertransferjob.h ├── legendwindow.cpp ├── legendwindow.h ├── menuselectadjustableline.cpp ├── menuselectadjustableline.h ├── menuselectoption.cpp ├── menuselectoption.h ├── menuselectoptioncheckbox.cpp ├── menuselectoptioncheckbox.h ├── menuselectoptioncontainer.cpp ├── menuselectoptioncontainer.h ├── menuselectoptionelement.cpp ├── menuselectoptionelement.h ├── menuselectoptionnumarrow.cpp ├── menuselectoptionnumarrow.h ├── menuselectoptiontextarrow.cpp ├── menuselectoptiontextarrow.h ├── menuselectoptiontextbutton.cpp ├── menuselectoptiontextbutton.h ├── menuselectoptiontextfield.cpp ├── menuselectoptiontextfield.h ├── misc.cpp ├── misc.h ├── ncurseswrap.h ├── numinputarrow.cpp ├── numinputarrow.h ├── renderer.cpp ├── renderer.h ├── resizableelement.h ├── screens │ ├── Makefile │ ├── allracesscreen.cpp │ ├── allracesscreen.h │ ├── alltransferjobsscreen.cpp │ ├── alltransferjobsscreen.h │ ├── browsescreen.cpp │ ├── browsescreen.h │ ├── browsescreenaction.h │ ├── browsescreenlocal.cpp │ ├── browsescreenlocal.h │ ├── browsescreenselector.cpp │ ├── browsescreenselector.h │ ├── browsescreensite.cpp │ ├── browsescreensite.h │ ├── browsescreensub.cpp │ ├── browsescreensub.h │ ├── changekeyscreen.cpp │ ├── changekeyscreen.h │ ├── confirmationscreen.cpp │ ├── confirmationscreen.h │ ├── disableencryptionscreen.cpp │ ├── disableencryptionscreen.h │ ├── editproxyscreen.cpp │ ├── editproxyscreen.h │ ├── editsectionscreen.cpp │ ├── editsectionscreen.h │ ├── editsitescreen.cpp │ ├── editsitescreen.h │ ├── editsitesectionscreen.cpp │ ├── editsitesectionscreen.h │ ├── eventlogscreen.cpp │ ├── eventlogscreen.h │ ├── externalscriptsscreen.cpp │ ├── externalscriptsscreen.h │ ├── fileinfoscreen.cpp │ ├── fileinfoscreen.h │ ├── fileviewersettingsscreen.cpp │ ├── fileviewersettingsscreen.h │ ├── globaloptionsscreen.cpp │ ├── globaloptionsscreen.h │ ├── infoscreen.cpp │ ├── infoscreen.h │ ├── keybindsscreen.cpp │ ├── keybindsscreen.h │ ├── loginscreen.cpp │ ├── loginscreen.h │ ├── mainscreen.cpp │ ├── mainscreen.h │ ├── makedirscreen.cpp │ ├── makedirscreen.h │ ├── metricsscreen.cpp │ ├── metricsscreen.h │ ├── movescreen.cpp │ ├── movescreen.h │ ├── newkeyscreen.cpp │ ├── newkeyscreen.h │ ├── newracescreen.cpp │ ├── newracescreen.h │ ├── nukescreen.cpp │ ├── nukescreen.h │ ├── proxyoptionsscreen.cpp │ ├── proxyoptionsscreen.h │ ├── racestatusscreen.cpp │ ├── racestatusscreen.h │ ├── rawcommandscreen.cpp │ ├── rawcommandscreen.h │ ├── rawdatascreen.cpp │ ├── rawdatascreen.h │ ├── scoreboardscreen.cpp │ ├── scoreboardscreen.h │ ├── sectionsscreen.cpp │ ├── sectionsscreen.h │ ├── selectjobsscreen.cpp │ ├── selectjobsscreen.h │ ├── selectsitesscreen.cpp │ ├── selectsitesscreen.h │ ├── sitesectionsscreen.cpp │ ├── sitesectionsscreen.h │ ├── siteslotsscreen.cpp │ ├── siteslotsscreen.h │ ├── sitestatusscreen.cpp │ ├── sitestatusscreen.h │ ├── skiplistscreen.cpp │ ├── skiplistscreen.h │ ├── snakescreen.cpp │ ├── snakescreen.h │ ├── transferjobstatusscreen.cpp │ ├── transferjobstatusscreen.h │ ├── transferpairingscreen.cpp │ ├── transferpairingscreen.h │ ├── transfersfilterscreen.cpp │ ├── transfersfilterscreen.h │ ├── transfersscreen.cpp │ ├── transfersscreen.h │ ├── transferstatusscreen.cpp │ ├── transferstatusscreen.h │ ├── viewfilescreen.cpp │ └── viewfilescreen.h ├── termint.cpp ├── termint.h ├── textarrow.cpp ├── textarrow.h ├── textinputfield.cpp ├── textinputfield.h ├── textwrap.cpp ├── textwrap.h ├── ui.cpp ├── ui.h ├── uicommand.cpp ├── uicommand.h ├── uifile.cpp ├── uifile.h ├── uifilelist.cpp ├── uifilelist.h ├── uiwindow.cpp ├── uiwindow.h ├── virtualview.cpp ├── virtualview.h ├── virtualviewelement.cpp └── virtualviewelement.h ├── uibase.cpp ├── uibase.h ├── util.cpp └── util.h /.github/workflows/cmake-multi-platform.yml: -------------------------------------------------------------------------------- 1 | name: build on "ubuntu-latest" 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | CBFTP_DEPENDENCIES_LINUX: make g++ libssl-dev libncursesw5-dev 11 | CBFTP_DEPENDENCIES_BSD: gmake gcc11-devel openssl ncurses 12 | 13 | jobs: 14 | build: 15 | runs-on: ${{ matrix.os }} 16 | 17 | strategy: 18 | # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. 19 | fail-fast: false 20 | 21 | matrix: 22 | os: [ubuntu-latest] 23 | config: 24 | - { name: "gcc", cc: "gcc", cxx: "g++", buildargs: "" } 25 | steps: 26 | - uses: actions/checkout@v3 27 | 28 | - name: Install dependencies 29 | run: | 30 | sudo apt-get update -qq 31 | sudo apt-get --yes --no-install-recommends install ${{ env.CBFTP_DEPENDENCIES_LINUX }} 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | ENV PATH="/app/bin:${PATH}" 3 | EXPOSE 55477/tcp 4 | EXPOSE 55477/udp 5 | RUN apk add g++ make openssl-dev ncurses-dev 6 | COPY . /app 7 | RUN make -C /app -j$(nproc) 8 | CMD ["cbftp"] 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2011-present The cbftp development team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /misc/create_redistributable_tgz.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" 3 | cd $SCRIPTPATH/.. 4 | DIFF=`svn diff|wc -l` 5 | #if [ $DIFF -gt 0 ]; then 6 | # echo "Error: this is not a clean svn copy." 7 | # exit 1 8 | #fi 9 | VERSION=`svn info|grep Revision|awk '{ print $2 }'` 10 | echo $VERSION > .version 11 | VERSION="r"$VERSION 12 | FILES=`find . -name "*.cpp" -o -name "*.h" -o -name "*.c" -o -name "*.hpp" -o -name Makefile -o -name Makefile.inc -o -name .version -o -name start_with_gdb.sh -o -name README -o -name API -o -name LICENSE -o -wholename "./examples/*" -o -name Dockerfile|xargs` 13 | tar czf cbftp-$VERSION.tar.gz $FILES --transform "s,^\.,cbftp-$VERSION," 14 | rm .version 15 | -------------------------------------------------------------------------------- /misc/start_with_gdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SCRIPTPATH=`pwd`"/"`dirname $0` 3 | gdb $SCRIPTPATH/cbftp --eval-command="set confirm off" --eval-command="handle SIGINT nostop print pass" --eval-command="handle SIGUSR1 nostop noprint pass" --eval-command="handle SIGPIPE nostop print pass" --eval-command="set confirm on" --eval-command="set print thread-events off" --eval-command="run" 4 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | SRC = $(wildcard *.cpp) 4 | OBJS = $(wildcard $(SRC:%.cpp=%.o) $(SRC:%.cpp=%.d)) 5 | 6 | all: $(SRC:%.cpp=%.o) 7 | @# 8 | 9 | ifeq ($(HAS_SVN), 0) 10 | ifneq ($(SVN_ROOT_DIR),) 11 | SVN_DIR := $(SVN_ROOT_DIR)/.svn/tmp 12 | else 13 | SVN_DIR := $(wildcard $(ROOT_DIR)/.svn/tmp) 14 | endif 15 | endif 16 | 17 | buildinfo.o: buildinfo.cpp ../Makefile.inc $(SVN_DIR) 18 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< -DBUILDTIME=$(DATE) -DVERSION=$(VERSION) -DBOXTAG=$(BOXTAG) 19 | 20 | datafilehandler.o: datafilehandler.cpp ../Makefile.inc $(SVN_DIR) 21 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< -DDATA_FILE=$(DATA_FILE) 22 | 23 | clean: 24 | @if test $(firstword $(OBJS)); then rm -rf $(OBJS); echo rm -rf $(OBJS); fi 25 | 26 | %.o: %.cpp ../Makefile.inc 27 | 28 | -include $(SRC:%.cpp=%.d) 29 | -------------------------------------------------------------------------------- /src/address.cpp: -------------------------------------------------------------------------------- 1 | #include "address.h" 2 | 3 | Address::Address() : addrfam(Core::AddressFamily::IPV4_IPV6), brackets(false), port(21) { 4 | 5 | } 6 | 7 | Address::Address(const std::string& host, int port, Core::AddressFamily addrfam, bool brackets) : addrfam(addrfam), brackets(brackets), host(host), port(port) { 8 | 9 | } 10 | 11 | std::string Address::toString(bool includeaddrfam) const { 12 | std::string addrstr; 13 | if (includeaddrfam) { 14 | if (addrfam == Core::AddressFamily::IPV4) { 15 | addrstr += "(4)"; 16 | } 17 | else if (addrfam == Core::AddressFamily::IPV6) { 18 | addrstr += "(6)"; 19 | } 20 | } 21 | if (brackets) { 22 | addrstr += "["; 23 | } 24 | addrstr += host; 25 | if (brackets) { 26 | addrstr += "]"; 27 | } 28 | if (port != 21) { 29 | addrstr += ":" + std::to_string(port); 30 | } 31 | return addrstr; 32 | } 33 | 34 | bool Address::operator==(const Address& other) const { 35 | return addrfam == other.addrfam && brackets == other.brackets && host == other.host && port == other.port; 36 | } 37 | -------------------------------------------------------------------------------- /src/address.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/types.h" 6 | 7 | struct Address { 8 | Address(); 9 | Address(const std::string& host, int port, Core::AddressFamily addrfam = Core::AddressFamily::IPV4_IPV6, bool brackets = false); 10 | std::string toString(bool includeaddrfam = true) const; 11 | bool operator==(const Address& other) const; 12 | Core::AddressFamily addrfam; 13 | bool brackets; 14 | std::string host; 15 | unsigned short port; 16 | }; 17 | -------------------------------------------------------------------------------- /src/buildinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "buildinfo.h" 2 | 3 | #ifndef BOXTAG 4 | #define BOXTAG "" 5 | #endif 6 | 7 | #ifndef VERSION 8 | #define VERSION "unknown" 9 | #endif 10 | 11 | #ifndef BUILDTIME 12 | #define BUILDTIME "unknown" 13 | #endif 14 | 15 | std::string BuildInfo::version() { 16 | return VERSION; 17 | } 18 | 19 | std::string BuildInfo::compileTime() { 20 | return BUILDTIME; 21 | } 22 | 23 | std::string BuildInfo::tag() { 24 | return BOXTAG; 25 | } 26 | -------------------------------------------------------------------------------- /src/buildinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class BuildInfo { 6 | public: 7 | static std::string version(); 8 | static std::string compileTime(); 9 | static std::string tag(); 10 | }; 11 | -------------------------------------------------------------------------------- /src/commandowner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/eventreceiver.h" 6 | #include "statistics.h" 7 | 8 | #define COMMANDOWNER_SITERACE 543 9 | #define COMMANDOWNER_TRANSFERJOB 544 10 | 11 | class FileList; 12 | class SiteLogic; 13 | class Path; 14 | 15 | class CommandOwner : public Core::EventReceiver { 16 | public: 17 | virtual ~CommandOwner() { 18 | } 19 | virtual int classType() const = 0; 20 | virtual std::string getName() const = 0; 21 | virtual unsigned int getId() const = 0; 22 | virtual void fileListUpdated(SiteLogic* sl, const std::shared_ptr& fl) = 0; 23 | virtual std::shared_ptr getFileListForFullPath(SiteLogic* sl, const Path& path) const = 0; 24 | virtual void addTransferStatsFile(StatsDirection, const std::string &, unsigned long long int, unsigned int) { } 25 | }; 26 | -------------------------------------------------------------------------------- /src/core/Makefile: -------------------------------------------------------------------------------- 1 | -include ../../Makefile.inc 2 | 3 | SRC = $(wildcard *.cpp) 4 | LIB = libcore.a 5 | CLEANFILES = $(wildcard $(SRC:%.cpp=%.o) $(SRC:%.cpp=%.d) $(LIB)) 6 | 7 | all: $(SRC:%.cpp=%.o) 8 | @+$(MAKE) --no-print-directory $(LIB) 9 | 10 | quiet: 11 | @# 12 | 13 | $(LIB): $(SRC:%.cpp=%.o) | quiet 14 | ar rc $@ $^ && ranlib $@ 15 | 16 | clean: 17 | @if test $(firstword $(CLEANFILES)); then rm -rf $(CLEANFILES); echo rm -rf $(CLEANFILES); fi 18 | 19 | ifneq ($(wildcard ../../Makefile.inc),) 20 | %.o: %.cpp ../../Makefile.inc 21 | 22 | sslmanager.o: sslmanager.cpp ../../Makefile.inc 23 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o sslmanager.o sslmanager.cpp -DCORP=$(BOXTAG) 24 | endif 25 | 26 | -include $(SRC:%.cpp=%.d) 27 | -------------------------------------------------------------------------------- /src/core/asynctask.cpp: -------------------------------------------------------------------------------- 1 | #include "asynctask.h" 2 | 3 | namespace Core { 4 | 5 | AsyncTask::AsyncTask(EventReceiver* er, int type, void (*taskfunction)(EventReceiver*, int), int data) : 6 | receiver(er), type(type), taskfunction(taskfunction), taskfunctionp(nullptr), data(data), datap(nullptr) 7 | { 8 | } 9 | 10 | AsyncTask::AsyncTask(EventReceiver* er, int type, void (*taskfunction)(EventReceiver*, void*), void* data) : 11 | receiver(er), type(type), taskfunction(nullptr), taskfunctionp(taskfunction), data(0), datap(data) 12 | { 13 | } 14 | 15 | bool AsyncTask::execute() { 16 | if (taskfunctionp) { 17 | taskfunctionp(receiver, datap); 18 | } 19 | else if (taskfunction) { 20 | taskfunction(receiver, data); 21 | } 22 | else { 23 | return false; 24 | } 25 | return true; 26 | } 27 | 28 | EventReceiver* AsyncTask::getReceiver() const { 29 | return receiver; 30 | } 31 | 32 | bool AsyncTask::dataIsPointer() const { 33 | return taskfunctionp; 34 | } 35 | 36 | int AsyncTask::getType() const { 37 | return type; 38 | } 39 | 40 | void* AsyncTask::getData() const { 41 | return datap; 42 | } 43 | 44 | int AsyncTask::getNumData() const { 45 | return data; 46 | } 47 | 48 | } // namespace Core 49 | -------------------------------------------------------------------------------- /src/core/asynctask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Core { 4 | 5 | class EventReceiver; 6 | 7 | class AsyncTask { 8 | public: 9 | AsyncTask(EventReceiver* er, int type, void (*taskfunction)(EventReceiver*, int), int data); 10 | AsyncTask(EventReceiver* er, int type, void (*taskfunctionp)(EventReceiver*, void*), void* data); 11 | bool execute(); 12 | EventReceiver* getReceiver() const; 13 | int getType() const; 14 | bool dataIsPointer() const; 15 | void* getData() const; 16 | int getNumData() const; 17 | private: 18 | EventReceiver* receiver; 19 | int type; 20 | void (*taskfunction)(EventReceiver*, int); 21 | void (*taskfunctionp)(EventReceiver*, void*); 22 | int data; 23 | void* datap; 24 | }; 25 | 26 | } // namespace Core 27 | -------------------------------------------------------------------------------- /src/core/asyncworker.cpp: -------------------------------------------------------------------------------- 1 | #include "asyncworker.h" 2 | 3 | #include "workmanager.h" 4 | 5 | namespace Core { 6 | 7 | AsyncWorker::AsyncWorker(WorkManager& wm, BlockingQueue& queue) : 8 | queue(queue), wm(wm) 9 | { 10 | } 11 | 12 | void AsyncWorker::init(const std::string& prefix, int id) { 13 | thread.start((prefix + "-aswk-" + std::to_string(id)).c_str(), this); 14 | } 15 | 16 | void AsyncWorker::run() { 17 | while (true) { 18 | AsyncTask task = queue.pop(); 19 | if (!task.execute()) { 20 | return; 21 | } 22 | wm.dispatchAsyncTaskComplete(task); 23 | } 24 | } 25 | 26 | void AsyncWorker::join() { 27 | thread.join(); 28 | } 29 | 30 | } // namespace Core 31 | -------------------------------------------------------------------------------- /src/core/asyncworker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "threading.h" 6 | #include "blockingqueue.h" 7 | #include "asynctask.h" 8 | 9 | namespace Core { 10 | 11 | class WorkManager; 12 | 13 | class AsyncWorker { 14 | public: 15 | AsyncWorker(WorkManager& wm, BlockingQueue& queue); 16 | void init(const std::string& prefix, int id); 17 | void run(); 18 | void join(); 19 | private: 20 | Thread thread; 21 | BlockingQueue& queue; 22 | WorkManager& wm; 23 | }; 24 | 25 | } // namespace Core 26 | -------------------------------------------------------------------------------- /src/core/blockingqueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "semaphore.h" 7 | 8 | namespace Core { 9 | 10 | template class BlockingQueue { 11 | public: 12 | BlockingQueue() : queuesize(0) {} 13 | void push(T t) { 14 | std::lock_guard lock(queuelock); 15 | queue.push_back(t); 16 | ++queuesize; 17 | content.post(); 18 | } 19 | T pop() { 20 | content.wait(); 21 | std::lock_guard lock(queuelock); 22 | T ret = queue.front(); 23 | queue.pop_front(); 24 | --queuesize; 25 | return ret; 26 | } 27 | unsigned int size() const { 28 | std::lock_guard lock(queuelock); 29 | return queuesize; 30 | } 31 | void lock() { 32 | queuelock.lock(); 33 | } 34 | void unlock() { 35 | queuelock.unlock(); 36 | } 37 | typename std::list::iterator begin() { 38 | return queue.begin(); 39 | } 40 | typename std::list::iterator end() { 41 | return queue.end(); 42 | } 43 | void erase(typename std::list::iterator it) { 44 | queue.erase(it); 45 | --queuesize; 46 | content.wait(); 47 | } 48 | private: 49 | std::list queue; 50 | unsigned int queuesize; 51 | mutable std::mutex queuelock; 52 | Semaphore content; 53 | }; 54 | 55 | } // namespace Core 56 | -------------------------------------------------------------------------------- /src/core/datablock.cpp: -------------------------------------------------------------------------------- 1 | #include "datablock.h" 2 | 3 | namespace Core { 4 | 5 | DataBlock::DataBlock(char* datap, int datalen) : 6 | datap(datap), 7 | datalen(datalen), 8 | offset(0) { 9 | } 10 | 11 | char* DataBlock::rawData() const { 12 | return datap; 13 | } 14 | 15 | char* DataBlock::data() const { 16 | return datap + offset; 17 | } 18 | 19 | int DataBlock::rawDataLength() const { 20 | return datalen; 21 | } 22 | 23 | int DataBlock::dataLength() const { 24 | return datalen - offset; 25 | } 26 | 27 | void DataBlock::consume(int consumed) { 28 | offset += consumed; 29 | } 30 | 31 | } // namespace Core 32 | -------------------------------------------------------------------------------- /src/core/datablock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Core { 4 | 5 | class DataBlock { 6 | public: 7 | DataBlock(char* datap, int datalen); 8 | char* rawData() const; 9 | int rawDataLength() const; 10 | char* data() const; 11 | int dataLength() const; 12 | void consume(int consumed); 13 | private: 14 | char* datap; 15 | int datalen; 16 | int offset; 17 | }; 18 | 19 | } // namespace Core 20 | -------------------------------------------------------------------------------- /src/core/datablockpool.cpp: -------------------------------------------------------------------------------- 1 | #include "datablockpool.h" 2 | 3 | #include 4 | 5 | namespace Core { 6 | 7 | #define BLOCKSIZE 16384 8 | 9 | DataBlockPool::DataBlockPool() : totalblocks(0) { 10 | std::lock_guard lock(blocklock); 11 | allocateNewBlocks(); 12 | } 13 | 14 | DataBlockPool::~DataBlockPool() 15 | { 16 | std::lock_guard lock(blocklock); 17 | for (char* block : blocks) { 18 | free(block); 19 | } 20 | } 21 | 22 | char* DataBlockPool::getBlock() { 23 | char* block; 24 | std::lock_guard lock(blocklock); 25 | if (availableblocks.empty()) { 26 | allocateNewBlocks(); 27 | } 28 | block = availableblocks.back(); 29 | availableblocks.pop_back(); 30 | return block; 31 | } 32 | 33 | const int DataBlockPool::blockSize() const { 34 | return BLOCKSIZE; 35 | } 36 | 37 | void DataBlockPool::returnBlock(char* block) { 38 | std::lock_guard lock(blocklock); 39 | availableblocks.push_back(block); 40 | } 41 | 42 | void DataBlockPool::allocateNewBlocks() { 43 | for (int i = 0; i < 10; i++) { 44 | char* block = (char*) malloc(BLOCKSIZE); 45 | blocks.push_back(block); 46 | availableblocks.push_back(block); 47 | totalblocks++; 48 | } 49 | } 50 | 51 | } // namespace Core 52 | -------------------------------------------------------------------------------- /src/core/datablockpool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | class DataBlockPool { 9 | public: 10 | DataBlockPool(); 11 | ~DataBlockPool(); 12 | char* getBlock(); 13 | const int blockSize() const; 14 | void returnBlock(char* block); 15 | private: 16 | void allocateNewBlocks(); 17 | std::list blocks; 18 | std::list availableblocks; 19 | int totalblocks; 20 | std::mutex blocklock; 21 | }; 22 | 23 | } // namespace Core 24 | -------------------------------------------------------------------------------- /src/core/event.cpp: -------------------------------------------------------------------------------- 1 | #include "event.h" 2 | 3 | #include "eventreceiver.h" 4 | 5 | namespace Core { 6 | 7 | Event::Event() { 8 | } 9 | 10 | Event::Event(EventReceiver* er, EventType type, int numdata, void* data, int datalen) : 11 | receiver(er), 12 | type(type), 13 | data(data), 14 | datalen(datalen), 15 | numdata(numdata), 16 | numdata2(0) 17 | { 18 | } 19 | 20 | Event::Event(EventReceiver* er, EventType type, int numdata, int numdata2) : 21 | receiver(er), 22 | type(type), 23 | data(nullptr), 24 | datalen(0), 25 | numdata(numdata), 26 | numdata2(numdata2) 27 | { 28 | } 29 | 30 | Event::Event(EventReceiver* er, EventType type, int numdata, const std::string& strdata, int numdata2) : 31 | receiver(er), 32 | type(type), 33 | data(nullptr), 34 | datalen(0), 35 | numdata(numdata), 36 | numdata2(numdata2), 37 | strdata(strdata) 38 | { 39 | } 40 | 41 | Event::Event(const std::shared_ptr& er, EventType type) : 42 | receiver(nullptr), 43 | preceiver(er), 44 | type(type), 45 | data(nullptr), 46 | datalen(0), 47 | numdata(0), 48 | numdata2(0) 49 | { 50 | } 51 | 52 | Event::~Event() { 53 | 54 | } 55 | 56 | EventReceiver* Event::getReceiver() const { 57 | return receiver; 58 | } 59 | 60 | EventType Event::getType() const { 61 | return type; 62 | } 63 | 64 | void* Event::getData() const { 65 | return data; 66 | } 67 | 68 | int Event::getDataLen() const { 69 | return datalen; 70 | } 71 | 72 | int Event::getNumericalData() const { 73 | return numdata; 74 | } 75 | 76 | int Event::getNumericalData2() const { 77 | return numdata2; 78 | } 79 | 80 | std::string Event::getStrData() const { 81 | return strdata; 82 | } 83 | 84 | } // namespace Core 85 | -------------------------------------------------------------------------------- /src/core/event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | class EventReceiver; 9 | 10 | enum class EventType { 11 | DATA, 12 | DATABUF, 13 | TICK, 14 | CONNECTING, 15 | CONNECTED, 16 | DISCONNECTED, 17 | SSL_SUCCESS, 18 | NEW, 19 | FAIL, 20 | SEND_COMPLETE, 21 | DELETE, 22 | ASYNC_COMPLETE, 23 | ASYNC_COMPLETE_P, 24 | APPLICATION_MESSAGE, 25 | FLUSH 26 | }; 27 | 28 | class Event { 29 | public: 30 | Event(); 31 | Event(EventReceiver* er, EventType type, int numdata = 0, void* data = nullptr, int datalen = 0); 32 | Event(EventReceiver* er, EventType type, int numdata, int numdata2); 33 | Event(EventReceiver* er, EventType type, int numdata, const std::string& strdata, int numdata2 = 0); 34 | Event(const std::shared_ptr& er, EventType type); 35 | ~Event(); 36 | EventReceiver* getReceiver() const; 37 | EventType getType() const; 38 | void* getData() const; 39 | int getDataLen() const; 40 | int getNumericalData() const; 41 | int getNumericalData2() const; 42 | std::string getStrData() const; 43 | private: 44 | EventReceiver* receiver; 45 | std::shared_ptr preceiver; 46 | EventType type; 47 | void* data; 48 | int datalen; 49 | int numdata; 50 | int numdata2; 51 | std::string strdata; 52 | }; 53 | 54 | } // namespace Core 55 | -------------------------------------------------------------------------------- /src/core/eventreceiver.cpp: -------------------------------------------------------------------------------- 1 | #include "eventreceiver.h" 2 | 3 | #include "workmanager.h" 4 | 5 | namespace Core { 6 | 7 | EventReceiver::EventReceiver() : workmanager(nullptr) { 8 | 9 | } 10 | 11 | EventReceiver::~EventReceiver() { 12 | if (workmanager) { 13 | workmanager->flushEventReceiver(this); 14 | } 15 | } 16 | 17 | void EventReceiver::tick(int message) { 18 | 19 | } 20 | 21 | void EventReceiver::signal(int sig, int value) { 22 | 23 | } 24 | 25 | void EventReceiver::FDNew(int sockid, int newsockid) { 26 | 27 | } 28 | 29 | void EventReceiver::FDConnecting(int sockid, const std::string& addr) { 30 | 31 | } 32 | 33 | void EventReceiver::FDConnected(int sockid) { 34 | 35 | } 36 | 37 | void EventReceiver::FDData(int sockid) { 38 | 39 | } 40 | 41 | void EventReceiver::FDData(int sockid, char* data, unsigned int len) { 42 | 43 | } 44 | 45 | void EventReceiver::FDDisconnected(int sockid, DisconnectType reason, const std::string& details) { 46 | 47 | } 48 | 49 | void EventReceiver::FDFail(int sockid, const std::string& error) { 50 | 51 | } 52 | 53 | void EventReceiver::FDSSLSuccess(int sockid, const std::string& cipher) { 54 | 55 | } 56 | 57 | void EventReceiver::FDSendComplete(int sockid) { 58 | 59 | } 60 | 61 | void EventReceiver::asyncTaskComplete(int type, void* data) { 62 | 63 | } 64 | 65 | void EventReceiver::asyncTaskComplete(int type, int) { 66 | 67 | } 68 | 69 | void EventReceiver::receivedApplicationMessage(int messagetype, void* messagedata) { 70 | 71 | } 72 | 73 | void EventReceiver::workerReady() { 74 | 75 | } 76 | 77 | void EventReceiver::bindWorkManager(WorkManager* wm) { 78 | if (!workmanager) { 79 | workmanager = wm; 80 | } 81 | } 82 | 83 | } // namespace Core 84 | -------------------------------------------------------------------------------- /src/core/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "logger.h" 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | namespace { 9 | 10 | std::shared_ptr g_logger; 11 | 12 | class CoutLogger : public Logger { 13 | void log(const std::string& owner, const std::string& text, LogLevel level) override { 14 | std::cout << toString(level) << "<" << owner << "> " << text << std::endl; 15 | } 16 | }; 17 | 18 | } // namespace 19 | 20 | std::shared_ptr& getLogger() { 21 | if (!g_logger) { 22 | g_logger = std::make_shared(); 23 | g_logger->log("Logger", "No custom logger set, using stdout.", LogLevel::INFO); 24 | } 25 | return g_logger; 26 | } 27 | 28 | void setLogger(const std::shared_ptr& logger) { 29 | assert(!g_logger); 30 | g_logger = logger; 31 | } 32 | 33 | std::string toString(LogLevel level) { 34 | switch (level) { 35 | case LogLevel::ERROR: 36 | return "ERROR"; 37 | case LogLevel::WARNING: 38 | return "WARNING"; 39 | case LogLevel::INFO: 40 | return "INFO"; 41 | case LogLevel::DEBUG: 42 | return "DEBUG"; 43 | } 44 | return "UNKNOWN"; 45 | } 46 | 47 | } // namespace Core 48 | -------------------------------------------------------------------------------- /src/core/logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | enum class LogLevel { 9 | ERROR, 10 | WARNING, 11 | INFO, 12 | DEBUG 13 | }; 14 | 15 | class Logger { 16 | public: 17 | virtual ~Logger() { } 18 | virtual void log(const std::string& owner, const std::string& text, LogLevel level = LogLevel::INFO) = 0; 19 | }; 20 | 21 | std::shared_ptr& getLogger(); 22 | void setLogger(const std::shared_ptr& logger); 23 | std::string toString(LogLevel level); 24 | 25 | } // namespace Core 26 | -------------------------------------------------------------------------------- /src/core/prio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Core { 4 | 5 | enum class Prio { 6 | LOW = 0, 7 | NORMAL = 1, 8 | HIGH = 2 9 | }; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/core/semaphore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __APPLE__ 4 | 5 | #include 6 | #include 7 | 8 | namespace Core { 9 | 10 | class Semaphore { 11 | public: 12 | void post() { 13 | std::unique_lock lock(mutex); 14 | ++count; 15 | condition.notify_one(); 16 | } 17 | void wait() { 18 | std::unique_lock lock(mutex); 19 | while (!count) { // Handle spurious wake-ups. 20 | condition.wait(lock); 21 | } 22 | --count; 23 | } 24 | private: 25 | std::mutex mutex; 26 | std::condition_variable condition; 27 | unsigned long count = 0; // Initialized as locked. 28 | }; 29 | 30 | #else 31 | 32 | #include 33 | 34 | namespace Core { 35 | 36 | class Semaphore { 37 | public: 38 | Semaphore() : 39 | semaphore(dispatch_semaphore_create(0)) { 40 | } 41 | ~Semaphore() { 42 | dispatch_release(semaphore); 43 | } 44 | void post() { 45 | dispatch_semaphore_signal(semaphore); 46 | } 47 | void wait() { 48 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 49 | } 50 | private: 51 | dispatch_semaphore_t semaphore; 52 | }; 53 | 54 | #endif 55 | 56 | } // namespace Core 57 | -------------------------------------------------------------------------------- /src/core/signal.cpp: -------------------------------------------------------------------------------- 1 | #include "signal.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "threading.h" 8 | #include "workmanager.h" 9 | 10 | namespace Core { 11 | 12 | namespace { 13 | 14 | struct Sig { 15 | int sig; 16 | WorkManager* wm; 17 | EventReceiver* er; 18 | 19 | }; 20 | 21 | std::map registeredsignals; 22 | 23 | } // namespace 24 | 25 | void dispatchSignal(void* arg) { 26 | // this function runs in a new detached thread to avoid calling the 27 | // workmanager directly from the signal handler as mutexes may cause problems 28 | Sig* s = reinterpret_cast(arg); 29 | s->wm->dispatchSignal(s->er, s->sig, 0); 30 | } 31 | 32 | 33 | 34 | void signalHandlerDispatch(int sig) { 35 | std::map::const_iterator it = registeredsignals.find(sig); 36 | assert(it != registeredsignals.end()); 37 | Core::Threading::createDetachedThread(dispatchSignal, const_cast(static_cast(&it->second))); 38 | } 39 | 40 | void registerSignalDispatch(int sig, WorkManager* wm, EventReceiver* er) { 41 | assert(registeredsignals.find(sig) == registeredsignals.end()); 42 | Sig s; 43 | s.sig = sig; 44 | s.wm = wm; 45 | s.er = er; 46 | registeredsignals[sig] = s; 47 | registerSignalHandler(sig, signalHandlerDispatch); 48 | } 49 | 50 | void registerSignalHandler(int sig, void (*sighandler)(int)) { 51 | struct sigaction sa; 52 | sa.sa_handler = sighandler; 53 | sa.sa_flags = SA_RESTART; 54 | sigfillset(&sa.sa_mask); 55 | sigaction(sig, &sa, nullptr); 56 | } 57 | 58 | void blockAllRegisteredSignals() { 59 | sigset_t set; 60 | sigemptyset(&set); 61 | for (const std::pair& sig : registeredsignals) { 62 | sigaddset(&set, sig.first); 63 | } 64 | pthread_sigmask(SIG_BLOCK, &set, nullptr); 65 | } 66 | 67 | } // namespace Core 68 | -------------------------------------------------------------------------------- /src/core/signal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Core { 6 | 7 | class EventReceiver; 8 | class WorkManager; 9 | 10 | void registerSignalDispatch(int sig, WorkManager* wm, EventReceiver* er); 11 | void registerSignalHandler(int sig, void (*sighandler)(int)); 12 | void blockAllRegisteredSignals(); 13 | 14 | } // namespace Core 15 | -------------------------------------------------------------------------------- /src/core/signalevents.cpp: -------------------------------------------------------------------------------- 1 | #include "signalevents.h" 2 | 3 | #include 4 | 5 | namespace Core { 6 | 7 | SignalEvents::SignalEvents() : 8 | hasevent(0) 9 | { 10 | slots.resize(10); 11 | } 12 | 13 | bool SignalEvents::set(EventReceiver * er, int signal, int value) { 14 | std::lock_guard lock(signallock); 15 | for (size_t i = 0; i < slots.size(); ++i) { 16 | if (!slots[i].set) { 17 | slots[i].set = true; 18 | slots[i].er = er; 19 | slots[i].signal = signal; 20 | slots[i].value = value; 21 | hasevent++; 22 | return true; 23 | } 24 | else if (slots[i].er == er && slots[i].signal == signal && slots[i].value == value) { 25 | return false; 26 | } 27 | } 28 | assert(false); 29 | return false; 30 | } 31 | 32 | bool SignalEvents::hasEvent() const { 33 | std::lock_guard lock(signallock); 34 | return hasevent; 35 | } 36 | 37 | SignalData SignalEvents::getClearFirst() { 38 | std::lock_guard lock(signallock); 39 | SignalData ret; 40 | for (size_t i = 0; i < slots.size(); ++i) { 41 | if (slots[i].set) { 42 | ret = slots[i]; 43 | slots[i].set = false; 44 | hasevent--; 45 | return ret; 46 | } 47 | } 48 | assert(false); 49 | return ret; 50 | } 51 | 52 | void SignalEvents::flushEventReceiver(EventReceiver* er) { 53 | std::lock_guard lock(signallock); 54 | for (size_t i = 0; i < slots.size(); ++i) { 55 | if (slots[i].set && slots[i].er == er) { 56 | slots[i].set = false; 57 | hasevent--; 58 | } 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/core/signalevents.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | class EventReceiver; 9 | 10 | struct SignalData { 11 | SignalData() : set(false), signal(0), value(0), er(nullptr) { } 12 | bool set; 13 | int signal; 14 | int value; 15 | EventReceiver* er; 16 | }; 17 | 18 | class SignalEvents { 19 | public: 20 | SignalEvents(); 21 | bool set(EventReceiver* er, int signal, int value); 22 | bool hasEvent() const; 23 | SignalData getClearFirst(); 24 | void flushEventReceiver(EventReceiver* er); 25 | private: 26 | int hasevent; 27 | std::vector slots; 28 | mutable std::recursive_mutex signallock; 29 | /* the lock needs to be recursive since the set method is supposed to be 30 | * called from signal handlers, which may interrupt current execution at 31 | * any time */ 32 | }; 33 | 34 | } //namespace Core 35 | -------------------------------------------------------------------------------- /src/core/socketinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _POSIX_C_SOURCE 200809L 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "datablock.h" 11 | #include "prio.h" 12 | #include "types.h" 13 | 14 | struct addrinfo; 15 | 16 | namespace Core { 17 | 18 | enum class SocketType { 19 | UNUSED, 20 | EXTERNAL, 21 | TCP_PLAIN, 22 | TCP_SSL, 23 | UDP, 24 | TCP_SERVER, 25 | TCP_SERVER_EXTERNAL, 26 | TCP_PLAIN_LISTEN, 27 | TCP_SSL_NEG_CONNECT, 28 | TCP_SSL_NEG_REDO_CONNECT, 29 | TCP_SSL_NEG_ACCEPT, 30 | TCP_SSL_NEG_REDO_ACCEPT, 31 | TCP_CONNECTING, 32 | TCP_RESOLVING, 33 | STOP 34 | }; 35 | 36 | enum class Direction { 37 | IN, 38 | OUT 39 | }; 40 | 41 | class EventReceiver; 42 | 43 | class SocketInfo { 44 | public: 45 | SocketInfo() : type(SocketType::UNUSED), addrfam(AddressFamily::NONE), fd(-1), id(-1), parentid(-1), port(0), localport(0), gairet(0), 46 | gaires(nullptr), gaiasync(false), receiver(nullptr), ssl(nullptr), sslshutdown(true), 47 | prio(Prio::NORMAL), paused(false), direction(Direction::IN), 48 | listenimmediately(true), closing(false), sessionkey(-1) 49 | { 50 | } 51 | SocketType type; 52 | AddressFamily addrfam; 53 | int fd; 54 | int id; 55 | int parentid; 56 | std::string addr; 57 | int port; 58 | std::string localaddr; 59 | int localport; 60 | int gairet; 61 | struct addrinfo* gaires; 62 | std::string gaierr; 63 | bool gaiasync; 64 | EventReceiver* receiver; 65 | mutable std::list sendqueue; 66 | SSL* ssl; 67 | bool sslshutdown; 68 | Prio prio; 69 | bool paused; 70 | Direction direction; 71 | bool listenimmediately; 72 | bool closing; 73 | int sessionkey; 74 | }; 75 | 76 | } // namespace Core 77 | -------------------------------------------------------------------------------- /src/core/sslmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "types.h" 10 | 11 | namespace Core { 12 | 13 | /* Most OpenSSL handling resides in this class. */ 14 | class SSLManager { 15 | public: 16 | /* List all the loaded certificate/private keys as binary data in DER 17 | * format. 18 | */ 19 | static std::list> certKeyPairs(); 20 | 21 | /* Load a cert/key pair into OpenSSL by providing binary data. 22 | * The data can be either in PEM or DER format. */ 23 | static bool addCertKeyPair(const BinaryData& key, const BinaryData& cert); 24 | 25 | /* Clear all loaded cert/key pairs */ 26 | static void clearCertKeyPairs(); 27 | 28 | /* Must be called by every thread intending to issue OpenSSL commands */ 29 | static void init(); 30 | 31 | /* When linking OpenSSL statically, this must be called by every thread 32 | * that has issued OpenSSL commands 33 | */ 34 | static void cleanupThread(); 35 | 36 | static SSL_CTX* getClientSSLCTX(); 37 | static SSL_CTX* getServerSSLCTX(); 38 | static bool addCertKeyPair(EVP_PKEY* pkey, X509* x509); 39 | static const char* getCipher(SSL* ssl); 40 | static std::string version(); 41 | static std::string sslErrorToString(int error); 42 | static bool isAbruptDisconnectError(unsigned long e); 43 | }; 44 | 45 | } // namespace Core 46 | -------------------------------------------------------------------------------- /src/core/threading.cpp: -------------------------------------------------------------------------------- 1 | #include "threading.h" 2 | 3 | #include 4 | 5 | #include "signal.h" 6 | 7 | namespace Core { 8 | namespace Threading { 9 | 10 | namespace { 11 | 12 | struct ThreadFunc { 13 | void (*func)(void*); 14 | void* arg; 15 | }; 16 | 17 | void* runDetached(void* vtf) { 18 | blockAllRegisteredSignals(); 19 | ThreadFunc* tf = reinterpret_cast(vtf); 20 | tf->func(tf->arg); 21 | delete tf; 22 | return nullptr; 23 | } 24 | } // namespace 25 | 26 | void setThreadName(pthread_t thread, const std::string& name) { 27 | assert(name.length() <= 15); 28 | #ifdef _ISOC95_SOURCE 29 | pthread_setname_np(thread, name.c_str()); 30 | #endif 31 | } 32 | 33 | void setCurrentThreadName(const std::string& name) { 34 | assert(name.length() <= 15); 35 | setThreadName(pthread_self(), name); 36 | } 37 | 38 | pthread_t createDetachedThread(void (*func)(void*), void* arg) { 39 | pthread_t thread; 40 | pthread_attr_t attr; 41 | pthread_attr_init(&attr); 42 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 43 | ThreadFunc* tf = new ThreadFunc(); 44 | tf->func = func; 45 | tf->arg = arg; 46 | pthread_create(&thread, &attr, runDetached, static_cast(tf)); 47 | return thread; 48 | } 49 | 50 | void blockSignalsInternal() { 51 | blockAllRegisteredSignals(); 52 | } 53 | 54 | } // namespace Threading 55 | } // namespace Core 56 | -------------------------------------------------------------------------------- /src/core/threading.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Core { 8 | namespace Threading { 9 | void setThreadName(pthread_t thread, const std::string& name); 10 | void setCurrentThreadName(const std::string& name); 11 | pthread_t createDetachedThread(void (*func)(void*), void* arg = nullptr); 12 | void blockSignalsInternal(); 13 | } // namespace Threading 14 | 15 | template class Thread { 16 | public: 17 | void start(const std::string& name, T* instance) { 18 | this->instance = instance; 19 | pthread_create(&thread, nullptr, run, (void *) this); 20 | Threading::setThreadName(thread, name); 21 | } 22 | void join() { 23 | pthread_join(thread, nullptr); 24 | } 25 | bool isCurrentThread() { 26 | return pthread_self() == thread; 27 | } 28 | private: 29 | static void* run(void* target) { 30 | Threading::blockSignalsInternal(); 31 | ((Thread*) target)->instance->run(); 32 | return nullptr; 33 | } 34 | T* instance; 35 | pthread_t thread; 36 | }; 37 | 38 | } // namespace Core 39 | -------------------------------------------------------------------------------- /src/core/tickpoketarget.cpp: -------------------------------------------------------------------------------- 1 | #include "tickpoketarget.h" 2 | 3 | namespace Core { 4 | 5 | TickPokeTarget::TickPokeTarget(EventReceiver* pokee, int interval, int message, const std::string& desc) : 6 | pokee(pokee), interval(interval), currentval(0), message(message), desc(desc) 7 | { 8 | } 9 | 10 | int TickPokeTarget::getMessage() const { 11 | return message; 12 | } 13 | 14 | EventReceiver* TickPokeTarget::getPokee() const { 15 | return pokee; 16 | } 17 | 18 | bool TickPokeTarget::tick(int msecs) { 19 | currentval += msecs; 20 | if (currentval >= interval) { 21 | currentval = currentval - interval; 22 | return true; 23 | } 24 | return false; 25 | } 26 | 27 | } // namespace Core 28 | -------------------------------------------------------------------------------- /src/core/tickpoketarget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Core { 6 | 7 | class EventReceiver; 8 | 9 | class TickPokeTarget { 10 | public: 11 | TickPokeTarget(EventReceiver* pokee, int interval, int message, const std::string& desc); 12 | int getMessage() const; 13 | EventReceiver* getPokee() const; 14 | bool tick(int msecs); 15 | private: 16 | EventReceiver* pokee; 17 | int interval; 18 | int currentval; 19 | int message; 20 | std::string desc; 21 | }; 22 | 23 | } // namespace Core 24 | -------------------------------------------------------------------------------- /src/core/types.cpp: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | namespace Core { 4 | 5 | StringResult::StringResult() : success(false) { 6 | 7 | } 8 | 9 | StringResult::StringResult(const char* result) : success(true), result(result) { 10 | 11 | } 12 | 13 | StringResult::StringResult(const std::string& result) : success(true), result(result) { 14 | 15 | } 16 | 17 | StringResultError::StringResultError(const std::string& error) { 18 | this->error = error; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/core/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Core { 7 | 8 | typedef std::vector BinaryData; 9 | 10 | enum class AddressFamily 11 | { 12 | NONE, 13 | IPV4, 14 | IPV6, 15 | IPV4_IPV6, 16 | }; 17 | 18 | struct StringResult { 19 | StringResult(); 20 | StringResult(const char* result); 21 | StringResult(const std::string& result); 22 | bool success; 23 | std::string result; 24 | std::string error; 25 | }; 26 | 27 | struct StringResultError : public StringResult { 28 | StringResultError(const std::string& error); 29 | }; 30 | 31 | } // namespace Core 32 | -------------------------------------------------------------------------------- /src/core/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Core { 6 | namespace util { 7 | 8 | const int ERR_BUF_SIZE = 256; 9 | 10 | /* Simple wildcard compare where * and ? are supported (not case sensitive) */ 11 | int wildcmp(const char* wild, const char* string); 12 | 13 | /* Simple wildcard compare where * and ? are supported */ 14 | int wildcmpCase(const char* wild, const char* string); 15 | 16 | /* convenience for thread-safe XSI-compatible strerror usage */ 17 | std::string getStrError(int error); 18 | 19 | } // namespace util 20 | } // namespace Core 21 | -------------------------------------------------------------------------------- /src/crypto.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/types.h" 6 | 7 | class Crypto { 8 | public: 9 | static void encrypt(const Core::BinaryData& indata, const Core::BinaryData& pass, Core::BinaryData& outdata); 10 | static void decrypt(const Core::BinaryData& indata, const Core::BinaryData& pass, Core::BinaryData& outdata); 11 | static void decryptOld(const Core::BinaryData& indata, const Core::BinaryData& pass, Core::BinaryData& outdata); 12 | static void sha256(const Core::BinaryData& indata, Core::BinaryData& outdata); 13 | static void base64Encode(const Core::BinaryData& indata, Core::BinaryData& outdata); 14 | static void base64Decode(const Core::BinaryData& indata, Core::BinaryData& outdata); 15 | static bool isMostlyASCII(const Core::BinaryData& data); 16 | static std::string toHex(const Core::BinaryData& indata); 17 | static void fromHex(const std::string& indata, Core::BinaryData& outdata); 18 | }; 19 | -------------------------------------------------------------------------------- /src/datafilehandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "core/types.h" 7 | #include "path.h" 8 | 9 | enum class DataFileState { 10 | NOT_EXISTING, 11 | EXISTS_PLAIN, 12 | EXISTS_ENCRYPTED, 13 | EXISTS_DECRYPTED 14 | }; 15 | 16 | class DataFileHandler { 17 | private: 18 | void parseDecryptedFile(const Core::BinaryData& data); 19 | Core::BinaryData rawdata; 20 | std::vector decryptedlines; 21 | std::vector outputlines; 22 | Path datafile; 23 | std::string key; 24 | Core::BinaryData filehash; 25 | DataFileState state; 26 | public: 27 | DataFileHandler(); 28 | DataFileState getState() const; 29 | bool tryDecrypt(const std::string& key); 30 | void writeFile(); 31 | bool changeKey(const std::string& key, const std::string& newkey); 32 | bool setEncrypted(const std::string& key); 33 | bool setPlain(const std::string& key); 34 | void clearOutputData(); 35 | void addOutputLine(const std::string& owner, const std::string& line); 36 | void getDataFor(const std::string& owner, std::vector* matches); 37 | static Path getDataDir(); 38 | }; 39 | -------------------------------------------------------------------------------- /src/datafilehandlermethod.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/types.h" 4 | #include "crypto.h" 5 | 6 | namespace { 7 | 8 | namespace DataFileHandlerMethod { 9 | 10 | inline bool encrypt(const Core::BinaryData& indata, const Core::BinaryData& pass, Core::BinaryData& outdata) { 11 | if (!Crypto::isMostlyASCII(indata)) { 12 | return false; 13 | } 14 | Crypto::encrypt(indata, pass, outdata); 15 | return true; 16 | } 17 | 18 | inline bool decrypt(const Core::BinaryData& indata, const Core::BinaryData& pass, Core::BinaryData& outdata) { 19 | Crypto::decrypt(indata, pass, outdata); 20 | if (!Crypto::isMostlyASCII(outdata)) { 21 | Crypto::decryptOld(indata, pass, outdata); 22 | } 23 | return Crypto::isMostlyASCII(outdata); 24 | } 25 | 26 | inline Path getDataFile() { 27 | std::string datafilestr = DATA_FILE; 28 | char * overridedf = getenv("CBFTP_DATA_PATH"); 29 | if (overridedf != nullptr) { 30 | datafilestr = overridedf; 31 | } 32 | size_t homepos = datafilestr.find('~'); 33 | if (homepos != std::string::npos) { 34 | datafilestr = datafilestr.substr(0, homepos) + getenv("HOME") + datafilestr.substr(homepos + 1); 35 | } 36 | Path datafile(datafilestr); 37 | if (datafile.isRelative()) { 38 | char buf[512]; 39 | char* cwd = getcwd(buf, sizeof(buf)); 40 | if (cwd == nullptr) { 41 | perror("Error: getcwd() failed."); 42 | exit(1); 43 | } 44 | return Path(std::string(cwd)) / datafile; 45 | } 46 | return datafile; 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/delayedcommand.cpp: -------------------------------------------------------------------------------- 1 | #include "delayedcommand.h" 2 | 3 | DelayedCommand::DelayedCommand() : 4 | active(false), 5 | released(false), 6 | persisting(false) { 7 | } 8 | 9 | void DelayedCommand::set(const std::string & command, unsigned long long int triggertime, const std::weak_ptr & co, bool persisting) { 10 | this->command = command; 11 | this->triggertime = triggertime; 12 | this->co = co; 13 | this->persisting = persisting; 14 | this->active = true; 15 | this->released = false; 16 | } 17 | 18 | void DelayedCommand::currentTime(unsigned long long int time) { 19 | if (active && !released && time >= triggertime) { 20 | released = true; 21 | } 22 | } 23 | 24 | void DelayedCommand::reset() { 25 | active = false; 26 | released = false; 27 | } 28 | 29 | void DelayedCommand::weakReset() { 30 | if (!persisting) { 31 | reset(); 32 | } 33 | } 34 | 35 | std::string DelayedCommand::getCommand() const { 36 | return command; 37 | } 38 | 39 | std::shared_ptr DelayedCommand::getCommandOwner() const { 40 | return co.lock(); 41 | } 42 | 43 | bool DelayedCommand::isActive() const { 44 | return active; 45 | } 46 | 47 | bool DelayedCommand::isReleased() const { 48 | return released; 49 | } 50 | -------------------------------------------------------------------------------- /src/delayedcommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class CommandOwner; 7 | 8 | class DelayedCommand { 9 | private: 10 | std::string command; 11 | unsigned long long int triggertime; 12 | std::weak_ptr co; 13 | bool active; 14 | bool released; 15 | bool persisting; 16 | public: 17 | DelayedCommand(); 18 | void set(const std::string & command, unsigned long long int triggertime, const std::weak_ptr & co = std::weak_ptr(), bool persisting = false); 19 | void currentTime(unsigned long long int); 20 | void reset(); 21 | void weakReset(); 22 | std::string getCommand() const; 23 | std::shared_ptr getCommandOwner() const; 24 | bool isActive() const; 25 | bool isReleased() const; 26 | bool isPersisting() const; 27 | }; 28 | -------------------------------------------------------------------------------- /src/downloadfiledata.cpp: -------------------------------------------------------------------------------- 1 | #include "downloadfiledata.h" 2 | 3 | #include "transferstatus.h" 4 | #include "filelist.h" 5 | 6 | DownloadFileData::~DownloadFileData() { 7 | } 8 | -------------------------------------------------------------------------------- /src/downloadfiledata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "core/types.h" 7 | 8 | class FileList; 9 | class TransferStatus; 10 | 11 | struct DownloadFileData { 12 | ~DownloadFileData(); 13 | std::shared_ptr fl; 14 | std::shared_ptr ts; 15 | Core::BinaryData data; 16 | std::string file; 17 | bool inmemory; 18 | }; 19 | -------------------------------------------------------------------------------- /src/encoding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/types.h" 6 | 7 | namespace encoding { 8 | 9 | enum Encoding { 10 | ENCODING_CP437, 11 | ENCODING_CP437_DOUBLE, 12 | ENCODING_ISO88591, 13 | ENCODING_UTF8 14 | }; 15 | 16 | unsigned int cp437toUnicode(unsigned char); 17 | std::basic_string cp437toUnicode(const std::string &); 18 | std::basic_string doublecp437toUnicode(const std::string &); 19 | std::basic_string toUnicode(const std::string &); 20 | std::basic_string utf8toUnicode(const std::string &); 21 | Encoding guessEncoding(const Core::BinaryData& data); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/eventlog.cpp: -------------------------------------------------------------------------------- 1 | #include "eventlog.h" 2 | 3 | #include "rawbuffer.h" 4 | 5 | EventLog::EventLog() { 6 | rawbuf = new RawBuffer(); 7 | latestid = 0; 8 | } 9 | 10 | EventLog::~EventLog() { 11 | delete rawbuf; 12 | } 13 | 14 | RawBuffer* EventLog::getRawBuffer() const { 15 | return rawbuf; 16 | } 17 | 18 | void EventLog::log(const std::string& owner, const std::string& text, Core::LogLevel level) { 19 | std::string line = "<" + owner + "> " + text; 20 | latest = line; 21 | latestid++; 22 | rawbuf->writeLine("<" + owner + "> " + text); 23 | } 24 | 25 | std::string EventLog::getLatest() const { 26 | return latest; 27 | } 28 | 29 | int EventLog::getLatestId() const { 30 | return latestid; 31 | } 32 | -------------------------------------------------------------------------------- /src/eventlog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/logger.h" 6 | 7 | class RawBuffer; 8 | 9 | class EventLog : public Core::Logger { 10 | public: 11 | EventLog(); 12 | ~EventLog(); 13 | RawBuffer* getRawBuffer() const; 14 | int getLatestId() const; 15 | std::string getLatest() const; 16 | void log(const std::string& owner, const std::string& text, Core::LogLevel level = Core::LogLevel::INFO) override; 17 | private: 18 | RawBuffer* rawbuf; 19 | std::string latest; 20 | int latestid; 21 | }; 22 | -------------------------------------------------------------------------------- /src/ext/Makefile: -------------------------------------------------------------------------------- 1 | -include ../../Makefile.inc 2 | 3 | SRC_C = $(wildcard *.c) 4 | SRC_CPP = $(wildcard *.cpp) 5 | OBJS = $(SRC_C:%.c=%.o) $(SRC_CPP:%.cpp=%.o) 6 | LIB = libext.a 7 | CLEANFILES = $(wildcard $(OBJS) $(OBJS:%.o=%.d) $(LIB)) 8 | 9 | all: $(OBJS) 10 | @+$(MAKE) --no-print-directory $(LIB) 11 | 12 | quiet: 13 | @# 14 | 15 | $(LIB): $(OBJS) | quiet 16 | ar rc $@ $^ && ranlib $@ 17 | 18 | clean: 19 | @if test $(firstword $(CLEANFILES)); then rm -rf $(CLEANFILES); echo rm -rf $(CLEANFILES); fi 20 | 21 | ifneq ($(wildcard ../../Makefile.inc),) 22 | $(OBJS): ../../Makefile.inc 23 | endif 24 | 25 | #-include $(OBJS:%.o=%.d) 26 | -------------------------------------------------------------------------------- /src/externalscripts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "path.h" 9 | #include "subprocessmanager.h" 10 | 11 | class RawBuffer; 12 | 13 | struct ExternalScript { 14 | ExternalScript(const std::string& name, const Path& path, int id); 15 | std::string name; 16 | Path path; 17 | int id; 18 | }; 19 | 20 | struct RunningScript { 21 | RunningScript(int pid, const std::string& name, const std::string& token); 22 | int pid; 23 | std::string name; 24 | std::string tempauthtoken; 25 | }; 26 | 27 | class ExternalScripts : public SubProcessCallback { 28 | public: 29 | ExternalScripts(const std::string& name = ""); 30 | virtual ~ExternalScripts(); 31 | std::list::const_iterator begin() const; 32 | std::list::const_iterator end() const; 33 | std::string getName() const; 34 | bool hasScript(const std::string& scriptname) const; 35 | bool hasScript(int id) const; 36 | std::string getScriptName(int id) const; 37 | void addScript(const std::string& name, const Path& path, int id = -1); 38 | std::shared_ptr execute(int id, const std::vector& args); 39 | int size() const; 40 | void clear(); 41 | private: 42 | int nextAvailableId() const; 43 | void processExited(int pid, int status) override; 44 | void processStdOut(int pid, const std::string& text) override; 45 | void processStdErr(int pid, const std::string& text) override; 46 | std::list scripts; 47 | std::string name; 48 | std::list runningscripts; 49 | }; 50 | -------------------------------------------------------------------------------- /src/externalscriptsmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "externalscriptsmanager.h" 2 | 3 | void ExternalScriptsManager::addExternalScripts(const std::string& name, ExternalScripts* externalscripts) { 4 | this->externalscripts.insert(std::make_pair(name, externalscripts)); 5 | } 6 | 7 | ExternalScripts* ExternalScriptsManager::getExternalScripts(const std::string& name) { 8 | std::map::const_iterator it = externalscripts.find(name); 9 | if (it != externalscripts.end()) { 10 | return it->second; 11 | } 12 | return nullptr; 13 | } 14 | 15 | std::map::const_iterator ExternalScriptsManager::begin() const { 16 | return externalscripts.begin(); 17 | } 18 | 19 | std::map::const_iterator ExternalScriptsManager::end() const { 20 | return externalscripts.end(); 21 | } 22 | -------------------------------------------------------------------------------- /src/externalscriptsmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class ExternalScripts; 7 | 8 | class ExternalScriptsManager { 9 | public: 10 | void addExternalScripts(const std::string& name, ExternalScripts* externalscripts); 11 | ExternalScripts* getExternalScripts(const std::string& name); 12 | std::map::const_iterator begin() const; 13 | std::map::const_iterator end() const; 14 | private: 15 | std::map externalscripts; 16 | }; 17 | -------------------------------------------------------------------------------- /src/filelistdata.cpp: -------------------------------------------------------------------------------- 1 | #include "filelistdata.h" 2 | 3 | FileListData::FileListData(const std::shared_ptr& filelist, RawBuffer* cwdrawbuffer) 4 | : filelist(filelist), cwdrawbuffer(*cwdrawbuffer) 5 | { 6 | 7 | } 8 | 9 | std::shared_ptr FileListData::getFileList() const { 10 | return filelist; 11 | } 12 | 13 | const RawBuffer& FileListData::getCwdRawBuffer() const { 14 | return cwdrawbuffer; 15 | } 16 | -------------------------------------------------------------------------------- /src/filelistdata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rawbuffer.h" 6 | 7 | class FileList; 8 | 9 | class FileListData { 10 | public: 11 | FileListData(const std::shared_ptr& filelist, RawBuffer* cwdrawbuffer); 12 | std::shared_ptr getFileList() const; 13 | const RawBuffer& getCwdRawBuffer() const; 14 | private: 15 | std::shared_ptr filelist; 16 | RawBuffer cwdrawbuffer; 17 | }; 18 | -------------------------------------------------------------------------------- /src/filesystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/types.h" 6 | #include "path.h" 7 | #include "util.h" 8 | 9 | namespace FileSystem { 10 | 11 | struct SpaceInfo { 12 | unsigned long long int size; 13 | unsigned long long int used; 14 | unsigned long long int avail; 15 | }; 16 | 17 | bool directoryExists(const Path& path); 18 | bool directoryExistsReadable(const Path& path); 19 | bool directoryExistsWritable(const Path& path); 20 | bool fileExists(const Path& path); 21 | bool fileExistsReadable(const Path& path); 22 | bool fileExistsWritable(const Path& path); 23 | util::Result createDirectory(const Path& path, bool privatedir = false); 24 | util::Result createDirectoryRecursive(const Path& path); 25 | util::Result readFile(const Path& path, Core::BinaryData& rawdata); 26 | util::Result writeFile(const Path& path, const Core::BinaryData& data); 27 | util::Result move(const Path& src, const Path& dst); 28 | SpaceInfo getSpaceInfo(const Path & path); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/ftpconnect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "eventreceiverproxyintermediate.h" 7 | 8 | #include "address.h" 9 | 10 | class FTPConnectOwner; 11 | class ProxySession; 12 | class Proxy; 13 | struct Address; 14 | 15 | class FTPConnect : public EventReceiverProxyIntermediate { 16 | public: 17 | FTPConnect(int id, FTPConnectOwner* owner, const Address& addr, Proxy* proxy, bool primary, bool implicittls); 18 | ~FTPConnect(); 19 | int getId() const; 20 | int handedOver(); 21 | Address getAddress() const; 22 | bool isPrimary() const; 23 | void disengage(); 24 | void tickIntern(); 25 | private: 26 | void FDInterConnecting(int sockid, const std::string& addr) override; 27 | void FDInterConnected(int sockid) override; 28 | void FDInterData(int sockid, char* data, unsigned int datalen) override; 29 | void FDInterInfo(int sockid, const std::string& info) override; 30 | void FDInterDisconnected(int sockid, Core::DisconnectType reason, const std::string& details) override; 31 | void FDFail(int sockid, const std::string& error) override; 32 | void FDSSLSuccess(int sockid, const std::string& cipher) override; 33 | void proxySessionInit(); 34 | int id; 35 | FTPConnectOwner * owner; 36 | unsigned int databuflen; 37 | char * databuf; 38 | unsigned int databufpos; 39 | int databufcode; 40 | Address addr; 41 | Address resolvedaddr; 42 | bool primary; 43 | bool engaged; 44 | bool connected; 45 | bool welcomereceived; 46 | int millisecs; 47 | bool implicittls; 48 | }; 49 | -------------------------------------------------------------------------------- /src/ftpconnectowner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Addr; 6 | 7 | class FTPConnectOwner { 8 | public: 9 | virtual void ftpConnectInfo(int id, const std::string &) = 0; 10 | virtual void ftpConnectSuccess(int id, const Address& addr) = 0; 11 | virtual void ftpConnectFail(int id) = 0; 12 | virtual ~FTPConnectOwner() { 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/hourlyalltracking.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class HourlyAllTracking { 6 | public: 7 | HourlyAllTracking(); 8 | void add(unsigned long long int); 9 | void tickMinute(); 10 | unsigned long long int getLast24Hours() const; 11 | unsigned long long int getAll() const; 12 | unsigned int getStartTimestamp() const; 13 | void setAll(unsigned long long int count); 14 | std::vector getHours() const; 15 | void setHours(const std::vector& hours, unsigned int timestamp); 16 | void reset(); 17 | void resetHours(); 18 | private: 19 | void checkRotate(); 20 | std::vector hours; 21 | unsigned long long int last24hours; 22 | unsigned long long int all; 23 | unsigned int minutessincelastrotation; 24 | }; 25 | -------------------------------------------------------------------------------- /src/http/Makefile: -------------------------------------------------------------------------------- 1 | -include ../../Makefile.inc 2 | 3 | SRC = $(wildcard *.cpp) 4 | LIB = libhttp.a 5 | CLEANFILES = $(wildcard $(SRC:%.cpp=%.o) $(SRC:%.cpp=%.d) $(LIB)) 6 | 7 | all: $(SRC:%.cpp=%.o) 8 | @+$(MAKE) --no-print-directory $(LIB) 9 | 10 | quiet: 11 | @# 12 | 13 | $(LIB): $(SRC:%.cpp=%.o) | quiet 14 | ar rc $@ $^ && ranlib $@ 15 | 16 | clean: 17 | @if test $(firstword $(CLEANFILES)); then rm -rf $(CLEANFILES); echo rm -rf $(CLEANFILES); fi 18 | 19 | ifneq ($(wildcard ../../Makefile.inc),) 20 | %.o: %.cpp ../../Makefile.inc 21 | endif 22 | 23 | -include $(SRC:%.cpp=%.d) 24 | -------------------------------------------------------------------------------- /src/http/message.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace http { 10 | 11 | /* Base class for the common parts of HTTPRequests and HTTPResponses. */ 12 | class Message { 13 | public: 14 | explicit Message(const std::string& protocol = "HTTP/1.1"); 15 | virtual ~Message(); 16 | 17 | /* Add header or append to already existing header through comma separation. */ 18 | void appendHeader(const std::string& header, const std::string& value); 19 | 20 | /* Add header or overwrite existing header value. */ 21 | void addHeader(const std::string& header, const std::string& value); 22 | 23 | bool hasHeader(const std::string& header) const; 24 | 25 | void removeHeader(const std::string& header); 26 | 27 | std::string getHeaderValue(const std::string& header) const; 28 | 29 | const std::list& getHeaderValues(const std::string& header) const; 30 | 31 | size_t getBodySize() const; 32 | 33 | std::shared_ptr> getBody() const; 34 | 35 | /* Set optional body, used as part of the serialized representation. */ 36 | void setBody(const std::vector& body); 37 | 38 | /* Serialize into a HTTP stream message */ 39 | virtual std::vector serialize() const = 0; 40 | 41 | protected: 42 | /* Called by serialize() in subclasses */ 43 | std::vector serializeCommon(const std::string& startline) const; 44 | 45 | std::string protocol; 46 | 47 | private: 48 | struct HeaderValues { 49 | explicit HeaderValues(const std::string& name); 50 | HeaderValues() = default; 51 | 52 | std::string name; 53 | std::list values; 54 | }; 55 | std::map headers; 56 | std::shared_ptr> body; 57 | }; 58 | } // namespace http 59 | -------------------------------------------------------------------------------- /src/http/parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../ext/picohttpparser.h" 7 | 8 | namespace http { 9 | 10 | class Message; 11 | 12 | enum class State { 13 | BODY = 0, 14 | HEADERS = 1, 15 | PARSING_FAILED = -1, 16 | PARTIAL = -2, 17 | BODY_TOO_LONG = -3, 18 | URI_TOO_LONG = -4, 19 | UNKNOWN = -5 20 | }; 21 | 22 | struct Result { 23 | Result(); 24 | Result(State state, const char* data = nullptr, size_t datalen = 0, bool complete = false); 25 | State state; 26 | const char* data; 27 | size_t datalen; 28 | bool complete; 29 | }; 30 | 31 | #define MAX_HEADERS 100 32 | 33 | /* Base class for the common parts of HTTP request and response parsing. */ 34 | class Parser { 35 | public: 36 | explicit Parser(); 37 | virtual ~Parser(); 38 | 39 | /* Feed incoming data from a socket into the parser. Returns false if a parsing 40 | * error occurred. 41 | */ 42 | Result feed(const char* data, size_t datalen); 43 | 44 | /* Clear the parsing buffer. */ 45 | void clear(); 46 | 47 | protected: 48 | /* Called by parse() in subclasses. */ 49 | void parseHeaders(Message& msg, struct phr_header* headers, size_t numheaders); 50 | 51 | private: 52 | virtual int parse(const char* data, size_t datalen, size_t prevdatalen = 0) = 0; 53 | std::vector headers; 54 | size_t headerslen; 55 | size_t bodylen; 56 | size_t contentlen; 57 | bool inbody; 58 | }; 59 | } // namespace http 60 | -------------------------------------------------------------------------------- /src/http/request.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "message.h" 8 | 9 | namespace http { 10 | 11 | class Request : public Message { 12 | public: 13 | /* Internally used by RequestParser. */ 14 | Request(); 15 | 16 | /* Create a HTTP request. 17 | * method: GET, POST, PUT, HEAD etc 18 | * path: the target path of the request 19 | * minorVersion: the HTTP version, HTTP/1.x 20 | * protocol is only used by classes that derive from this class. 21 | */ 22 | Request(const std::string& method, const std::string& path, int minorVersion = 1); 23 | 24 | /* Serialize into a HTTP request message. */ 25 | std::vector serialize() const override; 26 | 27 | std::string getMethod() const; 28 | std::string getPath() const; 29 | std::string getPathWithQueryParams() const; 30 | 31 | void setMethod(const std::string& method); 32 | void setPath(const std::string& path); 33 | void addQueryParam(const std::string& queryparam, const std::string& value); 34 | bool hasQueryParam(const std::string& queryparam) const; 35 | void removeQueryParam(const std::string& queryparam); 36 | std::string getQueryParamValue(const std::string& queryparam) const; 37 | std::map getQueryParams() const; 38 | 39 | private: 40 | void parseQueryParams(const std::string& queryparams); 41 | void generatePathWithQueryParams(); 42 | std::string method; 43 | std::string path; 44 | std::string pathwithqueryparams; 45 | std::map queryparams; 46 | }; 47 | } // namespace http 48 | -------------------------------------------------------------------------------- /src/http/requestparser.cpp: -------------------------------------------------------------------------------- 1 | #include "requestparser.h" 2 | 3 | #include "../ext/picohttpparser.h" 4 | 5 | #include "request.h" 6 | 7 | namespace http { 8 | 9 | const Request& RequestParser::getRequest() const { 10 | return request; 11 | } 12 | 13 | int RequestParser::parse(const char* data, size_t datalen, size_t prevdatalen) { 14 | const char* method; 15 | const char* path; 16 | int minorversion; 17 | struct phr_header headers[MAX_HEADERS]; 18 | size_t numheaders = MAX_HEADERS; 19 | size_t methodlen, pathlen; 20 | int ret = phr_parse_request(data, datalen, &method, &methodlen, &path, &pathlen, 21 | &minorversion, headers, &numheaders, prevdatalen); 22 | if (ret > 0) { 23 | request = Request(std::string(method, methodlen), std::string(path, pathlen), minorversion); 24 | parseHeaders(request, headers, numheaders); 25 | } 26 | return ret; 27 | } 28 | } // namespace http 29 | -------------------------------------------------------------------------------- /src/http/requestparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "parser.h" 4 | #include "request.h" 5 | 6 | namespace http { 7 | 8 | class RequestParser : public Parser { 9 | public: 10 | using Parser::Parser; 11 | const Request& getRequest() const; 12 | 13 | private: 14 | int parse(const char* data, size_t datalen, size_t prevdatalen) override; 15 | Request request; 16 | }; 17 | } // namespace http 18 | -------------------------------------------------------------------------------- /src/http/response.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "message.h" 7 | 8 | namespace http { 9 | 10 | class Response : public Message 11 | { 12 | public: 13 | /* Internally used by ResponseParser. */ 14 | Response(); 15 | 16 | /* Create a HTTP response. 17 | * code is the status code, i.e. 200, 404 etc 18 | * text is the status text, i.e. OK, File not found, etc 19 | * minorVersion is the HTTP version, HTTP/1.x 20 | * protocol is only used by classes that derive from this class. 21 | */ 22 | Response(int code, const std::string& text, int minorversion = 1); 23 | 24 | /* Create a HTTP response and infer the status text from the given code. */ 25 | Response(int code, int minorversion = 1); 26 | 27 | /* Serialize into a HTTP response message. */ 28 | std::vector serialize() const override; 29 | 30 | int getStatusCode() const; 31 | std::string getStatusText() const; 32 | void setStatusCode(int code); 33 | 34 | private: 35 | int statuscode; 36 | std::string statustext; 37 | }; 38 | } // namespace http 39 | -------------------------------------------------------------------------------- /src/http/responseparser.cpp: -------------------------------------------------------------------------------- 1 | #include "responseparser.h" 2 | 3 | #include 4 | 5 | #include "../ext/picohttpparser.h" 6 | 7 | #include "response.h" 8 | 9 | namespace http { 10 | 11 | Response ResponseParser::getResponse() { 12 | return response; 13 | } 14 | 15 | int ResponseParser::parse(const char* data, size_t datalen, size_t prevdatalen) { 16 | const char* message; 17 | int status; 18 | int minorversion; 19 | struct phr_header headers[MAX_HEADERS]; 20 | size_t numheaders = MAX_HEADERS; 21 | size_t messagelen; 22 | int ret = phr_parse_response(data, datalen, &minorversion, &status, &message, &messagelen, 23 | headers, &numheaders, prevdatalen); 24 | if (ret > 0) 25 | { 26 | response = Response(status, std::string(message, messagelen), minorversion); 27 | parseHeaders(response, headers, numheaders); 28 | } 29 | return ret; 30 | } 31 | } // namespace EWHTTPParser 32 | -------------------------------------------------------------------------------- /src/http/responseparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "parser.h" 4 | #include "response.h" 5 | 6 | namespace http { 7 | 8 | class ResponseParser : public Parser 9 | { 10 | public: 11 | using Parser::Parser; 12 | Response getResponse(); 13 | private: 14 | int parse(const char* data, size_t datalen, size_t prevdatalen) override; 15 | Response response; 16 | }; 17 | } // namespace http 18 | -------------------------------------------------------------------------------- /src/httpserver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "core/eventreceiver.h" 6 | 7 | #define DEFAULT_API_PORT 55477 8 | 9 | class HTTPConn; 10 | 11 | class HTTPServer : private Core::EventReceiver { 12 | public: 13 | HTTPServer(); 14 | ~HTTPServer(); 15 | bool getEnabled() const; 16 | int getPort() const; 17 | void setEnabled(bool enabled); 18 | void setPort(int port); 19 | private: 20 | void bindListen(); 21 | void close(); 22 | void FDNew(int sockid, int newsockid) override; 23 | void FDFail(int sockid, const std::string& error) override; 24 | bool enabled; 25 | int port; 26 | int sockid4; 27 | int sockid6; 28 | std::list conns; 29 | }; 30 | -------------------------------------------------------------------------------- /src/loadmonitorcallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class LoadMonitorCallback { 4 | public: 5 | virtual void recommendedPerformanceLevelChanged(int newlevel) = 0; 6 | virtual ~LoadMonitorCallback() {} 7 | }; 8 | -------------------------------------------------------------------------------- /src/localdownload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "localtransfer.h" 4 | #include "address.h" 5 | 6 | class LocalStorage; 7 | class Path; 8 | 9 | class LocalDownload : public LocalTransfer { 10 | public: 11 | LocalDownload(LocalStorage* ls); 12 | void engage(TransferMonitor* tm, const Path& path, const std::string& filename, bool ipv6, const std::string& addr, int port, bool ssl, FTPConn* ftpconn); 13 | bool engage(TransferMonitor* tm, const Path& path, const std::string& filename, bool ipv6, bool ssl, FTPConn* ftpconn); 14 | void engage(TransferMonitor* tm, int storeid, bool ipv6, const std::string& addr, int port, bool ssl, FTPConn* ftpconn); 15 | bool engage(TransferMonitor* tm, int storeid, bool ipv6, bool ssl, FTPConn* ftpconn); 16 | unsigned long long int size() const override; 17 | int getStoreId() const; 18 | private: 19 | void FDInterConnected(int sockid) override; 20 | void FDInterDisconnected(int sockid, Core::DisconnectType reason, const std::string& details) override; 21 | void FDInterData(int sockid, char* data, unsigned int len) override; 22 | void FDInterListening(int sockid, const Address& addr) override; 23 | void FDSSLSuccess(int sockid, const std::string& cipher) override; 24 | void FDFail(int sockid, const std::string& error) override; 25 | void init(TransferMonitor* tm, FTPConn* ftpconn, const Path& path, const std::string& filename, bool inmemory, int storeid, bool ssl, bool passivemode, int port = 0); 26 | void append(char* data, unsigned int datalen); 27 | int storeid; 28 | unsigned long long int filesize; 29 | LocalStorage * ls; 30 | }; 31 | -------------------------------------------------------------------------------- /src/localfile.cpp: -------------------------------------------------------------------------------- 1 | #include "localfile.h" 2 | 3 | LocalFile::LocalFile(const std::string& name, unsigned long long int size, bool isdir, const std::string& owner, const std::string& group, int year, int month, int day, int hour, int minute, bool download) : 4 | name(name), 5 | size(size), 6 | isdir(isdir), 7 | owner(owner), 8 | group(group), 9 | year(year), 10 | month(month), 11 | day(day), 12 | hour(hour), 13 | minute(minute), 14 | touch(0), 15 | download(download) 16 | { 17 | } 18 | 19 | std::string LocalFile::getName() const { 20 | return name; 21 | } 22 | 23 | unsigned long long int LocalFile::getSize() const { 24 | return size; 25 | } 26 | 27 | bool LocalFile::isDirectory() const { 28 | return isdir; 29 | } 30 | 31 | std::string LocalFile::getOwner() const { 32 | return owner; 33 | } 34 | 35 | std::string LocalFile::getGroup() const { 36 | return group; 37 | } 38 | 39 | int LocalFile::getYear() const { 40 | return year; 41 | } 42 | 43 | int LocalFile::getMonth() const { 44 | return month; 45 | } 46 | 47 | int LocalFile::getDay() const { 48 | return day; 49 | } 50 | 51 | int LocalFile::getHour() const { 52 | return hour; 53 | } 54 | 55 | int LocalFile::getMinute() const { 56 | return minute; 57 | } 58 | 59 | void LocalFile::setSize(unsigned long long int size) { 60 | this->size = size; 61 | } 62 | 63 | int LocalFile::getTouch() const { 64 | return touch; 65 | } 66 | 67 | void LocalFile::setTouch(int touch) { 68 | this->touch = touch; 69 | } 70 | 71 | bool LocalFile::isDownloading() const { 72 | return download; 73 | } 74 | 75 | void LocalFile::setDownloading() { 76 | download = true; 77 | } 78 | 79 | void LocalFile::finishDownload() { 80 | download = false; 81 | } 82 | -------------------------------------------------------------------------------- /src/localfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class LocalFile { 6 | public: 7 | LocalFile(const std::string& name, unsigned long long int size, bool isdir, 8 | const std::string& owner, const std::string& group, int year, int month, 9 | int day, int hour, int minute, bool download = false); 10 | std::string getName() const; 11 | unsigned long long int getSize() const; 12 | bool isDirectory() const; 13 | std::string getOwner() const; 14 | std::string getGroup() const; 15 | int getYear() const; 16 | int getMonth() const; 17 | int getDay() const; 18 | int getHour() const; 19 | int getMinute() const; 20 | void setSize(unsigned long long int size); 21 | int getTouch() const; 22 | void setTouch(int touch); 23 | bool isDownloading() const; 24 | void setDownloading(); 25 | void finishDownload(); 26 | private: 27 | std::string name; 28 | unsigned long long int size; 29 | bool isdir; 30 | std::string owner; 31 | std::string group; 32 | int year; 33 | int month; 34 | int day; 35 | int hour; 36 | int minute; 37 | int touch; 38 | bool download; 39 | }; 40 | -------------------------------------------------------------------------------- /src/localfilelist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "localfile.h" 7 | #include "path.h" 8 | 9 | class LocalFileList { 10 | public: 11 | LocalFileList(const Path& path); 12 | void updateFile(const LocalFile& file, int touch = 0); 13 | void touchFile(const std::string& name, bool download = false); 14 | std::unordered_map::const_iterator begin() const; 15 | std::unordered_map::const_iterator end() const; 16 | std::unordered_map::const_iterator find(const std::string& name) const; 17 | const Path & getPath() const; 18 | unsigned int size() const; 19 | unsigned int sizeFiles() const; 20 | void cleanSweep(int touch); 21 | void finishDownload(const std::string& file); 22 | private: 23 | std::unordered_map::iterator findIntern(const std::string& name); 24 | std::unordered_map files; 25 | std::unordered_map lowercasefilemap; 26 | Path path; 27 | int sizefiles; 28 | }; 29 | -------------------------------------------------------------------------------- /src/localpathinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "localpathinfo.h" 2 | 3 | LocalPathInfo::LocalPathInfo(int dirs, int files, int depth, unsigned long long int size) : dirs(dirs), files(files), depth(depth), size(size) { 4 | 5 | } 6 | 7 | int LocalPathInfo::getNumDirs() const { 8 | return dirs; 9 | } 10 | 11 | int LocalPathInfo::getNumFiles() const { 12 | return files; 13 | } 14 | 15 | int LocalPathInfo::getDepth() const { 16 | return depth; 17 | } 18 | 19 | unsigned long long int LocalPathInfo::getSize() const { 20 | return size; 21 | } 22 | -------------------------------------------------------------------------------- /src/localpathinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class LocalPathInfo { 4 | public: 5 | LocalPathInfo(int dirs, int files, int depth, unsigned long long int size); 6 | int getNumDirs() const; 7 | int getNumFiles() const; 8 | int getDepth() const; 9 | unsigned long long int getSize() const; 10 | private: 11 | int dirs; 12 | int files; 13 | int depth; 14 | unsigned long long int size; 15 | }; 16 | -------------------------------------------------------------------------------- /src/localstoragerequestdata.cpp: -------------------------------------------------------------------------------- 1 | #include "localstoragerequestdata.h" 2 | 3 | LocalStorageRequestData::LocalStorageRequestData() : requestid(-1), care(true) 4 | { 5 | 6 | } 7 | 8 | FileListTaskData::FileListTaskData() { 9 | type = LocalStorageRequestType::GET_FILE_LIST; 10 | } 11 | 12 | PathInfoTaskData::PathInfoTaskData() { 13 | type = LocalStorageRequestType::GET_PATH_INFO; 14 | } 15 | 16 | DeleteFileTaskData::DeleteFileTaskData() { 17 | type = LocalStorageRequestType::DELETE; 18 | } 19 | 20 | MakeDirTaskData::MakeDirTaskData() { 21 | type = LocalStorageRequestType::MKDIR; 22 | } 23 | 24 | MoveTaskData::MoveTaskData() { 25 | type = LocalStorageRequestType::MOVE; 26 | } 27 | -------------------------------------------------------------------------------- /src/localstoragerequestdata.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "path.h" 4 | #include "util.h" 5 | 6 | class LocalFileList; 7 | class LocalPathInfo; 8 | 9 | enum class LocalStorageRequestType { 10 | GET_FILE_LIST, 11 | GET_PATH_INFO, 12 | DELETE, 13 | MKDIR, 14 | MOVE 15 | }; 16 | 17 | struct LocalStorageRequestData { 18 | LocalStorageRequestData(); 19 | int requestid; 20 | bool care; 21 | LocalStorageRequestType type; 22 | }; 23 | 24 | struct FileListTaskData : public LocalStorageRequestData { 25 | FileListTaskData(); 26 | Path path; 27 | std::shared_ptr filelist; 28 | }; 29 | 30 | struct PathInfoTaskData : public LocalStorageRequestData { 31 | PathInfoTaskData(); 32 | std::list paths; 33 | std::shared_ptr pathinfo; 34 | }; 35 | 36 | struct DeleteFileTaskData : public LocalStorageRequestData { 37 | DeleteFileTaskData(); 38 | Path file; 39 | bool success; 40 | }; 41 | 42 | struct MakeDirTaskData : public LocalStorageRequestData { 43 | MakeDirTaskData(); 44 | Path path; 45 | std::string dirname; 46 | util::Result result; 47 | }; 48 | 49 | struct MoveTaskData : public LocalStorageRequestData { 50 | MoveTaskData(); 51 | Path srcpath; 52 | Path dstpath; 53 | util::Result result; 54 | }; 55 | -------------------------------------------------------------------------------- /src/localtransfer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "eventreceiverproxyintermediate.h" 7 | #include "path.h" 8 | 9 | #define CHUNK 524288 10 | 11 | class TransferMonitor; 12 | class FTPConn; 13 | 14 | class LocalTransfer : public EventReceiverProxyIntermediate { 15 | public: 16 | LocalTransfer(); 17 | bool active() const; 18 | bool openFile(bool); 19 | int getPort() const; 20 | virtual unsigned long long int size() const = 0; 21 | FTPConn * getConn() const; 22 | protected: 23 | void activate(); 24 | void deactivate(); 25 | bool ssl; 26 | bool inmemory; 27 | bool passivemode; 28 | int port; 29 | TransferMonitor * tm; 30 | bool fileopened; 31 | FTPConn * ftpconn; 32 | std::fstream filestream; 33 | Path path; 34 | std::string filename; 35 | char * buf; 36 | unsigned int buflen; 37 | unsigned int bufpos; 38 | bool timeoutticker; 39 | private: 40 | void FDInterNew(int sockid, int newsockid) override; 41 | void FDInterInfo(int sockid, const std::string& info) override; 42 | void tick(int) override; 43 | bool inuse; 44 | }; 45 | -------------------------------------------------------------------------------- /src/localupload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "localtransfer.h" 4 | 5 | class Path; 6 | 7 | class LocalUpload : public LocalTransfer { 8 | public: 9 | LocalUpload(); 10 | void engage(TransferMonitor* tm, const Path& path, const std::string& filename, bool ipv6, const std::string& addr, int port, bool ssl, FTPConn* ftpconn); 11 | bool engage(TransferMonitor* tm, const Path& path, const std::string& filename, bool ipv6, bool ssl, FTPConn* ftpconn); 12 | unsigned long long int size() const override; 13 | private: 14 | void FDInterConnected(int sockid) override; 15 | void FDInterDisconnected(int sockid, Core::DisconnectType reason, const std::string& details) override; 16 | void FDInterData(int sockid, char* data, unsigned int len) override; 17 | void FDSSLSuccess(int sockid, const std::string& cipher) override; 18 | void FDInterSendComplete(int sockid) override; 19 | void FDInterListening(int sockid, const Address& addr) override; 20 | void FDFail(int sockid, const std::string& error) override; 21 | void init(TransferMonitor* tm, FTPConn* ftpconn, const Path& path, const std::string& filename, bool ssl, bool passivemode, int port = 0); 22 | void sendChunk(); 23 | unsigned long long int filepos; 24 | }; 25 | -------------------------------------------------------------------------------- /src/logmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "logmanager.h" 2 | 3 | LogManager::LogManager() : maxrawbuflines(4096) { 4 | 5 | } 6 | 7 | int LogManager::getMaxRawbufLines() const { 8 | return maxrawbuflines; 9 | } 10 | 11 | void LogManager::setMaxRawbufLines(int max) { 12 | maxrawbuflines = max; 13 | } 14 | -------------------------------------------------------------------------------- /src/logmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class LogManager { 4 | public: 5 | LogManager(); 6 | int getMaxRawbufLines() const; 7 | void setMaxRawbufLines(int max); 8 | private: 9 | int maxrawbuflines; 10 | }; 11 | -------------------------------------------------------------------------------- /src/path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Path { 8 | public: 9 | Path(); 10 | Path(const char *); 11 | Path(const std::string &); 12 | const std::string & toString() const; 13 | const std::string & unixPath() const; 14 | const std::string & dirName() const; 15 | const std::string & baseName() const; 16 | bool isAbsolute() const; 17 | bool isRelative() const; 18 | Path operator/(const Path &) const; 19 | Path operator/(const std::string &) const; 20 | Path operator/(const char *) const; 21 | bool operator==(const Path &) const; 22 | bool operator!=(const Path &) const; 23 | bool contains(const Path &) const; 24 | Path operator-(const Path &) const; 25 | std::list split() const; 26 | int levels() const; 27 | Path cutLevels(int) const; 28 | Path level(int) const; 29 | bool operator<(const Path& other) const; 30 | bool empty() const; 31 | private: 32 | Path(const char *, char, bool); 33 | Path(const std::string &, char, bool); 34 | Path(const Path &, const Path &); 35 | void setSeparatorAbsolute(); 36 | void flipSlashes(); 37 | void cleanPath(); 38 | void setPathParts(); 39 | std::string path; 40 | std::string unixpath; 41 | std::string dirname; 42 | std::string basename; 43 | char separatorchar; 44 | bool absolute; 45 | bool separatorcertain; 46 | }; 47 | 48 | std::ostream & operator<<(std::ostream &, const Path &); 49 | -------------------------------------------------------------------------------- /src/pendingtransfer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define PENDINGTRANSFER_DOWNLOAD 5432 7 | #define PENDINGTRANSFER_UPLOAD 5433 8 | #define PENDINGTRANSFER_FXP 5434 9 | 10 | class SiteLogic; 11 | class FileList; 12 | class LocalFileList; 13 | 14 | class PendingTransfer { 15 | public: 16 | PendingTransfer(const std::shared_ptr &, const std::shared_ptr& fls, std::string, const std::shared_ptr &, const std::shared_ptr& fld, std::string); 17 | PendingTransfer(const std::shared_ptr &, const std::shared_ptr& fls, std::string, std::shared_ptr, std::string); 18 | PendingTransfer(std::shared_ptr, std::string, const std::shared_ptr &, const std::shared_ptr& fld, std::string); 19 | ~PendingTransfer(); 20 | int type() const; 21 | const std::shared_ptr & getSrc() const; 22 | const std::shared_ptr & getDst() const; 23 | std::shared_ptr getSrcFileList() const; 24 | std::shared_ptr getDstFileList() const; 25 | std::shared_ptr& getLocalFileList(); 26 | std::string getSrcFileName() const; 27 | std::string getDstFileName() const; 28 | private: 29 | std::shared_ptr slsrc; 30 | std::shared_ptr sldst; 31 | std::shared_ptr flsrc; 32 | std::shared_ptr fldst; 33 | std::shared_ptr fllocal; 34 | std::string srcfilename; 35 | std::string dstfilename; 36 | int transfertype; 37 | }; 38 | -------------------------------------------------------------------------------- /src/potentialelement.cpp: -------------------------------------------------------------------------------- 1 | #include "potentialelement.h" 2 | 3 | #include "sitelogic.h" 4 | 5 | PotentialElement::PotentialElement() : site(NULL), potential(0), dstupslots(0) { 6 | } 7 | 8 | const std::shared_ptr & PotentialElement::getSite() const { 9 | return site; 10 | } 11 | 12 | int PotentialElement::getPotential() const { 13 | return potential; 14 | } 15 | 16 | void PotentialElement::update(const std::shared_ptr & site, int dstupslots, int potential, const std::string & filename) { 17 | this->site = site; 18 | this->dstupslots = dstupslots; 19 | this->potential = potential; 20 | this->filename = filename; 21 | } 22 | 23 | void PotentialElement::reset() { 24 | site.reset(); 25 | potential = 0; 26 | dstupslots = 0; 27 | filename = ""; 28 | } 29 | 30 | int PotentialElement::getDestinationSiteUploadSlots() const { 31 | return dstupslots; 32 | } 33 | 34 | std::string PotentialElement::getFileName() const { 35 | return filename; 36 | } 37 | -------------------------------------------------------------------------------- /src/potentialelement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class SiteLogic; 7 | 8 | class PotentialElement { 9 | private: 10 | std::shared_ptr site; 11 | int potential; 12 | int dstupslots; 13 | std::string filename; 14 | public: 15 | PotentialElement(); 16 | const std::shared_ptr & getSite() const; 17 | int getDestinationSiteUploadSlots() const; 18 | int getPotential() const; 19 | std::string getFileName() const; 20 | void reset(); 21 | void update(const std::shared_ptr &, int, int, const std::string &); 22 | }; 23 | -------------------------------------------------------------------------------- /src/potentiallistelement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class SiteLogic; 8 | class PotentialElement; 9 | 10 | class PotentialListElement { 11 | private: 12 | std::vector slots; 13 | bool allSlotsUsedForSite(const std::shared_ptr &, int) const; 14 | public: 15 | PotentialListElement(int); 16 | ~PotentialListElement(); 17 | bool update(const std::shared_ptr &, int, int, const std::string &); 18 | void reset(); 19 | std::vector & getSlotsVector(); 20 | void updateSlots(int); 21 | 22 | }; 23 | -------------------------------------------------------------------------------- /src/potentialtracker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "core/eventreceiver.h" 9 | 10 | #define POTENTIALITY_LIFESPAN 3000 11 | #define POTENTIALITY_SLICES 10 12 | 13 | class PotentialElement; 14 | class PotentialListElement; 15 | class SiteLogic; 16 | 17 | class PotentialTracker : private Core::EventReceiver { 18 | private: 19 | std::list potentiallist; 20 | std::list top; 21 | bool maxpotentialcalculated; 22 | void tick(int); 23 | bool allTopSlotsUsedForSite(PotentialElement *) const; 24 | std::list::iterator findFirstOfSite(const std::shared_ptr &); 25 | void calculateMaxAvailablePotential(); 26 | public: 27 | PotentialTracker(int); 28 | ~PotentialTracker(); 29 | int getMaxAvailablePotential(); 30 | void pushPotential(int, const std::string &, const std::shared_ptr &, int); 31 | void updateSlots(int); 32 | }; 33 | -------------------------------------------------------------------------------- /src/preparedrace.cpp: -------------------------------------------------------------------------------- 1 | #include "preparedrace.h" 2 | 3 | PreparedRace::PreparedRace(unsigned int id, const std::string& name, const std::string& section, const std::list>& sites, bool reset, int ttl) : 4 | id(id), 5 | name(name), 6 | section(section), 7 | sites(sites), 8 | reset(reset), 9 | ttl(ttl) { 10 | 11 | } 12 | 13 | unsigned int PreparedRace::getId() const { 14 | return id; 15 | } 16 | 17 | const std::string& PreparedRace::getName() const { 18 | return name; 19 | } 20 | 21 | const std::string& PreparedRace::getSection() const { 22 | return section; 23 | } 24 | 25 | bool PreparedRace::getReset() const { 26 | return reset; 27 | } 28 | 29 | const std::list>& PreparedRace::getSites() const { 30 | return sites; 31 | } 32 | 33 | int PreparedRace::getRemainingTime() const { 34 | return ttl; 35 | } 36 | 37 | void PreparedRace::tick() { 38 | if (ttl >= 0) { 39 | ttl -= 1; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/preparedrace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class PreparedRace { 8 | public: 9 | PreparedRace(unsigned int id, const std::string& release, const std::string& section, const std::list>& sites, bool reset, int ttl); 10 | unsigned int getId() const; 11 | const std::string& getName() const; 12 | const std::string& getSection() const; 13 | bool getReset() const; 14 | const std::list>& getSites() const; 15 | int getRemainingTime() const; 16 | void tick(); 17 | private: 18 | unsigned int id; 19 | const std::string name; 20 | const std::string section; 21 | const std::list> sites; 22 | bool reset; 23 | int ttl; 24 | }; 25 | -------------------------------------------------------------------------------- /src/proxy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define PROXY_AUTH_NONE 232 6 | #define PROXY_AUTH_USERPASS 233 7 | 8 | enum class ActiveAddressSource { 9 | AUTO_BY_PROXY, 10 | CONNECTED_ADDRESS 11 | }; 12 | 13 | enum class ActivePortsMethod { 14 | AUTO_BY_PROXY, 15 | MANUAL 16 | }; 17 | 18 | class Proxy { 19 | public: 20 | Proxy(); 21 | Proxy(const std::string& name); 22 | std::string getName() const; 23 | std::string getAddr() const; 24 | std::string getPort() const; 25 | int getAuthMethod() const; 26 | std::string getAuthMethodText() const; 27 | std::string getUser() const; 28 | std::string getPass() const; 29 | bool getResolveHosts() const; 30 | ActiveAddressSource getActiveAddressSource() const; 31 | ActivePortsMethod getActivePortsMethod() const; 32 | int getActivePortFirst() const; 33 | int getActivePortLast() const; 34 | int getNextListenPort() const; 35 | void setName(const std::string& name); 36 | void setAddr(const std::string& addr); 37 | void setPort(const std::string& port); 38 | void setAuthMethod(int authmethod); 39 | void setUser(const std::string& user); 40 | void setPass(const std::string& pass); 41 | void setResolveHosts(bool resolvehosts); 42 | void setActiveAddressSource(ActiveAddressSource source); 43 | void setActivePortsMethod(ActivePortsMethod method); 44 | void setActivePortFirst(int port); 45 | void setActivePortLast(int port); 46 | private: 47 | std::string name; 48 | std::string addr; 49 | std::string port; 50 | int authmethod; 51 | std::string user; 52 | std::string pass; 53 | bool resolvehosts; 54 | ActiveAddressSource activeaddresssource; 55 | ActivePortsMethod activeportsmethod; 56 | int activeportfirst; 57 | int activeportlast; 58 | mutable int nextport; 59 | }; 60 | -------------------------------------------------------------------------------- /src/proxymanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Proxy; 7 | 8 | class ProxyManager { 9 | public: 10 | ProxyManager(); 11 | void addProxy(Proxy* proxy); 12 | Proxy* getProxy(const std::string& proxy) const; 13 | void removeProxy(const std::string& proxy); 14 | std::vector::const_iterator begin() const; 15 | std::vector::const_iterator end() const; 16 | bool hasDefaultProxy() const; 17 | bool hasDefaultDataProxy() const; 18 | Proxy* getDefaultProxy() const; 19 | Proxy* getDefaultDataProxy() const; 20 | void setDefaultProxy(const std::string& proxy); 21 | void setDefaultDataProxy(const std::string& proxy); 22 | void sortProxys(); 23 | unsigned int size() const; 24 | private: 25 | std::vector proxies; 26 | Proxy* defaultproxy; 27 | Proxy* defaultdataproxy; 28 | }; 29 | -------------------------------------------------------------------------------- /src/proxysession.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "address.h" 6 | 7 | enum ProxySessionStatus { 8 | PROXYSESSION_INIT, 9 | PROXYSESSION_SEND, 10 | PROXYSESSION_ERROR, 11 | PROXYSESSION_SUCCESS, 12 | PROXYSESSION_SEND_CONNECT, 13 | PROXYSESSION_SEND_LISTEN, 14 | PROXYSESSION_RECV_LISTEN 15 | }; 16 | 17 | enum class AddressMode { 18 | IPV4, 19 | IPV6, 20 | DNS 21 | }; 22 | 23 | class Proxy; 24 | 25 | class ProxySession { 26 | public: 27 | ProxySession(); 28 | void prepareConnect(Proxy* proxy, const Address& addr); 29 | void prepareListen(Proxy* proxy, Core::AddressFamily addrfam); 30 | int instruction() const; 31 | const char * getSendData() const; 32 | int getSendDataLen() const; 33 | void received(char* data, int datalen); 34 | std::string getErrorMessage() const; 35 | Address getListeningAddress() const; 36 | Address getReplyAddress() const; 37 | unsigned int getTryListenPort() const; 38 | private: 39 | void setInitialData(); 40 | void setConnectRequestData(); 41 | void setListenRequestData(); 42 | struct sockaddr_in* saddr; 43 | struct sockaddr_in6* saddr6; 44 | AddressMode addressmode; 45 | char senddata[256]; 46 | int senddatalen; 47 | Proxy * proxy; 48 | int state; 49 | bool listenmode; 50 | std::string errormessage; 51 | Address addr; 52 | Address addrlistening; 53 | Address addrreply; 54 | unsigned int trylistenport; 55 | }; 56 | -------------------------------------------------------------------------------- /src/racestatus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class RaceStatus { 4 | RUNNING, 5 | DONE, 6 | ABORTED, 7 | TIMEOUT 8 | }; 9 | -------------------------------------------------------------------------------- /src/rawbuffercallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class RawBufferCallback { 7 | public: 8 | virtual ~RawBufferCallback() {} 9 | virtual void newRawBufferLine(const std::pair &) = 0; 10 | }; 11 | -------------------------------------------------------------------------------- /src/recursivecommandlogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "path.h" 10 | 11 | class FileList; 12 | 13 | enum RecursiveCommandType { 14 | RCL_DELETE, 15 | RCL_DELETEOWN, 16 | RCL_TRANSFER 17 | }; 18 | 19 | enum RecursiveCommandLogicAction { 20 | RCL_ACTION_LIST, 21 | RCL_ACTION_CWD, 22 | RCL_ACTION_DELETE, 23 | RCL_ACTION_DELDIR, 24 | RCL_ACTION_NOOP, 25 | }; 26 | 27 | class RecursiveCommandLogic { 28 | private: 29 | RecursiveCommandType mode; 30 | bool active; 31 | Path basepath; 32 | Path target; 33 | std::list wantedlists; 34 | std::vector> deletefiles; 35 | bool listtarget; 36 | Path targetpath; 37 | std::string user; 38 | public: 39 | RecursiveCommandLogic(); 40 | ~RecursiveCommandLogic(); 41 | void initialize(RecursiveCommandType, const Path&, const std::string&); 42 | bool isActive() const; 43 | int getAction(const Path &, Path &); 44 | void addFileList(const std::shared_ptr& fl); 45 | void failedCwd(); 46 | }; 47 | -------------------------------------------------------------------------------- /src/refreshgovernor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "loadmonitorcallback.h" 7 | 8 | class Site; 9 | enum class SitePriority; 10 | 11 | class RefreshGovernor : private LoadMonitorCallback { 12 | public: 13 | RefreshGovernor(const std::shared_ptr& site); 14 | ~RefreshGovernor(); 15 | bool refreshAllowed() const; // is it time to perform a refresh? 16 | bool immediateRefreshAllowed() const; 17 | void timePassed(int timepassed); // called continously by the sitelogic ticker 18 | void useRefresh(); // call when a refresh has been "taken" by a connection 19 | void update(); // call when site settings have changed 20 | private: 21 | void recommendedPerformanceLevelChanged(int newlevel) override; 22 | void setDynamicInterval(int newlevel, SitePriority priority); 23 | std::shared_ptr site; 24 | int interval; 25 | int timepassed; 26 | bool immediaterefreshallowed; 27 | }; 28 | -------------------------------------------------------------------------------- /src/requestcallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class RequestCallback { 4 | public: 5 | virtual ~RequestCallback() = default; 6 | virtual void intermediateData(void* service, int requestid, void* data) {} 7 | virtual void requestReady(void* service, int requestid) = 0; 8 | }; 9 | -------------------------------------------------------------------------------- /src/restapicallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class RestApiCallback { 4 | public: 5 | virtual ~RestApiCallback() = default; 6 | virtual void requestHandled(int requestid, const http::Response& response) = 0; 7 | }; 8 | -------------------------------------------------------------------------------- /src/section.cpp: -------------------------------------------------------------------------------- 1 | #include "section.h" 2 | 3 | #include "globalcontext.h" 4 | 5 | Section::Section() : jobs(0), skiplist(global->getSkipList()), hotkey(-1) { 6 | 7 | } 8 | 9 | Section::Section(const std::string & name) : name(name), jobs(0), skiplist(global->getSkipList()), hotkey(-1) { 10 | 11 | } 12 | 13 | std::string Section::getName() const { 14 | return name; 15 | } 16 | 17 | SkipList & Section::getSkipList() { 18 | return skiplist; 19 | } 20 | 21 | const SkipList & Section::getSkipList() const { 22 | return skiplist; 23 | } 24 | 25 | int Section::getNumJobs() const { 26 | return jobs; 27 | } 28 | 29 | void Section::setName(const std::string & newname) { 30 | name = newname; 31 | } 32 | 33 | void Section::setNumJobs(int jobs) { 34 | this->jobs = jobs; 35 | } 36 | 37 | void Section::addJob() { 38 | ++jobs; 39 | } 40 | 41 | int Section::getHotKey() const { 42 | return hotkey; 43 | } 44 | 45 | void Section::setHotKey(int hotkey) { 46 | this->hotkey = hotkey; 47 | } 48 | -------------------------------------------------------------------------------- /src/section.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "skiplist.h" 6 | 7 | class Section { 8 | public: 9 | Section(); 10 | Section(const std::string & name); 11 | std::string getName() const; 12 | SkipList & getSkipList(); 13 | const SkipList & getSkipList() const; 14 | int getNumJobs() const; 15 | void setName(const std::string & newname); 16 | void setNumJobs(int jobs); 17 | void addJob(); 18 | int getHotKey() const; 19 | void setHotKey(int hotkey); 20 | private: 21 | std::string name; 22 | int jobs; 23 | SkipList skiplist; 24 | int hotkey; 25 | }; 26 | -------------------------------------------------------------------------------- /src/sectionmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "section.h" 6 | 7 | class SectionManager { 8 | public: 9 | std::unordered_map::const_iterator begin() const; 10 | std::unordered_map::const_iterator end() const; 11 | std::unordered_map::iterator begin(); 12 | std::unordered_map::iterator end(); 13 | size_t size() const; 14 | Section * getSection(const std::string & name); 15 | Section * getSection(int hotkey); 16 | bool addSection(const std::string & name); 17 | bool addSection(const Section & section); 18 | bool replaceSection(const Section & section, const std::string & oldname); 19 | void removeSection(const std::string & section); 20 | private: 21 | std::unordered_map sections; 22 | }; 23 | -------------------------------------------------------------------------------- /src/sectionutil.cpp: -------------------------------------------------------------------------------- 1 | #include "sectionutil.h" 2 | 3 | #include "path.h" 4 | #include "site.h" 5 | 6 | namespace SectionUtil { 7 | 8 | util::Result useOrSectionTranslate(const Path& path, const std::shared_ptr& site, std::string& section, Path& outpath) { 9 | if (path.isRelative()) { 10 | section = path.level(0).toString(); 11 | if (site->hasSection(section)) { 12 | outpath = site->getSectionPath(section) / path.cutLevels(-1); 13 | } 14 | else { 15 | return util::Result(false, "Path must be absolute or a section name on " + site->getName() + ": " + path.toString()); 16 | } 17 | } 18 | else { 19 | section.clear(); 20 | outpath = path; 21 | } 22 | return true; 23 | } 24 | 25 | util::Result useOrSectionTranslate(const Path& path, const std::shared_ptr& site, Path& outpath) { 26 | std::string section; 27 | return useOrSectionTranslate(path, site, section, outpath); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/sectionutil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "util.h" 7 | 8 | class Path; 9 | class Site; 10 | 11 | namespace SectionUtil { 12 | 13 | util::Result useOrSectionTranslate(const Path& path, const std::shared_ptr& site, std::string& section, Path& outpath); 14 | util::Result useOrSectionTranslate(const Path& path, const std::shared_ptr& site, Path& outpath); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/settingsloadersaver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "core/eventreceiver.h" 8 | 9 | #include "datafilehandler.h" 10 | 11 | class SkipList; 12 | 13 | class SettingsAdder { 14 | public: 15 | virtual ~SettingsAdder() { 16 | } 17 | virtual void loadSettings(std::shared_ptr) = 0; 18 | virtual void saveSettings(std::shared_ptr) = 0; 19 | }; 20 | 21 | class SettingsLoaderSaver : public Core::EventReceiver { 22 | public: 23 | SettingsLoaderSaver(); 24 | DataFileState getState() const; 25 | bool tryDecrypt(const std::string& key); 26 | void init(); 27 | void saveSettings(); 28 | bool changeKey(const std::string& key, const std::string& newkey); 29 | bool setEncrypted(const std::string& key); 30 | bool setPlain(const std::string& key); 31 | void tick(int); 32 | void addSettingsAdder(SettingsAdder *); 33 | void removeSettingsAdder(SettingsAdder *); 34 | static void addSkipList(const std::shared_ptr& dfh, const SkipList* skiplist, const std::string& owner, const std::string&); 35 | static void loadSkipListEntry(SkipList* skiplist, std::string value); 36 | private: 37 | void loadSettings(); 38 | void startAutoSaver(); 39 | std::shared_ptr dfh; 40 | std::list settingsadders; 41 | bool loaded; 42 | }; 43 | -------------------------------------------------------------------------------- /src/sitelogicmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "sitelogicmanager.h" 2 | 3 | #include "sitelogic.h" 4 | #include "site.h" 5 | #include "globalcontext.h" 6 | #include "sitemanager.h" 7 | 8 | SiteLogicManager::SiteLogicManager() { 9 | } 10 | 11 | const std::shared_ptr SiteLogicManager::getSiteLogic(const std::string & name) { 12 | std::vector >::iterator it; 13 | for(it = sitelogics.begin(); it != sitelogics.end(); it++) { 14 | if ((*it)->getSite()->getName().compare(name) == 0) return *it; 15 | } 16 | if (!global->getSiteManager()->getSite(name)) { 17 | return std::shared_ptr(); 18 | } 19 | std::shared_ptr x = std::make_shared(name); 20 | sitelogics.push_back(x); 21 | return x; 22 | } 23 | 24 | const std::shared_ptr SiteLogicManager::getSiteLogic(SiteLogic * sl) { 25 | std::vector >::iterator it; 26 | for(it = sitelogics.begin(); it != sitelogics.end(); it++) { 27 | if ((*it).get() == sl) return *it; 28 | } 29 | return std::shared_ptr(); 30 | } 31 | 32 | void SiteLogicManager::deleteSiteLogic(const std::string & name) { 33 | std::vector >::iterator it; 34 | for(it = sitelogics.begin(); it != sitelogics.end(); it++) { 35 | if ((*it)->getSite()->getName().compare(name) == 0) { 36 | sitelogics.erase(it); 37 | return; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/sitelogicmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class SiteLogic; 8 | 9 | class SiteLogicManager { 10 | private: 11 | std::vector > sitelogics; 12 | public: 13 | SiteLogicManager(); 14 | const std::shared_ptr getSiteLogic(const std::string &); 15 | const std::shared_ptr getSiteLogic(SiteLogic *); 16 | void deleteSiteLogic(const std::string &); 17 | }; 18 | -------------------------------------------------------------------------------- /src/sitelogicrequest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class RequestCallback; 6 | 7 | class SiteLogicRequest { 8 | private: 9 | int requestid; 10 | int connid; 11 | int requesttype; 12 | std::string data; 13 | std::string data2; 14 | int numdata; 15 | RequestCallback* cb; 16 | void* ptrdata; 17 | public: 18 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, void* ptrdata); 19 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, int numdata); 20 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, const std::string& data); 21 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, const std::string& data, int numdata); 22 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, const std::string& data, const std::string& data2); 23 | SiteLogicRequest(RequestCallback* cb, int requestid, int requesttype, const std::string& data, const std::string& data2, int numdata); 24 | int getId() const; 25 | int getType() const; 26 | std::string getData() const; 27 | std::string getData2() const; 28 | int getNumData() const; 29 | void setConnId(int); 30 | int getConnId() const; 31 | RequestCallback* getCallback() const; 32 | void* getPtrData() const; 33 | }; 34 | -------------------------------------------------------------------------------- /src/sitelogicrequestready.cpp: -------------------------------------------------------------------------------- 1 | #include "sitelogicrequestready.h" 2 | 3 | SiteLogicRequestReady::SiteLogicRequestReady(int type, int requestid, void * data, bool status) : 4 | type(type), 5 | requestid(requestid), 6 | data(data), 7 | status(status) { 8 | } 9 | 10 | int SiteLogicRequestReady::getType() const { 11 | return type; 12 | } 13 | 14 | int SiteLogicRequestReady::getId() const { 15 | return requestid; 16 | } 17 | 18 | void * SiteLogicRequestReady::getData() const { 19 | return data; 20 | } 21 | 22 | bool SiteLogicRequestReady::getStatus() const { 23 | return status; 24 | } 25 | -------------------------------------------------------------------------------- /src/sitelogicrequestready.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class SiteLogicRequestReady { 4 | private: 5 | int type; 6 | int requestid; 7 | void * data; 8 | bool status; 9 | public: 10 | SiteLogicRequestReady(int, int, void *, bool); 11 | int getType() const; 12 | int getId() const; 13 | void * getData() const; 14 | bool getStatus() const; 15 | }; 16 | -------------------------------------------------------------------------------- /src/sitetransferjob.cpp: -------------------------------------------------------------------------------- 1 | #include "sitetransferjob.h" 2 | 3 | #include "filelist.h" 4 | #include "transferjob.h" 5 | 6 | SiteTransferJob::SiteTransferJob(const std::shared_ptr& tj, bool source) : transferjob(tj), source(source) { 7 | 8 | } 9 | 10 | std::weak_ptr SiteTransferJob::getTransferJob() { 11 | return transferjob; 12 | } 13 | 14 | std::shared_ptr SiteTransferJob::getOtherSiteLogic() const { 15 | return source ? transferjob.lock()->getDst() : transferjob.lock()->getSrc(); 16 | } 17 | 18 | bool SiteTransferJob::wantsList() { 19 | return transferjob.lock()->wantsList(source); 20 | } 21 | 22 | bool SiteTransferJob::otherWantsList() { 23 | return transferjob.lock()->getSrc() != transferjob.lock()->getDst() && transferjob.lock()->wantsList(!source); 24 | } 25 | 26 | bool SiteTransferJob::isDone() const { 27 | std::shared_ptr tj = transferjob.lock(); 28 | return !tj || tj->isDone(); 29 | } 30 | 31 | Path SiteTransferJob::getPath() const { 32 | return transferjob.lock()->getPath(source); 33 | } 34 | 35 | std::shared_ptr SiteTransferJob::getListTarget() { 36 | return transferjob.lock()->getListTarget(source); 37 | } 38 | int SiteTransferJob::classType() const { 39 | return COMMANDOWNER_TRANSFERJOB; 40 | } 41 | 42 | std::string SiteTransferJob::getName() const { 43 | return transferjob.lock()->getName(); 44 | } 45 | 46 | unsigned int SiteTransferJob::getId() const { 47 | return transferjob.lock()->getId(); 48 | } 49 | void SiteTransferJob::fileListUpdated(SiteLogic * sl, const std::shared_ptr& fl) { 50 | std::shared_ptr tj = transferjob.lock(); 51 | if (tj) { 52 | tj->fileListUpdated(source, fl); 53 | } 54 | } 55 | 56 | std::shared_ptr SiteTransferJob::getFileListForFullPath(SiteLogic* sl, const Path& path) const { 57 | return transferjob.lock()->getFileListForFullPath(source, path); 58 | } 59 | -------------------------------------------------------------------------------- /src/sitetransferjob.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "commandowner.h" 7 | 8 | class FileList; 9 | class SiteLogic; 10 | class TransferJob; 11 | 12 | class SiteTransferJob : public CommandOwner { 13 | public: 14 | SiteTransferJob(const std::shared_ptr& tj, bool source); 15 | std::weak_ptr getTransferJob(); 16 | std::shared_ptr getOtherSiteLogic() const; 17 | bool wantsList(); 18 | bool otherWantsList(); 19 | bool isDone() const; 20 | Path getPath() const; 21 | std::shared_ptr getListTarget(); 22 | int classType() const override; 23 | std::string getName() const override; 24 | unsigned int getId() const override; 25 | void fileListUpdated(SiteLogic* sl, const std::shared_ptr& fl) override; 26 | std::shared_ptr getFileListForFullPath(SiteLogic* sl, const Path& path) const override; 27 | private: 28 | std::weak_ptr transferjob; 29 | bool source; 30 | }; 31 | -------------------------------------------------------------------------------- /src/sizelocationtrack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class SiteRace; 7 | 8 | class SizeLocationTrack { 9 | private: 10 | std::map, unsigned long long int> sitesizes; 11 | unsigned long long int estimatedsize; 12 | void recalculate(); 13 | public: 14 | SizeLocationTrack(); 15 | unsigned long long int getEstimatedSize() const; 16 | int numSites() const; 17 | bool add(const std::shared_ptr& site, unsigned long long int); 18 | void remove(const std::shared_ptr& site); 19 | }; 20 | -------------------------------------------------------------------------------- /src/skiplist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "skiplistitem.h" 9 | 10 | class Site; 11 | 12 | struct SkipListMatch { 13 | SkipListMatch(SkipListAction action, bool matched, const std::string& matchpattern, const std::string& matchedpath); 14 | SkipListMatch(SkipListAction action, bool matched, const std::string& matchpattern, const std::regex& matchregexpattern, const std::string& matchedpath); 15 | SkipListAction action; 16 | bool matched; 17 | bool regex; 18 | std::string matchpattern; 19 | std::regex matchregexpattern; 20 | std::string matchedpath; 21 | }; 22 | 23 | class SkipList { 24 | private: 25 | std::list entries; 26 | mutable std::unordered_map matchcache; 27 | const SkipList * globalskip; 28 | void addDefaultEntries(); 29 | SkipListMatch fallThrough(const std::string & element, const bool dir, const bool inrace, const SkipList * fallthrough) const; 30 | public: 31 | SkipList(bool adddefault = true); 32 | SkipList(const SkipList *); 33 | void addEntry(bool regex, const std::string & pattern, bool file, bool dir, int scope, SkipListAction action); 34 | void clearEntries(); 35 | std::list::const_iterator entriesBegin() const; 36 | std::list::const_iterator entriesEnd() const; 37 | SkipListMatch check(const std::string & element, const bool dir, const bool inrace = true, const SkipList * fallthrough = nullptr) const; 38 | unsigned int size() const; 39 | void wipeCache(); 40 | void setGlobalSkip(SkipList *); 41 | }; 42 | -------------------------------------------------------------------------------- /src/skiplistitem.cpp: -------------------------------------------------------------------------------- 1 | #include "skiplistitem.h" 2 | 3 | #include "util.h" 4 | 5 | SkiplistItem::SkiplistItem(bool regex, const std::string & pattern, bool file, bool dir, int scope, SkipListAction action) : 6 | regex(regex), pattern(pattern), file(file), dir(dir), scope(scope), action(action) 7 | { 8 | if (regex) { 9 | regexpattern = util::regexParse(pattern); 10 | } 11 | } 12 | 13 | bool SkiplistItem::matchRegex() const { 14 | return regex; 15 | } 16 | 17 | const std::regex & SkiplistItem::matchRegexPattern() const { 18 | return regexpattern; 19 | } 20 | 21 | const std::string & SkiplistItem::matchPattern() const { 22 | return pattern; 23 | } 24 | 25 | bool SkiplistItem::matchFile() const { 26 | return file; 27 | } 28 | 29 | bool SkiplistItem::matchDir() const { 30 | return dir; 31 | } 32 | 33 | SkipListAction SkiplistItem::getAction() const { 34 | return action; 35 | } 36 | 37 | int SkiplistItem::matchScope() const { 38 | return scope; 39 | } 40 | -------------------------------------------------------------------------------- /src/skiplistitem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | enum Scope { 7 | SCOPE_IN_RACE = 0, 8 | SCOPE_ALL = 1 9 | }; 10 | 11 | enum SkipListAction { 12 | SKIPLIST_ALLOW, 13 | SKIPLIST_DENY, 14 | SKIPLIST_UNIQUE, 15 | SKIPLIST_SIMILAR, 16 | SKIPLIST_NONE 17 | }; 18 | 19 | class SkiplistItem { 20 | public: 21 | SkiplistItem(bool regex, const std::string & pattern, bool file, bool dir, int scope, SkipListAction action); 22 | bool matchRegex() const; 23 | const std::string & matchPattern() const; 24 | const std::regex & matchRegexPattern() const; 25 | bool matchFile() const; 26 | bool matchDir() const; 27 | SkipListAction getAction() const; 28 | int matchScope() const; 29 | private: 30 | bool regex; 31 | std::string pattern; 32 | std::regex regexpattern; 33 | bool file; 34 | bool dir; 35 | int scope; 36 | SkipListAction action; 37 | }; 38 | -------------------------------------------------------------------------------- /src/statistics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "hourlyalltracking.h" 6 | #include "core/eventreceiver.h" 7 | 8 | enum StatsDirection { 9 | STATS_UP, 10 | STATS_DOWN, 11 | STATS_FXP 12 | }; 13 | 14 | class Statistics : public Core::EventReceiver { 15 | public: 16 | Statistics(); 17 | ~Statistics(); 18 | void tick(int message) override; 19 | void addTransferStatsFile(StatsDirection, unsigned long long int size); 20 | void addSpreadJob(); 21 | void addTransferJob(); 22 | void addFileListRefresh(); 23 | const HourlyAllTracking& getSizeDown() const; 24 | const HourlyAllTracking& getSizeUp() const; 25 | const HourlyAllTracking& getSizeFXP() const; 26 | const HourlyAllTracking& getFilesDown() const; 27 | const HourlyAllTracking& getFilesUp() const; 28 | const HourlyAllTracking& getFilesFXP() const; 29 | HourlyAllTracking& getSizeDown(); 30 | HourlyAllTracking& getSizeUp(); 31 | HourlyAllTracking& getSizeFXP(); 32 | HourlyAllTracking& getFilesDown(); 33 | HourlyAllTracking& getFilesUp(); 34 | HourlyAllTracking& getFilesFXP(); 35 | unsigned int getSpreadJobs() const; 36 | unsigned int getTransferJobs() const; 37 | unsigned int getFileListRefreshRate() const; 38 | void setSpreadJobs(unsigned int); 39 | void setTransferJobs(unsigned int); 40 | void resetHourlyStats(); 41 | void resetAllStats(); 42 | private: 43 | HourlyAllTracking sizedown; 44 | HourlyAllTracking filesdown; 45 | HourlyAllTracking sizeup; 46 | HourlyAllTracking filesup; 47 | HourlyAllTracking sizefxp; 48 | HourlyAllTracking filesfxp; 49 | unsigned int spreadjobs; 50 | unsigned int transferjobs; 51 | unsigned int currentsecondrefreshtrack; 52 | unsigned int lastsecondrefreshtrack; 53 | }; 54 | -------------------------------------------------------------------------------- /src/subprocessmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "core/eventreceiver.h" 10 | #include "core/datablockpool.h" 11 | 12 | class Path; 13 | class RawBuffer; 14 | 15 | class SubProcessCallback { 16 | public: 17 | virtual ~SubProcessCallback() { 18 | } 19 | virtual void processExited(int pid, int status); 20 | virtual void processStdOut(int pid, const std::string& text); 21 | virtual void processStdErr(int pid, const std::string& text); 22 | }; 23 | 24 | struct SubProcess { 25 | int pid; 26 | std::shared_ptr rawbuf; 27 | SubProcessCallback* cb; 28 | int stdinfd; 29 | int stdoutfd; 30 | int stderrfd; 31 | int stdinhandle; 32 | int stdouthandle; 33 | int stderrhandle; 34 | 35 | }; 36 | 37 | class SubProcessManager : public Core::EventReceiver { 38 | public: 39 | SubProcessManager(); 40 | std::shared_ptr runProcess(SubProcessCallback* cb, const Path& path, const std::vector& args); 41 | void killProcess(int pid); 42 | void killAll(); 43 | bool getIsRunning(int pid) const; 44 | void signal(int signal, int) override; 45 | private: 46 | void FDData(int sockid) override; 47 | std::list> subprocesses; 48 | Core::DataBlockPool blockpool; 49 | }; 50 | -------------------------------------------------------------------------------- /src/timereference.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/eventreceiver.h" 4 | 5 | class TimeReference : public Core::EventReceiver { 6 | public: 7 | TimeReference(); 8 | void tick(int); 9 | unsigned long long timeReference() const; 10 | unsigned long long timePassedSince(unsigned long long) const; 11 | std::string getCurrentLogTimeStamp() const; 12 | bool getLogTimeStampMilliseconds() const; 13 | void setLogTimeStampMilliseconds(bool ms); 14 | private: 15 | unsigned long long timeticker; 16 | bool logtimestampms; 17 | 18 | public: 19 | static void updateTime(); 20 | static int currentYear(); 21 | static int currentMonth(); 22 | static int currentDay(); 23 | }; 24 | -------------------------------------------------------------------------------- /src/tools/datafilecat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "datafiletoolfuncs.h" 7 | #include "../crypto.h" 8 | #include "../datafilehandlermethod.h" 9 | #include "../filesystem.h" 10 | #include "../path.h" 11 | 12 | int usage() { 13 | std::cerr << "datafilecat: decrypts the content of a cbftp data file.\n\n" 14 | << "Usage: datafilecat [--infile=] [--outfile=]" 15 | << std::endl; 16 | return 0; 17 | } 18 | 19 | int main(int argc, char ** argv) { 20 | Path path = DataFileHandlerMethod::getDataFile(); 21 | bool useoutfile = false; 22 | std::string outfile; 23 | for (int i = 1; i < argc; i++) { 24 | if (!strncmp(argv[i], "--infile=", 9)) { 25 | path = argv[i] + 9; 26 | } 27 | else if (!strncmp(argv[i], "--outfile=", 10)) { 28 | useoutfile = true; 29 | outfile = argv[i] + 10; 30 | } 31 | else { 32 | return usage(); 33 | } 34 | } 35 | 36 | 37 | if (!checkInputFile(path)) return -1; 38 | std::cerr << "Using data file: " << path.toString() << std::endl; 39 | 40 | 41 | Core::BinaryData rawdata; 42 | FileSystem::readFile(path, rawdata); 43 | 44 | Core::BinaryData decryptedtext; 45 | 46 | if (!Crypto::isMostlyASCII(rawdata)) { 47 | Core::BinaryData key = getPassphrase(); 48 | if (!DataFileHandlerMethod::decrypt(rawdata, key, decryptedtext)) { 49 | std::cerr << "Error: Either the passphrase is wrong, or the input file is" 50 | << " not a valid cbftp data file." 51 | << std::endl; 52 | return -1; 53 | } 54 | } 55 | else { 56 | decryptedtext = rawdata; 57 | } 58 | 59 | if (useoutfile) { 60 | FileSystem::writeFile(outfile, decryptedtext); 61 | } 62 | else { 63 | std::cout << std::string((const char *)&decryptedtext[0], 64 | decryptedtext.size()); 65 | std::cerr << std::endl; 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /src/tools/datafiletoolfuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../core/types.h" 9 | #include "../filesystem.h" 10 | 11 | void showInput(bool show) { 12 | termios tty; 13 | tcgetattr(STDIN_FILENO, &tty); 14 | if (show) { 15 | tty.c_lflag |= ECHO; 16 | } 17 | else { 18 | tty.c_lflag &= ~ECHO; 19 | } 20 | tcsetattr(STDIN_FILENO, TCSANOW, &tty); 21 | } 22 | 23 | Core::BinaryData getPassphrase() { 24 | std::cerr << "Passphrase: "; 25 | showInput(false); 26 | std::string passphrase; 27 | std::getline(std::cin, passphrase); 28 | std::cerr << std::endl; 29 | showInput(true); 30 | return Core::BinaryData(passphrase.begin(), passphrase.end()); 31 | } 32 | 33 | bool checkInputFile(const Path & path) { 34 | if (!FileSystem::fileExists(path)) { 35 | std::cerr << "Error: The input file does not exist." << std::endl; 36 | return false; 37 | } 38 | if (!FileSystem::fileExistsReadable(path)) { 39 | std::cerr << "Error: Could not read the input file." << std::endl; 40 | return false; 41 | } 42 | return true; 43 | } 44 | -------------------------------------------------------------------------------- /src/tools/datafilewrite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "datafiletoolfuncs.h" 7 | #include "../datafilehandlermethod.h" 8 | #include "../filesystem.h" 9 | #include "../path.h" 10 | 11 | int usage() { 12 | std::cerr << "datafilewrite: encrypts the content of a cbftp plain text " 13 | << "data file.\n\n" 14 | << "Usage: datafilewrite <--outfile= OR --defaultoutfile>" 15 | << std::endl; 16 | return 0; 17 | } 18 | 19 | int main(int argc, char ** argv) { 20 | if (argc != 3) { 21 | return usage(); 22 | } 23 | const std::string path = argv[1]; 24 | Path outpath = DataFileHandlerMethod::getDataFile(); 25 | bool outfileset = false; 26 | std::string outfile; 27 | for (int i = 2; i < argc; i++) { 28 | if (!strncmp(argv[i], "--outfile=", 10)) { 29 | outfileset = true; 30 | outpath = argv[i] + 10; 31 | } 32 | else if (!strcmp(argv[i], "--defaultoutfile")) { 33 | outfileset = true; 34 | } 35 | else { 36 | return usage(); 37 | } 38 | } 39 | if (!outfileset) { 40 | return usage(); 41 | } 42 | 43 | if (!checkInputFile(path)) return -1; 44 | std::cerr << "Using data file: " << outpath.toString() << std::endl; 45 | Core::BinaryData key = getPassphrase(); 46 | 47 | Core::BinaryData rawdata; 48 | FileSystem::readFile(path, rawdata); 49 | 50 | Core::BinaryData ciphertext; 51 | if (!DataFileHandlerMethod::encrypt(rawdata, key, ciphertext)) { 52 | std::cerr << "Error: The input file is not a valid cbftp data file." 53 | << std::endl; 54 | return -1; 55 | } 56 | 57 | FileSystem::writeFile(outpath, ciphertext); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /src/transferpairing.cpp: -------------------------------------------------------------------------------- 1 | #include "transferpairing.h" 2 | 3 | std::list::const_iterator TransferPairing::begin() const { 4 | return entries.begin(); 5 | } 6 | 7 | std::list::const_iterator TransferPairing::end() const { 8 | return entries.end(); 9 | } 10 | 11 | std::list TransferPairing::check(int slots, PairingJobType type, 12 | const std::string& targetsite, const std::string& jobname, 13 | const std::string& section) const 14 | { 15 | std::list usedslots; 16 | return usedslots; 17 | } 18 | 19 | void TransferPairing::add(bool allsites, const std::list& targetsites, 20 | PairingJobType type, const std::string& jobnamepattern, bool allsections, 21 | const std::list& sections, PairingAction action, int slots) 22 | { 23 | entries.emplace_back(allsites, targetsites, type, jobnamepattern, 24 | allsections, sections, action, slots); 25 | } 26 | 27 | void TransferPairing::clear() { 28 | entries.clear(); 29 | } 30 | 31 | bool TransferPairing::empty() const { 32 | return entries.empty(); 33 | } 34 | -------------------------------------------------------------------------------- /src/transferpairing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "transferpairingitem.h" 7 | 8 | class TransferPairing { 9 | public: 10 | std::list::const_iterator begin() const; 11 | std::list::const_iterator end() const; 12 | 13 | std::list check(int slots, PairingJobType type, 14 | const std::string& targetsite, const std::string& jobname, 15 | const std::string& section) const; 16 | void add(bool allsites, const std::list& targetsites, 17 | PairingJobType type, const std::string& jobnamepattern, bool allsections, 18 | const std::list& sections, PairingAction action, int slots); 19 | void clear(); 20 | bool empty() const; 21 | private: 22 | std::list entries; 23 | }; 24 | -------------------------------------------------------------------------------- /src/transferpairingitem.cpp: -------------------------------------------------------------------------------- 1 | #include "transferpairingitem.h" 2 | 3 | TransferPairingItem::TransferPairingItem(bool allsites, 4 | const std::list& targetsites, PairingJobType type, 5 | const std::string& jobnamepattern, bool allsections, 6 | const std::list& sections, PairingAction action, int slots) : 7 | allsites(allsites), targetsites(targetsites), type(type), 8 | jobnamepattern(jobnamepattern), allsections(allsections), sections(sections), 9 | action(action), slots(slots) 10 | { 11 | 12 | } 13 | 14 | bool TransferPairingItem::getAllSites() const { 15 | return allsites; 16 | } 17 | 18 | PairingJobType TransferPairingItem::getJobType() const { 19 | return type; 20 | } 21 | 22 | std::string TransferPairingItem::getJobNamePattern() const { 23 | return jobnamepattern; 24 | } 25 | 26 | bool TransferPairingItem::getAllSections() const { 27 | return allsections; 28 | } 29 | 30 | PairingAction TransferPairingItem::getPairingAction() const { 31 | return action; 32 | } 33 | 34 | int TransferPairingItem::getSlots() const { 35 | return slots; 36 | } 37 | -------------------------------------------------------------------------------- /src/transferpairingitem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | enum class PairingJobType { 7 | RACE, 8 | DISTRIBUTE, 9 | DLONLY, 10 | ALL 11 | }; 12 | 13 | enum class PairingAction { 14 | ALLOW, 15 | PREFER, 16 | SOFTLOCK, 17 | HARDLOCK, 18 | BLOCK 19 | }; 20 | 21 | 22 | class TransferPairingItem { 23 | public: 24 | TransferPairingItem(bool allsites, const std::list& targetsites, 25 | PairingJobType type, const std::string& jobnamepattern, bool allsections, 26 | const std::list& sections, PairingAction action, int slots); 27 | bool getAllSites() const; 28 | PairingJobType getJobType() const; 29 | std::string getJobNamePattern() const; 30 | bool getAllSections() const; 31 | PairingAction getPairingAction() const; 32 | int getSlots() const; 33 | private: 34 | bool allsites; 35 | std::list targetsites; 36 | PairingJobType type; 37 | std::string jobnamepattern; 38 | bool allsections; 39 | std::list sections; 40 | PairingAction action; 41 | int slots; 42 | }; 43 | -------------------------------------------------------------------------------- /src/transferprotocol.cpp: -------------------------------------------------------------------------------- 1 | #include "transferprotocol.h" 2 | 3 | bool transferProtocolCombinationPossible(TransferProtocol sprot, TransferProtocol dprot) { 4 | return !((sprot == TransferProtocol::IPV4_ONLY && dprot == TransferProtocol::IPV6_ONLY) || 5 | (sprot == TransferProtocol::IPV6_ONLY && dprot == TransferProtocol::IPV4_ONLY)); 6 | } 7 | 8 | bool useIPv6(TransferProtocol sprot, TransferProtocol dprot) { 9 | return ((sprot != TransferProtocol::IPV4_ONLY && dprot != TransferProtocol::IPV4_ONLY) && 10 | !(sprot == TransferProtocol::PREFER_IPV4 && dprot == TransferProtocol::PREFER_IPV4)); 11 | } 12 | -------------------------------------------------------------------------------- /src/transferprotocol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class TransferProtocol { 4 | IPV4_ONLY = 0, 5 | PREFER_IPV4 = 1, 6 | PREFER_IPV6 = 2, 7 | IPV6_ONLY = 3 8 | }; 9 | 10 | bool transferProtocolCombinationPossible(TransferProtocol sprot, TransferProtocol dprot); 11 | bool useIPv6(TransferProtocol sprot, TransferProtocol dprot); 12 | -------------------------------------------------------------------------------- /src/transferstatuscallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class TransferStatus; 6 | 7 | enum class CallbackType { 8 | RACE, 9 | TRANSFERJOB 10 | }; 11 | 12 | class TransferStatusCallback { 13 | public: 14 | virtual ~TransferStatusCallback() {} 15 | virtual void transferFailed(const std::shared_ptr &, int) = 0; 16 | virtual void transferSuccessful(const std::shared_ptr &) = 0; 17 | virtual CallbackType callbackType() const = 0; 18 | }; 19 | -------------------------------------------------------------------------------- /src/ui/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.inc 2 | 3 | SRC = $(wildcard *.cpp) 4 | SCREENS_SRC = $(wildcard screens/*.cpp) 5 | LIB = libui.a 6 | CLEANFILES = $(wildcard $(SRC:%.cpp=%.o) $(SRC:%.cpp=%.d) $(LIB)) 7 | 8 | all: $(SRC:%.cpp=%.o) screens 9 | @+$(MAKE) --no-print-directory $(LIB) 10 | 11 | .PHONY: screens 12 | screens: 13 | @+$(MAKE) -C $@ 14 | 15 | quiet: 16 | @# 17 | 18 | $(LIB): $(SRC:%.cpp=%.o) $(SCREENS_SRC:%.cpp=%.o) | quiet 19 | ar rc $@ $^ && ranlib $@ 20 | 21 | clean: 22 | @if test $(firstword $(CLEANFILES)); then rm -rf $(CLEANFILES); echo rm -rf $(CLEANFILES); fi 23 | @+$(MAKE) -C screens $@ 24 | 25 | %.o: %.cpp ../../Makefile.inc 26 | ifneq ($(DEBIAN),) 27 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< -DDEBIAN 28 | else 29 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< 30 | endif 31 | 32 | -include $(SRC:%.cpp=%.d) 33 | -------------------------------------------------------------------------------- /src/ui/chardraw.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define CHARDRAW_SIZE 6 8 | 9 | // legend: 10 | // top-left corner outside: A 11 | // top-left corner inside: a 12 | // top-right corner outside: B 13 | // top-right corner inside: b 14 | // bottom-left corner outside: C 15 | // bottom-left corner inside: c 16 | // bottom-right corner outside: D 17 | // bottom-right corner inside: d 18 | // horizontal line top: H 19 | // horizontal line bottom: h 20 | // vertical line left: V 21 | // vertical line right: v 22 | // blank: x 23 | 24 | class CharDraw { 25 | private: 26 | static void push(char, std::string, std::string, std::string, std::string, std::string, std::string); 27 | static std::map > charmap; 28 | public: 29 | static void init(); 30 | static std::string getCharLine(char, unsigned int); 31 | static int getMixedChar(int, int); 32 | }; 33 | -------------------------------------------------------------------------------- /src/ui/commandhistory.cpp: -------------------------------------------------------------------------------- 1 | #include "commandhistory.h" 2 | 3 | CommandHistory::CommandHistory() : pos(history.end()) { 4 | 5 | } 6 | 7 | bool CommandHistory::canBack() const { 8 | return pos != history.begin(); 9 | } 10 | 11 | void CommandHistory::back() { 12 | pos--; 13 | } 14 | 15 | bool CommandHistory::forward() { 16 | if (pos != history.end()) { 17 | pos++; 18 | return true; 19 | } 20 | return false; 21 | } 22 | 23 | bool CommandHistory::current() const { 24 | return pos == history.end(); 25 | } 26 | 27 | void CommandHistory::push(std::string text) { 28 | if (!history.size() || text != history.back()) { 29 | history.push_back(text); 30 | } 31 | pos = history.end(); 32 | } 33 | 34 | std::string CommandHistory::get() const { 35 | if (pos == history.end()) { 36 | return currenttext; 37 | } 38 | return *pos; 39 | } 40 | 41 | void CommandHistory::setCurrent(std::string text) { 42 | currenttext = text; 43 | } 44 | -------------------------------------------------------------------------------- /src/ui/commandhistory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class CommandHistory { 7 | public: 8 | CommandHistory(); 9 | bool canBack() const; 10 | void back(); 11 | bool forward(); 12 | bool current() const; 13 | void push(std::string); 14 | std::string get() const; 15 | void setCurrent(std::string); 16 | private: 17 | std::list history; 18 | std::string currenttext; 19 | std::list::iterator pos; 20 | }; 21 | -------------------------------------------------------------------------------- /src/ui/externalfileviewing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../subprocessmanager.h" 7 | 8 | class Path; 9 | 10 | class ExternalFileViewing : public SubProcessCallback { 11 | public: 12 | ExternalFileViewing(); 13 | bool isViewable(const Path &) const; 14 | int view(const Path &); 15 | int viewThenDelete(const Path &); 16 | void killViewer(int pid); 17 | bool hasDisplay() const; 18 | bool stillViewing(int) const; 19 | std::string getVideoViewer() const; 20 | std::string getAudioViewer() const; 21 | std::string getImageViewer() const; 22 | std::string getPDFViewer() const; 23 | void setVideoViewer(const std::string &); 24 | void setAudioViewer(const std::string &); 25 | void setImageViewer(const std::string &); 26 | void setPDFViewer(const std::string &); 27 | std::string getViewApplication(const Path &) const; 28 | private: 29 | int view(const Path &, bool); 30 | void checkDeleteFile(int); 31 | void processExited(int pid, int status) override; 32 | std::map files; 33 | std::string videoviewer; 34 | std::string audioviewer; 35 | std::string imageviewer; 36 | std::string pdfviewer; 37 | bool display; 38 | }; 39 | -------------------------------------------------------------------------------- /src/ui/focusablearea.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MenuSelectOptionElement; 6 | 7 | class FocusableArea { 8 | protected: 9 | bool focus; 10 | bool leaveup; 11 | bool leavedown; 12 | bool leaveright; 13 | bool leaveleft; 14 | public: 15 | FocusableArea(); 16 | virtual ~FocusableArea(); 17 | virtual bool goUp(); 18 | virtual bool goDown(); 19 | virtual bool goLeft(); 20 | virtual bool goRight(); 21 | virtual bool goNext(); 22 | virtual bool goPrevious(); 23 | virtual void enterFocusFrom(int); 24 | virtual void defocus(); 25 | bool isFocused() const; 26 | void makeLeavableUp(bool); 27 | void makeLeavableDown(bool); 28 | void makeLeavableLeft(bool); 29 | void makeLeavableRight(bool); 30 | void makeLeavableUp(); 31 | void makeLeavableDown(); 32 | void makeLeavableLeft(); 33 | void makeLeavableRight(); 34 | virtual bool activateSelected(); 35 | virtual unsigned int getLastSelectionPointer() const; 36 | virtual unsigned int getSelectionPointer() const = 0; 37 | virtual std::shared_ptr getElement(unsigned int) const; 38 | }; 39 | -------------------------------------------------------------------------------- /src/ui/infowindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fmtstring.h" 4 | 5 | #include "uiwindow.h" 6 | 7 | class InfoWindow : public UIWindow { 8 | public: 9 | InfoWindow(Ui* ui, unsigned int row, unsigned int col); 10 | void redraw(); 11 | void update(); 12 | void setLabel(const FmtString& label); 13 | void setText(const FmtString& text); 14 | void setSplit(bool split); 15 | private: 16 | FmtString label; 17 | FmtString text; 18 | bool split; 19 | }; 20 | -------------------------------------------------------------------------------- /src/ui/legendprinter.cpp: -------------------------------------------------------------------------------- 1 | #include "legendprinter.h" 2 | 3 | LegendPrinter::~LegendPrinter() { 4 | 5 | } 6 | 7 | void LegendPrinter::setColumns(unsigned int col) { 8 | this->col = col; 9 | } 10 | -------------------------------------------------------------------------------- /src/ui/legendprinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class LegendPrinter { 4 | public: 5 | virtual ~LegendPrinter(); 6 | virtual bool print() = 0; 7 | void setColumns(unsigned int col); 8 | protected: 9 | unsigned int col; 10 | }; 11 | -------------------------------------------------------------------------------- /src/ui/legendprinterkeybinds.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "legendprinter.h" 6 | 7 | class Ui; 8 | 9 | class LegendPrinterKeybinds : public LegendPrinter { 10 | public: 11 | LegendPrinterKeybinds(Ui* ui); 12 | bool print(); 13 | void setText(const std::string& text); 14 | private: 15 | Ui* ui; 16 | std::string text; 17 | unsigned int offset; 18 | int staticcount; 19 | }; 20 | -------------------------------------------------------------------------------- /src/ui/legendprinterspreadjob.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "legendprinter.h" 7 | #include "menuselectoption.h" 8 | 9 | class Race; 10 | class Ui; 11 | 12 | class LegendPrinterSpreadJob : public LegendPrinter { 13 | public: 14 | LegendPrinterSpreadJob(Ui* ui, unsigned int id); 15 | bool print(); 16 | private: 17 | Ui* ui; 18 | std::shared_ptr race; 19 | MenuSelectOption mso; 20 | int jobfinishedprintcount; 21 | }; 22 | -------------------------------------------------------------------------------- /src/ui/legendprintertransferjob.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "legendprinter.h" 7 | #include "menuselectoption.h" 8 | 9 | class TransferJob; 10 | class Ui; 11 | 12 | class LegendPrinterTransferJob : public LegendPrinter { 13 | public: 14 | LegendPrinterTransferJob(Ui* ui, unsigned int id); 15 | bool print(); 16 | private: 17 | Ui* ui; 18 | std::shared_ptr transferjob; 19 | MenuSelectOption mso; 20 | int jobfinishedprintcount; 21 | }; 22 | -------------------------------------------------------------------------------- /src/ui/legendwindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "uiwindow.h" 8 | 9 | class LegendPrinter; 10 | 11 | class LegendWindow : public UIWindow { 12 | public: 13 | LegendWindow(Ui* ui, unsigned int row, unsigned int col); 14 | void redraw(); 15 | void update(); 16 | void setSplit(bool split); 17 | void setMainLegendPrinter(std::shared_ptr printer); 18 | void addTempLegendPrinter(std::shared_ptr printer); 19 | void clearTempLegendPrinters(); 20 | private: 21 | int latestid; 22 | int latestcount; 23 | int staticcount; 24 | std::string latesttext; 25 | bool split; 26 | std::shared_ptr mainlegendprinter; 27 | std::list > templegendprinters; 28 | }; 29 | -------------------------------------------------------------------------------- /src/ui/menuselectadjustableline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define RESIZE_SPACING 2 8 | #define RESIZE_SPACING_SHORT 1 9 | 10 | class ResizableElement; 11 | 12 | class MenuSelectAdjustableLine { 13 | public: 14 | void addElement(std::shared_ptr, unsigned int); 15 | void addElement(std::shared_ptr, unsigned int, unsigned int); 16 | void addElement(std::shared_ptr, unsigned int, unsigned int, bool); 17 | void addElement(std::shared_ptr, unsigned int, unsigned int, unsigned int, bool); 18 | std::shared_ptr getElement(unsigned int) const; 19 | std::pair getMinMaxCol(bool usecontent = false) const; 20 | unsigned int getRow() const; 21 | unsigned int size() const; 22 | bool empty() const; 23 | private: 24 | std::vector > elements; 25 | }; 26 | -------------------------------------------------------------------------------- /src/ui/menuselectoptioncheckbox.cpp: -------------------------------------------------------------------------------- 1 | #include "menuselectoptioncheckbox.h" 2 | 3 | MenuSelectOptionCheckBox::MenuSelectOptionCheckBox(std::string identifier, int row, int col, std::string label, bool startval) { 4 | this->value = startval; 5 | init(identifier, row, col, label); 6 | } 7 | 8 | FmtString MenuSelectOptionCheckBox::getContentText() const { 9 | if (value) { 10 | return "[X]"; 11 | } 12 | return "[ ]"; 13 | } 14 | 15 | bool MenuSelectOptionCheckBox::activate() { 16 | if (value) { 17 | value = false; 18 | } 19 | else { 20 | value = true; 21 | } 22 | return false; 23 | } 24 | 25 | void MenuSelectOptionCheckBox::setValue(bool value) { 26 | this->value = value; 27 | } 28 | 29 | bool MenuSelectOptionCheckBox::getData() const { 30 | return value; 31 | } 32 | 33 | unsigned int MenuSelectOptionCheckBox::wantedWidth() const { 34 | return 3; 35 | } 36 | -------------------------------------------------------------------------------- /src/ui/menuselectoptioncheckbox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "menuselectoptionelement.h" 6 | #include "resizableelement.h" 7 | 8 | class MenuSelectOptionCheckBox : public ResizableElement { 9 | private: 10 | bool value; 11 | public: 12 | MenuSelectOptionCheckBox(std::string, int, int, std::string, bool); 13 | FmtString getContentText() const override; 14 | bool activate() override; 15 | void setValue(bool value); 16 | bool getData() const; 17 | unsigned int wantedWidth() const override; 18 | }; 19 | -------------------------------------------------------------------------------- /src/ui/menuselectoptioncontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "menuselectoptioncontainer.h" 2 | 3 | #include 4 | 5 | #include "menuselectoptionelement.h" 6 | 7 | MenuSelectOptionContainer::MenuSelectOptionContainer() { 8 | 9 | } 10 | 11 | MenuSelectOptionContainer::~MenuSelectOptionContainer() { 12 | 13 | } 14 | 15 | void MenuSelectOptionContainer::addElement(std::shared_ptr msoe) { 16 | elements.push_back(msoe); 17 | } 18 | 19 | std::shared_ptr MenuSelectOptionContainer::getOption(unsigned int id) const { 20 | if (elements.size() > 0 && elements.size() - 1 >= id) { 21 | return elements[id]; 22 | } 23 | return std::shared_ptr(); 24 | } 25 | -------------------------------------------------------------------------------- /src/ui/menuselectoptioncontainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class MenuSelectOptionElement; 7 | 8 | class MenuSelectOptionContainer { 9 | private: 10 | std::vector > elements; 11 | public: 12 | MenuSelectOptionContainer(); 13 | ~MenuSelectOptionContainer(); 14 | void addElement(std::shared_ptr); 15 | std::shared_ptr getOption(unsigned int) const; 16 | }; 17 | -------------------------------------------------------------------------------- /src/ui/menuselectoptionelement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fmtstring.h" 4 | 5 | class MenuSelectOptionElement { 6 | private: 7 | std::string identifier; 8 | int col; 9 | int row; 10 | bool shown; 11 | bool selectable; 12 | unsigned int id; 13 | std::string extradata; 14 | void * origin; 15 | protected: 16 | FmtString label; 17 | bool active; 18 | public: 19 | void init(const std::string& identifier, int row, int col, const std::string& label); 20 | virtual ~MenuSelectOptionElement(); 21 | void setPosition(int row, int col); 22 | virtual FmtString getLabelText() const; 23 | std::string getIdentifier() const; 24 | unsigned int getId() const; 25 | std::string getExtraData() const; 26 | virtual FmtString getContentText() const = 0; 27 | virtual unsigned int getTotalWidth() const; 28 | virtual bool activate(); 29 | virtual void deactivate(); 30 | virtual bool isActive() const; 31 | virtual int cursorPosition() const; 32 | virtual bool inputChar(int ch); 33 | void setOrigin(void* origin); 34 | void* getOrigin() const; 35 | virtual std::string getLegendText() const; 36 | unsigned int getCol() const; 37 | unsigned int getRow() const; 38 | void hide(); 39 | void show(); 40 | bool visible() const; 41 | bool isSelectable() const; 42 | void setSelectable(bool); 43 | void setId(unsigned int); 44 | void setExtraData(const std::string& data); 45 | void setLabel(const std::string& label); 46 | }; 47 | -------------------------------------------------------------------------------- /src/ui/menuselectoptionnumarrow.cpp: -------------------------------------------------------------------------------- 1 | #include "menuselectoptionnumarrow.h" 2 | 3 | #include "ncurseswrap.h" 4 | 5 | MenuSelectOptionNumArrow::MenuSelectOptionNumArrow(std::string identifier, int row, int col, std::string label, int value, int min, int max) { 6 | arrow = NumInputArrow(value, min, max); 7 | init(identifier, row, col, label); 8 | } 9 | 10 | FmtString MenuSelectOptionNumArrow::getContentText() const { 11 | return arrow.getVisual(); 12 | } 13 | 14 | bool MenuSelectOptionNumArrow::inputChar(int ch) { 15 | switch(ch) { 16 | case KEY_DOWN: 17 | case KEY_LEFT: 18 | arrow.decrease(); 19 | return true; 20 | case KEY_UP: 21 | case KEY_RIGHT: 22 | arrow.increase(); 23 | return true; 24 | } 25 | return false; 26 | } 27 | 28 | bool MenuSelectOptionNumArrow::activate() { 29 | arrow.activate(); 30 | return true; 31 | } 32 | 33 | void MenuSelectOptionNumArrow::deactivate() { 34 | arrow.deactivate(); 35 | } 36 | 37 | int MenuSelectOptionNumArrow::getData() const { 38 | return arrow.getValue(); 39 | } 40 | 41 | void MenuSelectOptionNumArrow::setData(int value) { 42 | arrow.setValue(value); 43 | } 44 | 45 | std::string MenuSelectOptionNumArrow::getLegendText() const { 46 | return "[Enter] Finish editing - [Left] Decrease value - [Right] Increase value"; 47 | } 48 | 49 | void MenuSelectOptionNumArrow::setSubstituteText(int value, const std::string & text) { 50 | arrow.setSubstituteText(value, text); 51 | } 52 | -------------------------------------------------------------------------------- /src/ui/menuselectoptionnumarrow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "menuselectoptionelement.h" 6 | #include "numinputarrow.h" 7 | 8 | class MenuSelectOptionNumArrow : public MenuSelectOptionElement { 9 | private: 10 | NumInputArrow arrow; 11 | public: 12 | MenuSelectOptionNumArrow(std::string, int, int, std::string, int, int, int); 13 | FmtString getContentText() const override; 14 | bool inputChar(int ch) override; 15 | bool activate() override; 16 | void deactivate() override; 17 | int getData() const; 18 | void setData(int value); 19 | std::string getLegendText() const override; 20 | void setSubstituteText(int value, const std::string & text); 21 | }; 22 | -------------------------------------------------------------------------------- /src/ui/menuselectoptiontextarrow.cpp: -------------------------------------------------------------------------------- 1 | #include "menuselectoptiontextarrow.h" 2 | 3 | #include "ncurseswrap.h" 4 | 5 | MenuSelectOptionTextArrow::MenuSelectOptionTextArrow(std::string identifier, int row, int col, std::string label) { 6 | arrow = TextArrow(); 7 | init(identifier, row, col, label); 8 | } 9 | 10 | FmtString MenuSelectOptionTextArrow::getContentText() const { 11 | return arrow.getVisual(); 12 | } 13 | 14 | bool MenuSelectOptionTextArrow::inputChar(int ch) { 15 | switch(ch) { 16 | case KEY_DOWN: 17 | case KEY_LEFT: 18 | arrow.previous(); 19 | return true; 20 | case KEY_UP: 21 | case KEY_RIGHT: 22 | arrow.next(); 23 | return true; 24 | } 25 | return false; 26 | } 27 | 28 | bool MenuSelectOptionTextArrow::activate() { 29 | arrow.activate(); 30 | return true; 31 | } 32 | 33 | void MenuSelectOptionTextArrow::deactivate() { 34 | arrow.deactivate(); 35 | } 36 | 37 | bool MenuSelectOptionTextArrow::isActive() const { 38 | return arrow.isActive(); 39 | } 40 | 41 | int MenuSelectOptionTextArrow::getData() const { 42 | return arrow.getOption(); 43 | } 44 | 45 | std::string MenuSelectOptionTextArrow::getDataText() const { 46 | return arrow.getOptionText(); 47 | } 48 | 49 | std::string MenuSelectOptionTextArrow::getLegendText() const { 50 | return "[Enter] Finish editing - [Left] Previous value - [Right] Next value"; 51 | } 52 | 53 | void MenuSelectOptionTextArrow::addOption(std::string text, int id) { 54 | arrow.addOption(text, id); 55 | } 56 | 57 | bool MenuSelectOptionTextArrow::setOption(int id) { 58 | return arrow.setOption(id); 59 | } 60 | 61 | bool MenuSelectOptionTextArrow::setOptionText(std::string text) { 62 | return arrow.setOptionText(text); 63 | } 64 | 65 | void MenuSelectOptionTextArrow::clear() { 66 | arrow.clear(); 67 | } 68 | 69 | unsigned int MenuSelectOptionTextArrow::wantedWidth() const { 70 | return arrow.getVisual().length(); 71 | } 72 | -------------------------------------------------------------------------------- /src/ui/menuselectoptiontextarrow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "menuselectoptionelement.h" 6 | #include "textarrow.h" 7 | #include "resizableelement.h" 8 | 9 | class MenuSelectOptionTextArrow : public ResizableElement { 10 | private: 11 | TextArrow arrow; 12 | public: 13 | MenuSelectOptionTextArrow(std::string, int, int, std::string); 14 | FmtString getContentText() const override; 15 | bool inputChar(int ch) override; 16 | bool activate() override; 17 | void deactivate() override; 18 | bool isActive() const override; 19 | int getData() const; 20 | std::string getDataText() const; 21 | std::string getLegendText() const override; 22 | void addOption(std::string, int); 23 | bool setOption(int); 24 | bool setOptionText(std::string); 25 | void clear(); 26 | unsigned int wantedWidth() const override; 27 | }; 28 | -------------------------------------------------------------------------------- /src/ui/menuselectoptiontextbutton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fmtstring.h" 4 | 5 | #include "menuselectoptionelement.h" 6 | #include "resizableelement.h" 7 | 8 | class MenuSelectOptionTextButton : public ResizableElement { 9 | private: 10 | FmtString text; 11 | std::string legendtext; 12 | public: 13 | MenuSelectOptionTextButton(std::string, int, int, std::string); 14 | MenuSelectOptionTextButton(std::string, int, int, std::string, bool); 15 | FmtString getContentText() const override; 16 | FmtString getLabelText() const override; 17 | bool isActivated() const; 18 | bool activate() override; 19 | unsigned int wantedWidth() const override; 20 | std::string getLegendText() const override; 21 | void setLegendText(const std::string& text); 22 | virtual unsigned int getTotalWidth() const override; 23 | }; 24 | -------------------------------------------------------------------------------- /src/ui/menuselectoptiontextfield.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "textinputfield.h" 6 | #include "menuselectoptionelement.h" 7 | #include "resizableelement.h" 8 | 9 | class MenuSelectOptionTextField : public ResizableElement { 10 | private: 11 | TextInputField textfield; 12 | std::string extralegend; 13 | public: 14 | MenuSelectOptionTextField(); 15 | MenuSelectOptionTextField(const std::string& identifier, int row, int col, 16 | const std::string& label, const std::string& starttext, int visiblelen, 17 | int maxlen, bool secret); 18 | FmtString getContentText() const override; 19 | bool activate() override; 20 | bool inputChar(int ch) override; 21 | int cursorPosition() const override; 22 | std::string getData() const; 23 | void clear(); 24 | void setText(const std::string& text); 25 | std::string getLegendText() const override; 26 | void setExtraLegendText(const std::string& extra); 27 | unsigned int wantedWidth() const override; 28 | void setMaxWidth(unsigned int maxwidth) override; 29 | }; 30 | -------------------------------------------------------------------------------- /src/ui/misc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class VirtualView; 6 | 7 | void printSlider(VirtualView* vv, unsigned int, unsigned int, unsigned int, unsigned int); 8 | void printSlider(VirtualView* vv, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); 9 | bool adaptViewSpan(unsigned int &, unsigned int, unsigned int, unsigned int); 10 | bool isYearEnd(); 11 | 12 | constexpr int encodeColorRepresentation(int fgcolor = -1, int bgcolor = -1) { 13 | return (fgcolor + 2) * 10 + bgcolor + 2; 14 | } 15 | 16 | struct Color { 17 | int fgcolor; 18 | int bgcolor; 19 | }; 20 | 21 | constexpr Color decodeColorRepresentation(int repr) { 22 | return Color{ repr / 10 - 2, repr % 10 - 2 }; 23 | } 24 | -------------------------------------------------------------------------------- /src/ui/ncurseswrap.h: -------------------------------------------------------------------------------- 1 | #ifndef _XOPEN_SOURCE_EXTENDED 2 | #define _XOPEN_SOURCE_EXTENDED 3 | #endif 4 | #ifdef DEBIAN 5 | #include 6 | #else 7 | #include 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ui/numinputarrow.cpp: -------------------------------------------------------------------------------- 1 | #include "numinputarrow.h" 2 | 3 | NumInputArrow::NumInputArrow() { 4 | 5 | } 6 | 7 | NumInputArrow::NumInputArrow(int startval, int min, int max) { 8 | val = startval; 9 | active = false; 10 | this->min = min; 11 | this->max = max; 12 | } 13 | 14 | bool NumInputArrow::decrease() { 15 | if (val > min) { 16 | val--; 17 | return true; 18 | } 19 | return false; 20 | 21 | } 22 | 23 | bool NumInputArrow::increase() { 24 | if (val < max) { 25 | val++; 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | bool NumInputArrow::setValue(int newval) { 32 | if (newval >= min && newval <= max) { 33 | val = newval; 34 | return true; 35 | } 36 | return false; 37 | } 38 | 39 | int NumInputArrow::getValue() const { 40 | return val; 41 | } 42 | 43 | void NumInputArrow::activate() { 44 | active = true; 45 | } 46 | 47 | void NumInputArrow::deactivate() { 48 | active = false; 49 | } 50 | std::string NumInputArrow::getVisual() const { 51 | unsigned int maxlen = std::to_string(max).length(); 52 | for (const std::pair & substitute : substituteTexts) { 53 | if (substitute.second.length() > maxlen) { 54 | maxlen = substitute.second.length(); 55 | } 56 | } 57 | maxlen += 4; 58 | std::map::const_iterator it = substituteTexts.find(val); 59 | std::string out = it != substituteTexts.end() ? it->second : std::to_string(val); 60 | if (active) { 61 | out = "< " + out + " >"; 62 | } 63 | while (out.length() < maxlen) out += ' '; 64 | return out; 65 | } 66 | 67 | void NumInputArrow::setSubstituteText(int value, const std::string & text) { 68 | substituteTexts[value] = text; 69 | } 70 | -------------------------------------------------------------------------------- /src/ui/numinputarrow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class NumInputArrow { 7 | public: 8 | NumInputArrow(); 9 | NumInputArrow(int, int, int); 10 | int getValue() const; 11 | bool setValue(int); 12 | bool increase(); 13 | bool decrease(); 14 | std::string getVisual() const; 15 | void activate(); 16 | void deactivate(); 17 | void setSubstituteText(int value, const std::string & text); 18 | private: 19 | int val; 20 | int min; 21 | int max; 22 | bool active; 23 | std::map substituteTexts; 24 | }; 25 | -------------------------------------------------------------------------------- /src/ui/screens/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.inc 2 | 3 | SRC = $(wildcard *.cpp) 4 | CLEANFILES = $(wildcard $(SRC:%.cpp=%.o) $(SRC:%.cpp=%.d)) 5 | 6 | all: $(SRC:%.cpp=%.o) 7 | @# 8 | 9 | clean: 10 | @if test $(firstword $(CLEANFILES)); then rm -rf $(CLEANFILES); echo rm -rf $(CLEANFILES); fi 11 | 12 | %.o: %.cpp ../../../Makefile.inc 13 | ifneq ($(DEBIAN),) 14 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< -DDEBIAN 15 | else 16 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< 17 | endif 18 | 19 | -include $(SRC:%.cpp=%.d) 20 | -------------------------------------------------------------------------------- /src/ui/screens/allracesscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class Engine; 11 | class Race; 12 | 13 | class AllRacesScreen : public UIWindow { 14 | public: 15 | AllRacesScreen(Ui *); 16 | void initialize(unsigned int, unsigned int); 17 | void redraw() override; 18 | void command(const std::string &, const std::string &) override; 19 | bool keyPressed(unsigned int) override; 20 | std::string getInfoLabel() const override; 21 | std::string getInfoText() const override; 22 | static void addRaceTableHeader(unsigned int, MenuSelectOption &, const std::string &); 23 | static void addRaceDetails(unsigned int, MenuSelectOption &, std::shared_ptr); 24 | private: 25 | static void addRaceTableRow(unsigned int, MenuSelectOption &, unsigned int, bool, const std::string &, 26 | const std::string &, const std::string &, const std::string &, const std::string &, const std::string &, 27 | const std::string &, const std::string &, const std::string &, const std::string &, const std::string &); 28 | MenuSelectOption table; 29 | Engine * engine; 30 | bool hascontents; 31 | unsigned int currentviewspan; 32 | unsigned int ypos; 33 | bool temphighlightline; 34 | std::shared_ptr abortrace; 35 | std::shared_ptr abortdeleteraceinc; 36 | std::shared_ptr abortdeleteraceall; 37 | }; 38 | -------------------------------------------------------------------------------- /src/ui/screens/alltransferjobsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class Engine; 11 | class TransferJob; 12 | 13 | class AllTransferJobsScreen : public UIWindow { 14 | public: 15 | AllTransferJobsScreen(Ui *); 16 | void initialize(unsigned int, unsigned int); 17 | void redraw() override; 18 | void command(const std::string &, const std::string &) override; 19 | bool keyPressed(unsigned int) override; 20 | std::string getInfoLabel() const override; 21 | std::string getInfoText() const override; 22 | static void addJobTableHeader(unsigned int, MenuSelectOption &, const std::string &); 23 | static void addJobDetails(unsigned int, MenuSelectOption &, std::shared_ptr); 24 | private: 25 | static void addJobTableRow(unsigned int, MenuSelectOption &, unsigned int, bool, const std::string &, 26 | const std::string &, const std::string &, const std::string &, const std::string &, const std::string &, 27 | const std::string &, const std::string &, const std::string &, const std::string &, const std::string &); 28 | MenuSelectOption table; 29 | Engine * engine; 30 | bool hascontents; 31 | unsigned int currentviewspan; 32 | unsigned int ypos; 33 | bool temphighlightline; 34 | std::shared_ptr abortjob; 35 | }; 36 | -------------------------------------------------------------------------------- /src/ui/screens/browsescreenaction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | enum BrowseScreenActionOp { 6 | BROWSESCREENACTION_CLOSE, 7 | BROWSESCREENACTION_SITE, 8 | BROWSESCREENACTION_HOME, 9 | BROWSESCREENACTION_NOOP, 10 | BROWSESCREENACTION_CAUGHT, 11 | BROWSESCREENACTION_CHDIR 12 | }; 13 | 14 | class BrowseScreenAction { 15 | public: 16 | BrowseScreenAction() : op(BROWSESCREENACTION_NOOP) { } 17 | BrowseScreenAction(BrowseScreenActionOp op) : op(op) { } 18 | BrowseScreenAction(BrowseScreenActionOp op, std::string arg) : op(op), arg(arg) { } 19 | BrowseScreenActionOp getOp() const { 20 | return op; 21 | } 22 | std::string getArg() const { 23 | return arg; 24 | } 25 | private: 26 | BrowseScreenActionOp op; 27 | std::string arg; 28 | }; 29 | -------------------------------------------------------------------------------- /src/ui/screens/browsescreenselector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../menuselectoption.h" 8 | 9 | #include "browsescreensub.h" 10 | 11 | #define BROWSESCREENSELECTOR_HOME "$HOME$" 12 | 13 | class Ui; 14 | class VirtualView; 15 | class BrowseScreenAction; 16 | class KeyBinds; 17 | 18 | class BrowseScreenSelector : public BrowseScreenSub { 19 | public: 20 | BrowseScreenSelector(Ui* ui, KeyBinds& keybinds); 21 | ~BrowseScreenSelector(); 22 | BrowseScreenType type() const override; 23 | void redraw(unsigned int, unsigned int, unsigned int) override; 24 | void update() override; 25 | BrowseScreenAction keyPressed(unsigned int) override; 26 | std::string getLegendText(int scope) const override; 27 | std::string getInfoLabel() const override; 28 | std::string getInfoText() const override; 29 | void setFocus(bool) override; 30 | BrowseScreenAction tryJumpSection(const std::string& section) override; 31 | private: 32 | Ui* ui; 33 | VirtualView* vv; 34 | unsigned int row; 35 | unsigned int col; 36 | unsigned int coloffset; 37 | bool focus; 38 | MenuSelectOption table; 39 | std::vector > entries; 40 | unsigned int pointer; 41 | unsigned int currentviewspan; 42 | bool gotomode; 43 | }; 44 | -------------------------------------------------------------------------------- /src/ui/screens/changekeyscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define SHORTESTKEY 4 4 | 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class MenuSelectOptionElement; 11 | 12 | class ChangeKeyScreen : public UIWindow { 13 | public: 14 | ChangeKeyScreen(Ui *); 15 | ~ChangeKeyScreen(); 16 | void initialize(unsigned int, unsigned int); 17 | void redraw() override; 18 | bool keyPressed(unsigned int) override; 19 | std::string getLegendText() const override; 20 | std::string getInfoLabel() const override; 21 | private: 22 | bool active; 23 | bool mismatch; 24 | bool oldmismatch; 25 | bool tooshort; 26 | std::shared_ptr activeelement; 27 | MenuSelectOption mso; 28 | std::string operation; 29 | }; 30 | -------------------------------------------------------------------------------- /src/ui/screens/confirmationscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | 5 | enum class ConfirmationMode { 6 | INFO, 7 | NORMAL, 8 | STRONG 9 | }; 10 | 11 | class ConfirmationScreen : public UIWindow { 12 | public: 13 | ConfirmationScreen(Ui *); 14 | void initialize(unsigned int row, unsigned int col, const std::string & message, ConfirmationMode mode); 15 | void redraw() override; 16 | bool keyPressed(unsigned int ch) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | private: 20 | std::string message; 21 | ConfirmationMode mode; 22 | int strongconfirmstep; 23 | }; 24 | -------------------------------------------------------------------------------- /src/ui/screens/disableencryptionscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class MenuSelectOptionElement; 9 | 10 | class DisableEncryptionScreen : public UIWindow { 11 | public: 12 | DisableEncryptionScreen(Ui *); 13 | ~DisableEncryptionScreen(); 14 | void initialize(unsigned int, unsigned int); 15 | void redraw() override; 16 | bool keyPressed(unsigned int) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | private: 20 | bool active; 21 | bool mismatch; 22 | std::shared_ptr activeelement; 23 | MenuSelectOption mso; 24 | }; 25 | -------------------------------------------------------------------------------- /src/ui/screens/editproxyscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../proxy.h" 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class MenuSelectOptionElement; 9 | 10 | class EditProxyScreen : public UIWindow { 11 | public: 12 | EditProxyScreen(Ui *); 13 | ~EditProxyScreen(); 14 | void initialize(unsigned int, unsigned int, std::string, std::string); 15 | void redraw() override; 16 | bool keyPressed(unsigned int) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | private: 20 | bool active; 21 | std::shared_ptr activeelement; 22 | MenuSelectOption mso; 23 | Proxy * proxy; 24 | Proxy modproxy; 25 | std::shared_ptr authmethod; 26 | std::shared_ptr ampm; 27 | int latestauthmethod; 28 | std::string operation; 29 | }; 30 | -------------------------------------------------------------------------------- /src/ui/screens/editsectionscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class MenuSelectOptionElement; 9 | class Section; 10 | 11 | class EditSectionScreen : public UIWindow { 12 | enum class Mode { 13 | ADD, 14 | EDIT 15 | }; 16 | public: 17 | EditSectionScreen(Ui *); 18 | ~EditSectionScreen(); 19 | void initialize(unsigned int row, unsigned int col, const std::string & section = ""); 20 | void redraw() override; 21 | bool keyPressed(unsigned int) override; 22 | std::string getLegendText() const override; 23 | std::string getInfoLabel() const override; 24 | private: 25 | void done(); 26 | Section * section; 27 | bool active; 28 | std::shared_ptr activeelement; 29 | MenuSelectOption mso; 30 | Mode mode; 31 | std::string oldname; 32 | }; 33 | -------------------------------------------------------------------------------- /src/ui/screens/editsitescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | #include "../menuselectoption.h" 8 | 9 | class Site; 10 | class MenuSelectOptionElement; 11 | 12 | class EditSiteScreen : public UIWindow { 13 | public: 14 | EditSiteScreen(Ui * ui); 15 | ~EditSiteScreen(); 16 | void initialize(unsigned int row, unsigned int col, const std::string & operation, const std::string & site); 17 | void redraw() override; 18 | void command(const std::string & command, const std::string & arg) override; 19 | bool keyPressed(unsigned int ch) override; 20 | std::string getLegendText() const override; 21 | std::string getInfoLabel() const override; 22 | private: 23 | void fillPreselectionList(const std::string &, std::list > *) const; 24 | bool active; 25 | std::shared_ptr activeelement; 26 | MenuSelectOption mso; 27 | std::shared_ptr site; 28 | std::shared_ptr modsite; 29 | std::string operation; 30 | bool slotsupdated; 31 | }; 32 | -------------------------------------------------------------------------------- /src/ui/screens/editsitesectionscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | #include "../menuselectoption.h" 8 | 9 | class Site; 10 | class MenuSelectOptionElement; 11 | class Path; 12 | 13 | class EditSiteSectionScreen : public UIWindow { 14 | enum class Mode { 15 | ADD, 16 | EDIT 17 | }; 18 | public: 19 | EditSiteSectionScreen(Ui *); 20 | ~EditSiteSectionScreen(); 21 | void initialize(unsigned int row, unsigned int col, const std::shared_ptr & site, const Path & path); 22 | void initialize(unsigned int row, unsigned int col, const std::shared_ptr & site, const std::string & section); 23 | void redraw() override; 24 | bool keyPressed(unsigned int) override; 25 | void command(const std::string & command, const std::string & arg) override; 26 | std::string getLegendText() const override; 27 | std::string getInfoLabel() const override; 28 | private: 29 | void initialize(unsigned int row, unsigned int col, const std::shared_ptr & site, const std::string & section, const Path & path); 30 | bool setSections(); 31 | std::shared_ptr modsite; 32 | bool active; 33 | std::shared_ptr activeelement; 34 | MenuSelectOption mso; 35 | Mode mode; 36 | std::string oldsection; 37 | bool exists; 38 | }; 39 | -------------------------------------------------------------------------------- /src/ui/screens/eventlogscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../menuselectoptiontextfield.h" 4 | #include "../uiwindow.h" 5 | 6 | class RawBuffer; 7 | 8 | class EventLogScreen : public UIWindow { 9 | public: 10 | EventLogScreen(Ui *); 11 | void initialize(unsigned int, unsigned int); 12 | void redraw() override; 13 | void update() override; 14 | bool keyPressed(unsigned int) override; 15 | std::string getLegendText() const override; 16 | std::string getInfoLabel() const override; 17 | std::string getInfoText() const override; 18 | private: 19 | void fixCopyReadPos(); 20 | bool readfromcopy; 21 | unsigned int copyreadpos; 22 | RawBuffer * rawbuf; 23 | std::string filtertext; 24 | bool filtermodeinput; 25 | bool filtermodeinputregex; 26 | MenuSelectOptionTextField filterfield; 27 | }; 28 | -------------------------------------------------------------------------------- /src/ui/screens/externalscriptsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class Path; 9 | class Ui; 10 | class FocusableArea; 11 | class MenuSelectOptionElement; 12 | class ExternalScripts; 13 | 14 | class ExternalScriptsScreen : public UIWindow { 15 | public: 16 | ExternalScriptsScreen(Ui *); 17 | ~ExternalScriptsScreen(); 18 | void initialize(unsigned int row, unsigned int col, ExternalScripts* externalscripts, const std::string& description); 19 | void redraw() override; 20 | bool keyPressed(unsigned int) override; 21 | std::string getLegendText() const override; 22 | std::string getInfoLabel() const override; 23 | private: 24 | void addScriptLine(int y, const std::string& name, const Path& path, int id = -1, 25 | const std::shared_ptr& before = nullptr); 26 | bool keyUp() override; 27 | bool keyDown() override; 28 | int getCurrentScope() const; 29 | void recreateTable(); 30 | void saveToTempScriptList(); 31 | bool active; 32 | std::shared_ptr activeelement; 33 | MenuSelectOption base; 34 | MenuSelectOption table; 35 | FocusableArea* focusedarea; 36 | FocusableArea* defocusedarea; 37 | bool temphighlightline; 38 | std::shared_ptr tempexternalscripts; 39 | ExternalScripts* externalscripts; 40 | std::list description; 41 | }; 42 | -------------------------------------------------------------------------------- /src/ui/screens/fileinfoscreen.cpp: -------------------------------------------------------------------------------- 1 | #include "fileinfoscreen.h" 2 | 3 | #include "../../util.h" 4 | 5 | #include "../ui.h" 6 | #include "../uifile.h" 7 | 8 | FileInfoScreen::FileInfoScreen(Ui* ui) : UIWindow(ui, "FileInfoScreen"), uifile(nullptr) { 9 | allowimplicitgokeybinds = false; 10 | } 11 | 12 | void FileInfoScreen::initialize(unsigned int row, unsigned int col, UIFile* uifile) { 13 | this->uifile = uifile; 14 | init(row, col); 15 | } 16 | 17 | void FileInfoScreen::redraw() { 18 | vv->clear(); 19 | ui->hideCursor(); 20 | 21 | unsigned int i = 1; 22 | vv->putStr(i++, 1, "Name: " + uifile->getName()); 23 | std::string type = "File"; 24 | if (uifile->isDirectory()) { 25 | type = "Directory"; 26 | } 27 | else if (uifile->isLink()) { 28 | type = "Link"; 29 | } 30 | vv->putStr(i++, 1, "Type: " + type); 31 | vv->putStr(i++, 1, "Size: " + uifile->getSizeRepr()); 32 | vv->putStr(i++, 1, "Last modified: " + uifile->getLastModified()); 33 | vv->putStr(i++, 1, "Owner: " + uifile->getOwner() + "/" + uifile->getGroup()); 34 | if (uifile->isLink()) { 35 | vv->putStr(i++, 1, "Link target: " + uifile->getLinkTarget()); 36 | } 37 | } 38 | 39 | bool FileInfoScreen::keyPressed(unsigned int ch) { 40 | switch(ch) { 41 | case 27: // esc 42 | case ' ': 43 | case 'c': 44 | case 10: 45 | ui->returnToLast(); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | std::string FileInfoScreen::getLegendText() const { 52 | return "[Esc/Space/Enter/c] Return"; 53 | } 54 | 55 | std::string FileInfoScreen::getInfoLabel() const { 56 | return "FILE INFO"; 57 | } 58 | -------------------------------------------------------------------------------- /src/ui/screens/fileinfoscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | 5 | class UIFile; 6 | 7 | class FileInfoScreen : public UIWindow { 8 | public: 9 | FileInfoScreen(Ui* ui); 10 | void initialize(unsigned int row, unsigned int col, UIFile* uifile); 11 | void redraw() override; 12 | bool keyPressed(unsigned int) override; 13 | std::string getLegendText() const override; 14 | std::string getInfoLabel() const override; 15 | private: 16 | UIFile* uifile; 17 | }; 18 | -------------------------------------------------------------------------------- /src/ui/screens/fileviewersettingsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | #include "../menuselectoption.h" 5 | 6 | class MenuSelectOptionTextArrow; 7 | class LocalStorage; 8 | 9 | class FileViewerSettingsScreen : public UIWindow { 10 | public: 11 | FileViewerSettingsScreen(Ui *); 12 | ~FileViewerSettingsScreen(); 13 | void initialize(unsigned int, unsigned int); 14 | void redraw() override; 15 | bool keyPressed(unsigned int) override; 16 | std::string getLegendText() const override; 17 | std::string getInfoLabel() const override; 18 | private: 19 | bool active; 20 | std::shared_ptr activeelement; 21 | MenuSelectOption mso; 22 | LocalStorage * ls; 23 | }; 24 | -------------------------------------------------------------------------------- /src/ui/screens/globaloptionsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../menuselectoption.h" 8 | #include "../uiwindow.h" 9 | 10 | class SiteManager; 11 | class RemoteCommandHandler; 12 | class LocalStorage; 13 | class MenuSelectOptionElement; 14 | class MenuSelectOptionTextArrow; 15 | 16 | class GlobalOptionsScreen : public UIWindow { 17 | public: 18 | GlobalOptionsScreen(Ui *); 19 | ~GlobalOptionsScreen(); 20 | void initialize(unsigned int, unsigned int); 21 | void update() override; 22 | void redraw() override; 23 | bool keyPressed(unsigned int) override; 24 | std::string getLegendText() const override; 25 | std::string getInfoLabel() const override; 26 | private: 27 | MenuSelectOption mso; 28 | RemoteCommandHandler * rch; 29 | SiteManager * sm; 30 | LocalStorage * ls; 31 | bool active; 32 | std::shared_ptr activeelement; 33 | std::map interfacemap; 34 | std::shared_ptr bindinterface; 35 | }; 36 | -------------------------------------------------------------------------------- /src/ui/screens/infoscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | 5 | class InfoScreen : public UIWindow { 6 | public: 7 | InfoScreen(Ui* ui); 8 | void initialize(unsigned int row, unsigned int col); 9 | void redraw() override; 10 | bool keyPressed(unsigned int ch) override; 11 | std::string getInfoLabel() const override; 12 | void command(const std::string& command, const std::string& arg) override; 13 | private: 14 | int confirmaction; 15 | }; 16 | -------------------------------------------------------------------------------- /src/ui/screens/keybindsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include "../uiwindow.h" 9 | #include "../menuselectoption.h" 10 | 11 | class KeyBinds; 12 | class MenuSelectOptionElement; 13 | 14 | class KeyBindsScreen : public UIWindow { 15 | public: 16 | KeyBindsScreen(Ui *); 17 | ~KeyBindsScreen(); 18 | void initialize(unsigned int row, unsigned int col, KeyBinds* keybinds); 19 | void redraw() override; 20 | bool keyPressed(unsigned int) override; 21 | std::string getLegendText() const override; 22 | std::string getInfoLabel() const override; 23 | private: 24 | void repopulate(); 25 | bool active; 26 | std::shared_ptr activeelement; 27 | MenuSelectOption mso; 28 | KeyBinds* realkeybinds; 29 | std::shared_ptr tempkeybinds; 30 | std::list> actionandscope; 31 | bool addextrakey; 32 | }; 33 | -------------------------------------------------------------------------------- /src/ui/screens/loginscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../textinputfield.h" 6 | #include "../uiwindow.h" 7 | 8 | class LoginScreen : public UIWindow { 9 | public: 10 | LoginScreen(Ui *); 11 | void initialize(unsigned int, unsigned int); 12 | void update(); 13 | void redraw(); 14 | bool keyPressed(unsigned int); 15 | private: 16 | std::string drawword; 17 | void randomizeDrawLocation(); 18 | std::vector > background; 19 | std::string passphrase; 20 | TextInputField passfield; 21 | int pass_row; 22 | int pass_col; 23 | int drawx; 24 | int drawy; 25 | bool attempt; 26 | }; 27 | -------------------------------------------------------------------------------- /src/ui/screens/makedirscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | #include "../menuselectoption.h" 8 | #include "../uifilelist.h" 9 | 10 | class MenuSelectOptionElement; 11 | class UIFileList; 12 | 13 | class MakeDirScreen : public UIWindow { 14 | public: 15 | MakeDirScreen(Ui *); 16 | ~MakeDirScreen(); 17 | void initialize(unsigned int row, unsigned int col, const std::string & site, UIFileList & filelist); 18 | void redraw() override; 19 | bool keyPressed(unsigned int) override; 20 | std::string getLegendText() const override; 21 | std::string getInfoLabel() const override; 22 | private: 23 | void tryMakeDir(); 24 | bool active; 25 | std::string site; 26 | std::shared_ptr activeelement; 27 | MenuSelectOption mso; 28 | std::string release; 29 | UIFileList filelist; 30 | bool alreadyexists; 31 | }; 32 | -------------------------------------------------------------------------------- /src/ui/screens/metricsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | 7 | class BrailleGraph; 8 | 9 | class MetricsScreen : public UIWindow { 10 | public: 11 | MetricsScreen(Ui* ui); 12 | ~MetricsScreen(); 13 | void initialize(unsigned int row, unsigned int col); 14 | void redraw() override; 15 | void update() override; 16 | bool keyPressed(unsigned int ch) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | std::string getInfoText() const override; 20 | private: 21 | std::unique_ptr cpuall; 22 | std::unique_ptr cpuworker; 23 | std::unique_ptr workqueuesize; 24 | std::unique_ptr perflevel; 25 | std::unique_ptr filelistrefreshrate; 26 | }; 27 | -------------------------------------------------------------------------------- /src/ui/screens/movescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | #include "../menuselectoption.h" 8 | 9 | class MenuSelectOptionElement; 10 | class Path; 11 | 12 | class MoveScreen : public UIWindow { 13 | public: 14 | MoveScreen(Ui *); 15 | ~MoveScreen(); 16 | void initialize(unsigned int row, unsigned int col, const std::string & site, const std::string& items, const Path& srcpath, const std::string& dstpath, const std::string& firstitem); 17 | void redraw() override; 18 | void deactivate(); 19 | bool keyPressed(unsigned int ch) override; 20 | std::string getLegendText() const override; 21 | std::string getInfoLabel() const override; 22 | private: 23 | bool active; 24 | std::string site; 25 | std::shared_ptr activeelement; 26 | MenuSelectOption mso; 27 | std::string srcpath; 28 | std::string items; 29 | std::string firstitem; 30 | }; 31 | -------------------------------------------------------------------------------- /src/ui/screens/newkeyscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class MenuSelectOptionElement; 9 | 10 | class NewKeyScreen : public UIWindow { 11 | public: 12 | NewKeyScreen(Ui *); 13 | ~NewKeyScreen(); 14 | void initialize(unsigned int, unsigned int); 15 | void redraw() override; 16 | bool keyPressed(unsigned int) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | private: 20 | bool active; 21 | bool mismatch; 22 | bool tooshort; 23 | std::shared_ptr activeelement; 24 | MenuSelectOption mso; 25 | }; 26 | -------------------------------------------------------------------------------- /src/ui/screens/newracescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include "../uiwindow.h" 9 | #include "../menuselectoption.h" 10 | #include "../../engine.h" 11 | 12 | class FocusableArea; 13 | class MenuSelectOptionElement; 14 | class MenuSelectOptionTextArrow; 15 | class Site; 16 | class Race; 17 | 18 | class NewRaceScreen : public UIWindow { 19 | public: 20 | NewRaceScreen(Ui *); 21 | ~NewRaceScreen(); 22 | void initialize(unsigned int row, unsigned int col, const std::string & site, const std::list & sections, const std::list > & items); 23 | void redraw() override; 24 | bool keyPressed(unsigned int) override; 25 | std::string getLegendText() const override; 26 | std::string getInfoLabel() const override; 27 | std::string getInfoText() const override; 28 | private: 29 | void populateSiteList(); 30 | JobStartResult startRace(bool addtemplegend); 31 | std::shared_ptr startsite; 32 | std::string getSectionButtonText(std::shared_ptr) const; 33 | bool active; 34 | bool toggleall; 35 | std::string section; 36 | std::shared_ptr activeelement; 37 | FocusableArea * focusedarea; 38 | FocusableArea * defocusedarea; 39 | MenuSelectOption msos; 40 | MenuSelectOption mso; 41 | std::list sections; 42 | std::list > items; 43 | std::string infotext; 44 | std::list > tempsites; 45 | std::shared_ptr msota; 46 | }; 47 | -------------------------------------------------------------------------------- /src/ui/screens/nukescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../../path.h" 7 | 8 | #include "../uiwindow.h" 9 | #include "../menuselectoption.h" 10 | 11 | class MenuSelectOptionElement; 12 | 13 | class NukeScreen : public UIWindow { 14 | public: 15 | NukeScreen(Ui *); 16 | ~NukeScreen(); 17 | void initialize(unsigned int row, unsigned int col, const std::string & sitestr, const std::string & items, const Path & path); 18 | void redraw() override; 19 | bool keyPressed(unsigned int) override; 20 | std::string getLegendText() const override; 21 | std::string getInfoLabel() const override; 22 | private: 23 | void nuke(); 24 | void nuke(int multiplier, const std::string & reason); 25 | std::string sitestr; 26 | bool active; 27 | std::string section; 28 | std::shared_ptr activeelement; 29 | MenuSelectOption mso; 30 | std::string items; 31 | Path path; 32 | }; 33 | -------------------------------------------------------------------------------- /src/ui/screens/proxyoptionsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | #include "../menuselectoption.h" 5 | 6 | class FocusableArea; 7 | class ProxyManager; 8 | class MenuSelectOptionTextArrow; 9 | 10 | class ProxyOptionsScreen : public UIWindow { 11 | public: 12 | ProxyOptionsScreen(Ui *); 13 | ~ProxyOptionsScreen(); 14 | void initialize(unsigned int, unsigned int); 15 | void redraw() override; 16 | void command(const std::string &) override; 17 | bool keyPressed(unsigned int) override; 18 | std::string getLegendText() const override; 19 | std::string getInfoLabel() const override; 20 | std::string getInfoText() const override; 21 | private: 22 | FocusableArea * focusedarea; 23 | FocusableArea * defocusedarea; 24 | bool active; 25 | bool defaultset; 26 | bool defaultdataset; 27 | std::string deleteproxy; 28 | std::string editproxy; 29 | std::shared_ptr activeelement; 30 | MenuSelectOption mso; 31 | MenuSelectOption msop; 32 | ProxyManager * pm; 33 | std::shared_ptr useproxy; 34 | std::shared_ptr dataproxy; 35 | }; 36 | -------------------------------------------------------------------------------- /src/ui/screens/racestatusscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class Race; 11 | 12 | class RaceStatusScreen : public UIWindow { 13 | public: 14 | RaceStatusScreen(Ui *); 15 | ~RaceStatusScreen(); 16 | bool initialize(unsigned int, unsigned int, unsigned int); 17 | void redraw() override; 18 | void update() override; 19 | void command(const std::string &, const std::string &) override; 20 | bool keyPressed(unsigned int) override; 21 | std::string getLegendText() const override; 22 | std::string getInfoLabel() const override; 23 | private: 24 | void deleteFiles(bool); 25 | std::list getIncompleteSites() const; 26 | std::list getDownloadOnlySites() const; 27 | int getCurrentScope() const; 28 | std::shared_ptr race; 29 | bool smalldirs; 30 | bool awaitingremovesite; 31 | bool awaitingremovesitedelownfiles; 32 | bool awaitingremovesitedelallfiles; 33 | bool awaitingabort; 34 | bool awaitingdeleteowninc; 35 | bool awaitingdeleteownall; 36 | bool awaitingremovesitefromallspreadjobs; 37 | unsigned int currnumsubpaths; 38 | unsigned int currguessedsize; 39 | unsigned int currincomplete; 40 | unsigned int longestsubpath; 41 | std::list subpaths; 42 | MenuSelectOption mso; 43 | std::map filetagpos; 44 | std::map filenametags; 45 | std::string removesite; 46 | bool finished; 47 | int selectsitesmode; 48 | }; 49 | -------------------------------------------------------------------------------- /src/ui/screens/rawcommandscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../path.h" 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoptiontextfield.h" 9 | #include "../commandhistory.h" 10 | 11 | class RawBuffer; 12 | class SiteLogic; 13 | 14 | class RawCommandScreen : public UIWindow { 15 | public: 16 | RawCommandScreen(Ui * ui); 17 | void initialize(unsigned int, unsigned int, const std::string &, const Path &, const std::string &); 18 | void initialize(unsigned int, unsigned int, const std::string &); 19 | void initialize(unsigned int, unsigned int, RawBuffer * rawbuffer, const std::string & label, const std::string & infotext); 20 | void redraw() override; 21 | void update() override; 22 | bool keyPressed(unsigned int) override; 23 | std::string getLegendText() const override; 24 | std::string getInfoLabel() const override; 25 | std::string getInfoText() const override; 26 | private: 27 | int getCurrentScope() const; 28 | void fixCopyReadPos(); 29 | bool readfromcopy; 30 | unsigned int copyreadpos; 31 | MenuSelectOptionTextField rawcommandfield; 32 | std::string label; 33 | std::string selection; 34 | Path path; 35 | bool hasselection; 36 | std::shared_ptr sitelogic; 37 | RawBuffer * rawbuf; 38 | CommandHistory history; 39 | bool allowinput; 40 | }; 41 | -------------------------------------------------------------------------------- /src/ui/screens/rawdatascreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoptiontextfield.h" 7 | #include "../commandhistory.h" 8 | 9 | class SiteLogic; 10 | class RawBuffer; 11 | 12 | class RawDataScreen : public UIWindow { 13 | public: 14 | RawDataScreen(Ui *); 15 | void initialize(unsigned int, unsigned int, std::string, int); 16 | void redraw() override; 17 | void update() override; 18 | bool keyPressed(unsigned int) override; 19 | std::string getLegendText() const override; 20 | std::string getInfoLabel() const override; 21 | std::string getInfoText() const override; 22 | static void printRawBufferLines(VirtualView* vv, RawBuffer *, unsigned int, unsigned int, unsigned int); 23 | static void printRawBufferLines(VirtualView* vv, RawBuffer *, unsigned int, unsigned int, unsigned int, bool, unsigned int); 24 | private: 25 | static bool skipCodePrint(const std::string &); 26 | void fixCopyReadPos(); 27 | bool rawcommandmode; 28 | bool rawcommandswitch; 29 | int threads; 30 | bool readfromcopy; 31 | unsigned int copyreadpos; 32 | MenuSelectOptionTextField rawcommandfield; 33 | std::string sitename; 34 | int connid; 35 | std::shared_ptr sitelogic; 36 | RawBuffer * rawbuf; 37 | CommandHistory history; 38 | std::string filtertext; 39 | bool filtermodeinput; 40 | bool filtermodeinputregex; 41 | MenuSelectOptionTextField filterfield; 42 | }; 43 | -------------------------------------------------------------------------------- /src/ui/screens/scoreboardscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class Engine; 9 | class ScoreBoard; 10 | 11 | class ScoreBoardScreen : public UIWindow { 12 | public: 13 | ScoreBoardScreen(Ui *); 14 | ~ScoreBoardScreen(); 15 | void initialize(unsigned int, unsigned int); 16 | void redraw() override; 17 | bool keyPressed(unsigned int) override; 18 | std::string getLegendText() const override; 19 | std::string getInfoLabel() const override; 20 | std::string getInfoText() const override; 21 | private: 22 | Engine * engine; 23 | std::shared_ptr scoreboard; 24 | MenuSelectOption table; 25 | unsigned int currentviewspan; 26 | }; 27 | -------------------------------------------------------------------------------- /src/ui/screens/sectionsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class MenuSelectOptionElement; 9 | class Section; 10 | 11 | class SectionsScreen : public UIWindow { 12 | public: 13 | SectionsScreen(Ui *); 14 | ~SectionsScreen(); 15 | void initialize(unsigned int row, unsigned int col, bool selectsection = false, 16 | const std::list& preselected = std::list(), 17 | const std::list& alreadybound = std::list()); 18 | void redraw() override; 19 | bool keyPressed(unsigned int) override; 20 | std::string getLegendText() const override; 21 | std::string getInfoLabel() const override; 22 | std::string getInfoText() const override; 23 | void command(const std::string & command, const std::string & arg) override; 24 | private: 25 | enum class Mode { 26 | EDIT, 27 | SELECT 28 | }; 29 | void addSectionTableHeader(unsigned int y, MenuSelectOption & mso); 30 | void addSectionDetails(unsigned int y, MenuSelectOption & mso, const Section & section); 31 | void addSectionTableRow(unsigned int y, MenuSelectOption & mso, bool selectable, 32 | const std::string& selected, const std::string & name, const std::string & skiplist, const std::string & hotkey, const std::string & numjobs, 33 | const std::string & numsites, const std::string & sites); 34 | int getCurrentScope() const; 35 | MenuSelectOption table; 36 | unsigned int currentviewspan; 37 | unsigned int ypos; 38 | bool temphighlightline; 39 | bool hascontents; 40 | unsigned int totallistsize; 41 | Mode mode; 42 | std::set selected; 43 | std::set alreadybound; 44 | bool togglestate; 45 | }; 46 | -------------------------------------------------------------------------------- /src/ui/screens/selectjobsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "../uiwindow.h" 9 | #include "../menuselectoption.h" 10 | 11 | class CommandOwner; 12 | class TransferJob; 13 | class Race; 14 | 15 | enum JobType { 16 | JOBTYPE_TRANSFERJOB, 17 | JOBTYPE_SPREADJOB 18 | }; 19 | 20 | class SelectJobsScreen : public UIWindow { 21 | public: 22 | SelectJobsScreen(Ui *); 23 | void initialize(unsigned int, unsigned int, JobType); 24 | void redraw() override; 25 | bool keyPressed(unsigned int) override; 26 | std::string getLegendText() const override; 27 | std::string getInfoLabel() const override; 28 | std::string getInfoText() const override; 29 | static void addJobTableHeader(unsigned int, MenuSelectOption &, const std::string &); 30 | static void addJobDetails(unsigned int, MenuSelectOption &, std::shared_ptr); 31 | static void addJobDetails(unsigned int, MenuSelectOption &, std::shared_ptr); 32 | private: 33 | static void addTableRow(unsigned int, MenuSelectOption &, unsigned int, bool, const std::string &, const std::string &); 34 | MenuSelectOption table; 35 | bool hascontents; 36 | unsigned int currentviewspan; 37 | unsigned int ypos; 38 | int numselected; 39 | unsigned int totallistsize; 40 | JobType type; 41 | }; 42 | -------------------------------------------------------------------------------- /src/ui/screens/selectsitesscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../uiwindow.h" 10 | 11 | #include "../menuselectoption.h" 12 | 13 | class SiteManager; 14 | class MenuSelectOption; 15 | class Site; 16 | 17 | class SelectSitesScreen : public UIWindow { 18 | public: 19 | SelectSitesScreen(Ui *); 20 | void initializeSelect(unsigned int, unsigned int, const std::string &, std::list >, std::list >); 21 | void initializeExclude(unsigned int, unsigned int, const std::string &, std::list >, std::list >); 22 | void redraw() override; 23 | bool keyPressed(unsigned int) override; 24 | std::string getLegendText() const override; 25 | std::string getInfoLabel() const override; 26 | private: 27 | SiteManager * sm; 28 | MenuSelectOption mso; 29 | std::string purpose; 30 | std::list > tempsites; 31 | bool togglestate; 32 | }; 33 | -------------------------------------------------------------------------------- /src/ui/screens/sitesectionsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../uiwindow.h" 4 | #include "../menuselectoption.h" 5 | 6 | #include "../../site.h" 7 | 8 | class MenuSelectOptionElement; 9 | class Path; 10 | 11 | class SiteSectionsScreen : public UIWindow { 12 | public: 13 | SiteSectionsScreen(Ui *); 14 | ~SiteSectionsScreen(); 15 | void initialize(unsigned int row, unsigned int col, const std::shared_ptr & site); 16 | void redraw() override; 17 | bool keyPressed(unsigned int) override; 18 | std::string getLegendText() const override; 19 | std::string getInfoLabel() const override; 20 | std::string getInfoText() const override; 21 | private: 22 | void addSectionTableHeader(unsigned int y, MenuSelectOption & mso); 23 | void addSectionDetails(unsigned int y, MenuSelectOption & mso, const std::string & section, const Path & path); 24 | void addSectionTableRow(unsigned int y, MenuSelectOption & mso, bool selectable, 25 | const std::string & name, const std::string & path); 26 | MenuSelectOption table; 27 | std::shared_ptr site; 28 | std::shared_ptr sitecopy; 29 | unsigned int currentviewspan; 30 | unsigned int ypos; 31 | bool temphighlightline; 32 | bool hascontents; 33 | unsigned int totallistsize; 34 | }; 35 | -------------------------------------------------------------------------------- /src/ui/screens/siteslotsscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | class Site; 9 | class MenuSelectOptionElement; 10 | 11 | class SiteSlotsScreen : public UIWindow { 12 | public: 13 | SiteSlotsScreen(Ui *); 14 | ~SiteSlotsScreen(); 15 | void initialize(unsigned int row, unsigned int col, const std::shared_ptr & site); 16 | void redraw() override; 17 | bool keyPressed(unsigned int) override; 18 | std::string getLegendText() const override; 19 | std::string getInfoLabel() const override; 20 | private: 21 | std::shared_ptr modsite; 22 | bool active; 23 | std::shared_ptr activeelement; 24 | MenuSelectOption mso; 25 | }; 26 | -------------------------------------------------------------------------------- /src/ui/screens/sitestatusscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | 8 | class Site; 9 | class SiteLogic; 10 | 11 | class SiteStatusScreen : public UIWindow { 12 | public: 13 | SiteStatusScreen(Ui *); 14 | void initialize(unsigned int, unsigned int, std::string); 15 | void redraw() override; 16 | bool keyPressed(unsigned int) override; 17 | std::string getLegendText() const override; 18 | std::string getInfoLabel() const override; 19 | void command(const std::string& command, const std::string& arg) override; 20 | private: 21 | std::string sitename; 22 | std::shared_ptr site; 23 | std::shared_ptr st; 24 | int confirmaction; 25 | }; 26 | -------------------------------------------------------------------------------- /src/ui/screens/skiplistscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | #include "../../skiplist.h" 9 | 10 | class SkipList; 11 | class Ui; 12 | class FocusableArea; 13 | class MenuSelectAdjustableLine; 14 | class MenuSelectOptionTextField; 15 | class MenuSelectOptionTextArrow; 16 | class MenuSelectOptionElement; 17 | 18 | class SkipListScreen : public UIWindow { 19 | public: 20 | SkipListScreen(Ui *); 21 | ~SkipListScreen(); 22 | void initialize(unsigned int row, unsigned int col, SkipList * skiplist); 23 | void redraw() override; 24 | bool keyPressed(unsigned int) override; 25 | std::string getLegendText() const override; 26 | std::string getInfoLabel() const override; 27 | private: 28 | void initialize(); 29 | void saveToTempSkipList(); 30 | void addPatternLine(int y, bool regex, std::string pattern, bool file, bool dir, 31 | int scope, SkipListAction action, 32 | std::shared_ptr before = nullptr); 33 | bool keyUp() override; 34 | bool keyDown() override; 35 | int getCurrentScope() const; 36 | void recreateTable(); 37 | SkipList * skiplist; 38 | bool active; 39 | std::shared_ptr activeelement; 40 | MenuSelectOption base; 41 | MenuSelectOption table; 42 | FocusableArea * focusedarea; 43 | FocusableArea * defocusedarea; 44 | SkipList testskiplist; 45 | std::shared_ptr testpattern; 46 | std::shared_ptr testtype; 47 | std::shared_ptr testinspreadjob; 48 | unsigned int currentviewspan; 49 | bool globalskip; 50 | bool temphighlightline; 51 | }; 52 | -------------------------------------------------------------------------------- /src/ui/screens/snakescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | 9 | namespace Snake { 10 | 11 | struct Pos { 12 | unsigned int x; 13 | unsigned int y; 14 | }; 15 | 16 | enum class Direction { 17 | UP = 0, 18 | RIGHT = 1, 19 | DOWN = 2, 20 | LEFT = 3 21 | }; 22 | 23 | enum class Pixel { 24 | EMPTY, 25 | SNAKEPART, 26 | FRUIT 27 | }; 28 | 29 | enum class State { 30 | RUNNING, 31 | WON, 32 | LOST 33 | }; 34 | 35 | } 36 | 37 | class SnakeScreen : public UIWindow { 38 | public: 39 | SnakeScreen(Ui *); 40 | void initialize(unsigned int row, unsigned int col); 41 | void redraw() override; 42 | void update() override; 43 | bool keyPressed(unsigned int ch) override; 44 | std::string getLegendText() const override; 45 | std::string getInfoLabel() const override; 46 | std::string getInfoText() const override; 47 | private: 48 | void start(); 49 | void grow(); 50 | bool placeFruit(); 51 | void lose(); 52 | void win(); 53 | Snake::Pixel& getPixel(unsigned int y, unsigned int x); 54 | Snake::Pos getTarget(Snake::Direction direction) const; 55 | std::list snakepos; 56 | std::vector grid; 57 | Snake::Direction direction; 58 | Snake::Direction lastmoveddirection; 59 | int score; 60 | unsigned int xmax; 61 | unsigned int ymax; 62 | Snake::State state; 63 | int timepassed; 64 | }; 65 | -------------------------------------------------------------------------------- /src/ui/screens/transferjobstatusscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class TransferJob; 11 | class Ui; 12 | class TransferStatus; 13 | class MenuSelectOptionElement; 14 | 15 | class TransferJobStatusScreen : public UIWindow { 16 | public: 17 | TransferJobStatusScreen(Ui *); 18 | ~TransferJobStatusScreen(); 19 | bool initialize(unsigned int, unsigned int, unsigned int); 20 | void redraw() override; 21 | void command(const std::string &, const std::string &) override; 22 | bool keyPressed(unsigned int) override; 23 | std::string getLegendText() const override; 24 | std::string getInfoLabel() const override; 25 | static std::string getRoute(std::shared_ptr); 26 | private: 27 | void addTransferDetails(unsigned int, std::shared_ptr); 28 | void addTransferDetails(unsigned int, const std::string &, const std::string &, const std::string &, 29 | const std::string &, const std::string &, const std::string &, int); 30 | int getCurrentScope() const; 31 | std::shared_ptr transferjob; 32 | MenuSelectOption table; 33 | MenuSelectOption mso; 34 | std::map, int> progressmap; 35 | bool active; 36 | std::shared_ptr activeelement; 37 | }; 38 | -------------------------------------------------------------------------------- /src/ui/screens/transferpairingscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../uiwindow.h" 6 | #include "../menuselectoption.h" 7 | 8 | #include "../../transferpairing.h" 9 | 10 | class Ui; 11 | class MenuSelectAdjustableLine; 12 | class MenuSelectOptionTextField; 13 | class MenuSelectOptionTextArrow; 14 | class MenuSelectOptionElement; 15 | 16 | class TransferPairingScreen : public UIWindow { 17 | public: 18 | TransferPairingScreen(Ui* ui); 19 | ~TransferPairingScreen(); 20 | void initialize(unsigned int row, unsigned int col, TransferPairing* transferpairing); 21 | void redraw() override; 22 | bool keyPressed(unsigned int) override; 23 | std::string getLegendText() const override; 24 | std::string getInfoLabel() const override; 25 | private: 26 | void initialize(); 27 | //void addPatternLine(int y); 28 | TransferPairing* transferpairing; 29 | bool active; 30 | std::shared_ptr activeelement; 31 | MenuSelectOption table; 32 | unsigned int currentviewspan; 33 | bool temphighlightline; 34 | }; 35 | -------------------------------------------------------------------------------- /src/ui/screens/transfersfilterscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../uiwindow.h" 7 | #include "../menuselectoption.h" 8 | 9 | class TransferManager; 10 | class TransferStatus; 11 | class MenuSelectOptionElement; 12 | class CommandOwner; 13 | class Race; 14 | class TransferJob; 15 | struct TransferFilteringParameters; 16 | 17 | class TransfersFilterScreen : public UIWindow { 18 | public: 19 | TransfersFilterScreen(Ui *); 20 | ~TransfersFilterScreen(); 21 | void initialize(unsigned int, unsigned int, const TransferFilteringParameters &); 22 | void redraw() override; 23 | bool keyPressed(unsigned int) override; 24 | std::string getLegendText() const override; 25 | std::string getInfoLabel() const override; 26 | void command(const std::string & command, const std::string & arg) override; 27 | private: 28 | std::string getSpreadJobsText() const; 29 | std::string getTransferJobsText() const; 30 | MenuSelectOption mso; 31 | bool active; 32 | std::shared_ptr activeelement; 33 | std::list selectedspreadjobs; 34 | std::list selectedtransferjobs; 35 | }; 36 | -------------------------------------------------------------------------------- /src/ui/screens/transferstatusscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | #include "../menuselectoption.h" 9 | 10 | class Ui; 11 | class TransferStatus; 12 | class MenuSelectOptionElement; 13 | class TransferStatus; 14 | 15 | class TransferStatusScreen : public UIWindow { 16 | public: 17 | TransferStatusScreen(Ui *); 18 | ~TransferStatusScreen(); 19 | void initialize(unsigned int, unsigned int, std::shared_ptr); 20 | void redraw() override; 21 | bool keyPressed(unsigned int) override; 22 | std::string getLegendText() const override; 23 | std::string getInfoLabel() const override; 24 | static void abortTransfer(std::shared_ptr ts); 25 | private: 26 | std::shared_ptr ts; 27 | std::shared_ptr activeelement; 28 | std::string defaultlegendtext; 29 | std::string currentlegendtext; 30 | std::string abortedlegendtext; 31 | }; 32 | -------------------------------------------------------------------------------- /src/ui/screens/viewfilescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../uiwindow.h" 8 | 9 | #include "../../core/types.h" 10 | 11 | #include "../../encoding.h" 12 | #include "../../path.h" 13 | 14 | class TransferStatus; 15 | class SiteLogic; 16 | class FileList; 17 | class Ui; 18 | 19 | #define MAXOPENSIZE 524288 20 | 21 | class ViewFileScreen : public UIWindow { 22 | public: 23 | ViewFileScreen(Ui * ui); 24 | ~ViewFileScreen(); 25 | void initialize(unsigned int, unsigned int, const std::string &, const std::string &, const std::shared_ptr& fl); 26 | void initialize(unsigned int, unsigned int, const Path &, const std::string &); 27 | void redraw() override; 28 | void update() override; 29 | bool keyPressed(unsigned int) override; 30 | std::string getLegendText() const override; 31 | std::string getInfoLabel() const override; 32 | std::string getInfoText() const override; 33 | private: 34 | int getCurrentScope() const; 35 | int state; 36 | int requestid; 37 | std::shared_ptr sitelogic; 38 | std::shared_ptr ts; 39 | std::shared_ptr filelist; 40 | std::string site; 41 | std::string file; 42 | unsigned int x; 43 | unsigned int xmax; 44 | unsigned int y; 45 | unsigned int ymax; 46 | unsigned long long int size; 47 | bool externallyviewable; 48 | bool legendupdated; 49 | bool deleteafter; 50 | std::vector rawcontents; 51 | std::vector > translatedcontents; 52 | Path path; 53 | int pid; 54 | encoding::Encoding encoding; 55 | Core::BinaryData tmpdata; 56 | bool goDown(); 57 | bool goUp(); 58 | void printTransferInfo(); 59 | void translate(); 60 | void initialize(); 61 | void loadViewer(); 62 | void viewInternal(); 63 | void viewExternal(); 64 | }; 65 | -------------------------------------------------------------------------------- /src/ui/termint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fmtstring.h" 4 | 5 | struct _win_st; 6 | typedef struct _win_st WINDOW; 7 | 8 | #define BOX_HLINE 4194417 9 | #define BOX_HLINE_TOP 4194422 10 | #define BOX_HLINE_BOT 4194423 11 | #define BOX_VLINE 4194424 12 | #define BOX_VLINE_R 4194420 13 | #define BOX_VLINE_L 4194421 14 | #define BOX_CORNER_BR 4194410 15 | #define BOX_CORNER_BL 4194413 16 | #define BOX_CORNER_TL 4194412 17 | #define BOX_CORNER_TR 4194411 18 | #define BOX_CROSS 4194414 19 | #define BOX_MIN BOX_CORNER_BR 20 | #define BOX_MAX BOX_VLINE 21 | 22 | enum CursesSpecialKeys { 23 | TERMINT_CTRL_A = 1, 24 | TERMINT_CTRL_L = 12, 25 | TERMINT_HOME = 262, 26 | TERMINT_END = 360, 27 | TERMINT_SHIFT_DOWN = 336, 28 | TERMINT_SHIFT_UP = 337, 29 | TERMINT_SHIFT_LEFT = 393, 30 | TERMINT_SHIFT_RIGHT = 402, 31 | TERMINT_CTRL_DOWN = 524, 32 | TERMINT_CTRL_LEFT = 544, 33 | TERMINT_CTRL_RIGHT = 559, 34 | TERMINT_CTRL_UP = 565, 35 | TERMINT_CTRL_SHIFT_LEFT = 545, 36 | TERMINT_CTRL_SHIFT_RIGHT = 560 37 | }; 38 | 39 | class TermInt { 40 | private: 41 | static unsigned int cursorrow; 42 | static unsigned int cursorcol; 43 | static WINDOW * cursorwindow; 44 | public: 45 | static void printChar(WINDOW *, unsigned int, unsigned int, unsigned int); 46 | static void printStr(WINDOW *, unsigned int, unsigned int, const FmtString& str); 47 | static void printStr(WINDOW *, unsigned int, unsigned int, const FmtString& str, unsigned int); 48 | static void printStr(WINDOW *, unsigned int, unsigned int, const FmtString& str, unsigned int, bool); 49 | static void moveCursor(WINDOW *, unsigned int, unsigned int); 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /src/ui/textarrow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class TextArrow { 7 | public: 8 | TextArrow(); 9 | int getOption() const; 10 | std::string getOptionText() const; 11 | bool setOption(int); 12 | bool setOptionText(std::string); 13 | bool next(); 14 | bool previous(); 15 | std::string getVisual() const; 16 | void activate(); 17 | void deactivate(); 18 | bool isActive() const; 19 | void addOption(std::string, int); 20 | void clear(); 21 | private: 22 | bool active; 23 | std::vector > options; 24 | unsigned int currentpos; 25 | unsigned int maxlen; 26 | }; 27 | -------------------------------------------------------------------------------- /src/ui/textinputfield.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fmtstring.h" 4 | 5 | class TextInputField { 6 | public: 7 | TextInputField(); 8 | TextInputField(int, int); 9 | TextInputField(int, int, bool); 10 | TextInputField(const FmtString& starttext, int, int, bool); 11 | FmtString getText() const; 12 | FmtString getVisualText() const; 13 | unsigned int getVisualCursorPosition() const; 14 | bool addchar(char); 15 | void erase(); 16 | void eraseForward(); 17 | void eraseCursoredWord(); 18 | void eraseAllBefore(); 19 | bool moveCursorLeft(); 20 | bool moveCursorRight(); 21 | void moveCursorHome(); 22 | void moveCursorEnd(); 23 | void moveCursorPreviousWord(); 24 | void moveCursorNextWord(); 25 | void setText(const FmtString& text); 26 | void clear(); 27 | void setVisibleLength(unsigned int); 28 | private: 29 | void construct(const FmtString& starttext, int, int, bool); 30 | FmtString text; 31 | unsigned int cursor; 32 | bool secret; 33 | unsigned int maxlen; 34 | unsigned int visiblelen; 35 | }; 36 | -------------------------------------------------------------------------------- /src/ui/textwrap.cpp: -------------------------------------------------------------------------------- 1 | #include "textwrap.h" 2 | 3 | std::list TextWrap::wrap(const std::string & text, unsigned int linelen) { 4 | std::list out; 5 | size_t linestart = 0; 6 | size_t lastspace = 0; 7 | for (size_t i = 0; i < text.length(); i++) { 8 | if (text[i] != ' ' && i && i - linestart + 1 <= linelen) { 9 | continue; 10 | } 11 | if (i - linestart + 1 > linelen) { 12 | out.emplace_back(text.substr(linestart, lastspace - linestart)); 13 | i = lastspace; 14 | lastspace++; 15 | linestart = lastspace; 16 | } 17 | else if (i > linestart && text[i - 1] == '.') { 18 | out.emplace_back(text.substr(linestart, i - linestart)); 19 | lastspace = i + 1; 20 | linestart = lastspace; 21 | } 22 | else { 23 | lastspace = i; 24 | } 25 | } 26 | if (linestart < text.length()) { 27 | out.emplace_back(text.substr(linestart)); 28 | } 29 | return out; 30 | } 31 | -------------------------------------------------------------------------------- /src/ui/textwrap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class TextWrap { 7 | public: 8 | static std::list wrap(const std::string & text, unsigned int linelen); 9 | }; 10 | -------------------------------------------------------------------------------- /src/ui/uifile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class File; 6 | class LocalFile; 7 | 8 | class UIFile { 9 | private: 10 | std::string name; 11 | unsigned long long int size; 12 | std::string sizerepr; 13 | std::string owner; 14 | std::string group; 15 | std::string linktarget; 16 | int lastmodified; 17 | int lastmodifieddate; 18 | std::string lastmodifiedrepr; 19 | bool directory; 20 | bool softlink; 21 | bool softselected; 22 | bool hardselected; 23 | void parseTimeStamp(const std::string &); 24 | void parseUNIXTimeStamp(const std::string &, int &, int &, int &, int &, int &); 25 | void parseWindowsTimeStamp(const std::string &, int &, int &, int &, int &, int &); 26 | void setLastModified(int, int, int, int, int); 27 | public: 28 | UIFile(File *); 29 | UIFile(const LocalFile &); 30 | bool isDirectory() const; 31 | bool isLink() const; 32 | std::string getOwner() const; 33 | std::string getGroup() const; 34 | unsigned long long int getSize() const; 35 | std::string getSizeRepr() const; 36 | std::string getLastModified() const; 37 | int getModifyTime() const; 38 | int getModifyDate() const; 39 | std::string getName() const; 40 | std::string getLinkTarget() const; 41 | bool isSoftSelected() const; 42 | bool isHardSelected() const; 43 | void softSelect(); 44 | void hardSelect(); 45 | void unSoftSelect(); 46 | void unHardSelect(); 47 | }; 48 | -------------------------------------------------------------------------------- /src/ui/uiwindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "keybinds.h" 7 | 8 | class Ui; 9 | class VirtualView; 10 | 11 | class UIWindow { 12 | protected: 13 | bool isTop() const; 14 | std::string name; 15 | unsigned int row; 16 | unsigned int col; 17 | bool autoupdate; 18 | bool expectbackendpush; 19 | Ui * ui; 20 | VirtualView* vv; 21 | KeyBinds keybinds; 22 | bool allowimplicitgokeybinds; 23 | public: 24 | void init(unsigned int row, unsigned int col); 25 | UIWindow(Ui* ui, const std::string& name); 26 | virtual ~UIWindow(); 27 | virtual void redraw() = 0; 28 | void resize(unsigned int row, unsigned int col); 29 | virtual void update(); 30 | virtual void command(const std::string& command); 31 | virtual void command(const std::string& command, const std::string& arg); 32 | virtual std::string getInfoLabel() const; 33 | virtual std::string getInfoText() const; 34 | virtual std::string getLegendText() const; 35 | virtual std::basic_string getWideInfoLabel() const; 36 | virtual std::basic_string getWideInfoText() const; 37 | virtual std::basic_string getWideLegendText() const; 38 | bool keyPressedBase(unsigned int); 39 | virtual bool keyPressed(unsigned int); 40 | bool autoUpdate() const; 41 | bool expectBackendPush() const; 42 | virtual bool keyUp(); 43 | virtual bool keyDown(); 44 | }; 45 | -------------------------------------------------------------------------------- /src/ui/virtualviewelement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class VirtualViewElement { 4 | public: 5 | VirtualViewElement(); 6 | unsigned int getChar() const; 7 | bool getHighlight() const; 8 | bool getBold() const; 9 | int getColor() const; 10 | bool isModified() const; 11 | int getClearIteration() const; 12 | int getRedrawIteration() const; 13 | bool isClear() const; 14 | void set(unsigned int c, bool highlight, bool bold, int color, int cleariteration, int redrawiteration); 15 | void setHighlightOn(int cleariteration, int redrawiteration); 16 | void setHighlightOff(int cleariteration, int redrawiteration); 17 | void setColor(int color, int cleariteration, int redrawiteration); 18 | void setBoldOn(int cleariteration, int redrawiteration); 19 | void setBoldOff(int cleariteration, int redrawiteration); 20 | void render(); 21 | void clear(); 22 | private: 23 | unsigned int c; 24 | unsigned int newc; 25 | bool highlight; 26 | bool newhighlight; 27 | bool bold; 28 | bool newbold; 29 | int cleariteration; 30 | int redrawiteration; 31 | int newcleariteration; 32 | int newredrawiteration; 33 | int color; 34 | int newcolor; 35 | }; 36 | -------------------------------------------------------------------------------- /src/uibase.cpp: -------------------------------------------------------------------------------- 1 | #include "uibase.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | static UIBase * uibase = NULL; 8 | 9 | UIBase::UIBase() { 10 | assert(uibase == NULL); 11 | uibase = this; 12 | } 13 | 14 | UIBase::~UIBase() { 15 | 16 | } 17 | 18 | class UIBaseDefault : public UIBase { 19 | public: 20 | UIBaseDefault() { 21 | std::cout << "WARNING: cbftp was built without UI - falling back to UIBaseDefault." << std::endl; 22 | } 23 | bool init() { 24 | std::cout << "UIBase::init() called." << std::endl; 25 | return true; 26 | } 27 | void backendPush() { 28 | std::cout << "UIBase::backendPush() called." << std::endl; 29 | } 30 | void kill() { 31 | std::cout << "UIBase::kill() called." << std::endl; 32 | } 33 | void notify() { 34 | std::cout << (char)7 << std::endl; 35 | } 36 | }; 37 | 38 | UIBase * UIBase::instance() { 39 | if (uibase == NULL) { 40 | new UIBaseDefault(); 41 | } 42 | return uibase; 43 | } 44 | -------------------------------------------------------------------------------- /src/uibase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class UIBase { 4 | public: 5 | UIBase(); 6 | virtual ~UIBase(); 7 | static UIBase * instance(); 8 | virtual bool init() = 0; 9 | virtual void backendPush() = 0; 10 | virtual void kill() = 0; 11 | virtual void notify() = 0; 12 | }; 13 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define SIZEPOWER 1024 10 | #define SIZEDECIMALS 2 11 | 12 | namespace util { 13 | 14 | struct Result { 15 | Result(); 16 | Result(bool success, const std::string& error = ""); 17 | bool success; 18 | std::string error; 19 | }; 20 | 21 | std::string trim(const std::string &); 22 | std::list trim(const std::list & in); 23 | std::vector trim(const std::vector & in); 24 | std::string simpleTimeFormat(int); 25 | std::string & debugString(const char *); 26 | std::string parseSize(unsigned long long int); 27 | std::string getGroupNameFromRelease(const std::string &); 28 | std::string toLower(const std::string &); 29 | int wildcmp(const char *, const char *); 30 | int wildcmpCase(const char *, const char *); 31 | std::list split(const std::string& in, const std::string& sep = " "); 32 | std::vector splitVec(const std::string& in, const std::string& sep = " "); 33 | std::string join(const std::list& in, const std::string& sep = " "); 34 | std::string join(const std::vector& in, const std::string& sep = " "); 35 | std::string join(const std::set& in, const std::string& sep = " "); 36 | int chrstrfind(const char *, unsigned int, const char *, unsigned int); 37 | int chrfind(const char *, unsigned int, char); 38 | bool eightCharUserCompare(const std::string & a, const std::string & b); 39 | std::regex regexParse(const std::string & pattern); 40 | struct naturalComparator { 41 | bool operator()(const std::string& a, const std::string& b) const; 42 | }; 43 | } 44 | --------------------------------------------------------------------------------