Panda3D
chunkedStreamBuf.h
1 // Filename: chunkedStreamBuf.h
2 // Created by: drose (25Sep02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CHUNKEDSTREAMBUF_H
16 #define CHUNKEDSTREAMBUF_H
17 
18 #include "pandabase.h"
19 
20 // This module is not compiled if OpenSSL is not available.
21 #ifdef HAVE_OPENSSL
22 
23 #include "httpChannel.h"
24 #include "bioStreamPtr.h"
25 #include "pointerTo.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : ChunkedStreamBuf
29 // Description : The streambuf object that implements
30 // IChunkedStream.
31 ////////////////////////////////////////////////////////////////////
32 // No need to export from DLL.
33 class ChunkedStreamBuf : public streambuf {
34 public:
35  ChunkedStreamBuf();
36  virtual ~ChunkedStreamBuf();
37 
38  void open_read(BioStreamPtr *source, HTTPChannel *doc);
39  void close_read();
40 
41  INLINE bool is_closed() const;
42  INLINE ISocketStream::ReadState get_read_state() const;
43 
44 protected:
45  virtual int underflow();
46 
47 private:
48  size_t read_chars(char *start, size_t length);
49  bool http_getline(string &str);
50 
51  PT(BioStreamPtr) _source;
52  size_t _chunk_remaining;
53  bool _done;
54  bool _wanted_nonblocking;
55  string _working_getline;
56  ISocketStream::ReadState _read_state;
57 
58  PT(HTTPChannel) _doc;
59  int _read_index;
60  char *_buffer;
61 
62  friend class IChunkedStream;
63 };
64 
65 #include "chunkedStreamBuf.I"
66 
67 #endif // HAVE_OPENSSL
68 
69 #endif