]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - blob.c
afs: Make afs callbacks more flexible.
[paraslash.git] / blob.c
diff --git a/blob.c b/blob.c
index fbfea00ce90a2ac4bf49c5b8e7002248d5c329e0..0b5f1f9b01f6102b6ff78bcae0645b6ee2debec1 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -131,14 +131,14 @@ static int print_blob(struct osl_table *table, struct osl_row *row,
 }
 
 static int com_lsblob_callback(struct osl_table *table,
-               int fd, const struct osl_object *query)
+               struct afs_callback_arg *aca)
 {
        struct lsblob_action_data lbad = {
-               .flags = *(uint32_t *)query->data,
+               .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,
@@ -146,8 +146,8 @@ static int com_lsblob_callback(struct osl_table *table,
        };
        struct pattern_match_data pmd = {
                .table = table,
-               .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)},
                .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING | PM_SKIP_EMPTY_NAME,
                .match_col_num = BLOBCOL_NAME,
                .data = &lbad,
@@ -171,7 +171,7 @@ out:
        return ret;
 }
 
-static int com_lsblob(callback_function *f, struct command_context *cc)
+static int com_lsblob(afs_callback *f, struct command_context *cc)
 {
        uint32_t flags = 0;
        struct osl_object options = {.data = &flags, .size = sizeof(flags)};
@@ -220,17 +220,17 @@ static int cat_blob(struct osl_table *table, struct osl_row *row,
        return (ret < 0)? ret : ret2;
 }
 
-static int com_catblob_callback(struct osl_table *table, int fd,
-               const struct osl_object *query)
+static int com_catblob_callback(struct osl_table *table,
+               struct afs_callback_arg *aca)
 {
        int ret;
        struct pattern_match_data pmd = {
                .table = table,
-               .patterns = *query,
+               .patterns = aca->query,
                .loop_col_num = BLOBCOL_NAME,
                .match_col_num = BLOBCOL_NAME,
                .pm_flags = PM_SKIP_EMPTY_NAME,
-               .data = &fd,
+               .data = &aca->fd,
                .action = cat_blob
        };
        ret = for_each_matching_row(&pmd);
@@ -241,7 +241,7 @@ static int com_catblob_callback(struct osl_table *table, int fd,
        return ret;
 }
 
-static int com_catblob(callback_function *f, struct command_context *cc)
+static int com_catblob(afs_callback *f, struct command_context *cc)
 {
        if (cc->argc < 2)
                return -E_BLOB_SYNTAX;
@@ -261,21 +261,21 @@ static int remove_blob(struct osl_table *table, struct osl_row *row,
        return 1;
 }
 
-static int com_rmblob_callback(struct osl_table *table, int fd,
-               const struct osl_object *query)
+static int com_rmblob_callback(struct osl_table *table,
+               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,
        };
        struct pattern_match_data pmd = {
                .table = table,
-               .patterns = *query,
+               .patterns = aca->query,
                .loop_col_num = BLOBCOL_NAME,
                .match_col_num = BLOBCOL_NAME,
                .pm_flags = PM_SKIP_EMPTY_NAME,
@@ -289,14 +289,14 @@ static int com_rmblob_callback(struct osl_table *table, int fd,
                ret = -E_NO_MATCH;
        else {
                para_printf(&pb, "removed %d blob(s)\n", pmd.num_matches);
-               afs_event(BLOB_RENAME, NULL, table);
+               ret = afs_event(BLOB_RENAME, NULL, table);
        }
 out:
        flush_and_free_pb(&pb);
        return ret;
 }
 
-static int com_rmblob(callback_function *f, struct command_context *cc)
+static int com_rmblob(afs_callback *f, struct command_context *cc)
 {
        if (cc->argc < 2)
                return -E_MOOD_SYNTAX;
@@ -304,11 +304,11 @@ static int com_rmblob(callback_function *f, struct command_context *cc)
                afs_cb_result_handler, cc);
 }
 
-static int com_addblob_callback(struct osl_table *table, int fd,
-               const struct osl_object *query)
+static int com_addblob_callback(struct osl_table *table,
+               struct afs_callback_arg *aca)
 {
        struct osl_object objs[NUM_BLOB_COLUMNS];
-       char *name = query->data, *msg;
+       char *name = aca->query.data, *msg;
        size_t name_len = strlen(name) + 1, msg_len;
        uint32_t id;
        unsigned num_rows;
@@ -342,7 +342,7 @@ static int com_addblob_callback(struct osl_table *table, int fd,
                                goto out;
                        id = *(uint32_t *)obj.data;
                        obj.data = name + name_len;
-                       obj.size = query->size - name_len;
+                       obj.size = aca->query.size - name_len;
                        ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj));
                        goto out;
                }
@@ -367,17 +367,17 @@ static int com_addblob_callback(struct osl_table *table, int fd,
        objs[BLOBCOL_NAME].data = name;
        objs[BLOBCOL_NAME].size = name_len;
        objs[BLOBCOL_DEF].data = name + name_len;
-       objs[BLOBCOL_DEF].size = query->size - name_len;
+       objs[BLOBCOL_DEF].size = aca->query.size - name_len;
        ret = osl(osl_add_row(table, objs));
        if (ret < 0)
                goto out;
-       afs_event(BLOB_ADD, NULL, table);
+       ret = afs_event(BLOB_ADD, NULL, table);
 out:
        if (ret < 0)
                msg_len = xasprintf(&msg, "cannot add %s\n", name);
        else
                msg_len = xasprintf(&msg, "added %s as id %u\n", name, id);
-       pass_buffer_as_shm(fd, SBD_OUTPUT, msg, msg_len);
+       pass_buffer_as_shm(aca->fd, SBD_OUTPUT, msg, msg_len);
        free(msg);
        return ret;
 }
@@ -428,7 +428,7 @@ again:
  * afs process via the callback method.
  */
 static int stdin_command(struct command_context *cc, struct osl_object *arg_obj,
-               callback_function *f)
+               afs_callback *f)
 {
        struct osl_object query, stdin_obj;
        int ret;
@@ -451,7 +451,7 @@ static int stdin_command(struct command_context *cc, struct osl_object *arg_obj,
        return ret;
 }
 
-static int com_addblob(callback_function *f, struct command_context *cc)
+static int com_addblob(afs_callback *f, struct command_context *cc)
 {
        struct osl_object arg_obj;
 
@@ -464,16 +464,16 @@ static int com_addblob(callback_function *f, struct command_context *cc)
        return stdin_command(cc, &arg_obj, f);
 }
 
-static int com_mvblob_callback(struct osl_table *table, int fd,
-               const struct osl_object *query)
+static int com_mvblob_callback(struct osl_table *table,
+               struct afs_callback_arg *aca)
 {
-       char *src = (char *) query->data;
+       char *src = (char *)aca->query.data;
        struct osl_object obj = {.data = src, .size = strlen(src) + 1};
        char *dest = src + obj.size;
        struct osl_row *row;
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
+               .private_data = &aca->fd,
                .max_size_handler = afs_max_size_handler
        };
        int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
@@ -489,13 +489,13 @@ static int com_mvblob_callback(struct osl_table *table, int fd,
                para_printf(&pb, "cannot rename blob %s to %s\n", src, dest);
                goto out;
        }
-       afs_event(BLOB_RENAME, NULL, table);
+       ret = afs_event(BLOB_RENAME, NULL, table);
 out:
        flush_and_free_pb(&pb);
        return ret;
 }
 
-static int com_mvblob(callback_function *f, struct command_context *cc)
+static int com_mvblob(afs_callback *f, struct command_context *cc)
 {
        if (cc->argc != 3)
                return -E_MOOD_SYNTAX;
@@ -504,9 +504,9 @@ static int com_mvblob(callback_function *f, struct command_context *cc)
 }
 
 #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \
-       static int com_ ## cmd_name ## cmd_prefix ## _callback(int fd, const struct osl_object *query) \
+       static int com_ ## cmd_name ## cmd_prefix ## _callback(struct afs_callback_arg *aca) \
        { \
-               return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \
+               return com_ ## cmd_name ## blob_callback(table_name ## _table, aca); \
        } \
        int com_ ## cmd_name ## cmd_prefix(struct command_context *cc) \
        { \