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 00042 std::string CreateSum(); 00043 00056 class ircd_connector : public Extensible 00057 { 00058 private: 00061 sockaddr_in addr; 00062 00065 int fd; 00066 00069 std::string servername; 00070 00073 std::string description; 00074 00078 char state; 00079 00082 bool SetHostAddress(char* host, int port); 00083 00086 std::string version; 00087 00090 std::string sendq; 00091 00094 std::string WriteError; 00095 00098 time_t nextping; 00099 00102 bool replied; 00103 00104 public: 00105 00110 std::string ircdbuffer; 00111 00112 00117 char host[MAXBUF]; 00118 00123 int port; 00124 00129 std::vector<std::string> routes; 00130 00133 ircd_connector(); 00134 00137 bool MakeOutboundConnection(char* newhost, int newport); 00138 00141 std::string GetServerName(); 00142 00146 void SetServerName(std::string serv); 00147 00151 int GetDescriptor(); 00152 00156 void SetDescriptor(int fd); 00157 00161 int GetState(); 00162 00166 void SetState(int state); 00167 00171 char* GetServerIP(); 00172 00176 std::string GetDescription(); 00177 00181 void SetDescription(std::string desc); 00182 00190 int GetServerPort(); 00191 00195 void SetServerPort(int p); 00196 00202 bool SetHostAndPort(char* newhost, int newport); 00203 00207 void CloseConnection(); 00208 00217 bool AddBuffer(std::string a); 00218 00225 bool BufferIsComplete(); 00226 00229 void ClearBuffer(); 00230 00237 std::string GetBuffer(); 00238 00242 void SetVersionString(std::string newversion); 00243 00249 std::string GetVersionString(); 00250 00258 bool AddWriteBuf(std::string data); 00259 00265 bool FlushWriteBuf(); 00266 00270 void SetWriteError(std::string error); 00271 00275 std::string GetWriteError(); 00276 00280 bool HasBufferedOutput(); 00281 00286 bool CheckPing(); 00287 00290 void ResetPing(); 00291 }; 00292 00293 00296 class connection : public Extensible 00297 { 00298 public: 00301 int fd; 00302 00305 char host[160]; 00306 00309 char ip[16]; 00310 00313 int bytes_in; 00314 00317 int bytes_out; 00318 00321 int cmds_in; 00322 00325 int cmds_out; 00326 00329 bool haspassed; 00330 00335 int port; 00336 00339 char registered; 00340 00343 time_t lastping; 00344 00347 time_t signon; 00348 00351 time_t idle_lastmsg; 00352 00355 time_t nping; 00356 00359 connection(); 00360 }; 00361 00362 00363 #endif