MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

HttpdClient.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_OUTPUT_HTTPD_CLIENT_HXX
21 #define MPD_OUTPUT_HTTPD_CLIENT_HXX
22
23 #include "event/BufferedSocket.hxx"
24 #include "Compiler.h"
25
26 #include <boost/intrusive/link_mode.hpp>
27 #include <boost/intrusive/list_hook.hpp>
28
29 #include <queue>
30 #include <list>
31
32 #include <stddef.h>
33
34 class HttpdOutput;
35 class Page;
36
37 class HttpdClient final
38 : BufferedSocket,
39 public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
43 HttpdOutput &httpd;
44
48 enum {
50 REQUEST,
51
53 HEADERS,
54
56 RESPONSE,
57 } state;
58
62 std::queue<Page *, std::list<Page *>> pages;
63
67 size_t queue_size;
68
72 Page *current_page;
73
78 size_t current_position;
79
83 bool head_method;
84
88 bool dlna_streaming_requested;
89
90 /* ICY */
91
96 bool metadata_supported;
97
101 bool metadata_requested;
102
106 bool metadata_sent;
107
111 unsigned metaint;
112
116 Page *metadata;
117
118 /*
119 * The amount of bytes which were already sent from the metadata.
120 */
121 size_t metadata_current_position;
122
127 unsigned metadata_fill;
128
129 public:
134 HttpdClient(HttpdOutput &httpd, int _fd, EventLoop &_loop,
135 bool _metadata_supported);
136
141 ~HttpdClient();
142
146 void Close();
147
148 void LockClose();
149
153 void CancelQueue();
154
158 bool HandleLine(const char *line);
159
163 void BeginResponse();
164
168 bool SendResponse();
169
170 gcc_pure
171 ssize_t GetBytesTillMetaData() const;
172
173 ssize_t TryWritePage(const Page &page, size_t position);
174 ssize_t TryWritePageN(const Page &page, size_t position, ssize_t n);
175
176 bool TryWrite();
177
181 void PushPage(Page *page);
182
186 void PushMetaData(Page *page);
187
188 private:
189 void ClearQueue();
190
191 protected:
192 virtual bool OnSocketReady(unsigned flags) override;
193 virtual InputResult OnSocketInput(void *data, size_t length) override;
194 void OnSocketError(std::exception_ptr ep) override;
195 virtual void OnSocketClosed() override;
196 };
197
198 #endif
HttpdClient::PushPage
void PushPage(Page *page)
Appends a page to the client's queue.
HttpdClient::OnSocketError
void OnSocketError(std::exception_ptr ep) override
BufferedSocket.hxx
HttpdClient::LockClose
void LockClose()
HttpdOutput
Definition: HttpdInternal.hxx:51
HttpdClient::HttpdClient
HttpdClient(HttpdOutput &httpd, int _fd, EventLoop &_loop, bool _metadata_supported)
HttpdClient::TryWrite
bool TryWrite()
EventLoop
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:51
SocketMonitor::ssize_t
std::make_signed< size_t >::type ssize_t
Definition: SocketMonitor.hxx:69
HttpdClient::CancelQueue
void CancelQueue()
Clears the page queue.
BufferedSocket::InputResult
InputResult
Definition: BufferedSocket.hxx:78
HttpdClient::PushMetaData
void PushMetaData(Page *page)
Sends the passed metadata.
HttpdClient::BeginResponse
void BeginResponse()
Switch the client to the "RESPONSE" state.
HttpdClient::GetBytesTillMetaData
gcc_pure ssize_t GetBytesTillMetaData() const
HttpdClient::~HttpdClient
~HttpdClient()
Note: this does not remove the client from the HttpdOutput object.
HttpdClient::OnSocketInput
virtual InputResult OnSocketInput(void *data, size_t length) override
Data has been received on the socket.
Compiler.h
HttpdClient::SendResponse
bool SendResponse()
Sends the status line and response headers to the client.
HttpdClient::OnSocketClosed
virtual void OnSocketClosed() override
HttpdClient::TryWritePageN
ssize_t TryWritePageN(const Page &page, size_t position, ssize_t n)
HttpdClient
Definition: HttpdClient.hxx:37
BufferedSocket
A SocketMonitor specialization that adds an input buffer.
Definition: BufferedSocket.hxx:37
HttpdClient::OnSocketReady
virtual bool OnSocketReady(unsigned flags) override
HttpdClient::TryWritePage
ssize_t TryWritePage(const Page &page, size_t position)
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
HttpdClient::HandleLine
bool HandleLine(const char *line)
Handle a line of the HTTP request.
HttpdClient::Close
void Close()
Frees the client and removes it from the server's client list.
Page
A dynamically allocated buffer which keeps track of its reference count.
Definition: Page.hxx:37