* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2008 InspIRCd Development Team
* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
class ModuleZLib : public Module
{
- izip_session sessions[MAX_DESCRIPTORS];
+ izip_session* sessions;
/* Used for stats z extensions */
float total_out_compressed;
float total_in_compressed;
float total_out_uncompressed;
float total_in_uncompressed;
-
+
public:
-
+
ModuleZLib(InspIRCd* Me)
: Module::Module(Me)
{
- ServerInstance->Modules->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->Modules->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)
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)
{
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)
{
virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
{
izip_session* session = &sessions[fd];
-
+
/* allocate state and buffers */
session->fd = fd;
session->status = IZIP_OPEN;
/* Add it to the frame queue */
session->inbuf->AddData(compr, readresult);
total_in_compressed += readresult;
-
+
/* Parse all completed frames */
int size = 0;
while ((size = session->inbuf->GetFrame(compr, CHUNK)) != 0)
/* If we cant call this, well, we're boned. */
if (inflateInit(&session->d_stream) != Z_OK)
return 0;
-
+
while ((session->d_stream.total_out < count) && (session->d_stream.total_in < (unsigned int)size))
{
session->d_stream.avail_in = session->d_stream.avail_out = 1;
if (inflate(&session->d_stream, Z_NO_FLUSH) == Z_STREAM_END)
break;
}
-
+
/* Stick a fork in me, i'm done */
inflateEnd(&session->d_stream);
*/
return ocount;
}
-
+
void CloseSession(izip_session* session)
{
if (session->status == IZIP_OPEN)
};
-MODULE_INIT(ModuleZLib);
+MODULE_INIT(ModuleZLib)