diff options
author | Moritz Schulte <[email protected]> | 2007-08-16 12:44:17 +0000 |
---|---|---|
committer | Moritz Schulte <[email protected]> | 2007-08-16 12:44:17 +0000 |
commit | 62039d815eef5a699cb7d78a36a0a5e9eb5910c8 (patch) | |
tree | 925563c8c20b48aabd3825d26bc387d9e4631c84 /scd/command.c | |
parent | Creating new branch for moritz' hacks (diff) | |
download | gnupg-GNUPG-TRUNK-MO-HACKS.tar.gz gnupg-GNUPG-TRUNK-MO-HACKS.zip |
Implemented the STATUSFD mechanism.GNUPG-TRUNK-MO-HACKS
2007-08-16 Moritz Schulte <[email protected]>
* command.c: Include "statusfd.h".
(cmd_statusfd): New function.
(register_commands): New entry for STATUSFD command.
(update_reader_status_file): Call statusfd_event_card_inserted and
statusfd_event_card_removed on events.
(scd_command_handler): Pass flags=3 to
assuan_init_socket_server_ext (enabling fd passing).
* statusfd.c, statusfd.h: New files.
* Makefile.am (scdaemon_SOURCES): Added statusfd.c, statusfd.h.
* NOTES-STATUSFD: New file.
Diffstat (limited to '')
-rw-r--r-- | scd/command.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/scd/command.c b/scd/command.c index e65262d06..2ac0abe71 100644 --- a/scd/command.c +++ b/scd/command.c @@ -40,6 +40,7 @@ #ifdef HAVE_LIBUSB #include "ccid-driver.h" #endif +#include "statusfd.h" /* Maximum length allowed as a PIN; used for INQUIRE NEEDPIN */ #define MAXLEN_PIN 100 @@ -1649,6 +1650,34 @@ cmd_apdu (assuan_context_t ctx, char *line) return rc; } +/* STATUSFD + */ +static int +cmd_statusfd (assuan_context_t ctx, char *line) +{ + ctrl_t ctrl = assuan_get_pointer (ctx); + int rc; + int fd; + + /* FIXME, moritz, locking? */ + if ( IS_LOCKED (ctrl) ) + return gpg_error (GPG_ERR_LOCKED); + + rc = assuan_receivefd (ctx, &fd); + if (rc) + /* FIXME, moritz, proper error message for client? */ + goto leave; + + rc = statusfd_register (fd); + + leave: + + if (rc) + close (fd); + + return rc; +} + @@ -1683,6 +1712,7 @@ register_commands (assuan_context_t ctx) { "GETINFO", cmd_getinfo }, { "RESTART", cmd_restart }, { "APDU", cmd_apdu }, + { "STATUSFD", cmd_statusfd }, { NULL } }; int i, rc; @@ -1719,7 +1749,7 @@ scd_command_handler (ctrl_t ctrl, int fd) } else { - rc = assuan_init_socket_server_ext (&ctx, fd, 2); + rc = assuan_init_socket_server_ext (&ctx, fd, 3); } if (rc) { @@ -1880,6 +1910,15 @@ update_reader_status_file (void) log_info ("updating status of slot %d to 0x%04X\n", ss->slot, status); + { + /* Broadcast on statusfds. */ + + if ((! (ss->status & 2)) && (status & 2)) + statusfd_event_card_inserted (0); + if ((ss->status & 2) && (! (status & 2))) + statusfd_event_card_removed (0); + } + /* FIXME: Should this be IDX instead of ss->slot? This depends on how client sessions will associate the reader status with their session. */ |