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

Generated on Sun Jul 21 10:57:32 2002 for libicq2000 by doxygen1.2.16