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     bool m_use_portrange;
00114     unsigned short m_upper_port, m_lower_port;
00115     TCPSocket m_serverSocket;
00116     TCPServer m_listenServer;
00117 
00118     SMTPClient m_smtp;
00119 
00120     DCCache m_dccache;
00121 
00122     time_t m_last_server_ping;
00123 
00124     RequestIDCache m_reqidcache;
00125     ICBMCookieCache m_cookiecache;
00126 
00127     Buffer m_recv;
00128    
00129     void Init();
00130     unsigned short NextSeqNum();
00131     unsigned int NextRequestID();
00132 
00133     void ConnectAuthorizer(State state);
00134     void DisconnectAuthorizer();
00135     void ConnectBOS();
00136     void DisconnectBOS();
00137 
00138     // -- Ping server --
00139     void PingServer();
00140 
00141     DirectClient* ConnectDirect(const ContactRef& c);
00142     void DisconnectDirectConns();
00143     void DisconnectDirectConn(int fd);
00144 
00145     // ------------------ Signal dispatchers -----------------
00146     void SignalConnect();
00147     void SignalDisconnect(DisconnectedEvent::Reason r);
00148     void SignalMessage(MessageSNAC *snac);
00149     void SignalMessageACK(MessageACKSNAC *snac);
00150     void SignalMessageOfflineUser(MessageOfflineUserSNAC *snac);
00151     void SignalSrvResponse(SrvResponseSNAC *snac);
00152     void SignalUINResponse(UINResponseSNAC *snac);
00153     void SignalUINRequestError();
00154     void SignalRateInfoChange(RateInfoChangeSNAC *snac);
00155     void SignalLog(LogEvent::LogType type, const string& msg);
00156     void SignalUserOnline(BuddyOnlineSNAC *snac);
00157     void SignalUserOffline(BuddyOfflineSNAC *snac);
00158     void SignalServerBasedContactList(const ContactList& l);
00159     void SignalAddSocket(int fd, SocketEvent::Mode m);
00160     void SignalRemoveSocket(int fd);
00161     // ------------------ Outgoing packets -------------------
00162 
00163     // -------------- Callbacks from ContactList -------------
00164     void contactlist_cb(ContactListEvent *ev);
00165 
00166     // ------- Callbacks from visible, invisible lists -------
00167     void visiblelist_cb(ContactListEvent *ev);
00168     void invisiblelist_cb(ContactListEvent *ev);
00169 
00170     // -------------- Callbacks from Contacts ----------------
00171 
00172     void SendAuthReq();
00173     void SendNewUINReq();
00174     void SendCookie();
00175     void SendCapabilities();
00176     void SendRateInfoRequest();
00177     void SendRateInfoAck();
00178     void SendPersonalInfoRequest();
00179     void SendAddICBMParameter();
00180     void SendSetUserInfo();
00181     void SendLogin();
00182     void SendOfflineMessagesRequest();
00183     void SendOfflineMessagesACK();
00184 
00185     void SendAdvancedACK(MessageSNAC *snac);
00186 
00187     void Send(Buffer& b);
00188 
00189     void HandleUserInfoSNAC(UserInfoSNAC *snac);
00190 
00191     Buffer::marker FLAPHeader(Buffer& b, unsigned char channel);
00192     void FLAPFooter(Buffer& b, Buffer::marker& mk);
00193 
00194     void FLAPwrapSNAC(Buffer& b, const OutSNAC& snac);
00195     void FLAPwrapSNACandSend(const OutSNAC& snac);
00196 
00197     // ------------------ Incoming packets -------------------
00198 
00203     void RecvFromServer();
00204 
00205     void Parse();
00206     void ParseCh1(Buffer& b, unsigned short seq_num);
00207     void ParseCh2(Buffer& b, unsigned short seq_num);
00208     void ParseCh3(Buffer& b, unsigned short seq_num);
00209     void ParseCh4(Buffer& b, unsigned short seq_num);
00210 
00211     // -------------------------------------------------------
00212 
00213     ContactRef getUserInfoCacheContact(unsigned int reqid);
00214 
00215     void ICBMCookieCache_expired_cb(MessageEvent *ev);
00216     void dccache_expired_cb(DirectClient *dc);
00217     void reqidcache_expired_cb( RequestIDCacheValue *v );
00218     void dc_connected_cb(DirectClient *dc);
00219     void dc_log_cb(LogEvent *ev);
00220     void dc_socket_cb(SocketEvent *ev);
00221     void dc_messageack_cb(MessageEvent *ev);
00222 
00223     bool SendDirect(MessageEvent *ev);
00224 
00225     void SendViaServer(MessageEvent *ev);
00226     void SendViaServerAdvanced(MessageEvent *ev);
00227     void SendViaServerNormal(MessageEvent *ev);
00228     
00229     void Disconnect(DisconnectedEvent::Reason r = DisconnectedEvent::REQUESTED);
00230 
00231    public:
00232     Client();
00233     Client(const unsigned int uin, const string& password);
00234     ~Client();
00235    
00236     void setUIN(unsigned int uin);
00237     unsigned int getUIN() const;
00238     void setPassword(const string& password);
00239     string getPassword() const;
00240 
00241     ContactRef getSelfContact();
00242 
00243     bool setTranslationMap(const string& szMapFileName);
00244     const string& getTranslationMapFileName() const;
00245     const string& getTranslationMapName() const;
00246     bool usingDefaultMap() const;
00247 
00248     // -- Signals --
00254     SigC::Signal1<void,ConnectedEvent*> connected;
00255 
00269     SigC::Signal1<void,DisconnectedEvent*> disconnected;
00270 
00276     SigC::Signal1<void,MessageEvent*> messaged;
00277 
00286     SigC::Signal1<void,MessageEvent*> messageack;
00287 
00292     SigC::Signal1<void,ContactListEvent*> contactlist;
00293 
00298     SigC::Signal1<void,UserInfoChangeEvent*> contact_userinfo_change_signal;
00299 
00304     SigC::Signal1<void,StatusChangeEvent*> contact_status_change_signal;
00305 
00311     SigC::Signal1<void,NewUINEvent*> newuin;
00312 
00318     SigC::Signal1<void,RateInfoChangeEvent*> rate;
00319 
00328     SigC::Signal1<void,LogEvent*> logger;
00329 
00339     SigC::Signal1<void,SocketEvent*> socket;
00340 
00345     SigC::Signal1<void,UserInfoChangeEvent*> self_contact_userinfo_change_signal;
00346 
00351     SigC::Signal1<void,StatusChangeEvent*> self_contact_status_change_signal;
00352 
00359     SigC::Signal1<void,ICQMessageEvent*> want_auto_resp;
00360 
00367     SigC::Signal1<void,SearchResultEvent*> search_result;
00368     
00369     SigC::Signal1<void,ServerBasedContactEvent*> server_based_contact_list;
00370     
00371     // -------------
00372 
00373     // -- Send calls --
00374     void SendEvent(MessageEvent *ev);
00375 
00376     // -- Set Status --
00377     void setStatus(const Status st);
00378     void setStatus(const Status st, bool inv);
00379     void setInvisible(bool inv);
00380     
00381     Status getStatus() const;
00382     bool getInvisible() const;
00383 
00384     void uploadSelfDetails();
00385     
00386     // -- Contact List --
00387     void addContact(ContactRef c);
00388     void removeContact(const unsigned int uin);
00389     void addVisible(ContactRef c);
00390     void removeVisible(const unsigned int uin);
00391     void addInvisible(ContactRef c);
00392     void removeInvisible(const unsigned int uin);
00393     ContactRef getContact(const unsigned int uin);
00394 
00395     ContactList& getContactList();
00396 
00397     void fetchSimpleContactInfo(ContactRef c);
00398     void fetchDetailContactInfo(ContactRef c);
00399     void fetchServerBasedContactList();
00400     void fetchSelfSimpleContactInfo();
00401     void fetchSelfDetailContactInfo();
00402 
00403     // -- Whitepage searches --
00404     SearchResultEvent* searchForContacts(const string& nickname, const string& firstname,
00405                                          const string& lastname);
00406 
00407     SearchResultEvent* searchForContacts(const string& nickname, const string& firstname,
00408                                          const string& lastname, const string& email,
00409                                          AgeRange age, Sex sex, unsigned char language, const string& city,
00410                                          const string& state, unsigned short country,
00411                                          const string& company_name, const string& department,
00412                                          const string& position, bool only_online);
00413 
00414     SearchResultEvent* searchForContacts(unsigned int uin);
00415 
00416     SearchResultEvent* searchForContacts(const std::string& keyword);
00417 
00418     /*
00419      *  Poll must be called regularly (at least every 60 seconds)
00420      *  but I recommended 5 seconds, so timeouts work with good
00421      *  granularity.
00422      *  It is not related to the socket callback - the client using
00423      *  this library must select() on the sockets it gets signalled
00424      *  and call socket_cb when select returns a status flag on one
00425      *  of the sockets. ickle simply uses the gtk-- built in signal handlers
00426      *  to do all this.
00427      */
00428 
00429     // -- Network settings --
00430     void setLoginServerHost(const string& host);
00431     string getLoginServerHost() const;
00432 
00433     void setLoginServerPort(const unsigned short& port);
00434     unsigned short getLoginServerPort() const;
00435 
00436     void setBOSServerOverridePort(const bool& b);
00437     bool getBOSServerOverridePort() const;
00438 
00439     void setBOSServerPort(const unsigned short& port);
00440     unsigned short getBOSServerPort() const;
00441 
00442     void setSMTPServerHost(const string& host);
00443     string getSMTPServerHost() const;
00444 
00445     void setSMTPServerPort(unsigned short port);
00446     unsigned short getSMTPServerPort() const;
00447 
00448     void setAcceptInDC(bool d);
00449     bool getAcceptInDC() const;
00450 
00451     void setUseOutDC(bool d);
00452     bool getUseOutDC() const;
00453 
00454     void setPortRangeLowerBound(unsigned short lower);
00455     void setPortRangeUpperBound(unsigned short upper);
00456     unsigned short getPortRangeLowerBound() const;
00457     unsigned short getPortRangeUpperBound() const;
00458 
00459     void setUsePortRange(bool b);
00460     bool getUsePortRange() const;
00461 
00462     void Poll();
00463     void socket_cb(int fd, SocketEvent::Mode m);
00464 
00465     void RegisterUIN();
00466 
00467     /* isConnected() is a convenience for the
00468      * client, it should correspond exactly to ConnectedEvents
00469      * & DisconnectedEvents the client gets
00470      */
00471     bool isConnected() const;
00472     
00473   };
00474 }
00475 
00476 #endif

Generated on Fri Apr 26 23:48:14 2002 for libicq2000 by doxygen1.2.15