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

DirectClient.h

00001 /*
00002  * DirectClient
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 DIRECTCLIENT_H
00023 #define DIRECTCLIENT_H
00024 
00025 #include <list>
00026 #include <string>
00027 
00028 #include <sigc++/signal_system.h>
00029 
00030 #include <stdlib.h>
00031 
00032 #include <libicq2000/socket.h>
00033 #include <libicq2000/buffer.h>
00034 #include <libicq2000/events.h>
00035 #include <libicq2000/exceptions.h>
00036 #include <libicq2000/Contact.h>
00037 #include <libicq2000/ContactList.h>
00038 #include <libicq2000/SeqNumCache.h>
00039 #include <libicq2000/Translator.h>
00040 
00041 using std::string;
00042 using std::list;
00043 using std::exception;
00044 using SigC::Signal0;
00045 using SigC::Signal1;
00046 
00047 namespace ICQ2000 {
00048 
00049   class UINICQSubType;
00050   
00051   class DirectClient : public SigC::Object {
00052    private:
00053     enum State { NOT_CONNECTED,
00054                  WAITING_FOR_INIT,
00055                  WAITING_FOR_INIT_ACK,
00056                  WAITING_FOR_INIT2,
00057                  CONNECTED };
00058 
00059     State m_state;
00060 
00061     TCPSocket *m_socket;
00062     Buffer m_recv;
00063 
00064     Contact *m_contact;
00065     ContactList *m_contact_list;
00066 
00067     bool m_incoming;
00068 
00069     unsigned short m_remote_tcp_version;
00070     unsigned int m_remote_uin;
00071     unsigned char m_tcp_flags;
00072     unsigned short m_eff_tcp_version;
00073 
00074     unsigned int m_local_uin, m_local_ext_ip, m_session_id;
00075     unsigned short m_local_server_port;
00076 
00077     void Parse();
00078     void ParseInitPacket(Buffer &b);
00079     void ParseInitAck(Buffer &b);
00080     void ParseInit2(Buffer &b);
00081     void ParsePacket(Buffer& b);
00082     void ParsePacketInt(Buffer& b);
00083 
00084     void SendInitAck();
00085     void SendInitPacket();
00086     void SendInit2();
00087     void SendPacketEvent(MessageEvent *ev);
00088     void SendPacketAck(UINICQSubType *i);
00089     void Send(Buffer &b);
00090     
00091     bool Decrypt(Buffer& in, Buffer& out);
00092     void Encrypt(Buffer& in, Buffer& out);
00093     static unsigned char client_check_data[];
00094     Translator *m_translator;
00095     SeqNumCache m_msgcache;
00096     list<MessageEvent*> m_msgqueue;
00097     unsigned short m_seqnum;
00098 
00099     unsigned short NextSeqNum();
00100     void ConfirmUIN();
00101 
00102     void expired_cb(MessageEvent *ev);
00103     void flush_queue();
00104 
00105     void Init();
00106 
00107     void SignalAddSocket(int fd, SocketEvent::Mode m);
00108     void SignalRemoveSocket(int fd);
00109 
00110    public:
00111     DirectClient(TCPSocket *sock, ContactList *cl, unsigned int uin, unsigned int ext_ip, unsigned short server_port, Translator* translator);
00112     DirectClient(Contact *c, unsigned int uin, unsigned int ext_ip, unsigned short server_port, Translator *translator);
00113     ~DirectClient();
00114 
00115     void Connect();
00116     void FinishNonBlockingConnect();
00117     void Recv();
00118 
00119     // ------------------ Signal dispatchers -----------------
00120     void SignalLog(LogEvent::LogType type, const string& msg);
00121     void SignalMessageEvent(MessageEvent *ev);
00122     // ------------------  Signals ---------------------------
00123     Signal1<void,LogEvent*> logger;
00124     Signal1<void,MessageEvent*> messaged;
00125     Signal1<void,MessageEvent*> messageack;
00126     Signal1<void,SocketEvent*> socket;
00127     Signal0<void> connected;
00128     Signal1<void,AwayMessageEvent*> want_auto_resp;
00129 
00130     unsigned int getUIN() const;
00131     unsigned int getIP() const;
00132     unsigned short getPort() const;
00133     int getfd() const;
00134     TCPSocket* getSocket() const;
00135     void clearoutMessagesPoll();
00136 
00137     void setContact(Contact* c);
00138     Contact* getContact() const;
00139     void SendEvent(MessageEvent* ev);
00140   };
00141 
00142   class DirectClientException : public exception {
00143    private:
00144     string m_errortext;
00145     
00146    public:
00147     DirectClientException();
00148     DirectClientException(const string& text);
00149     ~DirectClientException() throw() { }
00150 
00151     const char* what() const throw();
00152   };
00153   
00154   class DisconnectedException : public DirectClientException {
00155    public:
00156     DisconnectedException(const string& text);
00157   };
00158 
00159 }
00160 
00161 #endif

Generated on Tue Jan 15 12:24:35 2002 for libicq2000 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001