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