CPPMyth
Library to interoperate with MythTV server
wsresponse.h
1 /*
2  * Copyright (C) 2014-2015 Jean-Luc Barriere
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 3, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #ifndef WSRESPONSE_H
23 #define WSRESPONSE_H
24 
25 #include <cppmyth_config.h>
26 #include "wscontent.h"
27 #include "wsrequest.h"
28 
29 #include <cstddef> // for size_t
30 #include <string>
31 #include <list>
32 
33 namespace NSROOT
34 {
35 
36  class NetSocket;
37  class TcpSocket;
38  class Decompressor;
39 
40  class WSResponse
41  {
42  public:
43  WSResponse(const WSRequest& request);
44  ~WSResponse();
45 
46  bool IsSuccessful() const { return m_successful; }
47  bool IsChunkedTransfer() const { return m_contentChunked; }
48  size_t GetContentLength() const { return m_contentLength; }
49  size_t ReadContent(char *buf, size_t buflen);
50  size_t GetConsumed() const { return m_consumed; }
51  int GetStatusCode() const { return m_statusCode; }
52  const std::string& Redirection() const { return m_location; }
53 
54  bool GetHeaderValue(const std::string& header, std::string& value);
55 
56  static bool ReadHeaderLine(NetSocket *socket, const char *eol, std::string& line, size_t *len);
57 
58  private:
59  TcpSocket *m_socket;
60  bool m_successful;
61  int m_statusCode;
62  std::string m_serverInfo;
63  std::string m_etag;
64  std::string m_location;
65  CT_t m_contentType;
66  CE_t m_contentEncoding;
67  bool m_contentChunked;
68  size_t m_contentLength;
69  size_t m_consumed;
70  char* m_chunkBuffer;
71  char* m_chunkPtr;
72  char* m_chunkEOR;
73  char* m_chunkEnd;
74  Decompressor *m_decoder;
75 
76  typedef std::list<std::pair<std::string, std::string> > HeaderList;
77  HeaderList m_headers;
78 
79  // prevent copy
80  WSResponse(const WSResponse&);
81  WSResponse& operator=(const WSResponse&);
82 
83  bool SendRequest(const WSRequest& request);
84  bool GetResponse();
85  size_t ReadChunk(void *buf, size_t buflen);
86  static int SocketStreamReader(void *hdl, void *buf, int sz);
87  static int ChunkStreamReader(void *hdl, void *buf, int sz);
88  };
89 
90 }
91 
92 #endif /* WSRESPONSE_H */
char * m_chunkPtr
The next position to read data from the chunk.
Definition: wsresponse.h:71
char * m_chunkBuffer
The chunk data buffer.
Definition: wsresponse.h:70
char * m_chunkEOR
The end of received data in the chunk.
Definition: wsresponse.h:72
char * m_chunkEnd
The end of the chunk buffer.
Definition: wsresponse.h:73