gloox  0.9.9.12
client.h
1 /*
2  Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef CLIENT_H__
15 #define CLIENT_H__
16 
17 #include "clientbase.h"
18 #include "iqhandler.h"
19 #include "stanza.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
26  class RosterManager;
27  class NonSaslAuth;
28 
97  class GLOOX_API Client : public ClientBase
98  {
99  public:
100 
101  friend class NonSaslAuth;
102  friend class Parser;
103 
110  Client( const std::string& server );
111 
122  Client( const JID& jid, const std::string& password, int port = -1 );
123 
136  Client( const std::string& username, const std::string& password,
137  const std::string& server, const std::string& resource, int port = -1 );
138 
142  virtual ~Client();
143 
149  void bindResource();
150 
155  const std::string& resource() const { return m_jid.resource(); }
156 
161  int priority() const { return m_priority; }
162 
167  void setUsername( const std::string &username );
168 
173  void setResource( const std::string &resource ) { m_jid.setResource( resource ); }
174 
186  void setPresence( Presence presence, int priority = 0, const std::string& msg = "" );
187 
192  Presence presence() const { return m_presence; }
193 
198  const std::string& status() const { return m_status; }
199 
211  void addPresenceExtension( StanzaExtension *se );
212 
216  void removePresenceExtensions();
217 
223  GLOOX_DEPRECATED void setForceNonSasl( bool force = true ) { m_forceNonSasl = force; }
224 
230  void disableRoster();
231 
236  RosterManager* rosterManager() { return m_rosterManager; }
237 
241  void disconnect();
242 
250  bool login();
251 
252  protected:
256  void nonSaslLogin();
257 
258  private:
259  virtual void handleStartNode() {}
260  virtual bool handleNormalNode( Stanza *stanza );
261  virtual void disconnect( ConnectionError reason );
262  int getStreamFeatures( Stanza *stanza );
263  int getSaslMechs( Tag *tag );
264  int getCompressionMethods( Tag *tag );
265  void processResourceBind( Stanza *stanza );
266  void processCreateSession( Stanza *stanza );
267  void sendPresence();
268  void createSession();
269  void negotiateCompression( StreamFeature method );
270  void connected();
271  virtual void rosterFilled();
272  virtual void cleanup();
273 
274  void init();
275 
276  RosterManager *m_rosterManager;
277  NonSaslAuth *m_auth;
278 
279  StanzaExtensionList m_presenceExtensions;
280 
281  Presence m_presence;
282  std::string m_status;
283 
284  bool m_resourceBound;
285  bool m_forceNonSasl;
286  bool m_manageRoster;
287  bool m_doAuth;
288 
289  int m_streamFeatures;
290  int m_priority;
291 
292  };
293 
294 }
295 
296 #endif // CLIENT_H__