diff --git a/docs/README.md b/docs/README.md index 6ca0331..f8cb2c8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -106,7 +106,7 @@ makeself Linux_build.sh is a custom script designed to build this project from the source code using qmake, make and makeself. You can pass 2 optional arguments: 1. The path to the QT bin folder in case you want to compile with a QT install not defined in PATH. -2. Path of the output makeself file (usually has a .run extension). If not given, the outfile will be named cmdr-1.0.0.run in the source code folder. +2. Path of the output makeself file (usually has a .run extension). If not given, the outfile will be named cmdr-x.x.x.run in the source code folder. Build: ``` @@ -115,6 +115,6 @@ sh ./linux_build.sh ``` Install: ``` -chmod +x ./cmdr-1.0.0.run -./cmdr-1.0.0.run +chmod +x ./cmdr-x.x.x.run +./cmdr-x.x.x.run ``` diff --git a/docs/type_ids.md b/docs/type_ids.md index 0559d1c..fb36019 100644 --- a/docs/type_ids.md +++ b/docs/type_ids.md @@ -1,6 +1,6 @@ ### 3.1 Type IDs ### -All mrci frames transferred to or from this application have an 8bit numeric value to indicate the type of data being passed with the binary data. The type id enum values are as follows: +All mrci frames transferred throughout this application have an 8bit numeric value to indicate the type of data being passed with the binary data. The type id enum values are as follows: ``` enum TypeID : quint8 @@ -47,7 +47,9 @@ format: ```[UTF-16LE_string] (no BOM)``` ```GEN_FILE``` This is a file transfer type id that can be used to transfer any file type (music, photos, documents, etc...). It operates in its own protocol of sorts. The 1st GEN_FILE frame received by the host or client is TEXT parameters similar to what you see in terminal command lines with at least one of the arguments listed below. The next set of GEN_FILE frames received by the host or client is then the binary data that needs to be written to an open file or streamed until the limit defined in -len is meet. -The host or the client can be set as the sender or receiver of the GEN_FILE binary data. Which ever is designated as the receiver by the TEXT parameters need to send an empty GEN_FILE frame to start the process. An example of this can be found in section 3.3. +The host or the client can be set as the sender or receiver of the GEN_FILE binary data. This designation is determined by what the command defined in genfile type when the NEW_CMD frame was sent. A genfile type of 2 sets the client as the sender and the host as the receiver. Genfile type 3 sets the client as the receiver and the host as the sender. + +see section 3.3 for an example of how GEN_FILE works. arguments: @@ -61,10 +63,6 @@ arguments: * **-single_step** | the presents of this argument tells both the client and host to operate in single step mode. single step mode causes the receiver of the binary data whether host or client to send an empty GEN_FILE frame after successfully receiving the data. this then tells the sender to send the next GEN_FILE frame containing binary data for the file and the cycle continues until len is meet. if this argument is not found, the sender can simply send all GEN_FILE data without waiting for an empty GEN_FILE from the receiver. -* **-to_host** | this argument should only come from the host and it will define the client as the sender and the host as the receiver. - -* **-from_host** | opposite affect to *-to_host*. it defines the host as the sender and the client as the receiver. - * **-truncate** | this indicates to whoever is the receiver to truncate the file being written to. * **-force** | in some cases, the receiver might need to overwrite the target file. the presents of this argument tells it to overwrite without asking the user. the host should never send this argument and the client should ignore it if it is received from the host. @@ -133,6 +131,7 @@ This is a data structure that carries information about a file system object (fi notes: 1. 16bit terminated UTF-16LE strings are basically terminated by 2 bytes of 0x00. + 2. the symmlink target is empty if not a symmlink but the terminator should still be present. @@ -161,9 +160,11 @@ This carry some user account and session information about a peer client connect notes: 1. the session id is unique to the peer's session connection only. it can change upon reconnection. + 2. the user id is unique to the peer's user account. is stays constant even when the user name changes and across all clients logged into the same account. + 3. the display name is the preffered display name of the peer. clients are encouraged to use this rather than the user name when displaying peer info to the user. if empty, it's ok to just fall back to the user @@ -189,7 +190,7 @@ This contains information about a new command that was added to the current sess ``` format: 1. bytes[0-1] 2bytes - 16bit LE unsigned int (command id) - 2. bytes[2] 1byte - bool (0x01 or 0x00) (handles gen file) + 2. bytes[2] 1byte - 8bit LE unsigned int (genfile type) 3. bytes[3-130] 128bytes - command name (TEXT - padded with 0x00) 4. bytes[131-258] 128bytes - library name (TEXT - padded with 0x00) 5. bytes[259-n] variable - short text (16bit null terminated) @@ -197,10 +198,13 @@ This contains information about a new command that was added to the current sess 7. bytes[n-n] variable - long text (16bit null terminated) notes: - 1. the handles gen file flag is a single byte 0x01 to indicate true and - 0x00 to indicate false. clients need to be aware of which command - handles the GEN_FILE mini protocol because it requires user input at - both ends (host and client). + 1. the genfile type is numerical value of 2, 3 or 0. a value of 2 + indicates that the command handles/understands the GEN_FILE mini + protocol and it can be used to upload a file or other data to the + host. a value of 3 indicates the commmand downloads a file or other + data from the host. 0 simply indicates that the command doesn't use + or understand GEN_FILE. + 2. the library name can contain the module name and/or extra informaion the client can use to identify the library the command is a part of. ``` @@ -233,6 +237,7 @@ This contain status information of a peer client when the peer changes sub-chann 1. if (is disconnected) is set true (0x01) the session id will no longer be valid for that peer client so you should not make anymore attempts to send data to it. + 2. channel-sub ids is a string of 9byte channel-sub id combinations at a fixed length of 54bytes (padded with 0x00). this indicates what channels-subs the peer currently have open if the peer's channel ids @@ -272,9 +277,8 @@ This contains public information about a channel member. notes: 1. a 16bit null terminated TEXT formatted string ended with 2 bytes of (0x00) to indicate the end of the string data. - 2. the member's privilege level can be any of the values discribed in - section [4.3](host_features.md). - 3. is invite? indicates if this user has received an invite to join + + 2. is invite? indicates if this user has received an invite to join that channel by has not accepted yet. if, accepted the user will become a full member of the channel at the level indicated by this data type. @@ -284,17 +288,19 @@ This contains public information about a channel member. Setup: -* The host has a command called *upload_file* with a command id of *768* and handles the ```GEN_FILE``` data type. +* The host has a command called *upload_file* with a command id of *768* and handles the ```GEN_FILE``` data type with a genfile type of 2. * The client has a file called */home/foo/bar.mp3* and wants to upload it to the host file */home/host/music/bar.mp3* and the client knows the file size is 512bytes. +Process: + To upload the file, the client calls command id *768* with the following text arguments (must still be sent as a GEN_FILE): ```-client_file "/home/foo/bar.mp3" -remote_file "/home/host/music/bar.mp3" -len 512``` -The host will then return the following the text arguments to the client (also sent as a GEN_FILE): -```-to_host``` +The host can then return text arguments to the client like (also sent as a GEN_FILE): +```-truncate and/or -single_step``` -This argument from the host designates it as the receiver so it will be up to the host to send an empty ```GEN_FILE``` to indicate to the client that it was ready to start receiving binary data from the client to write to */home/host/music/bar.mp3*. If that file already exists, the host will need to ask the user to overwrite or not. +This only needs to be done if the command call needs to be modified by host and if the client supports such a thing. In this example, host will just return an empty GEN_FILE because there is no need for modification. -If the host indicates that it's ready for the upload, the client can then simply read 512 bytes from */home/foo/bar.mp3* and send the read bytes to the host command id *768* as a ```GEN_FILE```. +At this point, the host will then need to check of the destination file: /home/host/music/bar.mp3 already exists. If it does, the host will need to ask the user if it's ok to overwrite. -The host will then write the bytes received from the client to */home/host/music/bar.mp3* and then auto terminate the command since 512 bytes has been meet. \ No newline at end of file +Once the host confirms it is ok to write to the destination file, it will then need to send another empty GEN_FILE to the client to confirm that it is ready to start receiving GEN_FILE frames from the client through command id *768* that will contain binary data to be written to the destination file until -len (512 bytes) is meet. \ No newline at end of file diff --git a/linux_build.sh b/linux_build.sh index e104c7b..6734813 100644 --- a/linux_build.sh +++ b/linux_build.sh @@ -5,7 +5,7 @@ installer_file="$2" src_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" bin_name="cmdr" -app_version="1.0.0" +app_version="2.2.0" app_name="Cmdr" install_dir="/opt/$bin_name" bin_dir="/usr/bin" @@ -55,6 +55,9 @@ if [ $? -eq 0 -a -d "$qt_dir" ]; then ldd ./$bin_name | grep "libicu" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib ldd ./$bin_name | grep "libssl" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib ldd ./$bin_name | grep "libcrypto" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib + ldd ./$bin_name | grep "libGL.so" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib + ldd ./$bin_name | grep "libpcre16.so" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib + ldd ./$bin_name | grep "libpcre.so" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ./build/lib mv -v ./$bin_name ./build/$bin_name cp -v $qt_dir/../plugins/platforms/libqxcb.so ./build/platforms/libqxcb.so cp -rfv ./icons ./build @@ -64,15 +67,11 @@ if [ $? -eq 0 -a -d "$qt_dir" ]; then cp -fv $qt_dir/../../libQt5DBus.so.5 ./build/lib/libQt5DBus.so.5 cp -fv $qt_dir/../../libQt5XcbQpa.so.5 ./build/lib/libQt5XcbQpa.so.5 - cp -fv $qt_dir/../../libGL.so ./build/lib/libGL.so - cp -fv $qt_dir/../../libpcre16.so.3 ./build/lib/libpcre16.so.3 else cp -fv $qt_dir/../lib/libQt5DBus.so.5 ./build/lib/libQt5DBus.so.5 cp -fv $qt_dir/../lib/libQt5XcbQpa.so.5 ./build/lib/libQt5XcbQpa.so.5 - cp -fv $qt_dir/../lib/libGL.so ./build/lib/libGL.so - cp -fv $qt_dir/../lib/libpcre16.so.3 ./build/lib/libpcre16.so.3 fi @@ -208,6 +207,10 @@ if [ $? -eq 0 -a -d "$qt_dir" ]; then fi +else + + echo "err: A valid Qt dir could not be found." + fi if [ -d "$tmp_dir" ]; then diff --git a/src/cmd_line.cpp b/src/cmd_line.cpp index 154939e..a525e13 100644 --- a/src/cmd_line.cpp +++ b/src/cmd_line.cpp @@ -176,7 +176,9 @@ void CmdLine::toHost(const QString &cmdName, const QString &args) } else if (Shared::genfileCmds->contains(cmdId)) { - emit dataToGenFile(cmdId, toTEXT(args)); + emit setHostCmdId(cmdId); + emit setGenfileType(Shared::genfileTypes->value(cmdId)); + emit dataToGenFile(toTEXT(args)); } else { @@ -223,7 +225,7 @@ void CmdLine::procCmdLine(const QString &line) if (flags & GEN_HOOK) { - emit dataToHookedGenFile(toTEXT(argsLine)); + emit dataToGenFile(toTEXT(argsLine)); } else if (Shared::clientCmds->contains(cmdName)) { diff --git a/src/cmd_line.h b/src/cmd_line.h index d60a405..932b5ac 100644 --- a/src/cmd_line.h +++ b/src/cmd_line.h @@ -63,8 +63,9 @@ signals: void dataToHookedCmdObj(const QString &argsLine); void dataToHost(quint16 cmdId, const QByteArray &data, uchar dType); void dataToHookedHost(const QByteArray &data, uchar dType); - void dataToGenFile(quint16 cmdId, const QByteArray &data); - void dataToHookedGenFile(const QByteArray &data); + void dataToGenFile(const QByteArray &data); + void setHostCmdId(quint16 cmdId); + void setGenfileType(quint8 typeId); void txtInCache(); }; diff --git a/src/cmd_objs/host_doc.cpp b/src/cmd_objs/host_doc.cpp index 075703e..cfccfcb 100644 --- a/src/cmd_objs/host_doc.cpp +++ b/src/cmd_objs/host_doc.cpp @@ -34,9 +34,10 @@ HostDoc::HostDoc(const QByteArray &import, QObject *parent) : Command(parent) setObjectName(cmdName + num); - if (import[2] == 0x01) + if ((import[2] == GEN_UPLOAD) || (import[2] == GEN_DOWNLOAD)) { Shared::genfileCmds->insert(cmdId, objectName()); + Shared::genfileTypes->insert(cmdId, static_cast(import[2])); } quint32 offs = 259; @@ -112,6 +113,7 @@ void HostDoc::cmdRemoved(quint16 id) Shared::hostCmds->remove(cmdId); Shared::hostDocs->remove(objectName()); Shared::genfileCmds->remove(cmdId); + Shared::genfileTypes->remove(cmdId); deleteLater(); } diff --git a/src/common.cpp b/src/common.cpp index c7848be..0a89172 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -388,6 +388,7 @@ QJsonObject *Shared::localData = nullptr; QHash *Shared::clientCmds = nullptr; QHash *Shared::hostCmds = nullptr; QHash *Shared::genfileCmds = nullptr; +QHash *Shared::genfileTypes = nullptr; QHash *Shared::hostDocs = nullptr; QStringList *Shared::hookBypass = nullptr; QByteArray *Shared::sessionId = nullptr; diff --git a/src/common.h b/src/common.h index 8dca158..0ecdbf6 100644 --- a/src/common.h +++ b/src/common.h @@ -68,13 +68,13 @@ #define DEFAULT_HIST_LIMIT 100 #define DEFAULT_MAX_LINES 1000 -#define RDBUFF 128000 +#define RDBUFF 16777215 #define TXT_CODEC "UTF-16LE" #define BOOKMARK_FOLDER "bookmarks" #define CONFIG_FILENAME "config.json" #define APP_NAME "Cmdr" #define APP_TARGET "cmdr" -#define APP_VERSION "2.1.0" +#define APP_VERSION "2.2.0" enum TypeID : quint8 { @@ -109,6 +109,12 @@ enum TypeID : quint8 RESUME_CMD = 29 }; +enum GenFileType : quint8 +{ + GEN_UPLOAD = 2, + GEN_DOWNLOAD = 3 +}; + enum AsyncCommands : quint16 { ASYNC_RDY = 1, // client | none @@ -203,6 +209,7 @@ public: static QHash *clientCmds; static QHash *hostCmds; static QHash *genfileCmds; + static QHash *genfileTypes; static QHash *hostDocs; static QList *idCache; static QList *txtCache; diff --git a/src/gen_file.cpp b/src/gen_file.cpp index 33544c2..eac032d 100644 --- a/src/gen_file.cpp +++ b/src/gen_file.cpp @@ -19,12 +19,11 @@ Genfile::Genfile(QObject *parent) : QObject(nullptr) { file = new QFile(this); - hook = 0; finished(); connect(parent, &QObject::destroyed, this, &QObject::deleteLater); - connect(this, &Genfile::rdFileLoop, this, &Genfile::hookedDataIn); + connect(this, &Genfile::rdFileLoop, this, &Genfile::dataIn); } void Genfile::cacheTxt(quint8 typeId, QString txt) @@ -39,22 +38,25 @@ void Genfile::cacheTxt(quint8 typeId, QString txt) void Genfile::finished() { - flags = 0; - bytesRW = 0; - hook = 0; - - localFile.clear(); - remoteFile.clear(); - len.clear(); - offs.clear(); - - if (file->isOpen()) + if (flags & ACTIVE) { - file->close(); - } + flags = 0; + bytesRW = 0; - emit unsetUserIO(GEN_HOOK); - emit enableGenFile(false); + localFile.clear(); + remoteFile.clear(); + len.clear(); + offs.clear(); + + if (file->isOpen()) + { + file->close(); + } + + emit unsetUserIO(GEN_HOOK); + emit enableGenFile(false); + emit termHostCmd(); + } } void Genfile::askOverwrite() @@ -80,7 +82,7 @@ bool Genfile::seekToOffset() if (!ok) { - cacheTxt(ERR, "err: Invalid offset was provided: " + offs + "\n"); + cacheTxt(ERR, "err: An invalid offset was provided: " + offs + "\n"); } ret = file->seek(pos); @@ -140,7 +142,7 @@ void Genfile::setupForWriting() } else { - emit hookedDataOut(QByteArray()); + emit dataOut(QByteArray()); } } @@ -188,7 +190,7 @@ bool Genfile::wrToFile(const QByteArray &data) } else if (flags & SINGLE_STEP_MODE) { - emit hookedDataOut(QByteArray()); + emit dataOut(QByteArray()); } } else @@ -224,7 +226,7 @@ bool Genfile::rdFromFile() ret = true; bytesRW += data.size(); - emit hookedDataOut(data); + emit dataOut(data); if (atEnd()) { @@ -243,41 +245,44 @@ bool Genfile::rdFromFile() return ret; } +void Genfile::setGenfileType(quint8 typeId) +{ + if (typeId == GEN_UPLOAD) + { + flags |= READ_MODE; + } + else if (typeId == GEN_DOWNLOAD) + { + flags |= WRITE_MODE; + } +} + QByteArray Genfile::autoFill(const QByteArray &data) { - len = QString::number(QFileInfo(localFile).size()); - QStringList args = parseArgs(data, -1); int ind = args.indexOf(QRegExp("-len", Qt::CaseInsensitive)); - if (ind != -1) + if (ind == -1) { - args.removeAt(ind); + len = QString::number(QFileInfo(localFile).size()); - if ((ind + 1) < args.size()) - { - args.removeAt(ind + 1); - } + args.append("-len"); + args.append(len); + + return toTEXT(args.join(' ')); + } + else + { + return data; } - - args.append("-len"); - args.append(len); - - return toTEXT(args.join(' ')); } -void Genfile::hookedDataIn(const QByteArray &data) -{ - dataIn(hook, data); -} - -void Genfile::dataIn(quint16 cmdId, const QByteArray &data) +void Genfile::dataIn(const QByteArray &data) { if (!(flags & CLIENT_PARAMS_RDY)) { QStringList args = parseArgs(data, -1); - hook = cmdId; localFile = getParam("-client_file", args); remoteFile = getParam("-remote_file", args); len = getParam("-len", args); @@ -289,9 +294,37 @@ void Genfile::dataIn(quint16 cmdId, const QByteArray &data) } flags |= CLIENT_PARAMS_RDY; + flags |= ACTIVE; emit enableGenFile(true); - emit dataOut(cmdId, autoFill(data)); + + if (flags & READ_MODE) + { + if (!argExists("-client_file", args)) + { + cacheTxt(ERR, "err: The client file (-client_file) argument was not found.\n"); + finished(); + + emit preCallTerm(); + } + else if (!QFile::exists(localFile)) + { + cacheTxt(ERR, "err: The client file: '" + localFile + "' does not exists.\n"); + finished(); + + emit preCallTerm(); + } + else + { + emit setUserIO(HOST_HOOK); + emit dataOut(autoFill(data)); + } + } + else + { + emit setUserIO(HOST_HOOK); + emit dataOut(data); + } } else if (!(flags & HOST_PARAMS_RDY)) { @@ -302,19 +335,24 @@ void Genfile::dataIn(quint16 cmdId, const QByteArray &data) flags |= SINGLE_STEP_MODE; } - if (args.contains("-truncate", Qt::CaseInsensitive)) - { - flags |= TRUNCATE; - } - - if (args.contains("-to_host", Qt::CaseInsensitive)) + if (flags & READ_MODE) { setupForReading(); flags |= HOST_PARAMS_RDY; } - else if (args.contains("-from_host", Qt::CaseInsensitive)) + else if (flags & WRITE_MODE) { + if (args.contains("-truncate", Qt::CaseInsensitive)) + { + flags |= TRUNCATE; + } + + if (args.contains("-len", Qt::CaseInsensitive)) + { + len = getParam("-len", args); + } + if (QFile::exists(localFile) && !(flags & DO_NOT_ASK)) { askOverwrite(); @@ -328,7 +366,7 @@ void Genfile::dataIn(quint16 cmdId, const QByteArray &data) } else { - cacheTxt(ERR, "err: The host did not return -to_host or -from_host, making this command call ambiguous.\n"); + cacheTxt(ERR, "err: The client doesn't know if this command call is an upload or download. this is a bug, please report it.\n"); finished(); } } @@ -340,7 +378,7 @@ void Genfile::dataIn(quint16 cmdId, const QByteArray &data) { emit unsetUserIO(GEN_HOOK); - flags ^= CONFIRM_NEEDED; + flags &= ~CONFIRM_NEEDED; setupForWriting(); } diff --git a/src/gen_file.h b/src/gen_file.h index d158b41..aaf41ca 100644 --- a/src/gen_file.h +++ b/src/gen_file.h @@ -25,7 +25,7 @@ class Genfile : public QObject private: - enum GenfileFlags + enum GenfileFlags : uint { CLIENT_PARAMS_RDY = 1, HOST_PARAMS_RDY = 1 << 1, @@ -34,7 +34,8 @@ private: DO_NOT_ASK = 1 << 4, CONFIRM_NEEDED = 1 << 5, WRITE_MODE = 1 << 6, - READ_MODE = 1 << 7 + READ_MODE = 1 << 7, + ACTIVE = 1 << 8 }; uint flags; @@ -61,8 +62,8 @@ private: public slots: void finished(); - void hookedDataIn(const QByteArray &data); - void dataIn(quint16 cmdId, const QByteArray &data); + void setGenfileType(quint8 typeId); + void dataIn(const QByteArray &data); public: @@ -71,11 +72,12 @@ public: signals: void txtInCache(); + void termHostCmd(); + void preCallTerm(); void enableGenFile(bool state); void setUserIO(int flgs); void unsetUserIO(int flgs); - void dataOut(quint16 cmdId, const QByteArray &data, uchar typeID = GEN_FILE); - void hookedDataOut(const QByteArray &data, uchar typeID = GEN_FILE); + void dataOut(const QByteArray &data, quint8 typeID = GEN_FILE); void rdFileLoop(QByteArray data = QByteArray()); }; diff --git a/src/main.cpp b/src/main.cpp index fe02173..c4b8d88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) QString hostAddress; QStringList hookBypass; QHash genfileCmds; + QHash genfileTypes; QHash clientCmds; QHash hostDocs; QHash hostCmds; @@ -70,6 +71,7 @@ int main(int argc, char *argv[]) Shared::connectedToHost = &connected; Shared::genfileCmds = &genfileCmds; + Shared::genfileTypes = &genfileTypes; Shared::clientCmds = &clientCmds; Shared::hostCmds = &hostCmds; Shared::hostDocs = &hostDocs; @@ -124,6 +126,8 @@ int main(int argc, char *argv[]) Shared::mainWin->setCmdLine(Shared::cmdLine); Shared::mainWin->showUi(); + QDir::setCurrent(QDir::homePath()); + return app.exec(); } @@ -202,9 +206,10 @@ void setupCmdLine() QObject::connect(cmdLine, &CmdLine::dataToHost, session, &Session::binToServer); QObject::connect(cmdLine, &CmdLine::dataToHookedHost, session, &Session::hookedBinToServer); + QObject::connect(cmdLine, &CmdLine::setHostCmdId, session, &Session::setCmdHook); QObject::connect(cmdLine, &CmdLine::dataToGenFile, genFile, &Genfile::dataIn); - QObject::connect(cmdLine, &CmdLine::dataToHookedGenFile, genFile, &Genfile::hookedDataIn); + QObject::connect(cmdLine, &CmdLine::setGenfileType, genFile, &Genfile::setGenfileType); QObject::connect(cmdLine, &CmdLine::txtInCache, textWorker, &TextWorker::dumpTxtCache); } @@ -218,9 +223,10 @@ void setupGenFile() ThreadKiller *killer = Shared::theadKiller; QThread *genThr = new QThread(QCoreApplication::instance()); - QObject::connect(genFile, &Genfile::dataOut, session, &Session::binToServer); - QObject::connect(genFile, &Genfile::hookedDataOut, session, &Session::hookedBinToServer); + QObject::connect(genFile, &Genfile::termHostCmd, session, &Session::termHostCmd); + QObject::connect(genFile, &Genfile::dataOut, session, &Session::hookedBinToServer); QObject::connect(genFile, &Genfile::enableGenFile, session, &Session::enableGenFile); + QObject::connect(genFile, &Genfile::preCallTerm, session, &Session::idle); QObject::connect(genFile, &Genfile::setUserIO, cmdLine, &CmdLine::setFlags); QObject::connect(genFile, &Genfile::unsetUserIO, cmdLine, &CmdLine::unsetFlags); @@ -244,7 +250,7 @@ void setupSession() QThread *sesThr = new QThread(QCoreApplication::instance()); QObject::connect(session, &Session::hostFinished, genFile, &Genfile::finished); - QObject::connect(session, &Session::toGenFile, genFile, &Genfile::hookedDataIn); + QObject::connect(session, &Session::toGenFile, genFile, &Genfile::dataIn); QObject::connect(session, &Session::setUserIO, cmdLine, &CmdLine::setFlags); QObject::connect(session, &Session::unsetUserIO, cmdLine, &CmdLine::unsetFlags); diff --git a/src/session.cpp b/src/session.cpp index 17c44bb..5c780af 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -63,6 +63,11 @@ void Session::binToServer(quint16 cmdId, const QByteArray &data, quint8 typeId) } } +void Session::setCmdHook(quint16 cmdId) +{ + hook = cmdId; +} + void Session::sockerr(QAbstractSocket::SocketError err) { if (err == QAbstractSocket::RemoteHostClosedError) @@ -141,6 +146,7 @@ void Session::isDisconnected() Shared::sessionId->clear(); Shared::hostCmds->clear(); Shared::genfileCmds->clear(); + Shared::genfileTypes->clear(); cacheTxt(TEXT, "\nHost session ended. (disconnected)\n\n"); @@ -291,6 +297,23 @@ void Session::cacheTxt(quint8 typeId, QString txt) } } +void Session::idle() +{ + emit hostFinished(); + emit unsetUserIO(HOST_HOOK); + + if (Shared::hostCmds->contains(hook)) + { + cacheTxt(TEXT, "\nFinished: " + Shared::hostCmds->value(hook) + "\n\n"); + } + else + { + cacheTxt(TEXT, "\nFinished: Unknown\n\n"); + } + + hook = 0; +} + void Session::dataFromHost(const QByteArray &data) { if (isAsync(cmdId)) @@ -305,19 +328,7 @@ void Session::dataFromHost(const QByteArray &data) } else if (dType == IDLE) { - hook = 0; - - emit hostFinished(); - emit unsetUserIO(HOST_HOOK); - - if (Shared::hostCmds->contains(cmdId)) - { - cacheTxt(TEXT, "\nFinished: " + Shared::hostCmds->value(cmdId) + "\n\n"); - } - else - { - cacheTxt(TEXT, "\nFinished: Unknown\n\n"); - } + idle(); } else if ((dType == GEN_FILE) && (flags & GEN_FILE_ON)) { diff --git a/src/session.h b/src/session.h index 3828b8d..b4702f7 100644 --- a/src/session.h +++ b/src/session.h @@ -87,6 +87,8 @@ public slots: void hookedBinToServer(const QByteArray &data, quint8 typeId); void binToServer(quint16 cmdId, const QByteArray &data, quint8 typeId); void enableGenFile(bool state); + void setCmdHook(quint16 cmdId); + void idle(); void termHostCmd(); void haltHostCmd(); void resumeHostCmd();