summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-07-19 17:30:25 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-07-20 12:19:13 +0100
commit745b5ddcaf5220f2976cabd60a966c52eb25f440 (patch)
treea5498e795a2ad072d964f9b568ce0a35bae4e91d
parent18f0ca014a92fcc40be0f4658a247687739fc1dd (diff)
tubes: use 64bit uints for tube IDs everywhere
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--src/muc-channel.c34
-rw-r--r--src/private-tubes-factory.c61
-rw-r--r--src/private-tubes-factory.h2
-rw-r--r--src/tube-dbus.c10
-rw-r--r--src/tube-dbus.h2
-rw-r--r--src/tube-iface.c6
-rw-r--r--src/tube-stream.c14
-rw-r--r--src/tube-stream.h2
8 files changed, 63 insertions, 68 deletions
diff --git a/src/muc-channel.c b/src/muc-channel.c
index cb675f287..384324f30 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -1964,7 +1964,7 @@ tube_closed_cb (GabbleTubeIface *tube,
GabbleMucChannel *gmuc)
{
GabbleMucChannelPrivate *priv = gmuc->priv;
- guint tube_id;
+ guint64 tube_id;
g_object_get (tube, "id", &tube_id, NULL);
@@ -1978,7 +1978,7 @@ create_new_tube (GabbleMucChannel *gmuc,
const gchar *service,
GHashTable *parameters,
const gchar *stream_id,
- guint tube_id,
+ guint64 tube_id,
GabbleBytestreamIface *bytestream,
gboolean requested)
{
@@ -2009,7 +2009,7 @@ create_new_tube (GabbleMucChannel *gmuc,
tp_base_channel_register ((TpBaseChannel *) tube);
- DEBUG ("create tube %u", tube_id);
+ DEBUG ("create tube %" G_GUINT64_FORMAT, tube_id);
g_hash_table_insert (priv->tubes, GUINT_TO_POINTER (tube_id), tube);
g_signal_connect (tube, "closed", G_CALLBACK (tube_closed_cb), gmuc);
@@ -2017,16 +2017,16 @@ create_new_tube (GabbleMucChannel *gmuc,
return tube;
}
-static guint
+static guint64
generate_tube_id (GabbleMucChannel *self)
{
GabbleMucChannelPrivate *priv = self->priv;
- guint out;
+ guint64 out;
/* probably totally overkill */
do
{
- out = g_random_int_range (0, G_MAXINT);
+ out = g_random_int_range (1, G_MAXINT32);
}
while (g_hash_table_lookup (priv->tubes,
GUINT_TO_POINTER (out)) != NULL);
@@ -2044,7 +2044,7 @@ gabble_muc_channel_tube_request (GabbleMucChannel *self,
const gchar *channel_type;
const gchar *service;
GHashTable *parameters = NULL;
- guint tube_id;
+ guint64 tube_id;
gchar *stream_id;
TpTubeType type;
@@ -2118,9 +2118,7 @@ gabble_muc_channel_handle_si_stream_request (GabbleMucChannel *self,
GabbleMucChannelPrivate *priv = self->priv;
WockyNode *si_node, *stream_node;
const gchar *tmp;
- gchar *endptr;
- unsigned long tube_id_tmp;
- guint tube_id;
+ guint64 tube_id;
GabbleTubeIface *tube;
si_node = wocky_node_get_child_ns (
@@ -2141,17 +2139,16 @@ gabble_muc_channel_handle_si_stream_request (GabbleMucChannel *self,
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- tube_id_tmp = strtoul (tmp, &endptr, 10);
- if (!endptr || *endptr || tube_id_tmp > G_MAXUINT32)
+ tube_id = g_ascii_strtoull (tmp, NULL, 10);
+ if (tube_id == 0 || tube_id > G_MAXUINT32)
{
GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
- "<muc-stream> tube attribute not numeric or > 2**32" };
+ "<muc-stream> tube ID attribute non-numeric or out of range" };
- DEBUG ("tube id is not numeric or > 2**32: %s", tmp);
+ DEBUG ("tube id is non-numeric or out of range: %s", tmp);
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- tube_id = (guint) tube_id_tmp;
tube = g_hash_table_lookup (priv->tubes, GUINT_TO_POINTER (tube_id));
if (tube == NULL)
@@ -2160,12 +2157,13 @@ gabble_muc_channel_handle_si_stream_request (GabbleMucChannel *self,
"<muc-stream> tube attribute points to a nonexistent "
"tube" };
- DEBUG ("tube %u doesn't exist", tube_id);
+ DEBUG ("tube %" G_GUINT64_FORMAT " doesn't exist", tube_id);
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- DEBUG ("received new bytestream request for existing tube: %u", tube_id);
+ DEBUG ("received new bytestream request for existing tube: %" G_GUINT64_FORMAT,
+ tube_id);
gabble_tube_iface_add_bytestream (tube, bytestream);
}
@@ -2234,7 +2232,7 @@ tubes_presence_update (GabbleMucChannel *gmuc,
{
const gchar *stream_id;
GabbleTubeIface *tube;
- guint tube_id;
+ guint64 tube_id;
TpTubeType type;
stream_id = wocky_node_get_attribute (tube_node, "stream-id");
diff --git a/src/private-tubes-factory.c b/src/private-tubes-factory.c
index e8b8aa7b8..f2d626870 100644
--- a/src/private-tubes-factory.c
+++ b/src/private-tubes-factory.c
@@ -49,7 +49,7 @@
#include "util.h"
static GabbleTubeIface * new_channel_from_stanza (GabblePrivateTubesFactory *self,
- WockyStanza *stanza, WockyNode *tube_node, guint tube_id,
+ WockyStanza *stanza, WockyNode *tube_node, guint64 tube_id,
GabbleBytestreamIface *bytestream);
static gboolean private_tubes_factory_tube_close_cb (
@@ -114,7 +114,7 @@ gabble_private_tubes_factory_extract_tube_information (
TpHandle *initiator_handle,
const gchar **service,
GHashTable **parameters,
- guint *tube_id)
+ guint64 *tube_id)
{
if (type != NULL)
{
@@ -176,8 +176,7 @@ gabble_private_tubes_factory_extract_tube_information (
if (tube_id != NULL)
{
const gchar *str;
- gchar *endptr;
- unsigned long tmp;
+ guint64 tmp;
str = wocky_node_get_attribute (tube_node, "id");
if (str == NULL)
@@ -186,13 +185,13 @@ gabble_private_tubes_factory_extract_tube_information (
return FALSE;
}
- tmp = strtoul (str, &endptr, 10);
- if (!endptr || *endptr || tmp > G_MAXUINT32)
+ tmp = g_ascii_strtoull (str, NULL, 10);
+ if (tmp == 0 || tmp > G_MAXUINT32)
{
- DEBUG ("tube id is not numeric or > 2**32: %s", str);
+ DEBUG ("tube id is non-numeric or out of range: %s", str);
return FALSE;
}
- *tube_id = (guint) tmp;
+ *tube_id = tmp;
}
return TRUE;
@@ -692,7 +691,7 @@ gabble_private_tubes_factory_handle_si_tube_request (
WockyNode *si_node, *tube_node;
WockyStanzaType stanza_type;
WockyStanzaSubType sub_type;
- guint tube_id;
+ guint64 tube_id;
GabbleTubeIface *tube;
DEBUG ("contact#%u stream %s", handle, stream_id);
@@ -749,10 +748,8 @@ gabble_private_tubes_factory_handle_si_stream_request (
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
const gchar *tmp;
- gchar *endptr;
- guint tube_id;
+ guint64 tube_id;
WockyNode *si_node, *stream_node;
- unsigned long tube_id_tmp;
GabbleTubeIface *tube;
WockyStanzaType stanza_type;
WockyStanzaSubType sub_type;
@@ -782,17 +779,16 @@ gabble_private_tubes_factory_handle_si_stream_request (
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- tube_id_tmp = strtoul (tmp, &endptr, 10);
- if (!endptr || *endptr || tube_id_tmp > G_MAXUINT32)
+ tube_id = g_ascii_strtoull (tmp, NULL, 10);
+ if (tube_id == 0 || tube_id > G_MAXUINT32)
{
GError e = { WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_BAD_REQUEST,
- "<stream> tube attribute not numeric or > 2**32" };
+ "<stream> tube ID attribute non-numeric or out of range" };
- DEBUG ("tube id is not numeric or > 2**32: %s", tmp);
+ DEBUG ("tube id is non-numeric or out of range: %s", tmp);
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- tube_id = (guint) tube_id_tmp;
tube = g_hash_table_lookup (priv->tubes, GUINT_TO_POINTER (tube_id));
if (tube == NULL)
@@ -801,12 +797,13 @@ gabble_private_tubes_factory_handle_si_stream_request (
"<stream> tube attribute points to a nonexistent "
"tube" };
- DEBUG ("tube %u doesn't exist", tube_id);
+ DEBUG ("tube %" G_GUINT64_FORMAT " doesn't exist", tube_id);
gabble_bytestream_iface_close (bytestream, &e);
return;
}
- DEBUG ("received new bytestream request for existing tube: %u", tube_id);
+ DEBUG ("received new bytestream request for existing tube: %" G_GUINT64_FORMAT,
+ tube_id);
gabble_tube_iface_add_bytestream (tube, bytestream);
}
@@ -816,7 +813,7 @@ tube_msg_checks (GabblePrivateTubesFactory *self,
WockyStanza *msg,
WockyNode *node,
TpHandle *out_handle,
- guint *out_tube_id)
+ guint64 *out_tube_id)
{
GabblePrivateTubesFactoryPrivate *priv =
GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (self);
@@ -824,7 +821,7 @@ tube_msg_checks (GabblePrivateTubesFactory *self,
(TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
const gchar *from, *tmp;
TpHandle handle;
- guint tube_id;
+ guint64 tube_id;
from = wocky_node_get_attribute (
wocky_stanza_get_top_node (msg), "from");
@@ -849,9 +846,9 @@ tube_msg_checks (GabblePrivateTubesFactory *self,
}
tube_id = g_ascii_strtoull (tmp, NULL, 10);
- if (tube_id == 0 || tube_id >= G_MAXINT)
+ if (tube_id == 0 || tube_id > G_MAXUINT32)
{
- DEBUG ("tube ID is not numeric or > 2**32: %s", tmp);
+ DEBUG ("tube ID is non-numeric or out of range: %s", tmp);
return FALSE;
}
@@ -874,7 +871,7 @@ private_tubes_factory_msg_tube_cb (
GabblePrivateTubesFactoryPrivate *priv =
GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (self);
WockyNode *node;
- guint tube_id;
+ guint64 tube_id;
GabbleTubeIface *channel;
TpHandle handle;
@@ -921,7 +918,7 @@ private_tubes_factory_tube_close_cb (
GabblePrivateTubesFactoryPrivate *priv =
GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (self);
WockyNode *node;
- guint tube_id;
+ guint64 tube_id;
GabbleTubeIface *channel;
TpTubeType type;
@@ -947,7 +944,7 @@ private_tubes_factory_tube_close_cb (
return TRUE;
}
- DEBUG ("tube %u was closed by remote peer", tube_id);
+ DEBUG ("tube %" G_GUINT64_FORMAT " was closed by remote peer", tube_id);
gabble_tube_iface_close (channel, TRUE);
return TRUE;
@@ -1013,7 +1010,7 @@ channel_closed_cb (GabbleTubeIface *tube,
g_hash_table_remove (priv->tubes, GUINT_TO_POINTER (id));
}
-static guint
+static guint64
generate_tube_id (GabblePrivateTubesFactory *self)
{
GabblePrivateTubesFactoryPrivate *priv =
@@ -1023,7 +1020,7 @@ generate_tube_id (GabblePrivateTubesFactory *self)
/* probably totally overkill */
do
{
- out = g_random_int_range (0, G_MAXINT);
+ out = g_random_int_range (1, G_MAXINT32);
}
while (g_hash_table_lookup (priv->tubes,
GUINT_TO_POINTER (out)) != NULL);
@@ -1048,7 +1045,7 @@ new_channel_from_request (GabblePrivateTubesFactory *self,
const gchar *ctype, *service;
TpHandleType handle_type;
GHashTable *parameters;
- guint tube_id;
+ guint64 tube_id;
ctype = tp_asv_get_string (request, TP_PROP_CHANNEL_CHANNEL_TYPE);
handle = tp_asv_get_uint32 (request, TP_PROP_CHANNEL_TARGET_HANDLE,
@@ -1107,7 +1104,7 @@ new_channel_from_request (GabblePrivateTubesFactory *self,
static void
send_tube_close_msg (GabblePrivateTubesFactory *self,
const gchar *jid,
- guint tube_id)
+ guint64 tube_id)
{
GabblePrivateTubesFactoryPrivate *priv =
GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (self);
@@ -1115,7 +1112,7 @@ send_tube_close_msg (GabblePrivateTubesFactory *self,
WockyStanza *msg;
gchar *id_str;
- id_str = g_strdup_printf ("%u", tube_id);
+ id_str = g_strdup_printf ("%" G_GUINT64_FORMAT, tube_id);
porter = gabble_connection_dup_porter (priv->conn);
@@ -1142,7 +1139,7 @@ static GabbleTubeIface *
new_channel_from_stanza (GabblePrivateTubesFactory *self,
WockyStanza *stanza,
WockyNode *tube_node,
- guint tube_id,
+ guint64 tube_id,
GabbleBytestreamIface *bytestream)
{
GabblePrivateTubesFactoryPrivate *priv =
diff --git a/src/private-tubes-factory.h b/src/private-tubes-factory.h
index 1ae86f322..eb2f9fc08 100644
--- a/src/private-tubes-factory.h
+++ b/src/private-tubes-factory.h
@@ -78,7 +78,7 @@ gboolean gabble_private_tubes_factory_extract_tube_information (
TpHandleRepoIface *contact_repo, WockyNode *tube_node,
TpTubeType *type, TpHandle *initiator_handle,
const gchar **service, GHashTable **parameters,
- guint *tube_id);
+ guint64 *tube_id);
G_END_DECLS
diff --git a/src/tube-dbus.c b/src/tube-dbus.c
index 3df502bfb..897f1ff86 100644
--- a/src/tube-dbus.c
+++ b/src/tube-dbus.c
@@ -120,7 +120,7 @@ enum
struct _GabbleTubeDBusPrivate
{
TpHandle self_handle;
- guint id;
+ guint64 id;
GabbleBytestreamIface *bytestream;
gchar *stream_id;
gchar *service;
@@ -599,7 +599,7 @@ gabble_tube_dbus_get_property (GObject *object,
g_value_set_uint (value, priv->self_handle);
break;
case PROP_ID:
- g_value_set_uint (value, priv->id);
+ g_value_set_uint64 (value, priv->id);
break;
case PROP_BYTESTREAM:
g_value_set_object (value, priv->bytestream);
@@ -655,7 +655,7 @@ gabble_tube_dbus_set_property (GObject *object,
priv->self_handle = g_value_get_uint (value);
break;
case PROP_ID:
- priv->id = g_value_get_uint (value);
+ priv->id = g_value_get_uint64 (value);
break;
case PROP_BYTESTREAM:
if (priv->bytestream == NULL)
@@ -833,7 +833,7 @@ gabble_tube_dbus_get_object_path_suffix (TpBaseChannel *base)
{
GabbleTubeDBus *self = GABBLE_TUBE_DBUS (base);
- return g_strdup_printf ("DBusTubeChannel/%u/%u",
+ return g_strdup_printf ("DBusTubeChannel/%u/%" G_GUINT64_FORMAT,
tp_base_channel_get_target_handle (base),
self->priv->id);
}
@@ -1344,7 +1344,7 @@ gabble_tube_dbus_new (GabbleConnection *conn,
const gchar *service,
GHashTable *parameters,
const gchar *stream_id,
- guint id,
+ guint64 id,
GabbleBytestreamIface *bytestream,
GabbleMucChannel *muc,
gboolean requested)
diff --git a/src/tube-dbus.h b/src/tube-dbus.h
index 35073ce3f..051781387 100644
--- a/src/tube-dbus.h
+++ b/src/tube-dbus.h
@@ -73,7 +73,7 @@ GType gabble_tube_dbus_get_type (void);
GabbleTubeDBus *gabble_tube_dbus_new (GabbleConnection *conn, TpHandle handle,
TpHandleType handle_type, TpHandle self_handle, TpHandle initiator,
const gchar *service, GHashTable *parameters, const gchar *stream_id,
- guint id, GabbleBytestreamIface *bytestream, GabbleMucChannel *muc,
+ guint64 id, GabbleBytestreamIface *bytestream, GabbleMucChannel *muc,
gboolean requested);
gboolean gabble_tube_dbus_add_name (GabbleTubeDBus *tube, TpHandle handle,
diff --git a/src/tube-iface.c b/src/tube-iface.c
index 62585eb33..c38a9ab03 100644
--- a/src/tube-iface.c
+++ b/src/tube-iface.c
@@ -72,7 +72,7 @@ gabble_tube_iface_base_init (gpointer klass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property (klass, param_spec);
- param_spec = g_param_spec_uint (
+ param_spec = g_param_spec_uint64 (
"id",
"id",
"The unique identifier of this tube",
@@ -151,7 +151,7 @@ gabble_tube_iface_publish_in_node (GabbleTubeIface *tube,
GHashTable *parameters;
TpTubeType type;
gchar *service, *id_str;
- guint tube_id;
+ guint64 tube_id;
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
conn, TP_HANDLE_TYPE_CONTACT);
TpHandle initiator_handle;
@@ -164,7 +164,7 @@ gabble_tube_iface_publish_in_node (GabbleTubeIface *tube,
"id", &tube_id,
NULL);
- id_str = g_strdup_printf ("%u", tube_id);
+ id_str = g_strdup_printf ("%" G_GUINT64_FORMAT, tube_id);
wocky_node_set_attributes (node,
"service", service,
diff --git a/src/tube-stream.c b/src/tube-stream.c
index 28415cd2a..a28c58a8d 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -136,7 +136,7 @@ enum
struct _GabbleTubeStreamPrivate
{
TpHandle self_handle;
- guint id;
+ guint64 id;
/* Bytestreams for tubes. One tube can have several bytestreams. The
* mapping between the tube bytestream and the transport to the local
@@ -503,7 +503,7 @@ start_stream_initiation (GabbleTubeStream *self,
wocky_stanza_get_top_node (msg), "si", NS_SI);
g_assert (si_node != NULL);
- id_str = g_strdup_printf ("%u", priv->id);
+ id_str = g_strdup_printf ("%" G_GUINT64_FORMAT, priv->id);
if (cls->target_handle_type == TP_HANDLE_TYPE_CONTACT)
{
@@ -1235,7 +1235,7 @@ gabble_tube_stream_get_property (GObject *object,
g_value_set_uint (value, priv->self_handle);
break;
case PROP_ID:
- g_value_set_uint (value, priv->id);
+ g_value_set_uint64 (value, priv->id);
break;
case PROP_TYPE:
g_value_set_uint (value, TP_TUBE_TYPE_STREAM);
@@ -1289,7 +1289,7 @@ gabble_tube_stream_set_property (GObject *object,
priv->self_handle = g_value_get_uint (value);
break;
case PROP_ID:
- priv->id = g_value_get_uint (value);
+ priv->id = g_value_get_uint64 (value);
break;
case PROP_SERVICE:
g_free (priv->service);
@@ -1401,7 +1401,7 @@ gabble_tube_stream_get_object_path_suffix (TpBaseChannel *base)
{
GabbleTubeStream *self = GABBLE_TUBE_STREAM (base);
- return g_strdup_printf ("StreamTubeChannel/%u/%u",
+ return g_strdup_printf ("StreamTubeChannel/%u/%" G_GUINT64_FORMAT,
tp_base_channel_get_target_handle (base),
self->priv->id);
}
@@ -1620,7 +1620,7 @@ gabble_tube_stream_new (GabbleConnection *conn,
TpHandle initiator,
const gchar *service,
GHashTable *parameters,
- guint id,
+ guint64 id,
GabbleMucChannel *muc,
gboolean requested)
{
@@ -1725,7 +1725,7 @@ gabble_tube_iface_stream_close (GabbleTubeIface *tube,
jid = tp_handle_inspect (contact_repo,
tp_base_channel_get_target_handle (base));
- id_str = g_strdup_printf ("%u", priv->id);
+ id_str = g_strdup_printf ("%" G_GUINT64_FORMAT, priv->id);
/* Send the close message */
msg = wocky_stanza_build (WOCKY_STANZA_TYPE_MESSAGE,
diff --git a/src/tube-stream.h b/src/tube-stream.h
index 991116238..b29aa12fc 100644
--- a/src/tube-stream.h
+++ b/src/tube-stream.h
@@ -69,7 +69,7 @@ GType gabble_tube_stream_get_type (void);
GabbleTubeStream *gabble_tube_stream_new (GabbleConnection *conn,
TpHandle handle, TpHandleType handle_type, TpHandle self_handle,
TpHandle initiator, const gchar *service, GHashTable *parameters,
- guint id, GabbleMucChannel *muc, gboolean requested);
+ guint64 id, GabbleMucChannel *muc, gboolean requested);
gboolean gabble_tube_stream_check_params (TpSocketAddressType address_type,
const GValue *address, TpSocketAccessControl access_control,