00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TLV_H
00023 #define TLV_H
00024
00025 #include <string>
00026 #include <map>
00027
00028 #include <string.h>
00029 #include <stdlib.h>
00030
00031 #include <libicq2000/Xml.h>
00032 #include <libicq2000/exceptions.h>
00033 #include <libicq2000/buffer.h>
00034 #include <libicq2000/constants.h>
00035 #include <libicq2000/ICQ.h>
00036 #include <libicq2000/Capabilities.h>
00037
00038 using std::string;
00039 using std::map;
00040
00041 namespace ICQ2000 {
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 enum TLV_ParseMode { TLV_ParseMode_Channel01,
00056 TLV_ParseMode_Channel02,
00057 TLV_ParseMode_Channel04,
00058 TLV_ParseMode_MessageBlock,
00059 TLV_ParseMode_AdvMsgBlock,
00060 TLV_ParseMode_InMessageData,
00061 TLV_ParseMode_InAdvMsgData
00062 };
00063
00064
00065 const unsigned short TLV_Screenname = 0x0001;
00066 const unsigned short TLV_Password = 0x0002;
00067 const unsigned short TLV_ClientProfile = 0x0003;
00068 const unsigned short TLV_UserInfo = 0x0005;
00069 const unsigned short TLV_Cookie = 0x0006;
00070 const unsigned short TLV_CountryCode = 0x000e;
00071 const unsigned short TLV_Language = 0x000f;
00072 const unsigned short TLV_ClientBuildMinor = 0x0014;
00073 const unsigned short TLV_ClientType = 0x0016;
00074 const unsigned short TLV_ClientVersionMajor = 0x0017;
00075 const unsigned short TLV_ClientVersionMinor = 0x0018;
00076 const unsigned short TLV_ClientICQNumber = 0x0019;
00077 const unsigned short TLV_ClientBuildMajor = 0x001a;
00078
00079
00080 const unsigned short TLV_UserClass = 0x0001;
00081 const unsigned short TLV_SignupDate = 0x0002;
00082 const unsigned short TLV_SignonDate = 0x0003;
00083 const unsigned short TLV_Port = 0x0004;
00084 const unsigned short TLV_UserInfoCapabilities = 0x0005;
00085 const unsigned short TLV_Status = 0x0006;
00086 const unsigned short TLV_Unknown = 0x0008;
00087 const unsigned short TLV_IPAddress = 0x000a;
00088 const unsigned short TLV_WebAddress = 0x000b;
00089 const unsigned short TLV_LANDetails = 0x000c;
00090 const unsigned short TLV_Capabilities = 0x000d;
00091 const unsigned short TLV_TimeOnline = 0x000f;
00092
00093
00094
00095 const unsigned short TLV_ErrorURL = 0x0004;
00096 const unsigned short TLV_Redirect = 0x0005;
00097
00098 const unsigned short TLV_ErrorCode = 0x0008;
00099 const unsigned short TLV_DisconnectReason = 0x0009;
00100 const unsigned short TLV_DisconnectMessage = 0x000b;
00101 const unsigned short TLV_Unknown3 = 0x000c;
00102 const unsigned short TLV_EmailAddress = 0x0011;
00103 const unsigned short TLV_RegStatus = 0x0013;
00104
00105
00106 const unsigned short TLV_MessageData = 0x0002;
00107 const unsigned short TLV_ServerAckRequested = 0x0003;
00108 const unsigned short TLV_MessageIsAutoResponse = 0x0004;
00109 const unsigned short TLV_ICQData = 0x0005;
00110
00111
00112 const unsigned short TLV_AdvMsgData = 0x0005;
00113
00114
00115 const unsigned short TLV_Unknown0501 = 0x0501;
00116 const unsigned short TLV_MessageText = 0x0101;
00117
00118
00119 const unsigned short TLV_AdvMsgBody = 0x2711;
00120
00121
00122
00123
00124 class TLV {
00125 public:
00126 virtual ~TLV() { }
00127
00128 virtual unsigned short Type() const = 0;
00129 virtual unsigned short Length() const = 0;
00130 };
00131
00132
00133 class InTLV : public TLV {
00134 public:
00135 virtual void ParseValue(Buffer& b) = 0;
00136
00137 static InTLV* ParseTLV(Buffer& b, TLV_ParseMode pm);
00138 };
00139
00140
00141 class OutTLV : public TLV {
00142 protected:
00143 virtual void OutputHeader(Buffer& b) const;
00144 virtual void OutputValue(Buffer& b) const = 0;
00145
00146 public:
00147 virtual void Output(Buffer& b) const;
00148 };
00149
00150
00151
00152 class ShortTLV : public OutTLV, public InTLV {
00153 protected:
00154 unsigned short m_value;
00155
00156 virtual void OutputValue(Buffer& b) const;
00157
00158 public:
00159 ShortTLV();
00160 ShortTLV(unsigned short n);
00161
00162 unsigned short Length() const { return 2; }
00163
00164 virtual void ParseValue(Buffer& b);
00165 virtual unsigned short Value() const { return m_value; }
00166 };
00167
00168
00169 class LongTLV : public OutTLV, public InTLV {
00170 protected:
00171 unsigned int m_value;
00172
00173 virtual void OutputValue(Buffer& b) const;
00174
00175 public:
00176 LongTLV();
00177 LongTLV(unsigned int n);
00178
00179 unsigned short Length() const { return 4; }
00180
00181 virtual void ParseValue(Buffer& b);
00182 virtual unsigned int Value() const { return m_value; }
00183 };
00184
00185
00186 class StringTLV : public OutTLV, public InTLV {
00187 protected:
00188 string m_value;
00189
00190 virtual void OutputValue(Buffer& b) const;
00191
00192 public:
00193 StringTLV();
00194 StringTLV(const string& val);
00195
00196 unsigned short Length() const { return m_value.size(); }
00197
00198 virtual void ParseValue(Buffer& b);
00199 virtual string Value() const { return m_value; }
00200 };
00201
00202
00203
00204
00205 class ErrorURLTLV : public StringTLV {
00206 public:
00207 ErrorURLTLV() { }
00208 unsigned short Type() const { return TLV_ErrorURL; }
00209 };
00210
00211 class ErrorCodeTLV : public ShortTLV {
00212 public:
00213 ErrorCodeTLV() { }
00214 unsigned short Type() const { return TLV_ErrorCode; }
00215 };
00216
00217 class DisconnectReasonTLV : public ShortTLV {
00218 public:
00219 DisconnectReasonTLV() { }
00220 unsigned short Type() const { return TLV_DisconnectReason; }
00221 };
00222
00223 class DisconnectMessageTLV : public StringTLV {
00224 public:
00225 DisconnectMessageTLV() { }
00226 unsigned short Type() const { return TLV_DisconnectMessage; }
00227 };
00228
00229 class ScreenNameTLV : public StringTLV {
00230 public:
00231 ScreenNameTLV();
00232 ScreenNameTLV(const string& val);
00233
00234 unsigned short Type() const { return TLV_Screenname; }
00235 };
00236
00237 class PasswordTLV : public OutTLV {
00238 protected:
00239 string m_password;
00240
00241 void OutputValue(Buffer& b) const;
00242
00243 public:
00244 PasswordTLV(const string& pw);
00245
00246 unsigned short Type() const { return TLV_Password; }
00247 unsigned short Length() const { return m_password.size(); }
00248 };
00249
00250 const unsigned char ALLOWDIRECT_EVERYONE = 0x00;
00251 const unsigned char ALLOWDIRECT_AUTHORIZATION = 0x10;
00252 const unsigned char ALLOWDIRECT_CONTACTLIST = 0x20;
00253
00254 const unsigned char WEBAWARE_NORMAL = 0x02;
00255 const unsigned char WEBAWARE_WEBAWARE = 0x03;
00256
00257 class StatusTLV : public OutTLV, public InTLV {
00258 private:
00259 unsigned char m_allowDirect;
00260 unsigned char m_webAware;
00261 unsigned short m_status;
00262
00263 protected:
00264 void OutputValue(Buffer& b) const;
00265 void ParseValue(Buffer& b);
00266
00267 public:
00268 StatusTLV(unsigned char ad, unsigned char wa, unsigned short st)
00269 : m_allowDirect(ad), m_webAware(wa), m_status(st)
00270 { }
00271 StatusTLV() { }
00272
00273 unsigned short Type() const { return TLV_Status; }
00274 unsigned short Length() const { return 4; }
00275
00276 unsigned char getAllowDirect() { return m_allowDirect; }
00277 unsigned char getWebAware() { return m_webAware; }
00278 unsigned short getStatus() { return m_status; }
00279
00280 void setAllowDirect(unsigned char m) { m_allowDirect = m; }
00281 void setWebAware(unsigned char m) { m_webAware = m; }
00282 void setStatus(unsigned short m) { m_status = m; }
00283 };
00284
00285
00286
00287 class ClientProfileTLV : public StringTLV {
00288 public:
00289 ClientProfileTLV(const string& val) : StringTLV(val) { }
00290 unsigned short Type() const { return TLV_ClientProfile; }
00291 };
00292
00293 class ClientTypeTLV : public ShortTLV {
00294 public:
00295 ClientTypeTLV(unsigned short n) : ShortTLV(n) { }
00296 unsigned short Type() const { return TLV_ClientType; }
00297 };
00298
00299 class ClientVersionMajorTLV : public ShortTLV {
00300 public:
00301 ClientVersionMajorTLV(unsigned short n) : ShortTLV(n) { }
00302 unsigned short Type() const { return TLV_ClientVersionMajor; }
00303 };
00304
00305 class ClientVersionMinorTLV : public ShortTLV {
00306 public:
00307 ClientVersionMinorTLV(unsigned short n) : ShortTLV(n) { }
00308 unsigned short Type() const { return TLV_ClientVersionMinor; }
00309 };
00310
00311 class ClientICQNumberTLV : public ShortTLV {
00312 public:
00313 ClientICQNumberTLV(unsigned short n) : ShortTLV(n) { }
00314 unsigned short Type() const { return TLV_ClientICQNumber; }
00315 };
00316
00317 class ClientBuildMajorTLV : public ShortTLV {
00318 public:
00319 ClientBuildMajorTLV(unsigned short n) : ShortTLV(n) { }
00320 unsigned short Type() const { return TLV_ClientBuildMajor; }
00321 };
00322
00323 class ClientBuildMinorTLV : public LongTLV {
00324 public:
00325 ClientBuildMinorTLV(unsigned int n) : LongTLV(n) { }
00326 unsigned short Type() const { return TLV_ClientBuildMinor; }
00327 };
00328
00329 class CountryCodeTLV : public StringTLV {
00330 public:
00331 CountryCodeTLV(string val) : StringTLV(val) { }
00332 unsigned short Type() const { return TLV_CountryCode; }
00333 };
00334
00335 class LanguageTLV : public StringTLV {
00336 public:
00337 LanguageTLV(const string& val) : StringTLV(val) { }
00338 unsigned short Type() const { return TLV_Language; }
00339 };
00340
00341
00342
00343 class WebAddressTLV : public StringTLV {
00344 public:
00345 WebAddressTLV() { }
00346 unsigned short Type() const { return TLV_WebAddress; }
00347 };
00348
00349 class UserClassTLV : public ShortTLV {
00350 public:
00351 UserClassTLV() { }
00352 unsigned short Type() const { return TLV_UserClass; }
00353 };
00354
00355 class TimeOnlineTLV : public LongTLV {
00356 public:
00357 TimeOnlineTLV() { }
00358 unsigned short Type() const { return TLV_TimeOnline; }
00359 };
00360
00361 class SignupDateTLV : public LongTLV {
00362 public:
00363 SignupDateTLV() { }
00364 unsigned short Type() const { return TLV_SignupDate; }
00365 };
00366
00367 class SignonDateTLV : public LongTLV {
00368 public:
00369 SignonDateTLV() { }
00370 unsigned short Type() const { return TLV_SignonDate; }
00371 };
00372
00373 class UnknownTLV : public ShortTLV {
00374 public:
00375 UnknownTLV() : ShortTLV(0) { }
00376 unsigned short Type() const { return TLV_Unknown; }
00377 };
00378
00379 class IPAddressTLV : public LongTLV {
00380 public:
00381 IPAddressTLV() { }
00382 unsigned short Type() const { return TLV_IPAddress; }
00383 };
00384
00385 class PortTLV : public ShortTLV {
00386 public:
00387 PortTLV() { }
00388 unsigned short Type() const { return TLV_Port; }
00389 };
00390
00391 class UserInfoCapabilitiesTLV : public OutTLV {
00392 private:
00393 Capabilities m_capabilities;
00394
00395 public:
00396 UserInfoCapabilitiesTLV();
00397 unsigned short Type() const { return TLV_UserInfoCapabilities; }
00398 unsigned short Length() const;
00399
00400 void OutputValue(Buffer& b) const;
00401 };
00402
00403 class CapabilitiesTLV : public InTLV {
00404 private:
00405 Capabilities m_capabilities;
00406
00407 public:
00408 CapabilitiesTLV() { }
00409 unsigned short Type() const { return TLV_Capabilities; }
00410 unsigned short Length() const { return m_capabilities.get_length(); }
00411
00412 Capabilities get_capabilities() const;
00413
00414 void ParseValue(Buffer& b);
00415 };
00416
00417 class RedirectTLV : public InTLV {
00418 private:
00419 string m_server;
00420 unsigned short m_port;
00421
00422 public:
00423 RedirectTLV() { }
00424
00425 unsigned short Length() const { return m_server.size(); }
00426 unsigned short Type() const { return TLV_Redirect; }
00427
00428 void ParseValue(Buffer& b);
00429
00430 string getHost() { return m_server; }
00431 unsigned short getPort() { return m_port; }
00432 };
00433
00434 class CookieTLV : public InTLV, public OutTLV {
00435 private:
00436 unsigned char *m_value;
00437 unsigned short m_length;
00438
00439 public:
00440 CookieTLV() : m_value(NULL), m_length(0) { }
00441 CookieTLV(const unsigned char *ck, unsigned short len);
00442 ~CookieTLV();
00443
00444 unsigned short Length() const { return m_length; }
00445 unsigned short Type() const { return TLV_Cookie; }
00446
00447 void ParseValue(Buffer& b);
00448 void OutputValue(Buffer& b) const;
00449
00450 const unsigned char* Value() { return m_value; }
00451 };
00452
00453
00454 class LANDetailsTLV : public InTLV, public OutTLV {
00455 private:
00456 unsigned int m_lan_ip;
00457 unsigned short m_lan_port, m_firewall;
00458 unsigned char m_tcp_version;
00459
00460 public:
00461 LANDetailsTLV();
00462 LANDetailsTLV(unsigned int ip, unsigned short port);
00463
00464 unsigned short Length() const { return 0; }
00465 unsigned short Type() const { return TLV_LANDetails; }
00466
00467 unsigned int getLanIP() const { return m_lan_ip; }
00468 unsigned short getLanPort() const { return m_lan_port; }
00469 unsigned short getFirewall() const { return m_firewall; }
00470 unsigned char getTCPVersion() const { return m_tcp_version; }
00471
00472 void ParseValue(Buffer& b);
00473 void OutputValue(Buffer& b) const;
00474 };
00475
00476 class RawTLV : public InTLV {
00477 protected:
00478 unsigned short m_type;
00479 unsigned short m_length;
00480
00481 public:
00482 RawTLV(unsigned short type);
00483
00484 unsigned short Type() const { return m_type; }
00485 unsigned short Length() const { return m_length; }
00486 void ParseValue(Buffer& b);
00487 };
00488
00489 class MessageTextTLV : public InTLV {
00490 protected:
00491 string m_message;
00492 unsigned short m_flag1, m_flag2;
00493
00494 public:
00495 MessageTextTLV()
00496 : m_message(), m_flag1(0), m_flag2(0) { }
00497
00498 string getMessage() { return m_message; }
00499 unsigned short getFlag1() { return m_flag1; }
00500 unsigned short getFlag2() { return m_flag1; }
00501
00502 void ParseValue(Buffer& b);
00503 unsigned short Type() const { return TLV_MessageText; }
00504 unsigned short Length() const { return 0; }
00505 };
00506
00507 class MessageDataTLV : public InTLV {
00508 MessageTextTLV mttlv;
00509
00510 public:
00511 MessageDataTLV();
00512
00513 string getMessage() { return mttlv.getMessage(); }
00514 unsigned short getFlag1() { return mttlv.getFlag1(); }
00515 unsigned short getFlag2() { return mttlv.getFlag2(); }
00516
00517 void ParseValue(Buffer& b);
00518 unsigned short Type() const { return TLV_MessageData; }
00519 unsigned short Length() const { return 0; }
00520 };
00521
00522 class AdvMsgBodyTLV : public InTLV {
00523 protected:
00524 ICQSubType *m_icqsubtype;
00525
00526 public:
00527 AdvMsgBodyTLV();
00528 ~AdvMsgBodyTLV();
00529
00530 ICQSubType* grabICQSubType();
00531
00532 void ParseValue(Buffer& b);
00533 unsigned short Type() const { return TLV_AdvMsgBody; }
00534 unsigned short Length() const { return 0; }
00535 };
00536
00537 class AdvMsgDataTLV : public InTLV {
00538 ICQSubType *m_icqsubtype;
00539
00540 public:
00541 AdvMsgDataTLV();
00542 ~AdvMsgDataTLV();
00543
00544 ICQSubType* grabICQSubType();
00545
00546 void ParseValue(Buffer& b);
00547 unsigned short Type() const { return TLV_AdvMsgData; }
00548 unsigned short Length() const { return 0; }
00549 };
00550
00551
00552
00553
00554 class ICQDataTLV : public InTLV {
00555 private:
00556 ICQSubType *m_icqsubtype;
00557
00558 public:
00559 ICQDataTLV();
00560 ~ICQDataTLV();
00561
00562 ICQSubType* getICQSubType() const;
00563 ICQSubType* grabICQSubType();
00564
00565 void ParseValue(Buffer& b);
00566 unsigned short Type() const { return TLV_ICQData; }
00567 unsigned short Length() const { return 0; }
00568
00569 };
00570
00571
00572
00573 class TLVList {
00574 private:
00575 map<unsigned short,InTLV*> tlvmap;
00576 public:
00577 TLVList();
00578 ~TLVList();
00579
00580 void Parse(Buffer& b, TLV_ParseMode pm, unsigned short no_tlvs);
00581 bool exists(unsigned short type);
00582 InTLV* & operator[](unsigned short type);
00583
00584 };
00585
00586 }
00587
00588 Buffer& operator<<(Buffer& b, const ICQ2000::OutTLV& t);
00589
00590 #endif