1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
27 #include "corenetwork.h"
28 #include "eventmanager.h"
30 #include "ctcpevent.h"
35 class CtcpParser : public QObject
40 CtcpParser(CoreSession *coreSession, QObject *parent = nullptr);
42 inline CoreSession *coreSession() const { return _coreSession; }
44 void query(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
45 void reply(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
47 Q_INVOKABLE void processIrcEventRawNotice(IrcEventRawMessage *event);
48 Q_INVOKABLE void processIrcEventRawPrivmsg(IrcEventRawMessage *event);
50 Q_INVOKABLE void sendCtcpEvent(CtcpEvent *event);
53 void newEvent(Event *event);
56 inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
58 // FIXME duplicates functionality in EventStringifier, maybe want to put that in something common
59 //! Creates and sends a MessageEvent
60 void displayMsg(NetworkEvent *event,
61 Message::Type msgType,
63 const QString &sender = QString(),
64 const QString &target = QString(),
65 Message::Flags msgFlags = Message::None);
67 void parse(IrcEventRawMessage *event, Message::Type msgType);
68 void parseSimple(IrcEventRawMessage *e, Message::Type messagetype, QByteArray dequotedMessage, CtcpEvent::CtcpType ctcptype, Message::Flags flags);
69 void parseStandard(IrcEventRawMessage *e, Message::Type messagetype, QByteArray dequotedMessage, CtcpEvent::CtcpType ctcptype, Message::Flags flags);
71 QByteArray lowLevelQuote(const QByteArray &);
72 QByteArray lowLevelDequote(const QByteArray &);
73 QByteArray xdelimQuote(const QByteArray &);
74 QByteArray xdelimDequote(const QByteArray &);
76 QByteArray pack(const QByteArray &ctcpTag, const QByteArray &message);
77 void packedReply(CoreNetwork *network, const QString &bufname, const QList<QByteArray> &replies);
80 void setStandardCtcp(bool enabled);
83 inline QString targetDecode(IrcEventRawMessage *e, const QByteArray &msg) { return coreNetwork(e)->userDecode(e->target(), msg); }
85 CoreSession *_coreSession;
90 QList<QByteArray> replies;
92 CtcpReply() : network(nullptr) {}
93 CtcpReply(CoreNetwork *net, QString buf) : network(net), bufferName(std::move(buf)) {}
96 QHash<QUuid, CtcpReply> _replies;
98 QHash<QByteArray, QByteArray> _ctcpMDequoteHash;
99 QHash<QByteArray, QByteArray> _ctcpXDelimDequoteHash;