]> Some of my projects - anidbudpclient.git/commitdiff
Make it possible to tell if a command's parameter combination will result in a valid...
authorAPTX <marek321@gmail.com>
Tue, 28 Feb 2012 19:35:44 +0000 (20:35 +0100)
committerAPTX <marek321@gmail.com>
Tue, 28 Feb 2012 19:35:44 +0000 (20:35 +0100)
abstractcommand.cpp
abstractcommand.h
anidbudpclient_global.h
client.cpp
filecommand.cpp
filecommand.h
mylistaddcommand.cpp
mylistaddcommand.h
mylistcommand.h
votecommand.cpp
votecommand.h

index 9e13892154bfbe215568ac9cd28319778ca158a4..9d7d1a4fed421e43741582536380fff7af673496 100644 (file)
@@ -25,6 +25,11 @@ bool AbstractCommand::requiresSession() const
        return true;
 }
 
+bool AbstractCommand::isValid() const
+{
+       return true;
+}
+
 // ===
 
 AbstractReply::AbstractReply(const QByteArray &id, QObject *parent) : QObject(parent)
index 63e2cc28a3e4c2a04908d57abe0f38beede9b0fe..0a71104c6f775c82bb4bdd7a0762e4d040dfbc53 100644 (file)
@@ -31,6 +31,7 @@ public:
         **/
        virtual bool waitForResult() const;
        virtual bool requiresSession() const;
+       virtual bool isValid() const;
 };
 
 #define REPLY_DEFINITION_HELPER_INTERNAL(name, constructor) \
index 83e31294b441e513813d00aae1a0decea171586c..d885f77f0cb4b21fee1080eb4eda4a3dd0429f99 100644 (file)
@@ -46,6 +46,7 @@ namespace AniDBUdpClient
 
        enum ReplyCode
        {
+               INVALID_COMMAND                         = -2,
                CLIENT_DESTROYED                        = -1,
                UNKNOWN_REPLY                           = 0,
 
index 03f1e6ae45a125b58a610a01c847b4841fe16286..684618133636584ce54f08273fd0a625aaf6894a 100644 (file)
@@ -1093,6 +1093,14 @@ void Client::enqueueControlCommand(AbstractReply *command, bool first)
 
 void Client::sendCommand(AbstractReply *command, bool controlCommand)
 {
+       if (!command->command().isValid())
+       {
+               command->setRawReply(INVALID_COMMAND, QString());
+               if (!command->command().waitForResult())
+                       command->deleteLater();
+               return;
+       }
+
        if (m_enableEncryption && command->command().requiresSession() && (m_salt.isEmpty() || !usingEncryption))
        {
                if (controlCommand)
index 4fa8836ba4a26ad4198b0e664aa23fdb1da0a597..18266e65a52afe223ccc1abf3820fc2e795bdcbc 100644 (file)
@@ -174,6 +174,14 @@ bool FileCommand::waitForResult() const
        return true;
 }
 
+bool FileCommand::isValid() const
+{
+       const bool validAnameGE = !m_aname.isEmpty() && (!m_gname.isEmpty() && m_epno || m_gid && m_epno);
+       const bool validAidGE = m_aid && ((!m_gname.isEmpty() && m_epno) || (m_gid && m_epno));
+       return (m_fid || (!m_ed2k.isEmpty() && m_size) || validAnameGE || validAidGE);
+       // fmask & amask don't need to be checked as all invalid bits are removed
+}
+
 Command FileCommand::rawCommand() const
 {
        Command cmd;
index aa0496d060c856ac4f6fe8c9f2050ccbf627661a..6edf2bb4a4c67f88cddd6401db2ed9a8c45ab55a 100644 (file)
@@ -62,6 +62,7 @@ public:
        void setAmask(FileAnimeFlags amask);
 
        bool waitForResult() const;
+       bool isValid() const;
        Command rawCommand() const;
 
 private:
index 46e305eb02818c407d0444ab49317fdfb8303785..cff7e92830f8de2803c3322c7abfc986e6b071d4 100644 (file)
@@ -114,6 +114,11 @@ bool MyListAddCommand::waitForResult() const
        return true;
 }
 
+bool MyListAddCommand::isValid() const
+{
+       return m_fid || (!m_ed2k.isEmpty() && m_size) || (m_lid && m_edit);
+}
+
 Command MyListAddCommand::rawCommand() const
 {
        Command cmd;
index 637635e6b46410db571cd4ea83317fda397394bb..749e9a3ad5e486bdcdfd92232b01215c07d894ac 100644 (file)
@@ -55,6 +55,7 @@ public:
        void setMyListState(const MyListState &state);
 
        bool waitForResult() const;
+       bool isValid() const;
 
        Command rawCommand() const;
 
index 336b1bf6c35a7adc73103247412bcc95adf9f17e..4360df464a66add0286c4d63806037ff7a5ace52 100644 (file)
@@ -49,7 +49,6 @@ public:
 \r
        bool waitForResult() const;\r
        Command rawCommand() const;\r
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);\r
 \r
 private:\r
        void init();\r
index 5de008287059126c6b828bda3ac9352abd1bc66e..261eaf5e4f973a2eb7039fa4ebc4c9cab036b0fd 100644 (file)
@@ -85,6 +85,13 @@ bool VoteCommand::waitForResult() const
        return true;
 }
 
+bool VoteCommand::isValid() const
+{
+       return (m_id || !m_name.isEmpty())
+                       && (m_epno && m_voteType == AnimeVote || !m_epno);
+       // Value is set to 0 if not in valid range
+}
+
 Command VoteCommand::rawCommand() const
 {
        Command cmd;
index 8e8e78f436e9774d7ccdc2e6a758ffa63948b8eb..6ed6dbb9fc9f75986ff3ed8ea60cf9001ff5af1d 100644 (file)
@@ -41,6 +41,7 @@ public:
        void setEpno(int epno);
 
        bool waitForResult() const;
+       bool isValid() const;
        Command rawCommand() const;
 
 private: