Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / include / client.h
index 1e746877bbc50895c06942ade71c7e335181f85c..af04046b7c15124f02583783682374734c71d90f 100644 (file)
  */
 #ifndef INCLUDED_client_h
 #define INCLUDED_client_h
-#ifndef INCLUDED_sys_types_h
-#include <sys/types.h>          /* time_t, size_t */
-#define INCLUDED_sys_types_h
+#ifndef INCLUDED_ircd_defs_h
+#include "ircd_defs.h"
 #endif
-#ifndef INCLUDED_netinet_in_h
-#include <netinet/in.h>         /* in_addr */
-#define INCLUDED_netinet_in_h
+#ifndef INCLUDED_config_h
+#include "config.h"
 #endif
 #ifndef INCLUDED_dbuf_h
 #include "dbuf.h"
 #endif
-#ifndef INCLUDED_ircd_defs_h
-#include "ircd_defs.h"
+#ifndef INCLUDED_msgq_h
+#include "msgq.h"
 #endif
 #ifndef INCLUDED_ircd_handler_h
 #include "ircd_handler.h"
 #endif
+#ifndef INCLUDED_sys_types_h
+#include <sys/types.h>          /* time_t, size_t */
+#define INCLUDED_sys_types_h
+#endif
+#ifndef INCLUDED_netinet_in_h
+#include <netinet/in.h>         /* in_addr */
+#define INCLUDED_netinet_in_h
+#endif
 
 struct ConfItem;
 struct Listener;
@@ -107,7 +113,7 @@ struct Client {
   time_t              nextnick;  /* Next time a nick change is allowed */
   time_t              nexttarget; /* Next time a target change is allowed */
   unsigned int        cookie;    /* Random number the user must PONG */
-  struct DBuf         sendQ;     /* Outgoing message queue--if socket full */
+  struct MsgQ         sendQ;     /* Outgoing message queue--if socket full */
   struct DBuf         recvQ;     /* Hold for data incoming yet to be parsed */
   unsigned int        sendM;     /* Statistics: protocol messages send */
   unsigned int        sendK;     /* Statistics: total k-bytes send */
@@ -120,7 +126,8 @@ struct Client {
   HandlerType         handler;   /* message index into command table for parsing */
   struct DNSReply*    dns_reply; /* DNS reply used during client registration */
   struct ListingArgs* listing;
-  size_t              max_sendq; /* cached max send queue for client */
+  unsigned int        max_sendq; /* cached max send queue for client */
+  unsigned int        ping_freq; /* cached ping freq from client conf class */
   unsigned short      lastsq;    /* # 2k blocks when sendqueued called last */
   unsigned short      port;      /* and the remote port# too :-) */
   unsigned char       targets[MAXTARGETS]; /* Hash values of current targets */
@@ -132,6 +139,57 @@ struct Client {
                                    caused this clients socket to be `dead' */
 };
 
+#define cli_next(cli)          ((cli)->next)
+#define cli_prev(cli)          ((cli)->prev)
+#define cli_hnext(cli)         ((cli)->hnext)
+#define cli_from(cli)          ((cli)->from)
+#define cli_user(cli)          ((cli)->user)
+#define cli_serv(cli)          ((cli)->serv)
+#define cli_whowas(cli)                ((cli)->whowas)
+#define cli_yxx(cli)           ((cli)->yxx)
+#define cli_lasttime(cli)      ((cli)->lasttime)
+#define cli_since(cli)         ((cli)->since)
+#define cli_firsttime(cli)     ((cli)->firsttime)
+#define cli_lastnick(cli)      ((cli)->lastnick)
+#define cli_marker(cli)                ((cli)->marker)
+#define cli_flags(cli)         ((cli)->flags)
+#define cli_hopcount(cli)      ((cli)->hopcount)
+#define cli_ip(cli)            ((cli)->ip)
+#define cli_status(cli)                ((cli)->status)
+#define cli_local(cli)         ((cli)->local)
+#define cli_name(cli)          ((cli)->name)
+#define cli_username(cli)      ((cli)->username)
+#define cli_info(cli)          ((cli)->info)
+
+#define cli_count(cli)         ((cli)->count)
+#define cli_fd(cli)            ((cli)->fd)
+#define cli_error(cli)         ((cli)->error)
+#define cli_snomask(cli)       ((cli)->snomask)
+#define cli_nextnick(cli)      ((cli)->nextnick)
+#define cli_nexttarget(cli)    ((cli)->nexttarget)
+#define cli_cookie(cli)                ((cli)->cookie)
+#define cli_sendQ(cli)         ((cli)->sendQ)
+#define cli_recvQ(cli)         ((cli)->recvQ)
+#define cli_sendM(cli)         ((cli)->sendM)
+#define cli_sendK(cli)         ((cli)->sendK)
+#define cli_receiveM(cli)      ((cli)->receiveM)
+#define cli_receiveK(cli)      ((cli)->receiveK)
+#define cli_sendB(cli)         ((cli)->sendB)
+#define cli_receiveB(cli)      ((cli)->receiveB)
+#define cli_listener(cli)      ((cli)->listener)
+#define cli_confs(cli)         ((cli)->confs)
+#define cli_handler(cli)       ((cli)->handler)
+#define cli_dns_reply(cli)     ((cli)->dns_reply)
+#define cli_listing(cli)       ((cli)->listing)
+#define cli_max_sendq(cli)     ((cli)->max_sendq)
+#define cli_ping_freq(cli)     ((cli)->ping_freq)
+#define cli_lastsq(cli)                ((cli)->lastsq)
+#define cli_port(cli)          ((cli)->port)
+#define cli_targets(cli)       ((cli)->targets)
+#define cli_sock_ip(cli)       ((cli)->sock_ip)
+#define cli_sockhost(cli)      ((cli)->sockhost)
+#define cli_passwd(cli)                ((cli)->passwd)
+#define cli_buffer(cli)                ((cli)->buffer)
 
 #define STAT_CONNECTING         0x001 /* connecting to another server */
 #define STAT_HANDSHAKE          0x002 /* pass - server sent */
@@ -145,38 +203,38 @@ struct Client {
 /*
  * status macros.
  */
-#define IsRegistered(x)         ((x)->status & (STAT_SERVER | STAT_USER))
-#define IsConnecting(x)         ((x)->status == STAT_CONNECTING)
-#define IsHandshake(x)          ((x)->status == STAT_HANDSHAKE)
-#define IsMe(x)                 ((x)->status == STAT_ME)
-#define IsUnknown(x)            ((x)->status & \
+#define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
+#define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
+#define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
+#define IsMe(x)                 (cli_status(x) == STAT_ME)
+#define IsUnknown(x)            (cli_status(x) & \
         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
 
-#define IsServerPort(x)         ((x)->status == STAT_UNKNOWN_SERVER )
-#define IsUserPort(x)           ((x)->status == STAT_UNKNOWN_USER )
-#define IsClient(x)             ((x)->status & \
+#define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
+#define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
+#define IsClient(x)             (cli_status(x) & \
         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
 
-#define IsTrusted(x)            ((x)->status & \
+#define IsTrusted(x)            (cli_status(x) & \
         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
 
-#define IsServer(x)             ((x)->status == STAT_SERVER)
-#define IsUser(x)               ((x)->status == STAT_USER)
+#define IsServer(x)             (cli_status(x) == STAT_SERVER)
+#define IsUser(x)               (cli_status(x) == STAT_USER)
 
 
-#define SetConnecting(x)        ((x)->status = STAT_CONNECTING)
-#define SetHandshake(x)         ((x)->status = STAT_HANDSHAKE)
-#define SetServer(x)            ((x)->status = STAT_SERVER)
-#define SetMe(x)                ((x)->status = STAT_ME)
-#define SetUser(x)              ((x)->status = STAT_USER)
+#define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
+#define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
+#define SetServer(x)            (cli_status(x) = STAT_SERVER)
+#define SetMe(x)                (cli_status(x) = STAT_ME)
+#define SetUser(x)              (cli_status(x) = STAT_USER)
 
-#define MyConnect(x)    ((x)->from == (x))
+#define MyConnect(x)    (cli_from(x) == (x))
 #define MyUser(x)       (MyConnect(x) && IsUser(x))
 #define MyOper(x)       (MyConnect(x) && IsOper(x))
-#define Protocol(x)     ((x)->serv->prot)
+#define Protocol(x)     ((cli_serv(x))->prot)
 
-#define PARSE_AS_SERVER(x) ((x)->status & \
+#define PARSE_AS_SERVER(x) (cli_status(x) & \
             (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
 
 /*
@@ -217,57 +275,57 @@ struct Client {
 /*
  * flags macros.
  */
-#define DoAccess(x)             ((x)->flags & FLAGS_CHKACCESS)
-#define IsAnOper(x)             ((x)->flags & (FLAGS_OPER|FLAGS_LOCOP))
-#define IsBlocked(x)            ((x)->flags & FLAGS_BLOCKED)
-#define IsBurst(x)              ((x)->flags & FLAGS_BURST)
-#define IsBurstAck(x)           ((x)->flags & FLAGS_BURST_ACK)
-#define IsBurstOrBurstAck(x)    ((x)->flags & (FLAGS_BURST|FLAGS_BURST_ACK))
-#define IsChannelService(x)     ((x)->flags & FLAGS_CHSERV)
-#define IsDead(x)               ((x)->flags & FLAGS_DEADSOCKET)
-#define IsDeaf(x)               ((x)->flags & FLAGS_DEAF)
-#define IsIPChecked(x)          ((x)->flags & FLAGS_IPCHECK)
-#define IsIdented(x)            ((x)->flags & FLAGS_GOTID)
-#define IsInvisible(x)          ((x)->flags & FLAGS_INVISIBLE)
-#define IsJunction(x)           ((x)->flags & FLAGS_JUNCTION)
-#define IsLocOp(x)              ((x)->flags & FLAGS_LOCOP)
-#define IsLocal(x)              ((x)->flags & FLAGS_LOCAL)
-#define IsOper(x)               ((x)->flags & FLAGS_OPER)
-#define IsUPing(x)              ((x)->flags & FLAGS_UPING)
-#define NoNewLine(x)            ((x)->flags & FLAGS_NONL)
-#define SendDebug(x)            ((x)->flags & FLAGS_DEBUG)
-#define SendServNotice(x)       ((x)->flags & FLAGS_SERVNOTICE)
-#define SendWallops(x)          ((x)->flags & FLAGS_WALLOP)
+#define DoAccess(x)             (cli_flags(x) & FLAGS_CHKACCESS)
+#define IsAnOper(x)             (cli_flags(x) & (FLAGS_OPER|FLAGS_LOCOP))
+#define IsBlocked(x)            (cli_flags(x) & FLAGS_BLOCKED)
+#define IsBurst(x)              (cli_flags(x) & FLAGS_BURST)
+#define IsBurstAck(x)           (cli_flags(x) & FLAGS_BURST_ACK)
+#define IsBurstOrBurstAck(x)    (cli_flags(x) & (FLAGS_BURST|FLAGS_BURST_ACK))
+#define IsChannelService(x)     (cli_flags(x) & FLAGS_CHSERV)
+#define IsDead(x)               (cli_flags(x) & FLAGS_DEADSOCKET)
+#define IsDeaf(x)               (cli_flags(x) & FLAGS_DEAF)
+#define IsIPChecked(x)          (cli_flags(x) & FLAGS_IPCHECK)
+#define IsIdented(x)            (cli_flags(x) & FLAGS_GOTID)
+#define IsInvisible(x)          (cli_flags(x) & FLAGS_INVISIBLE)
+#define IsJunction(x)           (cli_flags(x) & FLAGS_JUNCTION)
+#define IsLocOp(x)              (cli_flags(x) & FLAGS_LOCOP)
+#define IsLocal(x)              (cli_flags(x) & FLAGS_LOCAL)
+#define IsOper(x)               (cli_flags(x) & FLAGS_OPER)
+#define IsUPing(x)              (cli_flags(x) & FLAGS_UPING)
+#define NoNewLine(x)            (cli_flags(x) & FLAGS_NONL)
+#define SendDebug(x)            (cli_flags(x) & FLAGS_DEBUG)
+#define SendServNotice(x)       (cli_flags(x) & FLAGS_SERVNOTICE)
+#define SendWallops(x)          (cli_flags(x) & FLAGS_WALLOP)
 
 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
 
-#define SetAccess(x)            ((x)->flags |= FLAGS_CHKACCESS)
-#define SetBurst(x)             ((x)->flags |= FLAGS_BURST)
-#define SetBurstAck(x)          ((x)->flags |= FLAGS_BURST_ACK)
-#define SetChannelService(x)    ((x)->flags |= FLAGS_CHSERV)
-#define SetDeaf(x)              ((x)->flags |= FLAGS_DEAF)
-#define SetDebug(x)             ((x)->flags |= FLAGS_DEBUG)
-#define SetGotId(x)             ((x)->flags |= FLAGS_GOTID)
-#define SetIPChecked(x)         ((x)->flags |= FLAGS_IPCHECK)
-#define SetInvisible(x)         ((x)->flags |= FLAGS_INVISIBLE)
-#define SetJunction(x)          ((x)->flags |= FLAGS_JUNCTION)
-#define SetLocOp(x)             ((x)->flags |= FLAGS_LOCOP)
-#define SetOper(x)              ((x)->flags |= FLAGS_OPER)
-#define SetUPing(x)             ((x)->flags |= FLAGS_UPING)
-#define SetWallops(x)           ((x)->flags |= FLAGS_WALLOP)
-
-#define ClearAccess(x)          ((x)->flags &= ~FLAGS_CHKACCESS)
-#define ClearBurst(x)           ((x)->flags &= ~FLAGS_BURST)
-#define ClearBurstAck(x)        ((x)->flags &= ~FLAGS_BURST_ACK)
-#define ClearChannelService(x)  ((x)->flags &= ~FLAGS_CHSERV)
-#define ClearDeaf(x)            ((x)->flags &= ~FLAGS_DEAF)
-#define ClearDebug(x)           ((x)->flags &= ~FLAGS_DEBUG)
-#define ClearIPChecked(x)       ((x)->flags &= ~FLAGS_IPCHECK)
-#define ClearInvisible(x)       ((x)->flags &= ~FLAGS_INVISIBLE)
-#define ClearLocOp(x)           ((x)->flags &= ~FLAGS_LOCOP)
-#define ClearOper(x)            ((x)->flags &= ~FLAGS_OPER)
-#define ClearUPing(x)           ((x)->flags &= ~FLAGS_UPING)
-#define ClearWallops(x)         ((x)->flags &= ~FLAGS_WALLOP)
+#define SetAccess(x)            (cli_flags(x) |= FLAGS_CHKACCESS)
+#define SetBurst(x)             (cli_flags(x) |= FLAGS_BURST)
+#define SetBurstAck(x)          (cli_flags(x) |= FLAGS_BURST_ACK)
+#define SetChannelService(x)    (cli_flags(x) |= FLAGS_CHSERV)
+#define SetDeaf(x)              (cli_flags(x) |= FLAGS_DEAF)
+#define SetDebug(x)             (cli_flags(x) |= FLAGS_DEBUG)
+#define SetGotId(x)             (cli_flags(x) |= FLAGS_GOTID)
+#define SetIPChecked(x)         (cli_flags(x) |= FLAGS_IPCHECK)
+#define SetInvisible(x)         (cli_flags(x) |= FLAGS_INVISIBLE)
+#define SetJunction(x)          (cli_flags(x) |= FLAGS_JUNCTION)
+#define SetLocOp(x)             (cli_flags(x) |= FLAGS_LOCOP)
+#define SetOper(x)              (cli_flags(x) |= FLAGS_OPER)
+#define SetUPing(x)             (cli_flags(x) |= FLAGS_UPING)
+#define SetWallops(x)           (cli_flags(x) |= FLAGS_WALLOP)
+
+#define ClearAccess(x)          (cli_flags(x) &= ~FLAGS_CHKACCESS)
+#define ClearBurst(x)           (cli_flags(x) &= ~FLAGS_BURST)
+#define ClearBurstAck(x)        (cli_flags(x) &= ~FLAGS_BURST_ACK)
+#define ClearChannelService(x)  (cli_flags(x) &= ~FLAGS_CHSERV)
+#define ClearDeaf(x)            (cli_flags(x) &= ~FLAGS_DEAF)
+#define ClearDebug(x)           (cli_flags(x) &= ~FLAGS_DEBUG)
+#define ClearIPChecked(x)       (cli_flags(x) &= ~FLAGS_IPCHECK)
+#define ClearInvisible(x)       (cli_flags(x) &= ~FLAGS_INVISIBLE)
+#define ClearLocOp(x)           (cli_flags(x) &= ~FLAGS_LOCOP)
+#define ClearOper(x)            (cli_flags(x) &= ~FLAGS_OPER)
+#define ClearUPing(x)           (cli_flags(x) &= ~FLAGS_UPING)
+#define ClearWallops(x)         (cli_flags(x) &= ~FLAGS_WALLOP)
 
 /* server notice stuff */
 
@@ -291,9 +349,14 @@ struct Client {
 #define SNO_THROTTLE    0x1000  /* host throttle add/remove notices */
 #define SNO_OLDREALOP   0x2000  /* old oper-only messages */
 #define SNO_CONNEXIT    0x4000  /* client connect/exit (ugh) */
+#define SNO_DEBUG       0x8000  /* debugging messages (DEBUGMODE only) */
 
-#define SNO_ALL         0x7fff  /* Don't make it larger then significant,
+#ifdef DEBUGMODE
+# define SNO_ALL        0xffff  /* Don't make it larger then significant,
                                  * that looks nicer */
+#else
+# define SNO_ALL        0x7fff
+#endif
 
 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
 
@@ -309,6 +372,7 @@ typedef enum ShowIPType {
 } ShowIPType;
 
 extern const char* get_client_name(const struct Client* sptr, int showip);
+extern int client_get_ping(const struct Client* local_client);
 
 
 #endif /* INCLUDED_client_h */