]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/connection.h
Removed __single_client_alloc again because gcc devs were smoking crack and removed it
[user/henk/code/inspircd.git] / include / connection.h
index eaa995f897c1f762c3f83ada22b9a7f349407569..b84d39df9b42b623270980d91dfd2601eae94696 100644 (file)
@@ -1,13 +1,25 @@
-/*
-
-*/
+/*       +------------------------------------+
+ *       | 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 "inspircd_config.h"
 #include "base.h"
 #include <string>
 #include <map>
-#include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <unistd.h>
@@ -15,6 +27,7 @@
 #include <time.h>
 #include <vector>
 #include <deque>
+#include <sstream>
 
 #ifndef __CONNECTION_H__
 #define __CONNECTION_H__
@@ -26,6 +39,8 @@
 #define STATE_NOAUTH_OUTBOUND  4
 #define STATE_SERVICES         5
 
+std::string CreateSum();
+
 /** Each connection has one or more of these
  * each represents ONE outbound connection to another ircd
  * so each inbound has multiple outbounds. A listening socket
@@ -38,7 +53,7 @@
  * connection(s) relating to the server you want information on.
  * The core and module API provide functions for this.
  */
-class ircd_connector : public classbase
+class ircd_connector : public Extensible
 {
  private:
        /** Sockaddr of the outbound ip and port
@@ -60,13 +75,24 @@ class ircd_connector : public classbase
        /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
         * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
         */
-       int state;
+       char state;
        
        /** PRIVATE function to set the host address and port to connect to
         */
        bool SetHostAddress(char* host, int port);
 
+       /** This string holds the ircd's version response
+        */
+       std::string version;
+
  public:
+
+        /** IRCD Buffer for input characters, holds as many lines as are
+        * pending - Note that the final line may not be complete and should
+        * only be read when there is a \n seperator.
+         */
+        std::string ircdbuffer;
+
  
        /** When MakeOutboundConnection is called, these public members are
         * filled with the details passed to the function, for future
@@ -89,7 +115,7 @@ class ircd_connector : public classbase
 
        /** Create an outbound connection to a listening socket
         */ 
-       bool MakeOutboundConnection(char* host, int port);
+       bool MakeOutboundConnection(char* newhost, int newport);
        
        /** Return the servername on this established connection
         */
@@ -140,22 +166,47 @@ class ircd_connector : public classbase
        
        /** Set both the host and the port in one operation for this connection
         */
-       bool SetHostAndPort(char* host, int port);
+       bool SetHostAndPort(char* newhost, int newport);
        
        /** Close the connection by calling close() on its file descriptor
         * This function call updates no other data.
         */
        void CloseConnection();
-};
 
+       /** This method adds text to the ircd connection's buffer
+        * There is no limitation on how much text of what line width may
+        * be added to this buffer. It is the sending server's responsibility
+        * to ensure sent data is kept within reasonable quanities.
+        */
+       void AddBuffer(std::string a);
 
-/** Class packet is deprecated.
- * This declaration is preserved here to maintain documentation only.
- */
-class packet : public classbase
-{
+       /** This method returns true if the buffer contains at least one
+        * carriage return character, e.g. one line can be read from the
+        * buffer successfully.
+        */
+       bool BufferIsComplete();
+
+       /** This method clears the server's buffer by setting it to an empty string.
+        */
+       void ClearBuffer();
+
+       /** This method retrieves the first string from the tail end of the
+        * buffer and advances the tail end of the buffer past the returned
+        * string, in a similar manner to strtok().
+        */
+       std::string GetBuffer();
+
+       /** This method sets the version string of the remote server
+        */
+        void SetVersionString(std::string newversion);
+
+       /** This method returns the version string of the remote server.
+        * If the server has no version string an empty string is returned.
+        */
+        std::string GetVersionString();
 };
 
+
 /** Please note: classes serverrec and userrec both inherit from class connection.
  */
 class connection : public Extensible
@@ -167,15 +218,11 @@ class connection : public Extensible
        
        /** Hostname of connection. Not used if this is a serverrec
         */
-       char host[256];
-       
-       /** IP of connection. Reserved for future use.
-        */
-       char ip[32];
+       char host[160];
        
-       /** Inbuf of connection. Only used for userrec
+       /** IP of connection.
         */
-       char inbuf[MAXBUF];
+       char ip[16];
        
        /** Stats counter for bytes inbound
         */
@@ -205,11 +252,7 @@ class connection : public Extensible
        
        /** Used by userrec to indicate the registration status of the connection
         */
-       int registered;
-       
-       /** Reserved for future use
-        */
-       short int state;
+       char registered;
        
        /** Time the connection was last pinged
         */
@@ -227,14 +270,6 @@ class connection : public Extensible
         */
        time_t nping;
        
-       /** Unused, will be removed in a future alpha/beta
-        */
-       char internal_addr[MAXBUF];
-       
-       /** Unused, will be removed in a future alpha/beta
-        */
-       int internal_port;
-
        /** With a serverrec, this is a list of all established server connections.
         * With a userrec this is unused.
         */
@@ -254,7 +289,7 @@ class connection : public Extensible
        
        /** Begin an outbound mesh link to another ircd on a network you are already an authenticated member of
         */
-       bool MeshCookie(char* targethost, int port, long cookie, char* servername);
+       bool MeshCookie(char* targethost, int port, unsigned long cookie, char* servername);
        
        /** Terminate a link to 'targethost' by calling the ircd_connector::CloseConnection method.
         */
@@ -269,7 +304,7 @@ class connection : public Extensible
         * If no data is available this function returns false.
         * This function will automatically close broken links and reroute pathways, generating split messages on the network.
         */
-       bool RecvPacket(std::deque<std::string> &messages, char* host);
+       bool RecvPacket(std::deque<std::string> &messages, char* host, std::deque<std::string> &sums);
        
        /** Find the ircd_connector oject related to a certain servername given in 'host'
         */
@@ -280,11 +315,7 @@ class connection : public Extensible
         */
        bool AddIncoming(int fd,char* targethost, int sourceport);
        
-       /** This function is deprecated and may be removed in a later alpha/beta
-        */
-       long GenKey();
 };
 
 
 #endif
-