Merge commit 'meins/next' into next
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index c89e3cec68ce835d44b803ce1fc144948ab9d8e1..1350db3423c3a184cb645e09cae9a2ebb060358b 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -6,9 +6,11 @@
 
 /** \file afs.c Paraslash's audio file selector. */
 
+#include <regex.h>
 #include <signal.h>
 #include <fnmatch.h>
 #include <openssl/rc4.h>
+#include <osl.h>
 
 #include "server.cmdline.h"
 #include "para.h"
@@ -27,6 +29,7 @@
 #include "sched.h"
 #include "signal.h"
 #include "fd.h"
+#include "mood.h"
 
 /** The osl tables used by afs. \sa blob.c. */
 enum afs_table_num {
@@ -57,13 +60,13 @@ enum afs_table_num {
 };
 
 static struct afs_table afs_tables[NUM_AFS_TABLES] = {
-       [TBLNUM_AUDIO_FILES] = {.init = aft_init},
-       [TBLNUM_ATTRIBUTES] = {.init = attribute_init},
-       [TBLNUM_SCORES] = {.init = score_init},
-       [TBLNUM_MOODS] = {.init = moods_init},
-       [TBLNUM_LYRICS] = {.init = lyrics_init},
-       [TBLNUM_IMAGES] = {.init = images_init},
-       [TBLNUM_PLAYLIST] = {.init = playlists_init},
+       [TBLNUM_AUDIO_FILES] = {.init = aft_init, .name = "audio_files"},
+       [TBLNUM_ATTRIBUTES] = {.init = attribute_init, .name = "attributes"},
+       [TBLNUM_SCORES] = {.init = score_init, .name = "scores"},
+       [TBLNUM_MOODS] = {.init = moods_init, .name = "moods"},
+       [TBLNUM_LYRICS] = {.init = lyrics_init, .name = "lyrics"},
+       [TBLNUM_IMAGES] = {.init = images_init, .name = "images"},
+       [TBLNUM_PLAYLIST] = {.init = playlists_init, .name = "playlists"},
 };
 
 struct command_task {
@@ -88,7 +91,6 @@ static struct signal_task signal_task_struct;
 static enum play_mode current_play_mode;
 static char *current_mop; /* mode or playlist specifier. NULL means dummy mooe */
 
-
 /**
  * A random number used to "authenticate" the connection.
  *
@@ -345,7 +347,7 @@ static int action_if_pattern_matches(struct osl_row *row, void *data)
        struct pattern_match_data *pmd = data;
        struct osl_object name_obj;
        const char *p, *name;
-       int ret = osl_get_object(pmd->table, row, pmd->match_col_num, &name_obj);
+       int ret = osl(osl_get_object(pmd->table, row, pmd->match_col_num, &name_obj));
        const char *pattern_txt = (const char *)pmd->patterns.data;
 
        if (ret < 0)
@@ -372,16 +374,15 @@ static int action_if_pattern_matches(struct osl_row *row, void *data)
  *
  * \param pmd Describes what to match and how.
  *
- * \return The return value of the underlying call to osl_rbtree_loop()
- * or osl_rbtree_loop_reverse().
+ * \return Standard.
  */
 int for_each_matching_row(struct pattern_match_data *pmd)
 {
        if (pmd->pm_flags & PM_REVERSE_LOOP)
-               return osl_rbtree_loop_reverse(pmd->table, pmd->loop_col_num, pmd,
-                       action_if_pattern_matches);
-       return osl_rbtree_loop(pmd->table, pmd->loop_col_num, pmd,
-                       action_if_pattern_matches);
+               return osl(osl_rbtree_loop_reverse(pmd->table, pmd->loop_col_num, pmd,
+                       action_if_pattern_matches));
+       return osl(osl_rbtree_loop(pmd->table, pmd->loop_col_num, pmd,
+                       action_if_pattern_matches));
 }
 
 /**
@@ -660,7 +661,7 @@ static void get_database_dir(void)
                else {
                        char *home = para_homedir();
                        database_dir = make_message(
-                               "%s/.paraslash/afs_database", home);
+                               "%s/.paraslash/afs_database-0.4", home);
                        free(home);
                }
        }
@@ -1002,7 +1003,7 @@ static void create_tables_callback(int fd, const struct osl_object *query)
 {
        uint32_t table_mask = *(uint32_t *)query->data;
        int i, ret;
-       char *buf;
+       struct para_buffer pb = {.buf = NULL};
 
        close_afs_tables();
        for (i = 0; i < NUM_AFS_TABLES; i++) {
@@ -1015,15 +1016,15 @@ static void create_tables_callback(int fd, const struct osl_object *query)
                ret = t->create(database_dir);
                if (ret < 0)
                        goto out;
+               para_printf(&pb, "successfully created %s table\n", t->name);
        }
        ret = open_afs_tables();
 out:
-       if (ret >= 0)
-               buf = make_message("successfully created afs table(s)\n");
-       else
-               buf = make_message("%s\n", para_strerror(-ret));
-       pass_buffer_as_shm(buf, strlen(buf), &fd);
-       free(buf);
+       if (ret < 0)
+               para_printf(&pb, "%s\n", para_strerror(-ret));
+       if (pb.buf)
+               pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+       free(pb.buf);
 }
 
 int com_init(struct rc4_context *rc4c, int argc, char * const * const argv)