From 9e1458c37f119335e7338b998c1e820c8edaff33 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 28 May 2012 09:13:42 -0400 Subject: [PATCH] Add GETINFO --data. --- src/commands.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/commands.c b/src/commands.c index 833610e8..7b5254f3 100644 --- a/src/commands.c +++ b/src/commands.c @@ -72,6 +72,7 @@ #define OPT_SIGN 0x0080 #define OPT_LIST_ALL 0x0100 #define OPT_LIST_WITH_TARGET 0x0200 +#define OPT_DATA 0x0400 struct command_table_s { const gchar *name; @@ -3467,15 +3468,47 @@ static gpg_error_t keygrip_command(assuan_context_t ctx, gchar *line) return send_error(ctx, rc); } +static gpg_error_t parse_opt_data(gpointer data, gpointer value) +{ + struct client_s *client = data; + + (void)value; + client->opts |= OPT_DATA; + return 0; +} + static gpg_error_t getinfo_command(assuan_context_t ctx, gchar *line) { struct client_s *client = assuan_get_pointer(ctx); gpg_error_t rc; + gchar buf[ASSUAN_LINELENGTH]; + struct argv_s *args[] = { + &(struct argv_s) { "data", OPTION_TYPE_NOARG, parse_opt_data }, + NULL + }; - if (!g_ascii_strcasecmp(line, "clients")) - rc = send_status(ctx, STATUS_CLIENTS, NULL); - else if (!g_ascii_strcasecmp(line, "cache")) - rc = send_status(ctx, STATUS_CACHE, NULL); + rc = parse_options(&line, args, client); + if (rc) + return send_error(ctx, rc); + + if (!g_ascii_strcasecmp(line, "clients")) { + if (client->opts&OPT_DATA) { + MUTEX_LOCK(&cn_mutex); + print_fmt(buf, sizeof(buf), "%i", g_slist_length(cn_thread_list)); + MUTEX_UNLOCK(&cn_mutex); + rc = xfer_data(ctx, buf, strlen(buf)); + } + else + rc = send_status(ctx, STATUS_CLIENTS, NULL); + } + else if (!g_ascii_strcasecmp(line, "cache")) { + if (client->opts&OPT_DATA) { + print_fmt(buf, sizeof(buf), "%u", cache_file_count()); + rc = xfer_data(ctx, buf, strlen(buf)); + } + else + rc = send_status(ctx, STATUS_CACHE, NULL); + } else if (!g_ascii_strcasecmp(line, "pid")) { gchar buf[32]; pid_t pid = getpid(); @@ -3582,14 +3615,17 @@ void init_commands() )); new_command("GETINFO", TRUE, TRUE, getinfo_command, _( -"GETINFO CACHE | CLIENTS | PID | LAST_ERROR | VERSION\n" +"GETINFO [--data] CACHE | CLIENTS | PID | LAST_ERROR | VERSION\n" "Get server and other information: @var{cache} returns the number of cached " "documents via a status message. @var{clients} returns the number of " "connected clients via a status message. @var{pid} returns the process ID " "number of the server via a data response. @var{VERSION} returns the server " "version number and compile-time features with a data response with each " "being space delimited. @var{LAST_ERROR} returns a detailed description of " -"the last failed command when available. @xref{Status Messages}." +"the last failed command when available. @xref{Status Messages}. " +"\n" +"When the @option{--data} option is specified then the result will be send " +"via a data response rather than a status message." )); new_command("PASSWD", FALSE, FALSE, passwd_command, _( -- 2.11.4.GIT