]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server: Convert com_mvatt() to lopsub.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 2 Oct 2015 21:21:11 +0000 (21:21 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2017 09:02:28 +0000 (11:02 +0200)
We need to cast the obj->data pointer to a non-constant type because
the osl library functions expect void *, which results in a warning
without the cast.

afs.cmd
attribute.c
m4/lls/server_cmd.suite.m4

diff --git a/afs.cmd b/afs.cmd
index 2b9e4f8e15947c6ee60a21cfea1eda9548079fa7..5a265d6164678d2758ab3d2cdb512d91f9750dee 100644 (file)
--- a/afs.cmd
+++ b/afs.cmd
@@ -59,12 +59,6 @@ U: addatt attribute1...
 H: This adds new attributes to the attribute table. At most 64
 H: attributes may be defined.
 ---
-N: mvatt
-P: AFS_READ | AFS_WRITE
-D: Rename an attribute.
-U: mvatt old new
-H: Rename attribute old to new.
----
 N: check
 P: AFS_READ
 D: Run integrity checks against osl tables.
index 99e7865eaf599a14311d31de6778234b48d64136..2beabafa7a3d4b65f7ea87207b0c1e020f15a1d3 100644 (file)
@@ -254,34 +254,46 @@ int com_addatt(struct command_context *cc)
 
 static int com_mvatt_callback(struct afs_callback_arg *aca)
 {
-       char *old = aca->query.data;
-       size_t size = strlen(old) + 1;
-       char *new = old + size;
-       struct osl_object obj = {.data = old, .size = size};
+       const struct lls_command *cmd = SERVER_CMD_CMD_PTR(MVATT);
+       const char *old, *new;
+       struct osl_object obj;
        struct osl_row *row;
        int ret;
 
+       ret = lls(lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr));
+       assert(ret >= 0);
+       old = lls_input(0, aca->lpr);
+       new = lls_input(1, aca->lpr);
+       obj.data = (char *)old;
+       obj.size = strlen(old) + 1;
        ret = osl(osl_get_row(attribute_table, ATTCOL_NAME, &obj, &row));
        if (ret < 0)
                goto out;
-       obj.data = new;
+       obj.data = (char *)new;
        obj.size = strlen(new) + 1;
+       /* The update fails if the destination attribute exists. */
        ret = osl(osl_update_object(attribute_table, row, ATTCOL_NAME, &obj));
 out:
        if (ret < 0)
                para_printf(&aca->pbout, "cannot rename %s to %s\n", old, new);
        else
                ret = afs_event(ATTRIBUTE_RENAME, &aca->pbout, NULL);
+       lls_free_parse_result(aca->lpr, cmd);
        return ret;
 }
 
-int com_mvatt(struct command_context *cc)
+static int com_mvatt(struct command_context *cc, struct lls_parse_result *lpr)
 {
-       if (cc->argc != 3)
-               return -E_ATTR_SYNTAX;
-       return send_standard_callback_request(cc->argc - 1, cc->argv + 1,
-               com_mvatt_callback, afs_cb_result_handler, cc);
+       const struct lls_command *cmd = SERVER_CMD_CMD_PTR(MVATT);
+       char *errctx;
+       int ret = lls(lls_check_arg_count(lpr, 2, 2, &errctx));
+       if (ret < 0) {
+               send_errctx(cc, errctx);
+               return ret;
+       }
+       return send_lls_callback_request(com_mvatt_callback, cmd, lpr, cc);
 }
+EXPORT_SERVER_CMD_HANDLER(mvatt);
 
 static int remove_attribute(struct osl_table *table, struct osl_row *row,
                const char *name, void *data)
index b113934164315741699cc3f119f122d0c34cb8c2..fdc8ff4f349881ca68b8c42e1800f56779267a3e 100644 (file)
@@ -136,6 +136,16 @@ aux_info_prefix = Permissions:
                short_opt = r
                summary = reverse sort order
 
+[subcommand mvatt]
+       purpose = rename an attribute
+       synopsis = source dest
+       aux_info = AFS_READ | AFS_WRITE
+       [description]
+               Rename the attribute given by the first argument to the destination
+               given by the second argument. It is an error if the destination
+               attribute exists.
+       [/description]
+
 [subcommand next]
        purpose = close the stream and start to stream the next audio file
        aux_info = VSS_READ | VSS_WRITE