Commit 70879356 authored by Max Kellermann's avatar Max Kellermann

output/httpd: convert to C++

parent 5822daa6
......@@ -101,8 +101,6 @@ mpd_headers = \
src/AudioCompress/compress.h \
src/path.h \
src/open.h \
src/output/httpd_client.h \
src/output/httpd_internal.h \
src/page.h \
src/Playlist.hxx \
src/playlist_error.h \
......@@ -899,8 +897,9 @@ endif
if ENABLE_HTTPD_OUTPUT
liboutput_plugins_a_SOURCES += \
src/icy_server.c \
src/output/httpd_client.c \
src/output/httpd_output_plugin.c src/output/httpd_output_plugin.h
src/output/HttpdInternal.hxx \
src/output/HttpdClient.cxx src/output/HttpdClient.hxx \
src/output/HttpdOutputPlugin.cxx src/output/HttpdOutputPlugin.hxx
endif
if ENABLE_SOLARIS_OUTPUT
......
......@@ -24,7 +24,7 @@
#include "output/ao_output_plugin.h"
#include "output/ffado_output_plugin.h"
#include "output/fifo_output_plugin.h"
#include "output/httpd_output_plugin.h"
#include "output/HttpdOutputPlugin.hxx"
#include "output/jack_output_plugin.h"
#include "output/mvp_output_plugin.h"
#include "output/null_output_plugin.h"
......
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_OUTPUT_HTTPD_CLIENT_HXX
#define MPD_OUTPUT_HTTPD_CLIENT_HXX
#include "gcc.h"
#include <glib.h>
#include <list>
#include <stddef.h>
struct httpd_output;
struct page;
class HttpdClient final {
/**
* The httpd output object this client is connected to.
*/
httpd_output *const httpd;
/**
* The TCP socket.
*/
GIOChannel *channel;
/**
* The GLib main loop source id for reading from the socket,
* and to detect errors.
*/
guint read_source_id;
/**
* The GLib main loop source id for writing to the socket. If
* 0, then there is no event source currently (because there
* are no queued pages).
*/
guint write_source_id;
/**
* For buffered reading. This pointer is only valid while the
* HTTP request is read.
*/
struct fifo_buffer *input;
/**
* The current state of the client.
*/
enum {
/** reading the request line */
REQUEST,
/** reading the request headers */
HEADERS,
/** sending the HTTP response */
RESPONSE,
} state;
/**
* A queue of #page objects to be sent to the client.
*/
std::list<page *> pages;
/**
* The #page which is currently being sent to the client.
*/
page *current_page;
/**
* The amount of bytes which were already sent from
* #current_page.
*/
size_t current_position;
/**
* If DLNA streaming was an option.
*/
bool dlna_streaming_requested;
/* ICY */
/**
* Do we support sending Icy-Metadata to the client? This is
* disabled if the httpd audio output uses encoder tags.
*/
bool metadata_supported;
/**
* If we should sent icy metadata.
*/
bool metadata_requested;
/**
* If the current metadata was already sent to the client.
*/
bool metadata_sent;
/**
* The amount of streaming data between each metadata block
*/
guint metaint;
/**
* The metadata as #page which is currently being sent to the client.
*/
page *metadata;
/*
* The amount of bytes which were already sent from the metadata.
*/
size_t metadata_current_position;
/**
* The amount of streaming data sent to the client
* since the last icy information was sent.
*/
guint metadata_fill;
public:
/**
* @param httpd the HTTP output device
* @param fd the socket file descriptor
*/
HttpdClient(httpd_output *httpd, int _fd, bool _metadata_supported);
/**
* Note: this does not remove the client from the
* #httpd_output object.
*/
~HttpdClient();
/**
* Frees the client and removes it from the server's client list.
*/
void Close();
void LockClose();
/**
* Returns the total size of this client's page queue.
*/
gcc_pure
size_t GetQueueSize() const;
/**
* Clears the page queue.
*/
void CancelQueue();
bool Read();
/**
* Data has been received from the client and it is appended
* to the input buffer.
*/
bool Received();
/**
* Check if a complete line of input is present in the input
* buffer, and duplicates it. It is removed from the input
* buffer. The return value has to be freed with g_free().
*/
char *ReadLine();
/**
* Handle a line of the HTTP request.
*/
bool HandleLine(const char *line);
/**
* Switch the client to the "RESPONSE" state.
*/
void BeginResponse();
/**
* Sends the status line and response headers to the client.
*/
bool SendResponse();
gcc_pure
int GetBytesTillMetaData() const;
bool Write();
/**
* Appends a page to the client's queue.
*/
void PushPage(page *page);
/**
* Sends the passed metadata.
*/
void PushMetaData(page *page);
};
#endif
......@@ -25,14 +25,18 @@
#ifndef MPD_OUTPUT_HTTPD_INTERNAL_H
#define MPD_OUTPUT_HTTPD_INTERNAL_H
#include "HttpdClient.hxx"
#include "output_internal.h"
#include "timer.h"
#include "thread/Mutex.hxx"
#include <glib.h>
#include <forward_list>
#include <stdbool.h>
struct httpd_client;
class HttpdClient;
struct httpd_output {
struct audio_output base;
......@@ -65,7 +69,7 @@ struct httpd_output {
* This mutex protects the listener socket and the client
* list.
*/
GMutex *mutex;
mutable Mutex mutex;
/**
* A #timer object to synchronize this output with the
......@@ -105,7 +109,7 @@ struct httpd_output {
* A linked list containing all clients which are currently
* connected.
*/
GList *clients;
std::forward_list<HttpdClient> clients;
/**
* A temporary buffer for the httpd_output_read_page()
......@@ -125,7 +129,7 @@ struct httpd_output {
*/
void
httpd_output_remove_client(struct httpd_output *httpd,
struct httpd_client *client);
HttpdClient *client);
/**
* Sends the encoder header to the client. This is called right after
......@@ -133,6 +137,6 @@ httpd_output_remove_client(struct httpd_output *httpd,
*/
void
httpd_output_send_header(struct httpd_output *httpd,
struct httpd_client *client);
HttpdClient *client);
#endif
/*
* Copyright (C) 2003-2011 The Music Player Daemon Project
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
......@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_HTTPD_OUTPUT_PLUGIN_H
#define MPD_HTTPD_OUTPUT_PLUGIN_H
#ifndef MPD_HTTPD_OUTPUT_PLUGIN_HXX
#define MPD_HTTPD_OUTPUT_PLUGIN_HXX
extern const struct audio_output_plugin httpd_output_plugin;
......
/*
* Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_OUTPUT_HTTPD_CLIENT_H
#define MPD_OUTPUT_HTTPD_CLIENT_H
#include <stdbool.h>
#include <stddef.h>
struct httpd_client;
struct httpd_output;
struct page;
/**
* Creates a new #httpd_client object
*
* @param httpd the HTTP output device
* @param fd the socket file descriptor
*/
struct httpd_client *
httpd_client_new(struct httpd_output *httpd, int fd, bool metadata_supported);
/**
* Frees memory and resources allocated by the #httpd_client object.
* This does not remove it from the #httpd_output object.
*/
void
httpd_client_free(struct httpd_client *client);
/**
* Returns the total size of this client's page queue.
*/
size_t
httpd_client_queue_size(const struct httpd_client *client);
/**
* Clears the page queue.
*/
void
httpd_client_cancel(struct httpd_client *client);
/**
* Appends a page to the client's queue.
*/
void
httpd_client_send(struct httpd_client *client, struct page *page);
/**
* Sends the passed metadata.
*/
void
httpd_client_send_metadata(struct httpd_client *client, struct page *page);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment