X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_ziplink.cpp;h=7b1cb281c2c53651f559b02bedf9f7fb982c3566;hb=813bc55a8496875cef52e6da42d608e4d2fa35da;hp=479eaa12ede87972124827276b7e4ecdc1beda9c;hpb=d92a8cde88d6d119fa10ca52cf7f802a60323931;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_ziplink.cpp b/src/modules/extra/m_ziplink.cpp index 479eaa12e..7b1cb281c 100644 --- a/src/modules/extra/m_ziplink.cpp +++ b/src/modules/extra/m_ziplink.cpp @@ -2,33 +2,22 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -#include -#include - -#include "zlib.h" - -#include "inspircd_config.h" -#include "configreader.h" +#include "inspircd.h" +#include #include "users.h" #include "channels.h" #include "modules.h" - #include "socket.h" #include "hashcomp.h" -#include "inspircd.h" - #include "transport.h" /* $ModDesc: Provides zlib link support for servers */ @@ -148,7 +137,7 @@ class izip_session : public classbase class ModuleZLib : public Module { - izip_session sessions[MAX_DESCRIPTORS]; + izip_session* sessions; /* Used for stats z extensions */ float total_out_compressed; @@ -161,30 +150,30 @@ class ModuleZLib : public Module ModuleZLib(InspIRCd* Me) : Module::Module(Me) { - ServerInstance->PublishInterface("InspSocketHook", this); + ServerInstance->Modules->PublishInterface("BufferedSocketHook", this); + + sessions = new izip_session[ServerInstance->SE->GetMaxFds()]; total_out_compressed = total_in_compressed = 0; total_out_uncompressed = total_out_uncompressed = 0; + Implementation eventlist[] = { I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnStats, I_OnRequest }; + ServerInstance->Modules->Attach(eventlist, this, 7); } virtual ~ModuleZLib() { - ServerInstance->UnpublishInterface("InspSocketHook", this); + ServerInstance->Modules->UnpublishInterface("BufferedSocketHook", this); + delete[] sessions; } virtual Version GetVersion() { - return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION); + return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION); } - void Implements(char* List) - { - List[I_OnRawSocketConnect] = List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = 1; - List[I_OnStats] = List[I_OnRequest] = 1; - } - /* Handle InspSocketHook API requests */ - virtual char* OnRequest(Request* request) + /* Handle BufferedSocketHook API requests */ + virtual const char* OnRequest(Request* request) { ISHRequest* ISR = (ISHRequest*)request; if (strcmp("IS_NAME", request->GetId()) == 0) @@ -195,10 +184,10 @@ class ModuleZLib : public Module else if (strcmp("IS_HOOK", request->GetId()) == 0) { /* Attach to an inspsocket */ - char* ret = "OK"; + const char* ret = "OK"; try { - ret = ServerInstance->Config->AddIOHook((Module*)this, (InspSocket*)ISR->Sock) ? (char*)"OK" : NULL; + ret = ServerInstance->Config->AddIOHook((Module*)this, (BufferedSocket*)ISR->Sock) ? "OK" : NULL; } catch (ModuleException& e) { @@ -209,7 +198,7 @@ class ModuleZLib : public Module else if (strcmp("IS_UNHOOK", request->GetId()) == 0) { /* Detatch from an inspsocket */ - return ServerInstance->Config->DelIOHook((InspSocket*)ISR->Sock) ? (char*)"OK" : NULL; + return ServerInstance->Config->DelIOHook((BufferedSocket*)ISR->Sock) ? "OK" : NULL; } else if (strcmp("IS_HSDONE", request->GetId()) == 0) { @@ -229,7 +218,7 @@ class ModuleZLib : public Module } /* Handle stats z (misc stats) */ - virtual int OnStats(char symbol, userrec* user, string_list &results) + virtual int OnStats(char symbol, User* user, string_list &results) { if (symbol == 'z') { @@ -318,6 +307,7 @@ class ModuleZLib : public Module { /* Add it to the frame queue */ session->inbuf->AddData(compr, readresult); + total_in_compressed += readresult; /* Parse all completed frames */ int size = 0; @@ -327,8 +317,9 @@ class ModuleZLib : public Module session->d_stream.avail_in = 0; session->d_stream.next_out = (Bytef*)(buffer + offset); + /* If we cant call this, well, we're boned. */ if (inflateInit(&session->d_stream) != Z_OK) - return -EBADF; + return 0; while ((session->d_stream.total_out < count) && (session->d_stream.total_in < (unsigned int)size)) { @@ -337,15 +328,19 @@ class ModuleZLib : public Module break; } + /* Stick a fork in me, i'm done */ inflateEnd(&session->d_stream); - total_in_compressed += readresult; + /* Update counters and offsets */ total_size += session->d_stream.total_out; total_in_uncompressed += session->d_stream.total_out; offset += session->d_stream.total_out; } + /* Null-terminate the buffer -- this doesnt harm binary data */ buffer[total_size] = 0; + + /* Set the read size to the correct total size */ readresult = total_size; } @@ -392,7 +387,7 @@ class ModuleZLib : public Module return 0; } } - /* Finish the stream */ + /* Finish the stream */ for (session->c_stream.avail_out = 1; deflate(&session->c_stream, Z_FINISH) != Z_STREAM_END; session->c_stream.avail_out = 1); deflateEnd(&session->c_stream); @@ -424,13 +419,13 @@ class ModuleZLib : public Module return 0; else { - session->outbuf = ""; + session->outbuf.clear(); return 0; } } else { - session->outbuf = ""; + session->outbuf.clear(); return 0; } } @@ -443,35 +438,15 @@ class ModuleZLib : public Module void CloseSession(izip_session* session) { - if (session->status = IZIP_OPEN) + if (session->status == IZIP_OPEN) { session->status = IZIP_CLOSED; - session->outbuf = ""; + session->outbuf.clear(); delete session->inbuf; } } }; -class ModuleZLibFactory : public ModuleFactory -{ - public: - ModuleZLibFactory() - { - } - - ~ModuleZLibFactory() - { - } - - virtual Module * CreateModule(InspIRCd* Me) - { - return new ModuleZLib(Me); - } -}; - +MODULE_INIT(ModuleZLib) -extern "C" void * init_module( void ) -{ - return new ModuleZLibFactory; -}