X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.c;h=bd3d17c8335bea17bcd95ec909ddeef8cf779d7f;hp=cba2afb40464a5373ef2320f65b3966845ba357d;hb=79a88784e0819c1bbe9de8d39a0e05997c8211f6;hpb=263cda6ee386b9c5d409ca02798632ca67282796 diff --git a/command.c b/command.c index cba2afb4..bd3d17c8 100644 --- a/command.c +++ b/command.c @@ -16,18 +16,19 @@ #include "server.lsg.h" #include "para.h" #include "error.h" +#include "lsu.h" #include "crypt.h" #include "sideband.h" #include "command.h" #include "string.h" #include "afh.h" #include "afs.h" +#include "net.h" #include "server.h" #include "list.h" #include "send.h" #include "sched.h" #include "vss.h" -#include "net.h" #include "daemon.h" #include "fd.h" #include "ipc.h" @@ -528,63 +529,35 @@ out: } EXPORT_SERVER_CMD_HANDLER(stat); -/* fixed-length, human readable permission string */ -const char *server_cmd_perms_str(unsigned int perms) +const char *aux_info_cb(unsigned cmd_num, bool verbose) { - static char result[5]; - - result[0] = perms & AFS_READ? 'a' : '-'; - result[1] = perms & AFS_WRITE? 'A' : '-'; - result[2] = perms & VSS_READ? 'v' : '-'; - result[3] = perms & VSS_WRITE? 'V' : '-'; - result[4] = '\0'; - return result; -} + static char result[80]; + unsigned perms = server_command_perms[cmd_num]; -static int send_list_of_commands(struct command_context *cc) -{ - int i; - const struct lls_command *cmd; - char *msg = para_strdup(""); - - for (i = 1; (cmd = lls_cmd(i, server_cmd_suite)); i++) { - const char *perms = server_cmd_perms_str(server_command_perms[i]); - char *tmp = make_message("%s%s\t%s\t%s\n", msg, - lls_command_name(cmd), perms, lls_purpose(cmd)); - free(msg); - msg = tmp; + if (verbose) { + /* permissions: VSS_READ | VSS_WRITE */ + sprintf(result, "permissions: %s", + server_command_perms_txt[cmd_num]); + } else { + result[0] = perms & AFS_READ? 'a' : '-'; + result[1] = perms & AFS_WRITE? 'A' : '-'; + result[2] = perms & VSS_READ? 'v' : '-'; + result[3] = perms & VSS_WRITE? 'V' : '-'; + result[4] = '\0'; } - return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false); + return result; } static int com_help(struct command_context *cc, struct lls_parse_result *lpr) { - const char *perms; - char *long_help, *buf, *errctx; + char *buf; int ret; - const struct lls_command *cmd; + unsigned n; + bool long_help = SERVER_CMD_OPT_GIVEN(HELP, LONG, lpr); - ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx)); - if (ret < 0) { - send_errctx(cc, errctx); - return ret; - } - if (lls_num_inputs(lpr) == 0) - return send_list_of_commands(cc); - /* argument given for help */ - ret = lls(lls_lookup_subcmd(lls_input(0, lpr), server_cmd_suite, - &errctx)); - if (ret < 0) { - send_errctx(cc, errctx); - return ret; - } - cmd = lls_cmd(ret, server_cmd_suite); - perms = server_command_perms_txt[ret]; - long_help = lls_long_help(cmd); - assert(long_help); - ret = xasprintf(&buf, "%spermissions: %s\n", long_help, perms); - free(long_help); - return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false); + lsu_com_help(long_help, lpr, server_cmd_suite, aux_info_cb, &buf, &n); + ret = send_sb(&cc->scc, buf, n, SBD_OUTPUT, false); + return ret; } EXPORT_SERVER_CMD_HANDLER(help);