~ubuntu-branches/ubuntu/vivid/gloox/vivid-proposed

« back to all changes in this revision

Viewing changes to src/clientbase.h

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng
  • Date: 2014-03-16 17:34:43 UTC
  • mfrom: (12.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20140316173443-4s177dovzaz5dm8o
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  Copyright (c) 2005-2009 by Jakob Schroeter <js@camaya.net>
 
2
  Copyright (c) 2005-2013 by Jakob Schroeter <js@camaya.net>
3
3
  This file is part of the gloox library. http://camaya.net/gloox
4
4
 
5
5
  This software is distributed under a license. The full license
28
28
#include "compressiondatahandler.h"
29
29
#include "connectiondatahandler.h"
30
30
#include "parser.h"
 
31
#include "atomicrefcount.h"
31
32
 
32
33
#include <string>
33
34
#include <list>
128
129
       * until data was available.
129
130
       * @return The state of the connection.
130
131
       */
131
 
      ConnectionError recv( int timeout = -1 );
 
132
      virtual ConnectionError recv( int timeout = -1 );
132
133
 
133
134
      /**
134
135
       * Reimplement this function to provide a username for connection purposes.
147
148
 
148
149
      /**
149
150
       * Switches usage of SASL on/off. Default: on. SASL should only be disabled if there are
150
 
       * problems with using it.
 
151
       * problems with using it, and if an alternative authentication method exists.
151
152
       * @param sasl Whether to switch SASL usage on or off.
152
153
       */
153
154
      void setSasl( bool sasl ) { m_sasl = sasl; }
280
281
       * A convenience function that sends the given Presence stanza.
281
282
       * @param pres The Presence stanza to send.
282
283
       */
283
 
      void send( Presence& pres );
 
284
      void send( const Presence& pres );
284
285
 
285
286
      /**
286
287
       * Returns whether authentication has taken place and was successful.
363
364
      void whitespacePing();
364
365
 
365
366
      /**
366
 
       * Sends a XMPP Ping (XEP-0199) to the given JID.
 
367
       * Sends a XMPP Ping (@xep{0199}) to the given JID.
367
368
       * @param to Then entity to ping.
368
369
       * @param eh An EventHandler to inform about the reply.
369
370
       * @since 0.9
433
434
 
434
435
      /**
435
436
       * Removes the given IqHandler from the list of handlers of pending operations, added
436
 
       * using trackID(). Necessary, for example, when closing a GUI element that has an
 
437
       * using send( IQ&, IqHandler*, int, bool ). Necessary, for example, when closing a GUI element that has an
437
438
       * operation pending.
438
439
       * @param ih The IqHandler to remove.
439
440
       * @since 0.8.7
678
679
       */
679
680
      const StanzaExtensionList& presenceExtensions() const { return m_presenceExtensions; }
680
681
 
 
682
      /**
 
683
       * Returns a list of Tags that are currently in the send queue.
 
684
       * You should not rely on the currentness of this data when there is an established connection.
 
685
       * @return A 'decoupled' list of Tags (deep copies) in the send queue. The caller is responsible
 
686
       * for deleting the tags.
 
687
       * @since 1.0.6
 
688
       */
 
689
      const TagList sendQueue();
 
690
 
681
691
      // reimplemented from ParserHandler
682
692
      virtual void handleTag( Tag* tag );
683
693
 
706
716
      virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo &certinfo );
707
717
 
708
718
    protected:
 
719
#ifdef CLIENTBASE_TEST
 
720
    public:
 
721
#endif
709
722
      /**
710
723
       * This function is called when resource binding yieled an error.
711
724
       * @param error A pointer to an Error object that contains more
786
799
      void startSASL( SaslMechanism type );
787
800
 
788
801
      /**
789
 
       * Releases SASL related resources.
 
802
       * Verifies the server response after successful authentication (if applicable) and
 
803
       * releases SASL related resources (if applicable).
 
804
       * @param payload The server's verification string.
 
805
       * @return @b True if verification is not supported by the chosen SASL mechanism or could be completed successfully,
 
806
       * @b false if verification failed.
790
807
       */
791
 
      void processSASLSuccess();
 
808
      bool processSASLSuccess( const std::string& payload );
792
809
 
793
810
      /**
794
811
       * Processes the given SASL challenge and sends a response.
819
836
       */
820
837
      bool hasTls();
821
838
 
 
839
      /**
 
840
       * Sends the given data unchecked over the underlying transport connection. Use at your own risk.
 
841
       * The server will check any data received anyway and disconnect if something is wrong.
 
842
       * @param xml The data to send.
 
843
       */
 
844
      void send( const std::string& xml );
 
845
 
 
846
      /**
 
847
       * This function checks if there are any unacknowledged Tags in the send queue and resends
 
848
       * as necessary.
 
849
       * @param handled The sequence number of the last handled stanza.
 
850
       * @param resend Whether to resend unhandled stanzas.
 
851
       * @note This function is part of @xep{0198}. You should not need to use it directly.
 
852
       * @since 1.0.4
 
853
       */
 
854
      void checkQueue( int handled, bool resend );
 
855
 
 
856
      /**
 
857
       * Returns the number of sent stanzas, if Stream Management is enabled.
 
858
       * @return The number of sent stanzas.
 
859
       */
 
860
      int stanzasSent() const { return m_smSent; }
 
861
 
 
862
      /**
 
863
       * Returns 32 octets of random characters.
 
864
       * @return Random characters.
 
865
       */
 
866
      std::string getRandom();
 
867
 
822
868
      JID m_jid;                         /**< The 'self' JID. */
823
869
      JID m_authzid;                     /**< An optional authorization ID. See setAuthzid(). */
824
870
      std::string m_authcid;             /**< An alternative authentication ID. See setAuthcid(). */
830
876
      /** A list of permanent presence extensions. */
831
877
      StanzaExtensionList m_presenceExtensions;
832
878
 
833
 
      std::string m_selectedResource;    /**< The currently selected resource.
834
 
                                          * See Client::selectResource() and Client::binRessource(). */
 
879
      GLOOX_DEPRECATED std::string m_selectedResource; /**< The currently selected resource.
 
880
                                          * See Client::selectResource() and Client::bindRessource().
 
881
                                          * @deprecated Not used anymore. Will be removed for 1.1.
 
882
                                          * @todo Remove for 1.1 */
835
883
      std::string m_clientCerts;         /**< TLS client certificates. */
836
884
      std::string m_clientKey;           /**< TLS client private key. */
837
885
      std::string m_namespace;           /**< Default namespace. */
855
903
 
856
904
      int m_availableSaslMechs;          /**< The SASL mechanisms the server offered. */
857
905
 
 
906
      /**
 
907
       * An enum for the Stream Management state machine.
 
908
       */
 
909
      enum SMContext
 
910
      {
 
911
        CtxSMInvalid,                    /**< Initial value. */
 
912
        CtxSMFailed,                      /**< Either of the above failed. */
 
913
        CtxSMEnable,                     /**< 'enable' request sent */
 
914
        CtxSMResume,                     /**< 'resume' request sent */
 
915
        CtxSMEnabled,                    /**< Stream Management successfully enabled. */
 
916
        CtxSMResumed                     /**< Stream successfully resumed. */
 
917
      };
 
918
 
 
919
      SMContext m_smContext;             /**< The Stream Management state. Used in @xep{0198}. */
 
920
      int m_smHandled;                   /**< The number of handled stanzas. Used in @xep{0198}.
 
921
                                          * You should NOT mess with this. */
 
922
 
858
923
    private:
859
924
#ifdef CLIENTBASE_TEST
860
925
    public:
861
926
#endif
862
927
      /**
863
 
       * @brief This is an implementation of an XMPP Ping (XEP-199).
 
928
       * @brief This is an implementation of an XMPP Ping (@xep{0199}).
864
929
       *
865
930
       * @author Jakob Schroeter <js@camaya.net>
866
931
       * @since 1.0
908
973
 
909
974
      /**
910
975
       * This function is called right after the opening &lt;stream:stream&gt; was received.
 
976
       * @param start The complete stream opening tag. Note that the XML representation (Tag::xml())
 
977
       * will contain a closed stream tag. The original is open.
911
978
       */
912
 
      virtual void handleStartNode() = 0;
 
979
      virtual void handleStartNode( const Tag* start ) = 0;
913
980
 
914
981
      /**
915
982
       * This function is called for each Tag. Only stream initiation/negotiation should
916
983
       * be done here.
917
984
       * @param tag A Tag to handle.
 
985
       * @return Returns @b true if the tag has been handled inside the function, @b false otherwise.
918
986
       */
919
987
      virtual bool handleNormalNode( Tag* tag ) = 0;
920
988
      virtual void rosterFilled() = 0;
921
989
      virtual void cleanup() {}
922
990
      virtual void handleIqIDForward( const IQ& iq, int context ) { (void) iq; (void) context; }
 
991
      void send( Tag* tag, bool queue, bool del );
 
992
      std::string hmac( const std::string& str, const std::string& key );
 
993
      std::string hi( const std::string& str, const std::string& key, int iter );
923
994
 
924
995
      void parse( const std::string& data );
925
996
      void init();
933
1004
      void notifySubscriptionHandlers( Subscription& s10n );
934
1005
      void notifyTagHandlers( Tag* tag );
935
1006
      void notifyOnDisconnect( ConnectionError e );
936
 
      void send( const std::string& xml );
937
1007
      void addFrom( Tag* tag );
938
1008
      void addNamespace( Tag* tag );
939
1009
 
973
1043
      typedef std::multimap<const int, IqHandler*>         IqHandlerMap;
974
1044
      typedef std::map<const std::string, TrackStruct>     IqTrackMap;
975
1045
      typedef std::map<const std::string, MessageHandler*> MessageHandlerMap;
 
1046
      typedef std::map<int, Tag*>                          SMQueueMap;
976
1047
      typedef std::list<MessageSession*>                   MessageSessionList;
977
1048
      typedef std::list<MessageHandler*>                   MessageHandlerList;
978
1049
      typedef std::list<PresenceHandler*>                  PresenceHandlerList;
984
1055
      IqHandlerMapXmlns        m_iqNSHandlers;
985
1056
      IqHandlerMap             m_iqExtHandlers;
986
1057
      IqTrackMap               m_iqIDHandlers;
 
1058
      SMQueueMap               m_smQueue;
987
1059
      MessageSessionList       m_messageSessions;
988
1060
      MessageHandlerList       m_messageHandlers;
989
1061
      PresenceHandlerList      m_presenceHandlers;
999
1071
      MessageSessionHandler  * m_messageSessionHandlerNormal;
1000
1072
 
1001
1073
      util::Mutex m_iqHandlerMapMutex;
 
1074
      util::Mutex m_iqExtHandlerMapMutex;
 
1075
      util::Mutex m_queueMutex;
1002
1076
 
1003
1077
      Parser m_parser;
1004
1078
      LogSink m_logInstance;
1015
1089
 
1016
1090
      SaslMechanism m_selectedSaslMech;
1017
1091
 
 
1092
      std::string m_clientFirstMessageBare;
 
1093
      std::string m_serverSignature;
 
1094
      std::string m_gs2Header;
1018
1095
      std::string m_ntlmDomain;
1019
 
      bool m_autoMessageSession;
 
1096
      bool m_customConnection;
 
1097
 
 
1098
      int m_uniqueBaseId;
 
1099
      util::AtomicRefCount m_nextId;
 
1100
 
 
1101
      int m_smSent;
1020
1102
 
1021
1103
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
1022
1104
      CredHandle m_credHandle;