1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 ***************************************************************************/
23 #include "common-export.h"
29 class COMMON_EXPORT IrcDecoder
33 * Parses an IRC message
34 * @param decode Decoder to be used for decoding the message
35 * @param rawMsg Raw Message
36 * @param tags[out] Parsed map of IRCv3 message tags
37 * @param prefix[out] Parsed prefix
38 * @param command[out] Parsed command
39 * @param parameters[out] Parsed list of parameters
41 static void parseMessage(const std::function<QString(const QByteArray&)>& decode, const QByteArray& raw, QHash<IrcTagKey, QString>& tags, QString& prefix, QString& command, QList<QByteArray>& parameters);
44 * Parses an encoded IRCv3 message tag value
45 * @param value encoded IRCv3 message tag value
46 * @return decoded string
48 static QString parseTagValue(const QString& value);
50 * Parses IRCv3 message tags given a message
51 * @param net Decoder to be used for decoding the message
52 * @param raw Raw Message
53 * @param start Current index into the message, will be advanced automatically
54 * @return Parsed message tags
56 static QHash<IrcTagKey, QString> parseTags(const std::function<QString(const QByteArray&)>& decode, const QByteArray& raw, int& start);
58 * Parses an IRC prefix, if available
59 * @param net Decoder to be used for decoding the message
60 * @param raw Raw Message
61 * @param start Current index into the message, will be advanced automatically
62 * @return Parsed prefix or empty string
64 static QString parsePrefix(const std::function<QString(const QByteArray&)>& decode, const QByteArray& raw, int& start);
66 * Parses an IRC named command or numeric RPL
67 * @param net Decoder to be used for decoding the message
68 * @param raw Raw Message
69 * @param start Current index into the message, will be advanced automatically
70 * @return Parsed command
72 static QString parseCommand(const std::function<QString(const QByteArray&)>& decode, const QByteArray& raw, int& start);
74 * Parses an IRC parameter
75 * @param net Decoder to be used for decoding the message
76 * @param raw Raw Message
77 * @param start Current index into the message, will be advanced automatically
78 * @return Parsed parameter
80 static QByteArray parseParameter(const QByteArray& raw, int& start);