From 7e843c22e16c81054bad18073d24fe1a07026431 Mon Sep 17 00:00:00 2001 From: danieldg Date: Thu, 8 Oct 2009 23:29:21 +0000 Subject: Update Event and Request APIs git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11808 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_ripemd160.cpp | 47 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'src/modules/m_ripemd160.cpp') diff --git a/src/modules/m_ripemd160.cpp b/src/modules/m_ripemd160.cpp index 1d3b1eb34..3e94efb0a 100644 --- a/src/modules/m_ripemd160.cpp +++ b/src/modules/m_ripemd160.cpp @@ -149,6 +149,8 @@ typedef uint32_t dword; } +const char* const chars = "0123456789abcdef"; + class ModuleRIPEMD160 : public Module { @@ -437,16 +439,11 @@ class ModuleRIPEMD160 : public Module return (byte *)hashcode; } - unsigned int* currkey; - const char* chars; - public: - ModuleRIPEMD160() : currkey(NULL), chars("0123456789abcdef") + ModuleRIPEMD160() { ServerInstance->Modules->PublishInterface("HashRequest", this); - Implementation eventlist[] = { I_OnRequest }; - ServerInstance->Modules->Attach(eventlist, this, 1); } virtual ~ModuleRIPEMD160() @@ -454,42 +451,26 @@ class ModuleRIPEMD160 : public Module ServerInstance->Modules->UnpublishInterface("HashRequest", this); } - - virtual const char* OnRequest(Request* request) + void OnRequest(Request& request) { - HashRequest* SHA = (HashRequest*)request; - if (strcmp("KEY", request->GetId()) == 0) - { - this->currkey = (unsigned int*)SHA->GetKeyData(); - } - else if (strcmp("HEX", request->GetId()) == 0) + if (strcmp("HASH", request.id) == 0) { - this->chars = SHA->GetOutputs(); - } - else if (strcmp("SUM", request->GetId()) == 0) - { - static char output[MAXBUF]; - unsigned char* data = (unsigned char*)RMD((byte *)SHA->GetHashData().data(),SHA->GetHashData().length(), currkey); + char res[41]; + HashRequest& req = static_cast(request); + unsigned char* data = (unsigned char*)RMD((byte*)req.data.data(), req.data.length(), NULL); int j = 0; for (int i = 0; i < RMDsize / 8; i++) { - output[j++] = chars[data[i] / 16]; - output[j++] = chars[data[i] % 16]; - ServerInstance->Logs->Log("m_ripemd160", DEBUG, "Hash: %02x", data[i]); + res[j++] = chars[data[i] / 16]; + res[j++] = chars[data[i] % 16]; } - output[j] = '\0'; - return output; - } - else if (strcmp("NAME", request->GetId()) == 0) - { - return "ripemd160"; + res[j] = '\0'; + req.result = res; } - else if (strcmp("RESET", request->GetId()) == 0) + else if (strcmp("NAME", request.id) == 0) { - this->chars = "0123456789abcdef"; - this->currkey = NULL; + static_cast(request).response = "ripemd160"; } - return NULL; } virtual Version GetVersion() -- cgit v1.2.3