From 435ad905b15bdad01dc3189bed5bf1d647ed1229 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 19 Jun 2014 11:46:31 +0200 Subject: [PATCH] Add sender subcommand "status". Currently, the si (server info) command prints information about each sender, like the number of connected clients and the access control lists. As this information is related to senders, the sender command seems to be a better fit. This commit introduces the new sender subcommand "status" for this purpose and changes com_si() to not print the sender information any more, making the output of com_si() bounded. It also renames the ->info() function of the senders to ->status() to make it clear that this function is related to the new status subcommand. The Networking paragraph of the manual is adjusted accordingly and now contains an example of the status command. --- command.c | 21 ++++++++------------- dccp_send.c | 14 +++++++------- http_send.c | 6 +++--- send.h | 4 ++-- send_common.c | 16 +++++++--------- server.cmd | 2 +- udp_send.c | 11 +++++------ web/manual.m4 | 20 +++++++++++++++----- 8 files changed, 48 insertions(+), 46 deletions(-) diff --git a/command.c b/command.c index 92002c34..585bb31c 100644 --- a/command.c +++ b/command.c @@ -344,7 +344,10 @@ static int com_sender(struct command_context *cc) if (ret < 0) { if (scd.sender_num < 0) return ret; - msg = senders[scd.sender_num].help(); + if (strcmp(cc->argv[2], "status") == 0) + msg = senders[scd.sender_num].status(); + else + msg = senders[scd.sender_num].help(); return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false); } @@ -374,17 +377,12 @@ static int com_sender(struct command_context *cc) /* server info */ static int com_si(struct command_context *cc) { - int i, ret; - char *msg, *ut, *sender_info = NULL; + int ret; + char *msg, *ut; if (cc->argc != 1) return -E_COMMAND_SYNTAX; mutex_lock(mmd_mutex); - for (i = 0; senders[i].name; i++) { - char *info = senders[i].info(); - sender_info = para_strcat(sender_info, info); - free(info); - } ut = get_server_uptime_str(now); ret = xasprintf(&msg, "up: %s\nplayed: %u\n" @@ -392,8 +390,7 @@ static int com_si(struct command_context *cc) "afs_pid: %d\n" "connections (active/accepted/total): %u/%u/%u\n" "current loglevel: %s\n" - "supported audio formats: %s\n" - "%s", + "supported audio formats: %s\n", ut, mmd->num_played, (int)getppid(), (int)mmd->afs_pid, @@ -401,12 +398,10 @@ static int com_si(struct command_context *cc) mmd->num_commands, mmd->num_connects, conf.loglevel_arg, - AUDIO_FORMAT_HANDLERS, - sender_info + AUDIO_FORMAT_HANDLERS ); mutex_unlock(mmd_mutex); free(ut); - free(sender_info); return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false); } diff --git a/dccp_send.c b/dccp_send.c index 1e95aac6..f80787d2 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -199,13 +199,13 @@ static const char *dccp_list_available_ccids(void) return list; } -static char *dccp_info(void) +static char *dccp_status(void) { - char *info = get_sender_info(dss, "dccp"); - char *ret = make_message("%s" "\tsupported ccids: %s\n", - info, dccp_list_available_ccids()); - free(info); - return ret; + char *status = generic_sender_status(dss, "dccp"); + char *result = make_message("%ssupported ccids: %s\n", status, + dccp_list_available_ccids()); + free(status); + return result; } /** @@ -220,7 +220,7 @@ void dccp_send_init(struct sender *s) { int ret, k, n; - s->info = dccp_info; + s->status = dccp_status; s->send = NULL; s->pre_select = dccp_pre_select; s->post_select = dccp_post_select; diff --git a/http_send.c b/http_send.c index 3e9c9539..aba61e9d 100644 --- a/http_send.c +++ b/http_send.c @@ -235,9 +235,9 @@ static int http_com_allow(struct sender_command_data *scd) return 1; } -static char *http_info(void) +static char *http_status(void) { - return get_sender_info(hss, "http"); + return generic_sender_status(hss, "http"); } /** @@ -251,7 +251,7 @@ static char *http_info(void) void http_send_init(struct sender *s) { int ret; - s->info = http_info; + s->status = http_status; s->send = http_send; s->pre_select = http_pre_select; s->post_select = http_post_select; diff --git a/send.h b/send.h index f577c9a7..0736b1bc 100644 --- a/send.h +++ b/send.h @@ -45,7 +45,7 @@ struct sender { * * The result must be dynamically allocated and is freed by the caller. */ - char* (*info)(void); + char* (*status)(void); /** * The send-hook. * @@ -179,7 +179,7 @@ void shutdown_client(struct sender_client *sc, struct sender_status *ss); void shutdown_clients(struct sender_status *ss); void init_sender_status(struct sender_status *ss, char **access_arg, int num_access_args, int port, int max_clients, int default_deny); -char *get_sender_info(struct sender_status *ss, const char *name); +char *generic_sender_status(struct sender_status *ss, const char *name); void generic_com_allow(struct sender_command_data *scd, struct sender_status *ss); diff --git a/send_common.c b/send_common.c index 0baac3a6..f75b9a07 100644 --- a/send_common.c +++ b/send_common.c @@ -159,7 +159,7 @@ void init_sender_status(struct sender_status *ss, char **access_arg, * * \return The string printed in the "si" command. */ -char *get_sender_info(struct sender_status *ss, const char *name) +char *generic_sender_status(struct sender_status *ss, const char *name) { char *clnts = NULL, *ret; struct sender_client *sc, *tmp_sc; @@ -171,14 +171,12 @@ char *get_sender_info(struct sender_status *ss, const char *name) clnts = tmp; } ret = make_message( - "%s sender:\n" - "\tstatus: %s\n" - "\tport: %s\n" - "\tnumber of connected clients: %d\n" - "\tmaximal number of clients: %d%s\n" - "\tconnected clients: %s\n" - "\taccess %s list: %s\n", - name, + "status: %s\n" + "port: %s\n" + "number of connected clients: %d\n" + "maximal number of clients: %d%s\n" + "connected clients: %s\n" + "access %s list: %s\n", (ss->listen_fd >= 0)? "on" : "off", stringify_port(ss->port, strcmp(name, "http") ? "dccp" : "tcp"), ss->num_clients, diff --git a/server.cmd b/server.cmd index eba992f8..ebe372b7 100644 --- a/server.cmd +++ b/server.cmd @@ -75,7 +75,7 @@ U: sender [s cmd [arguments]] H: Send a command to a specific sender. The following commands are available, but H: not all senders support every command. H: -H: help, on, off, add, delete, allow, deny. +H: help, on, off, add, delete, allow, deny, status. H: H: The help command prints the help text of the given sender. If no command is H: given the list of compiled in senders is shown. diff --git a/udp_send.c b/udp_send.c index 6ed5026a..4315b7d7 100644 --- a/udp_send.c +++ b/udp_send.c @@ -355,7 +355,7 @@ err: return ret; } -static char *udp_info(void) +static char *udp_status(void) { struct sender_client *sc; char *ret, *tgts = NULL; @@ -371,10 +371,9 @@ static char *udp_info(void) tgts = tmp; } ret = make_message( - "udp sender:\n" - "\tstatus: %s\n" - "\tport: %s\n" - "\ttargets: %s\n", + "status: %s\n" + "port: %s\n" + "targets: %s\n", (sender_status == SENDER_ON)? "on" : "off", stringify_port(conf.udp_default_port_arg, "udp"), tgts? tgts : "(none)" @@ -427,7 +426,7 @@ static char *udp_help(void) void udp_send_init(struct sender *s) { INIT_LIST_HEAD(&targets); - s->info = udp_info; + s->status = udp_status; s->help = udp_help; s->send = NULL; s->pre_select = NULL; diff --git a/web/manual.m4 b/web/manual.m4 index 73eafbb4..50b2d46c 100644 --- a/web/manual.m4 +++ b/web/manual.m4 @@ -1452,15 +1452,21 @@ the stream. Examples ~~~~~~~~ -The sender command of para_server allows to (de-)activate senders -and to change the access permissions senders at runtime. The "si" -(server info) command is used to list the streaming options of the -currently running server as well as the various sender access lists. +The "si" (server info) command lists some information about the +currently running server process. --> Show client/target/access lists: +-> Show PIDs, number of connected clients, uptime, and more: para_client si +The sender command of para_server prints information about senders, +like the various access control lists, and it allows to (de-)activate +senders and to change the access permissions at runtime. + +-> List all senders + + para_client sender + -> Obtain general help for the sender command: para_client help sender @@ -1470,6 +1476,10 @@ currently running server as well as the various sender access lists. s=http # or dccp or udp para_client sender $s help +-> Show status of the http sender + + para_client sender http status + By default para_server activates both the HTTP and th DCCP sender on startup. This can be changed via command line options or para_server's config file. -- 2.39.5