1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
28 #include "corenetwork.h"
29 #include "ctcpevent.h"
30 #include "eventmanager.h"
36 class CtcpParser : public QObject
41 CtcpParser(CoreSession* coreSession, QObject* parent = nullptr);
43 inline CoreSession* coreSession() const { return _coreSession; }
45 void query(CoreNetwork* network, const QString& bufname, const QString& ctcpTag, const QString& message);
46 void reply(CoreNetwork* network, const QString& bufname, const QString& ctcpTag, const QString& message);
48 Q_INVOKABLE void processIrcEventRawNotice(IrcEventRawMessage* event);
49 Q_INVOKABLE void processIrcEventRawPrivmsg(IrcEventRawMessage* event);
51 Q_INVOKABLE void sendCtcpEvent(CtcpEvent* event);
54 void newEvent(Event* event);
57 inline CoreNetwork* coreNetwork(NetworkEvent* e) const { return qobject_cast<CoreNetwork*>(e->network()); }
59 // FIXME duplicates functionality in EventStringifier, maybe want to put that in something common
60 //! Creates and sends a MessageEvent
61 void displayMsg(NetworkEvent* event,
62 Message::Type msgType,
66 Message::Flags msgFlags = Message::None);
68 void parse(IrcEventRawMessage* event, Message::Type msgType);
69 void parseSimple(IrcEventRawMessage* e,
70 Message::Type messagetype,
71 const QByteArray& dequotedMessage,
72 CtcpEvent::CtcpType ctcptype,
73 Message::Flags flags);
74 void parseStandard(IrcEventRawMessage* e,
75 Message::Type messagetype,
76 const QByteArray& dequotedMessage,
77 CtcpEvent::CtcpType ctcptype,
78 Message::Flags flags);
80 QByteArray lowLevelQuote(const QByteArray&);
81 QByteArray lowLevelDequote(const QByteArray&);
82 QByteArray xdelimQuote(const QByteArray&);
83 QByteArray xdelimDequote(const QByteArray&);
85 QByteArray pack(const QByteArray& ctcpTag, const QByteArray& message);
86 void packedReply(CoreNetwork* network, const QString& bufname, const QList<QByteArray>& replies);
89 void setStandardCtcp(bool enabled);
92 inline QString targetDecode(IrcEventRawMessage* e, const QByteArray& msg) { return coreNetwork(e)->userDecode(e->target(), msg); }
94 CoreSession* _coreSession;
98 CoreNetwork* network{nullptr};
100 QList<QByteArray> replies;
102 CtcpReply() = default;
103 CtcpReply(CoreNetwork* net, QString buf)
105 , bufferName(std::move(buf))
109 QHash<QUuid, CtcpReply> _replies;
111 QHash<QByteArray, QByteArray> _ctcpMDequoteHash;
112 QHash<QByteArray, QByteArray> _ctcpXDelimDequoteHash;