-rw-r--r-- | noncore/net/opieirc/ircmessage.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp index 1b7072e..da8db77 100644 --- a/noncore/net/opieirc/ircmessage.cpp +++ b/noncore/net/opieirc/ircmessage.cpp | |||
@@ -1,157 +1,157 @@ | |||
1 | #include <opie2/odebug.h> | 1 | #include <opie2/odebug.h> |
2 | 2 | ||
3 | using namespace Opie::Core; | 3 | using namespace Opie::Core; |
4 | 4 | ||
5 | 5 | ||
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | #include <qstringlist.h> | 8 | #include <qstringlist.h> |
9 | #include <qregexp.h> | 9 | #include <qregexp.h> |
10 | 10 | ||
11 | #include "ircmessage.h" | 11 | #include "ircmessage.h" |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * Create a new IRCMessage by evaluating | 14 | * Create a new IRCMessage by evaluating |
15 | * a received string | 15 | * a received string |
16 | */ | 16 | */ |
17 | 17 | ||
18 | IRCMessage::IRCMessage(QString line) { | 18 | IRCMessage::IRCMessage(QString line) { |
19 | /* Remove CRs from the message */ | 19 | /* Remove CRs from the message */ |
20 | while((line.right(1) == "\n") || (line.right(1) == "\r")) | 20 | while((line.right(1) == "\n") || (line.right(1) == "\r")) |
21 | line = line.left(line.length() - 1); | 21 | line = line.left(line.length() - 1); |
22 | QTextIStream stream(&line); | 22 | QTextIStream stream(&line); |
23 | QString temp; | 23 | QString temp; |
24 | 24 | ||
25 | stream >> temp; | 25 | stream >> temp; |
26 | if (temp.startsWith(":")) { | 26 | if (temp.startsWith(":")) { |
27 | /* extract the prefix */ | 27 | /* extract the prefix */ |
28 | m_prefix = temp.right(temp.length()-1); | 28 | m_prefix = temp.right(temp.length()-1); |
29 | stream >> temp; | 29 | stream >> temp; |
30 | m_command = temp.upper(); | 30 | m_command = temp.upper(); |
31 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); | 31 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); |
32 | } else { | 32 | } else { |
33 | m_command = temp.upper(); | 33 | m_command = temp.upper(); |
34 | m_allParameters = line.right(line.length() - m_command.length() - 1); | 34 | m_allParameters = line.right(line.length() - m_command.length() - 1); |
35 | } | 35 | } |
36 | 36 | ||
37 | /* Create a list of all parameters */ | 37 | /* Create a list of all parameters */ |
38 | while(!(stream.atEnd())) { | 38 | while(!(stream.atEnd())) { |
39 | stream >> temp; | 39 | stream >> temp; |
40 | if (temp.startsWith(":")) { | 40 | if (temp.startsWith(":")) { |
41 | /* last parameter */ | 41 | /* last parameter */ |
42 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); | 42 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); |
43 | m_parameters << m_trailing; | 43 | m_parameters << m_trailing; |
44 | break; | 44 | break; |
45 | } else { | 45 | } else { |
46 | m_parameters << temp; | 46 | m_parameters << temp; |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | m_commandNumber = m_command.toInt(&m_isNumerical); | 51 | m_commandNumber = m_command.toInt(&m_isNumerical); |
52 | /* Is this a CTCP command */ | 52 | /* Is this a CTCP command */ |
53 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { | 53 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { |
54 | m_ctcp = TRUE; | 54 | m_ctcp = TRUE; |
55 | if (m_command == "PRIVMSG") { | 55 | |
56 | m_ctcpRequest = TRUE; | 56 | m_ctcpRequest = (m_command == "PRIVMSG"); |
57 | } | ||
58 | else { | ||
59 | m_ctcpRequest = FALSE; | ||
60 | } | ||
61 | 57 | ||
62 | /* Strip CTCP \001 characters */ | 58 | /* Strip CTCP \001 characters */ |
63 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); | 59 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); |
64 | QTextIStream ctcpStream(&m_allParameters); | 60 | QTextIStream ctcpStream(&m_allParameters); |
65 | ctcpStream >> m_ctcpDestination; | 61 | ctcpStream >> m_ctcpDestination; |
66 | ctcpStream >> temp; | 62 | ctcpStream >> temp; |
67 | m_ctcpCommand = temp.upper().right(temp.length()-1); | 63 | m_ctcpCommand = temp.upper().right(temp.length()-1); |
68 | m_parameters.clear(); | 64 | m_parameters.clear(); |
69 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; | 65 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; |
70 | length -= m_ctcpDestination.length() + 1; | 66 | length -= m_ctcpDestination.length() + 1; |
71 | if (length <= 0) { | 67 | if (length <= 0) { |
72 | m_allParameters = ""; | 68 | m_allParameters = ""; |
73 | } | 69 | } |
74 | else { | 70 | else { |
75 | m_allParameters = m_allParameters.right(length); | 71 | m_allParameters = m_allParameters.right(length); |
76 | m_parameters << m_allParameters; | 72 | m_parameters << m_allParameters; |
77 | } | 73 | } |
78 | } | 74 | } |
79 | else { | 75 | else { |
80 | m_ctcp = FALSE; | 76 | m_ctcp = FALSE; |
81 | } | 77 | } |
82 | 78 | ||
83 | 79 | ||
84 | odebug << "Parsed: " << line << oendl; | 80 | odebug << "Parsed: " << line << oendl; |
85 | odebug << "Prefix: " << m_prefix << oendl; | 81 | odebug << "Prefix: " << m_prefix << oendl; |
86 | odebug << "Command: " << m_command << oendl; | 82 | odebug << "Command: " << m_command << oendl; |
87 | odebug << "Allparameters: " << m_allParameters << oendl; | 83 | odebug << "Allparameters: " << m_allParameters << oendl; |
84 | |||
88 | for (unsigned int i=0; i<m_parameters.count(); i++) { | 85 | for (unsigned int i=0; i<m_parameters.count(); i++) { |
89 | odebug << "Parameter " << i << ":" << m_parameters[i] << oendl; | 86 | odebug << "Parameter " << i << ":" << m_parameters[i] << oendl; |
90 | } | 87 | } |
91 | odebug << "CTCP Command: " << m_ctcpCommand << oendl; | 88 | |
92 | odebug << "CTCP Destination: " << m_ctcpDestination << oendl; | 89 | if(m_ctcp) { |
93 | odebug << "CTCP param count is: " << m_parameters.count() << oendl; | 90 | odebug << "CTCP " << (m_ctcpRequest? "Request" : "Reply") << ": " << m_ctcpCommand << oendl; |
91 | odebug << "CTCP Destination: " << m_ctcpDestination << oendl; | ||
92 | odebug << "CTCP param count is: " << m_parameters.count() << oendl; | ||
93 | } | ||
94 | 94 | ||
95 | } | 95 | } |
96 | 96 | ||
97 | QString IRCMessage::param(int param) { | 97 | QString IRCMessage::param(int param) { |
98 | return m_parameters[param]; | 98 | return m_parameters[param]; |
99 | } | 99 | } |
100 | 100 | ||
101 | QStringList IRCMessage::params(const QString ¶mstring) const { | 101 | QStringList IRCMessage::params(const QString ¶mstring) const { |
102 | QStringList params, retvalue; | 102 | QStringList params, retvalue; |
103 | params = QStringList::split(',', paramstring); | 103 | params = QStringList::split(',', paramstring); |
104 | QStringList::Iterator end = params.end(); | 104 | QStringList::Iterator end = params.end(); |
105 | 105 | ||
106 | for (QStringList::Iterator it = params.begin(); it != end; ++it) { | 106 | for (QStringList::Iterator it = params.begin(); it != end; ++it) { |
107 | int pos = (*it).find(':'); | 107 | int pos = (*it).find(':'); |
108 | if(pos < 0) { | 108 | if(pos < 0) { |
109 | if((*it).toUInt() < m_parameters.count()) | 109 | if((*it).toUInt() < m_parameters.count()) |
110 | retvalue << m_parameters[(*it).toUInt()]; | 110 | retvalue << m_parameters[(*it).toUInt()]; |
111 | } | 111 | } |
112 | 112 | ||
113 | else { | 113 | else { |
114 | unsigned int start, end; | 114 | unsigned int start, end; |
115 | start = (*it).left(pos).toUInt(); | 115 | start = (*it).left(pos).toUInt(); |
116 | end = (*it).mid(pos+1).toUInt(); | 116 | end = (*it).mid(pos+1).toUInt(); |
117 | for (unsigned int i=start;i<=end && i < m_parameters.count() ;++i) { | 117 | for (unsigned int i=start;i<=end && i < m_parameters.count() ;++i) { |
118 | retvalue << m_parameters[i]; | 118 | retvalue << m_parameters[i]; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | return retvalue; | 123 | return retvalue; |
124 | } | 124 | } |
125 | 125 | ||
126 | QString IRCMessage::prefix() { | 126 | QString IRCMessage::prefix() { |
127 | return m_prefix; | 127 | return m_prefix; |
128 | } | 128 | } |
129 | 129 | ||
130 | QString IRCMessage::command() { | 130 | QString IRCMessage::command() { |
131 | return m_command; | 131 | return m_command; |
132 | } | 132 | } |
133 | 133 | ||
134 | QString IRCMessage::ctcpCommand() { | 134 | QString IRCMessage::ctcpCommand() { |
135 | return m_ctcpCommand; | 135 | return m_ctcpCommand; |
136 | } | 136 | } |
137 | 137 | ||
138 | QString IRCMessage::ctcpDestination() { | 138 | QString IRCMessage::ctcpDestination() { |
139 | return m_ctcpDestination; | 139 | return m_ctcpDestination; |
140 | } | 140 | } |
141 | 141 | ||
142 | unsigned short IRCMessage::commandNumber() { | 142 | unsigned short IRCMessage::commandNumber() { |
143 | return m_commandNumber; | 143 | return m_commandNumber; |
144 | } | 144 | } |
145 | 145 | ||
146 | bool IRCMessage::isNumerical() { | 146 | bool IRCMessage::isNumerical() { |
147 | return m_isNumerical; | 147 | return m_isNumerical; |
148 | } | 148 | } |
149 | 149 | ||
150 | bool IRCMessage::isCTCP() { | 150 | bool IRCMessage::isCTCP() { |
151 | return m_ctcp; | 151 | return m_ctcp; |
152 | } | 152 | } |
153 | 153 | ||
154 | bool IRCMessage::isCTCPRequest() { | 154 | bool IRCMessage::isCTCPRequest() { |
155 | return m_ctcpRequest; | 155 | return m_ctcpRequest; |
156 | } | 156 | } |
157 | 157 | ||