/** \file command.c does client authentication and executes server commands */
-
-#include <malloc.h> /* mallinfo */
#include <sys/time.h> /* gettimeofday */
#include "crypt.h"
#include "server.cmdline.h"
#include "send.h"
#include "rc4.h"
#include <openssl/rc4.h>
-#include "gcc-compat.h"
#include "error.h"
#include "net.h"
#include "daemon.h"
extern const char *status_item_list[NUM_STAT_ITEMS];
extern struct misc_meta_data *mmd;
extern struct gengetopt_args_info conf;
-extern struct dbtool dblist[];
-extern struct audio_format afl[];
+extern struct audio_file_selector selectors[];
extern struct sender senders[];
extern char *user_list;
struct sockaddr_in *in_addr;
static int com_pause(int, int, char **);
static int com_next(int, int, char **);
static int com_nomore(int, int, char **);
-static int com_cdt(int, int, char **);
+static int com_chs(int, int, char **);
static int com_ff(int, int, char **);
static int com_jmp(int, int, char **);
static int com_sender(int, int, char **);
/* commands that are handled by the server itself */
static struct server_command cmd_struct[] = {
{
-.name = "cdt",
-.handler = com_cdt,
+.name = "chs",
+.handler = com_chs,
.perms = DB_READ | DB_WRITE,
-.description = "change database tool",
-.synopsis = "cdt [name_of_new_dbtool]",
+.description = "change the current audio file selector",
+.synopsis = "chs [new_selector]",
.help =
-"Deactivate current dbtool and activate name_of_new_dbtool. If no\n"
-"argument was given, print the current database tool.\n"
+"Shutdown the current selector and activate new_selector. If no\n"
+"argument was given, print the name of the current selector.\n"
},
{
}
};
-static void dummy(__unused int s)
+static void dummy(__a_unused int s)
{}
static void mmd_dup(struct misc_meta_data *new_mmd)
return para_strdup("paused");
}
-
/*
* return human readable permission string. Never returns NULL.
*/
status_item_list[SI_STATUS_BAR], bar ? bar : "(none)",
status_item_list[SI_STATUS], status,
status_item_list[SI_STATUS_FLAGS], flags,
- status_item_list[SI_DBTOOL], dblist[nmmd->dbt_num].name,
+ status_item_list[SI_SELECTOR], selectors[nmmd->selector_num].name,
status_item_list[SI_OFFSET], offset,
status_item_list[SI_FORMAT], audio_format_name(nmmd->audio_format),
- nmmd->dbinfo,
+ nmmd->selector_info,
nmmd->audio_file_info,
status_item_list[SI_UPTIME], ut,
- status_item_list[SI_STREAM_START], nmmd->stream_start.tv_sec,
- nmmd->stream_start.tv_usec,
- status_item_list[SI_CURRENT_TIME], now.tv_sec, now.tv_usec
+ status_item_list[SI_STREAM_START],
+ (long unsigned)nmmd->stream_start.tv_sec,
+ (long unsigned)nmmd->stream_start.tv_usec,
+ status_item_list[SI_CURRENT_TIME],
+ (long unsigned)now.tv_sec,
+ (long unsigned)now.tv_usec
);
free(bar);
const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
scd->sender_num = -1;
- if (argc < 0)
+ if (argc < 2)
return -E_COMMAND_SYNTAX;
for (i = 0; senders[i].name; i++)
- if (!strcmp(senders[i].name, argv[0]))
+ if (!strcmp(senders[i].name, argv[1]))
break;
-// PARA_DEBUG_LOG("%d:%s\n", argc, argv[0]);
+ PARA_DEBUG_LOG("%d:%s\n", argc, argv[1]);
if (!senders[i].name)
return -E_COMMAND_SYNTAX;
scd->sender_num = i;
for (i = 0; subcmds[i]; i++)
- if (!strcmp(subcmds[i], argv[1]))
+ if (!strcmp(subcmds[i], argv[2]))
break;
if (!subcmds[i])
return -E_COMMAND_SYNTAX;
scd->cmd_num = i;
-// scd->self = *in_addr;
mmd_lock();
if (!senders[scd->sender_num].client_cmds[scd->cmd_num]) {
mmd_unlock();
switch (scd->cmd_num) {
case SENDER_ON:
case SENDER_OFF:
- if (argc != 1)
+ if (argc != 3)
return -E_COMMAND_SYNTAX;
break;
case SENDER_DENY:
case SENDER_ALLOW:
- if (argc != 2 && argc != 3)
+ if (argc != 4 && argc != 5)
return -E_COMMAND_SYNTAX;
- if (!inet_aton(argv[2], &scd->addr))
+ if (!inet_aton(argv[3], &scd->addr))
return -E_COMMAND_SYNTAX;
scd->netmask = 32;
- if (argc == 3) {
- scd->netmask = atoi(argv[3]);
+ if (argc == 5) {
+ scd->netmask = atoi(argv[4]);
if (scd->netmask < 0 || scd->netmask > 32)
return -E_COMMAND_SYNTAX;
}
break;
case SENDER_ADD:
case SENDER_DELETE:
- if (argc != 2 && argc != 3)
+ if (argc != 4 && argc != 5)
return -E_COMMAND_SYNTAX;
- if (!inet_aton(argv[2], &scd->addr))
+ if (!inet_aton(argv[3], &scd->addr))
return -E_COMMAND_SYNTAX;
scd->port = -1;
- if (argc == 3) {
- scd->port = atoi(argv[3]);
+ if (argc == 5) {
+ scd->port = atoi(argv[4]);
if (scd->port < 0 || scd->port > 65535)
return -E_COMMAND_SYNTAX;
}
int i, ret;
struct sender_command_data scd;
- if (!argc) {
+ if (argc < 2) {
char *msg = NULL;
for (i = 0; senders[i].name; i++) {
char *tmp = make_message("%s%s\n",
free(msg);
return ret;
}
- ret = check_sender_args(argc - 1, argv + 1, &scd);
+ ret = check_sender_args(argc, argv, &scd);
if (ret < 0) {
char *msg;
if (scd.sender_num < 0)
}
/* server info */
-static int com_si(int fd, int argc, __unused char **argv)
+static int com_si(int fd, int argc, __a_unused char **argv)
{
int i, ret;
char *ut;
- char *dbtools = NULL, *sender_info = NULL, *sender_list = NULL;
- struct mallinfo mi = mallinfo();
+ char *selector_string = NULL, *sender_info = NULL, *sender_list = NULL;
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
- for (i = 0; dblist[i].name; i++) {
- dbtools = para_strcat(dbtools, dblist[i].name);
- dbtools = para_strcat(dbtools, " ");
+ for (i = 0; selectors[i].name; i++) {
+ selector_string = para_strcat(selector_string, selectors[i].name);
+ selector_string = para_strcat(selector_string, " ");
}
for (i = 0; senders[i].name; i++) {
char *info = senders[i].info();
ut = uptime_str();
ret = send_va_buffer(fd, "up: %s\nplayed: %u\n"
"pid: %d\n"
- "mallinfo: %d\n"
"connections (active/accepted/total): %u/%u/%u\n"
"current loglevel: %i\n"
- "supported database tools: %s\n"
+ "supported audio file selectors: %s\n"
"supported audio formats: %s\n"
"supported senders: %s\n"
"%s",
ut, mmd->num_played,
getppid(),
- mi.arena / 1024,
mmd->active_connections,
mmd->num_commands,
mmd->num_connects,
conf.loglevel_arg,
- dbtools,
- SUPPORTED_AUDIO_FORMATS,
+ selector_string,
+ supported_audio_formats(),
sender_list,
sender_info
);
mmd_unlock();
free(ut);
- free(dbtools);
+ free(selector_string);
free(sender_list);
free(sender_info);
return ret;
}
/* version */
-static int com_version(int socket_fd, int argc, __unused char **argv)
+static int com_version(int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
return send_buffer(socket_fd, "para_server-" VERSION ", \"" CODENAME "\"\n"
COPYRIGHT "\n"
char *name = NULL;
int ret, old = 0, count = -1; /* print af change forever */
- if (argc)
+ if (argc > 1)
count = atoi(argv[1]);
repeat:
mmd_lock();
name = NULL;
if (ret < 0)
return ret;
- if (argc && !--count)
+ if (argc > 1 && !--count)
return 1;
}
usleep(500000);
* times. Negative value means: print
* forever
*/
- if (argc)
+ if (argc > 1)
nr = atoi(argv[1]);
while (nr) {
mmd_lock();
/* stat */
static int com_stat(int socket_fd, int argc, char **argv)
{
-// char *old_stat = NULL, *old_dbinfo = NULL;
int ret, num = 0;/* status will be printed that many
* times. num <= 0 means: print forever
*/
signal(SIGUSR1, dummy);
- if (argc)
+ if (argc > 1)
num = atoi(argv[1]);
for (;;) {
return 1;
}
-/* always returns string that must be freed by the caller in handeler */
+/* always returns string that must be freed by the caller in handler */
static struct server_command *get_cmd_ptr(char *name, char **handler)
{
struct server_command *cmd = cmd_struct;
*handler = para_strdup("para_server"); /* server commands */
return cmd;
}
- /* not found, look for dbtool commands */
+ /* not found, look for commands supported by the current selector */
mmd_lock();
if (handler)
- *handler = make_message("the %s database tool", dblist[mmd->dbt_num].name);
- cmd = dblist[mmd->dbt_num].cmd_list;
+ *handler = make_message("the %s selector",
+ selectors[mmd->selector_num].name);
+ cmd = selectors[mmd->selector_num].cmd_list;
mmd_unlock();
for (; cmd->name; cmd++)
if (!strcmp(cmd->name, name))
char *perms, *handler;
int ret;
- if (!argc) {
+ if (argc < 2) {
/* no argument given, print list of commands */
if ((ret = send_description(fd, cmd_struct, "server", 0)) < 0)
return ret;
mmd_lock();
- handler = para_strdup(dblist[mmd->dbt_num].name);
- cmd = dblist[mmd->dbt_num].cmd_list;
+ handler = para_strdup(selectors[mmd->selector_num].name);
+ cmd = selectors[mmd->selector_num].cmd_list;
mmd_unlock();
ret = send_description(fd, cmd, handler, 0);
free(handler);
}
/* hup */
-static int com_hup(__unused int socket_fd, int argc, __unused char **argv)
+static int com_hup(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
kill(getppid(), SIGHUP);
return 1;
}
/* term */
-static int com_term(__unused int socket_fd, int argc, __unused char **argv)
+static int com_term(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
kill(getppid(), SIGTERM);
return 1;
}
-static int com_play(__unused int socket_fd, int argc, __unused char **argv)
+static int com_play(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
mmd->new_afs_status_flags |= AFS_PLAYING;
}
/* stop */
-static int com_stop(__unused int socket_fd, int argc, __unused char **argv)
+static int com_stop(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
mmd->new_afs_status_flags &= ~AFS_PLAYING;
}
/* pause */
-static int com_pause(__unused int socket_fd, int argc, __unused char **argv)
+static int com_pause(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
if (!afs_paused())
return 1;
}
-static int com_cdt(int fd, int argc, char **argv)
+static int com_chs(int fd, int argc, char **argv)
{
int i, ret;
- if (!argc) {
- char *dbtool;
+ if (argc == 1) {
+ char *selector;
mmd_lock();
- dbtool = para_strdup(dblist[mmd->dbt_num].name);
+ selector = para_strdup(selectors[mmd->selector_num].name);
mmd_unlock();
- ret = send_va_buffer(fd, "%s\n", dbtool);
- free(dbtool);
+ ret = send_va_buffer(fd, "%s\n", selector);
+ free(selector);
return ret;
}
- for (i = 0; dblist[i].name; i++) {
- if (strcmp(dblist[i].name, argv[1]))
+ for (i = 0; selectors[i].name; i++) {
+ if (strcmp(selectors[i].name, argv[1]))
continue;
mmd_lock();
- mmd->dbt_change = i;
+ mmd->selector_change = i;
mmd->events++;
mmd_unlock();
return 1;
}
- return -E_BAD_DBTOOL;
+ return -E_BAD_SELECTOR;
}
/* next */
-static int com_next(__unused int socket_fd, int argc, __unused char **argv)
+static int com_next(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
+ mmd->events++;
mmd->new_afs_status_flags |= AFS_NEXT;
mmd_unlock();
return 1;
}
/* nomore */
-static int com_nomore(__unused int socket_fd, int argc, __unused char **argv)
+static int com_nomore(__a_unused int socket_fd, int argc, __a_unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
if (afs_playing() || afs_paused())
}
/* ff */
-static int com_ff(__unused int socket_fd, int argc, char **argv)
+static int com_ff(__a_unused int socket_fd, int argc, char **argv)
{
long promille;
int ret, backwards = 0;
unsigned i;
char c;
- if (!argc)
+ if (argc != 2)
return -E_COMMAND_SYNTAX;
if (!(ret = sscanf(argv[1], "%u%c", &i, &c)))
return -E_COMMAND_SYNTAX;
}
/* jmp */
-static int com_jmp(__unused int socket_fd, int argc, char **argv)
+static int com_jmp(__a_unused int socket_fd, int argc, char **argv)
{
long unsigned int i;
int ret;
- if (!argc)
+ if (argc != 2)
return -E_COMMAND_SYNTAX;
if (sscanf(argv[1], "%lu", &i) <= 0)
return -E_COMMAND_SYNTAX;
sscanf(cmdstr, "%200s%n", buf, &n);
if (!n)
- return NULL;
+ return NULL;
buf[n] = '\0';
return get_cmd_ptr(buf, NULL);
}
return (long int) ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
}
-
/* Open user_list file, returns pointer to opened file on success,
* NULL on errors
*/
PARA_DEBUG_LOG("rc4 keys initialized (%u:%u)\n",
(unsigned char) rc4_buf[0],
(unsigned char) rc4_buf[RC4_KEY_LEN]);
- RC4_set_key(&rc4_recv_key, RC4_KEY_LEN, rc4_buf);
- RC4_set_key(&rc4_send_key, RC4_KEY_LEN, rc4_buf + RC4_KEY_LEN);
+ RC4_set_key(&rc4_recv_key, RC4_KEY_LEN, rc4_buf);
+ RC4_set_key(&rc4_send_key, RC4_KEY_LEN, rc4_buf + RC4_KEY_LEN);
}
static void rc4_recv(unsigned long len, const unsigned char *indata, unsigned char *outdata)
{
- RC4(&rc4_recv_key, len, indata, outdata);
+ RC4(&rc4_recv_key, len, indata, outdata);
}
+
static void rc4_send(unsigned long len, const unsigned char *indata, unsigned char *outdata)
{
- RC4(&rc4_send_key, len, indata, outdata);
+ RC4(&rc4_send_key, len, indata, outdata);
}
-
-
-
int handle_connect(int fd, struct sockaddr_in *addr)
{
int numbytes, ret, argc, use_rc4 = 0;
if (use_rc4) {
crypt_function_recv = rc4_recv;
crypt_function_send = rc4_send;
- PARA_INFO_LOG("%s", "rc4 encrytion activated\n");
+ PARA_INFO_LOG("%s", "rc4 encryption activated\n");
}
/* read command */
while ((numbytes = recv_buffer(fd, buf, sizeof(buf))) > 0) {
goto err_out;
/* valid command and sufficient perms */
alarm(0);
- argc = split_args(command, &argv, '\n');
- argv[0] = cmd->name;
+ argc = split_args(command, &argv, "\n");
mmd_lock();
mmd->num_commands++;
mmd_unlock();