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

Generated on Sat Jul 20 16:59:08 2002 for libicq2000 by doxygen1.2.16