adding missing includes; trivial fix - comparison with string literal. by
[centerim.git] / libicq2000 / src / ICQ.h
blob1579ac26a4a4a724386894ea9c29d0f4fddd178e
1 /*
2 * ICQ Subtypes
4 * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef ICQ_H
23 #define ICQ_H
25 #include <string>
26 #include <list>
28 #include "Xml.h"
29 #include "buffer.h"
30 #include "exceptions.h"
31 #include "constants.h"
32 #include "Contact.h"
34 namespace ICQ2000 {
36 // ------------- TCP Command Types ------------------
38 const unsigned short V6_TCP_START = 0x07ee;
39 const unsigned short V6_TCP_ACK = 0x07da;
40 const unsigned short V6_TCP_CANCEL = 0x07d0;
42 // ------------- Message Types ----------------------
44 const unsigned char MSG_Type_Normal = 0x01;
45 const unsigned char MSG_Type_FT = 0x03;
46 const unsigned char MSG_Type_URL = 0x04;
47 const unsigned char MSG_Type_AuthReq = 0x06;
48 const unsigned char MSG_Type_AuthRej = 0x07;
49 const unsigned char MSG_Type_AuthAcc = 0x08;
50 const unsigned char MSG_Type_UserAdd = 0x0c;
51 const unsigned char MSG_Type_WebPager= 0x0d;
52 const unsigned char MSG_Type_EmailEx = 0x0e;
53 const unsigned char MSG_Type_SMS = 0x1a;
54 const unsigned char MSG_Type_Contact = 0x13;
56 const unsigned char MSG_Type_AutoReq_Away = 0xe8;
57 const unsigned char MSG_Type_AutoReq_Occ = 0xe9;
58 const unsigned char MSG_Type_AutoReq_NA = 0xea;
59 const unsigned char MSG_Type_AutoReq_DND = 0xeb;
60 const unsigned char MSG_Type_AutoReq_FFC = 0xec;
62 const unsigned char MSG_Flag_AutoReq = 0x03;
63 const unsigned char MSG_Flag_Multi = 0x80;
65 const unsigned short Priority_Normal = 0x0001;
66 const unsigned short Priority_Urgent = 0x0002;
67 const unsigned short Priority_ToContactList = 0x0004;
69 const unsigned short AcceptStatus_Online = 0x0000; // accepted
70 const unsigned short AcceptStatus_Denied = 0x0001; // not accepted - denied
71 const unsigned short AcceptStatus_Away = 0x0004; // accepted in away
72 const unsigned short AcceptStatus_Occupied = 0x0009; // not accepted in occupied
73 const unsigned short AcceptStatus_DND = 0x000a; // not accepted in DND
74 const unsigned short AcceptStatus_Occ_Accept = 0x000c; // accepted from a to contact list in occupied
75 const unsigned short AcceptStatus_NA = 0x000e; // accepted in NA
78 /* ICQSubtype classes
79 * An attempt at clearing up the complete
80 * mess ICQ have made of bundling everything
81 * into one TLV
84 class ICQSubType {
85 protected:
86 unsigned short m_seqnum;
88 unsigned char m_flags;
90 public:
91 ICQSubType();
92 virtual ~ICQSubType() { }
94 static ICQSubType* ParseICQSubType(Buffer& b, bool adv, bool ack);
95 void Output(Buffer& b) const;
97 virtual void ParseBody(Buffer& b) = 0;
98 virtual void OutputBody(Buffer& b) const = 0;
99 virtual unsigned short Length() const = 0;
101 virtual unsigned char getType() const = 0;
102 virtual unsigned char getFlags() const { return m_flags; }
103 virtual void setFlags(unsigned char f) { m_flags = f; }
105 unsigned short getSeqNum() const { return m_seqnum; }
106 void setSeqNum(unsigned short s) { m_seqnum = s; }
109 class UINICQSubType : public ICQSubType {
110 protected:
111 unsigned int m_source, m_destination;
112 bool m_advanced, m_ack;
113 bool m_urgent, m_tocontactlist;
114 unsigned short m_status;
115 std::string m_away_message;
117 public:
118 UINICQSubType();
119 UINICQSubType(unsigned int s, unsigned int d);
121 void setDestination(unsigned int uin);
122 void setSource(unsigned int uin);
123 unsigned int getSource() const;
124 unsigned int getDestination() const;
126 unsigned short getStatus() const;
127 void setStatus(unsigned short s);
129 void ParseBody(Buffer& b);
130 void OutputBody(Buffer& b) const;
132 virtual void ParseBodyUIN(Buffer& b) = 0;
133 virtual void ParseBodyUINACK(Buffer& b);
135 virtual void OutputBodyUIN(Buffer& b) const = 0;
136 virtual void OutputBodyUINACK(Buffer& b) const;
138 bool isAdvanced() const;
139 void setAdvanced(bool b);
140 void setACK(bool b);
141 bool isACK() const;
142 void setUrgent(bool b);
143 bool isUrgent() const;
144 void setToContactList(bool b);
145 bool isToContactList() const;
147 void setAwayMessage(const std::string& m);
148 std::string getAwayMessage() const;
151 class NormalICQSubType : public UINICQSubType {
152 private:
153 std::string m_message;
154 bool m_multi;
155 unsigned int m_foreground, m_background;
156 unsigned short m_encoding;
158 public:
159 NormalICQSubType(bool multi);
160 NormalICQSubType(const std::string& msg);
162 std::string getMessage() const;
163 bool isMultiParty() const;
164 void setMessage(const std::string& message);
165 void setEncoding(const unsigned short encoding);
166 unsigned short getEncoding() const;
168 void setForeground(unsigned int f);
169 void setBackground(unsigned int f);
170 unsigned int getForeground() const;
171 unsigned int getBackground() const;
173 void ParseBodyUIN(Buffer& b);
174 void OutputBodyUIN(Buffer& b) const;
175 void ParseBodyUINACK(Buffer& b);
176 void OutputBodyUINACK(Buffer& b) const;
178 unsigned short Length() const;
179 unsigned char getType() const;
182 class URLICQSubType : public UINICQSubType {
183 private:
184 std::string m_message;
185 std::string m_url;
187 public:
188 URLICQSubType();
189 URLICQSubType(const std::string& msg, const std::string& url);
191 std::string getMessage() const;
192 void setMessage(const std::string& msg);
193 std::string getURL() const;
194 void setURL(const std::string& url);
196 void ParseBodyUIN(Buffer& b);
197 void OutputBodyUIN(Buffer& b) const;
198 unsigned short Length() const;
199 unsigned char getType() const;
202 class AwayMsgSubType : public UINICQSubType {
203 private:
204 unsigned char m_type;
205 std::string m_message;
207 public:
208 AwayMsgSubType(Status s);
209 AwayMsgSubType(unsigned char m_type);
211 void ParseBodyUIN(Buffer& b);
212 void OutputBodyUIN(Buffer& b) const;
214 unsigned short Length() const;
215 unsigned char getType() const;
216 unsigned char getFlags() const;
219 class SMSICQSubType : public ICQSubType {
220 public:
221 enum Type {
222 SMS,
223 SMS_Receipt
226 private:
227 // SMS fields
228 std::string m_source, m_sender, m_senders_network, m_time;
230 // SMS Receipt fields
231 std::string m_message_id, m_destination, m_submission_time, m_delivery_time;
232 bool m_delivered;
234 std::string m_message;
235 Type m_type;
237 public:
238 SMSICQSubType();
240 std::string getMessage() const;
241 Type getSMSType() const;
243 void ParseBody(Buffer& b);
244 void OutputBody(Buffer& b) const;
245 unsigned short Length() const;
246 unsigned char getType() const;
248 // -- SMS fields --
249 std::string getSource() const { return m_source; }
250 std::string getSender() const { return m_sender; }
251 std::string getSenders_network() const { return m_senders_network; }
252 std::string getTime() const { return m_time; }
254 // -- SMS Receipt fields --
255 std::string getMessageId() const { return m_message_id; }
256 std::string getDestination() const { return m_destination; }
257 std::string getSubmissionTime() const { return m_submission_time; }
258 std::string getDeliveryTime() const { return m_delivery_time; }
259 bool delivered() const { return m_delivered; }
263 class AuthReqICQSubType : public UINICQSubType {
264 private:
265 std::string m_alias, m_firstname, m_lastname, m_email, m_message;
266 bool m_auth;
268 public:
269 AuthReqICQSubType();
270 AuthReqICQSubType(const std::string& alias, const std::string& firstname,
271 const std::string& lastname, const std::string& email, bool auth,
272 const std::string& msg);
274 std::string getMessage() const;
276 void ParseBodyUIN(Buffer& b);
277 void OutputBodyUIN(Buffer& b) const;
278 unsigned short Length() const;
279 unsigned char getType() const;
283 class AuthAccICQSubType : public UINICQSubType {
284 public:
285 AuthAccICQSubType();
287 void ParseBodyUIN(Buffer& b);
288 void OutputBodyUIN(Buffer& b) const;
289 unsigned short Length() const;
290 unsigned char getType() const;
294 class AuthRejICQSubType : public UINICQSubType {
295 private:
296 std::string m_message;
298 public:
299 AuthRejICQSubType();
300 AuthRejICQSubType(const std::string& msg);
302 std::string getMessage() const;
303 void setMessage(const std::string& msg);
305 void ParseBodyUIN(Buffer& b);
306 void OutputBodyUIN(Buffer& b) const;
307 unsigned short Length() const;
308 unsigned char getType() const;
312 class EmailExICQSubType : public ICQSubType {
313 private:
314 std::string m_message, m_email, m_sender;
316 public:
317 EmailExICQSubType();
319 void ParseBody(Buffer& b);
320 void OutputBody(Buffer& b) const;
321 unsigned short Length() const;
322 unsigned char getType() const;
324 std::string getMessage() const;
325 std::string getEmail() const;
326 std::string getSender() const;
330 * (why the hell ICQ invented another subtype for this when it's almost identical to
331 * an email express message is anyones guess..)
333 class WebPagerICQSubType : public ICQSubType {
334 private:
335 std::string m_message, m_email, m_sender;
337 public:
338 WebPagerICQSubType();
340 void ParseBody(Buffer& b);
341 void OutputBody(Buffer& b) const;
342 unsigned short Length() const;
343 unsigned char getType() const;
345 std::string getMessage() const;
346 std::string getEmail() const;
347 std::string getSender() const;
350 class UserAddICQSubType : public UINICQSubType {
351 private:
352 std::string m_alias, m_firstname, m_lastname, m_email;
353 bool m_auth;
355 public:
356 UserAddICQSubType();
357 UserAddICQSubType(const std::string& alias, const std::string& firstname,
358 const std::string& lastname, const std::string& email, bool auth);
360 void ParseBodyUIN(Buffer& b);
361 void OutputBodyUIN(Buffer& b) const;
362 unsigned short Length() const;
363 unsigned char getType() const;
367 class FTICQSubType : public UINICQSubType
369 private:
370 std::string m_message, m_description;
371 unsigned int m_size;
372 unsigned short m_port, m_revport;
374 public:
375 FTICQSubType();
376 FTICQSubType(const std::string& msg, const std::string& desc,
377 const int size);
378 void ParseBodyUIN(Buffer& b);
379 void ParseBodyUINACK(Buffer& b);
380 void OutputBodyUIN(Buffer& b) const;
381 void OutputBodyUINACK(Buffer& b) const;
382 unsigned short Length() const;
383 unsigned char getType() const;
385 unsigned int getSize() const;
386 unsigned short getPort() const;
387 unsigned short getRevPort() const;
388 std::string getMessage() const;
389 std::string getDescription() const;
391 void setMessage(const std::string& msg);
392 void setDescription(const std::string& msg);
393 void setPort(unsigned short port);
394 void setRevPort(unsigned short port);
395 void setSize(unsigned int size);
398 class ContactICQSubType : public UINICQSubType
400 private:
401 std::list<ContactRef> m_content;
403 public:
404 ContactICQSubType();
405 ContactICQSubType(const std::list<ContactRef> &content);
407 void ParseBodyUIN(Buffer& b);
408 void OutputBodyUIN(Buffer& b) const;
409 unsigned short Length() const;
410 unsigned char getType() const;
412 std::list<ContactRef> getContacts() const;
415 // helper functions
417 void string_split(const std::string& in, const std::string& sep,
418 int count, std::list<std::string>& fields);
421 #endif