Thanks to Lorenzo Bettini for pointing this out.
This patch also fixes a bug with the default filter configuration which
allocated too little memory for the array of filter configurations. Now
we always allocate space for at least three entries.
struct timeval tv;
char *tmp;
+ PARA_INFO_LOG("line: %s\n", line);
if (!line)
return;
itemnum = stat_line_valid(line);
static int init_stream_io(void)
{
- int i, ret, receiver_num;
+ int i, ret, receiver_num, nf;
char *cmd;
for (i = 0; i < conf.stream_write_cmd_given; i++) {
free(cmd);
/* filters */
filter_init(filters);
+ nf = MAX(2, conf.filter_given) + 1;
+ PARA_INFO_LOG("allocating space for %d filters\n", nf);
FOR_EACH_AUDIO_FORMAT(i) {
- afi[i].filter_conf = para_malloc((conf.filter_given + 1) * sizeof(char *));
- afi[i].filters = para_malloc((conf.filter_given + 1) * sizeof(struct filter *));
+ afi[i].filter_conf = para_malloc(nf * sizeof(char *));
+ afi[i].filters = para_malloc(nf * sizeof(struct filter *));
}
if (!conf.no_default_filters_given)
return setup_default_filters();
ret = check_perms(&c);
if (ret < 0)
goto out;
- argc = split_args(buf, &argv, '\n');
- PARA_INFO_LOG("argv[0]: %s\n", argv[0]);
+ argc = split_args(buf, &argv, "\n");
+ PARA_INFO_LOG("argv[0]: %s, argc= %d\n", argv[0], argc);
for (i = 0; cmds[i].name; i++) {
if (strcmp(cmds[i].name, argv[0]))
continue;
- ret = cmds[i].handler(clifd, argc + 1, argv);
+ ret = cmds[i].handler(clifd, argc, argv);
goto out;
}
ret = -E_INVALID_AUDIOD_CMD; /* cmd not found */
char *cf;
int i;
+ fprintf(stderr, "argc: %d\n", argc);
valid_fd_012();
hostname = para_hostname();
cmdline_parser(argc, argv, &conf);
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)
char *selector_string = NULL, *sender_info = NULL, *sender_list = NULL;
struct mallinfo mi = mallinfo();
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
for (i = 0; selectors[i].name; i++) {
/* version */
static int com_version(int socket_fd, int argc, __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();
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;
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;
/* hup */
static int com_hup(__unused int socket_fd, int argc, __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)
{
- 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)
{
- 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)
{
- 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)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
if (!afs_paused())
{
int i, ret;
- if (!argc) {
+ if (argc == 1) {
char *selector;
mmd_lock();
selector = para_strdup(selectors[mmd->selector_num].name);
/* next */
static int com_next(__unused int socket_fd, int argc, __unused char **argv)
{
- if (argc)
+ if (argc =! 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
mmd->events++;
/* nomore */
static int com_nomore(__unused int socket_fd, int argc, __unused char **argv)
{
- if (argc)
+ if (argc != 1)
return -E_COMMAND_SYNTAX;
mmd_lock();
if (afs_playing() || afs_paused())
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;
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;
goto err_out;
/* valid command and sufficient perms */
alarm(0);
- argc = split_args(command, &argv, '\n');
+ argc = split_args(command, &argv, "\n");
mmd_lock();
mmd->num_commands++;
mmd_unlock();
if (!tmp)
exit(EXIT_FAILURE);
- argc = split_args(tmp, &argv, ' ');
+ argc = split_args(tmp, &argv, " \t");
ret = para_exec(pid, argv[0], argv, fds);
free(argv);
free(tmp);
if (!f->parse_config)
return strlen(options)? -E_BAD_FILTER_OPTIONS : filter_num;
// PARA_DEBUG_LOG("options: %s\n", options);
- argc = split_args(options, &argv, ' ');
+ argc = split_args(options, &argv, " \t");
// PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]);
- for (i = argc; i >= 0; i--)
+ for (i = argc - 1; i >= 0; i--)
argv[i + 1] = argv[i];
- argc += 2;
+ argv[0] = para_strdup(f->name);
+ argc += 1;
*conf = f->parse_config(argc, argv);
return *conf? filter_num : -E_BAD_FILTER_OPTIONS;
}
* argc, argv get freed when com_grab() returns, so we have to make a
* copy.
*/
-__malloc struct grab_client *grab_client_new(int fd, int argc, char **argv, int *err)
+struct grab_client *grab_client_new(int fd, int argc, char **argv, int *err)
{
int i, ret;
struct grab_client *gc = para_calloc(sizeof(struct grab_client));
gc->conf = para_calloc(sizeof(struct grab_client_args_info));
gc->argc = argc;
- gc->argv = para_calloc((argc + 1) * sizeof(char *));
+ gc->argv = para_calloc((argc + 2) * sizeof(char *));
- for (i = 0; i < argc; i++) {
+ for (i = 0; argv[i]; i++) {
gc->argv[i] = para_strdup(argv[i]);
PARA_INFO_LOG("argc: %d, argv[%d]: %s\n", argc, i, gc->argv[i]);
}
- PARA_INFO_LOG("argv[%d]: %s\n", argc, gc->argv[argc]);
ret = grab_client_cmdline_parser(gc->argc, gc->argv , gc->conf);
*err = -E_GC_SYNTAX;
if (ret)
char *q;
int ret;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
q = make_message("alter table data add %s char(1) "
"not null default 0", argv[1]);
char *q;
int ret;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
q = make_message("alter table data drop %s", argv[1]);
ret = real_query(q);
int ret, stradd = strcmp(argv[0], "picadd");
size_t size;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
if (strlen(argv[1]) >= MAXLINE - 1)
return -E_NAMETOOLONG;
int ret;
unsigned int num_rows, num_fields;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
result = get_result(argv[1]);
if (!result)
void *result;
int ret;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
result = get_all_attributes();
if (!result)
q = make_message("select name, to_days(now()) - to_days(lastplayed) from "
"data%s%s%s order by lastplayed",
- (argc < 1)? "" : " where ",
- (argc < 1)? "" : argv[1],
- (argc < 1)? "" : " = '1'");
+ (argc < 2)? "" : " where ",
+ (argc < 2)? "" : argv[1],
+ (argc < 2)? "" : " = '1'");
result = get_result(q);
free(q);
if (!result)
char *q;
int num, ret;
- if (argc < 1)
+ if (argc < 2)
num = 10;
else
num = atoi(argv[1]);
"\n\n\n"
"') from data"
);
- if (argc >= 1) {
+ if (argc >= 2) {
char *tmp = make_message("%s where name LIKE '%s'", query,
argv[1]);
free(query);
char *name = NULL, *meta = NULL, *atts = NULL, *dir = NULL;
int ret, com_la = strcmp(argv[0], "info");
- if (argc < 1) {
+ if (argc < 2) {
ret = -E_GET_AUDIO_FILE;
if (!(name = get_current_audio_file()))
goto out;
{
int ne = !strcmp(argv[0], "ne");
int i, ret;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
- for (i = 1; i <= argc; i++) {
+ for (i = 1; i < argc; i++) {
ret = remove_entry(argv[i]);
if (ret < 0)
return ret;
char *q, *dn, *ebn1 = NULL, *ebn2 = NULL, *edn = NULL;
int ret;
- if (argc != 2)
+ if (argc != 3)
return -E_MYSQL_SYNTAX;
ebn1 = escaped_basename(argv[1]);
ebn2 = escaped_basename(argv[2]);
int i, ret;
const char *field = strcmp(argv[0], "picass")? "numplayed" : "pic_id";
- if (argc < 2)
+ if (argc < 3)
return -E_MYSQL_SYNTAX;
id = atol(argv[1]);
- for (i = 2; i <= argc; i++) {
+ for (i = 2; i < argc; i++) {
ebn = escaped_basename(argv[i]);
if (!ebn)
return -E_ESCAPE;
long unsigned id;
char *q;
- if (argc != 2)
+ if (argc != 3)
return -E_MYSQL_SYNTAX;
id = atol(argv[1]);
if (strlen(argv[2]) > MAXLINE)
unsigned long *length;
int ret;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
result = get_result("select id,name,pic from pics order by id");
if (!result)
my_ulonglong aff;
int i, ret;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
- for (i = 1; i <= argc; i++) {
+ for (i = 1; i < argc; i++) {
id = atol(argv[i]);
q = make_message("delete from pics where id = %lu", id);
ret = real_query(q);
int ret;
char *q, *name = NULL;
- if (argc < 1) {
+ if (argc < 2) {
ret = -E_GET_AUDIO_FILE;
name = get_current_audio_file();
} else {
char *tmp;
int ret = -1;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
tmp = make_message("delete from streams where name='%s'", argv[1]);
ret = real_query(tmp);
int ret;
unsigned int num_rows;
- if (argc > 0)
+ if (argc > 1)
q = make_message("select name from data where name LIKE '%s'",
argv[1]);
else
const char *fmt = "select count(name) from data where %s='1'";
int ret = -E_NORESULT;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
result = get_all_attributes();
if (!result)
static int com_us(__unused int fd, int argc, char *argv[])
{
- if (argc != 1)
+ if (argc != 2)
return -E_MYSQL_SYNTAX;
return update_audio_file(argv[1]);
}
int match = -1, ret, i;
unsigned int num_rows;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
ret = -E_NORESULT;
if (!result)
void *result;
MYSQL_ROW row;
- if (argc && strcmp(argv[1], "current_stream"))
+ if (argc > 1 && strcmp(argv[1], "current_stream"))
return -E_MYSQL_SYNTAX;
- if (argc) {
+ if (argc > 1) {
char *cs = get_current_stream();
ret = send_va_buffer(fd, "%s\n", cs);
free(cs);
void *result;
int ret;
- if (argc < 1) {
+ if (argc < 2) {
ret = -E_GET_STREAM;
name = get_current_stream();
} else {
char *old_stream = get_current_stream();
int csp = !strcmp(argv[0], "csp");
- if (!argc) {
+ if (argc == 1) {
ret = -E_MYSQL_SYNTAX;
if (csp)
goto out;
char *query, *stream, *tmp;
unsigned int num_rows, num;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
num = atoi(argv[1]);
if (!num)
return -E_MYSQL_SYNTAX;
- stream = (argc == 1)? get_current_stream() : para_strdup(argv[2]);
+ stream = (argc == 2)? get_current_stream() : para_strdup(argv[2]);
tmp = get_query(stream, NULL, 0);
query = make_message("%s limit %d", tmp, num);
free(tmp);
int i, ret;
char *atts = NULL, *name;
- if (argc < 1)
+ if (argc < 2)
return -E_MYSQL_SYNTAX;
- for (i = 1; i <= argc; i++) {
+ for (i = 1; i < argc; i++) {
int unset = 0;
char *tmp, *p =argv[i];
int len = strlen(p);
no_more_atts:
if (!atts)
return -E_NOATTS;
- if (i > argc) { /* no name given, use current af */
+ if (i >= argc) { /* no name given, use current af */
ret = -E_GET_AUDIO_FILE;
if (!(name = get_current_audio_file()))
goto out;
char *name = NULL, *meta = NULL, *atts = NULL;
int i, ret;
- if (argc < 2)
+ if (argc < 3)
return -E_MYSQL_SYNTAX;
if (!(name = escaped_basename(argv[1])))
return -E_ESCAPE;
ret = -E_META;
if (!(meta = get_meta(name, 0)))
goto out;
- for (i = 2; i <= argc; i++) {
+ for (i = 2; i < argc; i++) {
char *ebn, *q;
ret = -E_ESCAPE;
if (!(ebn = escaped_basename(argv[i])))
MYSQL_ROW row;
char *escaped_name;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
ret = -E_NORESULT;
result = get_result("select data.name from data left join dir on "
unsigned int num_rows;
MYSQL_ROW row;
- if (argc)
+ if (argc != 1)
return -E_MYSQL_SYNTAX;
out_file = NULL;
tempname = para_strdup("/tmp/mysql.tmp.XXXXXX");
ret = -E_MYSQL_INIT;
if (init_mysql_server() < 0 || !mysql_ptr)
goto out;
- conf.mysql_database_arg = para_strdup((argc < 1)?
+ conf.mysql_database_arg = para_strdup((argc < 2)?
"paraslash" : argv[1]);
query = make_message("create database %s", conf.mysql_database_arg);
ret = real_query(query);
// PARA_DEBUG_LOG("%s, options: %s\n", r->name,
// options? options : "(none)");
if (options) {
-// PARA_DEBUG_LOG("%s options: %s\n", name, options);
- argc = split_args(options, &argv, ' ');
-// PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", fn->argc, fn->argv[0]);
- for (i = argc; i >= 0; i--)
+ PARA_DEBUG_LOG("options: %s\n", options);
+ argc = split_args(options, &argv, " \t");
+ for (i = argc - 1; i >= 0; i--)
argv[i + 1] = argv[i];
- argc += 2;
+ argv[0] = para_strdup(r->name);
+ argc += 1;
+ PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]);
} else {
argc = 1;
argv = para_malloc(2 * sizeof(char*));
{
int j;
-// PARA_DEBUG_LOG("checking %s\n", ra);
+ PARA_DEBUG_LOG("checking %s\n", ra);
for (j = 0; receivers[j].name; j++) {
const char *name = receivers[j].name;
size_t len = strlen(name);
int stat_item_valid(const char *item)
{
int i;
- if (!item || !*item)
+ if (!item || !*item) {
+ PARA_ERROR_LOG("%s\n", "no item");
return -E_UNKNOWN_STAT_ITEM;
+ }
FOR_EACH_STAT_ITEM(i)
if (!strcmp(status_item_list[i], item))
return i;
char *start = buf, *end;
int i, num_lines = 0;
+ PARA_INFO_LOG("buf: %s", buf);
while (start < buf + n) {
char *next_null;
char *next_cr;
num_lines++;
if (line_handler) {
*end = '\0';
+ PARA_INFO_LOG("calling line handler: %s\n", start);
line_handler(start);
start = ++end;
} else
*
* \return The number of substrings found in \a args.
*/
-__must_check unsigned split_args(char *args, char ***argv_ptr, int delim)
+
+__must_check unsigned split_args(char *args, char ***argv_ptr, const char *delim)
{
char *p = args;
char **argv;
- ssize_t n = 0, i;
+ size_t n = 0, i, j;
- while (p && (p = strchr(p, delim))) {
- p++;
+ while ((i = strcspn(p, delim)) && (p += i)) {
+ p += strspn(p, delim);
n++;
}
- *argv_ptr = para_calloc((n + 3) * sizeof(char *));
+ *argv_ptr = para_malloc((n + 1) * sizeof(char *));
argv = *argv_ptr;
i = 0;
p = args;
-// printf("split_args: a:%s\n", p);
while (p) {
argv[i] = p;
- p = strchr(p, delim);
- if (p) {
-// printf("a:%s\n", p);
+ j = strcspn(p, delim);
+ if (!j)
+ break;
+ p += strcspn(p, delim);
+ if (*p) {
*p = '\0';
-// printf("b:\n");
p++;
- i++;
+ p += strspn(p, delim);
}
+ i++;
}
+ argv[n] = NULL;
return n;
}
__must_check int para_mkstemp(char *template, mode_t mode);
__must_check __malloc char *para_logname(void);
__must_check __malloc char *para_homedir(void);
-__must_check unsigned split_args(char *args, char ***argv_ptr, int delim);
+__must_check unsigned split_args(char *args, char ***argv_ptr, const char *delim);
__malloc char *para_hostname(void);
void valid_fd_012(void);