The complete source code of IdealIRC http://www.idealirc.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
idealirc/IRCClient/IRCBasePriv.h

161 lines
5.0 KiB

/*
* IdealIRC Core - Internet Relay Chat API
* Copyright (C) 2021 Tom-Andre Barstad.
* This software is licensed under the Software Attribution License.
* See LICENSE for more information.
*/
#ifndef IRCBASEPRIV_H
#define IRCBASEPRIV_H
#include "Numeric.h"
#include "IRCError.h"
#include "IRCPrefix.h"
#include "IRCMember.h"
#include "IRCChannel.h"
#include "IRCMessage.h"
#include "DCC.h"
#include <asio.hpp>
#include <asio/ssl.hpp>
#include <ctime>
namespace {
/* Debug/development options */
constexpr bool DumpReadData = true;
constexpr bool DumpWriteData = true;
const std::vector<std::string> V3Support {
"account-notify",
"extended-join",
"away-notify",
"invite-notify",
"multi-prefix",
"userhost-in-names",
"message-tags",
"server-time",
//"batch"
/*
* TODO https://ircv3.net/irc/
* chghost
* sasl
*/
};
} // end anonymous namespace
class IRCBase;
using asio::ip::tcp;
struct IRCBasePriv
{
explicit IRCBasePriv(IRCBase& super_)
: super(super_)
, sslctx(asio::ssl::context::tls)
, resolver(ioctx)
, keepaliveTimer(ioctx)
{
readbuf.reserve(1024);
setDefaults();
}
IRCBase& super;
std::string hostname;
std::string port;
std::string realname;
std::string ident;
std::string password;
std::string nickname;
struct {
bool selfSigned{ false };
bool CNMismactch{ false };
bool expired{ false };
} sslExcept;
bool useSSL{ false };
asio::io_context ioctx;
asio::ssl::context sslctx;
tcp::resolver resolver;
tcp::resolver::results_type endpoints;
std::string readbuf;
std::optional<tcp::socket> sock;
std::optional< asio::ssl::stream<asio::ip::tcp::socket> > sslsock;
std::vector<IRCError> sslExceptions; // List of SSL verification errors that were ignored.
bool isConnected{ false }; // When the socket itself is successfully connected.
bool isOnline{ false }; // When the client itself is successfully registered.
IRCError lastError{ IRCError::NoError };
std::chrono::seconds keepaliveFreq{ 0 };
asio::steady_timer keepaliveTimer;
std::vector<std::shared_ptr<DCC>> dcclist;
std::unordered_map<std::string,std::string> isupport;
std::vector<std::string> registeredV3support;
std::vector<std::string> serverV3support;
std::vector<std::shared_ptr<IRCMember>> allMembers;
std::vector<std::shared_ptr<IRCChannel>> channels;
std::string validPrivilegeModes; // ohv etc. Ordered by most significant first.
std::string validPrivilegeSymbols; // @%+ etc. Ordered by most significant first.
/*
* Various helper functions for the IRC client implementation.
*/
char channelModeGroup(char m) const;
bool isChannelSymbol(char c);
bool isMemberPrivilegeSymbol(char m) const;
char memberPrivilegeSymbolToMode(char s) const;
void setDefaults();
void startKeepaliveTimer();
void stopKeepaliveTimer();
void keepaliveTimeout(const asio::error_code& ec);
void disconnectHandler();
void read(const asio::error_code& ec, std::size_t /*size*/);
void connected(const asio::error_code& /*ec*/);
void write(const std::string& command, const std::vector<std::string>& args, const std::string& msg);
void writeNoMsg(const std::string& command, const std::vector<std::string>& args);
void write(const std::string& command, const std::string& msg);
void ctcp(const std::string& messageType, const std::string& target, const std::string& command, const std::string& message = "");
void addMemberToChannel(const IRCPrefix& prefix, const std::string& channel);
void delMemberFromChannel(const IRCPrefix& prefix, const std::string& channel);
IRCError verify_X509(X509* cert);
void parseChannelModeMessage(std::shared_ptr<IRCChannel> chan, const std::string& modes, const std::vector<std::string>& args) const;
void parseIncoming(const std::string& line);
/*
* Message handlers for the various messages we receive from the IRC server.
*/
void handleNumeric(const IRCMessage& ircmessage);
void cmdNick(const IRCMessage& ircmessage);
void cmdMode(const IRCMessage& ircmessage);
void cmdQuit(const IRCMessage& ircmessage);
void cmdJoin(const IRCMessage& ircmessage);
void cmdPart(const IRCMessage& ircmessage);
void cmdTopic(const IRCMessage& ircmessage);
void cmdInvite(const IRCMessage& ircmessage);
void cmdKick(const IRCMessage& ircmessage);
void cmdPrivmsg(const IRCMessage& ircmessage);
void cmdNotice(const IRCMessage& ircmessage);
void cmdKill(const IRCMessage& ircmessage);
void cmdPing(const IRCMessage& ircmessage);
void cmdPong(const IRCMessage& ircmessage);
void cmdError(const IRCMessage& ircmessage);
void cmdWallops(const IRCMessage& ircmessage);
void cmdV3Cap(const IRCMessage& ircmessage);
void cmdV3Away(const IRCMessage& ircmessage);
void cmdv3Account(const IRCMessage& ircmessage);
void handleUnhandled(const IRCMessage& ircmessage);
};
#endif // IRCBASEPRIV_H