about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-04-07 19:19:02 +0100
committerJames Booth <boothj5@gmail.com>2013-04-07 19:19:02 +0100
commitf4041f049ce4f66ad6fa9ef167e0a095b35d9f60 (patch)
treeb259c6e816a1fa10e98bc6b8e77ba670a7030dbd
parentb6095ca9550941df5872a25979924053391cb6d1 (diff)
downloadprofani-tty-f4041f049ce4f66ad6fa9ef167e0a095b35d9f60.tar.gz
Handle when servers do not send fulljid with presence
A default resource "__prof_default" is created, and invisible to the
user for most purposes.
-rw-r--r--src/ui/windows.c25
-rw-r--r--src/xmpp/presence.c33
2 files changed, 42 insertions, 16 deletions
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 2905610e..9fb2be17 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -457,13 +457,21 @@ ui_contact_online(const char * const barejid, const char * const resource,
     const char * const show, const char * const status, GDateTime *last_activity)
 {
     Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
-    _show_status_string(console->win, jid->fulljid, show, status, last_activity, "++",
+    char *display_str = NULL;
+
+    if (strcmp(jid->resourcepart, "__prof_default") == 0) {
+        display_str = jid->barejid;
+    } else {
+        display_str = jid->fulljid;
+    }
+
+    _show_status_string(console->win, display_str, show, status, last_activity, "++",
         "online");
 
     int win_index = _find_prof_win_index(barejid);
     if (win_index != NUM_WINS) {
         WINDOW *win = windows[win_index]->win;
-        _show_status_string(win, jid->fulljid, show, status, last_activity, "++",
+        _show_status_string(win, display_str, show, status, last_activity, "++",
             "online");
     }
 
@@ -477,12 +485,21 @@ void
 ui_contact_offline(const char * const from, const char * const show,
     const char * const status)
 {
-    _show_status_string(console->win, from, show, status, NULL, "--", "offline");
+    Jid *jidp = jid_create(from);
+    char *display_str = NULL;
+
+    if (strcmp(jidp->resourcepart, "__prof_default") == 0) {
+        display_str = jidp->barejid;
+    } else {
+        display_str = jidp->fulljid;
+    }
+
+    _show_status_string(console->win, display_str, show, status, NULL, "--", "offline");
 
     int win_index = _find_prof_win_index(from);
     if (win_index != NUM_WINS) {
         WINDOW *win = windows[win_index]->win;
-        _show_status_string(win, from, show, status, NULL, "--", "offline");
+        _show_status_string(win, display_str, show, status, NULL, "--", "offline");
     }
 
     if (win_index == current_index)
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index ea7c51b6..94ea5bb6 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -339,6 +339,10 @@ _unavailable_handler(xmpp_conn_t * const conn,
     if (strcmp(my_jid->barejid, from_jid->barejid) !=0) {
         if (from_jid->resourcepart != NULL) {
             prof_handle_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
+
+        // hack for servers that do not send full jid with unavailable presence
+        } else {
+            prof_handle_contact_offline(from_jid->barejid, "__prof_default", status_str);
         }
     } else {
         if (from_jid->resourcepart != NULL) {
@@ -409,21 +413,26 @@ _available_handler(xmpp_conn_t * const conn,
         }
     }
 
-    // handle resource, if exists
-    if (from_jid->resourcepart != NULL) {
-        resource_presence_t presence = resource_presence_from_string(show_str);
-        Resource *resource = resource_new(from_jid->resourcepart, presence,
+    resource_presence_t presence = resource_presence_from_string(show_str);
+    Resource *resource = NULL;
+
+    // hack for servers that do not send fulljid with initial presence
+    if (from_jid->resourcepart == NULL) {
+        resource = resource_new("__prof_default", presence,
+            status_str, priority, caps_key);
+    } else {
+        resource = resource_new(from_jid->resourcepart, presence,
             status_str, priority, caps_key);
+    }
 
-        // self presence
-        if (strcmp(my_jid->barejid, from_jid->barejid) ==0) {
-            connection_add_available_resource(resource);
+    // self presence
+    if (strcmp(my_jid->barejid, from_jid->barejid) ==0) {
+        connection_add_available_resource(resource);
 
-        // contact presence
-        } else {
-            prof_handle_contact_online(from_jid->barejid, resource,
-                last_activity);
-        }
+    // contact presence
+    } else {
+        prof_handle_contact_online(from_jid->barejid, resource,
+            last_activity);
     }
 
     jid_destroy(my_jid);