Merge pull request #168 from esainane/irssi-msg-escape
[quassel.git] / src / core / coresessioneventprocessor.h
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 CORESESSIONEVENTPROCESSOR_H
22 #define CORESESSIONEVENTPROCESSOR_H
23
24 #include "basichandler.h"
25 #include "corenetwork.h"
26 #include "networkevent.h"
27
28 class CoreSession;
29 class CtcpEvent;
30 class IrcEvent;
31 class IrcEventNumeric;
32 class Netsplit;
33
34 #ifdef HAVE_QCA2
35 class KeyEvent;
36 #endif
37
38 class CoreSessionEventProcessor : public BasicHandler
39 {
40     Q_OBJECT
41
42 public:
43     CoreSessionEventProcessor(CoreSession *session);
44
45     inline CoreSession *coreSession() const { return _coreSession; }
46
47     Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event);
48
49     Q_INVOKABLE void processIrcEventAuthenticate(IrcEvent *event); /// SASL authentication
50     Q_INVOKABLE void processIrcEventCap(IrcEvent *event);          /// CAP framework negotiation
51     Q_INVOKABLE void processIrcEventAccount(IrcEvent *event);      /// account-notify received
52     Q_INVOKABLE void processIrcEventAway(IrcEvent *event);         /// away-notify received
53     Q_INVOKABLE void processIrcEventInvite(IrcEvent *event);
54     Q_INVOKABLE void processIrcEventJoin(IrcEvent *event);
55     Q_INVOKABLE void lateProcessIrcEventKick(IrcEvent *event);
56     Q_INVOKABLE void processIrcEventMode(IrcEvent *event);
57     Q_INVOKABLE void lateProcessIrcEventNick(IrcEvent *event);
58     Q_INVOKABLE void lateProcessIrcEventPart(IrcEvent *event);
59     Q_INVOKABLE void processIrcEventPing(IrcEvent *event);
60     Q_INVOKABLE void processIrcEventPong(IrcEvent *event);
61     Q_INVOKABLE void processIrcEventQuit(IrcEvent *event);
62     Q_INVOKABLE void lateProcessIrcEventQuit(IrcEvent *event);
63     Q_INVOKABLE void processIrcEventTopic(IrcEvent *event);
64 #ifdef HAVE_QCA2
65     Q_INVOKABLE void processKeyEvent(KeyEvent *event);
66 #endif
67
68     Q_INVOKABLE void processIrcEvent001(IrcEventNumeric *event);   // RPL_WELCOME
69     Q_INVOKABLE void processIrcEvent005(IrcEvent *event);          // RPL_ISUPPORT
70     Q_INVOKABLE void processIrcEvent221(IrcEvent *event);          // RPL_UMODEIS
71     Q_INVOKABLE void processIrcEvent250(IrcEvent *event);          // RPL_STATSCONN
72     Q_INVOKABLE void processIrcEvent265(IrcEvent *event);          // RPL_LOCALUSERS
73     Q_INVOKABLE void processIrcEvent266(IrcEvent *event);          // RPL_GLOBALUSERS
74     Q_INVOKABLE void processIrcEvent301(IrcEvent *event);          // RPL_AWAY
75     Q_INVOKABLE void processIrcEvent305(IrcEvent *event);          // RPL_UNAWAY
76     Q_INVOKABLE void processIrcEvent306(IrcEvent *event);          // RPL_NOWAWAY
77     Q_INVOKABLE void processIrcEvent307(IrcEvent *event);          // RPL_WHOISSERVICE
78     Q_INVOKABLE void processIrcEvent310(IrcEvent *event);          // RPL_SUSERHOST
79     Q_INVOKABLE void processIrcEvent311(IrcEvent *event);          // RPL_WHOISUSER
80     Q_INVOKABLE void processIrcEvent312(IrcEvent *event);          // RPL_WHOISSERVER
81     Q_INVOKABLE void processIrcEvent313(IrcEvent *event);          // RPL_WHOISOPERATOR
82     Q_INVOKABLE void processIrcEvent315(IrcEvent *event);          // RPL_ENDOFWHO
83     Q_INVOKABLE void processIrcEvent317(IrcEvent *event);          // RPL_WHOISIDLE
84     Q_INVOKABLE void processIrcEvent322(IrcEvent *event);          // RPL_LIST
85     Q_INVOKABLE void processIrcEvent323(IrcEvent *event);          // RPL_LISTEND
86     Q_INVOKABLE void processIrcEvent324(IrcEvent *event);          // RPL_CHANNELMODEIS
87     Q_INVOKABLE void processIrcEvent331(IrcEvent *event);          // RPL_NOTOPIC
88     Q_INVOKABLE void processIrcEvent332(IrcEvent *event);          // RPL_TOPIC
89     Q_INVOKABLE void processIrcEvent352(IrcEvent *event);          // RPL_WHOREPLY
90     Q_INVOKABLE void processIrcEvent353(IrcEvent *event);          // RPL_NAMREPLY
91     Q_INVOKABLE void processIrcEvent432(IrcEventNumeric *event);   // ERR_ERRONEUSNICKNAME
92     Q_INVOKABLE void processIrcEvent433(IrcEventNumeric *event);   // ERR_NICKNAMEINUSE
93     Q_INVOKABLE void processIrcEvent437(IrcEventNumeric *event);   // ERR_UNAVAILRESOURCE
94
95     // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
96
97     /* CTCP handlers */
98     Q_INVOKABLE void processCtcpEvent(CtcpEvent *event);
99
100     Q_INVOKABLE void handleCtcpAction(CtcpEvent *event);
101     Q_INVOKABLE void handleCtcpClientinfo(CtcpEvent *event);
102     Q_INVOKABLE void handleCtcpDcc(CtcpEvent *event);
103     Q_INVOKABLE void handleCtcpPing(CtcpEvent *event);
104     Q_INVOKABLE void handleCtcpTime(CtcpEvent *event);
105     Q_INVOKABLE void handleCtcpVersion(CtcpEvent *event);
106     Q_INVOKABLE void defaultHandler(const QString &ctcpCmd, CtcpEvent *event);
107
108 signals:
109     void newEvent(Event *event);
110
111 protected:
112     bool checkParamCount(IrcEvent *event, int minParams);
113     inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
114     void tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneous = false);
115
116 private slots:
117     //! Joins after a netsplit
118     /** This slot handles a bulk-join after a netsplit is over
119       * \param net     The network
120       * \param channel The channel the users joined
121       * \param users   The list of users that joind the channel
122       * \param modes   The list of modes the users get set
123       * \param quitMessage The message we received when the netsplit occured
124       */
125     void handleNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes, const QString &quitMessage);
126
127     //! Quits after a netsplit
128     /** This slot handles a bulk-quit after a netsplit occured
129       * \param net     The network
130       * \param channel The channel the users quitted
131       * \param users   The list of users that got split
132       * \param quitMessage The message we received when the netsplit occured
133       */
134     void handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage);
135
136     //! Netsplit finished
137     /** This slot deletes the netsplit object that sent the finished() signal
138       */
139     void handleNetsplitFinished();
140
141     void handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes);
142
143     //! Destroy any existing netsplits
144     /** This slot deletes all netsplit objects
145       * Used to get rid of existing netsplits on network reconnect
146       * \param network The network we want to clear
147       */
148     void destroyNetsplits(NetworkId network);
149
150 private:
151     CoreSession *_coreSession;
152
153     // structure to organize netsplits
154     // key: quit message
155     // value: the corresponding netsplit object
156     QHash<Network *, QHash<QString, Netsplit *> > _netsplits;
157
158     // IRCv3 capability negotiation
159     /**
160      * Sends the next capability from the queue.
161      *
162      * During nick registration if any capabilities remain queued, this will take the next and
163      * request it.  When no capabilities remain, capability negotiation is ended.
164      *
165      * @param[in,out] A network currently undergoing capability negotiation
166      */
167     void sendNextCap(Network *net);
168 };
169
170
171 #endif