Added SILC Client setting /set nickname_format that specifies
authorPekka Riikonen <priikone@silcnet.org>
Sun, 18 Mar 2007 15:49:14 +0000 (15:49 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 18 Mar 2007 15:49:14 +0000 (15:49 +0000)
the nickname format string.  Changed default nickname format
string to "%n#%a".  Fixed /MSG, /KEY and /FILE to parse and resolve
nickname correctly.

CHANGES
apps/irssi/silc.conf
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/silc-channels.c
apps/irssi/src/silc/core/silc-core.c
apps/irssi/src/silc/core/silc-servers.c

diff --git a/CHANGES b/CHANGES
index 79aaa5c35858169ea53e754ec29b6953de488bf1..3f0f4aa9240d5b5e082b5de8d7cfccf4a4ac1239 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,22 @@
+Sun Mar 18 15:54:10 EET 2007  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added SILC Client setting /set nickname_format that specifies
+         the nickname format string.  Changed default nickname format
+         string to "%n#%a".  Affected file is 
+          apps/irssi/src/silc/core/silc-core.c, apps/irssi/silc.conf.
+
+       * Fixed nickname parsing with WHOIS command to accept formatted
+         nicknames.  Changed the silc_client_get_clients_local to allow
+         the searched nickname to be formatted nickname.  Removed %s and
+         %S nickname formatters.  Affected files are in lib/silcclient/.
+
+       * Added silc_client_nickname_parse to Client library API.  Affected
+         file is lib/silcclient/silcclient.h.
+
+       * Fixed nickname parsing and resolving with /MSG, /FILE and /KEY
+          commands.  Affected file are
+          apps/irssi/src/silc/core/silc-servers.c and silc-channels.c.
+
 Sat Mar 17 19:07:15 CET 2007  Jochen Eisinger <coffee@silcnet.org>
 
        * Incorporate SILC Plugin patches.  Affected files are
index ed2655a08874d160dc36ec609e4618303bae6d13..76f8bc536ccdd896279c1c3a8ad7852e71b3e78b 100644 (file)
@@ -211,6 +211,21 @@ statusbar = {
 #
 # hmac-sha1-96, hmac-md5-96, hmac-sha1 and hmac-md5
 #
+#
+# You can set the default nickname formatting string.  If there are multiple
+# same nicknames on a SILC channel, this format string defines how they
+# appear on the channel.  Default nickname_format is "%n#%a".
+#
+# /set nickname_format
+#
+# %n  nickname      - the real nickname returned by the server (mandatory)
+# %a  number        - ascending number in case there are several
+#                     same nicknames (fe. nick#2 and nick#3)
+# %h  hostname      - the stripped hostname of the client
+# %H  full hostname - the full hostname of the client
+#
+# A separator character must follow '%n' if any other formatter follows it.
+#
 settings = {
   "fe-common/core" = {
     autocreate_own_query = "yes";
index 9e481781510da5feac3427537d75d862cebd0550..b1ff500cd7f8ff6bdd39281aaaba09669aefa174 100644 (file)
@@ -774,7 +774,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
       int count = 0;
 
       silc_parse_userfqdn(client_entry->nickname, nick, sizeof(nick), NULL, 0);
-      clients = silc_client_get_clients_local(client, conn, nick, NULL);
+      clients = silc_client_get_clients_local(client, conn, nick, TRUE);
       if (!clients || silc_dlist_count(clients) < 2) {
        silc_client_list_free(client, conn, clients);
        break;
index 189b1c9a616f02ccfc492e8ba01ced9b6ed7dce9..bf233bfdae05f1885cb4733ff2c9a2a8fe683254 100644 (file)
@@ -595,7 +595,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   SilcDList clients;
   SILC_CHANNEL_REC *chanrec = NULL;
   SilcChannelEntry channel_entry = NULL;
-  char nickname[128 + 1], *tmp;
+  char *nickname = NULL, *tmp;
   int command = 0, port = 0, type = 0;
   char *hostname = NULL;
   KeyInternal internal = NULL;
@@ -634,25 +634,23 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
 
   if (type == 1) {
     if (argv[2][0] == '*') {
-      strcpy(nickname, "*");
+      nickname = strdup("*");
     } else {
       /* Parse the typed nickname. */
-      if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
-       printformat_module("fe-common/silc", server, NULL,
-                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
-       return;
-      }
+      silc_client_nickname_parse(silc_client, conn, argv[2], &nickname);
+      if (!nickname)
+       nickname = strdup(argv[2]);
 
       /* Find client entry */
-      clients = silc_client_get_clients_local(silc_client, conn, nickname,
-                                             argv[2]);
+      clients = silc_client_get_clients_local(silc_client, conn, argv[2],
+                                             FALSE);
       if (!clients) {
        KeyGetClients inter = silc_calloc(1, sizeof(*inter));
        inter->server = server;
        inter->data = strdup(data);
        inter->nick = strdup(nickname);
        inter->item = item;
-       silc_client_get_clients(silc_client, conn, nickname, argv[2],
+       silc_client_get_clients(silc_client, conn, nickname, NULL,
                                silc_client_command_key_get_clients, inter);
        goto out;
       }
@@ -667,20 +665,16 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
     char *name;
 
     if (argv[2][0] == '*') {
-      if (!conn->current_channel) {
-       silc_free(nickname);
+      if (!conn->current_channel)
        cmd_return_error(CMDERR_NOT_JOINED);
-      }
       name = conn->current_channel->channel_name;
     } else {
       name = argv[2];
     }
 
     chanrec = silc_channel_find(server, name);
-    if (chanrec == NULL) {
-      silc_free(nickname);
+    if (chanrec == NULL)
       cmd_return_error(CMDERR_CHAN_NOT_FOUND);
-    }
     channel_entry = chanrec->entry;
   }
 
@@ -1062,6 +1056,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   }
 
  out:
+  silc_free(nickname);
   return;
 }
 
index 9510a9756f7b077e6e67fe0c7856cd27aafde75e..0ef483265ff7348e56d35ac264ad1829606225a2 100644 (file)
@@ -326,7 +326,7 @@ void silc_opt_callback(poptContext con,
   SilcUInt32 *argv_lens=NULL, *argv_types=NULL, argc=0;
   int i;
   unsigned char privkey[128], pubkey[128];
-   
+
   memset(privkey, 0, sizeof(privkey));
   memset(pubkey, 0, sizeof(pubkey));
   snprintf(pubkey, sizeof(pubkey) - 1, "%s/%s", get_irssi_dir(),
@@ -431,7 +431,7 @@ void silc_opt_callback(poptContext con,
     sig_setup_changed();
     printformat_module("fe-common/silc", NULL, NULL,
                       MSGLEVEL_CRAP, SILCTXT_CONFIG_DEBUG,
-                      (settings_get_bool("debug") == TRUE ? 
+                      (settings_get_bool("debug") == TRUE ?
                        "enabled" : "disabled"));
     goto out;
 #endif
@@ -473,7 +473,7 @@ void silc_opt_callback(poptContext con,
     rec = g_new0(CREATE_KEY_REC, 1);
     rec->pkcs = (pkcs == NULL ? NULL : g_strdup(pkcs));
     rec->bits = bits;
-             
+
     keyboard_entry_redirect((SIGNAL_FUNC) create_key_passphrase,
                            format_get_text("fe-common/silc", NULL, NULL,
                                            NULL, SILCTXT_CONFIG_PASS_ASK2),
@@ -500,7 +500,7 @@ void silc_opt_callback(poptContext con,
     /* Change the passphrase of the private key file */
 #ifdef SILC_PLUGIN
     CREATE_KEY_REC *rec;
-    
+
     rec = g_new0(CREATE_KEY_REC, 1);
     rec->file = g_strdup((argc == 3 ? argv[2] : privkey));
 
@@ -683,6 +683,7 @@ void silc_core_init(void)
   settings_add_str("server", "session_filename", "session.$chatnet");
   settings_add_bool("server", "sign_channel_messages", FALSE);
   settings_add_bool("server", "sign_private_messages", FALSE);
+  settings_add_str("silc", "nickname_format", "%n#%a");
 
   /* Requested Attributes settings */
   settings_add_bool("silc", "attr_allow", TRUE);
@@ -723,7 +724,7 @@ void silc_core_init(void)
 
   /* Initialize client parameters */
   memset(&params, 0, sizeof(params));
-  strcat(params.nickname_format, "%n@%h%a");
+  strcat(params.nickname_format, settings_get_str("nickname_format"));
 
   /* Allocate SILC client */
   silc_client = silc_client_alloc(&ops, &params, NULL, silc_version_string);
index 7f34ac9f2d1be12a8318b16b99782fa67d4fb311..ce5b6e02a66f84917885e4837e4fbd29f3e8441a 100644 (file)
@@ -89,48 +89,33 @@ static void silc_send_msg_clients(SilcClient client,
   PRIVMSG_REC *rec = context;
   SILC_SERVER_REC *server = rec->server;
   SilcClientEntry target;
-  char nickname[128 + 1];
-  SilcDList lclients = NULL;
 
   if (!clients) {
     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
              "%s: There is no such client", rec->nick);
-  } else {
-    if (silc_dlist_count(clients) > 1) {
-      silc_parse_userfqdn(rec->nick, nickname, sizeof(nickname), NULL, 0);
-
-      /* Find the correct one. The rec->nick might be a formatted nick
-        so this will find the correct one. */
-      clients = lclients =
-       silc_client_get_clients_local(silc_client, server->conn,
-                                     nickname, rec->nick);
-      if (!clients) {
-       printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
-                 "%s: There is no such client", rec->nick);
-       goto out;
-      }
-    }
-
-    target = silc_dlist_get(clients);
-
-    /* Still check for exact math for nickname, this compares the
-       real (formatted) nickname and the nick (maybe formatted) that
-       user gave. This is to assure that `nick' does not match
-       `nick@host'. */
-    if (!silc_utf8_strcasecmp(rec->nick, target->nickname)) {
-      printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
-               "%s: There is no such client", rec->nick);
-      goto out;
-    }
+    goto out;
+  }
 
-    /* Send the private message */
-    silc_client_send_private_message(client, conn, target,
-                                    rec->flags, sha1hash,
-                                    rec->msg, rec->len);
+  /* Find the correct one. The rec->nick might be a formatted nick
+     so this will find the correct one. */
+  target = silc_dlist_get(clients);
+  clients = silc_client_get_clients_local(silc_client, server->conn,
+                                         rec->nick, FALSE);
+  if (!clients) {
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
+             "%s: There is no such client (did you mean %s?)", rec->nick,
+             target->nickname);
+    goto out;
   }
 
+  /* Send the private message */
+  silc_dlist_start(clients);
+  target = silc_dlist_get(clients);
+  silc_client_send_private_message(client, conn, target, rec->flags, sha1hash,
+                                  rec->msg, rec->len);
+
  out:
-  silc_client_list_free(silc_client, server->conn, lclients);
+  silc_client_list_free(silc_client, server->conn, clients);
   g_free(rec->nick);
   g_free(rec->msg);
   g_free(rec);
@@ -140,21 +125,16 @@ int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
                  int msg_len, SilcMessageFlags flags)
 {
   PRIVMSG_REC *rec;
-  char nickname[128 + 1];
   SilcDList clients;
   SilcClientEntry target;
   int ret;
 
-  if (!silc_parse_userfqdn(nick, nickname, sizeof(nickname), NULL, 0)) {
-    printformat_module("fe-common/silc", server, NULL,
-                      MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
-    return FALSE;
-  }
-
   /* Find client entry */
-  clients = silc_client_get_clients_local(silc_client, server->conn,
-                                         nickname, nick);
+  clients = silc_client_get_clients_local(silc_client, server->conn, nick,
+                                         FALSE);
   if (!clients) {
+    char *nickname = NULL;
+
     rec = g_new0(PRIVMSG_REC, 1);
     rec->nick = g_strdup(nick);
     rec->msg = g_strdup(msg);
@@ -162,10 +142,14 @@ int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
     rec->flags = flags;
     rec->len = msg_len;
 
+    silc_client_nickname_parse(silc_client, server->conn, nick, &nickname);
+    if (!nickname)
+      nickname = strdup(nick);
+
     /* Could not find client with that nick, resolve it from server. */
-    silc_client_get_clients_whois(silc_client, server->conn,
-                                 nickname, NULL, NULL,
-                                 silc_send_msg_clients, rec);
+    silc_client_get_clients_whois(silc_client, server->conn, nickname,
+                                 NULL, NULL, silc_send_msg_clients, rec);
+    silc_free(nickname);
     return TRUE;
   }
 
@@ -457,7 +441,7 @@ static void sig_connected(SILC_SERVER_REC *server)
   /* Wrap the socket to TCP stream */
   fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
   server->tcp_op =
-    silc_socket_tcp_stream_create(fd, TRUE, FALSE, 
+    silc_socket_tcp_stream_create(fd, TRUE, FALSE,
                                  silc_client->schedule,
                                  sig_connected_stream_created, server);
 }
@@ -537,8 +521,8 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
     CHANNEL_REC *channel = tmp->data;
     CHANNEL_SETUP_REC *schannel;
 
-    if ((schannel = channel_setup_find(channel->name, server->connrec->chatnet)) && 
-        schannel->password) 
+    if ((schannel = channel_setup_find(channel->name, server->connrec->chatnet)) &&
+        schannel->password)
       g_string_sprintfa(chans, "%s %s,", channel->name,
                        schannel->password);
     else
@@ -866,8 +850,8 @@ static void silc_client_command_file_get_clients(SilcClient client,
   FileGetClients internal = (FileGetClients)context;
 
   if (!clients) {
-    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
-             internal->nick);
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
+             "There was no such nickname: %s", internal->nick);
     silc_free(internal->data);
     silc_free(internal->nick);
     silc_free(internal);
@@ -889,7 +873,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   SilcClientEntry client_entry;
   SilcDList entries;
   SilcClientFileError ret;
-  char nickname[128 + 1], *tmp;
+  char *nickname = NULL, *tmp;
   unsigned char **argv;
   SilcUInt32 argc;
   SilcUInt32 *argv_lens, *argv_types;
@@ -933,22 +917,19 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
       cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
 
     /* Parse the typed nickname. */
-    if (!silc_parse_userfqdn(argv[3], nickname, sizeof(nickname), NULL, 0)) {
-      printformat_module("fe-common/silc", server, NULL,
-                        MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
-      goto out;
-    }
+    silc_client_nickname_parse(silc_client, conn, argv[3], &nickname);
+    if (!nickname)
+      nickname = strdup(argv[3]);
 
     /* Find client entry */
-    entries = silc_client_get_clients_local(silc_client, conn, nickname,
-                                           argv[3]);
+    entries = silc_client_get_clients_local(silc_client, conn, argv[3], FALSE);
     if (!entries) {
       FileGetClients inter = silc_calloc(1, sizeof(*inter));
       inter->server = server;
       inter->data = strdup(data);
       inter->nick = strdup(nickname);
       inter->item = item;
-      silc_client_get_clients(silc_client, conn, nickname, argv[3],
+      silc_client_get_clients(silc_client, conn, nickname, NULL,
                              silc_client_command_file_get_clients, inter);
       goto out;
     }
@@ -1028,22 +1009,21 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   case 2:
     /* Parse the typed nickname. */
     if (argc >= 3) {
-      if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
-       printformat_module("fe-common/silc", server, NULL,
-                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
-       goto out;
-      }
+      /* Parse the typed nickname. */
+      silc_client_nickname_parse(silc_client, conn, argv[2], &nickname);
+      if (!nickname)
+       nickname = strdup(argv[2]);
 
       /* Find client entry */
-      entries = silc_client_get_clients_local(silc_client, conn, nickname,
-                                             argv[2]);
+      entries = silc_client_get_clients_local(silc_client, conn, argv[2],
+                                             FALSE);
       if (!entries) {
        FileGetClients inter = silc_calloc(1, sizeof(*inter));
        inter->server = server;
        inter->data = strdup(data);
        inter->nick = strdup(nickname);
        inter->item = item;
-       silc_client_get_clients(silc_client, conn, nickname, argv[2],
+       silc_client_get_clients(silc_client, conn, nickname, NULL,
                                silc_client_command_file_get_clients, inter);
        goto out;
       }
@@ -1161,22 +1141,21 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   case 3:
     /* Parse the typed nickname. */
     if (argc >= 3) {
-      if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
-       printformat_module("fe-common/silc", server, NULL,
-                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
-       goto out;
-      }
+      /* Parse the typed nickname. */
+      silc_client_nickname_parse(silc_client, conn, argv[2], &nickname);
+      if (!nickname)
+       nickname = strdup(argv[2]);
 
       /* Find client entry */
-      entries = silc_client_get_clients_local(silc_client, conn, nickname,
-                                             argv[2]);
+      entries = silc_client_get_clients_local(silc_client, conn, argv[2],
+                                             FALSE);
       if (!entries) {
        FileGetClients inter = silc_calloc(1, sizeof(*inter));
        inter->server = server;
        inter->data = strdup(data);
        inter->nick = strdup(nickname);
        inter->item = item;
-       silc_client_get_clients(silc_client, conn, nickname, argv[2],
+       silc_client_get_clients(silc_client, conn, nickname, NULL,
                                silc_client_command_file_get_clients, inter);
        goto out;
       }
@@ -1266,6 +1245,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   }
 
  out:
+  silc_free(nickname);
   return;
 }