+ return send_va_buffer(fd, "%s\n", para_strerror(-ret));
+ return ret;
+}
+
+/**
+ * Flags for the check command.
+ *
+ * \sa com_check().
+ */
+enum com_check_flags {
+ /** Check the audio file table. */
+ CHECK_AFT = 1,
+ /** Check the mood table. */
+ CHECK_MOODS = 2,
+ /** Check the playlist table. */
+ CHECK_PLAYLISTS = 4
+};
+
+int com_check(int fd, int argc, char * const * const argv)
+{
+ unsigned flags = 0;
+ int i, ret;
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-a")) {
+ flags |= CHECK_AFT;
+ continue;
+ }
+ if (!strcmp(arg, "-p")) {
+ flags |= CHECK_PLAYLISTS;
+ continue;
+ }
+ if (!strcmp(arg, "-m")) {
+ flags |= CHECK_MOODS;
+ continue;
+ }
+ return -E_AFS_SYNTAX;
+ }
+ if (i < argc)
+ return -E_AFS_SYNTAX;
+ if (!flags)
+ flags = ~0U;
+ if (flags & CHECK_AFT) {
+ ret = send_callback_request(aft_check_callback, NULL, send_result, &fd);
+ if (ret < 0)
+ return ret;
+ }
+ if (flags & CHECK_PLAYLISTS) {
+ ret = send_callback_request(playlist_check_callback, NULL, send_result, &fd);
+ if (ret < 0)
+ return ret;
+ }
+ if (flags & CHECK_MOODS) {
+ ret = send_callback_request(mood_check_callback, NULL, send_result, &fd);
+ if (ret < 0)
+ return ret;
+ }
+ return 1;
+}
+
+/**
+ * The afs event dispatcher.
+ *
+ * \param event Type of the event.
+ * \param pb May be \p NULL.
+ * \param data Type depends on \a event.
+ *
+ * This function calls the table handlers of all tables and passes \a pb and \a
+ * data verbatim. It's up to the handlers to interpret the \a data pointer.
+ */
+void afs_event(enum afs_events event, struct para_buffer *pb,
+ void *data)
+{
+ int i, ret;
+
+ for (i = 0; i < NUM_AFS_TABLES; i++) {
+ struct afs_table *t = &afs_tables[i];
+ if (!t->event_handler)
+ continue;
+ ret = t->event_handler(event, pb, data);
+ if (ret < 0)
+ PARA_CRIT_LOG("table %s, event %d: %s\n", t->name,
+ event, para_strerror(-ret));
+ }
+}
+
+int images_event_handler(__a_unused enum afs_events event,
+ __a_unused struct para_buffer *pb, __a_unused void *data)
+{
+ return 1;
+}
+
+int lyrics_event_handler(__a_unused enum afs_events event,
+ __a_unused struct para_buffer *pb, __a_unused void *data)
+{
+ return 1;