Send channel entry in SIGNOFF notify to application.
[silc.git] / lib / silcclient / client_notify.c
index be982311a734406dc690bba0b1e302cfbe3fccf7..005299c61f1a0610c9a3186c8c939f471ed5aca1 100644 (file)
@@ -33,6 +33,7 @@ typedef struct {
   SilcFSMThread fsm;                 /* Notify FSM thread */
   SilcChannelEntry channel;          /* Channel entry being resolved */
   SilcClientEntry client_entry;              /* Client entry being resolved */
+  SilcUInt32 resolve_retry;          /* Resolving retry counter */
 } *SilcClientNotify;
 
 /************************ Static utility functions **************************/
@@ -54,7 +55,9 @@ static void silc_client_notify_resolved(SilcClient client,
 
   /* 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);
+    /* If resolving timedout try it again many times. */
+    if (status != SILC_STATUS_ERR_TIMEDOUT || ++notify->resolve_retry > 1000)
+      silc_fsm_next(notify->fsm, silc_client_notify_processed);
     silc_client_unref_client(client, conn, notify->client_entry);
   }
 
@@ -500,7 +503,7 @@ SILC_FSM_STATE(silc_client_notify_signoff)
   SilcNotifyType type = silc_notify_get_type(payload);
   SilcArgumentPayload args = silc_notify_get_args(payload);
   SilcClientEntry client_entry;
-  SilcChannelEntry channel;
+  SilcChannelEntry channel = NULL;
   unsigned char *tmp;
   SilcUInt32 tmp_len;
   SilcID id;
@@ -521,20 +524,19 @@ SILC_FSM_STATE(silc_client_notify_signoff)
   if (tmp && tmp_len > 128)
     tmp[128] = '\0';
 
+  if (packet->dst_id_type == SILC_ID_CHANNEL) 
+    if (silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CHANNEL,
+                      &id.u.channel_id, sizeof(id.u.channel_id)))
+      channel = silc_client_get_channel_by_id(client, conn, &id.u.channel_id);
+
   /* Notify application */
   if (client_entry->internal.valid)
-    NOTIFY(client, conn, type, client_entry, tmp);
+    NOTIFY(client, conn, type, client_entry, tmp, channel);
 
   /* Remove from channel */
-  if (packet->dst_id_type == SILC_ID_CHANNEL) {
-    if (silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CHANNEL,
-                      &id.u.channel_id, sizeof(id.u.channel_id))) {
-      channel = silc_client_get_channel_by_id(client, conn, &id.u.channel_id);
-      if (channel) {
-       silc_client_remove_from_channel(client, conn, channel, client_entry);
-       silc_client_unref_channel(client, conn, channel);
-      }
-    }
+  if (channel) {
+    silc_client_remove_from_channel(client, conn, channel, client_entry);
+    silc_client_unref_channel(client, conn, channel);
   }
 
   /* Delete client */
@@ -925,13 +927,15 @@ SILC_FSM_STATE(silc_client_notify_cmode_change)
   if (!(channel->mode & SILC_CHANNEL_MODE_ULIMIT))
     channel->user_limit = 0;
 
-  /* Save the new mode */
-  channel->mode = mode;
-
   /* Get the channel public key that was added or removed */
   tmp = silc_argument_get_arg_type(args, 7, &tmp_len);
   if (tmp)
-    silc_client_channel_save_public_keys(channel, tmp, tmp_len);
+    silc_client_channel_save_public_keys(channel, tmp, tmp_len, FALSE);
+  else if (channel->mode & SILC_CHANNEL_MODE_CHANNEL_AUTH)
+    silc_client_channel_save_public_keys(channel, NULL, 0, TRUE);
+
+  /* Save the new mode */
+  channel->mode = mode;
 
   silc_rwlock_unlock(channel->internal.lock);
 
@@ -1489,7 +1493,7 @@ SILC_FSM_STATE(silc_client_notify_error)
     if (!silc_argument_get_decoded(args, 2, SILC_ARGUMENT_ID, &id, NULL))
       goto out;
     client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
-    if (client_entry) {
+    if (client_entry && client_entry != conn->local_entry) {
       silc_client_remove_from_channels(client, conn, client_entry);
       silc_client_del_client(client, conn, client_entry);
       silc_client_unref_client(client, conn, client_entry);