00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 #include <libicq2000/SocketClient.h>
00041 #include <libicq2000/MessageHandler.h>
00042
00043 using std::string;
00044 using std::list;
00045 using std::exception;
00046 using SigC::Signal0;
00047 using SigC::Signal1;
00048
00049 namespace ICQ2000 {
00050
00051 class UINICQSubType;
00052
00053 class DirectClient : public SocketClient {
00054 private:
00055 enum State { NOT_CONNECTED,
00056 WAITING_FOR_INIT,
00057 WAITING_FOR_INIT_ACK,
00058 WAITING_FOR_INIT2,
00059 CONNECTED };
00060
00061 State m_state;
00062
00063 Buffer m_recv;
00064
00065 ContactRef m_self_contact;
00066 ContactRef m_contact;
00067 ContactList *m_contact_list;
00068 MessageHandler *m_message_handler;
00069
00070 bool m_incoming;
00071
00072 unsigned short m_remote_tcp_version;
00073 unsigned int m_remote_uin;
00074 unsigned char m_tcp_flags;
00075 unsigned short m_eff_tcp_version;
00076
00077 unsigned int m_local_ext_ip, m_session_id;
00078 unsigned short m_local_server_port;
00079
00080 void Parse();
00081 void ParseInitPacket(Buffer &b);
00082 void ParseInitAck(Buffer &b);
00083 void ParseInit2(Buffer &b);
00084 void ParsePacket(Buffer& b);
00085 void ParsePacketInt(Buffer& b);
00086
00087 void SendInitAck();
00088 void SendInitPacket();
00089 void SendInit2();
00090 void SendPacketEvent(MessageEvent *ev);
00091 void SendPacketAck(ICQSubType *i);
00092 void Send(Buffer &b);
00093
00094 bool Decrypt(Buffer& in, Buffer& out);
00095 void Encrypt(Buffer& in, Buffer& out);
00096 static unsigned char client_check_data[];
00097 Translator *m_translator;
00098 SeqNumCache m_msgcache;
00099 list<MessageEvent*> m_msgqueue;
00100 unsigned short m_seqnum;
00101
00102 unsigned short NextSeqNum();
00103 void ConfirmUIN();
00104
00105 void expired_cb(MessageEvent *ev);
00106 void flush_queue();
00107
00108 void Init();
00109
00110 public:
00111 DirectClient(ContactRef self, TCPSocket *sock, MessageHandler *mh, ContactList *cl, unsigned int ext_ip,
00112 unsigned short server_port, Translator* translator);
00113 DirectClient(ContactRef self, ContactRef c, MessageHandler *mh, unsigned int ext_ip,
00114 unsigned short server_port, Translator *translator);
00115 ~DirectClient();
00116
00117 void Connect();
00118 void FinishNonBlockingConnect();
00119 void Recv();
00120
00121 unsigned int getUIN() const;
00122 unsigned int getIP() const;
00123 unsigned short getPort() const;
00124 int getfd() const;
00125 TCPSocket* getSocket() const;
00126 void clearoutMessagesPoll();
00127
00128 void setContact(ContactRef c);
00129 ContactRef getContact() const;
00130 void SendEvent(MessageEvent* ev);
00131 };
00132
00133 }
00134
00135 #endif