/** \file aac_afh.c para_server's aac audio format handler */
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "error.h"
#include "string.h"
#include "para.h"
+#include "afh.h"
#include "error.h"
#include <dirent.h> /* readdir() */
#include <sys/mman.h>
/** \file afs.c Paraslash's audio file selector. */
+static uint32_t socket_cookie;
+
/**
* Compare two osl objects of string type.
*
return ret;
}
-static void para_init_random_seed(void)
-{
- struct timeval now;
- unsigned int seed;
-
- gettimeofday(&now, NULL);
- seed = now.tv_usec;
- srand(seed);
-}
-
/**
* Open the audio file with highest score.
*
return para_munmap(afd->map.data, afd->map.size);
}
+#if 0
static void play_loop(enum play_mode current_play_mode)
{
int i, ret;
close_audio_file(&afd);
}
}
+#endif
+
static enum play_mode init_admissible_files(void)
{
return PLAY_MODE_MOOD;
}
-static int afs_init(void)
+int command_socket;
+
+static void setup_command_socket(void)
+{
+ int ret;
+ char *socket_name = "/tmp/afs_command_socket";
+ struct sockaddr_un unix_addr;
+
+ unlink(socket_name);
+ ret = create_local_socket(socket_name, &unix_addr,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+ if (ret < 0)
+ exit(EXIT_FAILURE);
+ command_socket = ret;
+ if (listen(command_socket , 5) < 0) {
+ PARA_EMERG_LOG("%s", "can not listen on socket\n");
+ exit(EXIT_FAILURE);
+ }
+ PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name,
+ command_socket);
+}
+
+int server_socket;
+
+void shed(void)
+{
+ for (;;)
+ sleep(1);
+}
+
+__noreturn int afs_init(uint32_t cookie, int socket_fd)
{
- int ret, shmid;
- void *shm_area;
+ int ret;
+// void *shm_area;
enum play_mode current_play_mode;
- para_init_random_seed();
+ server_socket = socket_fd;
+ socket_cookie = cookie;
+ PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n",
+ server_socket, (unsigned) cookie);
+ setup_command_socket();
ret = attribute_init(&afs_tables[TBLNUM_ATTRIBUTES]);
- PARA_DEBUG_LOG("ret %d\n", ret);
if (ret < 0)
- return ret;
+ goto attribute_init_error;
ret = moods_init(&afs_tables[TBLNUM_MOODS]);
if (ret < 0)
goto moods_init_error;
goto aft_init_error;
current_play_mode = init_admissible_files();
- play_loop(current_play_mode);
+ shed();
+#if 0
ret = shm_new(sizeof(struct callback_data));
if (ret < 0)
return ret;
return ret;
result_mutex = ret;
mutex_lock(result_mutex);
- return 1;
+#endif
aft_init_error:
score_shutdown(OSL_MARK_CLEAN);
score_init_error:
moods_shutdown(OSL_MARK_CLEAN);
moods_init_error:
attribute_shutdown(OSL_MARK_CLEAN);
- return ret;
-}
-
-static uint32_t afs_socket_cookie;
-static int para_random(unsigned max)
-{
- return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
-}
-
-int setup(void)
-{
- int ret, afs_server_socket[2];
-
- para_init_random_seed();
- ret = socketpair(PF_UNIX, SOCK_DGRAM, 0, afs_server_socket);
- if (ret < 0)
- exit(EXIT_FAILURE);
- afs_socket_cookie = para_random((uint32_t)-1);
- ret = fork();
- if (ret < 0)
- exit(EXIT_FAILURE);
- if (!ret) { /* child (afs) */
- char *socket_name = "/tmp/afs_command_socket";
- struct sockaddr_un unix_addr;
- int fd;
-
- unlink(socket_name);
- ret = create_local_socket(socket_name, &unix_addr,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
- if (ret < 0)
- exit(EXIT_FAILURE);
- fd = ret;
- if (listen(fd , 5) < 0) {
- PARA_EMERG_LOG("%s", "can not listen on socket\n");
- exit(EXIT_FAILURE);
- }
- ret = afs_init();
- if (ret < 0)
- exit(EXIT_FAILURE);
- PARA_NOTICE_LOG("accepting\n");
- ret = para_accept(fd, &unix_addr, sizeof(struct sockaddr_un));
- return ret;
- }
- ret = fork();
- if (ret < 0)
- exit(EXIT_FAILURE);
- if (!ret) { /* child (handler) */
- PARA_NOTICE_LOG("reading stdin\n");
- for (;;) {
- char buf[255];
- read(0, buf, 255);
- PARA_NOTICE_LOG("read: %s\n", buf);
- }
-
- }
- for (;;) {
- sleep(10);
- PARA_NOTICE_LOG("sending next requerst\n");
- }
+attribute_init_error:
+ exit(EXIT_FAILURE);
}
-
static int create_all_tables(void)
{
int i, ret;
mutex_unlock(result_mutex); /* wake up child */
}
-static void dummy(__a_unused int s)
-{}
-
static void afs_shutdown(enum osl_close_flags flags)
{
score_shutdown(flags);
aft_shutdown(flags);
}
+#if 0
static int got_sigchld;
-static void sigchld_handler(__a_unused int s)
-{
- got_sigchld = 1;
-}
-
static void server_loop(int child_pid)
{
// int status;
}
}
-#if 0
int main(int argc, const char **argv)
{
int i, ret = -E_AFS_SYNTAX;
#include <regex.h>
#include "osl.h"
-#include "afh.h"
#include "hash.h"
#define DATABASE_DIR "/home/maan/tmp/osl" /* FIXME */
/* afs */
typedef int callback_function(const struct osl_object *, struct osl_object *);
+__noreturn int afs_init(uint32_t cookie, int socket_fd);
int send_callback_request(callback_function *f, struct osl_object *query,
struct osl_object *result);
int send_standard_callback_request(int argc, const char **argv,
/** \file afs_common.c Functions common to all audio file selectors. */
+#include "para.h"
#include "server.cmdline.h"
+#include "afh.h"
#include "server.h"
#include "vss.h"
#include <dirent.h> /* readdir() */
#include "error.h"
#include <sys/mman.h>
#include <fnmatch.h>
+#include "afh.h"
#include "afs.h"
#include "string.h"
#include "para.h"
#include "error.h"
+#include "afh.h"
#include "afs.h"
#include "string.h"
#include "para.h"
#include "error.h"
+#include "afh.h"
#include "afs.h"
#include "string.h"
/** \file command.c does client authentication and executes server commands */
#include <sys/time.h> /* gettimeofday */
+#include "para.h" /* gettimeofday */
+
#include "server.cmdline.h"
#include "afs_common.h"
+#include "afh.h"
#include "server.h"
#include "vss.h"
#include "send.h"
* (C) 2005 Ian McDonald <imcdnzl@gmail.com>
*/
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "net.h"
#include "list.h"
/** \file http_send.c paraslash's http sender */
+#include "para.h"
#include "server.cmdline.h"
+#include "afh.h"
#include "server.h"
#include "http.h"
#include "vss.h"
#include "para.h"
#include "error.h"
+#include "afh.h"
#include "afs.h"
#include "list.h"
#include "string.h"
return -100;
}
-static int para_random(unsigned max)
-{
- return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
-}
-
/* returns 1 if row matches score item, -1 otherwise */
static int add_item_score(const void *row, struct mood_item *item, long *score,
long *score_arg_sum)
* Johannes Overmann <overmann@iname.com>
*/
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "error.h"
#include "string.h"
#define MEDIUM_BLOB_SIZE 16777220 /* (2**24 + 4) */
#define BLOB_SIZE 65539 /* (2**16 + 3) */
/** \endcond */
+
+#include "para.h"
#include "server.cmdline.h"
+#include "afh.h"
#include "server.h"
#include "vss.h"
#include "afs_common.h"
HC: prototypes for the commands of the mysql audio file selector
CC: array of commands for the mysql audio file selector
AT: server_command
-IN: server user_list
+IN: para afh server user_list
SN: list of mysql selector commands
---
N: cam
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "error.h"
#include "string.h"
#include <ortp/port.h>
#include "server.cmdline.h"
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "vss.h"
#include "send.h"
p = para_realloc(p, size); \
} \
}
+
+static inline int para_random(unsigned max)
+{
+ return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
+}
+
#include "para.h"
#include "error.h"
+#include "afh.h"
#include "afs.h"
#include "string.h"
/** \file playlist_selector.c The playlist audio file selector of paraslash */
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include "afs_common.h"
#include "error.h"
HC: prototypes for the commands of the playlist audio file selector
CC: array of commands for the playlist audio file selector
AT: server_command
-IN: server user_list
+IN: para afh server user_list
SN: list of playlist selector commands
---
N: ppl
/** \file random_selector.c An audio file selector which chooses files by random */
#include <sys/time.h> /* gettimeofday */
+#include "para.h"
#include "server.cmdline.h"
+#include "afh.h"
#include "server.h"
#include "afs_common.h"
#include "error.h"
HC: prototypes for the commands of the random audio file selector
CC: array of commands for the random audio file selector
AT: server_command
-IN: server user_list
+IN: para afh server user_list
SN: list of random selector commands
---
N: random_info
/** \file score.c Scoring functions to determine the audio file streaming order. */
#include "para.h"
#include "error.h"
+#include "afh.h"
#include "afs.h"
#include "list.h"
#include "string.h"
*/
-
+#include "para.h"
#include "server.cmdline.h"
#include "afs_common.h"
+#include "afh.h"
#include "server.h"
#include "vss.h"
#include "config.h"
#include "fd.h"
#include "signal.h"
#include "user_list.h"
+#include "afs.h"
/** define the array of error lists needed by para_server */
INIT_SERVER_ERRLISTS;
exit(EXIT_FAILURE);
}
+static uint32_t afs_socket_cookie;
+static int afs_socket;
+pid_t afs_pid;
+
+static void init_afs(void)
+{
+ int ret, afs_server_socket[2];
+
+ ret = socketpair(PF_UNIX, SOCK_DGRAM, 0, afs_server_socket);
+ if (ret < 0)
+ exit(EXIT_FAILURE);
+ afs_socket_cookie = para_random((uint32_t)-1);
+ afs_pid = fork();
+ if (afs_pid < 0)
+ exit(EXIT_FAILURE);
+ if (!afs_pid) /* child (afs) */
+ afs_init(afs_socket_cookie, afs_server_socket[1]);
+ close(afs_server_socket[1]);
+ afs_socket = afs_server_socket[0];
+ PARA_INFO_LOG("afs_socket: %d, afs_socket_cookie: %u\n", afs_socket,
+ (unsigned) afs_socket_cookie);
+}
+
+
static unsigned do_inits(int argc, char **argv)
{
/* connector's address information */
vss_init();
mmd->server_pid = getpid();
setup_signal_handling();
+ init_afs();
mmd_lock();
/* init network socket */
PARA_NOTICE_LOG("%s", "initializing tcp command socket\n");
status_refresh();
if (FD_ISSET(signal_pipe, &rfds)) {
int sig;
+ pid_t pid;
sig = para_next_signal();
switch (sig) {
case SIGHUP:
handle_sighup();
break;
case SIGCHLD:
- para_reap_children();
+ for (;;) {
+ pid = para_reap_child();
+ if (pid <= 0)
+ break;
+ if (pid != afs_pid)
+ continue;
+ PARA_EMERG_LOG("fatal: afs died\n");
+ goto genocide;
+ }
break;
/* die on sigint/sigterm. Kill all children too. */
case SIGINT:
case SIGTERM:
PARA_EMERG_LOG("terminating on signal %d\n", sig);
+genocide:
kill(0, SIGTERM);
selectors[mmd->selector_num].shutdown();
mutex_destroy(mmd_mutex);
shm_detach(mmd);
shm_destroy(mmd_shm_id);
+
exit(EXIT_FAILURE);
}
}
HC: prototypes for the server command handlers
CC: array of server commands
AT: server_command
-IN: server user_list
+IN: para afh server user_list
SN: list of server commands
---
N: chs
/** \file server.h common server data structures */
-#include "para.h"
-#include "afh.h"
/** size of the selector_info and audio_file info strings of struct misc_meta_data */
#define MMD_INFO_SIZE 16384
* senders.
*/
+#include "para.h"
+#include "afh.h"
#include "server.h"
#include <sys/mman.h> /* mmap */
#include <sys/time.h> /* gettimeofday */