* Licensed under the GPL v2. For licencing details see COPYING.
*/
-/** \file command.c does client authentication and executes server commands */
+/** \file command.c Client authentication and server commands. */
#include <signal.h>
#include <sys/time.h>
#include "server_command_list.h"
#include "afs_command_list.h"
-/** commands including options must be shorter than this */
+/** Commands including options must be shorter than this. */
#define MAX_COMMAND_LEN 32768
static RC4_KEY rc4_recv_key;
return msg;
}
-/*
- * compute status bar string. Never returns NULL
- */
-static char *get_sb_string(struct misc_meta_data *nmmd)
-{
- char *base, *ret;
- long long unsigned secs = 0, rsecs = 0, percent = 0;
-
- base = para_basename(nmmd->filename);
- if (!base)
- return para_strdup("");
- if (!base[0])
- return base;
- if (nmmd->afi.chunks_total) {
- secs = (long long) nmmd->afi.seconds_total * nmmd->chunks_sent
- / nmmd->afi.chunks_total;
- rsecs = (long long) nmmd->afi.seconds_total *
- (nmmd->afi.chunks_total - nmmd->chunks_sent)
- / nmmd->afi.chunks_total;
- percent = 100 * ((nmmd->chunks_sent + 5) / 10)
- / ((nmmd->afi.chunks_total + 5) / 10);
- }
- ret = make_message("%llu:%02llu [%llu:%02llu] (%llu%%) %s",
- secs / 60, secs % 60,
- rsecs / 60, rsecs % 60,
- percent,
- base
- );
- free(base);
- return ret;
-}
-
static char *get_status(struct misc_meta_data *nmmd)
{
char *bar, *ret, mtime[30] = "";
ret = make_message(
"%s:%zu\n" "%s:%s\n" "%s:%lu\n" "%s:%u\n"
"%s:%s\n" "%s:%s\n" "%s:%s\n" "%s:%s\n"
- "%s:%li\n" "%s:%s\n" "%s"
+ "%s:%li\n" "%s:%s\n" "%s:%s\n" "%s"
"%s:%s\n" "%s:%lu.%lu\n" "%s:%lu.%lu\n",
status_item_list[SI_FILE_SIZE], nmmd->size / 1024,
status_item_list[SI_MTIME], mtime,
status_item_list[SI_OFFSET], offset,
status_item_list[SI_FORMAT], audio_format_name(nmmd->audio_format),
+ status_item_list[SI_AFS_MODE], mmd->afs_mode_string,
nmmd->afi.info_string,
status_item_list[SI_UPTIME], ut,
);
}
-/* sc */
-int com_sc(int fd, int argc, char * const * argv)
-{
- char *name = NULL;
- int ret, old = 0, count = -1; /* print af change forever */
-
- if (argc > 1)
- count = atoi(argv[1]);
-repeat:
- mmd_lock();
- if (old != mmd->num_played) {
- old = mmd->num_played;
- name = para_strdup(mmd->filename);
- }
- mmd_unlock();
- if (name) {
- ret = send_va_buffer(fd, "%s\n", name);
- free(name);
- name = NULL;
- if (ret < 0)
- return ret;
- if (argc > 1 && !--count)
- return 1;
- }
- usleep(500000);
- goto repeat;
-}
-
-/* sb */
-int com_sb(int fd, int argc, char * const * argv)
-{
- char *sb;
- int ret, nr = -1; /* status bar will be printed that many
- * times. Negative value means: print
- * forever
- */
- if (argc > 1)
- nr = atoi(argv[1]);
- while (nr) {
- mmd_lock();
- sb = get_sb_string(mmd);
- mmd_unlock();
- ret = send_va_buffer(fd, "%s\n", sb);
- free(sb);
- if (ret < 0)
- return ret;
- if (nr == 1)
- return 1;
- usleep(500000);
- if (nr > 0)
- nr--;
- }
- return 1;
-}
-
/* stat */
int com_stat(int fd, int argc, char * const * argv)
{
return 1;
}
-/* always returns string that must be freed by the caller in handler */
+/* returns string that must be freed by the caller */
static struct server_command *get_cmd_ptr(const char *name, char **handler)
{
struct server_command *cmd;