summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Staudinger <robsta@linux.intel.com>2012-01-23 23:02:08 +0100
committerRob Staudinger <robsta@linux.intel.com>2012-01-23 23:02:08 +0100
commit333117d1fec9778595177369522d08e1e5a18a8a (patch)
tree500b3e7a72d8066ab91c54ed5a6a8167c290b1c1
parentac4859d4e1d88e8a7e660660cc416a9e48e3397a (diff)
Client: make sure capabilities are namespaced correctly
Ytstenut capabilities always need the urn:ytstenut:capabilities namespace.
-rw-r--r--examples/status.c32
-rw-r--r--ytstenut/yts-client.c28
2 files changed, 42 insertions, 18 deletions
diff --git a/examples/status.c b/examples/status.c
index ae314b5..a819740 100644
--- a/examples/status.c
+++ b/examples/status.c
@@ -27,7 +27,10 @@
#define CAPABILITY "org.freedesktop.ytstenut.StatusExample"
#define CLIENT_UID "org.freedesktop.ytstenut.StatusExampleClient"
+#define CLIENT_JID "ytstenut2@test.collabora.co.uk0"
+
#define SERVER_UID "org.freedesktop.ytstenut.StatusExampleServer"
+#define SERVER_JID "ytstenut1@test.collabora.co.uk0"
/*
* Client
@@ -97,13 +100,17 @@ _client_roster_service_added (YtsRoster *roster,
}
static int
-run_client (void)
+run_client (bool p2p)
{
YtsClient *client;
YtsRoster *roster;
GMainLoop *mainloop;
- client = yts_client_new_p2p (CLIENT_UID);
+ if (p2p)
+ client = yts_client_new_p2p (CLIENT_UID);
+ else
+ client = yts_client_new_c2s (CLIENT_JID, CLIENT_UID);
+
g_signal_connect (client, "authenticated",
G_CALLBACK (_client_authenticated), NULL);
g_signal_connect (client, "ready",
@@ -156,25 +163,24 @@ _server_text_message (YtsClient *client,
char const *text,
void *data)
{
- char const *property_name;
-
g_debug ("%s()", __FUNCTION__);
/* Got pinged, set some status */
- property_name = "urn:ytstenut:capabilities:" CAPABILITY;
-
- yts_client_set_status_by_capability (client,
- property_name, "Foo");
+ yts_client_set_status_by_capability (client, CAPABILITY, "Foo");
}
static int
-run_server (void)
+run_server (bool p2p)
{
YtsClient *client;
GMainLoop *mainloop;
- client = yts_client_new_p2p (SERVER_UID);
+ if (p2p)
+ client = yts_client_new_p2p (SERVER_UID);
+ else
+ client = yts_client_new_c2s (SERVER_JID, SERVER_UID);
+
yts_client_add_capability (client, CAPABILITY);
g_signal_connect (client, "authenticated",
G_CALLBACK (_server_authenticated), NULL);
@@ -200,9 +206,11 @@ main (int argc,
{
bool client = false;
bool server = true;
+ bool p2p = false;
GOptionEntry entries[] = {
{ "client", 'c', 0, G_OPTION_ARG_NONE, &client, "Run as client", NULL },
{ "server", 's', 0, G_OPTION_ARG_NONE, &server, "Run as server (default)", NULL },
+ { "p2p", 'p', 0, G_OPTION_ARG_NONE, &p2p, "Run in p2p mode", NULL },
{ NULL, }
};
@@ -222,10 +230,10 @@ main (int argc,
if (client) {
g_message ("Running as client ...");
- ret = run_client ();
+ ret = run_client (p2p);
} else if (server) {
g_message ("Running as server ...");
- ret = run_server ();
+ ret = run_server (p2p);
} else {
g_warning ("%s : Not running as server or client, quitting", G_STRLOC);
ret = -1;
diff --git a/ytstenut/yts-client.c b/ytstenut/yts-client.c
index 60561bf..641697d 100644
--- a/ytstenut/yts-client.c
+++ b/ytstenut/yts-client.c
@@ -2495,12 +2495,13 @@ yts_client_dispatch_status (YtsClient *self)
char *xml = NULL;
unsigned i;
+ // TODO something is fishy here, why are we setting the same status to all the caps?
+
g_return_if_fail (priv->caps && priv->caps->len);
- if (priv->status)
+ if (priv->status) {
xml = yts_metadata_to_string ((YtsMetadata*)priv->status);
-
- g_message ("Setting status to\n%s", xml);
+ }
for (i = 0; i < priv->caps->len; ++i)
{
@@ -2508,6 +2509,10 @@ yts_client_dispatch_status (YtsClient *self)
c = g_quark_to_string (g_array_index (priv->caps, YtsCaps, i));
+ g_message ("Setting status of capability '%s' to\n %s",
+ c,
+ xml);
+
tp_yts_status_advertise_status_async (priv->tp_status,
c,
priv->service_id,
@@ -2900,15 +2905,21 @@ yts_client_refresh_roster (YtsClient *self)
*/
void
yts_client_add_capability (YtsClient *self,
- char const *capability)
+ char const *c)
{
YtsClientPrivate *priv = GET_PRIVATE (self);
GQuark cap_quark;
+ char *capability;
/* FIXME check that there's no collision with service owned capabilities. */
g_return_if_fail (YTS_IS_CLIENT (self));
+ g_return_if_fail (c);
+
+ // TODO error reporting
+ // TODO make sure c doesn't have prefix already
+ capability = g_strdup_printf ("urn:ytstenut:capabilities:%s", c);
cap_quark = g_quark_from_string (capability);
if (yts_client_has_capability (self, cap_quark))
@@ -2926,6 +2937,8 @@ yts_client_add_capability (YtsClient *self,
g_array_append_val (priv->caps, cap_quark);
yts_client_refresh_roster (self);
+
+ g_free (capability);
}
/**
@@ -3126,18 +3139,20 @@ yts_client_set_status (YtsClient *self, YtsStatus *status)
*/
void
yts_client_set_status_by_capability (YtsClient *self,
- char const *capability,
+ char const *c,
char const *activity)
{
YtsClientPrivate *priv = GET_PRIVATE (self);
YtsStatus *status = NULL;
- g_return_if_fail (YTS_IS_CLIENT (self) && capability);
+ g_return_if_fail (YTS_IS_CLIENT (self) && c);
+ g_return_if_fail (c);
g_return_if_fail (priv->caps && priv->caps->len);
if (activity)
{
+ char *capability = g_strdup_printf ("urn:ytstenut:capabilities:%s", c);
char const *attributes[] =
{
"capability", capability,
@@ -3150,6 +3165,7 @@ yts_client_set_status_by_capability (YtsClient *self,
capability, activity, priv->service_id);
status = yts_status_new ((char const**)&attributes);
+ g_free (capability);
}
yts_client_set_status (self, status);