Main Page   Namespace List   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 
00027 #include <sigc++/signal_system.h>
00028 
00029 #include <stdlib.h>
00030 
00031 #include <libicq2000/socket.h>
00032 #include <libicq2000/buffer.h>
00033 #include <libicq2000/events.h>
00034 #include <libicq2000/exceptions.h>
00035 #include <libicq2000/Contact.h>
00036 #include <libicq2000/ContactList.h>
00037 #include <libicq2000/SeqNumCache.h>
00038 #include <libicq2000/Translator.h>
00039 #include <libicq2000/SocketClient.h>
00040 #include <libicq2000/MessageHandler.h>
00041 
00042 namespace ICQ2000 {
00043 
00044   class UINICQSubType;
00045   
00046   class DirectClient : public SocketClient {
00047    private:
00048     enum State { NOT_CONNECTED,
00049                  WAITING_FOR_INIT,
00050                  WAITING_FOR_INIT_ACK,
00051                  WAITING_FOR_INIT2,
00052                  CONNECTED };
00053 
00054     State m_state;
00055 
00056     Buffer m_recv;
00057 
00058     ContactRef m_self_contact;
00059     ContactRef m_contact;
00060     ContactList *m_contact_list;
00061     MessageHandler *m_message_handler;
00062 
00063     bool m_incoming;
00064 
00065     unsigned short m_remote_tcp_version;
00066     unsigned int m_remote_uin;
00067     unsigned char m_tcp_flags;
00068     unsigned short m_eff_tcp_version;
00069 
00070     unsigned int m_local_ext_ip, m_session_id;
00071     unsigned short m_local_server_port;
00072 
00073     void Parse();
00074     void ParseInitPacket(Buffer &b);
00075     void ParseInitAck(Buffer &b);
00076     void ParseInit2(Buffer &b);
00077     void ParsePacket(Buffer& b);
00078     void ParsePacketInt(Buffer& b);
00079 
00080     void SendInitAck();
00081     void SendInitPacket();
00082     void SendInit2();
00083     void SendPacketEvent(MessageEvent *ev);
00084     void SendPacketAck(ICQSubType *i);
00085     void Send(Buffer &b);
00086     
00087     bool Decrypt(Buffer& in, Buffer& out);
00088     void Encrypt(Buffer& in, Buffer& out);
00089     static unsigned char client_check_data[];
00090     Translator *m_translator;
00091     SeqNumCache m_msgcache;
00092     std::list<MessageEvent*> m_msgqueue;
00093     unsigned short m_seqnum;
00094 
00095     unsigned short NextSeqNum();
00096     void ConfirmUIN();
00097 
00098     void expired_cb(MessageEvent *ev);
00099     void flush_queue();
00100 
00101     void Init();
00102 
00103    public:
00104     DirectClient(ContactRef self, TCPSocket *sock, MessageHandler *mh, ContactList *cl, unsigned int ext_ip,
00105                  unsigned short server_port, Translator* translator);
00106     DirectClient(ContactRef self, ContactRef c, MessageHandler *mh, unsigned int ext_ip,
00107                  unsigned short server_port, Translator *translator);
00108     ~DirectClient();
00109 
00110     void Connect();
00111     void FinishNonBlockingConnect();
00112     void Recv();
00113 
00114     unsigned int getUIN() const;
00115     unsigned int getIP() const;
00116     unsigned short getPort() const;
00117     int getfd() const;
00118     TCPSocket* getSocket() const;
00119     void clearoutMessagesPoll();
00120 
00121     void setContact(ContactRef c);
00122     ContactRef getContact() const;
00123     void SendEvent(MessageEvent* ev);
00124   };
00125 
00126 }
00127 
00128 #endif

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