+ ret = t->create(database_dir);
+ if (ret < 0) {
+ para_printf(&aca->pbout, "cannot create table %s\n",
+ t->name);
+ goto out;
+ }
+ para_printf(&aca->pbout, "successfully created %s table\n",
+ t->name);
+ }
+ ret = open_afs_tables();
+ if (ret < 0)
+ para_printf(&aca->pbout, "cannot open afs tables\n");
+out:
+ return ret;
+}
+
+int com_init(struct command_context *cc)
+{
+ int i, j, ret;
+ uint32_t table_mask = (1 << (NUM_AFS_TABLES + 1)) - 1;
+ struct osl_object query = {.data = &table_mask,
+ .size = sizeof(table_mask)};
+
+ ret = make_database_dir();
+ if (ret < 0)
+ return ret;
+ if (cc->argc != 1) {
+ table_mask = 0;
+ for (i = 1; i < cc->argc; i++) {
+ for (j = 0; j < NUM_AFS_TABLES; j++) {
+ struct afs_table *t = &afs_tables[j];
+
+ if (strcmp(cc->argv[i], t->name))
+ continue;
+ table_mask |= (1 << j);
+ break;
+ }
+ if (j == NUM_AFS_TABLES)
+ return -E_BAD_TABLE_NAME;
+ }
+ }
+ return send_callback_request(com_init_callback, &query,
+ afs_cb_result_handler, cc);
+}
+
+/**
+ * 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,
+ /** Check the attribute table against the audio file table. */
+ CHECK_ATTS = 8
+};
+
+int com_check(struct command_context *cc)
+{
+ unsigned flags = 0;
+ int i, ret;
+
+ for (i = 1; i < cc->argc; i++) {
+ const char *arg = cc->argv[i];
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-a")) {
+ flags |= CHECK_AFT;
+ continue;
+ }
+ if (!strcmp(arg, "-A")) {
+ flags |= CHECK_ATTS;
+ continue;
+ }
+ if (!strcmp(arg, "-p")) {
+ flags |= CHECK_PLAYLISTS;
+ continue;
+ }
+ if (!strcmp(arg, "-m")) {
+ flags |= CHECK_MOODS;
+ continue;
+ }
+ return -E_AFS_SYNTAX;
+ }
+ if (i < cc->argc)
+ return -E_AFS_SYNTAX;
+ if (!flags)
+ flags = ~0U;
+ if (flags & CHECK_AFT) {
+ ret = send_callback_request(aft_check_callback, NULL,
+ afs_cb_result_handler, cc);
+ if (ret < 0)
+ return ret;
+ }
+ if (flags & CHECK_ATTS) {
+ ret = send_callback_request(attribute_check_callback, NULL,
+ afs_cb_result_handler, cc);
+ if (ret < 0)
+ return ret;
+ }
+ if (flags & CHECK_PLAYLISTS) {
+ ret = send_callback_request(playlist_check_callback,
+ NULL, afs_cb_result_handler, cc);
+ if (ret < 0)
+ return ret;
+ }
+ if (flags & CHECK_MOODS) {
+ ret = send_callback_request(mood_check_callback, NULL,
+ afs_cb_result_handler, cc);