]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/connection.cpp
Added documentation to manpages of Request, Event and ModuleMessage
[user/henk/code/inspircd.git] / src / connection.cpp
index ce166ace088913b8dde22d46f53464ee6e4d78a7..b197caef1a43097200e71771fece4e344a885e9c 100644 (file)
@@ -1,3 +1,19 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *                       E-mail:
+ *                <brain@chatspike.net>
+ *               <Craig@chatspike.net>
+ *     
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
 #include <connection.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <deque>
 #include "inspircd.h"
 #include "modules.h"
+#include "inspstring.h"
 
 using namespace std;
 
+
 extern std::vector<Module*> modules;
 extern std::vector<ircd_module*> factory;
 
 extern int MODCOUNT;
 
+extern time_t TIME;
+
 connection::connection()
 {
        fd = 0;
@@ -39,6 +59,18 @@ bool connection::CreateListener(char* host, int p)
                return false;
        }
 
+       setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&on,sizeof(on));
+       linger.l_onoff = 1;
+       linger.l_linger = 1;
+       setsockopt(fd,SOL_SOCKET,SO_LINGER,(const char*)&linger,sizeof(linger));
+       
+       // attempt to increase socket sendq and recvq as high as its possible
+       // to get them on linux.
+       int sendbuf = 32768;
+       int recvbuf = 32768;
+       setsockopt(fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf)); 
+       setsockopt(fd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
+
        memset((void*)&host_address, 0, sizeof(host_address));
 
        host_address.sin_family = AF_INET;
@@ -66,18 +98,6 @@ bool connection::CreateListener(char* host, int p)
 
        this->port = p;
 
-       setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&on,sizeof(on));
-       linger.l_onoff = 1;
-       linger.l_linger = 0;
-       setsockopt(fd,SOL_SOCKET,SO_LINGER,(const char*)&linger,sizeof(linger));
-       
-       // attempt to increase socket sendq and recvq as high as its possible
-       // to get them on linux.
-       int sendbuf = 32768;
-       int recvbuf = 32768;
-       setsockopt(fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf)); 
-       setsockopt(fd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
-       
        listen(this->fd,5);
 
        return true;
@@ -183,7 +203,7 @@ bool connection::BeginLink(char* targethost, int port, char* password, char* ser
                        // targethost has been turned into an ip...
                        // we dont want this as the server name.
                        connector.SetServerName(servername);
-                       sprintf(connect,"S %s %s %d %d :%s",getservername().c_str(),password,myport,GetRevision(),getserverdesc().c_str());
+                       snprintf(connect,MAXBUF,"S %s %s %d %d :%s",getservername().c_str(),password,myport,GetRevision(),getserverdesc().c_str());
                        connector.SetState(STATE_NOAUTH_OUTBOUND);
                        connector.SetHostAndPort(targethost, port);
                        this->connectors.push_back(connector);
@@ -213,7 +233,7 @@ bool connection::MeshCookie(char* targethost, int port, long cookie, char* serve
                        // targethost has been turned into an ip...
                        // we dont want this as the server name.
                        connector.SetServerName(servername);
-                       sprintf(connect,"- %d %s :%s",cookie,getservername().c_str(),getserverdesc().c_str());
+                       snprintf(connect,MAXBUF,"- %d %s :%s",cookie,getservername().c_str(),getserverdesc().c_str());
                        connector.SetState(STATE_NOAUTH_OUTBOUND);
                        connector.SetHostAndPort(targethost, port);
                        connector.SetState(STATE_CONNECTED);
@@ -331,11 +351,14 @@ void ircd_connector::SetDescriptor(int fd)
 
 bool connection::SendPacket(char *message, const char* host)
 {
+       if ((!message) || (!host))
+               return true;
+
        ircd_connector* cn = this->FindHost(host);
        
        if (!strchr(message,'\n'))
        {
-               strncat(message,"\n",MAXBUF);
+               strlcat(message,"\n",MAXBUF);
        }
 
        if (cn)
@@ -346,7 +369,7 @@ bool connection::SendPacket(char *message, const char* host)
                {
                        log(DEBUG,"Main route to %s is down, seeking alternative",host);
                        // fix: can only route one hop to avoid a loop
-                       if (strncat(message,"R ",2))
+                       if (strlcat(message,"R ",2))
                        {
                                // this route is down, we must re-route the packet through an available point in the mesh.
                                for (int k = 0; k < this->connectors.size(); k++)
@@ -430,7 +453,7 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host)
                                        if (strlen(sanitized))
                                        {
                                                messages.push_back(sanitized);
-                                               strncpy(host,this->connectors[i].GetServerName().c_str(),160);
+                                               strlcpy(host,this->connectors[i].GetServerName().c_str(),160);
                                                log(DEBUG,"main: Connection::RecvPacket() got '%s' from %s",sanitized,host);
                                                
                                        }
@@ -446,7 +469,6 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host)
 
 long connection::GenKey()
 {
-       srand(time(NULL));
        return (random()*time(NULL));
 }