From 3f696a82bbb79cb07bfdb8e510bb4f3515570cec Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 2 Oct 2015 21:21:11 +0000 Subject: [PATCH] server: Convert com_mvatt() to lopsub. 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 | 6 ------ attribute.c | 32 ++++++++++++++++++++++---------- m4/lls/server_cmd.suite.m4 | 10 ++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/afs.cmd b/afs.cmd index 2b9e4f8e..5a265d61 100644 --- 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. diff --git a/attribute.c b/attribute.c index 99e7865e..2beabafa 100644 --- a/attribute.c +++ b/attribute.c @@ -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) diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index b1139341..fdc8ff4f 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -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 -- 2.39.5