ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An intelligent IRC proxy 00002 // 00003 //! @file WhoRequest.h 00004 //! @brief Header of class WhoRequest 00005 // 00006 // Copyright (C) 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef WHOREQUEST_H 00017 #define WHOREQUEST_H 00018 00019 #ifndef USE_PCH 00020 #include <string> 00021 #endif 00022 00023 class ClientSession; 00024 00025 //! @brief A class representing the options that can be passed to a WhoRequest. 00026 // 00027 // The "options" part can be as follows: 00028 // 00029 // [<flags>][%[<fields>[,<querytype>]]] 00030 // 00031 // in which: 00032 // 00033 // <flags>: can be a sequence of field matching flags, use mode matching flags 00034 // and special purpose flags 00035 // 00036 // Field matching flags, when one of these is specified the field in 00037 // question is matched against the mask, otherwise it's not matched. 00038 // 00039 // n Nick (in nick!user@host) 00040 // u Username (in nick!user@host) 00041 // h Hostname (in nick!user@host) 00042 // i Numeric IP (the unresolved host) 00043 // s Servername (the canonic name of the server the guy is on) 00044 // r Info text (formerly "Realname") 00045 // a Account name 00046 // 00047 // If no field-matching flags are specified they default to what old servers 00048 // used to do: nuhsr (= everything except the numeric IP) 00049 // 00050 // User mode matching flags (specifying one of these means that only clients 00051 // with that umode are considered, what is not specified is always matched): 00052 // 00053 // d Join-delayed channel members 00054 // o Irc operator 00055 // [In the future more flags will be supported, basically all 00056 // usermodes plus the +/- specificators to revert the filtering] 00057 // 00058 // Special purpose flags: 00059 // 00060 // x If this is specified the extended visibility of information for opers 00061 // is applied, what this means depends on the fact that you are local or 00062 // global operator and on how the admin configured the server (global 00063 // and eventually local irc opers might be allowed with this flag to see 00064 // +i local users, to see all +i users, to see users into +p and/or +s 00065 // channels, and so on). Using the 'x' flag while not being an irc 00066 // operator is meaningless (it will be ignored), using it while oper'd 00067 // means that the query is almost certainly logged and the admin might 00068 // (rightfully) ask you an explanation on why you did. 00069 // 00070 // The rest, what follows the %, that is [%[fields[,<querytype>]]], is as it 00071 // has always been since the first who.patch, the <fields> part specifies 00072 // which fields to include in the output as: 00073 // 00074 // c : Include (first) channel name 00075 // d : Include "distance" in hops (hopcount) 00076 // f : Include flags (all of them) 00077 // h : Include hostname 00078 // i : Include IP 00079 // l : Include idle time (0 for remote users) [2.10.11+] 00080 // n : Include nick 00081 // r : Include real name 00082 // s : Include server name 00083 // t : Include the querytype in the reply 00084 // u : Include userID with eventual ~ 00085 // a : Include account name 00086 // o : Include oplevel (shows 999 to users without ops in the channel) 00087 // 00088 // And the ,<querytype> final option can be used to specify what you want the 00089 // server to say in the querytype field of the output, useful to filter the 00090 // output in scripts that do a kind of "on 354 ..." 00091 // 00092 // If no %fields are specified the reply is _exactly_ the same as has always 00093 // been, numeric 352, same fields, same order. 00094 // 00095 class WhoOptions { 00096 private: 00097 std::string M_flags; //!< Everything up till the '%'. 00098 unsigned int M_fields; //!< Mask representing the fields, or 0 when no fields where given. 00099 std::string M_querytype; //!< The query type, or empty when no query type was given. 00100 00101 public: 00102 WhoOptions(void) : M_fields(0) { } 00103 WhoOptions(std::string const& options); 00104 00105 //! Accessor for flags. 00106 std::string const& flags(void) const { return M_flags; } 00107 //! Accessor for fields. 00108 unsigned int fields(void) const { return M_fields; } 00109 //! Accessor for querytype. 00110 std::string const& querytype(void) const { return M_querytype; } 00111 00112 //! Return the reassembled options string. 00113 std::string str(void) const; 00114 00115 //! Return true if the mask is matched against channel names. 00116 bool matches_against_channel(void) const; 00117 }; 00118 00119 //! @brief A WHO request. 00120 // 00121 // Since ircu2.10.05 the format of the who query is. 00122 // 00123 // [:source] WHO <mask1> [<options> [<mask2>]] 00124 // 00125 // <mask2> is optional, if mask2 is present it's used for matching and mask1 is 00126 // ignored, otherwise mask1 is used for matching, since mask2 is the last 00127 // parameter it *can* contain a space and this can help when trying to match a 00128 // "realname". 00129 class WhoRequest { 00130 private: 00131 std::string M_mask; //!< The first or third parameter of the WHO request. 00132 WhoOptions M_options; //!< The options of the WHO request. 00133 bool M_mask_contains_space; //!< True if M_mask contains a space. 00134 bool M_mask_is_target; //!< True if M_mask is a known target and M_target is valid. 00135 boost::shared_ptr<Target> M_target; //!< The target that M_mask refers to. Only valid if M_mask_is_target is true. 00136 00137 private: 00138 void decode_mask(ClientSession& client_session); 00139 00140 public: 00141 //! Construct a WhoRequest for WHO <mask> 00142 WhoRequest(ClientSession& client_session, std::string const& mask) : M_mask(mask) { decode_mask(client_session); } 00143 //! Construct a WhoRequest for WHO <mask> <options> or WHO <dummy> <options> :<mask> 00144 WhoRequest(ClientSession& client_session, std::string const& mask, std::string options) : M_mask(mask), M_options(options) { decode_mask(client_session); } 00145 00146 //! Accessor for the mask. 00147 std::string const& mask(void) const { return M_mask; } 00148 //! Accessor for the options. 00149 WhoOptions const& options(void) const { return M_options; } 00150 //! Return true if the mask contains a space. 00151 bool mask_contains_space(void) const { return M_mask_contains_space; } 00152 //! Return true if the mask is a known target. 00153 bool mask_is_target(void) const { return M_mask_is_target; } 00154 //! Return the target that the mask contains. 00155 boost::shared_ptr<Target> const& mask_target(void) const { ASSERT(M_mask_is_target); return M_target; } 00156 }; 00157 00158 static unsigned int const field_t = 0x0001; //!< the querytype in the reply 00159 static unsigned int const field_c = 0x0002; //!< (first) channel name. 00160 static unsigned int const field_u = 0x0004; //!< userID with eventual ~ 00161 static unsigned int const field_i = 0x0008; //!< IP 00162 static unsigned int const field_h = 0x0010; //!< hostname 00163 static unsigned int const field_s = 0x0020; //!< server name 00164 static unsigned int const field_n = 0x0040; //!< nick 00165 static unsigned int const field_f = 0x0080; //!< flags (all of them) 00166 static unsigned int const field_d = 0x0100; //!< "distance" in hops (hopcount) 00167 static unsigned int const field_l = 0x0200; //!< idle time (0 for remote users) [2.10.11+] 00168 static unsigned int const field_a = 0x0400; //!< account name 00169 static unsigned int const field_r = 0x0800; //!< real name 00170 static unsigned int const field_o = 0x1000; //!< oplevel 00171 static unsigned int const field_percentage = 0x2000; //!< Set if the '%' character was seen. 00172 00173 #endif // WHOREQUEST_H
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|