From 8dfdfd4e1be6359dc49a44539699c1383ff2b46a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 30 Apr 2009 01:35:18 +0200 Subject: http: export information about currently active server strings --- src/modules/module-protocol-stub.c | 38 +++++++++++++++++++++++++++++++++++++- src/pulsecore/protocol-http.c | 29 ++++++++++++++++++++++++++++- src/pulsecore/protocol-http.h | 6 +++++- 3 files changed, 70 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index ce3dcd03..5b351d19 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -251,7 +251,7 @@ int pa__init(pa_module*m) { int r; #endif -#if defined(USE_PROTOCOL_NATIVE) +#if defined(USE_PROTOCOL_NATIVE) || defined(USE_PROTOCOL_HTTP) char t[256]; #endif @@ -382,6 +382,24 @@ int pa__init(pa_module*m) { # endif #endif +#if defined(USE_PROTOCOL_HTTP) +#if defined(USE_TCP_SOCKETS) + if (u->socket_server_ipv4) + if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t))) + pa_http_protocol_add_server_string(u->http_protocol, t); + +#ifdef HAVE_IPV6 + if (u->socket_server_ipv6) + if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t))) + pa_http_protocol_add_server_string(u->http_protocol, t); +#endif /* HAVE_IPV6 */ +#else /* USE_TCP_SOCKETS */ + if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t))) + pa_http_protocol_add_server_string(u->http_protocol, t); + +#endif /* USE_TCP_SOCKETS */ +#endif /* USE_PROTOCOL_HTTP */ + if (ma) pa_modargs_free(ma); @@ -419,6 +437,24 @@ void pa__done(pa_module*m) { } #elif defined(USE_PROTOCOL_HTTP) if (u->http_protocol) { + char t[256]; + +#if defined(USE_TCP_SOCKETS) + if (u->socket_server_ipv4) + if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t))) + pa_http_protocol_remove_server_string(u->http_protocol, t); + +#ifdef HAVE_IPV6 + if (u->socket_server_ipv6) + if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t))) + pa_http_protocol_remove_server_string(u->http_protocol, t); +#endif /* HAVE_IPV6 */ +#else /* USE_TCP_SOCKETS */ + if (u->socket_server_unix) + if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t))) + pa_http_protocol_remove_server_string(u->http_protocol, t); +#endif /* USE_PROTOCOL_HTTP */ + pa_http_protocol_disconnect(u->http_protocol, u->module); pa_http_protocol_unref(u->http_protocol); } diff --git a/src/pulsecore/protocol-http.c b/src/pulsecore/protocol-http.c index 46850b28..b5d75301 100644 --- a/src/pulsecore/protocol-http.c +++ b/src/pulsecore/protocol-http.c @@ -97,6 +97,8 @@ struct pa_http_protocol { pa_core *core; pa_idxset *connections; + + pa_strlist *servers; }; enum { @@ -698,7 +700,7 @@ static pa_http_protocol* http_protocol_new(pa_core *c) { pa_assert(c); - p = pa_xnew(pa_http_protocol, 1); + p = pa_xnew0(pa_http_protocol, 1); PA_REFCNT_INIT(p); p->core = c; p->connections = pa_idxset_new(NULL, NULL); @@ -740,7 +742,32 @@ void pa_http_protocol_unref(pa_http_protocol *p) { pa_idxset_free(p->connections, NULL, NULL); + pa_strlist_free(p->servers); + pa_assert_se(pa_shared_remove(p->core, "http-protocol") >= 0); pa_xfree(p); } + +void pa_http_protocol_add_server_string(pa_http_protocol *p, const char *name) { + pa_assert(p); + pa_assert(PA_REFCNT_VALUE(p) >= 1); + pa_assert(name); + + p->servers = pa_strlist_prepend(p->servers, name); +} + +void pa_http_protocol_remove_server_string(pa_http_protocol *p, const char *name) { + pa_assert(p); + pa_assert(PA_REFCNT_VALUE(p) >= 1); + pa_assert(name); + + p->servers = pa_strlist_remove(p->servers, name); +} + +pa_strlist *pa_http_protocol_servers(pa_http_protocol *p) { + pa_assert(p); + pa_assert(PA_REFCNT_VALUE(p) >= 1); + + return p->servers; +} diff --git a/src/pulsecore/protocol-http.h b/src/pulsecore/protocol-http.h index 40b3d82c..f7517e81 100644 --- a/src/pulsecore/protocol-http.h +++ b/src/pulsecore/protocol-http.h @@ -26,7 +26,7 @@ #include #include #include - +#include typedef struct pa_http_protocol pa_http_protocol; @@ -36,4 +36,8 @@ void pa_http_protocol_unref(pa_http_protocol *p); void pa_http_protocol_connect(pa_http_protocol *p, pa_iochannel *io, pa_module *m); void pa_http_protocol_disconnect(pa_http_protocol *p, pa_module *m); +void pa_http_protocol_add_server_string(pa_http_protocol *p, const char *name); +void pa_http_protocol_remove_server_string(pa_http_protocol *p, const char *name); +pa_strlist *pa_http_protocol_servers(pa_http_protocol *p); + #endif -- cgit