server: Simplify afs socket cookie code.
[paraslash.git] / server.h
index 43ba841d28681fc06b92c06d7ccfce95a3a6423f..1852dd50962b78a72d270bb1d20e61eb0d9911c4 100644 (file)
--- a/server.h
+++ b/server.h
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 1997-2010 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 1997 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file server.h Common server data structures. */
 
 #define MMD_INFO_SIZE 16384
 
 /** The maximum length of the host component in an URL */
-#define MAX_HOSTLEN    256
+#define MAX_HOSTLEN 256
 
 
-/** Holds the arguments for the para_server's sender command. */
-struct sender_command_data{
-       /** Greater than 0 indicates that a sender cmd is already queued. */
+/** Arguments for the sender command. */
+struct sender_command_data {
+       /** Greater than zero indicates that a sender cmd is already queued. */
        int cmd_num;
        /** The number of the sender in question. */
        int sender_num;
@@ -34,35 +30,29 @@ struct sender_command_data{
 };
 
 /**
- * Used for parent-child communication.
- *
- * There's only one struct of this type which lives in shared memory
- * for communication between the server instances. Access to this
- * area is serialized via mmd_lock() and mmd_unlock(). There are two
- * reasons for a variable to be included here:
- *
- *     - At least one command (i.e. child of the server) must be able to
- *     change its value.
+ * Miscellaneous data for communication between server and command handlers.
  *
- * or
+ * There's only one instance of this structure which lives in a shared memory
+ * area. Command handlers communicate with the server process through this
+ * area. Changes made by the command handlers stay after the command handler
+ * exits. Conversely, changes made by the server process propagate to the
+ * command handlers. Access to this area is serialized via mmd_lock() and
+ * mmd_unlock().
  *
- *     - The contents are listed in the stat command and have to be up to
- *     date.
+ * There are two reasons for a variable to be included here: (a) at least one
+ * command handler changes its value, or (b) updates by the server must
+ * propagate to the stat command handlers.
  */
 struct misc_meta_data {
-       /** The size of the current audio file in bytes. */
-       size_t size;
-       /** The last modification time of the current audio file. */
-       time_t mtime;
        /** The "old" status flags -- commands may only read them. */
        unsigned int vss_status_flags;
        /** The new status flags -- commands may set them. */
        unsigned int new_vss_status_flags;
-       /** The number of data chunks sent for the current audio file. */
+       /** The number of data chunks sent so far. */
        long unsigned chunks_sent;
        /** Set by the jmp/ff commands to the new position in chunks. */
        long unsigned repos_request;
-       /** The number of the chunk currently sent out. */
+       /** The number of the chunk currently being sent. */
        long unsigned current_chunk;
        /** The milliseconds that have been skipped of the current audio file. */
        long offset;
@@ -71,8 +61,8 @@ struct misc_meta_data {
        /**
         * The event counter.
         *
-        * Commands may increase this to force a status update to be sent to all
-        * connected clients.
+        * Commands may increase this to force a status update to be sent to
+        * all connected stat clients.
         */
        unsigned int events;
        /** The number of audio files already sent. */
@@ -83,8 +73,6 @@ struct misc_meta_data {
        unsigned int num_connects;
        /** The number of connections currently active. */
        unsigned int active_connections;
-       /** The process id of the audio file selector. */
-       pid_t afs_pid;
        /** This gets updated by afs and contains its current mode. */
        char afs_mode_string[MAXLINE];
        /** Used by the sender command. */
@@ -93,8 +81,38 @@ struct misc_meta_data {
        struct audio_file_data afd;
 };
 
-/** Command line options for para_server. */
-extern struct server_args_info conf;
+extern pid_t afs_pid;
+extern struct lls_parse_result *server_lpr;
+
+/**
+ * Get a reference to the supercommand of para_server.
+ *
+ * This is needed for parsing the command line and for the ENUM_STRING_VAL()
+ * macro below. The latter macro is used in command.c, so CMD_PTR() can not
+ * be made local to server.c.
+ */
+#define CMD_PTR (lls_cmd(0, server_suite))
+
+/** Get the parse result of an option to para_server. */
+#define OPT_RESULT(_name) (lls_opt_result( \
+               LSG_SERVER_PARA_SERVER_OPT_ ## _name, server_lpr))
+
+/** How many times a server option was given. */
+#define OPT_GIVEN(_name) (lls_opt_given(OPT_RESULT(_name)))
+
+/** The (first) argument to a server option of type string. */
+#define OPT_STRING_VAL(_name) (lls_string_val(0, OPT_RESULT(_name)))
+
+/** The (first) argument to a server option of type uint32. */
+#define OPT_UINT32_VAL(_name) (lls_uint32_val(0, OPT_RESULT(_name)))
+
+/** The (first) argument to a server option of type int32. */
+#define OPT_INT32_VAL(_name) (lls_int32_val(0, OPT_RESULT(_name)))
+
+/** Get the string which corresponds to an enum constant. */
+#define ENUM_STRING_VAL(_name) (lls_enum_string_val(OPT_UINT32_VAL(_name), \
+       lls_opt(LSG_SERVER_PARA_SERVER_OPT_ ## _name, CMD_PTR)))
 
-__noreturn void handle_connect(int fd, const char *peername);
-void parse_config_or_die(int override);
+__noreturn void handle_connect(int fd);
+void parse_config_or_die(bool reload);
+char *server_get_tasks(void);