/* * ---------------------------------------------------------------- * Night Light IRC Proxy - Connection Header * ---------------------------------------------------------------- * Copyright (C) 1997-2007 Jonas Kvinge * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Last modified by: * Jonas Kvinge (24.11.2007) * */ #ifdef CONN_H #warning "conn.h already included." #else #define CONN_H struct in_addr; #if IPV6_SUPPORT struct in6_addr; #endif struct Who_Struct; struct IRC_ISupport_Struct; struct ConnConf_Struct; /* DEFINES - JONAS (24.06.2000) */ #define CONN_INTERVAL 120 #define CONN_SOCKKEEPALIVEOPT TRUE #define CONN_CONNECTTIMEOUT 120 #define CONN_QUITTIMEOUT 5 #define CONN_IDLETIMEBEFOREPING 30 #define CONN_PINGTIMEOUT 1800 #define CONN_ISONTIME 30 #define CONN_IGNORENICKMASK 6 #define CONN_IGNOREUSERMASK 6 #define CONN_IGNOREHOSTMASK 1 #define CONN_IGNOREEXPIRETIME 30 #define CONN_IGNORETTL 10 #define CHAN_HASHSIZE 100 #define CHANUSER_HASHSIZE 10000 /* BIT MASKS - JONAS (24.06.2000) */ #define CONN_BITMASK_ATTACHED 1 #define CONN_BITMASK_REMOVE 2 #define CONN_BITMASK_LOGHOMEDIR 4 #define CONN_BITMASK_LOGERROR 8 #define CONN_BITMASK_CONNECTPROC 1 #define CONN_BITMASK_SOCKET 2 #define CONN_BITMASK_SOCKOPT 4 #define CONN_BITMASK_KEEPALIVEOPT 8 #define CONN_BITMASK_BOUND 16 #define CONN_BITMASK_CONNECTING 32 #define CONN_BITMASK_CONNECTED 64 #define CONN_BITMASK_SOCKNAME 128 #define CONN_BITMASK_PEERNAME 256 #define CONN_BITMASK_SSLHANDSHAKE 512 #define CONN_BITMASK_WELCOME 1024 #define CONN_BITMASK_AWAY 2048 #define CONN_BITMASK_SENTNICK 4096 #define CONN_BITMASK_SENTAWAYNICK 8192 #define CONN_BITMASK_SENTPING 16384 #define CONN_BITMASK_SENTISON 32768 #define CONN_BITMASK_SENTQUIT 65536 #define CONN_BITMASK_AWAYNICK 131072 #define CONN_USERMODE_INVISIBLE 1 #define CONN_USERMODE_NOTICE 2 #define CONN_USERMODE_WALLOPS 4 #define CONN_USERMODE_GOPER 8 #define CONN_USERMODE_LOPER 16 #define CONN_CHANMODE_ANONYMOUS 1 #define CONN_CHANMODE_INVITEONLY 2 #define CONN_CHANMODE_MODERATED 4 #define CONN_CHANMODE_NOOUTSIDE 8 #define CONN_CHANMODE_QUIET 16 #define CONN_CHANMODE_PRIVATE 32 #define CONN_CHANMODE_SECRET 64 #define CONN_CHANMODE_REOP 128 #define CONN_CHANMODE_ONLYOPTOPIC 256 #define CONN_CHANMODE_KEY 512 #define CONN_CHANMODE_LIMIT 1024 #define CONN_CHANLISTMODE_BAN 1 #define CONN_CHANLISTMODE_EXCEPTION 2 #define CONN_CHANLISTMODE_INVITATION 4 #define CONN_CHANUSERMODE_CREATOR 1 #define CONN_CHANUSERMODE_OPERATOR 2 #define CONN_CHANUSERMODE_VOICE 4 /* MACROS - JONAS (24.06.2000) */ #define Conn_SetAttached(x) ((x)->Flags |= CONN_BITMASK_ATTACHED) #define Conn_SetRemove(x) ((x)->Flags |= CONN_BITMASK_REMOVE) #define Conn_SetLogHomeDir(x) ((x)->Flags |= CONN_BITMASK_LOGHOMEDIR) #define Conn_SetLogError(x) ((x)->Flags |= CONN_BITMASK_LOGERROR) #define Conn_ClearAttached(x) ((x)->Flags &= ~CONN_BITMASK_ATTACHED) #define Conn_ClearRemove(x) ((x)->Flags &= ~CONN_BITMASK_REMOVE) #define Conn_ClearLogHomeDir(x) ((x)->Flags &= ~CONN_BITMASK_LOGHOMEDIR) #define Conn_ClearLogError(x) ((x)->Flags &= ~CONN_BITMASK_LOGERROR) #define Conn_IsAttached(x) ((x)->Flags & CONN_BITMASK_ATTACHED) #define Conn_IsRemove(x) ((x)->Flags & CONN_BITMASK_REMOVE) #define Conn_IsLogHomeDir(x) ((x)->Flags & CONN_BITMASK_LOGHOMEDIR) #define Conn_IsLogError(x) ((x)->Flags & CONN_BITMASK_LOGERROR) #define Conn_SetConnectProc(x) ((x)->ConnectionFlags |= CONN_BITMASK_CONNECTPROC) #define Conn_SetSocket(x) ((x)->ConnectionFlags |= CONN_BITMASK_SOCKET) #define Conn_SetSockOPT(x) ((x)->ConnectionFlags |= CONN_BITMASK_SOCKOPT) #define Conn_SetKeepAliveOPT(x) ((x)->ConnectionFlags |= CONN_BITMASK_KEEPALIVEOPT) #define Conn_SetBound(x) ((x)->ConnectionFlags |= CONN_BITMASK_BOUND) #define Conn_SetConnecting(x) ((x)->ConnectionFlags |= CONN_BITMASK_CONNECTING) #define Conn_SetConnected(x) ((x)->ConnectionFlags |= CONN_BITMASK_CONNECTED) #define Conn_SetSockName(x) ((x)->ConnectionFlags |= CONN_BITMASK_SOCKNAME) #define Conn_SetPeerName(x) ((x)->ConnectionFlags |= CONN_BITMASK_PEERNAME) #define Conn_SetSSLHandshake(x) ((x)->ConnectionFlags |= CONN_BITMASK_SSLHANDSHAKE) #define Conn_SetWelcome(x) ((x)->ConnectionFlags |= CONN_BITMASK_WELCOME) #define Conn_SetAway(x) ((x)->ConnectionFlags |= CONN_BITMASK_AWAY) #define Conn_SetSentNick(x) ((x)->ConnectionFlags |= CONN_BITMASK_SENTNICK) #define Conn_SetSentAwayNick(x) ((x)->ConnectionFlags |= CONN_BITMASK_SENTAWAYNICK) #define Conn_SetSentPing(x) ((x)->ConnectionFlags |= CONN_BITMASK_SENTPING) #define Conn_SetSentISON(x) ((x)->ConnectionFlags |= CONN_BITMASK_SENTISON) #define Conn_SetSentQuit(x) ((x)->ConnectionFlags |= CONN_BITMASK_SENTQUIT) #define Conn_SetAwayNick(x) ((x)->ConnectionFlags |= CONN_BITMASK_AWAYNICK) #define Conn_ClearConnectProc(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_CONNECTPROC) #define Conn_ClearSocket(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SOCKET) #define Conn_ClearSockOPT(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SOCKOPT) #define Conn_ClearKeepAliveOPT(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_KEEPALIVEOPT) #define Conn_ClearBound(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_BOUND) #define Conn_ClearConnecting(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_CONNECTING) #define Conn_ClearConnected(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_CONNECTED) #define Conn_ClearSockName(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SOCKNAME) #define Conn_ClearPeerName(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_PEERNAME) #define Conn_ClearSSLHandshake(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SSLHANDSHAKE) #define Conn_ClearWelcome(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_WELCOME) #define Conn_ClearAway(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_AWAY) #define Conn_ClearSentNick(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SENTNICK) #define Conn_ClearSentAwayNick(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SENTAWAYNICK) #define Conn_ClearSentPing(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SENTPING) #define Conn_ClearSentISON(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SENTISON) #define Conn_ClearSentQuit(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_SENTQUIT) #define Conn_ClearAwayNick(x) ((x)->ConnectionFlags &= ~CONN_BITMASK_AWAYNICK) #define Conn_IsConnectProc(x) ((x)->ConnectionFlags & CONN_BITMASK_CONNECTPROC) #define Conn_IsSocket(x) ((x)->ConnectionFlags & CONN_BITMASK_SOCKET) #define Conn_IsSockOPT(x) ((x)->ConnectionFlags & CONN_BITMASK_SOCKOPT) #define Conn_IsKeepAliveOPT(x) ((x)->ConnectionFlags & CONN_BITMASK_KEEPALIVEOPT) #define Conn_IsBound(x) ((x)->ConnectionFlags & CONN_BITMASK_BOUND) #define Conn_IsConnecting(x) ((x)->ConnectionFlags & CONN_BITMASK_CONNECTING) #define Conn_IsConnected(x) ((x)->ConnectionFlags & CONN_BITMASK_CONNECTED) #define Conn_IsSockName(x) ((x)->ConnectionFlags & CONN_BITMASK_SOCKNAME) #define Conn_IsPeerName(x) ((x)->ConnectionFlags & CONN_BITMASK_PEERNAME) #define Conn_IsSSLHandshake(x) ((x)->ConnectionFlags & CONN_BITMASK_SSLHANDSHAKE) #define Conn_IsWelcome(x) ((x)->ConnectionFlags & CONN_BITMASK_WELCOME) #define Conn_IsAway(x) ((x)->ConnectionFlags & CONN_BITMASK_AWAY) #define Conn_IsSentNick(x) ((x)->ConnectionFlags & CONN_BITMASK_SENTNICK) #define Conn_IsSentAwayNick(x) ((x)->ConnectionFlags & CONN_BITMASK_SENTAWAYNICK) #define Conn_IsSentPing(x) ((x)->ConnectionFlags & CONN_BITMASK_SENTPING) #define Conn_IsSentISON(x) ((x)->ConnectionFlags & CONN_BITMASK_SENTISON) #define Conn_IsSentQuit(x) ((x)->ConnectionFlags & CONN_BITMASK_SENTQUIT) #define Conn_IsAwayNick(x) ((x)->ConnectionFlags & CONN_BITMASK_AWAYNICK) #define Conn_IsConnect(x) ((x)->ConnectionFlags & (CONN_BITMASK_CONNECTING|CONN_BITMASK_CONNECTED)) #define ConnISupport_SetInvisible(x) ((x)->UserModeFlags |= CONN_USERMODE_INVISIBLE) #define ConnISupport_SetNotice(x) ((x)->UserModeFlags |= CONN_USERMODE_NOTICE) #define ConnISupport_SetWallops(x) ((x)->UserModeFlags |= CONN_USERMODE_WALLOPS) #define ConnISupport_SetGOper(x) ((x)->UserModeFlags |= CONN_USERMODE_GOPER) #define ConnISupport_SetLOper(x) ((x)->UserModeFlags |= CONN_USERMODE_LOPER) #define ConnISupport_SetAnonymous(x) ((x)->ChanModeFlags |= CONN_CHANMODE_ANONYMOUS) #define ConnISupport_SetInviteOnly(x) ((x)->ChanModeFlags |= CONN_CHANMODE_INVITEONLY) #define ConnISupport_SetModerated(x) ((x)->ChanModeFlags |= CONN_CHANMODE_MODERATED) #define ConnISupport_SetNoOutSide(x) ((x)->ChanModeFlags |= CONN_CHANMODE_NOOUTSIDE) #define ConnISupport_SetQuiet(x) ((x)->ChanModeFlags |= CONN_CHANMODE_QUIET) #define ConnISupport_SetPrivate(x) ((x)->ChanModeFlags |= CONN_CHANMODE_PRIVATE) #define ConnISupport_SetSecret(x) ((x)->ChanModeFlags |= CONN_CHANMODE_SECRET) #define ConnISupport_SetReOP(x) ((x)->ChanModeFlags |= CONN_CHANMODE_REOP) #define ConnISupport_SetOnlyOPTopic(x) ((x)->ChanModeFlags |= CONN_CHANMODE_ONLYOPTOPIC) #define ConnISupport_SetKey(x) ((x)->ChanModeFlags |= CONN_CHANMODE_KEY) #define ConnISupport_SetLimit(x) ((x)->ChanModeFlags |= CONN_CHANMODE_LIMIT) #define ConnISupport_SetBan(x) ((x)->ChanListModeFlags |= CONN_CHANLISTMODE_BAN) #define ConnISupport_SetException(x) ((x)->ChanListModeFlags |= CONN_CHANLISTMODE_EXCEPTION) #define ConnISupport_SetInvitation(x) ((x)->ChanListModeFlags |= CONN_CHANLISTMODE_INVITATION) #define ConnISupport_SetCreator(x) ((x)->ChanUserModeFlags |= CONN_CHANUSERMODE_CREATOR) #define ConnISupport_SetOperator(x) ((x)->ChanUserModeFlags |= CONN_CHANUSERMODE_OPERATOR) #define ConnISupport_SetVoice(x) ((x)->ChanUserModeFlags |= CONN_CHANUSERMODE_VOICE) #define ConnISupport_ClearInvisible(x) ((x)->UserModeFlags &= ~CONN_USERMODE_INVISIBLE) #define ConnISupport_ClearNotice(x) ((x)->UserModeFlags &= ~CONN_USERMODE_NOTICE) #define ConnISupport_ClearWallops(x) ((x)->UserModeFlags &= ~CONN_USERMODE_WALLOPS) #define ConnISupport_ClearGOper(x) ((x)->UserModeFlags &= ~CONN_USERMODE_GOPER) #define ConnISupport_ClearLOper(x) ((x)->UserModeFlags &= ~CONN_USERMODE_LOPER) #define ConnISupport_ClearAnonymous(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_ANONYMOUS) #define ConnISupport_ClearInviteOnly(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_INVITEONLY) #define ConnISupport_ClearModerated(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_MODERATED) #define ConnISupport_ClearNoOutSide(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_NOOUTSIDE) #define ConnISupport_ClearQuiet(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_QUIET) #define ConnISupport_ClearPrivate(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_PRIVATE) #define ConnISupport_ClearSecret(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_SECRET) #define ConnISupport_ClearReOP(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_REOP) #define ConnISupport_ClearOnlyOPTopic(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_ONLYOPTOPIC) #define ConnISupport_ClearKey(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_KEY) #define ConnISupport_ClearLimit(x) ((x)->ChanModeFlags &= ~CONN_CHANMODE_LIMIT) #define ConnISupport_ClearBan(x) ((x)->ChanListModeFlags &= ~CONN_CHANLISTMODE_BAN) #define ConnISupport_ClearException(x) ((x)->ChanListModeFlags &= ~CONN_CHANLISTMODE_EXCEPTION) #define ConnISupport_ClearInvitation(x) ((x)->ChanListModeFlags &= ~CONN_CHANLISTMODE_INVITATION) #define ConnISupport_ClearCreator(x) ((x)->ChanUserModeFlags &= ~CONN_CHANUSERMODE_CREATOR) #define ConnISupport_ClearOperator(x) ((x)->ChanUserModeFlags &= ~CONN_CHANUSERMODE_OPERATOR) #define ConnISupport_ClearVoice(x) ((x)->ChanUserModeFlags &= ~CONN_CHANUSERMODE_VOICE) #define ConnISupport_IsInvisible(x) ((x)->UserModeFlags & CONN_USERMODE_INVISIBLE) #define ConnISupport_IsNotice(x) ((x)->UserModeFlags & CONN_USERMODE_NOTICE) #define ConnISupport_IsWallops(x) ((x)->UserModeFlags & CONN_USERMODE_WALLOPS) #define ConnISupport_IsGOper(x) ((x)->UserModeFlags & CONN_USERMODE_GOPER) #define ConnISupport_IsLOper(x) ((x)->UserModeFlags & CONN_USERMODE_LOPER) #define ConnISupport_IsAnonymous(x) ((x)->ChanModeFlags & CONN_CHANMODE_ANONYMOUS) #define ConnISupport_IsInviteOnly(x) ((x)->ChanModeFlags & CONN_CHANMODE_INVITEONLY) #define ConnISupport_IsModerated(x) ((x)->ChanModeFlags & CONN_CHANMODE_MODERATED) #define ConnISupport_IsNoOutSide(x) ((x)->ChanModeFlags & CONN_CHANMODE_NOOUTSIDE) #define ConnISupport_IsQuiet(x) ((x)->ChanModeFlags & CONN_CHANMODE_QUIET) #define ConnISupport_IsPrivate(x) ((x)->ChanModeFlags & CONN_CHANMODE_PRIVATE) #define ConnISupport_IsSecret(x) ((x)->ChanModeFlags & CONN_CHANMODE_SECRET) #define ConnISupport_IsReOP(x) ((x)->ChanModeFlags & CONN_CHANMODE_REOP) #define ConnISupport_IsOnlyOPTopic(x) ((x)->ChanModeFlags & CONN_CHANMODE_ONLYOPTOPIC) #define ConnISupport_IsKey(x) ((x)->ChanModeFlags & CONN_CHANMODE_KEY) #define ConnISupport_IsLimit(x) ((x)->ChanModeFlags & CONN_CHANMODE_LIMIT) #define ConnISupport_IsBan(x) ((x)->ChanListModeFlags & CONN_CHANLISTMODE_BAN) #define ConnISupport_IsException(x) ((x)->ChanListModeFlags & CONN_CHANLISTMODE_EXCEPTION) #define ConnISupport_IsInvitation(x) ((x)->ChanListModeFlags & CONN_CHANLISTMODE_INVITATION) #define ConnISupport_IsCreator(x) ((x)->ChanUserModeFlags & CONN_CHANUSERMODE_CREATOR) #define ConnISupport_IsOperator(x) ((x)->ChanUserModeFlags & CONN_CHANUSERMODE_OPERATOR) #define ConnISupport_IsVoice(x) ((x)->ChanUserModeFlags & CONN_CHANUSERMODE_VOICE) /* STRUCTURES - JONAS (18.07.2001) */ struct Conn_Struct { char *Name; char *Nick; char *AwayNick; char *User; char *Host; char *Mode; char *Info; char *Chans; char *AwayMsg; char *PublicDetachMsg; char *PublicAttachMsg; char *NickServNUH; char *NickServPass; unsigned long int ConfFlags; unsigned short int MaxClients; unsigned short int SendMaxLines; unsigned short int SendLineTime; unsigned short int SendMaxBuffer; unsigned short int SendBufferTime; unsigned short int NumServers; struct ConnServer_Struct *Server_Head; struct ConnServer_Struct *Server_Tail; unsigned long int Flags; char *FileName; unsigned short int NumClients; struct ConnServer_Struct *ConnServerTry; unsigned long int ResolveFlags; char *HostName; char *HostIPS; struct in_addr INAddr; #if IPV6_SUPPORT struct in6_addr INAddr6; #endif unsigned long int PortH; unsigned long int PortN; unsigned long int ServerResolveFlags; char *ServerHostName; char *ServerHostIPS; struct in_addr ServerINAddr; #if IPV6_SUPPORT struct in6_addr ServerINAddr6; #endif unsigned long int ServerPortH; unsigned long int ServerPortN; char *ServerPass; unsigned long long int ConnectionFlags; signed long int FD; char *ServerName; char *IRCNick; char *Welcome[5]; char **ISupport_String; unsigned short int ISupportLines; struct IRC_ISupport_Struct ISupport; unsigned long int UserModeFlags; unsigned long int ChanModeFlags; unsigned long int ChanListModeFlags; unsigned long int ChanUserModeFlags; unsigned short int NumSendQs; struct SendQ_Struct *SendQ_Head; unsigned short int NumFlushLs; unsigned long int SendQMaxFlushLines; struct FlushL_Struct *FlushL_Head; struct FlushL_Struct *FlushL_Tail; unsigned short int NumFlushBs; unsigned long int SendQMaxFlushBuffer; struct FlushB_Struct *FlushB_Head; struct FlushB_Struct *FlushB_Tail; char *RecvBuffer; char *SendBuffer; unsigned short int NicksIndex; time_t ConnectProcTime; time_t ConnectTime; time_t ConnectedTime; time_t SentPingTime; time_t SentQuitTime; time_t LastRecvTime; time_t IgnoreExpireTime; time_t SentISONTime; time_t LogError; unsigned short int NumChans; struct Chan_Struct *Chan_Head; struct Chan_Struct *Chan_Tail; struct Chan_Struct *Chan_Table[CHAN_HASHSIZE]; unsigned short int NumIgnores; struct Ignore_Struct *Ignore_Head; struct Ignore_Struct *Ignore_Tail; #if SSL_SUPPORT SSL *SSL_H; X509 *Cert; #endif struct Conn_Struct *Prev; struct Conn_Struct *Next; }; struct ConnServer_Struct { char *Host; unsigned long int Port; char *Pass; unsigned short int Tries; struct ConnServer_Struct *Prev; struct ConnServer_Struct *Next; }; /* FUNCTION PROTOTYPES - JONAS (18.07.2001) */ struct Conn_Struct *conn_add(struct ConnConf_Struct *ConnConf); void conn_rem(struct Conn_Struct *ConnS); struct Conn_Struct *conn_get(const char *const NamePT); struct ConnServer_Struct *conn_addserver(struct Conn_Struct *ConnS, const char *const HostPT, const unsigned long int Port, const char *const PassPT); void conn_remserver(struct Conn_Struct *ConnS, struct ConnServer_Struct *ConnServer); struct ConnServer_Struct *conn_getserver(struct Conn_Struct *ConnS, const char *const HostPT); void conn_destroyservers(struct Conn_Struct *ConnS); void conn_initconnection(struct Conn_Struct *ConnS); #endif