summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/protocol-http.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulsecore/protocol-http.c')
-rw-r--r--src/pulsecore/protocol-http.c73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/pulsecore/protocol-http.c b/src/pulsecore/protocol-http.c
index 3b1207f6..03990435 100644
--- a/src/pulsecore/protocol-http.c
+++ b/src/pulsecore/protocol-http.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2005-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
-
+
PulseAudio 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 Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -23,7 +23,6 @@
#include <config.h>
#endif
-#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -32,6 +31,7 @@
#include <pulse/xmalloc.h>
#include <pulsecore/ioline.h>
+#include <pulsecore/macro.h>
#include <pulsecore/log.h>
#include <pulsecore/namereg.h>
#include <pulsecore/cli-text.h>
@@ -63,11 +63,12 @@ struct pa_protocol_http {
static void http_response(struct connection *c, int code, const char *msg, const char *mime) {
char s[256];
- assert(c);
- assert(msg);
- assert(mime);
- snprintf(s, sizeof(s),
+ pa_assert(c);
+ pa_assert(msg);
+ pa_assert(mime);
+
+ pa_snprintf(s, sizeof(s),
"HTTP/1.0 %i %s\n"
"Connection: close\n"
"Content-Type: %s\n"
@@ -81,14 +82,14 @@ static void http_response(struct connection *c, int code, const char *msg, const
static void http_message(struct connection *c, int code, const char *msg, const char *text) {
char s[256];
- assert(c);
+ pa_assert(c);
http_response(c, code, msg, "text/html");
if (!text)
text = msg;
- snprintf(s, sizeof(s),
+ pa_snprintf(s, sizeof(s),
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>%s</title></head>\n"
@@ -101,21 +102,22 @@ static void http_message(struct connection *c, int code, const char *msg, const
static void connection_free(struct connection *c, int del) {
- assert(c);
+ pa_assert(c);
if (c->url)
pa_xfree(c->url);
if (del)
pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
+
pa_ioline_unref(c->line);
pa_xfree(c);
}
static void line_callback(pa_ioline *line, const char *s, void *userdata) {
struct connection *c = userdata;
- assert(line);
- assert(c);
+ pa_assert(line);
+ pa_assert(c);
if (!s) {
/* EOF */
@@ -137,16 +139,16 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
}
case MIME_HEADER: {
-
+
/* Ignore MIME headers */
if (strcspn(s, " \r\n") != 0)
break;
-
+
/* We're done */
c->state = DATA;
pa_log_info("request for %s", c->url);
-
+
if (!strcmp(c->url, URL_ROOT)) {
char txt[256];
http_response(c, 200, "OK", "text/html");
@@ -164,22 +166,22 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
#define PRINTF_FIELD(a,b) pa_ioline_printf(c->line, "<tr><td><b>%s</b></td><td>%s</td></tr>\n",(a),(b))
PRINTF_FIELD("User Name:", pa_get_user_name(txt, sizeof(txt)));
- PRINTF_FIELD("Fully Qualified Domain Name:", pa_get_fqdn(txt, sizeof(txt)));
+ PRINTF_FIELD("Host name:", pa_get_host_name(txt, sizeof(txt)));
PRINTF_FIELD("Default Sample Specification:", pa_sample_spec_snprint(txt, sizeof(txt), &c->protocol->core->default_sample_spec));
PRINTF_FIELD("Default Sink:", pa_namereg_get_default_sink_name(c->protocol->core));
PRINTF_FIELD("Default Source:", pa_namereg_get_default_source_name(c->protocol->core));
-
+
pa_ioline_puts(c->line, "</table>");
pa_ioline_puts(c->line, "<p><a href=\"/status\">Click here</a> for an extensive server status report.</p>");
-
+
pa_ioline_puts(c->line, "</body></html>\n");
-
- pa_ioline_defer_close(c->line);
+
+ pa_ioline_defer_close(c->line);
} else if (!strcmp(c->url, URL_CSS)) {
http_response(c, 200, "OK", "text/css");
- pa_ioline_puts(c->line,
+ pa_ioline_puts(c->line,
"body { color: black; background-color: white; margin: 0.5cm; }\n"
"a:link, a:visited { color: #900000; }\n"
"p { margin-left: 0.5cm; margin-right: 0.5cm; }\n"
@@ -207,13 +209,13 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
break;
}
-
+
default:
;
}
return;
-
+
fail:
internal_server_error(c);
}
@@ -221,7 +223,10 @@ fail:
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
pa_protocol_http *p = userdata;
struct connection *c;
- assert(s && io && p);
+
+ pa_assert(s);
+ pa_assert(io);
+ pa_assert(p);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@@ -229,7 +234,7 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
return;
}
- c = pa_xmalloc(sizeof(struct connection));
+ c = pa_xnew(struct connection, 1);
c->protocol = p;
c->line = pa_ioline_new(io);
c->state = REQUEST_LINE;
@@ -241,12 +246,14 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
pa_protocol_http* p;
- assert(core && server);
- p = pa_xmalloc(sizeof(pa_protocol_http));
+ pa_core_assert_ref(core);
+ pa_assert(server);
+
+ p = pa_xnew(pa_protocol_http, 1);
p->module = m;
p->core = core;
- p->server = server;
+ p->server = pa_socket_server_ref(server);
p->connections = pa_idxset_new(NULL, NULL);
pa_socket_server_set_callback(p->server, on_connection, p);
@@ -255,12 +262,12 @@ pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server,
}
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
- assert(p);
+ pa_assert(p);
connection_free(p, 0);
}
void pa_protocol_http_free(pa_protocol_http *p) {
- assert(p);
+ pa_assert(p);
pa_idxset_free(p->connections, free_connection, NULL);
pa_socket_server_unref(p->server);