afs: Make afs callbacks more flexible.
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 3d5170cca76df4861739202733856c5afe6d6cdf..07d8805f1444156b97acdcaf133106de01ff9bdd 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1293,16 +1293,16 @@ err:
        return ret;
 }
 
-static int com_ls_callback(int fd, const struct osl_object *query)
+static int com_ls_callback(struct afs_callback_arg *aca)
 {
-       struct ls_options *opts = query->data;
-       char *p, *pattern_start = (char *)query->data + sizeof(*opts);
+       struct ls_options *opts = aca->query.data;
+       char *p, *pattern_start = (char *)aca->query.data + sizeof(*opts);
        struct para_buffer b = {
                .max_size = shm_get_shmmax(),
                .flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0,
                .max_size_handler = afs_max_size_handler,
                .private_data = &(struct afs_max_size_handler_data) {
-                       .fd = fd,
+                       .fd = aca->fd,
                        .band = SBD_OUTPUT
                }
        };
@@ -1613,9 +1613,9 @@ enum com_add_flags {
        ADD_FLAG_ALL = 8,
 };
 
-static int com_add_callback(int fd, const struct osl_object *query)
+static int com_add_callback(struct afs_callback_arg *aca)
 {
-       char *buf = query->data, *path;
+       char *buf = aca->query.data, *path;
        struct osl_row *pb, *aft_row;
        struct osl_row *hs;
        struct osl_object objs[NUM_AFT_COLUMNS];
@@ -1629,7 +1629,7 @@ static int com_add_callback(int fd, const struct osl_object *query)
                .max_size = shm_get_shmmax(),
                .max_size_handler = afs_max_size_handler,
                .private_data = &(struct afs_max_size_handler_data) {
-                       .fd = fd,
+                       .fd = aca->fd,
                        .band = SBD_OUTPUT
                }
        };
@@ -1696,7 +1696,7 @@ static int com_add_callback(int fd, const struct osl_object *query)
        if (!objs[AFTCOL_AFHI].size) /* "impossible" */
                goto out;
        objs[AFTCOL_CHUNKS].data = buf + chunks_offset;
-       objs[AFTCOL_CHUNKS].size = query->size - chunks_offset;
+       objs[AFTCOL_CHUNKS].size = aca->query.size - chunks_offset;
        if (pb && !hs) { /* update pb's hash */
                char old_asc[2 * HASH_SIZE + 1];
                unsigned char *old_hash;
@@ -1756,26 +1756,26 @@ struct private_add_data {
        uint32_t flags;
 };
 
-static int path_brother_callback(int fd, const struct osl_object *query)
+static int path_brother_callback(struct afs_callback_arg *aca)
 {
-       char *path = query->data;
+       char *path = aca->query.data;
        struct osl_row *path_brother;
        int ret = aft_get_row_of_path(path, &path_brother);
        if (ret < 0)
                return ret;
-       return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
+       return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&path_brother,
                sizeof(path_brother));
 }
 
-static int hash_sister_callback(int fd, const struct osl_object *query)
+static int hash_sister_callback(struct afs_callback_arg *aca)
 {
-       unsigned char *hash = query->data;
+       unsigned char *hash = aca->query.data;
        struct osl_row *hash_sister;
 
        hash_sister = find_hash_sister(hash);
        if (!hash_sister)
                return 0;
-       return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
+       return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&hash_sister,
                sizeof(hash_sister));
 }
 
@@ -2018,13 +2018,13 @@ static int touch_audio_file(__a_unused struct osl_table *table,
        return afs_event(AFSI_CHANGE, &tad->pb, &aced);
 }
 
-static int com_touch_callback(int fd, const struct osl_object *query)
+static int com_touch_callback(struct afs_callback_arg *aca)
 {
-       struct touch_action_data tad = {.cto = query->data,
+       struct touch_action_data tad = {.cto = aca->query.data,
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &(struct afs_max_size_handler_data) {
-                               .fd = fd,
+                               .fd = aca->fd,
                                .band = SBD_OUTPUT
                        },
                        .max_size_handler = afs_max_size_handler
@@ -2035,8 +2035,8 @@ static int com_touch_callback(int fd, const struct osl_object *query)
                .table = audio_file_table,
                .loop_col_num = AFTCOL_HASH,
                .match_col_num = AFTCOL_PATH,
-               .patterns = {.data = (char *)query->data + sizeof(*tad.cto),
-                       .size = query->size - sizeof(*tad.cto)},
+               .patterns = {.data = (char *)aca->query.data + sizeof(*tad.cto),
+                       .size = aca->query.size - sizeof(*tad.cto)},
                .data = &tad,
                .action = touch_audio_file
        };
@@ -2155,13 +2155,13 @@ static int remove_audio_file(__a_unused struct osl_table *table,
        return ret;
 }
 
-static int com_rm_callback(int fd, const struct osl_object *query)
+static int com_rm_callback(struct afs_callback_arg *aca)
 {
-       struct com_rm_action_data crd = {.flags = *(uint32_t *)query->data,
+       struct com_rm_action_data crd = {.flags = *(uint32_t *)aca->query.data,
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &(struct afs_max_size_handler_data) {
-                               .fd = fd,
+                               .fd = aca->fd,
                                .band = SBD_OUTPUT
                        },
                        .max_size_handler = afs_max_size_handler
@@ -2172,8 +2172,8 @@ static int com_rm_callback(int fd, const struct osl_object *query)
                .table = audio_file_table,
                .loop_col_num = AFTCOL_HASH,
                .match_col_num = AFTCOL_PATH,
-               .patterns = {.data = (char *)query->data + sizeof(uint32_t),
-                       .size = query->size - sizeof(uint32_t)},
+               .patterns = {.data = (char *)aca->query.data + sizeof(uint32_t),
+                       .size = aca->query.size - sizeof(uint32_t)},
                .data = &crd,
                .action = remove_audio_file
        };
@@ -2288,27 +2288,27 @@ static int copy_selector_info(__a_unused struct osl_table *table,
        return afs_event(AFSI_CHANGE, &cad->pb, &aced);
 }
 
-static int com_cpsi_callback(int fd, const struct osl_object *query)
+static int com_cpsi_callback(struct afs_callback_arg *aca)
 {
        struct cpsi_action_data cad = {
-               .flags = *(unsigned *)query->data,
+               .flags = *(unsigned *)aca->query.data,
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &(struct afs_max_size_handler_data) {
-                               .fd = fd,
+                               .fd = aca->fd,
                                .band = SBD_OUTPUT
                        },
                        .max_size_handler = afs_max_size_handler
                }
        };
        int ret;
-       char *source_path = (char *)query->data + sizeof(cad.flags);
+       char *source_path = (char *)aca->query.data + sizeof(cad.flags);
        struct pattern_match_data pmd = {
                .table = audio_file_table,
                .loop_col_num = AFTCOL_HASH,
                .match_col_num = AFTCOL_PATH,
                .patterns = {.data = source_path + strlen(source_path) + 1,
-                       .size = query->size - sizeof(cad.flags)
+                       .size = aca->query.size - sizeof(cad.flags)
                                - strlen(source_path) - 1},
                .data = &cad,
                .action = copy_selector_info
@@ -2409,7 +2409,7 @@ static int change_atts(__a_unused struct osl_table *table,
        return afs_event(AFSI_CHANGE, &cad->pb, &aced);
 }
 
-static int com_setatt_callback(int fd, const struct osl_object *query)
+static int com_setatt_callback(struct afs_callback_arg *aca)
 {
        char *p;
        int ret;
@@ -2419,7 +2419,7 @@ static int com_setatt_callback(int fd, const struct osl_object *query)
                        .max_size = shm_get_shmmax(),
                        .max_size_handler = afs_max_size_handler,
                        .private_data = &(struct afs_max_size_handler_data) {
-                               .fd = fd,
+                               .fd = aca->fd,
                                .band = SBD_OUTPUT
                        }
                }
@@ -2433,7 +2433,11 @@ static int com_setatt_callback(int fd, const struct osl_object *query)
                .action = change_atts
        };
 
-       for (p = query->data; p < (char *)query->data + query->size; p += len + 1) {
+       for (
+               p = aca->query.data;
+               p < (char *)aca->query.data + aca->query.size;
+               p += len + 1
+       ) {
                char c;
                unsigned char bitnum;
 
@@ -2459,8 +2463,8 @@ static int com_setatt_callback(int fd, const struct osl_object *query)
        if (!cad.add_mask && !cad.del_mask)
                goto out;
        pmd.patterns.data = p;
-       assert(p < (char *)query->data + query->size);
-       pmd.patterns.size = (char *)query->data + query->size - p;
+       assert(p < (char *)aca->query.data + aca->query.size);
+       pmd.patterns.size = (char *)aca->query.data + aca->query.size - p;
        ret = for_each_matching_row(&pmd);
        if (ret < 0)
                goto out;
@@ -2479,15 +2483,15 @@ int com_setatt(struct command_context *cc)
                com_setatt_callback, afs_cb_result_handler, cc);
 }
 
-static int afs_stat_callback(int fd, const struct osl_object *query)
+static int afs_stat_callback(struct afs_callback_arg *aca)
 {
-       int *parser_friendly = query->data;
+       int *parser_friendly = aca->query.data;
        char *buf = *parser_friendly?
                parser_friendly_status_items : status_items;
 
        if (!buf)
                return 0;
-       return pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
+       return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, buf, strlen(buf));
 }
 
 /**
@@ -2550,20 +2554,19 @@ static int check_audio_file(struct osl_row *row, void *data)
 /**
  * Check the audio file table for inconsistencies.
  *
- * \param fd The afs socket.
- * \param query Unused.
+ * \param aca Only ->pbout is used for diagnostics.
  *
  * \return Standard. Inconsistencies are reported but not regarded as an error.
  *
  * \sa com_check().
  */
-int aft_check_callback(int fd, __a_unused const struct osl_object *query)
+int aft_check_callback(struct afs_callback_arg *aca)
 {
        int ret;
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
                .private_data = &(struct afs_max_size_handler_data) {
-                       .fd = fd,
+                       .fd = aca->fd,
                        .band = SBD_OUTPUT
                },
                .max_size_handler = afs_max_size_handler