diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/assuan-defs.h | 5 | ||||
-rw-r--r-- | src/assuan-handler.c | 15 | ||||
-rw-r--r-- | src/assuan.h.in | 10 | ||||
-rw-r--r-- | src/context.c | 12 |
5 files changed, 39 insertions, 11 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 261c605..ddbad5e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2011-08-10 Werner Koch <[email protected]> + + * assuan.h.in (ASSUAN_FORCE_CLOSE): New. + * assuan-defs.h (assuan_context_s): Add flags.FORCE_CLOSE. + * context.c (assuan_set_flag, assuan_get_flag): Set/get the flag. + * assuan-handler.c (assuan_process_done): Close connection if + requested. + 2011-04-06 Werner Koch <[email protected]> * libassuan-config.in: Add option --host. diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 8a3fcc2..f6cb9b4 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -40,7 +40,7 @@ #include "assuan.h" -#if __GNUC__ > 2 +#if __GNUC__ > 2 # define ASSUAN_GCC_A_PURE __attribute__ ((__pure__)) #else # define ASSUAN_GCC_A_PURE @@ -97,6 +97,7 @@ struct assuan_context_s unsigned int no_fixsignals : 1; unsigned int convey_comments : 1; unsigned int no_logging : 1; + unsigned int force_close : 1; } flags; /* If set, this is called right before logging an I/O line. */ @@ -199,7 +200,7 @@ struct assuan_context_s struct cmdtbl_s *cmdtbl; size_t cmdtbl_used; /* used entries */ size_t cmdtbl_size; /* allocated size of table */ - + /* The name of the command currently processed by a command handler. This is a pointer into CMDTBL. NULL if not in a command handler. */ diff --git a/src/assuan-handler.c b/src/assuan-handler.c index bd57ca0..28fcdfd 100644 --- a/src/assuan-handler.c +++ b/src/assuan-handler.c @@ -635,6 +635,9 @@ assuan_process_done (assuan_context_t ctx, gpg_error_t rc) if (!ctx->in_command) return _assuan_error (ctx, GPG_ERR_ASS_GENERAL); + if (ctx->flags.force_close) + ctx->process_complete = 1; + ctx->in_command = 0; /* Check for data write errors. */ @@ -673,12 +676,18 @@ assuan_process_done (assuan_context_t ctx, gpg_error_t rc) const char *text = ctx->err_no == rc ? ctx->err_str : NULL; char ebuf[50]; + if (ctx->flags.force_close) + text = "[closing connection]"; + gpg_strerror_r (rc, ebuf, sizeof (ebuf)); - sprintf (errline, "ERR %d %.50s <%.30s>%s%.100s", - rc, ebuf, gpg_strsource (rc), - text? " - ":"", text?text:""); + snprintf (errline, sizeof errline, "ERR %d %.50s <%.30s>%s%.100s", + rc, ebuf, gpg_strsource (rc), + text? " - ":"", text?text:""); rc = assuan_write_line (ctx, errline); + + if (ctx->flags.force_close) + ctx->finish_handler (ctx); } if (ctx->post_cmd_notify_fnc) diff --git a/src/assuan.h.in b/src/assuan.h.in index 9ff263f..7aae362 100644 --- a/src/assuan.h.in +++ b/src/assuan.h.in @@ -164,8 +164,10 @@ typedef unsigned int assuan_flag_t; /* This flag changes assuan_transact to return comment lines via the status callback. The default is to skip comment lines. */ #define ASSUAN_CONVEY_COMMENTS 4 -/* This flags disables logging for one context. */ +/* This flag disables logging for one context. */ #define ASSUAN_NO_LOGGING 5 +/* This flag forces a connection close. */ +#define ASSUAN_FORCE_CLOSE 6 /* For context CTX, set the flag FLAG to VALUE. Values for flags are usually 1 or 0 but certain flags might allow for other values; @@ -402,7 +404,7 @@ gpg_error_t assuan_client_parse_response (assuan_context_t ctx, int *off); /*-- assuan-client.c --*/ -gpg_error_t +gpg_error_t assuan_transact (assuan_context_t ctx, const char *command, gpg_error_t (*data_cb)(void *, const void *, size_t), @@ -453,10 +455,10 @@ gpg_error_t assuan_sock_init (void); void assuan_sock_deinit (void); int assuan_sock_close (assuan_fd_t fd); assuan_fd_t assuan_sock_new (int domain, int type, int proto); -int assuan_sock_connect (assuan_fd_t sockfd, +int assuan_sock_connect (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen); int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen); -int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, +int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, assuan_sock_nonce_t *nonce); int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce); diff --git a/src/context.c b/src/context.c index a56a4d2..b4d4d49 100644 --- a/src/context.c +++ b/src/context.c @@ -88,6 +88,10 @@ assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value) case ASSUAN_NO_LOGGING: ctx->flags.no_logging = value; break; + + case ASSUAN_FORCE_CLOSE: + ctx->flags.force_close = 1; + break; } } @@ -120,10 +124,14 @@ assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag) case ASSUAN_CONVEY_COMMENTS: res = ctx->flags.convey_comments; break; - + case ASSUAN_NO_LOGGING: res = ctx->flags.no_logging; break; + + case ASSUAN_FORCE_CLOSE: + res = ctx->flags.force_close; + break; } return TRACE_SUC1 ("flag_value=%i", res); @@ -183,7 +191,7 @@ assuan_set_error (assuan_context_t ctx, gpg_error_t err, const char *text) TRACE4 (ctx, ASSUAN_LOG_CTX, "assuan_set_error", ctx, "err=%i (%s,%s),text=%s", err, gpg_strsource (err), gpg_strerror (err), text); - + ctx->err_no = err; ctx->err_str = text; return err; |