From 3830181358ac025958983272ec6bcb0ca8ded5b5 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 5 Oct 2000 07:26:43 +0000 Subject: [PATCH] Minor ops API change and bugfixes. --- lib/silcclient/client.c | 2 +- lib/silcclient/command_reply.c | 5 +++-- lib/silcclient/ops.h | 11 +++++----- lib/silcclient/protocol.c | 39 +++++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 39147b26..0bb10c78 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -126,7 +126,7 @@ void silc_client_run(SilcClient client) SilcClientConnection silc_client_add_connection(SilcClient client, char *hostname, int port, - void *context); + void *context) { SilcClientConnection conn; int i; diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 60438937..b9c897a0 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -108,11 +108,12 @@ const SilcCommandStatusMessage silc_command_status_messages[] = { Usage: COMMAND_REPLY((ARGS, argument1, argument2, etc...)), */ #define COMMAND_REPLY(args) cmd->client->ops->command_reply args #define ARGS cmd->client, cmd->sock->user_data, \ - cmd->payload, TRUE, silc_command_get(cmd->payload) + cmd->payload, TRUE, status, silc_command_get(cmd->payload) /* Error reply to application. Usage: COMMAND_REPLY_ERROR; */ #define COMMAND_REPLY_ERROR cmd->client->ops->command_reply(cmd->client, \ - cmd->sock->user_data, cmd->payload, FALSE, silc_command_get(cmd->payload)) + cmd->sock->user_data, cmd->payload, FALSE, status, \ + silc_command_get(cmd->payload)) /* Process received command reply. */ diff --git a/lib/silcclient/ops.h b/lib/silcclient/ops.h index 69eb54e5..69da2416 100644 --- a/lib/silcclient/ops.h +++ b/lib/silcclient/ops.h @@ -44,7 +44,7 @@ typedef struct { SilcCommand command); void (*command_reply)(SilcClient client, SilcClientConnection conn, SilcCommandPayload cmd_payload, int success, - SilcCommand command, ...); + SilcCommandStatus status, SilcCommand command, ...); void (*connect)(SilcClient client, SilcClientConnection conn, int success); void (*disconnect)(SilcClient client, SilcClientConnection conn); int (*get_auth_method)(SilcClient client, SilcClientConnection conn, @@ -105,7 +105,7 @@ typedef struct { void (*command_reply)(SilcClient client, SilcClientConnection conn, SilcCommandPayload cmd_payload, int success, - SilcCommand command, ...); + SilcCommandStatus status, SilcCommand command, ...); Command reply handler. This function is called always in the command reply function. If error occurs it will be called as well. Normal scenario @@ -118,9 +118,10 @@ typedef struct { if the application would like to re-parse the received command data, however, it must be noted that the data is parsed already by the library thus the payload can be ignored. `success' is FALSE if error occured. - In this case arguments are not sent to the application. `command' is the - command reply being processed. The function has variable argument list - and each command defines the number and type of arguments it passes to the + In this case arguments are not sent to the application. The `status' is + the command reply status server returned. The `command' is the command + reply being processed. The function has variable argument list and each + command defines the number and type of arguments it passes to the application (on error they are not sent). diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index d0b8064c..43fb6282 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -129,7 +129,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) (SilcClientKEInternalContext *)protocol->context; SilcClient client = (SilcClient)ctx->client; SilcClientConnection conn = ctx->sock->user_data; - SilcSKEStatus status; + SilcSKEStatus status = 0; SILC_LOG_DEBUG(("Start")); @@ -176,11 +176,14 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) } if (status != SILC_SKE_STATUS_OK) { - switch(status) { - - default: - break; - } + SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol", + status)); + SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol", + status)); + + protocol->state = SILC_PROTOCOL_STATE_ERROR; + protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + return; } /* Advance the state of the protocol. */ @@ -208,9 +211,15 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) status = silc_ske_initiator_phase_1(ctx->ske, ctx->packet, NULL, NULL); } - switch(status) { - default: - break; + if (status != SILC_SKE_STATUS_OK) { + SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol", + status)); + SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol", + status)); + + protocol->state = SILC_PROTOCOL_STATE_ERROR; + protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + return; } /* Advance the state of the protocol and call the next state. */ @@ -242,9 +251,15 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) context); } - switch(status) { - default: - break; + if (status != SILC_SKE_STATUS_OK) { + SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol", + status)); + SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol", + status)); + + protocol->state = SILC_PROTOCOL_STATE_ERROR; + protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + return; } /* Advance the state of the protocol. */ -- 2.43.0