aboutsummaryrefslogtreecommitdiffstats
path: root/agent/command.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2006-11-14 14:53:42 +0000
committerWerner Koch <[email protected]>2006-11-14 14:53:42 +0000
commita98ea89fa5737fed15055ecfc9cbba121e372207 (patch)
treee752e00b9538eaa32e3fe275c3a4967c0909fe22 /agent/command.c
parentsm/ (diff)
downloadgnupg-a98ea89fa5737fed15055ecfc9cbba121e372207.tar.gz
gnupg-a98ea89fa5737fed15055ecfc9cbba121e372207.zip
New command GETEVENTCOUNTER.
* command.c (bump_key_eventcounter): New. (bump_card_eventcounter): New. (cmd_geteventcounter): New command. * gpg-agent.c (handle_signal): Call bump_card_eventcounter. * findkey.c (agent_write_private_key): Call bump_key_eventcounter. * trustlist.c (agent_reload_trustlist): Ditto.
Diffstat (limited to 'agent/command.c')
-rw-r--r--agent/command.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/agent/command.c b/agent/command.c
index d91b690df..981232d40 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -73,6 +73,28 @@ struct putval_item_s
static struct putval_item_s *putval_list;
+
+/* To help polling clients, we keep tarck of the number of certain
+ events. This structure keeps those counters. The counters are
+ integers and there should be no problem if they are overflowing as
+ callers need to check only whether a counter changed. The actual
+ values are not meaningful. */
+struct
+{
+ /* Incremented if any of the other counters below changed. */
+ unsigned int any;
+
+ /* Incremented if a key is added or removed from the internal privat
+ key database. */
+ unsigned int key;
+
+ /* Incremented if a change of the card readers stati has been
+ detected. */
+ unsigned int card;
+
+} eventcounter;
+
+
@@ -293,6 +315,62 @@ agent_write_status (ctrl_t ctrl, const char *keyword, ...)
+/* GETEVENTCOUNTER
+
+ Return a a status line named EVENTCOUNTER with the current values
+ of all event counters. The values are decimal numbers in the range
+ 0 to UINT_MAX and wrapping around to 0. The actual values should
+ not be relied upon, they shall only be used to detect a change.
+
+ The currently defined counters are:
+
+ ANY - Incremented with any change of any of the other counters.
+ KEY - Incremented for added or removed private keys.
+ CARD - Incremented for changes of the card readers stati.
+*/
+static int
+cmd_geteventcounter (assuan_context_t ctx, char *line)
+{
+ ctrl_t ctrl = assuan_get_pointer (ctx);
+ char any_counter[25];
+ char key_counter[25];
+ char card_counter[25];
+
+ snprintf (any_counter, sizeof any_counter, "%u", eventcounter.any);
+ snprintf (key_counter, sizeof key_counter, "%u", eventcounter.key);
+ snprintf (card_counter, sizeof card_counter, "%u", eventcounter.card);
+
+ return agent_write_status (ctrl, "EVENTCOUNTER",
+ any_counter,
+ key_counter,
+ card_counter,
+ NULL);
+}
+
+
+/* This function should be called once for all key removals or
+ additions. Thus function is assured not to do any context
+ switches. */
+void
+bump_key_eventcounter (void)
+{
+ eventcounter.key++;
+ eventcounter.any++;
+}
+
+/* This function should be called for all card reader status
+ changes. Thus function is assured not to do any context
+ switches. */
+void
+bump_card_eventcounter (void)
+{
+ eventcounter.card++;
+ eventcounter.any++;
+}
+
+
+
+
/* ISTRUSTED <hexstring_with_fingerprint>
Return OK when we have an entry with this fingerprint in our
@@ -1281,6 +1359,7 @@ register_commands (assuan_context_t ctx)
const char *name;
int (*handler)(assuan_context_t, char *line);
} table[] = {
+ { "GETEVENTCOUNTER",cmd_geteventcounter },
{ "ISTRUSTED", cmd_istrusted },
{ "HAVEKEY", cmd_havekey },
{ "SIGKEY", cmd_sigkey },