Send channel entry in SIGNOFF notify to application.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 18 May 2007 15:09:20 +0000 (15:09 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 18 May 2007 15:09:20 +0000 (15:09 +0000)
Fixed silc_client_nickname_format to handle already formatted
nicknames better.

lib/silcclient/client_entry.c
lib/silcclient/client_notify.c

index fb6479a7c6b5eb525d39ff009de79ee4cdc444c9..c59a48fd3e4992008c26ed4a53cea0323688f2b5 100644 (file)
@@ -1099,9 +1099,9 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
   char *cp;
   char newnick[128 + 1];
   int i, off = 0, len;
-  SilcBool freebase;
   SilcDList clients;
   SilcClientEntry entry, unformatted = NULL;
+  SilcBool formatted = FALSE;
 
   if (!client->internal->params->nickname_format[0])
     return client_entry;
@@ -1118,32 +1118,70 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
                                              TRUE, FALSE);
   if (!clients)
     return NULL;
-  if (silc_dlist_count(clients) == 1 &&
+  if (silc_dlist_count(clients) == 1 && !priority &&
       !client->internal->params->nickname_force_format) {
     silc_client_list_free(client, conn, clients);
     return client_entry;
   }
 
-  len = 0;
-  freebase = TRUE;
+  /* Is the requested client formatted already */
+  if (!silc_utf8_strcasecmp(client_entry->nickname, 
+                           client_entry->nickname_normalized))
+    formatted = TRUE;
+
+  if (client->internal->params->nickname_force_format)
+    formatted = FALSE;
+
+  /* Find unformatted client entry */
   while ((entry = silc_dlist_get(clients))) {
-    if (entry->internal.valid && entry != client_entry)
-      len++;
-    if (entry->internal.valid && entry != client_entry &&
-       silc_utf8_strcasecmp(entry->nickname, client_entry->nickname)) {
-      freebase = FALSE;
+    if (!entry->internal.valid)
+      continue;
+    if (entry == client_entry)
+      continue;
+    if (silc_utf8_strcasecmp(entry->nickname, entry->nickname_normalized)) {
       unformatted = entry;
       break;
     }
-  }
-  if (!len || freebase) {
+  }  
+
+  /* If there are no other unformatted clients and the requested client is
+     unformatted, just return it. */
+  if (!unformatted && !formatted) {
     silc_client_list_free(client, conn, clients);
     return client_entry;
   }
 
-  /* If priority formatting, this client always gets unformatted nickname. */
-  if (unformatted && priority)
+  /* If priority formatting then the requested client will get the 
+     unformatted nickname, and the unformatted client will get a new
+     formatted nickname. */
+  if (priority) {
+    if (formatted) {
+      /* Simply change the client's nickname to unformatted */
+      if (!silc_client_nickname_parse(client, conn, client_entry->nickname,
+                                     &cp))
+        return NULL;
+
+      silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname), 
+                   cp);
+      silc_free(cp);
+    }
+
+    if (!unformatted) {
+      /* There was no other unformatted client */
+      silc_client_list_free(client, conn, clients);
+      return client_entry;
+    }
+
+    /* Now format the previously unformatted client */
     client_entry = unformatted;
+    formatted = FALSE;
+  }
+
+  /* If already formatted just return it */
+  if (formatted) {
+    silc_client_list_free(client, conn, clients);
+    return client_entry;
+  }
 
   memset(newnick, 0, sizeof(newnick));
   cp = client->internal->params->nickname_format;
index 10c36a324f8fa5bae0fd151cbc1dc5789f061133..005299c61f1a0610c9a3186c8c939f471ed5aca1 100644 (file)
@@ -503,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;
@@ -524,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 */