X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.c;h=f1f00fca8a29add0e35a2e415a927bdeb75c4376;hp=f9bace34146e28ccaf7b0632e0fa34ede51de8aa;hb=a37f31bbe4f1b2745ef0f617cff122a2c5f95078;hpb=c4bfb18b78b3935b8dbf68f70b219cfb2a192979 diff --git a/command.c b/command.c index f9bace34..f1f00fca 100644 --- a/command.c +++ b/command.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2012 Andre Noll + * Copyright (C) 1997-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -124,7 +123,7 @@ static unsigned get_status(struct misc_meta_data *nmmd, int parser_friendly, localtime_r(&nmmd->mtime, &mtime_tm); strftime(mtime, 29, "%b %d %Y", &mtime_tm); } - gettimeofday(¤t_time, NULL); + clock_get_realtime(¤t_time); /* * The calls to WRITE_STATUS_ITEM() below never fail because * b->max_size is zero (unlimited), see para_printf(). However, clang @@ -157,7 +156,7 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL}; scd->sender_num = -1; - if (argc < 2) + if (argc < 3) return -E_COMMAND_SYNTAX; for (i = 0; senders[i].name; i++) if (!strcmp(senders[i].name, argv[1])) @@ -259,6 +258,14 @@ __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band, return send_sb(scc, msg, ret, band, false); } +/** + * Send an error message to a client. + * + * \param cc Client info. + * \param err The (positive) error code. + * + * \return The return value of the underlying call to send_sb_va(). + */ int send_strerror(struct command_context *cc, int err) { return cc->use_sideband? @@ -388,7 +395,8 @@ static int com_si(struct command_context *cc) free(info); } ut = get_server_uptime_str(now); - ret = xasprintf(&msg, "version: " GIT_VERSION "\n" + ret = xasprintf(&msg, + "version: %s\n" "up: %s\nplayed: %u\n" "server_pid: %d\n" "afs_pid: %d\n" @@ -396,6 +404,7 @@ static int com_si(struct command_context *cc) "current loglevel: %s\n" "supported audio formats: %s\n" "%s", + version_git(), ut, mmd->num_played, (int)getppid(), (int)mmd->afs_pid, @@ -403,7 +412,7 @@ static int com_si(struct command_context *cc) mmd->num_commands, mmd->num_connects, conf.loglevel_arg, - SERVER_AUDIO_FORMATS, + AUDIO_FORMAT_HANDLERS, sender_info ); mutex_unlock(mmd_mutex); @@ -424,14 +433,13 @@ static int com_version(struct command_context *cc) if (cc->argc != 1) return -E_COMMAND_SYNTAX; - msg = VERSION_TEXT("server") "built: " BUILD_DATE "\n" UNAME_RS - ", " CC_VERSION "\n"; - len = strlen(msg); + len = xasprintf(&msg, "%s", version_text("server")); if (cc->use_sideband) - return send_sb(&cc->scc, msg, len, SBD_OUTPUT, true); + return send_sb(&cc->scc, msg, len, SBD_OUTPUT, false); return sc_send_bin_buffer(&cc->scc, msg, len); } +/** These status items are cleared if no audio file is currently open. */ #define EMPTY_STATUS_ITEMS \ ITEM(PATH) \ ITEM(DIRECTORY) \ @@ -458,7 +466,11 @@ static int com_version(struct command_context *cc) ITEM(YEAR) \ ITEM(ALBUM) \ ITEM(COMMENT) \ - ITEM(AMPLIFICATION) + ITEM(MTIME) \ + ITEM(FILE_SIZE) \ + ITEM(CHUNK_TIME) \ + ITEM(NUM_CHUNKS) \ + ITEM(AMPLIFICATION) \ /** * Write a list of audio-file related status items with empty values. @@ -467,11 +479,8 @@ static int com_version(struct command_context *cc) */ static unsigned empty_status_items(int parser_friendly, char **result) { - static char *esi; - static unsigned len; - - if (esi) - goto out; + char *esi; + unsigned len; if (parser_friendly) len = xasprintf(&esi, @@ -491,7 +500,6 @@ static unsigned empty_status_items(int parser_friendly, char **result) EMPTY_STATUS_ITEMS #undef ITEM ); -out: *result = esi; return len; } @@ -502,7 +510,7 @@ static int com_stat(struct command_context *cc) { int i, ret; struct misc_meta_data tmp, *nmmd = &tmp; - char *s, *esi = NULL; + char *s; int32_t num = 0; int parser_friendly = 0; @@ -542,12 +550,15 @@ static int com_stat(struct command_context *cc) if (ret < 0) goto out; if (nmmd->vss_status_flags & VSS_NEXT) { + char *esi; ret = empty_status_items(parser_friendly, &esi); if (cc->use_sideband) ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT, - true); - else + false); + else { ret = sc_send_bin_buffer(&cc->scc, esi, ret); + free(esi); + } if (ret < 0) goto out; } else @@ -561,7 +572,6 @@ static int com_stat(struct command_context *cc) goto out; } out: - free(esi); return ret; } @@ -984,7 +994,7 @@ __noreturn void handle_connect(int fd, const char *peername) /* send Welcome message */ ret = write_va_buffer(fd, "This is para_server, version " PACKAGE_VERSION ".\n" - "Features: sideband,foo\n" + "Features: sideband\n" ); if (ret < 0) goto net_err;