Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
ctcpparser.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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 #include "ctcpevent.h"
30 
31 class CoreSession;
32 class CtcpEvent;
33 
34 class CtcpParser : public QObject
35 {
36  Q_OBJECT
37 
38 public:
39  CtcpParser(CoreSession *coreSession, QObject *parent = 0);
40 
41  inline CoreSession *coreSession() const { return _coreSession; }
42 
43  void query(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
44  void reply(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
45 
46  Q_INVOKABLE void processIrcEventRawNotice(IrcEventRawMessage *event);
47  Q_INVOKABLE void processIrcEventRawPrivmsg(IrcEventRawMessage *event);
48 
49  Q_INVOKABLE void sendCtcpEvent(CtcpEvent *event);
50 
51 signals:
52  void newEvent(Event *event);
53 
54 protected:
55  inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
56 
57  // FIXME duplicates functionality in EventStringifier, maybe want to put that in something common
59  void displayMsg(NetworkEvent *event,
60  Message::Type msgType,
61  const QString &msg,
62  const QString &sender = QString(),
63  const QString &target = QString(),
64  Message::Flags msgFlags = Message::None);
65 
66  void parse(IrcEventRawMessage *event, Message::Type msgType);
67  void parseSimple(IrcEventRawMessage *e, Message::Type messagetype, QByteArray dequotedMessage, CtcpEvent::CtcpType ctcptype, Message::Flags flags);
68  void parseStandard(IrcEventRawMessage *e, Message::Type messagetype, QByteArray dequotedMessage, CtcpEvent::CtcpType ctcptype, Message::Flags flags);
69 
70  QByteArray lowLevelQuote(const QByteArray &);
71  QByteArray lowLevelDequote(const QByteArray &);
72  QByteArray xdelimQuote(const QByteArray &);
73  QByteArray xdelimDequote(const QByteArray &);
74 
75  QByteArray pack(const QByteArray &ctcpTag, const QByteArray &message);
76  void packedReply(CoreNetwork *network, const QString &bufname, const QList<QByteArray> &replies);
77 
78 private slots:
79  void setStandardCtcp(bool enabled);
80 
81 private:
82  inline QString targetDecode(IrcEventRawMessage *e, const QByteArray &msg) { return coreNetwork(e)->userDecode(e->target(), msg); }
83 
85 
86  struct CtcpReply {
88  QString bufferName;
89  QList<QByteArray> replies;
90 
91  CtcpReply() : network(0) {}
92  CtcpReply(CoreNetwork *net, const QString &buf) : network(net), bufferName(buf) {}
93  };
94 
95  QHash<QUuid, CtcpReply> _replies;
96 
97  QHash<QByteArray, QByteArray> _ctcpMDequoteHash;
98  QHash<QByteArray, QByteArray> _ctcpXDelimDequoteHash;
99 };
100 
101 
102 #endif