silc_buffer_len(&packet->buffer), &id))
goto out;
+ SILC_LOG_DEBUG(("New ID %s", silc_id_render(&id.u.client_id,
+ SILC_ID_CLIENT)));
+
/* Create local client entry */
conn->local_entry = silc_client_add_client(client, conn,
client->username,
conn->internal->local_idp = silc_buffer_copy(&packet->buffer);
/* Save cache entry */
- silc_idcache_find_by_id_one(conn->internal->client_cache, conn->local_id,
- &conn->internal->local_entry);
+ if (!silc_idcache_find_by_id_one(conn->internal->client_cache,
+ conn->local_id,
+ &conn->internal->local_entry))
+ goto out;
/* Save remote ID */
if (packet->src_id_len) {
&conn->remote_id);
}
+ /* Set IDs to the packet stream */
+ silc_packet_set_ids(conn->stream, SILC_ID_CLIENT, conn->local_id,
+ conn->remote_id.type, SILC_ID_GET_ID(conn->remote_id));
+
/* Signal connection that new ID was received so it can continue
with the registering. */
if (conn->internal->registering)
silc_list_add(cmd->reply_callbacks, cb);
}
+ SILC_LOG_DEBUG(("pending: cmd %p, command %d, ident %d", cmd, cmd->cmd,
+ cmd->cmd_ident));
+
/* Add pending reply */
silc_list_add(conn->internal->pending_commands, cmd);
argv_lens = silc_realloc(argv_lens, sizeof(*argv_lens) * (argc + 1));
argv_types = silc_realloc(argv_types, sizeof(*argv_types) * (argc + 1));
if (!argv || !argv_lens || !argv_types)
- return FALSE;
+ return 0;
argv[argc] = silc_memdup(arg, strlen(arg));
if (!argv[argc])
- return FALSE;
+ return 0;
argv_lens[argc] = strlen(arg);
argv_types[argc] = argc;
argc++;
/* Given without arguments fetches client's own information */
if (cmd->argc < 2) {
- silc_client_command_send(conn->client, conn, SILC_COMMAND_WHOIS,
- NULL, NULL, 1, 4,
- silc_buffer_datalen(conn->internal->local_idp));
- goto out;
+ silc_client_command_send_va(conn, cmd, cmd->cmd, NULL, NULL, 1, 4,
+ silc_buffer_data(conn->internal->local_idp),
+ silc_buffer_len(conn->internal->local_idp));
+
+ /* Notify application */
+ COMMAND(SILC_STATUS_OK);
+
+ /** Wait for command reply */
+ silc_fsm_next(fsm, silc_client_command_reply_wait);
+ return SILC_FSM_CONTINUE;
}
for (i = 1; i < cmd->argc; i++) {
silc_status_get_args(cmd->status, args, &arg1, &arg2); \
else \
cmd->status = error; \
- silc_client_command_callback(cmd, arg1, arg2); \
+ SILC_LOG_DEBUG(("Error in command reply")); \
+ silc_client_command_callback(cmd, arg1, arg2); \
} while(0)
/* Check for error */
/* Default reply callback */
if (cmd->called) {
+ SILC_LOG_DEBUG(("cp %p, ap %p", cp, ap));
silc_va_copy(cp, ap);
+ SILC_LOG_DEBUG(("cp %p, ap %p", cp, ap));
cmd->conn->client->internal->ops->command_reply(
cmd->conn->client, cmd->conn, cmd->cmd, cmd->status,
cmd->error, cp);
silc_list_start(cmd->reply_callbacks);
while ((cb = silc_list_get(cmd->reply_callbacks)))
if (!cb->do_not_call) {
+ SILC_LOG_DEBUG(("cp %p, ap %p", cp, ap));
silc_va_copy(cp, ap);
+ SILC_LOG_DEBUG(("cp %p, ap %p", cp, ap));
cb->do_not_call = cb->reply(cmd->conn->client, cmd->conn, cmd->cmd,
cmd->status, cmd->error, cb->context, cp);
va_end(cp);
/* Find the command pending reply */
silc_mutex_lock(conn->internal->lock);
silc_list_start(conn->internal->pending_commands);
- while ((cmd = silc_list_get(conn->internal->pending_commands)))
+ while ((cmd = silc_list_get(conn->internal->pending_commands))) {
+ SILC_LOG_DEBUG(("cmd %p, command %d, ident %d", cmd, cmd->cmd,
+ cmd->cmd_ident));
if ((cmd->cmd == command || cmd->cmd == SILC_COMMAND_NONE)
- && cmd->cmd_ident == cmd_ident)
+ && cmd->cmd_ident == cmd_ident) {
+ silc_list_del(conn->internal->pending_commands, cmd);
break;
+ }
+ }
silc_mutex_unlock(conn->internal->lock);
if (!cmd) {
return SILC_FSM_FINISH;
}
+ SILC_LOG_DEBUG(("cmd %p, command %d", cmd, cmd->cmd));
+
/* Signal command thread that command reply has arrived */
silc_fsm_set_state_context(&cmd->thread, payload);
silc_fsm_next(&cmd->thread, silc_client_command_reply_process);
}
/* Update the client entry */
+ silc_mutex_lock(conn->internal->lock);
if (!silc_idcache_update(conn->internal->client_cache,
conn->internal->local_entry,
&conn->local_entry->id,
conn->local_entry->nickname_normalized,
tmp, TRUE)) {
silc_free(tmp);
+ silc_mutex_unlock(conn->internal->lock);
ERROR_CALLBACK(SILC_STATUS_ERR_BAD_NICKNAME);
goto out;
}
- memcpy(conn->local_entry->nickname, nick, strlen(nick));
+ silc_mutex_unlock(conn->internal->lock);
+ memset(conn->local_entry->nickname, 0, sizeof(conn->local_entry->nickname));
+ memcpy(conn->local_entry->nickname, nick, len);
conn->local_entry->nickname_normalized = tmp;
silc_buffer_enlarge(conn->internal->local_idp, idp_len);
silc_buffer_put(conn->internal->local_idp, idp, idp_len);
silc_client_nickname_format(client, conn, conn->local_entry);
+ silc_packet_set_ids(conn->stream, SILC_ID_CLIENT, conn->local_id, 0, NULL);
/* Notify application */
silc_client_command_callback(cmd, conn->local_entry,
SilcInt64 diff;
diff = silc_time() - SILC_PTR_TO_64(cmd->context);
- SAY(client, conn, SILC_CLIENT_MESSAGE_INFO,
- "Ping reply from %s: %d second%s", conn->remote_host,
- (int)diff, diff == 1 ? "" : "s");
+ if (cmd->verbose)
+ SAY(client, conn, SILC_CLIENT_MESSAGE_INFO,
+ "Ping reply from %s: %d second%s", conn->remote_host,
+ (int)diff, diff == 1 ? "" : "s");
/* Notify application */
silc_client_command_callback(cmd);
/* Mode */
SILC_GET32_MSB(mode, client_mode_list.data);
+ SILC_LOG_DEBUG(("id %s", silc_id_render(&id.u.client_id, SILC_ID_CLIENT)));
+
/* Get client entry */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
if (!client_entry)