KVIrc  4.9.2
DeveloperAPIs
KviIrcMessage.h
Go to the documentation of this file.
1 #ifndef _KVI_IRCMESSAGE_H_
2 #define _KVI_IRCMESSAGE_H_
3 //=============================================================================
4 //
5 // File : KviIrcMessage.h
6 // Creation date : Fri Aug 2 23:08:55 2002 GMT by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "kvi_settings.h"
28 #include "KviPointerList.h"
29 #include "KviCString.h"
30 #include "KviQString.h"
31 #include "KviConsoleWindow.h"
32 #include "KviKvsHash.h"
33 
34 #include <QMap>
35 #include <QDateTime>
36 
37 class KviIrcConnection;
38 class KviIrcContext;
39 class KviConneciton;
40 
41 //
42 // This is a single IRC message received from the server.
43 // The message is strictly associated to the connection it came from.
44 //
45 // The IRC protocol is strictly 8 bit and thus the strings
46 // are all 8 bit strings. The decoding of these strings should
47 // be done on the targeting context (mainly channel or query...)
48 //
49 
51 {
52 public:
53  KviIrcMessage(const char * message, KviIrcConnection * pConnection);
54 
55  ~KviIrcMessage();
56 
57 public:
61  enum Flags
62  {
67  HaltOutput = 1,
71  Unrecognized = 2
72  };
73 
74 private:
75  const char * m_ptr; // shallow! never null
76  KviCString m_szPrefix; // the extracted prefix string
77  KviCString m_szMessageTags; // the extracted message tags
78  KviCString m_szCommand; // the extracted command (may be numeric)
79  KviPointerList<KviCString> * m_pParams; // the list of parameters
80  QHash<QString, QString> m_ParsedMessageTags; // parsed messaged tags
81  KviConsoleWindow * m_pConsole; // the console we're attacched to
82  KviIrcConnection * m_pConnection; // the connection we're attacched to
83  int m_iNumericCommand; // the numeric of the command (0 if non numeric)
84  int m_iFlags; // yes.. flags :D
85  QDateTime m_time; // from server-time tag, if presented
86 public:
87  KviConsoleWindow * console() { return m_pConsole; };
88  KviIrcConnection * connection() { return m_pConsole->connection(); };
89 
90  bool isNumeric() { return (m_iNumericCommand >= 0); };
91  const char * command() { return m_szCommand.ptr(); };
92  KviCString * commandPtr() { return &m_szCommand; };
93  int numeric() { return m_iNumericCommand; };
94 
95  KviCString * prefixPtr() { return &m_szPrefix; };
96  const char * prefix() { return m_szPrefix.ptr(); };
97  const char * safePrefix();
98  bool hasPrefix() { return m_szPrefix.hasData(); };
99 
100  KviCString * messageTagsPtr() { return &m_szMessageTags; };
101  const char * messageTags() { return m_szMessageTags.ptr(); };
102  bool hasMessageTags() { return m_szMessageTags.hasData(); };
103 
104  QString * messageTagPtr(const QString & szTag);
105  bool hasMessageTag(const QString & szTag) { return m_ParsedMessageTags.contains(szTag); };
106  QHash<QString, QString> & messageTagsMap() { return m_ParsedMessageTags; };
107  KviKvsHash * messageTagsKvsHash();
108 
109  QDateTime serverTime() { return m_time; }
110 
111  bool isEmpty() { return (m_szPrefix.isEmpty() && m_szCommand.isEmpty() && m_pParams->isEmpty()); };
112 
113  int paramCount() { return m_pParams->count(); };
114 
115  const char * param(unsigned int idx) { return (idx < m_pParams->count()) ? m_pParams->at(idx)->ptr() : 0; };
116 
117  const char * safeParam(unsigned int idx) { return (idx < m_pParams->count()) ? m_pParams->at(idx)->ptr() : KviCString::emptyString().ptr(); };
118 
119  KviCString * paramString(unsigned int idx) { return m_pParams->at(idx); };
120 
121  const char * trailing()
122  {
123  KviCString * tr = m_pParams->last();
124  return tr ? tr->ptr() : 0;
125  };
126  KviCString * trailingString() { return m_pParams->last(); };
128  {
129  KviCString * tr = m_pParams->last();
130  return tr ? *tr : KviCString::emptyString();
131  };
132  const char * safeTrailing()
133  {
134  KviCString * tr = m_pParams->last();
135  return tr ? tr->ptr() : KviCString::emptyString().ptr();
136  };
137 
138  const char * allParams() { return m_ptr; };
139 
140  KviCString * firstParam() { return m_pParams->first(); };
141  KviCString * nextParam() { return m_pParams->next(); };
142 
143  void setHaltOutput() { m_iFlags |= HaltOutput; };
144  bool haltOutput() { return (m_iFlags & HaltOutput); };
145  void setUnrecognized() { m_iFlags |= Unrecognized; };
146  bool unrecognized() { return (m_iFlags & Unrecognized); };
147 
148  void decodeAndSplitPrefix(QString & szNick, QString & szUser, QString & szHost);
149  void decodeAndSplitMask(char * mask, QString & szNick, QString & szUser, QString & szHost);
150 
151 private:
152  void parseMessageTags();
153 };
154 
155 #endif //_KVI_IRCMESSAGE_H_
int paramCount()
Definition: KviIrcMessage.h:113
KviCString * paramString(unsigned int idx)
Definition: KviIrcMessage.h:119
Definition: KviCString.h:105
Definition: KviConsoleWindow.h:75
#define KVIRC_API
Definition: kvi_settings.h:128
KviConsoleWindow * console()
Definition: KviIrcMessage.h:87
int numeric()
Definition: KviIrcMessage.h:93
int m_iNumericCommand
Definition: KviIrcMessage.h:83
KviCString * commandPtr()
Definition: KviIrcMessage.h:92
Definition: KviIrcMessage.h:50
KviCString & safeTrailingString()
Definition: KviIrcMessage.h:127
const char * safeTrailing()
Definition: KviIrcMessage.h:132
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
char & at(int idx) const
Definition: KviCString.h:190
bool haltOutput()
Definition: KviIrcMessage.h:144
bool unrecognized()
Definition: KviIrcMessage.h:146
Flags
Definition: KviIrcMessage.h:61
void setHaltOutput()
Definition: KviIrcMessage.h:143
const char * prefix()
Definition: KviIrcMessage.h:96
bool hasPrefix()
Definition: KviIrcMessage.h:98
KviIrcConnection * connection()
Definition: KviIrcMessage.h:88
This class defines a new data type which contains hash data.
Definition: KviKvsHash.h:47
const char * safeParam(unsigned int idx)
Definition: KviIrcMessage.h:117
const char * param(unsigned int idx)
Definition: KviIrcMessage.h:115
int m_iFlags
Definition: KviIrcMessage.h:84
QString szHost
Definition: libkvisetup.cpp:45
QDateTime m_time
Definition: KviIrcMessage.h:85
KviCString * prefixPtr()
Definition: KviIrcMessage.h:95
void setUnrecognized()
Definition: KviIrcMessage.h:145
QHash< QString, QString > & messageTagsMap()
Definition: KviIrcMessage.h:106
const char * m_ptr
Definition: KviIrcMessage.h:75
KviConsoleWindow * m_pConsole
Definition: KviIrcMessage.h:81
bool isNumeric()
Definition: KviIrcMessage.h:90
const char * messageTags()
Definition: KviIrcMessage.h:101
bool hasMessageTag(const QString &szTag)
Definition: KviIrcMessage.h:105
bool hasMessageTags()
Definition: KviIrcMessage.h:102
C++ Template based double linked pointer list class.
KviCString m_szMessageTags
Definition: KviIrcMessage.h:77
bool isEmpty()
Definition: KviIrcMessage.h:111
KviCString m_szCommand
Definition: KviIrcMessage.h:78
KviIrcConnection * m_pConnection
Definition: KviIrcMessage.h:82
const char * command()
Definition: KviIrcMessage.h:91
KviCString * firstParam()
Definition: KviIrcMessage.h:140
KviCString * trailingString()
Definition: KviIrcMessage.h:126
Handling of hash data type in KVS.
QHash< QString, QString > m_ParsedMessageTags
Definition: KviIrcMessage.h:80
This file contains compile time settings.
KviPointerList< KviCString > * m_pParams
Definition: KviIrcMessage.h:79
KviCString * nextParam()
Definition: KviIrcMessage.h:141
const char * trailing()
Definition: KviIrcMessage.h:121
KviCString m_szPrefix
Definition: KviIrcMessage.h:76
char * ptr() const
Definition: KviCString.h:172
KviCString * messageTagsPtr()
Definition: KviIrcMessage.h:100
QDateTime serverTime()
Definition: KviIrcMessage.h:109
const char * allParams()
Definition: KviIrcMessage.h:138
Definition: KviIrcContext.h:58
Helper functions for the QString class.
static KviCString & emptyString()
Definition: KviCString.cpp:3159