+/** Single element in a flag bitset array. */
+typedef unsigned long flagpage_t;
+
+/** Number of bits in a flagpage_t. */
+#define FLAGSET_NBITS (8 * sizeof(flagpage_t))
+/** Element number for flag \a flag. */
+#define FLAGSET_INDEX(flag) ((flag) / FLAGSET_NBITS)
+/** Element bit for flag \a flag. */
+#define FLAGSET_MASK(flag) (1ul<<((flag) % FLAGSET_NBITS))
+
+/** Declare a flagset structure of a particular size. */
+#define DECLARE_FLAGSET(name,max) \
+ struct name \
+ { \
+ unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
+ }
+
+/** Test whether a flag is set in a flagset. */
+#define FlagHas(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
+/** Set a flag in a flagset. */
+#define FlagSet(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag))
+/** Clear a flag in a flagset. */
+#define FlagClr(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag))
+
+/** String containing valid user modes, in no particular order. */
+#define infousermodes "diOoswkgx"
+
+/** Operator privileges. */
+enum Priv
+ {
+ PRIV_CHAN_LIMIT, /**< no channel limit on oper */
+ PRIV_MODE_LCHAN, /**< oper can mode local chans */
+ PRIV_WALK_LCHAN, /**< oper can walk through local modes */
+ PRIV_DEOP_LCHAN, /**< no deop oper on local chans */
+ PRIV_SHOW_INVIS, /**< show local invisible users */
+ PRIV_SHOW_ALL_INVIS, /**< show all invisible users */
+ PRIV_UNLIMIT_QUERY, /**< unlimit who queries */
+ PRIV_KILL, /**< oper can KILL */
+ PRIV_LOCAL_KILL, /**< oper can local KILL */
+ PRIV_REHASH, /**< oper can REHASH */
+ PRIV_RESTART, /**< oper can RESTART */
+ PRIV_DIE, /**< oper can DIE */
+ PRIV_GLINE, /**< oper can GLINE */
+ PRIV_LOCAL_GLINE, /**< oper can local GLINE */
+ PRIV_JUPE, /**< oper can JUPE */
+ PRIV_LOCAL_JUPE, /**< oper can local JUPE */
+ PRIV_OPMODE, /**< oper can OP/CLEARMODE */
+ PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */
+ PRIV_SET, /**< oper can SET */
+ PRIV_WHOX, /**< oper can use /who x */
+ PRIV_BADCHAN, /**< oper can BADCHAN */
+ PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */
+ PRIV_SEE_CHAN, /**< oper can see in secret chans */
+ PRIV_PROPAGATE, /**< propagate oper status */
+ PRIV_DISPLAY, /**< "Is an oper" displayed */
+ PRIV_SEE_OPERS, /**< display hidden opers */
+ PRIV_WIDE_GLINE, /**< oper can set wider G-lines */
+ PRIV_LIST_CHAN, /**< oper can list secret channels */
+ PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */
+ PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */
+ PRIV_APASS_OPMODE, /**< can hack modes +A/-A/+U/-U */
+ PRIV_UNLIMIT_FLOOD, /**< user won't get excess flooded */
+ PRIV_LAST_PRIV /**< number of privileges */
+ };
+
+/** Client flags and modes.
+ * Note that flags at least FLAG_LOCAL_UMODES but less than
+ * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least
+ * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as
+ * global modes.
+ */
+enum Flag
+ {
+ FLAG_PINGSENT, /**< Unreplied ping sent */
+ FLAG_DEADSOCKET, /**< Local socket is dead--Exiting soon */
+ FLAG_KILLED, /**< Prevents "QUIT" from being sent for this */
+ FLAG_BLOCKED, /**< socket is in a blocked condition */
+ FLAG_CLOSING, /**< set when closing to suppress errors */
+ FLAG_UPING, /**< has active UDP ping request */
+ FLAG_HUB, /**< server is a hub */
+ FLAG_IPV6, /**< server understands P10 IPv6 addrs */
+ FLAG_SERVICE, /**< server is a service */
+ FLAG_GOTID, /**< successful ident lookup achieved */
+ FLAG_DOID, /**< I-lines say must use ident return */
+ FLAG_NONL, /**< No \n in buffer */
+ FLAG_TS8, /**< Why do you want to know? */
+ FLAG_MAP, /**< Show server on the map */
+ FLAG_JUNCTION, /**< Junction causing the net.burst. */
+ FLAG_BURST, /**< Server is receiving a net.burst */
+ FLAG_BURST_ACK, /**< Server is waiting for eob ack */
+ FLAG_IPCHECK, /**< Added or updated IPregistry data */
+ FLAG_LOCOP, /**< Local operator -- SRB */
+ FLAG_SERVNOTICE, /**< server notices such as kill */
+ FLAG_OPER, /**< Operator */
+ FLAG_INVISIBLE, /**< makes user invisible */
+ FLAG_WALLOP, /**< send wallops to them */
+ FLAG_DEAF, /**< Makes user deaf */
+ FLAG_CHSERV, /**< Disallow KICK or MODE -o on the user;
+ don't display channels in /whois */
+ FLAG_DEBUG, /**< send global debug/anti-hack info */
+ FLAG_ACCOUNT, /**< account name has been set */
+ FLAG_HIDDENHOST, /**< user's host is hidden */
+ FLAG_SSLCONN, /**< SSL Connection */
+ FLAG_LAST_FLAG, /**< number of flags */
+ FLAG_LOCAL_UMODES = FLAG_LOCOP, /**< First local mode flag */
+ FLAG_GLOBAL_UMODES = FLAG_OPER /**< First global mode flag */
+ };
+
+/** Declare flagset type for operator privileges. */
+DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
+/** Declare flagset type for user flags. */
+DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
+
+#include "capab.h" /* client capabilities */
+
+/** Represents a local connection.
+ * This contains a lot of stuff irrelevant to server connections, but
+ * those are so rare as to not be worth special-casing.
+ */
+struct Connection
+{
+ unsigned long con_magic; /**< magic number */
+ struct Connection* con_next; /**< Next connection with queued data */
+ struct Connection** con_prev_p; /**< What points to us */
+ struct Client* con_client; /**< Client associated with connection */
+ unsigned int con_count; /**< Amount of data in buffer */
+ int con_freeflag; /**< indicates if connection can be freed */
+ int con_error; /**< last socket level error for client */
+ int con_sentalong; /**< sentalong marker for connection */
+ unsigned int con_snomask; /**< mask for server messages */
+ time_t con_nextnick; /**< Next time a nick change is allowed */
+ time_t con_nexttarget;/**< Next time a target change is allowed */
+ time_t con_lasttime; /**< Last time data read from socket */
+ time_t con_since; /**< Last time we accepted a command */
+ struct MsgQ con_sendQ; /**< Outgoing message queue */
+ struct DBuf con_recvQ; /**< Incoming data yet to be parsed */
+ unsigned int con_sendM; /**< Stats: protocol messages sent */
+ unsigned int con_receiveM; /**< Stats: protocol messages received */
+ uint64_t con_sendB; /**< Bytes sent. */
+ uint64_t con_receiveB; /**< Bytes received. */
+ struct Listener* con_listener; /**< Listening socket which we accepted
+ from. */
+ struct SLink* con_confs; /**< Associated configuration records. */
+ HandlerType con_handler; /**< Message index into command table
+ for parsing. */
+ struct ListingArgs* con_listing; /**< Current LIST status. */
+ unsigned int con_max_sendq; /**< cached max send queue for client */
+ unsigned int con_ping_freq; /**< cached ping freq */
+ unsigned short con_lastsq; /**< # 2k blocks when sendqueued
+ called last. */
+ unsigned char con_targets[MAXTARGETS]; /**< Hash values of
+ current targets. */
+ char con_sock_ip[SOCKIPLEN + 1]; /**< Remote IP address as a string. */
+ char con_sockhost[HOSTLEN + 1]; /**< This is the host name from
+ the socket and after which the
+ connection was accepted. */
+ char con_passwd[PASSWDLEN + 1]; /**< Password given by user. */
+ char con_buffer[BUFSIZE]; /**< Incoming message buffer; or
+ the error that caused this
+ clients socket to close. */
+ struct Socket con_socket; /**< socket descriptor for
+ client */
+ struct Timer con_proc; /**< process latent messages from
+ client */
+ struct Privs con_privs; /**< Oper privileges */
+ struct CapSet con_capab; /**< Client capabilities (from us) */
+ struct CapSet con_active; /**< Active capabilities (to us) */
+ struct AuthRequest* con_auth; /**< Auth request for client */
+ struct SSLConnection* con_ssl; /**< SSL connection for client */