Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

connection.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
00006  *                       E-mail:
00007  *                <brain@chatspike.net>
00008  *                <Craig@chatspike.net>
00009  *     
00010  * Written by Craig Edwards, Craig McLure, and others.
00011  * This program is free but copyrighted software; see
00012  *            the file COPYING for details.
00013  *
00014  * ---------------------------------------------------
00015  */
00016 
00017 #include "inspircd_config.h"
00018 #include "base.h"
00019 #include <string>
00020 #include <map>
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <netdb.h>
00024 #include <netinet/in.h>
00025 #include <unistd.h>
00026 #include <errno.h>
00027 #include <time.h>
00028 #include <vector>
00029 #include <deque>
00030 #include <sstream>
00031 
00032 #ifndef __CONNECTION_H__
00033 #define __CONNECTION_H__
00034 
00035 #define STATE_DISCONNECTED      0
00036 #define STATE_CONNECTED         1
00037 #define STATE_SYNC              2
00038 #define STATE_NOAUTH_INBOUND    3
00039 #define STATE_NOAUTH_OUTBOUND   4
00040 #define STATE_SERVICES          5
00041 
00054 class ircd_connector : public Extensible
00055 {
00056  private:
00059         sockaddr_in addr;
00060         
00063         int fd;
00064         
00067         std::string servername;
00068         
00071         std::string description;
00072         
00076         int state;
00077         
00080         bool SetHostAddress(char* host, int port);
00081 
00084         std::string version;
00085 
00086  public:
00087 
00092         std::string ircdbuffer;
00093 
00094  
00099         char host[MAXBUF];
00100 
00105         int port;
00106         
00111         std::vector<std::string> routes;
00112         
00113 
00116         bool MakeOutboundConnection(char* newhost, int newport);
00117         
00120         std::string GetServerName();
00121         
00124         void SetServerName(std::string serv);
00125         
00128         int GetDescriptor();
00129         
00132         void SetDescriptor(int fd);
00133         
00136         int GetState();
00137         
00140         void SetState(int state);
00141         
00144         char* GetServerIP();
00145         
00148         std::string GetDescription();
00149         
00152         void SetDescription(std::string desc);
00153         
00159         int GetServerPort();
00160         
00163         void SetServerPort(int p);
00164         
00167         bool SetHostAndPort(char* newhost, int newport);
00168         
00172         void CloseConnection();
00173 
00179         void AddBuffer(std::string a);
00180 
00185         bool BufferIsComplete();
00186 
00189         void ClearBuffer();
00190 
00195         std::string GetBuffer();
00196 
00199         void SetVersionString(std::string newversion);
00200 
00204         std::string GetVersionString();
00205 };
00206 
00207 
00210 class connection : public Extensible
00211 {
00212  public:
00215         int fd;
00216         
00219         char host[256];
00220         
00223         char ip[32];
00224         
00227         char inbuf[MAXBUF];
00228         
00231         long bytes_in;
00232 
00235         long bytes_out;
00236 
00239         long cmds_in;
00240 
00243         long cmds_out;
00244 
00247         bool haspassed;
00248 
00253         int port;
00254         
00257         int registered;
00258         
00261         short int state;
00262         
00265         time_t lastping;
00266         
00269         time_t signon;
00270         
00273         time_t idle_lastmsg;
00274         
00277         time_t nping;
00278         
00281         char internal_addr[MAXBUF];
00282         
00285         int internal_port;
00286 
00290         std::vector<ircd_connector> connectors;
00291         
00294         connection();
00295         
00298         bool CreateListener(char* host, int p);
00299         
00302         bool BeginLink(char* targethost, int port, char* password, char* servername, int myport);
00303         
00306         bool MeshCookie(char* targethost, int port, unsigned long cookie, char* servername);
00307         
00310         void TerminateLink(char* targethost);
00311         
00315         bool SendPacket(char *message, const char* host);
00316         
00321         bool RecvPacket(std::deque<std::string> &messages, char* host);
00322         
00325         ircd_connector* FindHost(std::string host);
00326         
00330         bool AddIncoming(int fd,char* targethost, int sourceport);
00331         
00332 };
00333 
00334 
00335 #endif

Generated on Thu May 12 02:25:11 2005 for InspIRCd by doxygen 1.3.3