[PSQL] properly preparing insert_sender queries (in all cases) before using them
[quassel.git] / src / core / ctcpparser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, 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   Q_OBJECT
35
36 public:
37   CtcpParser(CoreSession *coreSession, QObject *parent = 0);
38
39   inline CoreSession *coreSession() const { return _coreSession; }
40
41   void query(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
42   void reply(CoreNetwork *network, const QString &bufname, const QString &ctcpTag, const QString &message);
43
44   Q_INVOKABLE void processIrcEventRawNotice(IrcEventRawMessage *event);
45   Q_INVOKABLE void processIrcEventRawPrivmsg(IrcEventRawMessage *event);
46
47   Q_INVOKABLE void sendCtcpEvent(CtcpEvent *event);
48
49 protected:
50   inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
51
52   // FIXME duplicates functionality in EventStringifier, maybe want to put that in something common
53   //! Creates and sends a MessageEvent
54   void displayMsg(NetworkEvent *event,
55                   Message::Type msgType,
56                   const QString &msg,
57                   const QString &sender = QString(),
58                   const QString &target = QString(),
59                   Message::Flags msgFlags = Message::None);
60
61   void parse(IrcEventRawMessage *event, Message::Type msgType);
62
63   QByteArray lowLevelQuote(const QByteArray &);
64   QByteArray lowLevelDequote(const QByteArray &);
65   QByteArray xdelimQuote(const QByteArray &);
66   QByteArray xdelimDequote(const QByteArray &);
67
68   QByteArray pack(const QByteArray &ctcpTag, const QByteArray &message);
69   void packedReply(CoreNetwork *network, const QString &bufname, const QList<QByteArray> &replies);
70
71 private:
72   inline QString targetDecode(IrcEventRawMessage *e, const QByteArray &msg) { return coreNetwork(e)->userDecode(e->target(), msg); }
73
74   CoreSession *_coreSession;
75
76   struct CtcpReply {
77     CoreNetwork *network;
78     QString bufferName;
79     QList<QByteArray> replies;
80
81     CtcpReply() : network(0) {}
82     CtcpReply(CoreNetwork *net, const QString &buf) : network(net), bufferName(buf) {}
83   };
84
85   QHash<QUuid, CtcpReply> _replies;
86
87   QHash<QByteArray, QByteArray> _ctcpMDequoteHash;
88   QHash<QByteArray, QByteArray> _ctcpXDelimDequoteHash;
89 };
90
91 #endif