gloox  1.0
inbandbytestream.h
1 /*
2  Copyright (c) 2006-2009 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 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 
65  void setBlockSize( int blockSize ) { m_blockSize = blockSize; }
66 
67  // reimplemented from Bytestream
68  virtual ConnectionError recv( int timeout = -1 ) { (void)timeout; return ConnNoError; }
69 
70  // reimplemented from Bytestream
71  bool send( const std::string& data );
72 
73  // reimplemented from Bytestream
74  virtual bool connect();
75 
76  // reimplemented from Bytestream
77  virtual void close();
78 
79  // reimplemented from IqHandler
80  virtual bool handleIq( const IQ& iq );
81 
82  // reimplemented from IqHandler
83  virtual void handleIqID( const IQ& iq, int context );
84 
85  // reimplemented from MessageHandler
86  virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
87 
88  private:
89 #ifdef INBANDBYTESTREAM_TEST
90  public:
91 #endif
92  enum IBBType
93  {
94  IBBOpen,
95  IBBData,
96  IBBClose,
97  IBBInvalid
98  };
99 
106  class IBB : public StanzaExtension
107  {
108  public:
114  IBB( const std::string& sid, int blocksize );
115 
123  IBB( const std::string& sid, int seq, const std::string& data );
124 
129  IBB( const std::string& sid );
130 
135  IBB( const Tag* tag = 0 );
136 
140  virtual ~IBB();
141 
146  IBBType type() const { return m_type; }
147 
152  int blocksize() const { return m_blockSize; }
153 
158  int seq() const { return m_seq; }
159 
164  const std::string sid() const { return m_sid; }
165 
170  const std::string& data() const { return m_data; }
171 
172  // reimplemented from StanzaExtension
173  virtual const std::string& filterString() const;
174 
175  // reimplemented from StanzaExtension
176  virtual StanzaExtension* newInstance( const Tag* tag ) const
177  {
178  return new IBB( tag );
179  }
180 
181  // reimplemented from StanzaExtension
182  virtual Tag* tag() const;
183 
184  // reimplemented from StanzaExtension
185  virtual StanzaExtension* clone() const
186  {
187  return new IBB( *this );
188  }
189 
190  private:
191  std::string m_sid;
192  int m_seq;
193  int m_blockSize;
194  std::string m_data;
195  IBBType m_type;
196  };
197 
198  InBandBytestream( ClientBase* clientbase, LogSink& logInstance, const JID& initiator,
199  const JID& target, const std::string& sid );
200  InBandBytestream& operator=( const InBandBytestream& );
201  void closed(); // by remote entity
202  void returnResult( const JID& to, const std::string& id );
203  void returnError( const JID& to, const std::string& id, StanzaErrorType type, StanzaError error );
204 
205  ClientBase* m_clientbase;
206  int m_blockSize;
207  int m_sequence;
208  int m_lastChunkReceived;
209 
210  };
211 
212 }
213 
214 #endif // INBANDBYTESTREAM_H__