Merge ../paraslash.fml/paraslash
[paraslash.git] / command.c
index 1f94bbc..55070a3 100644 (file)
--- a/command.c
+++ b/command.c
@@ -18,7 +18,6 @@
 
 /** \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 "daemon.h"
 #include "string.h"
 
-void (*crypt_function_recv)(unsigned long len, const unsigned char *indata,
-       unsigned char *outdata) = NULL;
-void (*crypt_function_send)(unsigned long len, const unsigned char *indata,
-       unsigned char *outdata) = NULL;
 static RC4_KEY rc4_recv_key;
 static RC4_KEY rc4_send_key;
 static unsigned char rc4_buf[2 * RC4_KEY_LEN];
 
 extern const char *status_item_list[NUM_STAT_ITEMS];
 extern struct misc_meta_data *mmd;
-extern struct gengetopt_args_info conf;
 extern struct audio_file_selector selectors[];
-extern struct audio_format afl[];
 extern struct sender senders[];
 extern char *user_list;
 struct sockaddr_in *in_addr;
@@ -434,9 +427,12 @@ static char *get_status(struct misc_meta_data *nmmd)
                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);
@@ -559,7 +555,6 @@ static int com_si(int fd, int argc, __a_unused char **argv)
        int i, ret;
        char *ut;
        char *selector_string = NULL, *sender_info = NULL, *sender_list = NULL;
-       struct mallinfo mi = mallinfo();
 
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -578,7 +573,6 @@ static int com_si(int fd, int argc, __a_unused char **argv)
        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 audio file selectors: %s\n"
@@ -587,13 +581,12 @@ static int com_si(int fd, int argc, __a_unused char **argv)
                "%s",
                ut, mmd->num_played,
                getppid(),
-               mi.arena / 1024,
                mmd->active_connections,
                mmd->num_commands,
                mmd->num_connects,
                conf.loglevel_arg,
                selector_string,
-               SUPPORTED_AUDIO_FORMATS,
+               supported_audio_formats(),
                sender_list,
                sender_info
        );
@@ -610,7 +603,8 @@ static int com_version(int socket_fd, int argc, __a_unused char **argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
-       return send_buffer(socket_fd, "para_server-" VERSION ", \"" CODENAME "\"\n"
+       return send_buffer(socket_fd, "para_server-" PACKAGE_VERSION ", \""
+                       CODENAME "\"\n"
                        COPYRIGHT "\n"
                        "built: " BUILD_DATE "\n"
                        SYSTEM ", " CC_VERSION "\n"
@@ -696,7 +690,9 @@ static int com_stat(int socket_fd, int argc, char **argv)
                ret = 1;
                if (num == 1)
                        goto out;
-               usleep(500000 * 100);
+               sleep(50);
+               if (getppid() == 1)
+                       return -E_SERVER_CRASH;
        }
 out:
        return ret;
@@ -1075,12 +1071,14 @@ static void init_rc4_keys(void)
        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)
+static void rc4_recv(unsigned long len, const unsigned char *indata,
+               unsigned char *outdata, __a_unused void *private_data)
 {
        RC4(&rc4_recv_key, len, indata, outdata);
 }
 
-static void rc4_send(unsigned long len, const unsigned char *indata, unsigned char *outdata)
+static void rc4_send(unsigned long len, const unsigned char *indata,
+               unsigned char *outdata, __a_unused void *private_data)
 {
        RC4(&rc4_send_key, len, indata, outdata);
 }
@@ -1105,7 +1103,8 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        in_addr = addr;
        challenge_nr = random();
        /* send Welcome message */
-       ret = send_va_buffer(fd, "This is para_server, version " VERSION  ".\n" );
+       ret = send_va_buffer(fd, "This is para_server, version "
+               PACKAGE_VERSION  ".\n" );
        if (ret < 0)
                goto err_out;
        /* recv auth request line */
@@ -1173,11 +1172,8 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        ret = send_bin_buffer(fd, buf, numbytes);
        if (ret < 0)
                goto err_out;
-       if (use_rc4) {
-               crypt_function_recv = rc4_recv;
-               crypt_function_send = rc4_send;
-               PARA_INFO_LOG("%s", "rc4 encrytion activated\n");
-       }
+       if (use_rc4)
+               enable_crypt(fd, rc4_recv, rc4_send, NULL);
        /* read command */
        while ((numbytes = recv_buffer(fd, buf, sizeof(buf))) > 0) {
 //             PARA_INFO_LOG("recvd: %s (%d)\n", buf, numbytes);