author | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
commit | d478be344e2ba383a1e38d2a1705de1cdbe2e838 (patch) (unidiff) | |
tree | 9daf7b496c74c695ed8bd72a6ccd321f770b043c /noncore/net/opieirc/ircmessage.cpp | |
parent | 2d6c8bd7290b766c31c100cd2d66ef0d1d0c407c (diff) | |
download | opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.zip opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.gz opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.bz2 |
initial import of OpieIRC v0.1
Diffstat (limited to 'noncore/net/opieirc/ircmessage.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircmessage.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp new file mode 100644 index 0000000..74e9c6f --- a/dev/null +++ b/noncore/net/opieirc/ircmessage.cpp | |||
@@ -0,0 +1,120 @@ | |||
1 | #include <qtextstream.h> | ||
2 | #include "ircmessage.h" | ||
3 | |||
4 | /* | ||
5 | * Create a new IRCMessage by evaluating | ||
6 | * a received string | ||
7 | */ | ||
8 | |||
9 | IRCMessage::IRCMessage(QString line) { | ||
10 | /* Remove CRs from the message */ | ||
11 | while((line.right(1) == "\n") || (line.right(1) == "\r")) | ||
12 | line = line.left(line.length() - 1); | ||
13 | QTextIStream stream(&line); | ||
14 | QString temp; | ||
15 | |||
16 | stream >> temp; | ||
17 | if (temp.startsWith(":")) { | ||
18 | /* extract the prefix */ | ||
19 | m_prefix = temp.right(temp.length()-1); | ||
20 | stream >> temp; | ||
21 | m_command = temp.upper(); | ||
22 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); | ||
23 | } else { | ||
24 | m_command = temp.upper(); | ||
25 | m_allParameters = line.right(line.length() - m_command.length() - 1); | ||
26 | } | ||
27 | /* Create a list of all parameters */ | ||
28 | while(!(stream.atEnd())) { | ||
29 | stream >> temp; | ||
30 | if (temp.startsWith(":")) { | ||
31 | /* last parameter */ | ||
32 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); | ||
33 | m_parameters << m_trailing; | ||
34 | break; | ||
35 | } else { | ||
36 | m_parameters << temp; | ||
37 | } | ||
38 | } | ||
39 | m_commandNumber = m_command.toInt(&m_isNumerical); | ||
40 | /* Is this a CTCP command */ | ||
41 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { | ||
42 | m_ctcp = TRUE; | ||
43 | /* Strip CTCP \001 characters */ | ||
44 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); | ||
45 | QTextIStream ctcpStream(&m_allParameters); | ||
46 | if (m_command == "PRIVMSG") | ||
47 | ctcpStream >> m_ctcpDestination; | ||
48 | ctcpStream >> temp; | ||
49 | m_ctcpCommand = temp.upper().right(temp.length()-1); | ||
50 | m_parameters.clear(); | ||
51 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; | ||
52 | if (m_command == "PRIVMSG") | ||
53 | length -= m_ctcpDestination.length() + 1; | ||
54 | if (length <= 0) { | ||
55 | m_allParameters = ""; | ||
56 | } else { | ||
57 | m_allParameters = m_allParameters.right(length); | ||
58 | m_parameters << m_allParameters; | ||
59 | } | ||
60 | } else { | ||
61 | m_ctcp = FALSE; | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | -- Uncomment to debug -- | ||
66 | |||
67 | printf("Parsed : '%s'\n", line.ascii()); | ||
68 | printf("Prefix : '%s'\n", m_prefix.ascii()); | ||
69 | printf("Command : '%s'\n", m_command.ascii()); | ||
70 | printf("Allparameters : '%s'\n", m_allParameters.ascii()); | ||
71 | for (unsigned int i=0; i<m_parameters.count(); i++) { | ||
72 | printf("Parameter %i : '%s'\n", i, m_parameters[i].ascii()); | ||
73 | } | ||
74 | printf("CTCP Command : '%s'\n", m_ctcpCommand.latin1()); | ||
75 | printf("CTCP Destination : '%s'\n", m_ctcpDestination.latin1()); | ||
76 | printf("CTCP param count is : '%i'\n", m_parameters.count()); | ||
77 | |||
78 | */ | ||
79 | } | ||
80 | |||
81 | QString IRCMessage::param(int param) { | ||
82 | return m_parameters[param]; | ||
83 | } | ||
84 | |||
85 | QString IRCMessage::prefix() { | ||
86 | return m_prefix; | ||
87 | } | ||
88 | |||
89 | QString IRCMessage::command() { | ||
90 | return m_command; | ||
91 | } | ||
92 | |||
93 | QString IRCMessage::ctcpCommand() { | ||
94 | return m_ctcpCommand; | ||
95 | } | ||
96 | |||
97 | QString IRCMessage::ctcpDestination() { | ||
98 | return m_ctcpDestination; | ||
99 | } | ||
100 | |||
101 | unsigned short IRCMessage::commandNumber() { | ||
102 | return m_commandNumber; | ||
103 | } | ||
104 | |||
105 | bool IRCMessage::isNumerical() { | ||
106 | return m_isNumerical; | ||
107 | } | ||
108 | |||
109 | bool IRCMessage::isCTCP() { | ||
110 | return m_ctcp; | ||
111 | } | ||
112 | |||
113 | QString IRCMessage::trailing() { | ||
114 | return m_trailing; | ||
115 | } | ||
116 | |||
117 | QString IRCMessage::allParameters() { | ||
118 | return m_allParameters; | ||
119 | } | ||
120 | |||