[polari] room: Match on "login" to identify a nick as well



commit fce5c77892bbf551b6bcee9fe148bbe3afcc4605
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Mar 2 01:41:33 2017 +0100

    room: Match on "login" to identify a nick as well
    
    Some nick authentication bots are not only not called "NickServ", but
    expect a command that is not "identify", sigh. Support some more of them
    by matching on "login" as well as "identify" and remember the expected
    command - as long as the parameters are still the same, the existing
    NickServ support should then start to work for userserv and friends.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778841

 data/org.gnome.Polari.gschema.xml |    5 +++++
 src/chatView.js                   |    2 +-
 src/lib/polari-room.c             |   14 ++++++++------
 src/lib/polari-room.h             |    1 +
 src/lib/polari-util.c             |   11 ++++++++---
 src/lib/polari-util.h             |    1 +
 src/telepathyClient.js            |   11 +++++++++--
 7 files changed, 33 insertions(+), 12 deletions(-)
---
diff --git a/data/org.gnome.Polari.gschema.xml b/data/org.gnome.Polari.gschema.xml
index d6a16b9..ce531bc 100644
--- a/data/org.gnome.Polari.gschema.xml
+++ b/data/org.gnome.Polari.gschema.xml
@@ -34,6 +34,11 @@
       <summary>Identify botname</summary>
       <description>Nickname of the bot to identify with</description>
     </key>
+    <key type="s" name="identify-command">
+      <default>"identify"</default>
+      <summary>Identify command</summary>
+      <description>Command used to identify with bot</description>
+    </key>
     <key type="s" name="identify-username">
       <default>""</default>
       <summary>Identify username</summary>
diff --git a/src/chatView.js b/src/chatView.js
index 2ca8d9a..f3f3c3b 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1300,7 +1300,7 @@ const ChatView = new Lang.Class({
 
         // mask identify passwords in private chats
         if (this._room.type == Tp.HandleType.CONTACT) {
-            let [isIdentify, username, password] =
+            let [isIdentify, command, username, password] =
                 Polari.util_match_identify_message(text);
 
             if (isIdentify)
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 8d400a0..aded5a1 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -267,6 +267,7 @@ on_identify_message_sent (GObject      *source,
 
 void
 polari_room_send_identify_message_async (PolariRoom          *room,
+                                         const char          *command,
                                          const char          *username,
                                          const char          *password,
                                          GAsyncReadyCallback  callback,
@@ -278,7 +279,7 @@ polari_room_send_identify_message_async (PolariRoom          *room,
   char *text;
 
   g_return_if_fail (POLARI_IS_ROOM (room));
-  g_return_if_fail (username != NULL && password != NULL);
+  g_return_if_fail (command != NULL && username != NULL && password != NULL);
 
   priv = room->priv;
 
@@ -295,7 +296,7 @@ polari_room_send_identify_message_async (PolariRoom          *room,
   /* Don't emit ::identify-sent for our own identify message */
   room->priv->ignore_identify = TRUE;
 
-  text = g_strdup_printf ("identify %s %s", username, password);
+  text = g_strdup_printf ("%s %s %s", command, username, password);
   message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, text);
 
   tp_text_channel_send_message_async (TP_TEXT_CHANNEL (priv->channel), message,
@@ -466,20 +467,21 @@ on_message_sent (TpTextChannel      *channel,
 {
   PolariRoom *room = user_data;
   PolariRoomPrivate *priv = room->priv;
-  char *username, *password, *text;
+  char *command, *username, *password, *text;
 
   if (priv->type != TP_HANDLE_TYPE_CONTACT)
     return;
 
   text = tp_message_to_text (TP_MESSAGE (message), NULL);
 
-  if (polari_util_match_identify_message (text, &username, &password))
+  if (polari_util_match_identify_message (text, &command, &username, &password))
     {
       if (!priv->ignore_identify)
-        g_signal_emit (room, signals[IDENTIFY_SENT], 0, username, password);
+        g_signal_emit (room, signals[IDENTIFY_SENT], 0, command, username, password);
 
       priv->ignore_identify = FALSE;
 
+      g_free (command);
       g_free (username);
       g_free (password);
     }
@@ -968,7 +970,7 @@ polari_room_class_init (PolariRoomClass *klass)
                   G_SIGNAL_RUN_LAST,
                   0,
                   NULL, NULL, NULL,
-                  G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
+                  G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 }
 
 static void
diff --git a/src/lib/polari-room.h b/src/lib/polari-room.h
index 7a4e1bb..0170245 100644
--- a/src/lib/polari-room.h
+++ b/src/lib/polari-room.h
@@ -38,6 +38,7 @@ void  polari_room_add_member    (PolariRoom *room, TpContact *member);
 void  polari_room_remove_member (PolariRoom *room, TpContact *member);
 
 void polari_room_send_identify_message_async (PolariRoom          *room,
+                                              const char          *command,
                                               const char          *username,
                                               const char          *password,
                                               GAsyncReadyCallback  callback,
diff --git a/src/lib/polari-util.c b/src/lib/polari-util.c
index bfc2c6a..25a4c4d 100644
--- a/src/lib/polari-util.c
+++ b/src/lib/polari-util.c
@@ -45,6 +45,8 @@ polari_util_get_basenick (const char *nick)
 /**
  * polari_util_match_identify_message:
  * @message: a text message
+ * @command: (optional) (out): the parsed command if the @message is an
+ *                             identify command
  * @username: (optional) (out): the parsed name if the @message is an
  *                              identify command
  * @password: (optional) (out): the parsed password if the @message is an
@@ -54,6 +56,7 @@ polari_util_get_basenick (const char *nick)
  */
 gboolean
 polari_util_match_identify_message (const char  *message,
+                                    char       **command,
                                     char       **username,
                                     char       **password)
 {
@@ -66,17 +69,19 @@ polari_util_match_identify_message (const char  *message,
   stripped_text = g_strstrip (text);
 
   if (G_UNLIKELY (identify_message_regex == NULL))
-    identify_message_regex = g_regex_new ("^identify (?:(\\w+) )?(\\S+)$",
+    identify_message_regex = g_regex_new ("^(identify|login) (?:(\\w+) )?(\\S+)$",
                                           G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
                                           0, NULL);
 
   matched = g_regex_match (identify_message_regex, stripped_text, 0, &match);
   if (matched)
     {
+      if (command)
+        *command = g_match_info_fetch (match, 1);
       if (username)
-        *username = g_match_info_fetch (match, 1);
+        *username = g_match_info_fetch (match, 2);
       if (password)
-        *password = g_match_info_fetch (match, 2);
+        *password = g_match_info_fetch (match, 3);
     }
 
   g_match_info_free (match);
diff --git a/src/lib/polari-util.h b/src/lib/polari-util.h
index db8b508..0475105 100644
--- a/src/lib/polari-util.h
+++ b/src/lib/polari-util.h
@@ -24,6 +24,7 @@
 char *polari_util_get_basenick (const char *nick);
 
 gboolean polari_util_match_identify_message (const char  *message,
+                                             char       **command,
                                              char       **username,
                                              char       **password);
 
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index f413f4a..d6b5011 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -303,13 +303,14 @@ const TelepathyClient = new Lang.Class({
         let username = settings.get_string('identify-username') ||
                        params.username.deep_unpack();
         let contactName = settings.get_string('identify-botname');
+        let command = settings.get_string('identify-command');
         this._requestChannel(account, Tp.HandleType.CONTACT, contactName,
             (channel) => {
                 if (!channel)
                     return;
 
                 let room = this._roomManager.lookupRoomByChannel(channel);
-                room.send_identify_message_async(username, password, (r, res) => {
+                room.send_identify_message_async(command, username, password, (r, res) => {
                     try {
                         r.send_identify_message_finish(res);
                     } catch(e) {
@@ -432,6 +433,11 @@ const TelepathyClient = new Lang.Class({
         else
             settings.set_string('identify-botname', data.botname);
 
+        if (data.command == 'identify')
+            settings.reset('identify-command');
+        else
+            settings.set_string('identify-command', data.command);
+
         settings.set_string('identify-username', data.username);
     },
 
@@ -548,11 +554,12 @@ const TelepathyClient = new Lang.Class({
         return notification;
     },
 
-    _onIdentifySent: function(room, username, password) {
+    _onIdentifySent: function(room, command, username, password) {
         let accountPath = room.account.object_path;
 
         let data = {
             botname: room.channel.target_contact.alias,
+            command: command,
             username: username || room.channel.connection.self_contact.alias,
             password: password
         };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]