From ca83183166cfcc9e6cfa412a2d870746e9dad5ae Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 7 Oct 2007 15:32:54 +0100 Subject: [PATCH] rtp-address command allows client to query server config Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/disorder.c | 10 ++++++++++ doc/disorder.1.in | 5 ++++- doc/disorder_protocol.5.in | 8 ++++---- lib/client.c | 17 +++++++++++++++++ lib/client.h | 2 ++ server/server.c | 13 +++++++++++++ 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 5ccb625..156a02d 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -399,6 +399,14 @@ static void cf_new(disorder_client *c, xprintf("%s\n", nullcheck(utf82mb(*vec++))); } +static void cf_rtp_address(disorder_client *c, + char attribute((unused)) **argv) { + char *address, *port; + + if(disorder_rtp_address(c, &address, &port)) exit(EXIT_FAILURE); + xprintf("address: %s\nport: %s\n", address, port); +} + static const struct command { const char *name; int min, max; @@ -467,6 +475,8 @@ static const struct command { "Resolve alias for TRACK" }, { "resume", 0, 0, cf_resume, 0, "", "Resume after a pause" }, + { "rtp-address", 0, 0, cf_rtp_address, 0, "", + "Report server's broadcast address" }, { "scratch", 0, 0, cf_scratch, 0, "", "Scratch the currently playing track" }, { "scratch-id", 1, 1, cf_scratch, 0, "ID", diff --git a/doc/disorder.1.in b/doc/disorder.1.in index 4e6e184..a05ca8c 100644 --- a/doc/disorder.1.in +++ b/doc/disorder.1.in @@ -152,6 +152,9 @@ Resolve aliases for \fITRACK\fR and print out the real track name. .B resume Resume the current track after a pause. .TP +.B rtp-address +Report the RTP brodcast address used by the server (if any). +.TP .B scratch Scratch the currently playing track. .TP @@ -168,7 +171,7 @@ for example: You can limit the search to tracks with a particular tag, too, using the \fBtag:\fR modifier. For example: .IP -.B "disorder search 'love tag:depressing' +.B "disorder search 'love tag:depressing'" .TP .B set \fITRACK\fR \fIKEY\fR \fIVALUE\fR Set the preference \fIKEY\fR for \fITRACK\fR to \fIVALUE\fR. diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index ef18bb9..4fe53ce 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -192,6 +192,10 @@ Resolve a track name, i.e. if this is an alias then return the real track name. .B resume Resume the current track after a \fBpause\fR command. .TP +.B rtp-address +Reports the RTP broadcast (or multicast) address, in the form \fIADDRESS +PORT\fR. +.TP .B scratch \fR[\fIID\fR] Remove the track identified by \fIID\fR, or the currently playing track if no \fIID\fR is specified. If \fBrestrict scratch\fR is enabled in the server's @@ -287,10 +291,6 @@ Text part is just commentary; a dot-stuffed body follows. Text part is just commentary; an indefinite dot-stuffed body follows. (Used for \fBlog\fR.) .TP -.B 4 -Text part is just commentary; an indefinite dot-stuffed body follows. (Used -for \fBlog\fR.) -.TP .B 9 The text part is just commentary (but would normally be a response for this command) e.g. \fBplaying\fR. diff --git a/lib/client.c b/lib/client.c index d68d9d7..27b7beb 100644 --- a/lib/client.c +++ b/lib/client.c @@ -629,6 +629,23 @@ int disorder_get_global(disorder_client *c, const char *key, char **valuep) { return disorder_simple(c, valuep, "get-global", key, (char *)0); } +int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) { + char *r; + int rc, n; + char **vec; + + if((rc = disorder_simple(c, &r, "rtp-address", (char *)0))) + return rc; + vec = split(r, &n, SPLIT_QUOTES, 0, 0); + if(n != 2) { + error(0, "malformed rtp-address reply"); + return -1; + } + *addressp = vec[0]; + *portp = vec[1]; + return 0; +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/client.h b/lib/client.h index 773c555..39a6830 100644 --- a/lib/client.h +++ b/lib/client.h @@ -186,6 +186,8 @@ int disorder_new_tracks(disorder_client *c, int max); /* get new tracks */ +int disorder_rtp_address(disorder_client *c, char **addressp, char **portp); + #endif /* CLIENT_H */ /* diff --git a/server/server.c b/server/server.c index c5fb010..4ba43a6 100644 --- a/server/server.c +++ b/server/server.c @@ -930,6 +930,18 @@ static int c_new(struct conn *c, } +static int c_rtp_address(struct conn *c, + char attribute((unused)) **vec, + int attribute((unused)) nvec) { + if(config->speaker_backend == BACKEND_NETWORK) { + sink_printf(ev_writer_sink(c->w), "252 %s %s\n", + quoteutf8(config->broadcast.s[0]), + quoteutf8(config->broadcast.s[1])); + } else + sink_writes(ev_writer_sink(c->w), "550 No RTP\n"); + return 1; +} + #define C_AUTH 0001 /* must be authenticated */ #define C_TRUSTED 0002 /* must be trusted user */ @@ -970,6 +982,7 @@ static const struct command { { "rescan", 0, 0, c_rescan, C_AUTH|C_TRUSTED }, { "resolve", 1, 1, c_resolve, C_AUTH }, { "resume", 0, 0, c_resume, C_AUTH }, + { "rtp-address", 0, 0, c_rtp_address, C_AUTH }, { "scratch", 0, 1, c_scratch, C_AUTH }, { "search", 1, 1, c_search, C_AUTH }, { "set", 3, 3, c_set, C_AUTH, }, -- [mdw]