a33751fb40a819aee88a01e20fd739293eb4a2c4
[quassel.git] / src / core / ctcpparser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2012 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef CTCPPARSER_H
22 #define CTCPPARSER_H
23
24 #include <QUuid>
25
26 #include "corenetwork.h"
27 #include "eventmanager.h"
28 #include "ircevent.h"
29
30 class CoreSession;
31 class CtcpEvent;
32
33 class CtcpParser : public QObject
34 {
35     Q_OBJECT
36
37 public:
38     CtcpParser(CoreSession *coreSession, QObject *parent = 0);
39
40     inline CoreSession *coreSession() const { return _coreSession; }
41
42     void query(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
43     void reply(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
44
45     Q_INVOKABLE void processIrcEventRawNotice(IrcEventRawMessage *event);
46     Q_INVOKABLE void processIrcEventRawPrivmsg(IrcEventRawMessage *event);
47
48     Q_INVOKABLE void sendCtcpEvent(CtcpEvent *event);
49
50 signals:
51     void newEvent(Event *event);
52
53 protected:
54     inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
55
56     // FIXME duplicates functionality in EventStringifier, maybe want to put that in something common
57     //! Creates and sends a MessageEvent
58     void displayMsg(NetworkEvent *event,
59         Message::Type msgType,
60         const QString &msg,
61         const QString &sender = QString(),
62         const QString &target = QString(),
63         Message::Flags msgFlags = Message::None);
64
65     void parse(IrcEventRawMessage *event, Message::Type msgType);
66
67     QByteArray lowLevelQuote(const QByteArray &);
68     QByteArray lowLevelDequote(const QByteArray &);
69     QByteArray xdelimQuote(const QByteArray &);
70     QByteArray xdelimDequote(const QByteArray &);
71
72     QByteArray pack(const QByteArray &ctcpTag, const QByteArray &message);
73     void packedReply(CoreNetwork *network, const QString &bufname, const QList<QByteArray> &replies);
74
75 private:
76     inline QString targetDecode(IrcEventRawMessage *e, const QByteArray &msg) { return coreNetwork(e)->userDecode(e->target(), msg); }
77
78     CoreSession *_coreSession;
79
80     struct CtcpReply {
81         CoreNetwork *network;
82         QString bufferName;
83         QList<QByteArray> replies;
84
85         CtcpReply() : network(0) {}
86         CtcpReply(CoreNetwork *net, const QString &buf) : network(net), bufferName(buf) {}
87     };
88
89     QHash<QUuid, CtcpReply> _replies;
90
91     QHash<QByteArray, QByteArray> _ctcpMDequoteHash;
92     QHash<QByteArray, QByteArray> _ctcpXDelimDequoteHash;
93 };
94
95
96 #endif