mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
* extend HTTP module
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@340 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
4590f09d0b
commit
f586ce0842
5 changed files with 84 additions and 50 deletions
2
doc/todo
2
doc/todo
|
|
@ -16,7 +16,7 @@ Fixes:
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
- add radio module
|
- add radio module
|
||||||
- xmlrpc/http
|
- xmlrpc
|
||||||
- dbus/hal
|
- dbus/hal
|
||||||
- rendezvous autotunnel module
|
- rendezvous autotunnel module
|
||||||
- polish for starting polypaudio as root/system-wide instance
|
- polish for starting polypaudio as root/system-wide instance
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
#include "sample-util.h"
|
#include "sample-util.h"
|
||||||
#include "scache.h"
|
#include "scache.h"
|
||||||
#include "autoload.h"
|
#include "autoload.h"
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
char *pa_module_list_to_string(struct pa_core *c) {
|
char *pa_module_list_to_string(struct pa_core *c) {
|
||||||
struct pa_strbuf *s;
|
struct pa_strbuf *s;
|
||||||
|
|
@ -306,3 +307,46 @@ char *pa_autoload_list_to_string(struct pa_core *c) {
|
||||||
|
|
||||||
return pa_strbuf_tostring_free(s);
|
return pa_strbuf_tostring_free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *pa_full_status_string(struct pa_core *c) {
|
||||||
|
struct pa_strbuf *s;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
s = pa_strbuf_new();
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
char *t = NULL;
|
||||||
|
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
t = pa_sink_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
t = pa_source_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
t = pa_sink_input_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
t = pa_source_output_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
t = pa_client_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
t = pa_module_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
t = pa_scache_list_to_string(c);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
t = pa_autoload_list_to_string(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_strbuf_puts(s, t);
|
||||||
|
pa_xfree(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pa_strbuf_tostring_free(s);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,7 @@ char *pa_module_list_to_string(struct pa_core *c);
|
||||||
char *pa_scache_list_to_string(struct pa_core *c);
|
char *pa_scache_list_to_string(struct pa_core *c);
|
||||||
char *pa_autoload_list_to_string(struct pa_core *c);
|
char *pa_autoload_list_to_string(struct pa_core *c);
|
||||||
|
|
||||||
|
char *pa_full_status_string(struct pa_core *c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
45
polyp/main.c
45
polyp/main.c
|
|
@ -71,49 +71,16 @@ static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e,
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
pa_module_load(userdata, "module-cli", NULL);
|
pa_module_load(userdata, "module-cli", NULL);
|
||||||
return;
|
break;
|
||||||
|
|
||||||
case SIGUSR2:
|
case SIGUSR2:
|
||||||
pa_module_load(userdata, "module-cli-protocol-unix", NULL);
|
pa_module_load(userdata, "module-cli-protocol-unix", NULL);
|
||||||
return;
|
break;
|
||||||
|
|
||||||
case SIGHUP: {
|
case SIGHUP: {
|
||||||
int i;
|
char *c = pa_full_status_string(userdata);
|
||||||
|
pa_log_notice(c);
|
||||||
for (i = 0;; i++) {
|
pa_xfree(c);
|
||||||
char *c;
|
|
||||||
switch (i) {
|
|
||||||
case 0:
|
|
||||||
c = pa_sink_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
c = pa_source_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
c = pa_sink_input_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
c = pa_source_output_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
c = pa_client_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
c = pa_module_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
c = pa_scache_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
c = pa_autoload_list_to_string(userdata);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pa_log_notice(c);
|
|
||||||
pa_xfree(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +89,7 @@ static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e,
|
||||||
default:
|
default:
|
||||||
pa_log_info(__FILE__": Exiting.\n");
|
pa_log_info(__FILE__": Exiting.\n");
|
||||||
m->quit(m, 1);
|
m->quit(m, 1);
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "namereg.h"
|
#include "namereg.h"
|
||||||
|
#include "cli-text.h"
|
||||||
|
|
||||||
/* Don't allow more than this many concurrent connections */
|
/* Don't allow more than this many concurrent connections */
|
||||||
#define MAX_CONNECTIONS 10
|
#define MAX_CONNECTIONS 10
|
||||||
|
|
@ -40,7 +41,8 @@
|
||||||
#define internal_server_error(c) http_message((c), 500, "Internal Server Error", NULL)
|
#define internal_server_error(c) http_message((c), 500, "Internal Server Error", NULL)
|
||||||
|
|
||||||
#define URL_ROOT "/"
|
#define URL_ROOT "/"
|
||||||
#define URL_CSS "/style.css"
|
#define URL_CSS "/style"
|
||||||
|
#define URL_STATUS "/status"
|
||||||
|
|
||||||
struct connection {
|
struct connection {
|
||||||
struct pa_protocol_http *protocol;
|
struct pa_protocol_http *protocol;
|
||||||
|
|
@ -66,6 +68,9 @@ static void http_response(struct connection *c, int code, const char *msg, const
|
||||||
"HTTP/1.0 %i %s\n"
|
"HTTP/1.0 %i %s\n"
|
||||||
"Connection: close\n"
|
"Connection: close\n"
|
||||||
"Content-Type: %s\n"
|
"Content-Type: %s\n"
|
||||||
|
"Cache-Control: no-cache\n"
|
||||||
|
"Expires: 0\n"
|
||||||
|
"Server: "PACKAGE_NAME"/"PACKAGE_VERSION"\n"
|
||||||
"\n", code, msg, mime);
|
"\n", code, msg, mime);
|
||||||
|
|
||||||
pa_ioline_puts(c->line, s);
|
pa_ioline_puts(c->line, s);
|
||||||
|
|
@ -80,8 +85,10 @@ static void http_message(struct connection *c, int code, const char *msg, const
|
||||||
if (!text)
|
if (!text)
|
||||||
text = msg;
|
text = msg;
|
||||||
|
|
||||||
snprintf(s, sizeof(s),
|
snprintf(s, sizeof(s),
|
||||||
"<html><head><title>%s</title></head>\n"
|
"<?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"
|
||||||
"<body>%s</body></html>\n",
|
"<body>%s</body></html>\n",
|
||||||
text, text);
|
text, text);
|
||||||
|
|
||||||
|
|
@ -120,7 +127,7 @@ static void line_callback(struct pa_ioline *line, const char *s, void *userdata)
|
||||||
|
|
||||||
s +=4;
|
s +=4;
|
||||||
|
|
||||||
c->url = pa_xstrndup(s, strcspn(s, " \r\n\t"));
|
c->url = pa_xstrndup(s, strcspn(s, " \r\n\t?"));
|
||||||
c->state = MIME_HEADER;
|
c->state = MIME_HEADER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -135,19 +142,20 @@ static void line_callback(struct pa_ioline *line, const char *s, void *userdata)
|
||||||
/* We're done */
|
/* We're done */
|
||||||
c->state = DATA;
|
c->state = DATA;
|
||||||
|
|
||||||
pa_log("req for %s\n", c->url);
|
pa_log_info(__FILE__": request for %s\n", c->url);
|
||||||
|
|
||||||
if (!strcmp(c->url, URL_ROOT)) {
|
if (!strcmp(c->url, URL_ROOT)) {
|
||||||
char txt[256];
|
char txt[256];
|
||||||
http_response(c, 200, "OK", "text/html");
|
http_response(c, 200, "OK", "text/html");
|
||||||
|
|
||||||
pa_ioline_puts(c->line,
|
pa_ioline_puts(c->line,
|
||||||
"<html><head><title>"PACKAGE_NAME" "PACKAGE_VERSION"</title>\n"
|
"<?xml version=\"1.0\"?>\n"
|
||||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/></head><body>\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\"><title>"PACKAGE_NAME" "PACKAGE_VERSION"</title>\n"
|
||||||
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style\"/></head><body>\n");
|
||||||
|
|
||||||
pa_ioline_puts(c->line,
|
pa_ioline_puts(c->line,
|
||||||
"<h1>"PACKAGE_NAME" "PACKAGE_VERSION"</h1>\n"
|
"<h1>"PACKAGE_NAME" "PACKAGE_VERSION"</h1>\n"
|
||||||
"<h2>Server Information</h2>\n"
|
|
||||||
"<table>");
|
"<table>");
|
||||||
|
|
||||||
#define PRINTF_FIELD(a,b) pa_ioline_printf(c->line, "<tr><td><b>%s</b></td><td>%s</td></tr>\n",(a),(b))
|
#define PRINTF_FIELD(a,b) pa_ioline_printf(c->line, "<tr><td><b>%s</b></td><td>%s</td></tr>\n",(a),(b))
|
||||||
|
|
@ -157,7 +165,11 @@ static void line_callback(struct pa_ioline *line, const char *s, void *userdata)
|
||||||
PRINTF_FIELD("Default Sample Specification:", pa_sample_spec_snprint(txt, sizeof(txt), &c->protocol->core->default_sample_spec));
|
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 Sink:", pa_namereg_get_default_sink_name(c->protocol->core));
|
||||||
PRINTF_FIELD("Default Source:", pa_namereg_get_default_source_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, "</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_puts(c->line, "</body></html>\n");
|
||||||
|
|
||||||
pa_ioline_defer_close(c->line);
|
pa_ioline_defer_close(c->line);
|
||||||
|
|
@ -177,7 +189,16 @@ static void line_callback(struct pa_ioline *line, const char *s, void *userdata)
|
||||||
"table { margin-left: 1cm; border:1px solid lightgrey; padding: 0.2cm; }\n"
|
"table { margin-left: 1cm; border:1px solid lightgrey; padding: 0.2cm; }\n"
|
||||||
"td { padding-left:10px; padding-right:10px; }\n");
|
"td { padding-left:10px; padding-right:10px; }\n");
|
||||||
|
|
||||||
pa_ioline_defer_close(c->line);
|
pa_ioline_defer_close(c->line);
|
||||||
|
} else if (!strcmp(c->url, URL_STATUS)) {
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
http_response(c, 200, "OK", "text/plain");
|
||||||
|
s = pa_full_status_string(c->protocol->core);
|
||||||
|
pa_ioline_puts(c->line, s);
|
||||||
|
pa_xfree(s);
|
||||||
|
|
||||||
|
pa_ioline_defer_close(c->line);
|
||||||
} else
|
} else
|
||||||
http_message(c, 404, "Not Found", NULL);
|
http_message(c, 404, "Not Found", NULL);
|
||||||
|
|
||||||
|
|
@ -200,7 +221,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
||||||
assert(s && io && p);
|
assert(s && io && p);
|
||||||
|
|
||||||
if (pa_idxset_ncontents(p->connections)+1 > MAX_CONNECTIONS) {
|
if (pa_idxset_ncontents(p->connections)+1 > MAX_CONNECTIONS) {
|
||||||
pa_log(__FILE__": Warning! Too many connections (%u), dropping incoming connection.\n", MAX_CONNECTIONS);
|
pa_log_warn(__FILE__": Warning! Too many connections (%u), dropping incoming connection.\n", MAX_CONNECTIONS);
|
||||||
pa_iochannel_free(io);
|
pa_iochannel_free(io);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue