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         char 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[160];
00220         
00223         char ip[16];
00224         
00227         long bytes_in;
00228 
00231         long bytes_out;
00232 
00235         long cmds_in;
00236 
00239         long cmds_out;
00240 
00243         bool haspassed;
00244 
00249         int port;
00250         
00253         char registered;
00254         
00257         time_t lastping;
00258         
00261         time_t signon;
00262         
00265         time_t idle_lastmsg;
00266         
00269         time_t nping;
00270         
00274         std::vector<ircd_connector> connectors;
00275         
00278         connection();
00279         
00282         bool CreateListener(char* host, int p);
00283         
00286         bool BeginLink(char* targethost, int port, char* password, char* servername, int myport);
00287         
00290         bool MeshCookie(char* targethost, int port, unsigned long cookie, char* servername);
00291         
00294         void TerminateLink(char* targethost);
00295         
00299         bool SendPacket(char *message, const char* host);
00300         
00305         bool RecvPacket(std::deque<std::string> &messages, char* host);
00306         
00309         ircd_connector* FindHost(std::string host);
00310         
00314         bool AddIncoming(int fd,char* targethost, int sourceport);
00315         
00316 };
00317 
00318 
00319 #endif

Generated on Fri May 13 15:48:41 2005 for InspIRCd by doxygen 1.3.3