gloox  1.0.28
inbandbytestream.h
1 /*
2  Copyright (c) 2006-2023 by Jakob Schröter <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 INBANDBYTESTREAM_H__
15 #define INBANDBYTESTREAM_H__
16 
17 #include "bytestream.h"
18 #include "iqhandler.h"
19 #include "messagehandler.h"
20 #include "gloox.h"
21 
22 namespace gloox
23 {
24 
25  class BytestreamDataHandler;
26  class ClientBase;
27  class Message;
28 
43  class GLOOX_API InBandBytestream : public Bytestream, public IqHandler, public MessageHandler
44  {
45 
46  friend class SIProfileFT;
47 
48  public:
52  virtual ~InBandBytestream();
53 
58  int blockSize() const { return m_blockSize; }
59 
66  void setBlockSize( int blockSize ) { m_blockSize = blockSize; }
67 
68  // reimplemented from Bytestream
69  virtual ConnectionError recv( int timeout = -1 ) { (void)timeout; return ConnNoError; }
70 
71  // reimplemented from Bytestream
72  bool send( const std::string& data );
73 
74  // reimplemented from Bytestream
75  virtual bool connect();
76 
77  // reimplemented from Bytestream
78  virtual void close();
79 
80  // reimplemented from IqHandler
81  virtual bool handleIq( const IQ& iq );
82 
83  // reimplemented from IqHandler
84  virtual void handleIqID( const IQ& iq, int context );
85 
86  // reimplemented from MessageHandler
87  virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
88 
89  private:
90 #ifdef INBANDBYTESTREAM_TEST
91  public:
92 #endif
93  enum IBBType
94  {
95  IBBOpen,
96  IBBData,
97  IBBClose,
98  IBBInvalid
99  };
100 
107  class IBB : public StanzaExtension
108  {
109  public:
115  IBB( const std::string& sid, int blocksize );
116 
124  IBB( const std::string& sid, int seq, const std::string& data );
125 
130  IBB( const std::string& sid );
131 
136  IBB( const Tag* tag = 0 );
137 
141  virtual ~IBB();
142 
147  IBBType type() const { return m_type; }
148 
153  int blocksize() const { return m_blockSize; }
154 
159  int seq() const { return m_seq; }
160 
165  const std::string sid() const { return m_sid; }
166 
171  const std::string& data() const { return m_data; }
172 
173  // reimplemented from StanzaExtension
174  virtual const std::string& filterString() const;
175 
176  // reimplemented from StanzaExtension
177  virtual StanzaExtension* newInstance( const Tag* tag ) const
178  {
179  return new IBB( tag );
180  }
181 
182  // reimplemented from StanzaExtension
183  virtual Tag* tag() const;
184 
185  // reimplemented from StanzaExtension
186  virtual StanzaExtension* clone() const
187  {
188  return new IBB( *this );
189  }
190 
191  private:
192  std::string m_sid;
193  int m_seq;
194  int m_blockSize;
195  std::string m_data;
196  IBBType m_type;
197  };
198 
199  InBandBytestream( ClientBase* clientbase, LogSink& logInstance, const JID& initiator,
200  const JID& target, const std::string& sid );
201  InBandBytestream& operator=( const InBandBytestream& );
202  void closed(); // by remote entity
203  void returnResult( const JID& to, const std::string& id );
204  void returnError( const JID& to, const std::string& id, StanzaErrorType type, StanzaError error );
205 
206  ClientBase* m_clientbase;
207  int m_blockSize;
208  int m_sequence;
209  int m_lastChunkReceived;
210 
211  };
212 
213 }
214 
215 #endif // INBANDBYTESTREAM_H__
An abstraction of a single bytestream.
Definition: bytestream.h:37
An abstraction of an IQ stanza.
Definition: iq.h:34
An implementation of a single In-Band Bytestream (XEP-0047).
void setBlockSize(int blockSize)
virtual ConnectionError recv(int timeout=-1)
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:32
A virtual interface which can be reimplemented to receive incoming message stanzas.
An abstraction of a message session between any two entities.
An abstraction of a message stanza.
Definition: message.h:34
An implementation of the file transfer SI profile (XEP-0096).
Definition: siprofileft.h:152
The namespace for the gloox library.
Definition: adhoc.cpp:28
ConnectionError
Definition: gloox.h:684
@ ConnNoError
Definition: gloox.h:685
StanzaError
Definition: gloox.h:872
StanzaErrorType
Definition: gloox.h:857