]> Some of my projects - anidbudpclient.git/commitdiff
Make it possible to tell if a command's parameter combination will result in a valid...
authorAPTX <redacted>
Tue, 28 Feb 2012 19:35:44 +0000 (20:35 +0100)
committerAPTX <redacted>
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 9e13892..9d7d1a4 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 63e2cc2..0a71104 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 83e3129..d885f77 100644 (file)
@@ -46,6 +46,7 @@ namespace AniDBUdpClient
 
        enum ReplyCode
        {
+               INVALID_COMMAND                         = -2,
                CLIENT_DESTROYED                        = -1,
                UNKNOWN_REPLY                           = 0,
 
index 03f1e6a..6846181 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 4fa8836..18266e6 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 aa0496d..6edf2bb 100644 (file)
@@ -62,6 +62,7 @@ public:
        void setAmask(FileAnimeFlags amask);
 
        bool waitForResult() const;
+       bool isValid() const;
        Command rawCommand() const;
 
 private:
index 46e305e..cff7e92 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 637635e..749e9a3 100644 (file)
@@ -55,6 +55,7 @@ public:
        void setMyListState(const MyListState &state);
 
        bool waitForResult() const;
+       bool isValid() const;
 
        Command rawCommand() const;
 
index 336b1bf..4360df4 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 5de0082..261eaf5 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 8e8e78f..6ed6dbb 100644 (file)
@@ -41,6 +41,7 @@ public:
        void setEpno(int epno);
 
        bool waitForResult() const;
+       bool isValid() const;
        Command rawCommand() const;
 
 private: