summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorVivek Dasmohapatra <vivek@collabora.co.uk>2009-08-04 19:05:51 +0100
committerVivek Dasmohapatra <vivek@collabora.co.uk>2009-08-12 14:57:21 +0100
commitc51cc014131ccf6018debbf4fe42c23b466f1d2b (patch)
tree461322a9064376ee38d6ced28be5d367110355f6 /examples
parent6ab62ee512532ff31bc387bed87a1a6c5744be3d (diff)
downloadwocky-c51cc014131ccf6018debbf4fe42c23b466f1d2b.tar.gz
Example registration and unregistration binaries.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am15
-rw-r--r--examples/register.c80
-rw-r--r--examples/unregister.c76
3 files changed, 170 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index e9c9fdb..337d088 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,7 +1,18 @@
EXAMPLES =
EXAMPLES += wocky-connect
+EXAMPLES += wocky-register
+EXAMPLES += wocky-unregister
+
wocky_connect_SOURCES = connect.c
+wocky_connect_DEPENDENCIES = $(top_builddir)/wocky/libwocky.la
+
+wocky_register_SOURCES = register.c
+wocky_register_DEPENDENCIES = $(top_builddir)/wocky/libwocky.la
+
+wocky_unregister_SOURCES = unregister.c
+wocky_unregister_DEPENDENCIES = $(top_builddir)/wocky/libwocky.la
+
LDADD = \
@GLIB_LIBS@ \
@@ -11,7 +22,9 @@ AM_CFLAGS = \
$(ERROR_CFLAGS) \
@GLIB_CFLAGS@
-check_c_sources = $(wocky_connect_SOURCES)
+check_c_sources = $(wocky_connect_SOURCES) \
+ $(wocky_register_SOURCES) \
+ $(wocky_unregister_SOURCES)
include $(top_srcdir)/tools/check-coding-style.mk
check-local: check-coding-style
diff --git a/examples/register.c b/examples/register.c
new file mode 100644
index 0000000..d333079
--- /dev/null
+++ b/examples/register.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+#include <glib.h>
+
+#include <gio/gio.h>
+#include <wocky/wocky-connector.h>
+#include <wocky/wocky-utils.h>
+
+GMainLoop *mainloop;
+
+static void
+connector_callback (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+ gchar *jid = NULL;
+ gchar *sid = NULL;
+ WockyConnector *wcon = WOCKY_CONNECTOR (source);
+ WockyXmppConnection *connection =
+ wocky_connector_connect_finish (wcon, res, &error, &jid, &sid);
+
+ if (connection != NULL)
+ {
+ printf ("connected (%s) [%s]!\n", jid, sid);
+ g_free (sid);
+ g_free (jid);
+ }
+ else
+ {
+ if (error)
+ g_warning ("%s: %d: %s\n",
+ g_quark_to_string (error->domain), error->code, error->message);
+ }
+ g_main_loop_quit (mainloop);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ gchar *jid = NULL;
+ gchar *user = NULL;
+ gchar *host = NULL;
+ gchar *pass = NULL;
+ gchar *email = NULL;
+ WockyConnector *wcon = NULL;
+
+ g_type_init ();
+
+ if ((argc < 4) || (argc > 5))
+ {
+ printf ("Usage: %s <jid> <password> <email> [host]\n", argv[0]);
+ return -1;
+ }
+
+ jid = argv[1];
+ pass = argv[2];
+ email = argv[3];
+ wocky_decode_jid (jid, &user, NULL, NULL);
+
+ if (argc == 5)
+ host = argv[4];
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ if ((host != NULL) && (*host != '\0'))
+ wcon = wocky_connector_new (jid, pass, NULL);
+ else
+ wcon = g_object_new (WOCKY_TYPE_CONNECTOR,
+ "jid" , jid ,
+ "password" , pass,
+ "xmpp-server", host, NULL);
+
+ wocky_connector_register_async (wcon, email, connector_callback, NULL);
+ g_main_loop_run (mainloop);
+
+ return 0;
+}
diff --git a/examples/unregister.c b/examples/unregister.c
new file mode 100644
index 0000000..b754299
--- /dev/null
+++ b/examples/unregister.c
@@ -0,0 +1,76 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+#include <glib.h>
+
+#include <gio/gio.h>
+#include <wocky/wocky-connector.h>
+#include <wocky/wocky-utils.h>
+
+GMainLoop *mainloop;
+int rval = -1;
+
+static void
+unregister_callback (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+ WockyConnector *wcon = WOCKY_CONNECTOR (source);
+ gboolean done = wocky_connector_unregister_finish (wcon, res, &error);
+
+ if (done)
+ {
+ printf ("Unregistered!\n");
+ }
+ else
+ {
+ if (error)
+ g_warning ("Unregistration error: %s: %d: %s\n",
+ g_quark_to_string (error->domain), error->code, error->message);
+ else
+ g_warning ("Unregister failed: No error supplied\n");
+ }
+ g_main_loop_quit (mainloop);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ gchar *jid = NULL;
+ gchar *user = NULL;
+ gchar *host = NULL;
+ gchar *pass = NULL;
+ WockyConnector *wcon = NULL;
+
+ g_type_init ();
+
+ if ((argc < 3) || (argc > 4))
+ {
+ printf ("Usage: %s <jid> <password> [host]\n", argv[0]);
+ return -1;
+ }
+
+ jid = argv[1];
+ pass = argv[2];
+ wocky_decode_jid (jid, &user, NULL, NULL);
+
+ if (argc == 4)
+ host = argv[3];
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ if ((host != NULL) && (*host != '\0'))
+ wcon = wocky_connector_new (jid, pass, NULL);
+ else
+ wcon = g_object_new (WOCKY_TYPE_CONNECTOR,
+ "jid" , jid ,
+ "password" , pass,
+ "xmpp-server", host, NULL);
+
+ wocky_connector_unregister_async (wcon, unregister_callback, NULL);
+ g_main_loop_run (mainloop);
+
+ return rval;
+}