ScummVM API documentation
client.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_NETWORKING_SDL_NET_CLIENT_H
23 #define BACKENDS_NETWORKING_SDL_NET_CLIENT_H
24 
25 #include "backends/networking/sdl_net/reader.h"
26 #include "common/str.h"
27 
28 namespace Common {
29 class MemoryReadWriteStream;
30 }
31 
32 typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
33 typedef struct _TCPsocket *TCPsocket;
34 
35 namespace Networking {
36 
37 enum ClientState {
38  INVALID,
39  READING_HEADERS,
40  READ_HEADERS,
41  BAD_REQUEST,
42  BEING_HANDLED
43 };
44 
45 class Client;
46 
47 #define CLIENT_BUFFER_SIZE 1 * 1024 * 1024
48 
50 public:
51  virtual ~ClientHandler() {};
52  virtual void handle(Client *client) = 0;
53 };
54 
75 class Client {
76  ClientState _state;
77  SDLNet_SocketSet _set;
78  TCPsocket _socket;
79  Reader _reader;
80  ClientHandler *_handler, *_previousHandler;
82  byte *_buffer;
83 
84  bool readMoreIfNeeded();
85 
86 public:
87  Client();
88  Client(SDLNet_SocketSet set, TCPsocket socket);
89  virtual ~Client();
90 
91  void open(SDLNet_SocketSet set, TCPsocket socket);
92  void readHeaders();
93  bool readContent(Common::WriteStream *stream);
94  bool readFirstContent(Common::WriteStream *stream);
95  bool readBlockHeaders(Common::WriteStream *stream);
96  bool readBlockContent(Common::WriteStream *stream);
97  void setHandler(ClientHandler *handler);
98  void handle();
99  void close();
100 
101  ClientState state() const;
102  Common::String headers() const;
103  Common::String method() const;
104  Common::String path() const;
105  Common::String query() const;
106  Common::String queryParameter(const Common::String &name) const;
107  Common::String anchor() const;
108 
109  bool noMoreContent() const;
110 
118  bool socketIsReady();
119  int recv(void *data, int maxlen);
120  int send(void *data, int len);
121 };
122 
123 } // End of namespace Networking
124 
125 #endif
Definition: client.h:75
Definition: str.h:59
Definition: stream.h:77
Definition: scummvmcloud.h:31
Definition: reader.h:79
Definition: algorithm.h:29
Definition: client.h:49
Definition: memstream.h:283