2 * Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file afs.c Paraslash's audio file selector. */
11 #include "server.cmdline.h"
16 #include <dirent.h> /* readdir() */
28 /** The osl tables used by afs. \sa blob.c. */
30 /** Contains audio file information. See aft.c. */
32 /** The table for the paraslash attributes. See attribute.c. */
35 * Paraslash's scoring system is based on Gaussian normal
36 * distributions, and the relevant data is stored in the rbtrees of an
37 * osl table containing only volatile columns. See score.c for
42 * A standard blob table containing the mood definitions. For details
46 /** A blob table containing lyrics on a per-song basis. */
48 /** Another blob table for images (for example album cover art). */
50 /** Yet another blob table for storing standard playlists. */
52 /** How many tables are in use? */
56 static struct table_info afs_tables
[NUM_AFS_TABLES
];
59 /** The file descriptor for the local socket. */
62 * Value sent by the command handlers to identify themselves as
63 * children of the running para_server.
66 /** The associated task structure. */
71 * A random number used to "authenticate" the connection.
73 * para_server picks this number by random before forking the afs process. The
74 * command handlers write this number together with the id of the shared memory
75 * area containing the query. This way, a malicious local user has to know this
76 * number to be able to cause the afs process to crash by sending fake queries.
78 extern uint32_t afs_socket_cookie
;
81 * Struct to let command handlers execute a callback in afs context.
83 * Commands that need to change the state of afs can't change the relevant data
84 * structures directly because commands are executed in a child process, i.e.
85 * they get their own virtual address space.
87 * This structure is used by \p send_callback_request() (executed from handler
88 * context) in order to let the afs process call the specified function. An
89 * instance of that structure is written to a shared memory area together with
90 * the arguments to the callback function. The identifier of the shared memory
91 * area is written to the command socket.
93 * The afs process accepts connections on the command socket and reads the
94 * shared memory id, attaches the corresponing area, calls the given handler to
95 * perform the desired action and to optionally compute a result.
97 * The result and a \p callback_result structure is then written to another
98 * shared memory area. The identifier for that area is written to the handler's
99 * command socket, so that the handler process can read the id, attach the
100 * shared memory area and use the result.
102 * \sa struct callback_result.
104 struct callback_query
{
105 /** The function to be called. */
106 callback_function
*handler
;
107 /** The number of bytes of the query */
112 * Structure embedded in the result of a callback.
114 * If the callback produced a result, an instance of that structure is embeeded
115 * into the shared memory area holding the result, mainly to let the command
116 * handler know the size of the result.
118 * \sa struct callback_query.
120 struct callback_result
{
121 /** The number of bytes of the result. */
126 * Ask the parent process to call a given function.
128 * \param f The function to be called.
129 * \param query Pointer to arbitrary data for the callback.
130 * \param result Callback result will be stored here.
132 * This function creates a shared memory area, copies the buffer pointed to by
133 * \a buf to that area and notifies the afs process that \a f should be
136 * \return Negative, on errors, the return value of the callback function
139 * \sa send_option_arg_callback_request(), send_standard_callback_request().
141 int send_callback_request(callback_function
*f
, struct osl_object
*query
,
142 struct osl_object
*result
)
144 struct callback_query
*cq
;
145 struct callback_result
*cr
;
146 int ret
, fd
= -1, query_shmid
, result_shmid
;
147 void *query_shm
, *result_shm
;
148 char buf
[sizeof(afs_socket_cookie
) + sizeof(int)];
149 struct sockaddr_un unix_addr
;
150 size_t query_shm_size
= sizeof(*cq
);
153 query_shm_size
+= query
->size
;
154 ret
= shm_new(query_shm_size
);
158 ret
= shm_attach(query_shmid
, ATTACH_RW
, &query_shm
);
163 cq
->query_size
= query_shm_size
- sizeof(*cq
);
166 memcpy(query_shm
+ sizeof(*cq
), query
->data
, query
->size
);
167 ret
= shm_detach(query_shm
);
171 *(uint32_t *) buf
= afs_socket_cookie
;
172 *(int *) (buf
+ sizeof(afs_socket_cookie
)) = query_shmid
;
174 ret
= get_stream_socket(PF_UNIX
);
178 ret
= init_unix_addr(&unix_addr
, conf
.afs_socket_arg
);
181 ret
= PARA_CONNECT(fd
, &unix_addr
);
184 ret
= send_bin_buffer(fd
, buf
, sizeof(buf
));
187 ret
= recv_bin_buffer(fd
, buf
, sizeof(buf
));
190 if (ret
!= sizeof(int)) {
198 ret
= shm_attach(result_shmid
, ATTACH_RO
, &result_shm
);
202 result
->size
= cr
->result_size
;
203 result
->data
= para_malloc(result
->size
);
204 memcpy(result
->data
, result_shm
+ sizeof(*cr
), result
->size
);
205 ret
= shm_detach(result_shm
);
207 PARA_ERROR_LOG("can not detach result\n");
209 PARA_ERROR_LOG("attach result failed: %d\n", ret
);
210 if (shm_destroy(result_shmid
) < 0)
211 PARA_ERROR_LOG("destroy result failed\n");
214 if (shm_destroy(query_shmid
) < 0)
215 PARA_ERROR_LOG("%s\n", "shm destroy error");
218 // PARA_DEBUG_LOG("callback_ret: %d\n", ret);
223 * Send a callback request passing an options structure and an argument vector.
225 * \param options pointer to an arbitrary data structure.
226 * \param argc Argument count.
227 * \param argv Standard argument vector.
228 * \param f The callback function.
229 * \param result The result of the query is stored here.
231 * Some commands have a couple of options that are parsed in child context for
232 * syntactic correctness and are stored in a special options structure for that
233 * command. This function allows to pass such a structure together with a list
234 * of further arguments (often a list of audio files) to the parent process.
236 * \sa send_standard_callback_request(), send_callback_request().
238 int send_option_arg_callback_request(struct osl_object
*options
,
239 int argc
, char * const * const argv
, callback_function
*f
,
240 struct osl_object
*result
)
244 struct osl_object query
= {.size
= options
? options
->size
: 0};
246 for (i
= 0; i
< argc
; i
++)
247 query
.size
+= strlen(argv
[i
]) + 1;
248 query
.data
= para_malloc(query
.size
);
251 memcpy(query
.data
, options
->data
, options
->size
);
254 for (i
= 0; i
< argc
; i
++) {
255 strcpy(p
, argv
[i
]); /* OK */
256 p
+= strlen(argv
[i
]) + 1;
258 ret
= send_callback_request(f
, &query
, result
);
264 * Send a callback request with an argument vector only.
266 * \param argc The same meaning as in send_option_arg_callback_request().
267 * \param argv The same meaning as in send_option_arg_callback_request().
268 * \param f The same meaning as in send_option_arg_callback_request().
269 * \param result The same meaning as in send_option_arg_callback_request().
271 * This is similar to send_option_arg_callback_request(), but no options buffer
272 * is passed to the parent process.
274 * \return The return value of the underlying call to
275 * send_option_arg_callback_request().
277 int send_standard_callback_request(int argc
, char * const * const argv
,
278 callback_function
*f
, struct osl_object
*result
)
280 return send_option_arg_callback_request(NULL
, argc
, argv
, f
, result
);
283 static int action_if_pattern_matches(struct osl_row
*row
, void *data
)
285 struct pattern_match_data
*pmd
= data
;
286 struct osl_object name_obj
;
287 const char *p
, *name
;
288 int ret
= osl_get_object(pmd
->table
, row
, pmd
->match_col_num
, &name_obj
);
289 const char *pattern_txt
= (const char *)pmd
->patterns
.data
;
293 name
= (char *)name_obj
.data
;
294 if ((!name
|| !*name
) && (pmd
->pm_flags
& PM_SKIP_EMPTY_NAME
))
296 if (!pmd
->patterns
.size
&& (pmd
->pm_flags
& PM_NO_PATTERN_MATCHES_EVERYTHING
))
297 return pmd
->action(pmd
->table
, row
, name
, pmd
->data
);
298 for (p
= pattern_txt
; p
< pattern_txt
+ pmd
->patterns
.size
;
299 p
+= strlen(p
) + 1) {
300 ret
= fnmatch(p
, name
, pmd
->fnmatch_flags
);
301 if (ret
== FNM_NOMATCH
)
305 return pmd
->action(pmd
->table
, row
, name
, pmd
->data
);
310 int for_each_matching_row(struct pattern_match_data
*pmd
)
312 if (pmd
->pm_flags
& PM_REVERSE_LOOP
)
313 return osl_rbtree_loop_reverse(pmd
->table
, pmd
->loop_col_num
, pmd
,
314 action_if_pattern_matches
);
315 return osl_rbtree_loop(pmd
->table
, pmd
->loop_col_num
, pmd
,
316 action_if_pattern_matches
);
320 * Compare two osl objects of string type.
322 * \param obj1 Pointer to the first object.
323 * \param obj2 Pointer to the second object.
325 * In any case, only \p MIN(obj1->size, obj2->size) characters of each string
326 * are taken into account.
328 * \return It returns an integer less than, equal to, or greater than zero if
329 * \a obj1 is found, respectively, to be less than, to match, or be greater than
332 * \sa strcmp(3), strncmp(3), osl_compare_func.
334 int string_compare(const struct osl_object
*obj1
, const struct osl_object
*obj2
)
336 const char *str1
= (const char *)obj1
->data
;
337 const char *str2
= (const char *)obj2
->data
;
338 return strncmp(str1
, str2
, PARA_MIN(obj1
->size
, obj2
->size
));
342 * write input from fd to dynamically allocated buffer,
343 * but maximal max_size byte.
345 static int fd2buf(int fd
, unsigned max_size
, struct osl_object
*obj
)
347 const size_t chunk_size
= 1024;
348 size_t size
= 2048, received
= 0;
350 char *buf
= para_malloc(size
);
353 ret
= recv_bin_buffer(fd
, buf
+ received
, chunk_size
);
357 if (received
+ chunk_size
>= size
) {
359 ret
= -E_INPUT_TOO_LARGE
;
362 buf
= para_realloc(buf
, size
);
366 obj
->size
= received
;
373 * Read data from a file descriptor, and send it to the afs process.
375 * \param fd File descriptor to read data from.
376 * \param arg_obj Pointer to the arguments to \a f.
377 * \param f The callback function.
378 * \param max_len Don't read more than that many bytes from stdin.
379 * \param result The result of the query is stored here.
381 * This function is used by commands that wish to let para_server store
382 * arbitrary data specified by the user (for instance the add_blob family of
383 * commands). First, at most \a max_len bytes are read from \a fd, the result
384 * is concatenated with the buffer given by \a arg_obj, and the combined buffer
385 * is made available to the parent process via shared memory.
387 * \return Negative on errors, the return value of the underlying call to
388 * send_callback_request() otherwise.
390 int stdin_command(int fd
, struct osl_object
*arg_obj
, callback_function
*f
,
391 unsigned max_len
, struct osl_object
*result
)
393 struct osl_object query
, stdin_obj
;
396 ret
= send_buffer(fd
, AWAITING_DATA_MSG
);
399 ret
= fd2buf(fd
, max_len
, &stdin_obj
);
402 query
.size
= arg_obj
->size
+ stdin_obj
.size
;
403 query
.data
= para_malloc(query
.size
);
404 memcpy(query
.data
, arg_obj
->data
, arg_obj
->size
);
405 memcpy((char *)query
.data
+ arg_obj
->size
, stdin_obj
.data
, stdin_obj
.size
);
406 free(stdin_obj
.data
);
407 ret
= send_callback_request(f
, &query
, result
);
413 * Open the audio file with highest score.
415 * \param afd Audio file data is returned here.
417 * This stores all information for streaming the "best" audio file
418 * in the \a afd structure.
420 * \return Positive on success, negative on errors.
422 * \sa close_audio_file(), open_and_update_audio_file().
424 int open_next_audio_file(struct audio_file_data
*afd
)
426 struct osl_row
*aft_row
;
429 ret
= score_get_best(&aft_row
, &afd
->score
);
432 ret
= open_and_update_audio_file(aft_row
, afd
);
439 * Free all resources which were allocated by open_next_audio_file().
441 * \param afd The structure previously filled in by open_next_audio_file().
443 * \return The return value of the underlying call to para_munmap().
445 * \sa open_next_audio_file().
447 int close_audio_file(struct audio_file_data
*afd
)
449 free(afd
->afhi
.chunk_table
);
450 return para_munmap(afd
->map
.data
, afd
->map
.size
);
453 static enum play_mode
init_admissible_files(void)
457 if (conf
.mood_given
) {
458 ret
= change_current_mood(conf
.mood_arg
);
460 if (conf
.playlist_given
)
461 PARA_WARNING_LOG("ignoring playlist %s\n",
463 return PLAY_MODE_MOOD
;
466 if (conf
.playlist_given
) {
467 ret
= playlist_open(conf
.playlist_arg
);
469 return PLAY_MODE_PLAYLIST
;
471 ret
= change_current_mood(NULL
); /* open first available mood */
473 return PLAY_MODE_MOOD
;
474 change_current_mood(""); /* open dummy mood, always successful */
475 return PLAY_MODE_MOOD
;
478 static int setup_command_socket_or_die(void)
481 char *socket_name
= conf
.afs_socket_arg
;
482 struct sockaddr_un unix_addr
;
485 ret
= create_local_socket(socket_name
, &unix_addr
,
486 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IWOTH
);
488 PARA_EMERG_LOG("%s: %s\n", PARA_STRERROR(-ret
), socket_name
);
491 if (listen(ret
, 5) < 0) {
492 PARA_EMERG_LOG("%s", "can not listen on socket\n");
495 PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name
,
500 static int server_socket
;
501 static struct command_task command_task_struct
;
502 static struct signal_task signal_task_struct
;
504 static void unregister_tasks(void)
506 unregister_task(&command_task_struct
.task
);
507 unregister_task(&signal_task_struct
.task
);
510 static void close_afs_tables(enum osl_close_flags flags
)
512 PARA_NOTICE_LOG("closing afs_tables\n");
513 score_shutdown(flags
);
514 attribute_shutdown(flags
);
515 close_current_mood();
517 moods_shutdown(flags
);
518 playlists_shutdown(flags
);
519 lyrics_shutdown(flags
);
520 images_shutdown(flags
);
524 static void signal_pre_select(struct sched
*s
, struct task
*t
)
526 struct signal_task
*st
= t
->private_data
;
528 para_fd_set(st
->fd
, &s
->rfds
, &s
->max_fileno
);
531 static void signal_post_select(struct sched
*s
, struct task
*t
)
533 struct signal_task
*st
= t
->private_data
;
535 if (!FD_ISSET(st
->fd
, &s
->rfds
))
537 st
->signum
= para_next_signal();
539 if (st
->signum
== SIGUSR1
)
540 return; /* ignore SIGUSR1 */
541 PARA_NOTICE_LOG("caught signal %d\n", st
->signum
);
542 t
->ret
= -E_SIGNAL_CAUGHT
;
546 static void register_signal_task(void)
548 struct signal_task
*st
= &signal_task_struct
;
549 st
->fd
= para_signal_init();
550 PARA_INFO_LOG("signal pipe: fd %d\n", st
->fd
);
551 para_install_sighandler(SIGINT
);
552 para_install_sighandler(SIGTERM
);
553 para_install_sighandler(SIGPIPE
);
555 st
->task
.pre_select
= signal_pre_select
;
556 st
->task
.post_select
= signal_post_select
;
557 st
->task
.private_data
= st
;
558 sprintf(st
->task
.status
, "signal task");
559 register_task(&st
->task
);
562 static struct list_head afs_client_list
;
565 struct list_head node
;
567 struct timeval connect_time
;
570 static void command_pre_select(struct sched
*s
, struct task
*t
)
572 struct command_task
*ct
= t
->private_data
;
573 struct afs_client
*client
;
575 para_fd_set(ct
->fd
, &s
->rfds
, &s
->max_fileno
);
576 list_for_each_entry(client
, &afs_client_list
, node
)
577 para_fd_set(client
->fd
, &s
->rfds
, &s
->max_fileno
);
582 * On errors, negative value is written to fd.
583 * On success: If query produced a result, the result_shmid is written to fd.
584 * Otherwise, zero is written.
586 static int call_callback(int fd
, int query_shmid
)
588 void *query_shm
, *result_shm
;
589 struct callback_query
*cq
;
590 struct callback_result
*cr
;
591 struct osl_object query
, result
= {.data
= NULL
};
592 int result_shmid
= -1, ret
, ret2
;
594 ret
= shm_attach(query_shmid
, ATTACH_RW
, &query_shm
);
598 query
.data
= (char *)query_shm
+ sizeof(*cq
);
599 query
.size
= cq
->query_size
;
600 ret
= cq
->handler(&query
, &result
);
601 ret2
= shm_detach(query_shm
);
602 if (ret2
< 0 && ret
>= 0)
607 if (!result
.data
|| !result
.size
)
609 ret
= shm_new(result
.size
+ sizeof(struct callback_result
));
613 ret
= shm_attach(result_shmid
, ATTACH_RW
, &result_shm
);
617 cr
->result_size
= result
.size
;
618 memcpy(result_shm
+ sizeof(*cr
), result
.data
, result
.size
);
619 ret
= shm_detach(result_shm
);
625 ret2
= send_bin_buffer(fd
, (char *)&ret
, sizeof(int));
626 if (ret
< 0 || ret2
< 0) {
627 if (result_shmid
>= 0)
628 if (shm_destroy(result_shmid
) < 0)
629 PARA_ERROR_LOG("destroy result failed\n");
636 static void execute_afs_command(int fd
, uint32_t expected_cookie
)
640 char buf
[sizeof(cookie
) + sizeof(query_shmid
)];
641 int ret
= recv_bin_buffer(fd
, buf
, sizeof(buf
));
644 PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-ret
));
647 if (ret
!= sizeof(buf
)) {
648 PARA_NOTICE_LOG("short read (%d bytes, expected %lu)\n",
649 ret
, (long unsigned) sizeof(buf
));
652 cookie
= *(uint32_t *)buf
;
653 if (cookie
!= expected_cookie
) {
654 PARA_NOTICE_LOG("received invalid cookie(got %u, expected %u)\n",
655 (unsigned)cookie
, (unsigned)expected_cookie
);
658 query_shmid
= *(int *)(buf
+ sizeof(cookie
));
659 if (query_shmid
< 0) {
660 PARA_WARNING_LOG("received invalid query shmid %d)\n",
664 /* Ignore return value: Errors might be ok here. */
665 call_callback(fd
, query_shmid
);
668 #define AFS_CLIENT_TIMEOUT 3
670 static void command_post_select(struct sched
*s
, struct task
*t
)
672 struct command_task
*ct
= t
->private_data
;
673 struct sockaddr_un unix_addr
;
674 struct afs_client
*client
, *tmp
;
676 /* First, check the list of connected clients. */
677 list_for_each_entry_safe(client
, tmp
, &afs_client_list
, node
) {
678 if (FD_ISSET(client
->fd
, &s
->rfds
))
679 execute_afs_command(client
->fd
, ct
->cookie
);
680 else { /* prevent bogus connection flodding */
682 tv_diff(now
, &client
->connect_time
, &diff
);
683 if (diff
.tv_sec
< AFS_CLIENT_TIMEOUT
)
685 PARA_WARNING_LOG("connection timeout\n");
688 list_del(&client
->node
);
691 /* Next, accept connections on the local socket. */
692 if (!FD_ISSET(ct
->fd
, &s
->rfds
))
694 t
->ret
= para_accept(ct
->fd
, &unix_addr
, sizeof(unix_addr
));
696 PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t
->ret
));
699 client
= para_malloc(sizeof(*client
));
701 client
->connect_time
= *now
;
702 para_list_add(&client
->node
, &afs_client_list
);
707 static void register_command_task(uint32_t cookie
)
709 struct command_task
*ct
= &command_task_struct
;
710 ct
->fd
= setup_command_socket_or_die();
713 ct
->task
.pre_select
= command_pre_select
;
714 ct
->task
.post_select
= command_post_select
;
715 ct
->task
.private_data
= ct
;
716 sprintf(ct
->task
.status
, "command task");
717 register_task(&ct
->task
);
720 void register_tasks(uint32_t cookie
)
722 register_signal_task();
723 register_command_task(cookie
);
726 static char *database_dir
;
728 static int make_database_dir(void)
733 if (conf
.afs_database_dir_given
)
734 database_dir
= para_strdup(conf
.afs_database_dir_arg
);
736 char *home
= para_homedir();
737 database_dir
= make_message(
738 "%s/.paraslash/afs_database", home
);
742 PARA_INFO_LOG("afs_database dir %s\n", database_dir
);
743 ret
= para_mkdir(database_dir
, 0777);
744 if (ret
>= 0 || ret
== -E_EXIST
)
751 static int open_afs_tables(void)
753 int ret
= make_database_dir();
757 ret
= attribute_init(&afs_tables
[TBLNUM_ATTRIBUTES
], database_dir
);
760 ret
= moods_init(&afs_tables
[TBLNUM_MOODS
], database_dir
);
762 goto moods_init_error
;
763 ret
= playlists_init(&afs_tables
[TBLNUM_PLAYLIST
], database_dir
);
765 goto playlists_init_error
;
766 ret
= lyrics_init(&afs_tables
[TBLNUM_LYRICS
], database_dir
);
768 goto lyrics_init_error
;
769 ret
= images_init(&afs_tables
[TBLNUM_IMAGES
], database_dir
);
771 goto images_init_error
;
772 ret
= score_init(&afs_tables
[TBLNUM_SCORES
], database_dir
);
774 goto score_init_error
;
775 ret
= aft_init(&afs_tables
[TBLNUM_AUDIO_FILES
], database_dir
);
781 score_shutdown(OSL_MARK_CLEAN
);
783 images_shutdown(OSL_MARK_CLEAN
);
785 lyrics_shutdown(OSL_MARK_CLEAN
);
787 playlists_shutdown(OSL_MARK_CLEAN
);
788 playlists_init_error
:
789 moods_shutdown(OSL_MARK_CLEAN
);
791 attribute_shutdown(OSL_MARK_CLEAN
);
795 __noreturn
int afs_init(uint32_t cookie
, int socket_fd
)
797 enum play_mode current_play_mode
;
801 INIT_LIST_HEAD(&afs_client_list
);
802 ret
= open_afs_tables();
805 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret
));
808 server_socket
= socket_fd
;
809 ret
= mark_fd_nonblock(server_socket
);
812 PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n",
813 server_socket
, (unsigned) cookie
);
814 current_play_mode
= init_admissible_files();
815 register_tasks(cookie
);
816 s
.default_timeout
.tv_sec
= 0;
817 s
.default_timeout
.tv_usec
= 99 * 1000;
820 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret
));
821 close_afs_tables(OSL_MARK_CLEAN
);
825 static int create_tables_callback(const struct osl_object
*query
,
826 __a_unused
struct osl_object
*result
)
828 uint32_t table_mask
= *(uint32_t *)query
->data
;
831 close_afs_tables(OSL_MARK_CLEAN
);
832 for (i
= 0; i
< NUM_AFS_TABLES
; i
++) {
833 struct table_info
*ti
= afs_tables
+ i
;
835 if (ti
->flags
& TBLFLAG_SKIP_CREATE
)
837 if (!(table_mask
& (1 << i
)))
839 ret
= osl_create_table(ti
->desc
);
843 ret
= open_afs_tables();
844 return ret
< 0? ret
: 0;
847 int com_init(int fd
, int argc
, char * const * const argv
)
850 uint32_t table_mask
= (1 << (NUM_AFS_TABLES
+ 1)) - 1;
851 struct osl_object query
= {.data
= &table_mask
,
852 .size
= sizeof(table_mask
)};
856 for (i
= 1; i
< argc
; i
++) {
857 for (j
= 0; j
< NUM_AFS_TABLES
; j
++) {
858 struct table_info
*ti
= afs_tables
+ j
;
860 if (ti
->flags
& TBLFLAG_SKIP_CREATE
)
862 if (strcmp(argv
[i
], ti
->desc
->name
))
864 table_mask
|= (1 << j
);
867 if (j
== NUM_AFS_TABLES
)
868 return -E_BAD_TABLE_NAME
;
871 ret
= send_callback_request(create_tables_callback
, &query
, NULL
);
874 return send_va_buffer(fd
, "successfully created afs table(s)\n");
877 enum com_check_flags
{
883 int com_check(int fd
, int argc
, char * const * const argv
)
887 struct osl_object result
;
889 for (i
= 1; i
< argc
; i
++) {
890 const char *arg
= argv
[i
];
893 if (!strcmp(arg
, "--")) {
897 if (!strcmp(arg
, "-a")) {
901 if (!strcmp(arg
, "-p")) {
902 flags
|= CHECK_PLAYLISTS
;
905 if (!strcmp(arg
, "-m")) {
906 flags
|= CHECK_MOODS
;
909 return -E_AFS_SYNTAX
;
912 return -E_AFS_SYNTAX
;
915 if (flags
& CHECK_AFT
) {
916 ret
= send_callback_request(aft_check_callback
, NULL
, &result
);
920 ret
= send_buffer(fd
, (char *) result
.data
);
926 if (flags
& CHECK_PLAYLISTS
) {
927 ret
= send_callback_request(playlist_check_callback
, NULL
, &result
);
931 ret
= send_buffer(fd
, (char *) result
.data
);
937 if (flags
& CHECK_MOODS
) {
938 ret
= send_callback_request(mood_check_callback
, NULL
, &result
);
942 ret
= send_buffer(fd
, (char *) result
.data
);