fecdec: Minor cleanups.
[paraslash.git] / command.c
index 1f9dd85..b59fae7 100644 (file)
--- a/command.c
+++ b/command.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -61,17 +61,20 @@ static void mmd_dup(struct misc_meta_data *new_mmd)
 }
 
 /*
- * compute human readable string containing
- * vss status for given integer value
+ * Compute human readable string containing vss status for given integer value.
+ *
+ * We don't want to use vss_playing() and friends here because we take a
+ * snapshot of the mmd struct and use the copy for computing the state of the
+ * vss. If the real data were used, we would take the mmd lock for a rather
+ * long time or risk to get an inconsistent view.
  */
 static char *vss_status_tohuman(unsigned int flags)
 {
        if (flags & VSS_PLAYING)
                return para_strdup("playing");
-       else if (flags & VSS_NEXT)
+       if (flags & VSS_NEXT)
                return para_strdup("stopped");
-       else
-               return para_strdup("paused");
+       return para_strdup("paused");
 }
 
 /*
@@ -177,12 +180,8 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman
        if (!subcmds[i])
                return -E_COMMAND_SYNTAX;
        scd->cmd_num = i;
-       mutex_lock(mmd_mutex);
-       if (!senders[scd->sender_num].client_cmds[scd->cmd_num]) {
-               mutex_unlock(mmd_mutex);
+       if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
                return -E_SENDER_CMD;
-       }
-       mutex_unlock(mmd_mutex);
        switch (scd->cmd_num) {
        case SENDER_ON:
        case SENDER_OFF:
@@ -193,7 +192,7 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman
        case SENDER_ALLOW:
                if (argc != 4 && argc != 5)
                        return -E_COMMAND_SYNTAX;
-               if (!inet_pton(AF_INET, argv[3], &scd->addr))
+               if (!is_valid_ipv4_address(argv[3]))
                        return -E_COMMAND_SYNTAX;
                scd->netmask = 32;
                if (argc == 5) {
@@ -201,20 +200,13 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman
                        if (scd->netmask < 0 || scd->netmask > 32)
                                return -E_COMMAND_SYNTAX;
                }
+               strncpy(scd->host, argv[3], sizeof(scd->host));
                break;
        case SENDER_ADD:
        case SENDER_DELETE:
-               if (argc != 4 && argc != 5)
-                       return -E_COMMAND_SYNTAX;
-               if (!inet_pton(AF_INET, argv[3], &scd->addr))
+               if (argc != 4)
                        return -E_COMMAND_SYNTAX;
-               scd->port = -1;
-               if (argc == 5) {
-                       scd->port = atoi(argv[4]);
-                       if (scd->port < 0 || scd->port > 65535)
-                               return -E_COMMAND_SYNTAX;
-               }
-               break;
+               return parse_fec_url(argv[3], scd);
        default:
                return -E_COMMAND_SYNTAX;
        }
@@ -255,7 +247,7 @@ int com_sender(int fd, int argc, char * const * argv)
                        usleep(100 * 1000);
                        continue;
                }
-               mmd->sender_cmd_data = scd;
+               memcpy(&mmd->sender_cmd_data, &scd, sizeof(scd));
                mutex_unlock(mmd_mutex);
                break;
        }
@@ -281,14 +273,16 @@ int com_si(int fd, int argc, __a_unused char * const * argv)
        }
        ut = uptime_str();
        ret = send_va_buffer(fd, "up: %s\nplayed: %u\n"
-               "pid: %d\n"
+               "server_pid: %d\n"
+               "afs_pid: %d\n"
                "connections (active/accepted/total): %u/%u/%u\n"
-               "current loglevel: %i\n"
+               "current loglevel: %s\n"
                "supported audio formats: %s\n"
                "supported senders: %s\n"
                "%s",
                ut, mmd->num_played,
                (int)getppid(),
+               (int)mmd->afs_pid,
                mmd->active_connections,
                mmd->num_commands,
                mmd->num_connects,