X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=attribute.c;h=99e7865eaf599a14311d31de6778234b48d64136;hb=db8b6df30d17d9f93c60758e156699067121cbb5;hp=d5f488467e4854f5463d5bf72df3b4f0e2d6cb02;hpb=a9bdbe2c8a73675be499fc95b935f3839e30c575;p=paraslash.git diff --git a/attribute.c b/attribute.c index d5f48846..99e7865e 100644 --- a/attribute.c +++ b/attribute.c @@ -10,6 +10,7 @@ #include #include +#include "server_cmd.lsg.h" #include "para.h" #include "error.h" #include "crypt.h" @@ -107,30 +108,16 @@ int get_attribute_bitnum_by_name(const char *att_name, unsigned char *bitnum) return 1; } -/** - * Flags used by the lsatt command. - * - * \param \sa com_lsatt(). - */ -enum lsatt_flags { - /** Whether "-a" was given for the lsatt command. */ - LSATT_FLAG_SORT_BY_ID = 1, - /** Whether "-l" was given for the lsatt command. */ - LSATT_FLAG_LONG = 2, - /** Reverse sort order. */ - LSATT_FLAG_REVERSE = 4 -}; - /** Data passed to the action function of lsatt */ static int print_attribute(struct osl_table *table, struct osl_row *row, const char *name, void *data) { struct afs_callback_arg *aca = data; - unsigned flags = *(unsigned *)aca->query.data; + bool l_given = SERVER_CMD_OPT_GIVEN(LSATT, LONG, aca->lpr); struct osl_object bitnum_obj; int ret; - if (!(flags & LSATT_FLAG_LONG)) { + if (!l_given) { para_printf(&aca->pbout, "%s\n", name); return 1; } @@ -146,21 +133,27 @@ static int print_attribute(struct osl_table *table, struct osl_row *row, static int com_lsatt_callback(struct afs_callback_arg *aca) { - unsigned flags = *(unsigned *)aca->query.data; + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LSATT); + bool i_given, r_given; int ret; struct pattern_match_data pmd = { .table = attribute_table, .loop_col_num = ATTCOL_NAME, .match_col_num = ATTCOL_NAME, - .patterns = {.data = (char *)aca->query.data + sizeof(flags), - .size = aca->query.size - sizeof(flags)}, .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING, .data = aca, .action = print_attribute }; - if (flags & LSATT_FLAG_SORT_BY_ID) + + ret = lls(lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr)); + assert(ret >= 0); + pmd.lpr = aca->lpr; + i_given = SERVER_CMD_OPT_GIVEN(LSATT, ID_SORT, aca->lpr); + r_given = SERVER_CMD_OPT_GIVEN(LSATT, REVERSE, aca->lpr); + + if (i_given) pmd.loop_col_num = ATTCOL_BITNUM; - if (flags & LSATT_FLAG_REVERSE) + if (r_given) pmd.pm_flags |= PM_REVERSE_LOOP; ret = for_each_matching_row(&pmd); if (ret < 0) @@ -168,46 +161,22 @@ static int com_lsatt_callback(struct afs_callback_arg *aca) if (pmd.num_matches == 0) ret = -E_NO_MATCH; out: + lls_free_parse_result(aca->lpr, cmd); return ret; } -int com_lsatt(struct command_context *cc) +static int com_lsatt(struct command_context *cc, struct lls_parse_result *lpr) { - unsigned flags = 0; - struct osl_object options = {.data = &flags, .size = sizeof(flags)}; - int i; - - for (i = 1; i < cc->argc; i++) { - const char *arg = cc->argv[i]; - if (arg[0] != '-') - break; - if (!strcmp(arg, "--")) { - i++; - break; - } - if (!strcmp(arg, "-i")) { - flags |= LSATT_FLAG_SORT_BY_ID; - continue; - } - if (!strcmp(arg, "-l")) { - flags |= LSATT_FLAG_LONG; - continue; - } - if (!strcmp(arg, "-r")) { - flags |= LSATT_FLAG_REVERSE; - continue; - } - } - return send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i, - com_lsatt_callback, afs_cb_result_handler, cc); + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LSATT); + return send_lls_callback_request(com_lsatt_callback, cmd, lpr, cc); } +EXPORT_SERVER_CMD_HANDLER(lsatt); struct addatt_event_data { const char *name; unsigned char bitnum; }; - static int com_addatt_callback(struct afs_callback_arg *aca) { char *p;