From aafbde956f88d0e618b661f86041679bf8c5850a Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 25 May 2022 16:18:51 +0900 Subject: struct assuan_context_s: Move boolean fields to flags. * src/assuan-defs.h (struct assuan_context_s): Move is_server, in_inquire, in_process_next, process_complete, in_command into flags. * src/assuan-buffer.c: Follow the change. * src/assuan-handler.c: Likewise. * src/assuan-inquire.c: Likewise. * src/assuan-pipe-server.c: Likewise. * src/assuan-socket-server.c: Likewise. -- Signed-off-by: NIIBE Yutaka --- src/assuan-buffer.c | 2 +- src/assuan-defs.h | 13 ++++++------- src/assuan-handler.c | 40 ++++++++++++++++++++-------------------- src/assuan-inquire.c | 20 ++++++++++---------- src/assuan-pipe-server.c | 2 +- src/assuan-socket-server.c | 2 +- 6 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c index f131a8d..7cb3032 100644 --- a/src/assuan-buffer.c +++ b/src/assuan-buffer.c @@ -503,7 +503,7 @@ assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length) wipememory (ctx->outbound.data.line, LINELENGTH); if (ctx->outbound.data.error) return ctx->outbound.data.error; - if (!ctx->is_server) + if (!ctx->flags.is_server) return assuan_write_line (ctx, length == 1? "CAN":"END"); } else diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 1d1617f..b9a0e8b 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -96,8 +96,13 @@ struct assuan_context_s unsigned int convey_comments : 1; unsigned int no_logging : 1; unsigned int force_close : 1; - /* From here, it's internal flag. */ + /* From here, we have internal flags, not defined by assuan_flag_t. */ unsigned int is_socket : 1; + unsigned int is_server : 1; /* Set if this is context belongs to a server */ + unsigned int in_inquire : 1; + unsigned int in_process_next : 1; + unsigned int process_complete : 1; + unsigned int in_command : 1; } flags; /* If set, this is called right before logging an I/O line. */ @@ -136,12 +141,6 @@ struct assuan_context_s gpg_error_t err_no; const char *err_str; - int is_server; /* Set if this is context belongs to a server */ - int in_inquire; - int in_process_next; - int process_complete; - int in_command; - /* The following members are used by assuan_inquire_ext. */ gpg_error_t (*inquire_cb) (void *cb_data, gpg_error_t rc, unsigned char *buf, size_t len); diff --git a/src/assuan-handler.c b/src/assuan-handler.c index 52dc9bc..a572b62 100644 --- a/src/assuan-handler.c +++ b/src/assuan-handler.c @@ -39,7 +39,7 @@ static int my_strcasecmp (const char *a, const char *b); #define PROCESS_DONE(ctx, rc) \ - ((ctx)->in_process_next ? assuan_process_done ((ctx), (rc)) : (rc)) + ((ctx)->flags.in_process_next ? assuan_process_done ((ctx), (rc)) : (rc)) static gpg_error_t dummy_handler (assuan_context_t ctx, char *line) @@ -147,7 +147,7 @@ std_handler_bye (assuan_context_t ctx, char *line) assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); /* pretty simple :-) */ - ctx->process_complete = 1; + ctx->flags.process_complete = 1; return PROCESS_DONE (ctx, 0); } @@ -683,13 +683,13 @@ dispatch_command (assuan_context_t ctx, char *line, int linelen) gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc) { - if (!ctx->in_command) + if (!ctx->flags.in_command) return _assuan_error (ctx, GPG_ERR_ASS_GENERAL); if (ctx->flags.force_close) - ctx->process_complete = 1; + ctx->flags.process_complete = 1; - ctx->in_command = 0; + ctx->flags.in_command = 0; /* Check for data write errors. */ if (ctx->outbound.data.fp) @@ -711,7 +711,7 @@ assuan_process_done (assuan_context_t ctx, gpg_error_t rc) /* Error handling. */ if (!rc) { - if (ctx->process_complete) + if (ctx->flags.process_complete) { /* No error checking because the peer may have already disconnect. */ @@ -769,7 +769,7 @@ process_next (assuan_context_t ctx) return 0; if (gpg_err_code (rc) == GPG_ERR_EOF) { - ctx->process_complete = 1; + ctx->flags.process_complete = 1; return 0; } if (rc) @@ -784,18 +784,18 @@ process_next (assuan_context_t ctx) in a command, it can only be the response to an INQUIRE reply. */ - if (!ctx->in_command) + if (!ctx->flags.in_command) { - ctx->in_command = 1; + ctx->flags.in_command = 1; ctx->outbound.data.error = 0; ctx->outbound.data.linelen = 0; /* Dispatch command and return reply. */ - ctx->in_process_next = 1; + ctx->flags.in_process_next = 1; rc = dispatch_command (ctx, ctx->inbound.line, ctx->inbound.linelen); - ctx->in_process_next = 0; + ctx->flags.in_process_next = 0; } - else if (ctx->in_inquire) + else if (ctx->flags.in_inquire) { /* FIXME: Pick up the continuation. */ rc = _assuan_inquire_ext_cb (ctx); @@ -827,15 +827,15 @@ assuan_process_next (assuan_context_t ctx, int *done) if (done) *done = 0; - ctx->process_complete = 0; + ctx->flags.process_complete = 0; do { rc = process_next (ctx); } - while (!rc && !ctx->process_complete && assuan_pending_line (ctx)); + while (!rc && !ctx->flags.process_complete && assuan_pending_line (ctx)); if (done) - *done = !!ctx->process_complete; + *done = !!ctx->flags.process_complete; return rc; } @@ -847,7 +847,7 @@ process_request (assuan_context_t ctx) { gpg_error_t rc; - if (ctx->in_inquire) + if (ctx->flags.in_inquire) return _assuan_error (ctx, GPG_ERR_ASS_NESTED_COMMANDS); do @@ -857,7 +857,7 @@ process_request (assuan_context_t ctx) while (_assuan_error_is_eagain (ctx, rc)); if (gpg_err_code (rc) == GPG_ERR_EOF) { - ctx->process_complete = 1; + ctx->flags.process_complete = 1; return 0; } if (rc) @@ -865,7 +865,7 @@ process_request (assuan_context_t ctx) if (*ctx->inbound.line == '#' || !ctx->inbound.linelen) return 0; /* comment line - ignore */ - ctx->in_command = 1; + ctx->flags.in_command = 1; ctx->outbound.data.error = 0; ctx->outbound.data.linelen = 0; /* dispatch command and return reply */ @@ -890,10 +890,10 @@ assuan_process (assuan_context_t ctx) { gpg_error_t rc; - ctx->process_complete = 0; + ctx->flags.process_complete = 0; do { rc = process_request (ctx); - } while (!rc && !ctx->process_complete); + } while (!rc && !ctx->flags.process_complete); return rc; } diff --git a/src/assuan-inquire.c b/src/assuan-inquire.c index 9599a77..064c8e9 100644 --- a/src/assuan-inquire.c +++ b/src/assuan-inquire.c @@ -163,12 +163,12 @@ assuan_inquire (assuan_context_t ctx, const char *keyword, nodataexpected = !r_buffer && !r_length && !maxlen; if (!nodataexpected && (!r_buffer || !r_length)) return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); - if (!ctx->is_server) + if (!ctx->flags.is_server) return _assuan_error (ctx, GPG_ERR_ASS_NOT_A_SERVER); - if (ctx->in_inquire) + if (ctx->flags.in_inquire) return _assuan_error (ctx, GPG_ERR_ASS_NESTED_COMMANDS); - ctx->in_inquire = 1; + ctx->flags.in_inquire = 1; if (nodataexpected) memset (&mb, 0, sizeof mb); /* avoid compiler warnings */ else @@ -261,7 +261,7 @@ assuan_inquire (assuan_context_t ctx, const char *keyword, } if (ctx->flags.confidential) wipememory (ctx->inbound.line, LINELENGTH); - ctx->in_inquire = 0; + ctx->flags.in_inquire = 0; return rc; } @@ -269,14 +269,14 @@ assuan_inquire (assuan_context_t ctx, const char *keyword, void _assuan_inquire_release (assuan_context_t ctx) { - if (ctx->in_inquire) + if (ctx->flags.in_inquire) { if (ctx->inquire_membuf) { free_membuf (ctx, ctx->inquire_membuf); free (ctx->inquire_membuf); } - ctx->in_inquire = 0; + ctx->flags.in_inquire = 0; } } @@ -360,7 +360,7 @@ _assuan_inquire_ext_cb (assuan_context_t ctx) free (mb); ctx->inquire_membuf = NULL; } - ctx->in_inquire = 0; + ctx->flags.in_inquire = 0; rc = (ctx->inquire_cb) (ctx->inquire_cb_data, rc, buf, buf_len); } return rc; @@ -391,9 +391,9 @@ assuan_inquire_ext (assuan_context_t ctx, const char *keyword, size_t maxlen, if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf))) return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); - if (!ctx->is_server) + if (!ctx->flags.is_server) return _assuan_error (ctx, GPG_ERR_ASS_NOT_A_SERVER); - if (ctx->in_inquire) + if (ctx->flags.in_inquire) return _assuan_error (ctx, GPG_ERR_ASS_NESTED_COMMANDS); mb = malloc (sizeof (struct membuf)); @@ -410,7 +410,7 @@ assuan_inquire_ext (assuan_context_t ctx, const char *keyword, size_t maxlen, return rc; } - ctx->in_inquire = 1; + ctx->flags.in_inquire = 1; /* Set up the continuation. */ ctx->inquire_cb = cb; diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c index c78abcd..db66978 100644 --- a/src/assuan-pipe-server.c +++ b/src/assuan-pipe-server.c @@ -110,7 +110,7 @@ assuan_init_pipe_server (assuan_context_t ctx, assuan_fd_t filedes[2]) } #endif - ctx->is_server = 1; + ctx->flags.is_server = 1; ctx->engine.release = _assuan_server_release; ctx->engine.readfnc = _assuan_simple_read; ctx->engine.writefnc = _assuan_simple_write; diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c index 8b20718..a8330a8 100644 --- a/src/assuan-socket-server.c +++ b/src/assuan-socket-server.c @@ -211,7 +211,7 @@ assuan_init_socket_server (assuan_context_t ctx, assuan_fd_t fd, ctx->engine.writefnc = _assuan_simple_write; ctx->engine.sendfd = NULL; ctx->engine.receivefd = NULL; - ctx->is_server = 1; + ctx->flags.is_server = 1; if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED) /* We want a second accept to indicate EOF. */ ctx->max_accepts = 1; -- cgit v1.2.1