[sugar] [PATCH] telepathy-salut: push ipv4 & ipv6 address through OLPC buddy properties

Dan Williams dcbw
Sat Jul 14 09:01:28 EDT 2007


As a hack for trial 2; post trial 2 the "ip4-address" buddy property
will be going away and activity authors should use other, more
appropriate mechanisms (like tubes, direct avahi, or multicast or
something).

diff -rN -u old-telepathy-salut-olpc-trial2/src/salut-connection.c new-telepathy-salut-olpc-trial2/src/salut-connection.c
--- old-telepathy-salut-olpc-trial2/src/salut-connection.c	2007-07-13 22:03:20.000000000 -0400
+++ new-telepathy-salut-olpc-trial2/src/salut-connection.c	2007-07-13 22:03:20.000000000 -0400
@@ -1096,7 +1096,9 @@
 static GHashTable *
 get_properties_hash (const GArray *key,
                      const gchar *color,
-                     const gchar *jid)
+                     const gchar *jid,
+                     const gchar *ip4,
+                     const gchar *ip6)
 {
   GHashTable *properties;
   GValue *gvalue;
@@ -1124,6 +1126,20 @@
       g_hash_table_insert (properties, "jid", gvalue);
     }
 
+  if (ip4 != NULL)
+    {
+      gvalue = new_gvalue (G_TYPE_STRING);
+      g_value_set_string (gvalue, ip4);
+      g_hash_table_insert (properties, "ip4-address", gvalue);
+    }
+
+  if (ip6 != NULL)
+    {
+      gvalue = new_gvalue (G_TYPE_STRING);
+      g_value_set_string (gvalue, ip6);
+      g_hash_table_insert (properties, "ip6-address", gvalue);
+    }
+
   return properties;
 }
 
@@ -1132,10 +1148,12 @@
                          TpHandle handle,
                          const GArray *key,
                          const gchar *color,
-                         const gchar *jid)
+                         const gchar *jid,
+                         const gchar *ip4,
+                         const gchar *ip6)
 {
   GHashTable *properties;
-  properties = get_properties_hash (key, color, jid);
+  properties = get_properties_hash (key, color, jid, ip4, ip6);
 
   salut_svc_olpc_buddy_info_emit_properties_changed (connection,
       handle, properties);
@@ -1194,7 +1212,7 @@
                                                   TpHandle handle)
 {
   emit_properties_changed (self, handle, contact->olpc_key,
-      contact->olpc_color, contact->jid);
+      contact->olpc_color, contact->jid, contact->olpc_ip4, contact->olpc_ip6);
 }
 
 static void
@@ -1212,7 +1230,7 @@
   if (handle == base->self_handle)
     {
       properties = get_properties_hash (priv->self->olpc_key,
-          priv->self->olpc_color, priv->self->jid);
+          priv->self->olpc_color, priv->self->jid, NULL, NULL);
     }
   else
     {
@@ -1227,7 +1245,7 @@
           return;
         }
       properties = get_properties_hash (contact->olpc_key, contact->olpc_color,
-        contact->jid);
+        contact->jid, contact->olpc_ip4, contact->olpc_ip6);
       g_object_unref (contact);
     }
 
@@ -1910,7 +1928,9 @@
   }
 
 #ifdef ENABLE_OLPC
-  if (changes & SALUT_CONTACT_OLPC_PROPERTIES)
+  if ((changes & SALUT_CONTACT_OLPC_PROPERTIES) ||
+      (changes & SALUT_CONTACT_OLPC_IP4) ||
+      (changes & SALUT_CONTACT_OLPC_IP6))
     _contact_manager_contact_olpc_properties_changed (self, contact, handle);
 
   if (changes & SALUT_CONTACT_OLPC_CURRENT_ACTIVITY)
diff -rN -u old-telepathy-salut-olpc-trial2/src/salut-contact.c new-telepathy-salut-olpc-trial2/src/salut-contact.c
--- old-telepathy-salut-olpc-trial2/src/salut-contact.c	2007-07-13 22:03:20.000000000 -0400
+++ new-telepathy-salut-olpc-trial2/src/salut-contact.c	2007-07-13 22:03:20.000000000 -0400
@@ -131,6 +131,8 @@
   obj->olpc_cur_act_room = 0;
   priv->olpc_activities = g_hash_table_new_full (g_str_hash, g_str_equal,
       (GDestroyNotify) g_free, (GDestroyNotify) activity_free);
+  obj->olpc_ip4 = NULL;
+  obj->olpc_ip6 = NULL;
 #endif
   priv->client = NULL;
   priv->resolvers = NULL;
@@ -246,6 +248,8 @@
     }
   g_free (self->olpc_color);
   g_free (self->olpc_cur_act);
+  g_free (self->olpc_ip4);
+  g_free (self->olpc_ip6);
 #endif
 
   G_OBJECT_CLASS (salut_contact_parent_class)->finalize (object);
@@ -524,7 +528,7 @@
 contact_resolved_cb(SalutAvahiServiceResolver *resolver,
                     AvahiIfIndex interface, AvahiProtocol protocol,
                     gchar *name, gchar *type, gchar *domain, gchar *host_name,
-                    AvahiAddress *a, gint port,
+                    AvahiAddress *address, gint port,
                     AvahiStringList *txt, AvahiLookupResultFlags flags,
                     gpointer userdata) {
   SalutContact *self = SALUT_CONTACT (userdata);
@@ -797,6 +801,32 @@
           g_array_free (new_key, TRUE);
         }
     }
+
+  if (address)
+    {
+      gchar * saddr = g_malloc0 (AVAHI_ADDRESS_STR_MAX + 1);
+
+      if (saddr && avahi_address_snprint (saddr, AVAHI_ADDRESS_STR_MAX, address))
+        {
+          switch (address->proto)
+            {
+              case AVAHI_PROTO_INET:
+                self->olpc_ip4 = saddr;
+                SET_CHANGE (SALUT_CONTACT_OLPC_IP4);
+                break;
+              case AVAHI_PROTO_INET6:
+                self->olpc_ip6 = saddr;
+                SET_CHANGE (SALUT_CONTACT_OLPC_IP6);
+                break;
+              default:
+                g_free (saddr);
+                break;
+            }
+        }
+      else
+        g_free (saddr);
+    }
+
 #endif
 
   if (changes != 0) {
diff -rN -u old-telepathy-salut-olpc-trial2/src/salut-contact.h new-telepathy-salut-olpc-trial2/src/salut-contact.h
--- old-telepathy-salut-olpc-trial2/src/salut-contact.h	2007-07-13 22:03:20.000000000 -0400
+++ new-telepathy-salut-olpc-trial2/src/salut-contact.h	2007-07-13 22:03:20.000000000 -0400
@@ -42,6 +42,8 @@
 #define  SALUT_CONTACT_OLPC_PROPERTIES 0x8
 #define  SALUT_CONTACT_OLPC_CURRENT_ACTIVITY 0x10
 #define  SALUT_CONTACT_OLPC_ACTIVITIES 0x20
+#define  SALUT_CONTACT_OLPC_IP4 0x40
+#define  SALUT_CONTACT_OLPC_IP6 0x80
 #endif /* ENABLE_OLPC */
 
 typedef struct _SalutContact SalutContact;
@@ -63,6 +65,8 @@
     gchar *olpc_color;
     gchar *olpc_cur_act;
     TpHandle olpc_cur_act_room;
+    gchar *olpc_ip4;
+    gchar *olpc_ip6;
 #endif /* ENABLE_OLPC */
 };
 





More information about the Sugar-devel mailing list