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 namespace ICQ2000 {
00051
00052
00053 class MessageSNAC;
00054 class MessageACKSNAC;
00055 class MessageOfflineUserSNAC;
00056 class SrvResponseSNAC;
00057 class UINResponseSNAC;
00058 class RateInfoChangeSNAC;
00059 class BuddyOnlineSNAC;
00060 class BuddyOfflineSNAC;
00061 class UserInfoSNAC;
00062 class OutSNAC;
00063
00069 class Client : public SigC::Object {
00070 private:
00071 enum State { NOT_CONNECTED,
00072 AUTH_AWAITING_CONN_ACK,
00073 AUTH_AWAITING_AUTH_REPLY,
00074 BOS_AWAITING_CONN_ACK,
00075 BOS_AWAITING_LOGIN_REPLY,
00076 BOS_LOGGED_IN,
00077 UIN_AWAITING_CONN_ACK,
00078 UIN_AWAITING_UIN_REPLY
00079 } m_state;
00080
00081 ContactRef m_self;
00082 std::string m_password;
00083 Status m_status_wanted;
00084 bool m_invisible_wanted;
00085 bool m_web_aware;
00086
00087 std::string m_authorizerHostname;
00088 unsigned short m_authorizerPort;
00089
00090 std::string m_bosHostname;
00091 unsigned short m_bosPort;
00092 bool m_bosOverridePort;
00093
00094 bool m_in_dc, m_out_dc;
00095
00096 unsigned short m_client_seq_num;
00097 unsigned int m_requestid;
00098
00099 Translator m_translator;
00100
00101 ContactList m_contact_list;
00102
00103 ContactList m_visible_list;
00104 ContactList m_invisible_list;
00105
00106 MessageHandler m_message_handler;
00107
00108 unsigned char *m_cookie_data;
00109 unsigned short m_cookie_length;
00110
00111 unsigned int m_ext_ip;
00112 bool m_use_portrange;
00113 unsigned short m_upper_port, m_lower_port;
00114 TCPSocket m_serverSocket;
00115 TCPServer m_listenServer;
00116
00117 SMTPClient m_smtp;
00118
00119 DCCache m_dccache;
00120
00121 time_t m_last_server_ping;
00122
00123 RequestIDCache m_reqidcache;
00124 ICBMCookieCache m_cookiecache;
00125
00126 Buffer m_recv;
00127
00128 void Init();
00129 unsigned short NextSeqNum();
00130 unsigned int NextRequestID();
00131
00132 void ConnectAuthorizer(State state);
00133 void DisconnectAuthorizer();
00134 void ConnectBOS();
00135 void DisconnectBOS();
00136
00137
00138 void PingServer();
00139
00140 DirectClient* ConnectDirect(const ContactRef& c);
00141 void DisconnectDirectConns();
00142 void DisconnectDirectConn(int fd);
00143
00144
00145 void SignalConnect();
00146 void SignalDisconnect(DisconnectedEvent::Reason r);
00147 void SignalMessage(MessageSNAC *snac);
00148 void SignalMessageACK(MessageACKSNAC *snac);
00149 void SignalMessageOfflineUser(MessageOfflineUserSNAC *snac);
00150 void SignalSrvResponse(SrvResponseSNAC *snac);
00151 void SignalUINResponse(UINResponseSNAC *snac);
00152 void SignalUINRequestError();
00153 void SignalRateInfoChange(RateInfoChangeSNAC *snac);
00154 void SignalLog(LogEvent::LogType type, const std::string& msg);
00155 void SignalUserOnline(BuddyOnlineSNAC *snac);
00156 void SignalUserOffline(BuddyOfflineSNAC *snac);
00157 void SignalServerBasedContactList(const ContactList& l);
00158 void SignalAddSocket(int fd, SocketEvent::Mode m);
00159 void SignalRemoveSocket(int fd);
00160
00161
00162
00163 void contactlist_cb(ContactListEvent *ev);
00164
00165
00166 void visiblelist_cb(ContactListEvent *ev);
00167 void invisiblelist_cb(ContactListEvent *ev);
00168
00169
00170
00171 void SendAuthReq();
00172 void SendNewUINReq();
00173 void SendCookie();
00174 void SendCapabilities();
00175 void SendRateInfoRequest();
00176 void SendRateInfoAck();
00177 void SendPersonalInfoRequest();
00178 void SendAddICBMParameter();
00179 void SendSetUserInfo();
00180 void SendLogin();
00181 void SendOfflineMessagesRequest();
00182 void SendOfflineMessagesACK();
00183
00184 void SendAdvancedACK(MessageSNAC *snac);
00185
00186 void Send(Buffer& b);
00187
00188 void HandleUserInfoSNAC(UserInfoSNAC *snac);
00189
00190 Buffer::marker FLAPHeader(Buffer& b, unsigned char channel);
00191 void FLAPFooter(Buffer& b, Buffer::marker& mk);
00192
00193 void FLAPwrapSNAC(Buffer& b, const OutSNAC& snac);
00194 void FLAPwrapSNACandSend(const OutSNAC& snac);
00195
00196
00197
00202 void RecvFromServer();
00203
00204 void Parse();
00205 void ParseCh1(Buffer& b, unsigned short seq_num);
00206 void ParseCh2(Buffer& b, unsigned short seq_num);
00207 void ParseCh3(Buffer& b, unsigned short seq_num);
00208 void ParseCh4(Buffer& b, unsigned short seq_num);
00209
00210
00211
00212 ContactRef getUserInfoCacheContact(unsigned int reqid);
00213
00214 void ICBMCookieCache_expired_cb(MessageEvent *ev);
00215 void dccache_expired_cb(DirectClient *dc);
00216 void reqidcache_expired_cb( RequestIDCacheValue *v );
00217 void dc_connected_cb(DirectClient *dc);
00218 void dc_log_cb(LogEvent *ev);
00219 void dc_socket_cb(SocketEvent *ev);
00220 void dc_messageack_cb(MessageEvent *ev);
00221
00222 bool SendDirect(MessageEvent *ev);
00223
00224 void SendViaServer(MessageEvent *ev);
00225 void SendViaServerAdvanced(MessageEvent *ev);
00226 void SendViaServerNormal(MessageEvent *ev);
00227
00228 void Disconnect(DisconnectedEvent::Reason r = DisconnectedEvent::REQUESTED);
00229
00230 public:
00231 Client();
00232 Client(const unsigned int uin, const std::string& password);
00233 ~Client();
00234
00235 void setUIN(unsigned int uin);
00236 unsigned int getUIN() const;
00237 void setPassword(const std::string& password);
00238 std::string getPassword() const;
00239
00240 ContactRef getSelfContact();
00241
00242 bool setTranslationMap(const std::string& szMapFileName);
00243 const std::string& getTranslationMapFileName() const;
00244 const std::string& getTranslationMapName() const;
00245 bool usingDefaultMap() const;
00246
00247
00253 SigC::Signal1<void,ConnectingEvent*> connecting;
00254
00260 SigC::Signal1<void,ConnectedEvent*> connected;
00261
00275 SigC::Signal1<void,DisconnectedEvent*> disconnected;
00276
00282 SigC::Signal1<void,MessageEvent*> messaged;
00283
00292 SigC::Signal1<void,MessageEvent*> messageack;
00293
00298 SigC::Signal1<void,ContactListEvent*> contactlist;
00299
00304 SigC::Signal1<void,UserInfoChangeEvent*> contact_userinfo_change_signal;
00305
00310 SigC::Signal1<void,StatusChangeEvent*> contact_status_change_signal;
00311
00317 SigC::Signal1<void,NewUINEvent*> newuin;
00318
00324 SigC::Signal1<void,RateInfoChangeEvent*> rate;
00325
00334 SigC::Signal1<void,LogEvent*> logger;
00335
00345 SigC::Signal1<void,SocketEvent*> socket;
00346
00351 SigC::Signal1<void,UserInfoChangeEvent*> self_contact_userinfo_change_signal;
00352
00357 SigC::Signal1<void,StatusChangeEvent*> self_contact_status_change_signal;
00358
00365 SigC::Signal1<void,ICQMessageEvent*> want_auto_resp;
00366
00373 SigC::Signal1<void,SearchResultEvent*> search_result;
00374
00375 SigC::Signal1<void,ServerBasedContactEvent*> server_based_contact_list;
00376
00377
00378
00379
00380 void SendEvent(MessageEvent *ev);
00381
00382
00383 void setStatus(const Status st);
00384 void setStatus(const Status st, bool inv);
00385 void setInvisible(bool inv);
00386 void setWebAware(bool wa);
00387
00388 Status getStatus() const;
00389 bool getInvisible() const;
00390
00391 Status getStatusWanted() const;
00392 bool getInvisibleWanted() const;
00393
00394 bool getWebAware() const;
00395
00396 void uploadSelfDetails();
00397
00398
00399 void addContact(ContactRef c);
00400 void removeContact(const unsigned int uin);
00401 void addVisible(ContactRef c);
00402 void removeVisible(const unsigned int uin);
00403 void addInvisible(ContactRef c);
00404 void removeInvisible(const unsigned int uin);
00405 ContactRef getContact(const unsigned int uin);
00406
00407 ContactList& getContactList();
00408
00409 void fetchSimpleContactInfo(ContactRef c);
00410 void fetchDetailContactInfo(ContactRef c);
00411 void fetchServerBasedContactList();
00412 void fetchSelfSimpleContactInfo();
00413 void fetchSelfDetailContactInfo();
00414
00415
00416 SearchResultEvent* searchForContacts(const std::string& nickname, const std::string& firstname,
00417 const std::string& lastname);
00418
00419 SearchResultEvent* searchForContacts(const std::string& nickname, const std::string& firstname,
00420 const std::string& lastname, const std::string& email,
00421 AgeRange age, Sex sex, unsigned char language, const std::string& city,
00422 const std::string& state, unsigned short country,
00423 const std::string& company_name, const std::string& department,
00424 const std::string& position, bool only_online);
00425
00426 SearchResultEvent* searchForContacts(unsigned int uin);
00427
00428 SearchResultEvent* searchForContacts(const std::string& keyword);
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 void setLoginServerHost(const std::string& host);
00443 std::string getLoginServerHost() const;
00444
00445 void setLoginServerPort(const unsigned short& port);
00446 unsigned short getLoginServerPort() const;
00447
00448 void setBOSServerOverridePort(const bool& b);
00449 bool getBOSServerOverridePort() const;
00450
00451 void setBOSServerPort(const unsigned short& port);
00452 unsigned short getBOSServerPort() const;
00453
00454 void setSMTPServerHost(const std::string& host);
00455 std::string getSMTPServerHost() const;
00456
00457 void setSMTPServerPort(unsigned short port);
00458 unsigned short getSMTPServerPort() const;
00459
00460 void setAcceptInDC(bool d);
00461 bool getAcceptInDC() const;
00462
00463 void setUseOutDC(bool d);
00464 bool getUseOutDC() const;
00465
00466 void setPortRangeLowerBound(unsigned short lower);
00467 void setPortRangeUpperBound(unsigned short upper);
00468 unsigned short getPortRangeLowerBound() const;
00469 unsigned short getPortRangeUpperBound() const;
00470
00471 void setUsePortRange(bool b);
00472 bool getUsePortRange() const;
00473
00474 void Poll();
00475 void socket_cb(int fd, SocketEvent::Mode m);
00476
00477 void RegisterUIN();
00478
00479
00480
00481
00482
00483 bool isConnected() const;
00484
00485 };
00486 }
00487
00488 #endif