File: flexoff.h

package info (click to toggle)
gloox 1.0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,732 kB
  • ctags: 6,556
  • sloc: cpp: 45,479; sh: 11,344; makefile: 1,018
file content (178 lines) | stat: -rw-r--r-- 5,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
  Copyright (c) 2005-2016 by Jakob Schröter <js@camaya.net>
  This file is part of the gloox library. http://camaya.net/gloox

  This software is distributed under a license. The full license
  agreement can be found in the file LICENSE in this distribution.
  This software may not be copied, modified, sold or distributed
  other than expressed in the named license agreement.

  This software is distributed without any warranty.
*/


#ifndef FLEXOFF_H__
#define FLEXOFF_H__

#include "clientbase.h"
#include "discohandler.h"
#include "flexoffhandler.h"
#include "iqhandler.h"
#include "stanzaextension.h"

namespace gloox
{

  /**
   * @brief An implementation of @xep{0013} (Flexible Offline Message Retrieval).
   *
   * Use the FlexibleOfflineHandler to receive results.
   *
   * @author Jakob Schröter <js@camaya.net>
   * @since 0.7
   */
  class GLOOX_API FlexibleOffline : public DiscoHandler, public IqHandler
  {
    public:
      /**
       * Creates a new FlexibleOffline object that manages retrieval of offline messages.
       * @param parent The ClientBase to use for communication.
       */
      FlexibleOffline( ClientBase* parent );

      /**
       * Virtual Destructor.
       */
      virtual ~FlexibleOffline();

      /**
       * Initiates querying the server for Flexible Offline Message Retrieval-support.
       * The result is announced through the FlexibleOfflineHandler.
       * An application could cache the result on a per-server basis to eliminate the associated delay.
       */
      void checkSupport();

      /**
       * Asks the server for the number of stored offline messages.
       * The result is announced through the FlexibleOfflineHandler.
       */
      void getMsgCount();

      /**
       * Initiates fetching the offline message headers.
       * The result is announced through the FlexibleOfflineHandler.
       */
      void fetchHeaders();

      /**
       * Initiates fetching of one or more specific messages, or all messages.
       * The result is announced through the FlexibleOfflineHandler.
       * If the list of message nodes contains one or more nodes, the corresponding messages are
       * fetched. If the list is empty all messages are fetched (&lt;fetch&gt;).
       * @param msgs A list of message nodes to fetch.
       */
      void fetchMessages( const StringList& msgs )
        { messageOperation( FORequestMsgs, msgs ); }

      /**
       * Initiates removing of one or more specific messages, or all messages.
       * The result is announced through the FlexibleOfflineHandler.
       * If the list of message nodes contains one or more nodes, the corresponding messages are
       * removed. If the list is empty all messages are removed (&lt;purge&gt;).
       */
      void removeMessages( const StringList& msgs )
        { messageOperation( FORemoveMsgs, msgs ); }

      /**
       * Registers a FlexibleOfflineHandler as object that receives results of @xep{0013} queries.
       * Only one Handler at a time is possible.
       * @param foh The Handler object to register.
       */
      void registerFlexibleOfflineHandler( FlexibleOfflineHandler* foh );

      /**
       * Removes the registered handler.
       */
      void removeFlexibleOfflineHandler();

      // reimplemented from DiscoHandler
      virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );

      // reimplemented from DiscoHandler
      virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );

      // reimplemented from DiscoHandler
      virtual void handleDiscoError( const JID& from, const Error* error, int context );

      // reimplemented from IqHandler.
      virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }

      // reimplemented from IqHandler.
      virtual void handleIqID( const IQ& iq, int context );

    private:
#ifdef FLEXOFF_TEST
    public:
#endif
      class Offline : public StanzaExtension
      {
        public:
          /**
           * Constructs a new Offline object from the given Tag.
           * @param tag The Tag to parse.
           */
          Offline( const Tag* tag = 0 );

          /**
           * Constructs a new Offline object for the given context and messages.
           * @param context The context.
           * @param msgs The messages.
           */
          Offline( int context, const StringList& msgs );

          /**
           * Virtual destructor.
           */
          virtual ~Offline();

          // reimplemented from StanzaExtension
          virtual const std::string& filterString() const;

          // reimplemented from StanzaExtension
          virtual StanzaExtension* newInstance( const Tag* tag ) const
          {
            return new Offline( tag );
          }

          // reimplemented from StanzaExtension
          virtual Tag* tag() const;

          // reimplemented from StanzaExtension
          virtual StanzaExtension* clone() const
          {
            return new Offline( *this );
          }

        private:
          int m_context;
          StringList m_msgs;
      };

      void messageOperation( int context, const StringList& msgs );

      enum FOContext
      {
        FOCheckSupport,
        FORequestNum,
        FORequestHeaders,
        FORequestMsgs,
        FORemoveMsgs
      };

      ClientBase* m_parent;
      FlexibleOfflineHandler* m_flexibleOfflineHandler;
  };

}

#endif // FLEXOFF_H__