/* Allocate command reply context. This must be free'd by the
command reply routine receiving it. */
ctx = silc_calloc(1, sizeof(*ctx));
+ ctx->users++;
ctx->client = client;
ctx->sock = sock;
ctx->payload = payload;
}
}
+/* Duplicate Command Reply Context by adding reference counter. The context
+ won't be free'd untill it hits zero. */
+
+SilcClientCommandReplyContext
+silc_client_command_reply_dup(SilcClientCommandReplyContext cmd)
+{
+ cmd->users++;
+ SILC_LOG_DEBUG(("Command reply context %p refcnt %d->%d", cmd,
+ cmd->users - 1, cmd->users));
+ return cmd;
+}
+
/* Free command reply context and its internals. */
void silc_client_command_reply_free(SilcClientCommandReplyContext cmd)
{
- if (cmd) {
+ cmd->users--;
+ SILC_LOG_DEBUG(("Command reply context %p refcnt %d->%d", cmd,
+ cmd->users + 1, cmd->users));
+ if (cmd->users < 1) {
silc_command_payload_free(cmd->payload);
silc_free(cmd);
}
client_entry->fingerprint_len = fingerprint_len;
}
- if (client_entry->status & SILC_CLIENT_STATUS_RESOLVING)
- client_entry->status &= ~SILC_CLIENT_STATUS_RESOLVING;
+ client_entry->status &= ~SILC_CLIENT_STATUS_RESOLVING;
/* Notify application */
if (!cmd->callbacks_count && notify)
name, info, NULL, 0);
}
- if (client_entry->status & SILC_CLIENT_STATUS_RESOLVING)
- client_entry->status &= ~SILC_CLIENT_STATUS_RESOLVING;
+ client_entry->status &= ~SILC_CLIENT_STATUS_RESOLVING;
/* Notify application */
if (notify)
COMMAND_REPLY_ERROR;
return;
}
+ } else {
+ silc_client_update_server(client, conn, server_entry, name, info);
}
+ server_entry->resolve_cmd_ident = 0;
+
/* Notify application */
if (notify)
COMMAND_REPLY((ARGS, server_entry, name, info));
silc_client_command_reply_free(cmd);
}
+/* Received reply to STATS command. */
+
+SILC_CLIENT_CMD_REPLY_FUNC(stats)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ unsigned char *tmp, *buf = NULL;
+ SilcUInt32 len, buf_len = 0;
+
+ if (cmd->error != SILC_STATUS_OK) {
+ SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_get_status_message(cmd->error));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Get server ID */
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp)
+ goto out;
+
+ /* Get statistics structure */
+ buf = silc_argument_get_arg_type(cmd->args, 3, &buf_len);
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, buf, buf_len));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_STATS);
+ silc_client_command_reply_free(cmd);
+}
+
/* Received reply to PING command. The reply time is shown to user. */
SILC_CLIENT_CMD_REPLY_FUNC(ping)
}
argc = silc_argument_get_arg_num(cmd->args);
- if (argc < 7 || argc > 14) {
+ if (argc < 7) {
SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
"Cannot join channel: Bad reply packet");
COMMAND_REPLY_ERROR;
/* Check if we have this client cached already. */
client_entry = silc_client_get_client_by_id(cmd->client, conn, client_id);
if (!client_entry || !client_entry->username || !client_entry->realname) {
- if (client_entry) {
- if (client_entry->status & SILC_CLIENT_STATUS_RESOLVING) {
- /* Attach to this resolving and wait until it finishes */
- silc_client_command_pending(conn, SILC_COMMAND_NONE,
- client_entry->resolve_cmd_ident,
- get_clients, cmd);
- wait_res = TRUE;
-
- silc_buffer_pull(&client_id_list, idp_len);
- silc_buffer_pull(&client_mode_list, 4);
- continue;
- }
- client_entry->status |= SILC_CLIENT_STATUS_RESOLVING;
- client_entry->resolve_cmd_ident = conn->cmd_ident + 1;
- }
-
/* No we don't have it (or it is incomplete in information), query
it from the server. Assemble argument table that will be sent
for the WHOIS command later. */