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

Client.h

00001 
00022 #ifndef CLIENT_H
00023 #define CLIENT_H
00024 
00025 #include <iostream>
00026 #include <string>
00027 
00028 #include <map>
00029 
00030 #include <sigc++/signal_system.h>
00031 
00032 #include <time.h>
00033 
00034 #include <libicq2000/buffer.h>
00035 #include <libicq2000/socket.h>
00036 #include <libicq2000/events.h>
00037 #include <libicq2000/constants.h>
00038 #include <libicq2000/Contact.h>
00039 #include <libicq2000/ContactList.h>
00040 #include <libicq2000/custom_marshal.h>
00041 #include <libicq2000/Translator.h>
00042 #include <libicq2000/RequestIDCache.h>
00043 #include <libicq2000/ICBMCookieCache.h>
00044 #include <libicq2000/DirectClient.h>
00045 #include <libicq2000/DCCache.h>
00046 #include <libicq2000/SMTPClient.h>
00047 #include <libicq2000/userinfoconstants.h>
00048 #include <libicq2000/MessageHandler.h>
00049 
00050 using std::string;
00051 
00052 namespace ICQ2000 {
00053   
00054   // declare some SNAC classes - vastly decreases header dependancies
00055   class MessageSNAC;
00056   class MessageACKSNAC;
00057   class MessageOfflineUserSNAC;
00058   class SrvResponseSNAC;
00059   class UINResponseSNAC;
00060   class RateInfoChangeSNAC;
00061   class BuddyOnlineSNAC;
00062   class BuddyOfflineSNAC;
00063   class UserInfoSNAC;
00064   class OutSNAC;
00065 
00071   class Client : public SigC::Object {
00072    private:
00073     enum State { NOT_CONNECTED,
00074                  AUTH_AWAITING_CONN_ACK,
00075                  AUTH_AWAITING_AUTH_REPLY,
00076                  BOS_AWAITING_CONN_ACK,
00077                  BOS_AWAITING_LOGIN_REPLY,
00078                  BOS_LOGGED_IN,
00079                  UIN_AWAITING_CONN_ACK,
00080                  UIN_AWAITING_UIN_REPLY
00081     } m_state;
00082 
00083     ContactRef m_self;
00084     string m_password;
00085     Status m_status_wanted;
00086     bool m_invisible_wanted;
00087 
00088     string m_authorizerHostname;
00089     unsigned short m_authorizerPort;
00090 
00091     string m_bosHostname;
00092     unsigned short m_bosPort;
00093     bool m_bosOverridePort;
00094 
00095     bool m_in_dc, m_out_dc;
00096 
00097     unsigned short m_client_seq_num;
00098     unsigned int m_requestid;
00099     
00100     Translator m_translator;
00101 
00102     ContactList m_contact_list;
00103     
00104     ContactList m_visible_list;
00105     ContactList m_invisible_list;
00106 
00107     MessageHandler m_message_handler;
00108 
00109     unsigned char *m_cookie_data;
00110     unsigned short m_cookie_length;
00111 
00112     unsigned int m_ext_ip;
00113     TCPSocket m_serverSocket;
00114     TCPServer m_listenServer;
00115 
00116     SMTPClient m_smtp;
00117 
00118     DCCache m_dccache;
00119 
00120     time_t m_last_server_ping;
00121 
00122     RequestIDCache m_reqidcache;
00123     ICBMCookieCache m_cookiecache;
00124 
00125     Buffer m_recv;
00126    
00127     void Init();
00128     unsigned short NextSeqNum();
00129     unsigned int NextRequestID();
00130 
00131     void ConnectAuthorizer(State state);
00132     void DisconnectAuthorizer();
00133     void ConnectBOS();
00134     void DisconnectBOS();
00135 
00136     // -- Ping server --
00137     void PingServer();
00138 
00139     DirectClient* ConnectDirect(const ContactRef& c);
00140     void DisconnectDirectConns();
00141     void DisconnectDirectConn(int fd);
00142 
00143     // ------------------ Signal dispatchers -----------------
00144     void SignalConnect();
00145     void SignalDisconnect(DisconnectedEvent::Reason r);
00146     void SignalMessage(MessageSNAC *snac);
00147     void SignalMessageACK(MessageACKSNAC *snac);
00148     void SignalMessageOfflineUser(MessageOfflineUserSNAC *snac);
00149     void SignalSrvResponse(SrvResponseSNAC *snac);
00150     void SignalUINResponse(UINResponseSNAC *snac);
00151     void SignalUINRequestError();
00152     void SignalRateInfoChange(RateInfoChangeSNAC *snac);
00153     void SignalLog(LogEvent::LogType type, const string& msg);
00154     void SignalUserOnline(BuddyOnlineSNAC *snac);
00155     void SignalUserOffline(BuddyOfflineSNAC *snac);
00156     void SignalServerBasedContactList(const ContactList& l);
00157     void SignalAddSocket(int fd, SocketEvent::Mode m);
00158     void SignalRemoveSocket(int fd);
00159     // ------------------ Outgoing packets -------------------
00160 
00161     // -------------- Callbacks from ContactList -------------
00162     void contactlist_cb(ContactListEvent *ev);
00163 
00164     // ------- Callbacks from visible, invisible lists -------
00165     void visiblelist_cb(ContactListEvent *ev);
00166     void invisiblelist_cb(ContactListEvent *ev);
00167 
00168     // -------------- Callbacks from Contacts ----------------
00169 
00170     void SendAuthReq();
00171     void SendNewUINReq();
00172     void SendCookie();
00173     void SendCapabilities();
00174     void SendRateInfoRequest();
00175     void SendRateInfoAck();
00176     void SendPersonalInfoRequest();
00177     void SendAddICBMParameter();
00178     void SendSetUserInfo();
00179     void SendLogin();
00180     void SendOfflineMessagesRequest();
00181     void SendOfflineMessagesACK();
00182 
00183     void SendAdvancedACK(MessageSNAC *snac);
00184 
00185     void Send(Buffer& b);
00186 
00187     void HandleUserInfoSNAC(UserInfoSNAC *snac);
00188 
00189     Buffer::marker FLAPHeader(Buffer& b, unsigned char channel);
00190     void FLAPFooter(Buffer& b, Buffer::marker& mk);
00191 
00192     void FLAPwrapSNAC(Buffer& b, const OutSNAC& snac);
00193     void FLAPwrapSNACandSend(const OutSNAC& snac);
00194 
00195     // ------------------ Incoming packets -------------------
00196 
00201     void RecvFromServer();
00202 
00203     void Parse();
00204     void ParseCh1(Buffer& b, unsigned short seq_num);
00205     void ParseCh2(Buffer& b, unsigned short seq_num);
00206     void ParseCh3(Buffer& b, unsigned short seq_num);
00207     void ParseCh4(Buffer& b, unsigned short seq_num);
00208 
00209     // -------------------------------------------------------
00210 
00211     ContactRef lookupICQ(unsigned int uin);
00212     ContactRef lookupMobile(const string& m);
00213     ContactRef lookupEmail(const string& email);
00214 
00215     ContactRef getUserInfoCacheContact(unsigned int reqid);
00216 
00217     void ICBMCookieCache_expired_cb(MessageEvent *ev);
00218     void dccache_expired_cb(DirectClient *dc);
00219     void reqidcache_expired_cb( RequestIDCacheValue *v );
00220     void dc_connected_cb(DirectClient *dc);
00221     void dc_log_cb(LogEvent *ev);
00222     void dc_socket_cb(SocketEvent *ev);
00223     void dc_messageack_cb(MessageEvent *ev);
00224 
00225     bool SendDirect(MessageEvent *ev);
00226 
00227     void SendViaServer(MessageEvent *ev);
00228     void SendViaServerAdvanced(MessageEvent *ev);
00229     void SendViaServerNormal(MessageEvent *ev);
00230     
00231     void Disconnect(DisconnectedEvent::Reason r = DisconnectedEvent::REQUESTED);
00232 
00233    public:
00234     Client();
00235     Client(const unsigned int uin, const string& password);
00236     ~Client();
00237    
00238     void setUIN(unsigned int uin);
00239     unsigned int getUIN() const;
00240     void setPassword(const string& password);
00241     string getPassword() const;
00242 
00243     ContactRef getSelfContact();
00244 
00245     bool setTranslationMap(const string& szMapFileName);
00246     const string& getTranslationMapFileName() const;
00247     const string& getTranslationMapName() const;
00248     bool usingDefaultMap() const;
00249 
00250     // -- Signals --
00256     SigC::Signal1<void,ConnectedEvent*> connected;
00257 
00271     SigC::Signal1<void,DisconnectedEvent*> disconnected;
00272 
00278     SigC::Signal1<void,MessageEvent*> messaged;
00279 
00288     SigC::Signal1<void,MessageEvent*> messageack;
00289 
00294     SigC::Signal1<void,ContactListEvent*> contactlist;
00295 
00300     SigC::Signal1<void,UserInfoChangeEvent*> contact_userinfo_change_signal;
00301 
00306     SigC::Signal1<void,StatusChangeEvent*> contact_status_change_signal;
00307 
00313     SigC::Signal1<void,NewUINEvent*> newuin;
00314 
00320     SigC::Signal1<void,RateInfoChangeEvent*> rate;
00321 
00330     SigC::Signal1<void,LogEvent*> logger;
00331 
00341     SigC::Signal1<void,SocketEvent*> socket;
00342 
00347     SigC::Signal1<void,UserInfoChangeEvent*> self_contact_userinfo_change_signal;
00348 
00353     SigC::Signal1<void,StatusChangeEvent*> self_contact_status_change_signal;
00354 
00361     SigC::Signal1<void,ICQMessageEvent*> want_auto_resp;
00362 
00369     SigC::Signal1<void,SearchResultEvent*> search_result;
00370     
00371     SigC::Signal1<void,ServerBasedContactEvent*> server_based_contact_list;
00372     
00373     // -------------
00374 
00375     // -- Send calls --
00376     void SendEvent(MessageEvent *ev);
00377 
00378     // -- Set Status --
00379     void setStatus(const Status st);
00380     void setStatus(const Status st, bool inv);
00381     void setInvisible(bool inv);
00382     
00383     Status getStatus() const;
00384     bool getInvisible() const;
00385 
00386     void uploadSelfDetails();
00387     
00388     // -- Contact List --
00389     void addContact(ContactRef c);
00390     void removeContact(const unsigned int uin);
00391     void addVisible(ContactRef c);
00392     void removeVisible(const unsigned int uin);
00393     void addInvisible(ContactRef c);
00394     void removeInvisible(const unsigned int uin);
00395     ContactRef getContact(const unsigned int uin);
00396 
00397     ContactList& getContactList();
00398 
00399     void fetchSimpleContactInfo(ContactRef c);
00400     void fetchDetailContactInfo(ContactRef c);
00401     void fetchServerBasedContactList();
00402     void fetchSelfSimpleContactInfo();
00403     void fetchSelfDetailContactInfo();
00404 
00405     // -- Whitepage searches --
00406     SearchResultEvent* searchForContacts(const string& nickname, const string& firstname,
00407                                          const string& lastname);
00408 
00409     SearchResultEvent* searchForContacts(const string& nickname, const string& firstname,
00410                                          const string& lastname, const string& email,
00411                                          AgeRange age, Sex sex, unsigned char language, const string& city,
00412                                          const string& state, unsigned short country,
00413                                          const string& company_name, const string& department,
00414                                          const string& position, bool only_online);
00415 
00416     SearchResultEvent* searchForContacts(unsigned int uin);
00417 
00418     SearchResultEvent* searchForContacts(const std::string& keyword);
00419 
00420     /*
00421      *  Poll must be called regularly (at least every 60 seconds)
00422      *  but I recommended 5 seconds, so timeouts work with good
00423      *  granularity.
00424      *  It is not related to the socket callback - the client using
00425      *  this library must select() on the sockets it gets signalled
00426      *  and call socket_cb when select returns a status flag on one
00427      *  of the sockets. ickle simply uses the gtk-- built in signal handlers
00428      *  to do all this.
00429      */
00430 
00431     // -- Network settings --
00432     void setLoginServerHost(const string& host);
00433     string getLoginServerHost() const;
00434 
00435     void setLoginServerPort(const unsigned short& port);
00436     unsigned short getLoginServerPort() const;
00437 
00438     void setBOSServerOverridePort(const bool& b);
00439     bool getBOSServerOverridePort() const;
00440 
00441     void setBOSServerPort(const unsigned short& port);
00442     unsigned short getBOSServerPort() const;
00443 
00444     void setSMTPServerHost(const string& host);
00445     string getSMTPServerHost() const;
00446 
00447     void setSMTPServerPort(unsigned short port);
00448     unsigned short getSMTPServerPort() const;
00449 
00450     void setAcceptInDC(bool d);
00451     bool getAcceptInDC() const;
00452 
00453     void setUseOutDC(bool d);
00454     bool getUseOutDC() const;
00455 
00456     void Poll();
00457     void socket_cb(int fd, SocketEvent::Mode m);
00458 
00459     void RegisterUIN();
00460 
00461     /* isConnected() is a convenience for the
00462      * client, it should correspond exactly to ConnectedEvents
00463      * & DisconnectedEvents the client gets
00464      */
00465     bool isConnected() const;
00466     
00467   };
00468 }
00469 
00470 #endif

Generated on Tue Apr 16 22:12:38 2002 for libicq2000 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002