diff --git a/include/libirc/channel.h b/include/libirc/channel.h new file mode 100644 index 0000000..4c19d74 --- /dev/null +++ b/include/libirc/channel.h @@ -0,0 +1,45 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef LIBIRCCHANNEL_H +#define LIBIRCCHANNEL_H + +#include +#include "serializableitem.h" + +namespace libirc +{ + class LIBIRCSHARED_EXPORT Channel : public SerializableItem + { + public: + Channel(const QString &name); + ~Channel() override=default; + virtual QString GetName() const; + virtual void SetName(const QString &name); + virtual void SetTopic(const QString &topic); + virtual QString GetTopic() const; + virtual void SetTopicTime(const QDateTime &time); + virtual QDateTime GetTopicTime() const; + virtual QString GetTopicUser() const; + virtual void SetTopicUser(const QString &user); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + + protected: + QString _name; + QString _topic; + QDateTime _topicTime; + QString _topicUser; + }; +} + +#endif // CHANNEL_H diff --git a/include/libirc/error_code.h b/include/libirc/error_code.h new file mode 100644 index 0000000..c596090 --- /dev/null +++ b/include/libirc/error_code.h @@ -0,0 +1,22 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef ERROR_CODE +#define ERROR_CODE + +#define SUCCESS 0 +#define ENOTCONNECTED 1 +#define ESOCKETFAILED 2 +#define ENOTIMPLEMENTED 4 + +#endif // ERROR_CODE + diff --git a/include/libirc/irc_numerics.h b/include/libirc/irc_numerics.h new file mode 100644 index 0000000..a7a624a --- /dev/null +++ b/include/libirc/irc_numerics.h @@ -0,0 +1,117 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2018 + +#ifndef IRC_NUMERICS_H +#define IRC_NUMERICS_H + +// Definitions of IRC numerics, lot of them taken from https://www.alien.net.au/irc/irc2numerics.html + +// These are non-standard specific for libirc only +#define IRC_NUMERIC_INVALID -200 +#define IRC_NUMERIC_RAW_PING -1 +#define IRC_NUMERIC_RAW_PRIVMSG -2 +#define IRC_NUMERIC_RAW_NOTICE -3 +#define IRC_NUMERIC_RAW_KICK -4 +#define IRC_NUMERIC_RAW_QUIT -5 +#define IRC_NUMERIC_RAW_PART -6 +#define IRC_NUMERIC_RAW_JOIN -7 +#define IRC_NUMERIC_RAW_NICK -8 +#define IRC_NUMERIC_RAW_MODE -9 +#define IRC_NUMERIC_RAW_TOPIC -10 +#define IRC_NUMERIC_RAW_CTCP -11 +#define IRC_NUMERIC_RAW_CAP -12 +#define IRC_NUMERIC_RAW_AWAY -13 +#define IRC_NUMERIC_RAW_METADATA -14 +#define IRC_NUMERIC_RAW_INVITE -15 +#define IRC_NUMERIC_RAW_CHGHOST -16 // CAP https://ircv3.net/specs/extensions/chghost-3.2.html + +// Both RFC standard and not standard +#define IRC_NUMERIC_RAW_PONG 0 +#define IRC_NUMERIC_WELCOME 1 // The first message sent after client registration. The text used varies widely +#define IRC_NUMERIC_YOURHOST 2 // Part of the post-registration greeting. Text varies widely +#define IRC_NUMERIC_CREATED 3 // Part of the post-registration greeting. Text varies widely +#define IRC_NUMERIC_MYINFO 4 // Part of the post-registration greeting +#define IRC_NUMERIC_BOUNCE 5 // Sent by the server to a user to suggest an alternative server, sometimes used when the connection is refused because the server is already full. +// Also known as RPL_SLINE (AustHex), and RPL_REDIR Also see #010. +#define IRC_NUMERIC_ISUPPORT 5 // Also known as RPL_PROTOCTL (Bahamut, Unreal, Ultimate) +#define IRC_NUMERIC_MAP 6 +#define IRC_NUMERIC_MAPEND 7 +#define IRC_NUMERIC_SNOMASK 8 +#define IRC_NUMERIC_STATMEMTOT 9 +//#define IRC_NUMERIC_BOUNCE 10 +#define IRC_NUMERIC_YOURCOOKIE 14 +#define IRC_NUMERIC_YOURID 42 +#define IRC_NUMERIC_SAVENICK 43 // Sent to the client when their nickname was forced to change due to a collision +#define IRC_NUMERIC_TRACELINK 200 +#define IRC_NUMERIC_STATS 210 +#define IRC_NUMERIC_RPL_TRYAGAIN 263 // When a server drops a command without processing it, it MUST use this reply. Also known as RPL_LOAD_THROTTLED and RPL_LOAD2HI, I'm presuming they do the same thing. +#define IRC_NUMERIC_NONE 300 // Dummy reply, supposedly only used for debugging/testing new features, however has appeared in production daemons. +#define IRC_NUMERIC_AWAY 301 +#define IRC_NUMERIC_UNAWAY 305 // Reply from AWAY when no longer marked as away +#define IRC_NUMERIC_NOWAWAY 306 // Reply from AWAY when marked away +#define IRC_NUMERIC_WHOISREGNICK 307 // Reply to WHOIS - Registered nick +#define IRC_NUMERIC_WHOISUSER 311 // Reply to WHOIS - Information about the user +#define IRC_NUMERIC_WHOISSERVER 312 // Reply to WHOIS - What server they're on +#define IRC_NUMERIC_WHOISOPERATOR 313 // Reply to WHOIS - User has IRC Operator privileges +#define IRC_NUMERIC_WHOWASUSER 314 // Reply to WHOWAS - Information about the user +#define IRC_NUMERIC_ENDOFWHO 315 // Used to terminate a list of RPL_WHOREPLY replies +#define IRC_NUMERIC_WHOISCHANOP 316 // Deprecated +#define IRC_NUMERIC_WHOISIDLE 317 // Reply to WHOIS - Idle information +#define IRC_NUMERIC_ENDOFWHOIS 318 // Reply to WHOIS - End of list +#define IRC_NUMERIC_WHOISCHANNELS 319 // Reply to WHOIS - Channel list for user (See RFC) +#define IRC_NUMERIC_WHOISSPECIAL 320 // Unreal specific +#define IRC_NUMERIC_LISTSTART 321 +#define IRC_NUMERIC_LIST 322 +#define IRC_NUMERIC_LISTEND 323 +#define IRC_NUMERIC_MODEINFO 324 // Response to MODE if no parametres provided +#define IRC_NUMERIC_CHANNELURL 328 +#define IRC_NUMERIC_CREATIONTIME 329 +#define IRC_NUMERIC_WHOISACCOUNT 330 // Unreal specific +#define IRC_NUMERIC_NOTOPIC 331 +#define IRC_NUMERIC_TOPICINFO 332 +#define IRC_NUMERIC_TOPICWHOTIME 333 +#define IRC_NUMERIC_BADCHANPASS 339 +#define IRC_NUMERIC_EXCEPTION 348 +#define IRC_NUMERIC_ENDOFEX 349 +#define IRC_NUMERIC_WHOREPLY 352 +#define IRC_NUMERIC_NAMREPLY 353 +#define IRC_NUMERIC_WHOSPCRPL 354 +#define IRC_NUMERIC_ENDOFNAMES 366 +#define IRC_NUMERIC_BAN 367 +#define IRC_NUMERIC_ENDOFBANS 368 +#define IRC_NUMERIC_ENDOFWHOWAS 369 +#define IRC_NUMERIC_MOTD 372 +#define IRC_NUMERIC_MOTDBEGIN 375 +#define IRC_NUMERIC_MOTDEND 376 +#define IRC_NUMERIC_WHOISHOST 378 // Unreal specific host from which user is connected +#define IRC_NUMERIC_WHOISMODES 379 // Unreal specific list of modes "target nick :is using modes +iwx" +#define IRC_NUMERIC_YOUREOPER 381 +#define IRC_NUMERIC_ERR_UNKNOWNERROR 400 +#define IRC_NUMERIC_ERR_NOSUCHNICK 401 +#define IRC_NUMERIC_ERR_NOSUCHSERVER 402 +#define IRC_NUMERIC_ERR_NOSUCHCHANNEL 403 +#define IRC_NUMERIC_ERR_CANNOTSENDTOCHAN 404 +#define IRC_NUMERIC_ERR_TOOMANYCHANNELS 405 +#define IRC_NUMERIC_ERR_WASNOSUCHNICK 406 +#define IRC_NUMERIC_ERR_TOOMANYTARGETS 407 +#define IRC_NUMERIC_ERR_NOCOLORSONCHAN 408 +#define IRC_NUMERIC_ERR_NOORIGIN 409 +#define IRC_NUMERIC_ERR_INVALIDCAPCMD 410 +#define IRC_NUMERIC_ERR_NORECIPIENT 411 +#define IRC_NUMERIC_ERR_NOTEXTTOSEND 412 +#define IRC_NUMERIC_UNKNOWN 421 +#define IRC_NUMERIC_NICKUSED 433 +#define IRC_NUMERIC_NICKISNOTAVAILABLE 437 +#define IRC_NUMERIC_WHOISSECURE 671 // Reply to WHOIS command - Returned if the target is connected securely, eg. type +// may be TLSv1, or SSLv2 etc. If the type is unknown, a '*' may be used. + +#endif // IRC_NUMERICS_H diff --git a/include/libirc/irc_standards.h b/include/libirc/irc_standards.h new file mode 100644 index 0000000..5d1e6f4 --- /dev/null +++ b/include/libirc/irc_standards.h @@ -0,0 +1,21 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef IRC_STANDARDS +#define IRC_STANDARDS + +#define IRC_STANDARD_PORT 6667 +#define IRC_STANDARD_PORT_SSL 6697 + + +#endif // IRC_STANDARDS + diff --git a/include/libirc/libirc_global.h b/include/libirc/libirc_global.h new file mode 100644 index 0000000..876c2fa --- /dev/null +++ b/include/libirc/libirc_global.h @@ -0,0 +1,12 @@ +#ifndef LIBIRC_GLOBAL_H +#define LIBIRC_GLOBAL_H + +#include + +#if defined(LIBIRC_LIBRARY) +# define LIBIRCSHARED_EXPORT Q_DECL_EXPORT +#else +# define LIBIRCSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // LIBIRC_GLOBAL_H diff --git a/include/libirc/mode.h b/include/libirc/mode.h new file mode 100644 index 0000000..bbb6070 --- /dev/null +++ b/include/libirc/mode.h @@ -0,0 +1,77 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef LIBMODE_H +#define LIBMODE_H + +#include "serializableitem.h" + +#define MODE_INCLUDE '+' +#define MODE_EXCLUDE '-' + +namespace libirc +{ + class LIBIRCSHARED_EXPORT SingleMode : public SerializableItem + { + public: + static QList ToModeList(const QString &mode_string, QList parameters, const QList ¶meter_modes); + + SingleMode(QString mode); + SingleMode(const QHash &hash); + ~SingleMode() override=default; + bool IsIncluding(); + bool IsValid(); + QString ToString() const; + char Get() const; + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + QString Parameter; + + protected: + bool including; + bool valid; + char mode; + }; + + class LIBIRCSHARED_EXPORT Mode : public SerializableItem + { + public: + Mode()=default; + Mode(const QString &mode_string); + ~Mode() override=default; + /*! + * \brief SetMode Take a string for a mode (like +xt) and try to apply it over the existing mode + * \param mode_string String that represent some IRC mode + * \param reset If true the modes after MODE_EXCLUDE sign will be reset, instead of append to exluding modes + */ + void SetMode(const QString &mode_string, bool reset = false); + bool Includes(char mode); + bool Excludes(char mode); + bool IsEmpty(); + void IncludeMode(char mode); + void ExcludeMode(char mode); + void ResetMode(char mode); + void ResetModes(QList modes); + QList GetExcluding(); + QList GetIncluding(); + QString ToString(); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + QString Parameter; + + protected: + QList included_modes; + QList excluded_modes; + }; +} + +#endif // MODE_H diff --git a/include/libirc/network.h b/include/libirc/network.h new file mode 100644 index 0000000..7f1a628 --- /dev/null +++ b/include/libirc/network.h @@ -0,0 +1,34 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2018 + +#ifndef LIBIRCNETWORK_H +#define LIBIRCNETWORK_H + +#include "serializableitem.h" + +namespace libirc +{ + class LIBIRCSHARED_EXPORT Network : public QObject, public SerializableItem + { + Q_OBJECT + public: + Network(const QString &Name); + ~Network() override = default; + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + QString GetNetworkName(); + protected: + QString networkName; + }; +} + +#endif // NETWORK_H diff --git a/include/libirc/serializableitem.h b/include/libirc/serializableitem.h new file mode 100644 index 0000000..694bdc4 --- /dev/null +++ b/include/libirc/serializableitem.h @@ -0,0 +1,65 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef SERIALIZABLEITEM_H +#define SERIALIZABLEITEM_H + +#include +#include +#include +#include +#include "libirc_global.h" + +#define SERIALIZE(variable_name) hash.insert(#variable_name, QVariant(variable_name)) +#define SERIALIZE_CCHAR(variable_name) hash.insert(#variable_name, QVariant(QChar(variable_name))) +#define SERIALIZE_CHARLIST(variable_name) hash.insert(#variable_name, ::libirc::SerializableItem::CCharListToVariantList(variable_name)) +#define UNSERIALIZE_BOOL(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toBool(); } +#define UNSERIALIZE_HASH(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toHash(); } +#define UNSERIALIZE_INT(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toInt(); } +#define UNSERIALIZE_UINT(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toUInt(); } +#define UNSERIALIZE_STRING(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toString(); } +#define UNSERIALIZE_LIST(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toList(); } +#define UNSERIALIZE_CCHAR(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toChar().toLatin1(); } +#define UNSERIALIZE_DATETIME(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toDateTime(); } +#define UNSERIALIZE_ULONGLONG(variable_name) if (hash.contains(#variable_name)) { variable_name = hash[#variable_name].toULongLong(); } +#define UNSERIALIZE_STRINGLIST(list) if (hash.contains(#list)) { list = ::libirc::SerializableItem::DeserializeList_QString(hash[#list]); } +#define UNSERIALIZE_CHARLIST(list) if (hash.contains(#list)) { list = ::libirc::SerializableItem::DeserializeList_char(hash[#list]); } + +namespace libirc +{ + class LIBIRCSHARED_EXPORT SerializableItem + { + public: + static QList DeserializeList_QString(const QVariant &list); + static QList DeserializeList_int(const QVariant &list); + static QList DeserializeList_char(const QVariant &list); + static QList CCharListToVariantList(const QList &list); + static const unsigned long long LIBIRC_UNKNOWN_RPC_ID; + + SerializableItem(); + virtual ~SerializableItem(); + virtual QHash ToHash(); + virtual void LoadHash(QHash hash); + virtual void LoadHash(const QHash &hash); + virtual void RPC(int function, const QList ¶meters); + virtual bool SupportsRPC() { return false; } + virtual unsigned long long __rpc_GetID(); + protected: + static QHash __rpc_cache; + static QMutex __rpc_lock; + + static unsigned long long __rpc_currentID; + unsigned long long __rpc_id; + }; +} + +#endif // SERIALIZABLEITEM_H diff --git a/include/libirc/server.h b/include/libirc/server.h new file mode 100644 index 0000000..1c1efbe --- /dev/null +++ b/include/libirc/server.h @@ -0,0 +1,43 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef LIBIRCSERVER_H +#define LIBIRCSERVER_H + +#include "serializableitem.h" + +namespace libirc +{ + class LIBIRCSHARED_EXPORT Server : public SerializableItem + { + public: + Server(const QHash &hash); + // Default ct + Server(); + ~Server() override = default; + QString GetName() const; + void SetVersion(const QString &version); + void SetName(const QString &name); + QString GetVersion() const; + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + + protected: + QString _name; + QString _host; + QString _version; + unsigned int _port; + bool _ssl; + }; +} + +#endif // SERVER_H diff --git a/include/libirc/serveraddress.h b/include/libirc/serveraddress.h new file mode 100644 index 0000000..63b46cc --- /dev/null +++ b/include/libirc/serveraddress.h @@ -0,0 +1,66 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2018 + +#ifndef SERVERADDRESS_H +#define SERVERADDRESS_H + +#include "serializableitem.h" +#include "libirc_global.h" +#include + +namespace libirc +{ + class LIBIRCSHARED_EXPORT ServerAddress : public SerializableItem + { + public: + ServerAddress(const QString &url); + ServerAddress(const QString &Host, bool SSL, unsigned int Port, const QString &Nick = "", const QString &Password = "", const QString &Ident = ""); + ServerAddress(const QHash &hash); + ~ServerAddress() override=default; + bool IsValid(); + bool UsingSSL(); + QString GetHost(); + QString GetOriginal(); + QString GetIdent(); + void SetNick(const QString &nick); + void SetIdent (const QString &ident); + QString GetNick(); + QString GetPassword(); + //! Usually a list of channels to join after connect + QString GetSuffix(); + void SetSuffix(const QString &suffix); + unsigned int GetPort(); + void SetHost(const QString &host); + void SetPassword(const QString &pw); + void SetPort(unsigned int port); + void SetSSL(bool ssl); + void SetRealname(const QString &name); + QString GetRealname(); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + private: + bool IsIPv6(); + unsigned int _port; + QString _password; + QString _nick; + QString _ident; + QString _host; + QString _realname; + QString _suffix; + bool _ssl; + bool _valid; + bool _ipv6; + QString _original; + }; +} + +#endif // SERVERADDRESS_H diff --git a/include/libirc/user.h b/include/libirc/user.h new file mode 100644 index 0000000..4f40f85 --- /dev/null +++ b/include/libirc/user.h @@ -0,0 +1,52 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef LIBIRCUSER_H +#define LIBIRCUSER_H + +#include "serializableitem.h" + +namespace libirc +{ + class LIBIRCSHARED_EXPORT User : public SerializableItem + { + public: + User()=default; + User(User *user); + User(const QString &source); + ~User() override = default; + virtual QString GetHost() const; + virtual void SetHost(const QString &host); + virtual QString GetNick() const; + virtual void SetNick(const QString &nick); + virtual QString GetIdent() const; + virtual void SetIdent(const QString &ident); + virtual QString ToString() const; + virtual void SetRealname(const QString &user); + virtual QString GetRealname() const; + //! Returns whether User object is null, this can be verified for functions that + //! return a copy of object instead of pointer (pass by value), where it's not + //! possible to return NULL literally. + bool IsNull(); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + + protected: + QString _host; + QString _ident; + QString _nick; + QString _username; + + }; +} + +#endif // USER_H diff --git a/include/libircclient/channel.h b/include/libircclient/channel.h new file mode 100644 index 0000000..cd6fa1d --- /dev/null +++ b/include/libircclient/channel.h @@ -0,0 +1,89 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef CHANNEL_H +#define CHANNEL_H + +// This feature is extremely experimental and known to be bugged due to some internal bugs in Qt +#ifdef LIBIRC_HASH +#undef LIBIRC_HASH +#endif + +#include "libircclient_global.h" +#include +#include +#include +#include "mode.h" +#include "../libirc/channel.h" + +namespace libircclient +{ + class User; + class Network; + class LIBIRCCLIENTSHARED_EXPORT Channel : public libirc::Channel + { + public: + Channel(const QHash &hash); + Channel(const QString &name, Network *network = nullptr); + Channel(Channel *channel); + Channel(const Channel &channel); + ~Channel() override; + /*! + * \brief InsertUser Use this to insert a new user to channel, if user already exists it's updated according to information for new user + * \param user Pointer to user object, this function creates a copy, so the object passed here can be temporary + * \return Pointer to newly created user or existing user in case there is already this user in a channel + */ + User *InsertUser(User *user); + void RemoveUser(QString user); + void ChangeNick(const QString &old_nick, const QString &new_nick); + //! Changes a hostname or ident of user in channel + void ChangeHost(const QString &nick, const QString &new_host, const QString &new_ident); + bool ContainsUser(const QString &user); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + void SendMessage(QString text); + void SetNetwork(Network *network); + void ClearUsers(); + QHash GetUsers() const; + int GetUserCount(); + User *GetUser(QString user); + QDateTime GetMTime(); + void SetMTime(QDateTime tm); + QList GetBans(); + QList GetExceptions(); + bool RemovePMode(libirc::SingleMode mode); + bool RemovePMode(ChannelPMode mode); + bool SetPMode(ChannelPMode mode); + CMode GetMode(); + void SetMode(QString mode); + void Part(); + /*signals: + void Event_UserInserted(User *user); + void Event_UserRemoved(QString user); + void Event_NickChanged(QString old_nick, QString new_nick); */ + protected: + QList filteredList(char filter); +#ifdef LIBIRC_HASH + QSet _localPModes; +#else + QList _localPModes; +#endif + CMode _localMode; + QDateTime _localModeDateTime; + QHash _users; + Network *_net; + private: + void deepCopy(const Channel *source); + }; +} + +#endif // CHANNEL_H diff --git a/include/libircclient/generic.h b/include/libircclient/generic.h new file mode 100644 index 0000000..f1b4f66 --- /dev/null +++ b/include/libircclient/generic.h @@ -0,0 +1,31 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef LIBIRCCLIENTGENERIC_H +#define LIBIRCCLIENTGENERIC_H + +#include +#include +#include "libircclient_global.h" +#include + +namespace libircclient +{ + namespace Generic + { + LIBIRCCLIENTSHARED_EXPORT QString ErrorCode2String(QAbstractSocket::SocketError type); + //! Merge unique items in 2 lists + LIBIRCCLIENTSHARED_EXPORT QList UniqueMerge(QList a, QList b); + } +} + +#endif // LIBIRCCLIENTGENERIC_H diff --git a/include/libircclient/irceventhandler.h b/include/libircclient/irceventhandler.h new file mode 100644 index 0000000..3e8c27a --- /dev/null +++ b/include/libircclient/irceventhandler.h @@ -0,0 +1,30 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef IRCEVENTHANDLER_H +#define IRCEVENTHANDLER_H + +#include "libircclient_global.h" + +namespace libircclient +{ + class LIBIRCCLIENTSHARED_EXPORT IRCEventHandler + { + public: + static IRCEventHandler *EventHandler; + IRCEventHandler(); + virtual ~IRCEventHandler(); + + }; +} + +#endif // IRCEVENTHANDLER_H diff --git a/include/libircclient/libircclient_global.h b/include/libircclient/libircclient_global.h new file mode 100644 index 0000000..8397b8b --- /dev/null +++ b/include/libircclient/libircclient_global.h @@ -0,0 +1,25 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + + +#ifndef LIBIRCCLIENT_GLOBAL_H +#define LIBIRCCLIENT_GLOBAL_H + +#include + +#if defined(LIBIRCCLIENT_LIBRARY) +# define LIBIRCCLIENTSHARED_EXPORT Q_DECL_EXPORT +#else +# define LIBIRCCLIENTSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // LIBIRCCLIENT_GLOBAL_H diff --git a/include/libircclient/mode.h b/include/libircclient/mode.h new file mode 100644 index 0000000..a2d1407 --- /dev/null +++ b/include/libircclient/mode.h @@ -0,0 +1,68 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef MODE_H +#define MODE_H + +#include "libircclient_global.h" +#include +#include +#include +#include "user.h" +#include "../libirc/mode.h" + +namespace libircclient +{ + class LIBIRCCLIENTSHARED_EXPORT Mode : public libirc::Mode + { + public: + Mode()=default; + Mode(const QHash &hash); + Mode(const QString &mode) : libirc::Mode(mode) {} + }; + + class LIBIRCCLIENTSHARED_EXPORT UMode : public Mode + { + public: + UMode()=default; + UMode(const QHash &hash); + UMode(const QString &mode_string) : Mode(mode_string) {} + }; + + class LIBIRCCLIENTSHARED_EXPORT CMode : public Mode + { + public: + CMode()=default; + CMode(const QHash &hash); + CMode(const QString &mode_string) : Mode(mode_string) {}; + }; + + class LIBIRCCLIENTSHARED_EXPORT ChannelPMode : public libirc::SingleMode + { + public: + ChannelPMode(const QString &mode); + ChannelPMode(const QHash &mode); + ~ChannelPMode() override=default; + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + char Symbol; + QDateTime SetOn; + User SetBy; + bool operator==(const ChannelPMode& m) const { return m.EqualTo(*this); } + bool operator!=(const ChannelPMode& m) const { return !m.EqualTo(*this); } + bool EqualTo(const ChannelPMode& m) const; + }; + + uint qHash(const ChannelPMode& mode, uint seed = 0); +} + +#endif // MODE_H diff --git a/include/libircclient/network.h b/include/libircclient/network.h new file mode 100644 index 0000000..3ef0119 --- /dev/null +++ b/include/libircclient/network.h @@ -0,0 +1,427 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + +#ifndef NETWORK_H +#define NETWORK_H + +#include "../libirc/network.h" +#include "priority.h" +#include "user.h" +#include "mode.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "libircclient_global.h" +#include "../libirc/irc_standards.h" + +class QTcpSocket; + +#ifndef ETIMEDOUT +#define ETIMEDOUT 10 +#endif +#define EHANDSHAKE 20 +#define EDISCONNECTED 30 + +namespace libirc +{ + class ServerAddress; +} + +namespace libircclient +{ + enum Encoding + { + // Default by Qt + EncodingDefault = 0, + EncodingASCII = 1, + EncodingUTF8 = 2, + EncodingUTF16 = 3, + //EncodingUTF32 = 4, + EncodingLatin = 5 + }; + + class Server; + class Channel; + class Parser; + + class LIBIRCCLIENTSHARED_EXPORT Network : public libirc::Network + { + Q_OBJECT + + public: + friend class Network_SenderThread; + + Network(libirc::ServerAddress &server, const QString &name, const Encoding &enc = EncodingDefault); + Network(const QHash &hash); + ~Network() override; + virtual void Connect(); + virtual void Reconnect(); + virtual void Disconnect(QString reason = ""); + bool IsAway() const; + virtual bool IsConnected(); + virtual void SetAway(bool away, const QString &message = ""); + //! This function can be used to change the default nickname that will be requested upon connection to server + //! subsequent calls of this function while on active IRC connection will be ignored. + virtual void SetDefaultNick(const QString &nick); + virtual void SetDefaultIdent(const QString &ident); + virtual void SetDefaultUsername(const QString &realname); + virtual bool IsSSL(); + virtual QString GetNick(); + virtual QString GetHost(); + virtual QString GetServerVersion(); + virtual int GetTimeout() const; + unsigned int GetPort(); + virtual QString GetIdent(); + virtual QString GetServerAddress(); + virtual User *GetLocalUserInfo(); + virtual void SetHelpForMode(char mode, const QString &message); + virtual QString GetHelpForMode(char mode, QString missing); + virtual Channel *GetChannel(QString channel_name); + virtual QList GetChannels(); + virtual Encoding GetEncoding(); + virtual void SetPassword(const QString &Password); + virtual void RequestJoin(const QString &name, Priority priority = Priority_Normal); + virtual void TransferRaw(QString raw, Priority priority = Priority_Normal); + virtual int SendMessage(const QString &text, Channel *channel, Priority priority = Priority_Normal); + virtual int SendMessage(const QString &text, User *user, Priority priority = Priority_Normal); + virtual int SendMessage(const QString &text, const QString &target, Priority priority = Priority_Normal); + virtual int SendAction(const QString &text, Channel *channel, Priority priority = Priority_Normal); + virtual int SendAction(const QString &text, const QString &target, Priority priority = Priority_Normal); + virtual int SendNotice(const QString &text, User *user, Priority priority = Priority_Normal); + virtual int SendNotice(const QString &text, Channel *channel, Priority priority = Priority_Normal); + virtual int SendNotice(const QString &text, const QString &target, Priority priority = Priority_Normal); + virtual int SendCtcp(const QString &name, const QString &text, const QString &target, Priority priority = Priority_Normal); + virtual void RequestPart(const QString &channel_name, Priority priority = Priority_Normal); + virtual void RequestPart(Channel *channel, Priority priority = Priority_Normal); + virtual void RequestNick(const QString &nick, Priority priority = Priority_Normal); + virtual void Identify(QString Nickname = "", QString Password = "", Priority priority = Priority_Normal); + // IRCv3 + virtual bool SupportsIRCv3() const; + virtual void EnableIRCv3Support(); + virtual void DisableIRCv3Support(); + //! Requests IRCv3 capability, this needs to be called before connection is initiated + virtual void RequestCapability(const QString &capability); + //! Remove a capability from list of requested caps, meaning we will not ask for it after connecting to server + virtual void DisableCapability(const QString &capability); + //! Returns true in case this capability is on a list of caps we want to enabled after connection to network + virtual bool CapabilityRequested(const QString &capability); + virtual bool CapabilityEnabled(const QString &capability); + //! Works only after connection is established - will return true in case network supports this capability + virtual bool CapabilitySupported(const QString &capability); + virtual QList GetSupportedCaps(); + virtual QList GetSubscribedCaps(); + virtual bool ContainsChannel(const QString &channel_name); + //! Returns a network lag in MS, measured from last PONG response + virtual long long GetLag(); + virtual long long GetBytesSent(); + virtual long long GetBytesReceived(); + ////////////////////////////////////////////////////////////////////////////////////////// + // Synchronization tools + //! This will update the nick in operating memory, it will not request it from server and may cause troubles + //! if not properly called. This is only used for resynchronization. + virtual void _st_SetNick(const QString &nick); + //! This will delete all internal memory structures related to channels this user is in. + //! Use only for synchronization purposes, while implementing something like grumpyd + //! calling this function on live IRC network connection will have unpredictable result + void _st_ClearChannels(); + /*! + * \brief InsertChannel Inserts a deep copy of provided channel to local list of channels + * \param channel Source which is copied, can be safely deleted + * \return The copy of input object which was inserted to local vector of channels same as result of GetChannel + */ + Channel *_st_InsertChannel(libircclient::Channel *channel); + ////////////////////////////////////////////////////////////////////////////////////////// + /*! + * \brief StartsWithCUPrefix checks the user name whether it starts with a CUMode prefix (such as @) + * \param user_name Name of user including the prefix (@channel_op) + * \return 0 in case there is no prefix, otherwise it returns the respective CUMode (o in case of @) + */ + virtual char StartsWithCUPrefix(QString user_name); + /*! + * \brief PositionOfChannelPrefix returns a position of UCP or negative number in case it's not in there + * \param prefix + * \return + */ + virtual int PositionOfUCPrefix(char prefix); + virtual void SetChannelUserPrefixes(const QList &data); + virtual void SetCModes(const QList &data); + virtual QList GetChannelUserPrefixes(); + virtual bool HasCap(const QString &cap); + virtual QList GetCModes(); + virtual QList GetCPModes(); + virtual void SetCPModes(const QList &data); + virtual void SetCRModes(const QList &data); + virtual QList GetCCModes(); + virtual QList GetCRModes(); + virtual QList GetSTATUSMSGModes(); + virtual void SetSTATUSMSGModes(const QList &data); + virtual void SetCUModes(const QList &data); + virtual QList GetCUModes(); + virtual void SetCCModes(const QList &data); + virtual UMode GetLocalUserMode(); + virtual QList ModeHelper_GetSortedChannelPrefixes(const QList &unsorted_list); + virtual QList ModeHelper_GetSortedCUModes(const QList &unsorted_list); + QList ParameterModes(); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + //! This will automatically fix your own identification data in case they change + //! For example if server changes your hostname (cloak) system will recognize + //! the change and update localUser accordingly. + //! + //! There is a small CPU penalty for this, so this feature can be turned off + //! in case that this information isn't important for you + bool ResolveOnSelfChanges; + bool ResolveOnNickConflicts; + QHash ChannelModeHelp; + QHash UserModeHelp; + + signals: + // Primitives + void Event_RawOutgoing(QByteArray data); + void Event_RawIncoming(QByteArray data); + void Event_Invalid(QByteArray data); + void Event_ConnectionFailure(QAbstractSocket::SocketError reason); + void Event_ConnectionError(QString error, int code); + void Event_Parse(libircclient::Parser *parser); + void Event_SSLFailure(QList error_l, bool *fail); + //! Server gave us some unknown command + void Event_Unknown(libircclient::Parser *parser); + void Event_Timeout(); + void Event_Connected(); + void Event_Disconnected(); + void Event_Broken(libircclient::Parser *parser, QString reason); + void Event_NetworkFailure(QString reason, int failure); + //! Emitted when server sent us IRC_NUMERIC_UNKNOWN + void Event_NUMERIC_UNKNOWN(libircclient::Parser *parser); + + // Channel related + void Event_SelfJoin(libircclient::Channel *chan); + void Event_Join(libircclient::Parser *parser, libircclient::User *user, libircclient::Channel *chan); + /*! + * \brief Event_PerChannelQuit Emitted when a user quit the network for every single channel this user was in + * so that it's extremely simple to render the information in related scrollbacks + * \param parser Pointer to parser of IRC raw message + * \param chan Pointer to channel this user just left + */ + void Event_PerChannelQuit(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_Quit(libircclient::Parser *parser); + //! Emitted before the channel is removed from memory on part of a channel you were in + void Event_SelfPart(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_Part(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_SelfKick(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_Kick(libircclient::Parser *parser, libircclient::Channel *chan); + //! Emitted when someone changes the topic + void Event_TOPIC(libircclient::Parser *parser, libircclient::Channel * chan, QString old_topic); + //! Retrieved after channel is joined as part of info + void Event_TOPICInfo(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_TOPICWhoTime(libircclient::Parser *parser, libircclient::Channel *chan); + void Event_ModeInfo(libircclient::Parser *parser, libircclient::Channel *channel); + //! When user's channel mode was changed, but the changed mode was lower priority than the one which + //! user already possesed. + //! This change is very minor and probably doesn't reflect any real change + + //! Exampe: user who had owner ~ and halfop % (effectively being ~%) had halfop removed + void Event_ChannelUserSubmodeChanged(libircclient::Parser *parser, libircclient::Channel *channel, libircclient::User *user); + void Event_ChannelModeChanged(libircclient::Parser *parser, libircclient::Channel *channel); + void Event_ChannelUserModeChanged(libircclient::Parser *parser, libircclient::Channel *channel, libircclient::User *user); + void Event_CreationTime(libircclient::Parser *parser); + void Event_EndOfBans(libircclient::Parser *parser); + void Event_EndOfExcepts(libircclient::Parser *parser); + void Event_EndOfInvites(libircclient::Parser *parser); + void Event_CPMInserted(libircclient::Parser *parser, libircclient::ChannelPMode mode, libircclient::Channel *channel); + void Event_CPMRemoved(libircclient::Parser *parser, libircclient::ChannelPMode mode, libircclient::Channel *channel); + void Event_INVITE(libircclient::Parser *parser); + + // Server related + void Event_PONG(libircclient::Parser *parser); + void Event_EndOfNames(libircclient::Parser *parser); + void Event_ServerMode(libircclient::Parser *parser); + void Event_MOTDEnd(libircclient::Parser *parser); + void Event_MOTDBegin(libircclient::Parser *parser); + void Event_MOTD(libircclient::Parser *parser); + void Event_Mode(libircclient::Parser *parser); + void Event_NickCollision(libircclient::Parser *parser); + void Event_INFO(libircclient::Parser *parser); + //! IRC_NUMERIC_MYINFO + void Event_MyInfo(libircclient::Parser *parser); + void Event_Welcome(libircclient::Parser *parser); + void Event_ISUPPORT(libircclient::Parser *parser); + + // Whois + //! Emitted for all WHOIS events, in case you don't want to attach to individual replies + void Event_WhoisGeneric(libircclient::Parser *parser); + void Event_WhoisUser(libircclient::Parser *parser, libircclient::User *user); + void Event_WhoisOperator(libircclient::Parser *parser); + void Event_WhoisIdle(libircclient::Parser *parser, unsigned int seconds_idle, QDateTime signon_time); + void Event_WhoisRegNick(libircclient::Parser *parser); + void Event_WhoisChannels(libircclient::Parser *parser); + void Event_WhoisServer(libircclient::Parser *parser); + void Event_WhoisEnd(libircclient::Parser *parser); + void Event_WhoisSpecial(libircclient::Parser *parser); + void Event_WhoisAccount(libircclient::Parser *parser); + void Event_WhoisSecure(libircclient::Parser *parser); + void Event_WhoisHost(libircclient::Parser *parser); + void Event_WhoisModes(libircclient::Parser *parser); + + // Messaging + void Event_PRIVMSG(libircclient::Parser *parser); + void Event_CTCP(libircclient::Parser *parser, QString ctcp, QString parameters); + void Event_NOTICE(libircclient::Parser *parser); + + // Users + void Event_UserAwayStatusChange(libircclient::Parser *parser, libircclient::Channel *channel, libircclient::User *user); + void Event_NICK(libircclient::Parser *parser, QString old_nick, QString new_nick); + void Event_SelfNICK(libircclient::Parser *parser, QString old_nick, QString new_nick); + void Event_WHO(libircclient::Parser *parser, libircclient::Channel *channel, libircclient::User *user); + void Event_EndOfWHO(libircclient::Parser *parser); + void Event_PMode(libircclient::Parser *parser, char mode); + void Event_UnAway(libircclient::Parser *parser); + void Event_NowAway(libircclient::Parser *parser); + void Event_AWAY(libircclient::Parser *parser); + void Event_RplAway(libircclient::Parser *parser); + void Event_SelfCHGHOST(libircclient::Parser *parser, QString old_host, QString old_ident, QString new_host, QString new_ident); + void Event_CHGHOST(libircclient::Parser *parser, QString old_host, QString old_ident, QString new_host, QString new_ident); + + // IRCv3 + void Event_CAP(libircclient::Parser *parser); + void Event_CAP_ACK(libircclient::Parser *parser); + void Event_CAP_NAK(libircclient::Parser *parser); + void Event_CAP_Timeout(); + void Event_CAP_RequestedCapNotSupported(QString name); + + protected slots: + virtual void OnSslHandshakeFailure(QList errors); + virtual void OnError(QAbstractSocket::SocketError er); + virtual void OnReceive(); + virtual void OnDisconnect(); + virtual void OnConnected(); + virtual void OnSend(); + virtual void OnPing(); + virtual void OnPingSend(); + virtual void OnCapSupportTimeout(); + + protected: + virtual void OnReceive(const QByteArray &data); + virtual void closeError(const QString &error, int code); + bool usingSSL; + QTcpSocket *socket; + //! These capabilities will be automatically requested from a server if it supports them + QList _capabilitiesRequested; + QList _capabilitiesSupported; + QList _capabilitiesSubscribed; + bool _loggedIn; + int _capGraceTime; + bool _enableCap; + QString hostname; + unsigned int port; + int pingTimeout; + int pingRate; + QString defaultQuit; + bool autoRejoin; + bool autoIdentify; + QString identifyString; + QString password; + + private: + void updateSelfAway(Parser *parser, bool status, const QString &text); + void processIncomingRawData(QByteArray data); + void processNamrpl(Parser *parser); + void process433(Parser *parser); + void processInfo(Parser *parser); + void processWho(Parser *parser); + void processPrivMsg(Parser *parser); + void processMode(Parser *parser); + void processMdIn(Parser *parser); + void processTopic(Parser *parser); + void processKick(Parser *parser); + void processTopicWhoTime(Parser *parser); + void processPMode(Parser *parser, char mode); + void processMTime(Parser *parser); + void processJoin(Parser *parser, bool self_command); + void processNick(Parser *parser, bool self_command); + void processAway(Parser *parser, bool self_command); + void processCap(Parser *parser); + void processWhoisUser(Parser &parser); + void processWhoisIdle(Parser &parser); + void processChangeHost(Parser &parser); + void standardLogin(); + void deleteTimers(); + void initialize(); + void freemm(); + void resetCap(); + void processAutoCap(); + void pseudoSleep(unsigned int msec); + QByteArray getDataToSend(); + void scheduleDelivery(const QByteArray &data, libircclient::Priority priority); + void autoJoin(); + + ///////////////////////////////////// + // This probably doesn't need syncing + unsigned int MSDelayOnEmpty; + unsigned int MSDelayOnOpen; + unsigned int MSWait; + QTimer capTimeout; + bool capProcessingMultilineLS; + bool capProcessingChangeRequest; + bool capAutoRequestFinished; + bool loggedIn; + bool scheduling; + QDateTime senderTime; + QTimer senderTimer; + QMutex mutex; + unsigned long long bytesSent; + unsigned long long bytesRcvd; + QList hprFIFO; + QList mprFIFO; + QList lprFIFO; + ///////////////////////////////////// + + //! List of symbols that are used to prefix users + QList channelUserPrefixes; + //! Channel modes with no parameters + QList CModes; + //! Channel parameter modes (+b, +I) + QList CPModes; + //! Channel secret modes (+k) + QList CRModes; + //! Channel user modes (+o, +v) + QList CUModes; + //! Channel numeric modes (+l) + QList CCModes; + //! https://tools.ietf.org/html/draft-hardy-irc-isupport-00#section-4.18 + QList STATUSMSG_Modes; + QString originalNick; + UMode localUserMode; + QString alternateNick; + int alternateNickNumber; + QString awayMessage; + char channelPrefix; + Server *server; + QList users; + Encoding encoding = EncodingDefault; + QList channels; + User localUser; + QDateTime lastPing; + QTimer *timerPingTimeout; + QTimer *timerPingSend; + //! List of channels to join after connection to network + QList channelsToJoin; + long long lastPingResponseTimeInMs = 0; + }; +} + +#endif // NETWORK_H diff --git a/include/libircclient/networkmodehelp.h b/include/libircclient/networkmodehelp.h new file mode 100644 index 0000000..99de29e --- /dev/null +++ b/include/libircclient/networkmodehelp.h @@ -0,0 +1,34 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2017 + +#ifndef NETWORKMODEHELP_H +#define NETWORKMODEHELP_H + +#include +#include +#include "libircclient_global.h" +#include "../libirc/irc_standards.h" + +namespace libircclient +{ + /*! + * \brief The NetworkModeHelp class contains help for various ircd servers + */ + class LIBIRCCLIENTSHARED_EXPORT NetworkModeHelp + { + public: + static QHash GetUserModeHelp(QString ircd); + static QHash GetChannelModeHelp(QString ircd); + }; +} + +#endif // NETWORK_H diff --git a/include/libircclient/parser.h b/include/libircclient/parser.h new file mode 100644 index 0000000..ace91b2 --- /dev/null +++ b/include/libircclient/parser.h @@ -0,0 +1,62 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 - 2019 + + +#ifndef PARSER_H +#define PARSER_H + +#include +#include +#include +#include "libircclient_global.h" +#include "user.h" +#include "../libirc/irc_numerics.h" + +namespace libircclient +{ + class LIBIRCCLIENTSHARED_EXPORT Parser + { + public: + Parser(QString incoming_text); + ~Parser(); + int GetNumeric(); + bool IsValid(); + User *GetSourceUserInfo(); + QString GetSourceInfo(); + QString GetParameterLine(); + //! Returns RAW data as received from server, with some alterations to remove some CAP extras (such as server-time) + //! this RAW text follows IRC RFC preceeding IRCv3 + QString GetRaw(); + //! Returns true RAW data as received from server with no alterations, with IRCv3 caps this text doesn't follow standard convention + QString GetOriginalRaw(); + QString GetText(); + QList GetParameters(); + QDateTime GetTimestamp(); + + private: + void obtainNumeric(); + User *user; + QString source; + QString text; + QString original_text; + QString message_text; + bool _valid; + int _numeric; + QList parameters; + QString command; + QString parameterLine; + QDateTime timestamp; + + }; +} + +#endif // PARSER_H diff --git a/include/libircclient/priority.h b/include/libircclient/priority.h new file mode 100644 index 0000000..db8f017 --- /dev/null +++ b/include/libircclient/priority.h @@ -0,0 +1,28 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef PRIORITY +#define PRIORITY + +namespace libircclient +{ + enum Priority + { + Priority_RealTime = 3, + Priority_High = 2, + Priority_Normal = 1, + Priority_Low = 0 + }; +} + +#endif // PRIORITY + diff --git a/include/libircclient/server.h b/include/libircclient/server.h new file mode 100644 index 0000000..387b94e --- /dev/null +++ b/include/libircclient/server.h @@ -0,0 +1,32 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef SERVER_H +#define SERVER_H + +#include "libircclient_global.h" +#include +#include "../libirc/server.h" + +namespace libircclient +{ + class LIBIRCCLIENTSHARED_EXPORT Server : public libirc::Server + { + public: + Server()=default; + Server(const QHash &hash); + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + }; +} + +#endif // SERVER_H diff --git a/include/libircclient/user.h b/include/libircclient/user.h new file mode 100644 index 0000000..aa359a8 --- /dev/null +++ b/include/libircclient/user.h @@ -0,0 +1,45 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2015 + +#ifndef USER_H +#define USER_H + +#include "../libirc/user.h" +#include "libircclient_global.h" + +namespace libircclient +{ + class LIBIRCCLIENTSHARED_EXPORT User : public libirc::User + { + public: + User(); + User(const QHash &hash); + User(const QString &user); + User(User *user); + QString GetPrefixedNick(); + char GetHighestCUMode(); + QList ChannelPrefixes; + QString ServerName; + QList CUModes; + QString AwayMs; + bool IsAway; + int Hops; + void LoadHash(const QHash &hash) override; + QHash ToHash() override; + + + private: + + }; +} + +#endif // USER_H diff --git a/libircclient/network.cpp b/libircclient/network.cpp index fbce126..2fa88e9 100644 --- a/libircclient/network.cpp +++ b/libircclient/network.cpp @@ -77,7 +77,7 @@ void Network::Connect() this->scheduling = true; this->_loggedIn = false; //delete this->network_thread; - delete this->socket; + //delete this->socket; //this->network_thread = new NetworkThread(this); if (!this->IsSSL()) @@ -613,7 +613,7 @@ static QList SortingHelper(QList mask, QList list) } // Now that we have all modes in a hash table, we can just easily sort them QList unsorted_ints = hash.keys(); - qSort(unsorted_ints); + std::sort(unsorted_ints.begin(), unsorted_ints.end()); QList sorted_list; foreach (int mode, unsorted_ints) sorted_list.append(mask[mode]); @@ -1086,6 +1086,10 @@ void Network::processIncomingRawData(QByteArray data) case IRC_NUMERIC_WELCOME: emit this->Event_Welcome(&parser); this->loggedIn = true; + if (autoIdentify) + { + Identify(); + } break; case IRC_NUMERIC_EXCEPTION: this->processPMode(&parser, 'e'); @@ -1815,7 +1819,7 @@ void Network::standardLogin() if (this->_loggedIn) return; this->_loggedIn = true; - this->TransferRaw("USER " + this->localUser.GetIdent() + " 8 * :" + this->localUser.GetRealname()); + this->TransferRaw("USER " + this->localUser.GetIdent() + " * * :" + this->localUser.GetRealname()); this->TransferRaw("NICK " + this->localUser.GetNick()); this->lastPing = QDateTime::currentDateTime(); this->timerPingSend = new QTimer(this); @@ -1893,6 +1897,7 @@ void Network::initialize() this->defaultQuit = "GrumpyChat libirc: https://github.com/grumpy-irc/libirc"; this->channelPrefix = '#'; this->autoRejoin = false; + this->autoIdentify = true; this->identifyString = "PRIVMSG NickServ identify $nickname $password"; this->alternateNickNumber = 0; this->server = new Server();