Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

ICQ.h

00001 /*
00002  * ICQ Subtypes
00003  *
00004  * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
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   // ------------- TCP Command Types ------------------
00039 
00040   const unsigned short V6_TCP_START     = 0x07ee;
00041   const unsigned short V6_TCP_ACK       = 0x07da;
00042   
00043 
00044   // ------------- Message Types ----------------------
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_EmailEx = 0x0e;
00053   const unsigned char MSG_Type_SMS     = 0x1a;
00054 
00055   const unsigned char MSG_Type_AutoReq_Away = 0xe8;
00056   const unsigned char MSG_Type_AutoReq_Occ  = 0xe9;
00057   const unsigned char MSG_Type_AutoReq_NA   = 0xea;
00058   const unsigned char MSG_Type_AutoReq_DND  = 0xeb;
00059   const unsigned char MSG_Type_AutoReq_FFC  = 0xec;
00060 
00061   const unsigned char MSG_Flag_AutoReq = 0x03;
00062   const unsigned char MSG_Flag_Multi   = 0x80;
00063 
00064   const unsigned short Priority_Normal        = 0x0001;
00065   const unsigned short Priority_Urgent        = 0x0002;
00066   const unsigned short Priority_ToContactList = 0x0004;
00067 
00068   const unsigned short AcceptStatus_Online     = 0x0000; // accepted
00069   const unsigned short AcceptStatus_Denied     = 0x0001; // not accepted - denied
00070   const unsigned short AcceptStatus_Away       = 0x0004; // accepted in away
00071   const unsigned short AcceptStatus_Occupied   = 0x0009; // not accepted in occupied
00072   const unsigned short AcceptStatus_DND        = 0x000a; // not accepted in DND
00073   const unsigned short AcceptStatus_Occ_Accept = 0x000c; // accepted from a to contact list in occupied
00074   const unsigned short AcceptStatus_NA         = 0x000e; // accepted in NA
00075 
00076 
00077   /* ICQSubtype classes
00078    * An attempt at clearing up the complete
00079    * mess ICQ have made of bundling everything
00080    * into one TLV
00081    */
00082 
00083   class ICQSubType {
00084    protected:
00085     unsigned short m_seqnum;
00086 
00087     unsigned char m_flags;
00088     
00089    public:
00090     ICQSubType();
00091     virtual ~ICQSubType() { }
00092 
00093     static ICQSubType* ParseICQSubType(Buffer& b, bool adv, bool ack);
00094     void Output(Buffer& b) const;
00095 
00096     virtual void ParseBody(Buffer& b) = 0;
00097     virtual void OutputBody(Buffer& b) const = 0;
00098     virtual unsigned short Length() const = 0;
00099 
00100     virtual unsigned char getType() const = 0;
00101     virtual unsigned char getFlags() const { return m_flags; }
00102     virtual void setFlags(unsigned char f) { m_flags = f; }
00103 
00104     unsigned short getSeqNum() const { return m_seqnum; }
00105     void setSeqNum(unsigned short s)  { m_seqnum = s; }
00106   };
00107 
00108   class UINICQSubType : public ICQSubType {
00109    protected:
00110     unsigned int m_source, m_destination;
00111     bool m_advanced, m_ack;
00112     bool m_urgent, m_tocontactlist;
00113     unsigned short m_status;
00114     string m_away_message;
00115 
00116    public:
00117     UINICQSubType();
00118     UINICQSubType(unsigned int s, unsigned int d);
00119 
00120     void setDestination(unsigned int uin);
00121     void setSource(unsigned int uin);
00122     unsigned int getSource() const;
00123     unsigned int getDestination() const;
00124 
00125     unsigned short getStatus() const;
00126     void setStatus(unsigned short s);
00127 
00128     void ParseBody(Buffer& b);
00129     void OutputBody(Buffer& b) const;
00130 
00131     virtual void ParseBodyUIN(Buffer& b) = 0;
00132     virtual void ParseBodyUINACK(Buffer& b);
00133 
00134     virtual void OutputBodyUIN(Buffer& b) const = 0;
00135     virtual void OutputBodyUINACK(Buffer& b) const;
00136 
00137     bool isAdvanced() const;
00138     void setAdvanced(bool b);
00139     void setACK(bool b);
00140     bool isACK() const;
00141     void setUrgent(bool b);
00142     bool isUrgent() const;
00143     void setToContactList(bool b);
00144     bool isToContactList() const;
00145 
00146     void setAwayMessage(const std::string& m);
00147     string getAwayMessage() const;
00148   };
00149 
00150   class NormalICQSubType : public UINICQSubType {
00151    private:
00152     string m_message;
00153     bool m_multi;
00154     unsigned int m_foreground, m_background;
00155     
00156    public:
00157     NormalICQSubType(bool multi);
00158     NormalICQSubType(const string& msg);
00159 
00160     string getMessage() const;
00161     bool isMultiParty() const;
00162     void setMessage(const string& message);
00163     
00164     void setForeground(unsigned int f);
00165     void setBackground(unsigned int f);
00166     unsigned int getForeground() const;
00167     unsigned int getBackground() const;
00168 
00169     void ParseBodyUIN(Buffer& b);
00170     void OutputBodyUIN(Buffer& b) const;
00171     void ParseBodyUINACK(Buffer& b);
00172     void OutputBodyUINACK(Buffer& b) const;
00173 
00174     unsigned short Length() const;
00175     unsigned char getType() const;
00176   };
00177 
00178   class URLICQSubType : public UINICQSubType {
00179    private:
00180     string m_message;
00181     string m_url;
00182     
00183    public:
00184     URLICQSubType();
00185     URLICQSubType(const string& msg, const string& url);
00186 
00187     string getMessage() const;
00188     void setMessage(const string& msg);
00189     string getURL() const;
00190     void setURL(const string& url);
00191     
00192     void ParseBodyUIN(Buffer& b);
00193     void OutputBodyUIN(Buffer& b) const;
00194     unsigned short Length() const;
00195     unsigned char getType() const;
00196   };
00197 
00198   class AwayMsgSubType : public UINICQSubType {
00199    private:
00200     unsigned char m_type;
00201     string m_message;
00202 
00203    public:
00204     AwayMsgSubType(Status s);
00205     AwayMsgSubType(unsigned char m_type);
00206 
00207     void ParseBodyUIN(Buffer& b);
00208     void OutputBodyUIN(Buffer& b) const;
00209 
00210     unsigned short Length() const;
00211     unsigned char getType() const;
00212     unsigned char getFlags() const;
00213   };
00214 
00215   class SMSICQSubType : public ICQSubType {
00216    public:
00217     enum Type {
00218       SMS,
00219       SMS_Receipt
00220     };
00221 
00222    private:
00223     // SMS fields
00224     string m_source, m_sender, m_senders_network, m_time;
00225 
00226     // SMS Receipt fields
00227     string m_message_id, m_destination, m_submission_time, m_delivery_time;
00228     bool m_delivered;
00229 
00230     string m_message;
00231     Type m_type;
00232 
00233    public:
00234     SMSICQSubType();
00235 
00236     string getMessage() const;
00237     Type getSMSType() const;
00238 
00239     void ParseBody(Buffer& b);
00240     void OutputBody(Buffer& b) const;
00241     unsigned short Length() const;
00242     unsigned char getType() const;
00243 
00244     // -- SMS fields --
00245     string getSource() const { return m_source; }
00246     string getSender() const { return m_sender; }
00247     string getSenders_network() const { return m_senders_network; }
00248     string getTime() const { return m_time; }
00249 
00250     // -- SMS Receipt fields --
00251     string getMessageId() const { return m_message_id; }
00252     string getDestination() const { return m_destination; }
00253     string getSubmissionTime() const { return m_submission_time; }
00254     string getDeliveryTime() const { return m_delivery_time; }
00255     bool delivered() const { return m_delivered; }
00256 
00257   };
00258 
00259   class AuthReqICQSubType : public UINICQSubType {
00260    private:
00261     std::string m_alias, m_firstname, m_lastname, m_email, m_message;
00262     bool m_auth;
00263 
00264    public:
00265     AuthReqICQSubType();
00266     AuthReqICQSubType(const string& alias, const string& firstname,
00267                       const string& lastname, const string& email, bool auth,
00268                       const string& msg);
00269 
00270     std::string getMessage() const;
00271 
00272     void ParseBodyUIN(Buffer& b);
00273     void OutputBodyUIN(Buffer& b) const;
00274     unsigned short Length() const;
00275     unsigned char getType() const;
00276 
00277   };
00278   
00279   class AuthAccICQSubType : public UINICQSubType {
00280    public:
00281     AuthAccICQSubType();
00282 
00283     void ParseBodyUIN(Buffer& b);
00284     void OutputBodyUIN(Buffer& b) const;
00285     unsigned short Length() const;
00286     unsigned char getType() const;
00287 
00288   };
00289   
00290   class AuthRejICQSubType : public UINICQSubType {
00291    private:
00292     string m_message;
00293 
00294    public:
00295     AuthRejICQSubType();
00296     AuthRejICQSubType(const string& msg);
00297 
00298     string getMessage() const;
00299     void setMessage(const string& msg);
00300 
00301     void ParseBodyUIN(Buffer& b);
00302     void OutputBodyUIN(Buffer& b) const;
00303     unsigned short Length() const;
00304     unsigned char getType() const;
00305 
00306   };
00307 
00308   class EmailExICQSubType : public ICQSubType {
00309    private:
00310     string m_message, m_email, m_sender;
00311 
00312    public:
00313     EmailExICQSubType();
00314 
00315     void ParseBody(Buffer& b);
00316     void OutputBody(Buffer& b) const;
00317     unsigned short Length() const;
00318     unsigned char getType() const;
00319 
00320     string getMessage() const;
00321     string getEmail() const;
00322     string getSender() const;
00323   };
00324 
00325   class UserAddICQSubType : public UINICQSubType {
00326    private:
00327     std::string m_alias, m_firstname, m_lastname, m_email;
00328     bool m_auth;
00329 
00330    public:
00331     UserAddICQSubType();
00332     UserAddICQSubType(const std::string& alias, const std::string& firstname,
00333                       const std::string& lastname, const std::string& email, bool auth);
00334 
00335     void ParseBodyUIN(Buffer& b);
00336     void OutputBodyUIN(Buffer& b) const;
00337     unsigned short Length() const;
00338     unsigned char getType() const;
00339   };
00340 
00341   void string_split(const std::string& in, const std::string& sep,
00342                     int count, std::list<std::string>& fields);
00343 }
00344 
00345 #endif

Generated on Fri Apr 26 23:48:14 2002 for libicq2000 by doxygen1.2.15