From 74592ed100009a2d73e03861ae9626363f06aca9 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 2 Oct 2015 21:13:33 +0000 Subject: [PATCH] server: Convert com_addatt() to lopsub. Another simple command without options which is easy to convert. The only thing worth noting is that we now fail the command early if more than 64 arguments are given when previously we only checked that at least one argument is given. --- afs.cmd | 7 ----- attribute.c | 53 +++++++++++++++++++++----------------- m4/lls/server_cmd.suite.m4 | 9 +++++++ 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/afs.cmd b/afs.cmd index 9ee51f17..6047dbd9 100644 --- a/afs.cmd +++ b/afs.cmd @@ -52,13 +52,6 @@ H: b: by bit rate H: d: by duration H: a: by audio format --- -N: addatt -P: AFS_READ | AFS_WRITE -D: Add new attribute(s). -U: addatt attribute1... -H: This adds new attributes to the attribute table. At most 64 -H: attributes may be defined. ---- T: add N: add@member@ O: int com_add@member@(struct command_context *cc); diff --git a/attribute.c b/attribute.c index c869e391..637e1f51 100644 --- a/attribute.c +++ b/attribute.c @@ -179,28 +179,31 @@ struct addatt_event_data { static int com_addatt_callback(struct afs_callback_arg *aca) { - char *p; - int ret = 1; + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(ADDATT); + int i, ret = 1; size_t len; + unsigned num_inputs; - for ( - p = aca->query.data; - p < (char *)aca->query.data + aca->query.size; - p += len + 1 - ) { + ret = lls(lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr)); + assert(ret >= 0); + num_inputs = lls_num_inputs(aca->lpr); + for (i = 0; i < num_inputs; i++) { + const char *name = lls_input(i, aca->lpr); struct osl_object objs[NUM_ATT_COLUMNS]; struct osl_row *row; unsigned char bitnum; struct addatt_event_data aed; - len = strlen(p); - if (!len || p[len - 1] == '-' || p[len - 1] == '+') { - para_printf(&aca->pbout, "invalid attribute name: %s\n", p); + len = strlen(name); + if (len == 0 || name[len - 1] == '-' || name[len - 1] == '+') { + para_printf(&aca->pbout, + "invalid attribute name: %s\n", name); continue; } - ret = get_attribute_bitnum_by_name(p, &bitnum); + ret = get_attribute_bitnum_by_name(name, &bitnum); if (ret >= 0) { - para_printf(&aca->pbout, "attribute \"%s\" already exists\n", p); + para_printf(&aca->pbout, + "attribute \"%s\" already exists\n", name); continue; } if (ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) /* error */ @@ -221,12 +224,12 @@ static int com_addatt_callback(struct afs_callback_arg *aca) ret = -E_ATT_TABLE_FULL; goto out; } - objs[ATTCOL_NAME].data = p; + objs[ATTCOL_NAME].data = (char *)name; objs[ATTCOL_NAME].size = len + 1; ret = osl(osl_add_row(attribute_table, objs)); if (ret < 0) goto out; - aed.name = p; + aed.name = name; aed.bitnum = bitnum; ret = afs_event(ATTRIBUTE_ADD, &aca->pbout, &aed); if (ret < 0) @@ -235,22 +238,24 @@ static int com_addatt_callback(struct afs_callback_arg *aca) } out: if (ret < 0) - para_printf(&aca->pbout, "%s: %s\n", p, para_strerror(-ret)); + para_printf(&aca->pbout, "error while adding %s\n", + lls_input(i, aca->lpr)); return ret; } -int com_addatt(struct command_context *cc) +static int com_addatt(struct command_context *cc, struct lls_parse_result *lpr) { - int ret; + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(ADDATT); + char *errctx; + int ret = lls(lls_check_arg_count(lpr, 1, 64, &errctx)); - if (cc->argc < 2) - return -E_ATTR_SYNTAX; - ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1, - com_addatt_callback, afs_cb_result_handler, cc); - if (ret < 0) - send_strerror(cc, -ret); - return ret; + if (ret < 0) { + send_errctx(cc, errctx); + return ret; + } + return send_lls_callback_request(com_addatt_callback, cmd, lpr, cc); } +EXPORT_SERVER_CMD_HANDLER(addatt); static int com_mvatt_callback(struct afs_callback_arg *aca) { diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index 2ddc53dc..83041ddf 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -52,6 +52,15 @@ aux_info_prefix = Permissions: Print what is being done. [/help] +[subcommand addatt] + purpose = add new attribute(s) + non-opts-name = attribute... + aux_info = AFS_READ | AFS_WRITE + [description] + This adds new attributes to the attribute table. At most 64 attributes + may be defined. + [/description] + [subcommand check] purpose = run integrity checks on database tables aux_info = AFS_READ -- 2.39.5