]> git.mxchange.org Git - simgear.git/blob - simgear/io/HTTPContentDecode.hxx
Terrasync: implement HTTP service lookup via DNS
[simgear.git] / simgear / io / HTTPContentDecode.hxx
1 // Written by James Turner
2 //
3 // Copyright (C) 2013  James Turner  <zakalawe@mac.com>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19
20 #ifndef SG_HTTP_CONTENT_DECODER_HXX
21 #define SG_HTTP_CONTENT_DECODER_HXX
22
23 #include <string>
24
25 #include <zlib.h>
26
27 #include <simgear/io/HTTPRequest.hxx>
28
29
30 namespace simgear
31 {
32
33 namespace HTTP
34 {
35
36 class ContentDecoder
37 {
38 public:
39     ContentDecoder();
40     ~ContentDecoder();
41     
42     void reset();
43     
44     void initWithRequest(Request_ptr req);
45     
46     void finish();
47     
48     void setEncoding(const std::string& encoding);
49     
50     void receivedBytes(const char* n, size_t s);
51
52     size_t getTotalReceivedBytes() const
53     { return _totalReceivedBytes; }
54 private:
55     bool consumeGZipHeader();
56     void runDecoder();
57     
58     void consumeBytes(size_t consumed);
59     void reallocateInputBuffer(size_t newSize);
60     
61     Request_ptr _request;
62     unsigned char* _output;
63     
64     z_stream* _zlib;
65     unsigned char* _input;
66     size_t _inputAllocated, _inputSize;
67     bool _contentDeflate, _needGZipHeader;
68     size_t _totalReceivedBytes;
69 };
70
71 } // of namespace HTTP
72
73 } // of namespace simgear
74
75 #endif // of SG_HTTP_CONTENT_DECODER_HXX