~ubuntu-branches/ubuntu/maverick/telepathy-glib/maverick

« back to all changes in this revision

Viewing changes to telepathy-glib/base-connection.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon McVittie
  • Date: 2009-09-03 20:23:03 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090903202303-dhci6f1ri29fyo5c
Tags: 0.7.36-1
New upstream version (API, ABI added)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1468
1468
  priv->channel_requests = g_ptr_array_new ();
1469
1469
}
1470
1470
 
 
1471
static gchar *
 
1472
squash_name (const gchar *name, guint length)
 
1473
{
 
1474
  GChecksum *checksum;
 
1475
  gchar *squashed;
 
1476
 
 
1477
  g_assert (length >= 10);
 
1478
  checksum = g_checksum_new (G_CHECKSUM_MD5);
 
1479
  g_checksum_update (checksum, (guchar *) name, -1);
 
1480
  squashed = g_strdup_printf (
 
1481
      "%.*s_%.8s", length - 9, name, g_checksum_get_string (checksum));
 
1482
  g_checksum_free (checksum);
 
1483
  return squashed;
 
1484
}
 
1485
 
1471
1486
/**
1472
1487
 * tp_base_connection_register:
1473
1488
 * @self: A connection
1496
1511
  gchar *tmp;
1497
1512
  gchar *safe_proto;
1498
1513
  gchar *unique_name;
 
1514
  guint prefix_length;
 
1515
  const guint dbus_max_name_length = 255;
1499
1516
 
1500
1517
  g_return_val_if_fail (TP_IS_BASE_CONNECTION (self), FALSE);
1501
1518
  g_return_val_if_fail (cm_name != NULL, FALSE);
1513
1530
      safe_proto = tp_escape_as_identifier (priv->protocol);
1514
1531
    }
1515
1532
 
 
1533
  /* Plus two for the dots. */
 
1534
  prefix_length = strlen (TP_CONN_BUS_NAME_BASE) +
 
1535
      strlen (cm_name) + strlen (safe_proto) + 2;
 
1536
 
1516
1537
  if (cls->get_unique_connection_name)
1517
1538
    {
 
1539
 
1518
1540
      tmp = cls->get_unique_connection_name (self);
1519
1541
      g_assert (tmp != NULL);
1520
1542
      unique_name = tp_escape_as_identifier (tmp);
1521
1543
      g_free (tmp);
 
1544
 
 
1545
      if (prefix_length + strlen (unique_name) > dbus_max_name_length)
 
1546
        {
 
1547
          /* Is prefix is too long to make reasonable bus name? Ten = one
 
1548
           * character of the original unique name plus underscore plus
 
1549
           * 8-character hash.
 
1550
           */
 
1551
          if (prefix_length >= dbus_max_name_length - 10)
 
1552
            {
 
1553
              g_warning (
 
1554
                  "Couldn't fit CM name + protocol name + unique name into "
 
1555
                  "255 characters.");
 
1556
              g_free (unique_name);
 
1557
              return FALSE;
 
1558
            }
 
1559
 
 
1560
          tmp = unique_name;
 
1561
          unique_name = squash_name (
 
1562
              tmp, dbus_max_name_length - prefix_length);
 
1563
          g_free (tmp);
 
1564
        }
1522
1565
    }
1523
1566
  else
1524
1567
    {
1533
1576
 
1534
1577
  self->bus_name = g_strdup_printf (TP_CONN_BUS_NAME_BASE "%s.%s.%s",
1535
1578
      cm_name, safe_proto, unique_name);
 
1579
  g_assert (strlen (self->bus_name) <= 255);
1536
1580
  self->object_path = g_strdup_printf (TP_CONN_OBJECT_PATH_BASE "%s/%s/%s",
1537
1581
      cm_name, safe_proto, unique_name);
1538
1582
 
1700
1744
 
1701
1745
  g_assert (TP_IS_BASE_CONNECTION (self));
1702
1746
 
1703
 
  TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (self, context);
1704
 
 
1705
1747
  priv = self->priv;
1706
1748
  klass = TP_BASE_CONNECTION_GET_CLASS (self);
1707
1749
 
1708
1750
  if (priv->interfaces)
1709
1751
    {
1710
 
      /* There are some extra interfaces for this channel */
 
1752
      /* There are some extra interfaces for this connection */
1711
1753
      interfaces = (const gchar **)(priv->interfaces->data);
1712
1754
    }
1713
1755
  else