/* Notify processing context */
typedef struct {
- SilcPacket packet;
- SilcNotifyPayload payload;
- SilcFSMThread fsm;
- SilcChannelEntry channel;
+ SilcPacket packet; /* Notify packet */
+ SilcNotifyPayload payload; /* Parsed notify payload */
+ SilcFSMThread fsm; /* Notify FSM thread */
+ SilcChannelEntry channel; /* Channel entry being resolved */
+ SilcClientEntry client_entry; /* Client entry being resolved */
} *SilcClientNotify;
/************************ Static utility functions **************************/
-/* Entry resolving callback. This will continue processing the notify. */
+/* The client entires in notify processing are resolved if they do not exist,
+ or they are not valid. We go to this callback after resolving where we
+ check if the client entry has become valid. If resolving succeeded the
+ entry is valid but remains invalid if resolving failed. This callback
+ will continue processing the notify. We use this callback also with other
+ entry resolving. */
static void silc_client_notify_resolved(SilcClient client,
SilcClientConnection conn,
{
SilcClientNotify notify = context;
- /* If no entries found, just finish the notify processing, a silent error */
- if (!entries)
+ /* If entry is still invalid, resolving failed. Finish notify processing. */
+ if (notify->client_entry && !notify->client_entry->internal.valid) {
+ silc_fsm_next(notify->fsm, silc_client_notify_processed);
+ silc_client_unref_client(client, conn, notify->client_entry);
+ }
+
+ /* If no entries found, just finish the notify processing */
+ if (!entries && !notify->client_entry)
silc_fsm_next(notify->fsm, silc_client_notify_processed);
if (notify->channel) {
break;
}
- return SILC_FSM_YIELD;
+ return SILC_FSM_CONTINUE;
}
/* Notify processed, finish the packet processing thread */
/* Find Client entry and if not found query it */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
+ if (!client_entry || !client_entry->internal.valid) {
/** Resolve client */
silc_client_unref_client(client, conn, client_entry);
notify->channel = channel;
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
- /* Find Client entry and if not found query it */
- client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0] ||
+ /* Find client entry and if not found query it. If we just queried it
+ don't do it again, unless some data (like username) is missing. */
+ client_entry = notify->client_entry;
+ if (!client_entry)
+ client_entry = silc_client_get_client(client, conn, &id.u.client_id);
+ if (!client_entry || !client_entry->internal.valid ||
!client_entry->username[0]) {
/** Resolve client */
- silc_client_unref_client(client, conn, client_entry);
notify->channel = channel;
+ notify->client_entry = client_entry;
SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
silc_client_get_client_by_id_resolve(
- client, conn, &id.u.client_id, NULL,
- silc_client_notify_resolved,
+ client, conn, client_entry ?
+ &client_entry->id : &id.u.client_id,
+ NULL, silc_client_notify_resolved,
notify));
/* NOT REACHED */
}
goto out;
/* Remove client from channel */
- silc_client_remove_from_channel(client, conn, channel, client_entry);
+ if (!silc_client_remove_from_channel(client, conn, channel, client_entry))
+ goto out;
/* Notify application. */
NOTIFY(client, conn, type, client_entry, channel);
tmp[128] = '\0';
/* Notify application */
- NOTIFY(client, conn, type, client_entry, tmp);
+ if (client_entry->internal.valid)
+ NOTIFY(client, conn, type, client_entry, tmp);
/* Remove from channel */
if (packet->dst_id_type == SILC_ID_CHANNEL) {
}
/* Delete client */
+ client_entry->internal.valid = FALSE;
silc_client_del_client(client, conn, client_entry);
silc_client_unref_client(client, conn, client_entry);
/* NOT REACHED */
}
- /* Get ID */
+ /* Get ID of topic changer */
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
if (id.type == SILC_ID_CLIENT) {
/* Find Client entry */
- client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
- /** Resolve client */
- silc_client_unref_client(client, conn, client_entry);
- notify->channel = channel;
- SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
- silc_client_get_client_by_id_resolve(
+ client_entry = notify->client_entry;
+ if (!client_entry) {
+ client_entry = silc_client_get_client(client, conn, &id.u.client_id);
+ if (!client_entry || !client_entry->internal.valid) {
+ /** Resolve client */
+ notify->channel = channel;
+ notify->client_entry = client_entry;
+ SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
+ silc_client_get_client_by_id_resolve(
client, conn, &id.u.client_id, NULL,
silc_client_notify_resolved,
notify));
- /* NOT REACHED */
+ /* NOT REACHED */
+ }
}
+
+ /* If client is not on channel, ignore this notify */
+ if (!silc_client_on_channel(channel, client_entry))
+ goto out;
+
entry = client_entry;
} else if (id.type == SILC_ID_SERVER) {
/* Find Server entry */
unsigned char *tmp, oldnick[128 + 1];
SilcUInt32 tmp_len;
SilcID id, id2;
+ SilcBool valid;
SILC_LOG_DEBUG(("Notify: NICK_CHANGE"));
SILC_ID_CLIENT_COMPARE(&id2.u.client_id, conn->local_id))
goto out;
- /* Find old Client entry */
+ /* Find old client entry. If we don't have the entry, we ignore this
+ notify. */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
- /** Resolve client */
- silc_client_unref_client(client, conn, client_entry);
- SILC_FSM_CALL(silc_client_get_client_by_id_resolve(
- client, conn, &id.u.client_id, NULL,
- silc_client_notify_resolved,
- notify));
- /* NOT REACHED */
- }
+ if (!client_entry)
+ goto out;
+ valid = client_entry->internal.valid;
/* Take the new nickname */
tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
silc_rwlock_unlock(client_entry->internal.lock);
- /* Notify application */
- NOTIFY(client, conn, type, client_entry, client_entry->nickname, oldnick);
+ /* Notify application, if client entry is valid. We do not send nick change
+ notify for entries that were invalid (application doesn't know them). */
+ if (valid)
+ NOTIFY(client, conn, type, client_entry, oldnick, client_entry->nickname);
out:
/** Notify processed */
goto out;
SILC_GET32_MSB(mode, tmp);
- /* Get ID */
+ /* Get ID of who changed the mode */
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
if (id.type == SILC_ID_CLIENT) {
/* Find Client entry */
- client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
- /** Resolve client */
- silc_client_unref_client(client, conn, client_entry);
- notify->channel = channel;
- SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
- silc_client_get_client_by_id_resolve(
+ client_entry = notify->client_entry;
+ if (!client_entry) {
+ client_entry = silc_client_get_client(client, conn, &id.u.client_id);
+ if (!client_entry || !client_entry->internal.valid) {
+ /** Resolve client */
+ notify->channel = channel;
+ notify->client_entry = client_entry;
+ SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
+ silc_client_get_client_by_id_resolve(
client, conn, &id.u.client_id, NULL,
silc_client_notify_resolved,
notify));
- /* NOT REACHED */
+ /* NOT REACHED */
+ }
}
+
+ /* If client is not on channel, ignore this notify */
+ if (!silc_client_on_channel(channel, client_entry))
+ goto out;
+
entry = client_entry;
} else if (id.type == SILC_ID_SERVER) {
/* Find Server entry */
/* Find target Client entry */
client_entry2 = silc_client_get_client_by_id(client, conn, &id2.u.client_id);
- if (!client_entry2 || !client_entry2->nickname[0]) {
+ if (!client_entry2 || !client_entry2->internal.valid) {
/** Resolve client */
silc_client_unref_client(client, conn, client_entry2);
SILC_FSM_CALL(silc_client_get_client_by_id_resolve(
/* NOT REACHED */
}
+ /* If target client is not on channel, ignore this notify */
+ if (!silc_client_on_channel(channel, client_entry2))
+ goto out;
+
/* Get the mode */
tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
if (!tmp)
goto out;
SILC_GET32_MSB(mode, tmp);
- /* Get ID */
+ /* Get ID of mode changer */
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
if (id.type == SILC_ID_CLIENT) {
/* Find Client entry */
- client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
- /** Resolve client */
- silc_client_unref_client(client, conn, client_entry);
- notify->channel = channel;
- SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
- silc_client_get_client_by_id_resolve(
+ client_entry = notify->client_entry;
+ if (!client_entry) {
+ client_entry = silc_client_get_client(client, conn, &id.u.client_id);
+ if (!client_entry || !client_entry->internal.valid) {
+ /** Resolve client */
+ notify->channel = channel;
+ notify->client_entry = client_entry;
+ SILC_FSM_CALL(channel->internal.resolve_cmd_ident =
+ silc_client_get_client_by_id_resolve(
client, conn, &id.u.client_id, NULL,
silc_client_notify_resolved,
notify));
- /* NOT REACHED */
+ /* NOT REACHED */
+ }
}
+
+ /* If client is not on channel, ignore this notify */
+ if (!silc_client_on_channel(channel, client_entry))
+ goto out;
+
entry = client_entry;
} else if (id.type == SILC_ID_SERVER) {
/* Find Server entry */
/* NOT REACHED */
}
- /* Get Client ID */
+ /* Get the kicked Client ID */
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
- /* Find Client entry */
+ /* Find client entry */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
if (!client_entry)
goto out;
/* Find kicker's client entry and if not found resolve it */
client_entry2 = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry2 || !client_entry2->nickname[0]) {
+ if (!client_entry2 || !client_entry2->internal.valid) {
/** Resolve client */
silc_client_unref_client(client, conn, client_entry);
silc_client_unref_client(client, conn, client_entry2);
tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
/* Remove kicked client from channel */
- if (client_entry != conn->local_entry)
- silc_client_remove_from_channel(client, conn, channel, client_entry);
+ if (client_entry != conn->local_entry) {
+ if (!silc_client_remove_from_channel(client, conn, channel, client_entry))
+ goto out;
+ }
/* Notify application. */
NOTIFY(client, conn, type, client_entry, tmp, client_entry2, channel);
/* Find Client entry */
client_entry2 = silc_client_get_client_by_id(client, conn,
&id.u.client_id);
- if (!client_entry2 || !client_entry2->nickname[0]) {
+ if (!client_entry2 || !client_entry2->internal.valid) {
/** Resolve client */
silc_client_unref_client(client, conn, client_entry);
silc_client_unref_client(client, conn, client_entry2);
/* Delete the killed client */
if (client_entry != conn->local_entry) {
silc_client_remove_from_channels(client, conn, client_entry);
+ client_entry->internal.valid = FALSE;
silc_client_del_client(client, conn, client_entry);
}
/* Get the client entry */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (client_entry)
+ if (client_entry && client_entry->internal.valid)
silc_dlist_add(clients, client_entry);
}
silc_dlist_start(clients);
while ((client_entry = silc_dlist_get(clients))) {
silc_client_remove_from_channels(client, conn, client_entry);
+ client_entry->internal.valid = FALSE;
silc_client_del_client(client, conn, client_entry);
}
if (!silc_argument_get_decoded(args, 1, SILC_ARGUMENT_ID, &id, NULL))
goto out;
- /* Find Client entry and if not found resolve it */
+ /* Find client entry and if not found resolve it */
client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
- if (!client_entry || !client_entry->nickname[0]) {
+ if (!client_entry || !client_entry->internal.valid) {
/** Resolve client */
silc_client_unref_client(client, conn, client_entry);
SILC_FSM_CALL(silc_client_get_client_by_id_resolve(