I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList,
I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
- I_OnText, I_OnReadConfig, I_OnDownloadFile, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric,
+ I_OnText, I_OnReadConfig, I_OnDownloadFile, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookUserIO,
I_END
};
*/
virtual int OnDelBan(User* source, Channel* channel,const std::string &banmask);
+ virtual void OnHookUserIO(User* user);
+
/** Called immediately after any connection is accepted. This is intended for raw socket
* processing (e.g. modules which wrap the tcp connection within another library) and provides
* no information relating to a user record as the connection has not been assigned yet.
bool* AllowedChanModes;
public:
+ /** Module responsible for raw i/o
+ */
+ Module* io;
+
/** Contains a pointer to the connect class a user is on from - this will be NULL for remote connections.
* The pointer is guarenteed to *always* be valid. :)
*/
if (IS_LOCAL(u))
{
- if (ServerInstance->Config->GetIOHook(u->GetPort()))
+ if (u->io)
{
try
{
- ServerInstance->Config->GetIOHook(u->GetPort())->OnRawSocketClose(u->GetFd());
+ u->io->OnRawSocketClose(u->GetFd());
}
catch (CoreException& modexcept)
{
void Module::OnRunTestSuite() { }
void Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
int Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
+void Module::OnHookUserIO(User*) { }
ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
{
if (!user->GetExt("tls"))
return CMD_FAILURE;
- for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++)
- {
- if (ServerInstance->Config->ports[i]->GetDescription() == "ssl")
- {
- Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort());
- user->SetSockAddr(user->GetProtocolFamily(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort());
- break;
- }
- }
+ user->io = Caller;
+ Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort());
+
return CMD_FAILURE;
}
};
// Void return, guess we assume success
gnutls_certificate_set_dh_params(x509_cred, dh_params);
Implementation eventlist[] = { I_On005Numeric, I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup,
- I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnEvent };
- ServerInstance->Modules->Attach(eventlist, this, 16);
+ I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnEvent, I_OnHookUserIO };
+ ServerInstance->Modules->Attach(eventlist, this, 17);
starttls = new CommandStartTLS(ServerInstance, this);
ServerInstance->AddCommand(starttls);
delete tofree;
user->Shrink("ssl_cert");
}
+
+ user->io = NULL;
}
}
output.append(" SSL=" + sslports);
}
+ virtual void OnHookUserIO(User* user)
+ {
+ if (!user->io && isin(user->GetPort(), listenports))
+ {
+ /* Hook the user with our module */
+ user->io = this;
+ }
+ }
+
virtual const char* OnRequest(Request* request)
{
ISHRequest* ISR = (ISHRequest*)request;
// Needs the flag as it ignores a plain /rehash
OnRehash(NULL,"ssl");
Implementation eventlist[] = { I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup, I_On005Numeric,
- I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect };
- ServerInstance->Modules->Attach(eventlist, this, 15);
+ I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnHookUserIO };
+ ServerInstance->Modules->Attach(eventlist, this, 16);
+ }
+
+ virtual void OnHookUserIO(User* user)
+ {
+ if (!user->io && isin(user->GetPort(), listenports))
+ {
+ /* Hook the user with our module */
+ user->io = this;
+ }
}
virtual void OnRehash(User* user, const std::string ¶m)
delete tofree;
user->Shrink("ssl_cert");
}
+
+ user->io = NULL;
}
}
ServerInstance->SE->NonBlocking(incomingSockfd);
- if (ServerInstance->Config->GetIOHook(in_port))
- {
- try
- {
- ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, buf, in_port);
- }
- catch (CoreException& modexcept)
- {
- ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
- }
- }
ServerInstance->stats->statsAccept++;
ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
}
return;
}
- Instance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
-
- int j = 0;
-
- this->unregistered_count++;
-
char ipaddr[MAXBUF];
#ifdef IPV6
if (socketfamily == AF_INET6)
inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr));
else
#endif
- inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
+ inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
+
+
+ /* Give each of the modules an attempt to hook the user for I/O */
+ FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New));
+
+ if (New->io)
+ {
+ try
+ {
+ New->io->OnRawSocketAccept(socket, ipaddr, port);
+ }
+ catch (CoreException& modexcept)
+ {
+ ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+ }
+ }
+
+ Instance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
+
+ int j = 0;
+
+ this->unregistered_count++;
(*(this->clientlist))[New->uuid] = New;
char* ReadBuffer = Server->GetReadBuffer();
- if (Server->Config->GetIOHook(cu->GetPort()))
+ if (cu->io)
{
int result2 = 0;
int MOD_RESULT = 0;
try
{
- MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
+ MOD_RESULT = cu->io->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
}
catch (CoreException& modexcept)
{
Visibility = NULL;
ip = NULL;
MyClass = NULL;
+ io = NULL;
AllowedUserModes = NULL;
AllowedChanModes = NULL;
AllowedOperCommands = NULL;
return;
}
- if (ServerInstance->Config->GetIOHook(this->GetPort()))
+ if (this->io)
{
/* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
* implement their own buffering mechanisms
*/
try
{
- ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
+ this->io->OnRawSocketWrite(this->fd, text.data(), text.length());
}
catch (CoreException& modexcept)
{