00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ICQ_H
00023 #define ICQ_H
00024
00025 #include <string>
00026 #include <list>
00027
00028 #include <libicq2000/Xml.h>
00029 #include <libicq2000/buffer.h>
00030 #include <libicq2000/exceptions.h>
00031 #include <libicq2000/constants.h>
00032 #include <libicq2000/Contact.h>
00033
00034 using std::string;
00035
00036 namespace ICQ2000 {
00037
00038
00039
00040 const unsigned short V6_TCP_START = 0x07ee;
00041 const unsigned short V6_TCP_ACK = 0x07da;
00042
00043
00044
00045
00046 const unsigned char MSG_Type_Normal = 0x01;
00047 const unsigned char MSG_Type_URL = 0x04;
00048 const unsigned char MSG_Type_AuthReq = 0x06;
00049 const unsigned char MSG_Type_AuthRej = 0x07;
00050 const unsigned char MSG_Type_AuthAcc = 0x08;
00051 const unsigned char MSG_Type_UserAdd = 0x0c;
00052 const unsigned char MSG_Type_WebPager= 0x0d;
00053 const unsigned char MSG_Type_EmailEx = 0x0e;
00054 const unsigned char MSG_Type_SMS = 0x1a;
00055
00056 const unsigned char MSG_Type_AutoReq_Away = 0xe8;
00057 const unsigned char MSG_Type_AutoReq_Occ = 0xe9;
00058 const unsigned char MSG_Type_AutoReq_NA = 0xea;
00059 const unsigned char MSG_Type_AutoReq_DND = 0xeb;
00060 const unsigned char MSG_Type_AutoReq_FFC = 0xec;
00061
00062 const unsigned char MSG_Flag_AutoReq = 0x03;
00063 const unsigned char MSG_Flag_Multi = 0x80;
00064
00065 const unsigned short Priority_Normal = 0x0001;
00066 const unsigned short Priority_Urgent = 0x0002;
00067 const unsigned short Priority_ToContactList = 0x0004;
00068
00069 const unsigned short AcceptStatus_Online = 0x0000;
00070 const unsigned short AcceptStatus_Denied = 0x0001;
00071 const unsigned short AcceptStatus_Away = 0x0004;
00072 const unsigned short AcceptStatus_Occupied = 0x0009;
00073 const unsigned short AcceptStatus_DND = 0x000a;
00074 const unsigned short AcceptStatus_Occ_Accept = 0x000c;
00075 const unsigned short AcceptStatus_NA = 0x000e;
00076
00077
00078
00079
00080
00081
00082
00083
00084 class ICQSubType {
00085 protected:
00086 unsigned short m_seqnum;
00087
00088 unsigned char m_flags;
00089
00090 public:
00091 ICQSubType();
00092 virtual ~ICQSubType() { }
00093
00094 static ICQSubType* ParseICQSubType(Buffer& b, bool adv, bool ack);
00095 void Output(Buffer& b) const;
00096
00097 virtual void ParseBody(Buffer& b) = 0;
00098 virtual void OutputBody(Buffer& b) const = 0;
00099 virtual unsigned short Length() const = 0;
00100
00101 virtual unsigned char getType() const = 0;
00102 virtual unsigned char getFlags() const { return m_flags; }
00103 virtual void setFlags(unsigned char f) { m_flags = f; }
00104
00105 unsigned short getSeqNum() const { return m_seqnum; }
00106 void setSeqNum(unsigned short s) { m_seqnum = s; }
00107 };
00108
00109 class UINICQSubType : public ICQSubType {
00110 protected:
00111 unsigned int m_source, m_destination;
00112 bool m_advanced, m_ack;
00113 bool m_urgent, m_tocontactlist;
00114 unsigned short m_status;
00115 string m_away_message;
00116
00117 public:
00118 UINICQSubType();
00119 UINICQSubType(unsigned int s, unsigned int d);
00120
00121 void setDestination(unsigned int uin);
00122 void setSource(unsigned int uin);
00123 unsigned int getSource() const;
00124 unsigned int getDestination() const;
00125
00126 unsigned short getStatus() const;
00127 void setStatus(unsigned short s);
00128
00129 void ParseBody(Buffer& b);
00130 void OutputBody(Buffer& b) const;
00131
00132 virtual void ParseBodyUIN(Buffer& b) = 0;
00133 virtual void ParseBodyUINACK(Buffer& b);
00134
00135 virtual void OutputBodyUIN(Buffer& b) const = 0;
00136 virtual void OutputBodyUINACK(Buffer& b) const;
00137
00138 bool isAdvanced() const;
00139 void setAdvanced(bool b);
00140 void setACK(bool b);
00141 bool isACK() const;
00142 void setUrgent(bool b);
00143 bool isUrgent() const;
00144 void setToContactList(bool b);
00145 bool isToContactList() const;
00146
00147 void setAwayMessage(const std::string& m);
00148 string getAwayMessage() const;
00149 };
00150
00151 class NormalICQSubType : public UINICQSubType {
00152 private:
00153 string m_message;
00154 bool m_multi;
00155 unsigned int m_foreground, m_background;
00156
00157 public:
00158 NormalICQSubType(bool multi);
00159 NormalICQSubType(const string& msg);
00160
00161 string getMessage() const;
00162 bool isMultiParty() const;
00163 void setMessage(const string& message);
00164
00165 void setForeground(unsigned int f);
00166 void setBackground(unsigned int f);
00167 unsigned int getForeground() const;
00168 unsigned int getBackground() const;
00169
00170 void ParseBodyUIN(Buffer& b);
00171 void OutputBodyUIN(Buffer& b) const;
00172 void ParseBodyUINACK(Buffer& b);
00173 void OutputBodyUINACK(Buffer& b) const;
00174
00175 unsigned short Length() const;
00176 unsigned char getType() const;
00177 };
00178
00179 class URLICQSubType : public UINICQSubType {
00180 private:
00181 string m_message;
00182 string m_url;
00183
00184 public:
00185 URLICQSubType();
00186 URLICQSubType(const string& msg, const string& url);
00187
00188 string getMessage() const;
00189 void setMessage(const string& msg);
00190 string getURL() const;
00191 void setURL(const string& url);
00192
00193 void ParseBodyUIN(Buffer& b);
00194 void OutputBodyUIN(Buffer& b) const;
00195 unsigned short Length() const;
00196 unsigned char getType() const;
00197 };
00198
00199 class AwayMsgSubType : public UINICQSubType {
00200 private:
00201 unsigned char m_type;
00202 string m_message;
00203
00204 public:
00205 AwayMsgSubType(Status s);
00206 AwayMsgSubType(unsigned char m_type);
00207
00208 void ParseBodyUIN(Buffer& b);
00209 void OutputBodyUIN(Buffer& b) const;
00210
00211 unsigned short Length() const;
00212 unsigned char getType() const;
00213 unsigned char getFlags() const;
00214 };
00215
00216 class SMSICQSubType : public ICQSubType {
00217 public:
00218 enum Type {
00219 SMS,
00220 SMS_Receipt
00221 };
00222
00223 private:
00224
00225 string m_source, m_sender, m_senders_network, m_time;
00226
00227
00228 string m_message_id, m_destination, m_submission_time, m_delivery_time;
00229 bool m_delivered;
00230
00231 string m_message;
00232 Type m_type;
00233
00234 public:
00235 SMSICQSubType();
00236
00237 string getMessage() const;
00238 Type getSMSType() const;
00239
00240 void ParseBody(Buffer& b);
00241 void OutputBody(Buffer& b) const;
00242 unsigned short Length() const;
00243 unsigned char getType() const;
00244
00245
00246 string getSource() const { return m_source; }
00247 string getSender() const { return m_sender; }
00248 string getSenders_network() const { return m_senders_network; }
00249 string getTime() const { return m_time; }
00250
00251
00252 string getMessageId() const { return m_message_id; }
00253 string getDestination() const { return m_destination; }
00254 string getSubmissionTime() const { return m_submission_time; }
00255 string getDeliveryTime() const { return m_delivery_time; }
00256 bool delivered() const { return m_delivered; }
00257
00258 };
00259
00260 class AuthReqICQSubType : public UINICQSubType {
00261 private:
00262 std::string m_alias, m_firstname, m_lastname, m_email, m_message;
00263 bool m_auth;
00264
00265 public:
00266 AuthReqICQSubType();
00267 AuthReqICQSubType(const string& alias, const string& firstname,
00268 const string& lastname, const string& email, bool auth,
00269 const string& msg);
00270
00271 std::string getMessage() const;
00272
00273 void ParseBodyUIN(Buffer& b);
00274 void OutputBodyUIN(Buffer& b) const;
00275 unsigned short Length() const;
00276 unsigned char getType() const;
00277
00278 };
00279
00280 class AuthAccICQSubType : public UINICQSubType {
00281 public:
00282 AuthAccICQSubType();
00283
00284 void ParseBodyUIN(Buffer& b);
00285 void OutputBodyUIN(Buffer& b) const;
00286 unsigned short Length() const;
00287 unsigned char getType() const;
00288
00289 };
00290
00291 class AuthRejICQSubType : public UINICQSubType {
00292 private:
00293 string m_message;
00294
00295 public:
00296 AuthRejICQSubType();
00297 AuthRejICQSubType(const string& msg);
00298
00299 string getMessage() const;
00300 void setMessage(const string& msg);
00301
00302 void ParseBodyUIN(Buffer& b);
00303 void OutputBodyUIN(Buffer& b) const;
00304 unsigned short Length() const;
00305 unsigned char getType() const;
00306
00307 };
00308
00309 class EmailExICQSubType : public ICQSubType {
00310 private:
00311 string m_message, m_email, m_sender;
00312
00313 public:
00314 EmailExICQSubType();
00315
00316 void ParseBody(Buffer& b);
00317 void OutputBody(Buffer& b) const;
00318 unsigned short Length() const;
00319 unsigned char getType() const;
00320
00321 string getMessage() const;
00322 string getEmail() const;
00323 string getSender() const;
00324 };
00325
00326
00327
00328
00329
00330 class WebPagerICQSubType : public ICQSubType {
00331 private:
00332 string m_message, m_email, m_sender;
00333
00334 public:
00335 WebPagerICQSubType();
00336
00337 void ParseBody(Buffer& b);
00338 void OutputBody(Buffer& b) const;
00339 unsigned short Length() const;
00340 unsigned char getType() const;
00341
00342 string getMessage() const;
00343 string getEmail() const;
00344 string getSender() const;
00345 };
00346
00347 class UserAddICQSubType : public UINICQSubType {
00348 private:
00349 std::string m_alias, m_firstname, m_lastname, m_email;
00350 bool m_auth;
00351
00352 public:
00353 UserAddICQSubType();
00354 UserAddICQSubType(const std::string& alias, const std::string& firstname,
00355 const std::string& lastname, const std::string& email, bool auth);
00356
00357 void ParseBodyUIN(Buffer& b);
00358 void OutputBodyUIN(Buffer& b) const;
00359 unsigned short Length() const;
00360 unsigned char getType() const;
00361 };
00362
00363
00364
00365 void string_split(const std::string& in, const std::string& sep,
00366 int count, std::list<std::string>& fields);
00367 }
00368
00369 #endif