#include <regex.h>
#include <osl.h>
+#include <lopsub.h>
+#include "server_cmd.lsg.h"
#include "para.h"
#include "error.h"
#include "crypt.h"
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;
}
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_BITNUM,
+ .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)
- pmd.loop_col_num = ATTCOL_NAME;
- if (flags & LSATT_FLAG_REVERSE)
+
+ 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 (r_given)
pmd.pm_flags |= PM_REVERSE_LOOP;
ret = for_each_matching_row(&pmd);
if (ret < 0)
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;
out:
if (ret < 0)
para_printf(&aca->pbout, "%s: %s\n", p, para_strerror(-ret));
- return 0;
+ return ret;
}
int com_addatt(struct command_context *cc)
static int att_logical_or(struct osl_row *row, void *data)
{
- uint64_t *att_mask = data;
+ uint64_t *att_mask = data, one = 1;
struct osl_object bitnum_obj;
int ret = osl_get_object(attribute_table, row, ATTCOL_BITNUM, &bitnum_obj);
if (ret < 0)
return ret;
- *att_mask |= 1 << *(unsigned char *)bitnum_obj.data;
+ *att_mask |= one << *(unsigned char *)bitnum_obj.data;
return 0;
}
return ret;
}
attribute_table = NULL;
- if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
+ if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
return 1;
return ret;
}