1 #ifndef _KVI_IRCSERVER_H_ 2 #define _KVI_IRCSERVER_H_ 3 //============================================================================= 4 // 5 // File : KviIrcServer.h 6 // Creation date : Mon Jul 10 2000 03:24:11 by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 /** 28 * \file KviIrcServer.h 29 * \author Szymon Stefanek 30 * \brief Irc server handling 31 */ 32 33 #include "kvi_settings.h" 34 #include "kvi_inttypes.h" 35 #include "KviHeapObject.h" 36 #include "KviPointerList.h" 37 38 #include <QString> 39 #include <QStringList> 40 41 class KviConfigurationFile; 42 class KviNickServRuleSet; 43 class KviProxy; 44 class KviProxyDataBase; 45 class KviIrcServerReconnectInfo; 46 47 /** 48 * \class KviIrcServer 49 * \brief The class which manages the irc servers 50 */ 51 class KVILIB_API KviIrcServer : public KviHeapObject 52 { 53 public: 54 /** 55 * \enum Flags 56 * \brief Contains the features supported by the server 57 */ 58 enum Flags 59 { 60 IPv6 = 1, /**< IPv6 support */ 61 CacheIP = 2, /**< whether we cache the server's IP */ 62 SSL = 4, /**< SSL support */ 63 STARTTLS = 8, /**< STARTTLS support */ 64 SASL = 16, /**< SASL support */ 65 CAP = 32, /**< CAP support */ 66 FAVORITE = 64 /**< Favorite Server */ 67 }; 68 69 /** 70 * \brief Constructs the server object 71 * \return KviIrcServer 72 */ 73 KviIrcServer(); 74 75 /** 76 * \brief Carbon copy 77 * \param serv The irc server 78 * \return KviIrcServer 79 */ 80 KviIrcServer(const KviIrcServer & serv); 81 82 /** 83 * \brief Destroys the server object 84 */ 85 ~KviIrcServer(); 86 87 private: 88 KviIrcServerReconnectInfo * m_pReconnectInfo; 89 QString m_szHostname; /**< the server hostname (or IP eventually) */ 90 QString m_szIp; /**< the server's cached ip (if we're caching) */ 91 QString m_szDescription; /**< the server description */ 92 kvi_u32_t m_uPort; /**< the server's port */ 93 unsigned short int m_uFlags; /**< flags */ 94 95 // Extended data 96 QString m_szUserIdentityId; /**< the user identity to use for this server: if empty, then use the network identity instead */ 97 QString m_szUser; /**< special username */ 98 QString m_szPass; /**< special password */ 99 QString m_szNick; /**< special nickname */ 100 QString m_szAlternativeNick; /**< alternate special nickname */ 101 QString m_szRealName; /**< special real name */ 102 QString m_szInitUMode; /**< special user mode */ 103 QString m_szOnConnectCommand; /**< the command to run on connect */ 104 QString m_szOnLoginCommand; /**< the command to run after login */ 105 QString m_szLinkFilter; /**< the link filter object */ 106 QString m_szEncoding; /**< if empty, use network encoding */ 107 QString m_szTextEncoding; /**< if empty, use network encoding */ 108 QStringList * m_pAutoJoinChannelList; /**< Channels to auto join */ 109 bool m_bAutoConnect; /**< autoconnect */ 110 QString m_szId; /**< the server's may-be-unique id, may be auto-generated */ 111 int m_iProxy; /**< proxy server's id */ 112 QString m_szSaslNick; /**< nickname for sasl auth */ 113 QString m_szSaslPass; /**< password for sasl auth */ 114 QString m_szSaslMethod; /**< method name for sasl auth */ 115 116 public: reconnectInfo()117 KviIrcServerReconnectInfo * reconnectInfo() 118 { 119 return m_pReconnectInfo; 120 } 121 122 void clearReconnectInfo(); 123 124 void setReconnectInfo(KviIrcServerReconnectInfo * pInfo); 125 126 /** 127 * \brief Returns the proxy server's id 128 * \return int 129 */ proxy()130 int proxy() const { return m_iProxy; } 131 132 /** 133 * \brief Returns the proxy server 134 * \param pDb The proxy database 135 * \return KviProxy 136 */ 137 KviProxy * proxyServer(KviProxyDataBase * pDb); 138 139 /** 140 * \brief Returns the port number 141 * \return kvi_u32_t 142 */ port()143 kvi_u32_t port() const { return m_uPort; } 144 145 /** 146 * \brief Returns the password of the user associated to the server 147 * \return const QString & 148 */ password()149 const QString & password() const { return m_szPass; } 150 151 /** 152 * \brief Returns the nickname used for sasl auth 153 * \return const QString & 154 */ saslNick()155 const QString & saslNick() const { return m_szSaslNick; } 156 157 /** 158 * \brief Returns the password used for sasl auth 159 * \return const QString & 160 */ saslPass()161 const QString & saslPass() const { return m_szSaslPass; } 162 163 /** 164 * \brief Returns the sasl authentication method to be used 165 * \return const QString & 166 */ saslMethod()167 const QString & saslMethod() const { return m_szSaslMethod; } 168 169 /** 170 * \brief Returns the nickname of the user associated to the server 171 * \return const QString & 172 */ nickName()173 const QString & nickName() const { return m_szNick; } 174 175 /** 176 * \brief Returns the alternative nickname of the user associated to the server 177 * \return const QString & 178 */ alternativeNickName()179 const QString & alternativeNickName() const { return m_szAlternativeNick; } 180 181 /** 182 * \brief Returns the user modes of the user associated to the server 183 * \return const QString & 184 */ initUMode()185 const QString & initUMode() const { return m_szInitUMode; } 186 187 /** 188 * \brief Returns the hostname of the user associated to the server 189 * \return const QString & 190 */ hostName()191 const QString & hostName() const { return m_szHostname; } 192 193 /** 194 * \brief Returns the IP address of the server 195 * \return const QString & 196 */ ip()197 const QString & ip() const { return m_szIp; } 198 199 /** 200 * \brief Returns the commands to run on server login 201 * \return const QString & 202 */ onLoginCommand()203 const QString & onLoginCommand() const { return m_szOnLoginCommand; } 204 205 /** 206 * \brief Returns the commands to run on server connection 207 * \return const QString & 208 */ onConnectCommand()209 const QString & onConnectCommand() const { return m_szOnConnectCommand; } 210 211 /** 212 * \brief Returns the username of the user associated to the server 213 * \return const QString & 214 */ userName()215 const QString & userName() const { return m_szUser; } 216 217 /** 218 * \brief Returns the realname of the user associated to the server 219 * \return const QString & 220 */ realName()221 const QString & realName() const { return m_szRealName; } 222 223 /** 224 * \brief Returns the filter applied on the server 225 * \return const QString & 226 */ linkFilter()227 const QString & linkFilter() const { return m_szLinkFilter; } 228 229 /** 230 * \brief Returns the description of the server 231 * \return const QString & 232 */ description()233 const QString & description() const { return m_szDescription; } 234 235 /** 236 * \brief Returns the encoding associated to the server 237 * Some information as nickname and channel names are encoded when 238 * communicating with the server 239 * \return const QString & 240 */ encoding()241 const QString & encoding() const { return m_szEncoding; } 242 243 /** 244 * \brief Returns the text encoding associated to the server 245 * This is the default encoding when talking on channels or queries 246 * \return const QString & 247 */ textEncoding()248 const QString & textEncoding() const { return m_szTextEncoding; } 249 250 /** 251 * \brief Returns the id of the server 252 * \return const QString & 253 */ id()254 const QString & id() const { return m_szId; } 255 256 /** 257 * \brief Returns the id of the user associated to the server 258 * \return const QString & 259 */ userIdentityId()260 const QString & userIdentityId() const { return m_szUserIdentityId; } 261 262 /** 263 * \brief Returns true if the server is in autoconnect mode 264 * \return bool 265 */ autoConnect()266 bool autoConnect() const { return m_bAutoConnect; } 267 268 /** 269 * \brief Returns the list of the channels in the autojoin list 270 * \return QStringList * 271 */ autoJoinChannelList()272 QStringList * autoJoinChannelList() { return m_pAutoJoinChannelList; } 273 274 /** 275 * \brief Returns the list of the channels in the autojoin list as a string 276 * \return const QString & 277 */ autoJoinChannelListAsString()278 const QString autoJoinChannelListAsString() { return m_pAutoJoinChannelList ? m_pAutoJoinChannelList->join(",") : ""; } 279 280 /** 281 * \brief Returns true if the server uses IPv6 282 * \return bool 283 */ isIPv6()284 bool isIPv6() const { return (m_uFlags & KviIrcServer::IPv6); } 285 286 /** 287 * \brief Returns true if the server uses SSL 288 * \return bool 289 */ useSSL()290 bool useSSL() const { return (m_uFlags & KviIrcServer::SSL); } 291 292 /** 293 * \brief Returns true if the CAP protocol is enabled for this server 294 * \return bool 295 */ enabledCAP()296 bool enabledCAP() const { return (m_uFlags & KviIrcServer::CAP); } 297 298 /** 299 * \brief Returns true if the STARTTLS protocol is enabled for this server 300 * \return bool 301 */ enabledSTARTTLS()302 bool enabledSTARTTLS() const { return (m_uFlags & KviIrcServer::STARTTLS); } 303 304 /** 305 * \brief Returns true if the SASL protocol is enabled for this server 306 * \return bool 307 */ enabledSASL()308 bool enabledSASL() const { return (m_uFlags & KviIrcServer::SASL); } 309 310 /** 311 * \brief Returns true if the server caches the IP 312 * \return bool 313 */ cacheIp()314 bool cacheIp() const { return (m_uFlags & KviIrcServer::CacheIP); } 315 316 /** 317 * \brief Returns the irc URI for the server 318 * The URI is in the form irc[[s]6]://name.serverhost.tld 319 * \return QString 320 */ 321 QString ircUri(); 322 323 /** 324 * \brief Sets the proxy server for the server 325 * \param iProxy The proxy to connect through 326 * \return void 327 */ setProxy(int iProxy)328 void setProxy(int iProxy) { m_iProxy = iProxy; } 329 330 /** 331 * \brief Sets the IP for the server 332 * \param szIp The IP of the server 333 * \return void 334 */ setIp(const QString & szIp)335 void setIp(const QString & szIp) { m_szIp = szIp; } 336 337 /** 338 * \brief Sets the port for the server 339 * \param uPort The port of the server 340 * \return void 341 */ setPort(kvi_u32_t uPort)342 void setPort(kvi_u32_t uPort) { m_uPort = uPort; } 343 344 /** 345 * \brief Sets the hostname for the server 346 * \param szHost The host name of the user 347 * \return void 348 */ setHostName(const QString & szHost)349 void setHostName(const QString & szHost) { m_szHostname = szHost; } 350 351 /** 352 * \brief Sets the description for the server 353 * \param szDesc The description of the server 354 * \return void 355 */ setDescription(const QString & szDesc)356 void setDescription(const QString & szDesc) { m_szDescription = szDesc; } 357 358 /** 359 * \brief Sets the username of the user associated to the server 360 * \param szUser The user name of the user 361 * \return void 362 */ setUserName(const QString & szUser)363 void setUserName(const QString & szUser) { m_szUser = szUser; } 364 365 /** 366 * \brief Sets the password of the user associated to the server 367 * \param szPass The password of the user 368 * \return void 369 */ setPassword(const QString & szPass)370 void setPassword(const QString & szPass) { m_szPass = szPass; } 371 372 /** 373 * \brief Sets the nickname of the user associated to the server 374 * \param szNick The nick name of the user 375 * \return void 376 */ setNickName(const QString & szNick)377 void setNickName(const QString & szNick) { m_szNick = szNick; } 378 379 /** 380 * \brief Sets the alternative nickname of the user associated to the server 381 * \param szNick The nick name of the user 382 * \return void 383 */ setAlternativeNickName(const QString & szNick)384 void setAlternativeNickName(const QString & szNick) { m_szAlternativeNick = szNick; } 385 386 /** 387 * \brief Sets the password used for sasl auth 388 * \param szPass The password of the user 389 * \return void 390 */ setSaslPass(const QString & szPass)391 void setSaslPass(const QString & szPass) { m_szSaslPass = szPass; } 392 393 /** 394 * \brief Sets the nickname used for sasl auth 395 * \param szNick The nick name of the user 396 * \return void 397 */ setSaslNick(const QString & szNick)398 void setSaslNick(const QString & szNick) { m_szSaslNick = szNick; } 399 400 /** 401 * \brief Sets the sasl method to be used for auth 402 * \param szMethod The method name 403 * \return void 404 */ setSaslMethod(const QString & szMethod)405 void setSaslMethod(const QString & szMethod) { m_szSaslMethod = szMethod; } 406 407 /** 408 * \brief Sets the realname of the user associated to the server 409 * \param szReal The real name of the user 410 * \return void 411 */ setRealName(const QString & szReal)412 void setRealName(const QString & szReal) { m_szRealName = szReal; } 413 414 /** 415 * \brief Sets the encoding associated to the server 416 * Some information as nickname and channel names are encoded when 417 * communicating with the server 418 * This is the default encoding when talking on channels or queries 419 * \param szEncoding The default encoding of the text 420 * \return void 421 */ setEncoding(const QString & szEncoding)422 void setEncoding(const QString & szEncoding) { m_szEncoding = szEncoding; } 423 424 /** 425 * \brief Sets the encoding associated to the server 426 * This is the default encoding when talking on channels or queries 427 * \param szEncoding The default encoding of the text 428 * \return void 429 */ setTextEncoding(const QString & szEncoding)430 void setTextEncoding(const QString & szEncoding) { m_szTextEncoding = szEncoding; } 431 432 /** 433 * \brief Sets the user modes of the user associated to the server 434 * \param szUMode The user modes of the user 435 * \return void 436 */ setInitUMode(const QString & szUMode)437 void setInitUMode(const QString & szUMode) { m_szInitUMode = szUMode; } 438 439 /** 440 * \brief Sets the commands to run on server connection 441 * \param szCmd The comands to run on connection 442 * \return void 443 */ setOnConnectCommand(const QString & szCmd)444 void setOnConnectCommand(const QString & szCmd) { m_szOnConnectCommand = szCmd; } 445 446 /** 447 * \brief Sets the commands to run on server login 448 * \param szCmd The comands to run on login 449 * \return void 450 */ setOnLoginCommand(const QString & szCmd)451 void setOnLoginCommand(const QString & szCmd) { m_szOnLoginCommand = szCmd; } 452 453 /** 454 * \brief Applies the filter to the server 455 * 456 * A link filter resides between the low-level socket, which send/receive blocks 457 * of bytes, and the connection which talk using IRC messages. 458 * The filter can remap blocks of bytes in any direction 459 * \param szFilter 460 * \return void 461 */ setLinkFilter(const QString & szFilter)462 void setLinkFilter(const QString & szFilter) { m_szLinkFilter = szFilter; } 463 464 /** 465 * \brief Sets the list of channels to autojoin after connection 466 * The channel list must be allocated with a new! 467 * \param pNewChannelList The list of channels to autojoin 468 * \return void 469 */ 470 void setAutoJoinChannelList(QStringList * pNewChannelList); 471 472 /** 473 * \brief Sets the list of channels to mark for autojoin 474 * \param szNewChannelList A comma separated list of channels 475 * \return void 476 */ 477 void setAutoJoinChannelList(const QString & szNewChannelList); 478 479 /** 480 * \brief Sets the autoconnection mode for the server 481 * \param bAutoConnect Whether to set the autoconnection 482 * \return void 483 */ setAutoConnect(bool bAutoConnect)484 void setAutoConnect(bool bAutoConnect) { m_bAutoConnect = bAutoConnect; } 485 486 /** 487 * \brief Sets the id of the user associated to the server 488 * \param szUserIdentityId The user identity id to set 489 * \return void 490 */ setUserIdentityId(const QString & szUserIdentityId)491 void setUserIdentityId(const QString & szUserIdentityId) { m_szUserIdentityId = szUserIdentityId; } 492 493 /** 494 * \brief Sets if the server uses IPv6 495 * \param bSet Whether to set the support for IPv6 496 * \return void 497 */ setIPv6(bool bSet)498 void setIPv6(bool bSet) 499 { 500 if(bSet) 501 m_uFlags |= KviIrcServer::IPv6; 502 else 503 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::IPv6); 504 } 505 506 /** 507 * \brief Sets if the server uses SSL 508 * \param bSet Whether to set the support for SSL 509 * \return void 510 */ setUseSSL(bool bSet)511 void setUseSSL(bool bSet) 512 { 513 if(bSet) 514 m_uFlags |= KviIrcServer::SSL; 515 else 516 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::SSL); 517 } 518 519 /** 520 * \brief Sets if STARTTLS support is enabled/disabled for this server 521 * \param bSet Whether to enable the support for STARTTLS 522 * \return void 523 */ setEnabledSTARTTLS(bool bSet)524 void setEnabledSTARTTLS(bool bSet) 525 { 526 if(bSet) 527 m_uFlags |= KviIrcServer::STARTTLS; 528 else 529 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::STARTTLS); 530 } 531 532 /** 533 * \brief Sets if CAP support is enabled/disabled for this server 534 * \param bSet Whether to enable the support for CAP 535 * \return void 536 */ setEnabledCAP(bool bSet)537 void setEnabledCAP(bool bSet) 538 { 539 if(bSet) 540 m_uFlags |= KviIrcServer::CAP; 541 else 542 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::CAP); 543 } 544 545 /** 546 * \brief Sets if SASL support is enabled/disabled for this server 547 * \param bSet Whether to enable the support for SASL 548 * \return void 549 */ setEnabledSASL(bool bSet)550 void setEnabledSASL(bool bSet) 551 { 552 if(bSet) 553 m_uFlags |= KviIrcServer::SASL; 554 else 555 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::SASL); 556 } 557 558 /** 559 * \brief Sets if the server caches the IP 560 * \param bSet Whether to set the cache for the IP 561 * \return void 562 */ setCacheIp(bool bSet)563 void setCacheIp(bool bSet) 564 { 565 if(bSet) 566 m_uFlags |= KviIrcServer::CacheIP; 567 else 568 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::CacheIP); 569 } 570 571 /** 572 * \brief Generates an unique id for the server and sets it 573 * \return void 574 */ 575 void generateUniqueId(); 576 577 /** 578 * \brief Sets an unique id for the server 579 * \param szId The id of the server 580 * \return void 581 */ setId(const QString & szId)582 void setId(const QString & szId) 583 { 584 m_szId = szId; 585 if(m_szId.isEmpty()) 586 generateUniqueId(); 587 } 588 589 /** 590 * \brief Loads the information from the configuration file 591 * \param pCfg The configuration file 592 * \param szPrefix The prefix of the server 593 * \return bool 594 */ 595 bool load(KviConfigurationFile * pCfg, const QString & szPrefix); 596 597 /** 598 * \brief Saves the information to the configuration file 599 * \param pCfg The configuration file 600 * \param szPrefix The prefix of the server 601 * \return void 602 */ 603 void save(KviConfigurationFile * pCfg, const QString & szPrefix); 604 605 /** 606 * \brief Carbon copy 607 * \param serv The server to copy 608 * \return void 609 */ 610 void operator=(const KviIrcServer & serv); 611 612 /** 613 * \brief Sets the server to a favorite 614 * \param bSet whether the server is a favorite or not 615 * \return void 616 */ setFavorite(bool bSet)617 void setFavorite(bool bSet) 618 { 619 if(bSet) 620 m_uFlags |= KviIrcServer::FAVORITE; 621 else 622 m_uFlags &= static_cast<unsigned short>(~KviIrcServer::FAVORITE); 623 } 624 625 /** 626 * \brief Returns if the server is a favorite 627 * \return bool 628 */ favorite()629 bool favorite() const { return (m_uFlags & KviIrcServer::FAVORITE); } 630 }; 631 632 #endif //_KVI_IRCSERVER_H_ 633