From e06e6880f43ec8dc6d9b2ec8266f17d1751923ad Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 30 Nov 2006 17:51:40 +0000 Subject: [PATCH] More client library rewrites. --- lib/silcclient/client_entry.c | 7 +++---- lib/silcclient/command.c | 15 ++++++++++----- lib/silcclient/command_reply.c | 15 +++++++++++---- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/silcclient/client_entry.c b/lib/silcclient/client_entry.c index e8441a69..b7527433 100644 --- a/lib/silcclient/client_entry.c +++ b/lib/silcclient/client_entry.c @@ -78,11 +78,12 @@ SilcDList silc_client_get_clients_local(SilcClient client, if (!client || !conn || !nickname) return NULL; + SILC_LOG_DEBUG(("Find clients by nickname %s", nickname)); + /* Normalize nickname for search */ nicknamec = silc_identifier_check(nickname, strlen(nickname), SILC_STRING_UTF8, 128, NULL); if (!nicknamec) - silc_free(nicknamec); return NULL; clients = silc_dlist_init(); @@ -94,6 +95,7 @@ SilcDList silc_client_get_clients_local(SilcClient client, silc_mutex_lock(conn->internal->lock); /* Find from cache */ + silc_list_init(list, struct SilcIDCacheEntryStruct, next); if (!silc_idcache_find_by_name(conn->internal->client_cache, nicknamec, &list)) { silc_mutex_unlock(conn->internal->lock); @@ -1210,7 +1212,6 @@ silc_client_get_channel_by_id_resolve(SilcClient client, void *context) { SilcClientGetChannelInternal i; - SilcChannelEntry channel; SilcBuffer idp; SilcUInt16 cmd_ident; @@ -1240,8 +1241,6 @@ silc_client_get_channel_by_id_resolve(SilcClient client, if (!cmd_ident && completion) completion(client, conn, SILC_STATUS_ERR_RESOURCE_LIMIT, NULL, context); - silc_client_unref_channel(client, conn, channel); - return cmd_ident; } diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 42a119bf..4accee1a 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -1201,11 +1201,6 @@ SILC_FSM_STATE(silc_client_command_stats) SilcClientCommandContext cmd = fsm_context; SilcClientConnection conn = cmd->conn; - if (cmd->argc < 2) { - COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; - } - /* Send the command */ silc_client_command_send_va(conn, cmd, cmd->cmd, NULL, NULL, 1, 1, silc_buffer_datalen(conn->internal-> @@ -2561,7 +2556,16 @@ SILC_FSM_STATE(silc_client_command_getkey) /* Check whether user requested server */ server_entry = silc_client_get_server(client, conn, cmd->argv[1]); if (!server_entry) { + if (cmd->resolved) { + /* Resolving didn't find anything. We should never get here as + errors are handled in the resolving callback. */ + COMMAND_ERROR(SILC_STATUS_ERR_NO_SUCH_NICK); + COMMAND_ERROR(SILC_STATUS_ERR_NO_SUCH_SERVER); + return SILC_FSM_FINISH; + } + /* No client or server exist with this name, query for both. */ + cmd->resolved = TRUE; SILC_FSM_CALL(silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY, silc_client_command_continue, @@ -2570,6 +2574,7 @@ SILC_FSM_STATE(silc_client_command_getkey) strlen(cmd->argv[1]), 2, cmd->argv[1], strlen(cmd->argv[1]))); + /* NOT REACHED */ } idp = silc_id_payload_encode(&server_entry->id, SILC_ID_SERVER); } else { diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 55f8b4ab..a4d51b0d 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -46,7 +46,7 @@ do { \ msg "%s", silc_get_status_message(cmd->error)); \ ERROR_CALLBACK(cmd->error); \ silc_client_command_process_error(cmd, state_context, cmd->error); \ - silc_fsm_next(fsm, silc_client_command_reply_process); \ + silc_fsm_next(fsm, silc_client_command_reply_processed); \ return SILC_FSM_CONTINUE; \ } @@ -55,7 +55,7 @@ do { \ if (silc_argument_get_arg_num(args) < min || \ silc_argument_get_arg_num(args) > max) { \ ERROR_CALLBACK(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); \ - silc_fsm_next(fsm, silc_client_command_reply_process); \ + silc_fsm_next(fsm, silc_client_command_reply_processed); \ return SILC_FSM_CONTINUE; \ } @@ -157,7 +157,8 @@ SILC_FSM_STATE(silc_client_command_reply) silc_mutex_unlock(conn->internal->lock); if (!cmd) { - SILC_LOG_DEBUG(("Unknown command reply")); + SILC_LOG_DEBUG(("Unknown command reply %s, ident %d", + silc_get_command_name(command), cmd_ident)); silc_command_payload_free(payload); return SILC_FSM_FINISH; } @@ -582,6 +583,7 @@ SILC_FSM_STATE(silc_client_command_reply_identify) ERROR_CALLBACK(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } + silc_client_ref_server(client, conn, server_entry); } else { silc_client_update_server(client, conn, server_entry, name, info); } @@ -589,6 +591,7 @@ SILC_FSM_STATE(silc_client_command_reply_identify) /* Notify application */ silc_client_command_callback(cmd, server_entry, name, info); + silc_client_unref_server(client, conn, server_entry); break; case SILC_ID_CHANNEL: @@ -612,10 +615,12 @@ SILC_FSM_STATE(silc_client_command_reply_identify) ERROR_CALLBACK(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } + silc_client_ref_channel(client, conn, channel_entry); } /* Notify application */ silc_client_command_callback(cmd, channel_entry, name, info); + silc_client_unref_channel(client, conn, channel_entry); break; } @@ -715,7 +720,7 @@ SILC_FSM_STATE(silc_client_command_reply_list) SilcArgumentPayload args = silc_command_get_args(payload); unsigned char *tmp, *name, *topic; SilcUInt32 usercount = 0; - SilcChannelEntry channel_entry; + SilcChannelEntry channel_entry = NULL; SilcID id; /* Sanity checks */ @@ -752,12 +757,14 @@ SILC_FSM_STATE(silc_client_command_reply_list) ERROR_CALLBACK(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } + silc_client_ref_channel(client, conn, channel_entry); } /* Notify application */ silc_client_command_callback(cmd, channel_entry, name, topic, usercount); out: + silc_client_unref_channel(client, conn, channel_entry); silc_fsm_next(fsm, silc_client_command_reply_processed); return SILC_FSM_CONTINUE; } -- 2.24.0