]> jfr.im git - irc/rizon/znc.git/commitdiff
Make certauth use the CModCommand API
authorKyle Fuller <redacted>
Tue, 24 May 2011 12:14:41 +0000 (13:14 +0100)
committerKyle Fuller <redacted>
Wed, 25 May 2011 22:52:05 +0000 (23:52 +0100)
modules/certauth.cpp

index 337a51a1e90c637e9c16bc0f35efffc43e838252..80dbd7c1b9cd5c795baa812a4caa224492d69d13 100644 (file)
 
 class CSSLClientCertMod : public CGlobalModule {
 public:
-       GLOBALMODCONSTRUCTOR(CSSLClientCertMod) {}
+       GLOBALMODCONSTRUCTOR(CSSLClientCertMod) {
+               AddHelpCommand();
+               AddCommand("Add",  static_cast<CModCommand::ModCmdFunc>(&CSSLClientCertMod::HandleAddCommand));
+               AddCommand("Del",  static_cast<CModCommand::ModCmdFunc>(&CSSLClientCertMod::HandleDelCommand),
+                       "id");
+               AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CSSLClientCertMod::HandleListCommand));
+               AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CSSLClientCertMod::HandleShowCommand),
+                       "", "Print your current key");
+       }
+
        virtual ~CSSLClientCertMod() {}
 
        virtual bool OnBoot() {
@@ -109,80 +118,85 @@ public:
                return HALT;
        }
 
-       virtual void OnModCommand(const CString& sCommand) {
-               CString sCmd = sCommand.Token(0);
-
-               if (sCmd.Equals("show")) {
-                       CString sPubKey = GetKey(m_pClient);
-                       if (sPubKey.empty())
-                               PutModule("You are not connected with any valid public key");
-                       else
-                               PutModule("Your current public key is: " + sPubKey);
-               } else if (sCmd.Equals("add")) {
-                       CString sPubKey = GetKey(m_pClient);
-                       if (sPubKey.empty())
-                               PutModule("You are not connected with any valid public key");
-                       else {
-                               pair<SCString::iterator, bool> res = m_PubKeys[m_pUser->GetUserName()].insert(sPubKey);
-                               if (res.second) {
-                                       PutModule("Added your current public key to the list");
-                                       Save();
-                               } else
-                                       PutModule("Your key was already added");
-                       }
-               } else if (sCmd.Equals("list")) {
-                       CTable Table;
+       void HandleShowCommand(const CString& sLine) {
+               CString sPubKey = GetKey(m_pClient);
 
-                       Table.AddColumn("Id");
-                       Table.AddColumn("Key");
+               if (sPubKey.empty()) {
+                       PutModule("You are not connected with any valid public key");
+               } else {
+                       PutModule("Your current public key is: " + sPubKey);
+               }
+       }
 
-                       MSCString::iterator it = m_PubKeys.find(m_pUser->GetUserName());
-                       if (it == m_PubKeys.end()) {
-                               PutModule("No keys set for your user");
-                               return;
-                       }
+       void HandleAddCommand(const CString& sLine) {
+               CString sPubKey = GetKey(m_pClient);
 
-                       SCString::iterator it2;
-                       unsigned int id = 1;
-                       for (it2 = it->second.begin(); it2 != it->second.end(); it2++) {
-                               Table.AddRow();
-                               Table.SetCell("Id", CString(id++));
-                               Table.SetCell("Key", *it2);
+               if (sPubKey.empty()) {
+                       PutModule("You are not connected with any valid public key");
+               } else {
+                       pair<SCString::iterator, bool> res = m_PubKeys[m_pUser->GetUserName()].insert(sPubKey);
+                       if (res.second) {
+                               PutModule("Added your current public key to the list");
+                               Save();
+                       } else {
+                               PutModule("Your key was already added");
                        }
+               }
+       }
 
-                       if (PutModule(Table) == 0)
-                               // This double check is necessary, because the
-                               // set could be empty.
-                               PutModule("No keys set for your user");
-               } else if (sCmd.Equals("del") || sCmd.Equals("remove")) {
-                       unsigned int id = sCommand.Token(1, true).ToUInt();
-                       MSCString::iterator it = m_PubKeys.find(m_pUser->GetUserName());
-
-                       if (it == m_PubKeys.end()) {
-                               PutModule("No keys set for your user");
-                               return;
-                       }
+       void HandleListCommand(const CString& sLine) {
+               CTable Table;
 
-                       if (id == 0 || id > it->second.size()) {
-                               PutModule("Invalid #, check \"list\"");
-                               return;
-                       }
+               Table.AddColumn("Id");
+               Table.AddColumn("Key");
 
-                       SCString::iterator it2 = it->second.begin();
-                       while (id > 1) {
-                               it2++;
-                               id--;
-                       }
+               MSCString::iterator it = m_PubKeys.find(m_pUser->GetUserName());
+               if (it == m_PubKeys.end()) {
+                       PutModule("No keys set for your user");
+                       return;
+               }
+
+               SCString::iterator it2;
+               unsigned int id = 1;
+               for (it2 = it->second.begin(); it2 != it->second.end(); it2++) {
+                       Table.AddRow();
+                       Table.SetCell("Id", CString(id++));
+                       Table.SetCell("Key", *it2);
+               }
 
-                       it->second.erase(it2);
-                       if (it->second.size() == 0)
-                               m_PubKeys.erase(it);
-                       PutModule("Removed");
+               if (PutModule(Table) == 0) {
+                       // This double check is necessary, because the
+                       // set could be empty.
+                       PutModule("No keys set for your user");
+               }
+       }
 
-                       Save();
-               } else {
-                       PutModule("Commands: show, list, add, del [no]");
+       void HandleDelCommand(const CString& sLine) {
+               unsigned int id = sLine.Token(1, true).ToUInt();
+               MSCString::iterator it = m_PubKeys.find(m_pUser->GetUserName());
+
+               if (it == m_PubKeys.end()) {
+                       PutModule("No keys set for your user");
+                       return;
+               }
+
+               if (id == 0 || id > it->second.size()) {
+                       PutModule("Invalid #, check \"list\"");
+                       return;
                }
+
+               SCString::iterator it2 = it->second.begin();
+               while (id > 1) {
+                       it2++;
+                       id--;
+               }
+
+               it->second.erase(it2);
+               if (it->second.size() == 0)
+                       m_PubKeys.erase(it);
+               PutModule("Removed");
+
+               Save();
        }
 
        CString GetKey(Csock *pSock) {