summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Barnett <jbarnett@stanfordalumni.org>2012-04-26 14:11:11 -0700
committerJoe Barnett <jbarnett@stanfordalumni.org>2012-04-26 14:11:11 -0700
commit0ffd3c6d1f21c269e76c39f8a54eb3667ec2c9eb (patch)
treeb2632406e4f0aa306f17124827779d955b5c4634
parent8c5e3938b129358bde1023e884aa4451eb085000 (diff)
poll for channel list, but don't do anything with the result, and
also not sure how to get foreach_channel to be called after the result comes back?
-rw-r--r--src/kindling-connection.c39
-rw-r--r--src/kindling-connection.h3
-rw-r--r--src/kindling-muc-manager.c43
-rw-r--r--src/kindling-muc-manager.h3
4 files changed, 77 insertions, 11 deletions
diff --git a/src/kindling-connection.c b/src/kindling-connection.c
index bb072ef..96e5931 100644
--- a/src/kindling-connection.c
+++ b/src/kindling-connection.c
@@ -55,10 +55,13 @@ struct _KindlingConnectionPrivate {
char *password;
char *api_token;
+ KindlingMUCManager *muc_manager;
+
//for actual auth
TpSimplePasswordManager *password_manager;
SoupSession *soup_session;
gulong soup_auth_cb_handle;
+ guint auth_retries;
};
#define KINDLING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), KINDLING_TYPE_CONNECTION, KindlingConnectionPrivate))
@@ -118,7 +121,7 @@ static void _soup_authenticate_cb(SoupSession *session,
gboolean retrying,
gpointer user_data) {
KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(user_data);
- if (!retrying) {
+ if (!retrying || priv->auth_retries == 0) {
if (priv->api_token != NULL) {
g_printf("soup authenitcate with token\n");
soup_auth_authenticate (auth, priv->api_token, "x");
@@ -126,6 +129,8 @@ static void _soup_authenticate_cb(SoupSession *session,
g_printf("soup authenitcate with username\n");
soup_auth_authenticate(auth, priv->username, priv->password);
}
+ } else {
+ g_printf("not retrying auth\n");
}
}
@@ -171,6 +176,7 @@ static void conn_aliasing_fill_contact_attributes(GObject *obj,
static void kindling_connection_constructed (GObject *object) {
g_printf("connection constructed\n");
KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(object);
+ priv->auth_retries = 0;
priv->soup_session = soup_session_async_new();
priv->soup_auth_cb_handle = g_signal_connect(priv->soup_session,
@@ -221,9 +227,10 @@ static GPtrArray *_iface_create_channel_managers(TpBaseConnection *self) {
g_printf("connection create chan manager\n");
KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(self);
GPtrArray *managers = g_ptr_array_sized_new (1);
- g_ptr_array_add (managers, g_object_new (KINDLING_TYPE_MUC_MANAGER,
+ priv->muc_manager = g_object_new (KINDLING_TYPE_MUC_MANAGER,
"connection", self,
- NULL));
+ NULL);
+ g_ptr_array_add (managers, priv->muc_manager);
priv->password_manager = tp_simple_password_manager_new(self);
g_ptr_array_add(managers, priv->password_manager);
return managers;
@@ -278,6 +285,7 @@ _soup_get_user_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) {
json_reader_read_member (reader, "api_auth_token");
g_free(priv->api_token);
priv->api_token = g_strdup(json_reader_get_string_value(reader));
+ priv->auth_retries = 0; // reset so we reauthenticate
g_object_unref (reader);
g_object_unref (parser);
@@ -310,6 +318,15 @@ static void _start_connecting_continue(KindlingConnection *self) {
soup_session_queue_message(priv->soup_session, msg, _soup_get_user_cb, self);
}
+void kindling_connection_list_rooms(KindlingConnection *self, SoupSessionCallback cb, gpointer data) {
+ KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(self);
+ gchar *message = g_strdup_printf("https://%s.campfirenow.com/rooms.json", priv->server);
+ g_printf("getting room list at %s\n", message);
+ SoupMessage *msg = soup_message_new("GET", message);
+ g_free(message);
+ soup_session_queue_message(priv->soup_session, msg, cb, data);
+}
+
static void _password_prompt_cb (GObject *source, GAsyncResult *result, gpointer user_data) {
g_printf("prompt cb\n");
KindlingConnection *conn = KINDLING_CONNECTION(user_data);
@@ -365,6 +382,18 @@ static void _print_status_cb (TpBaseConnection *self) {
g_printf("Status is : %d\n", self->status);
}
+static void _connected_cb (TpBaseConnection *self) {
+ g_printf("Status is : %d (connected) \n", self->status);
+ KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(self);
+ kindling_muc_manager_connected(priv->muc_manager);
+}
+
+static void _disconnected_cb (TpBaseConnection *self) {
+ g_printf("Status is : %d (disconnected) \n", self->status);
+ KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(self);
+ kindling_muc_manager_disconnected(priv->muc_manager);
+}
+
static void
kindling_connection_class_init (KindlingConnectionClass *klass)
{
@@ -386,8 +415,8 @@ kindling_connection_class_init (KindlingConnectionClass *klass)
parent_class->shut_down = _iface_shut_down;
parent_class->interfaces_always_present = interfaces_always_present;
parent_class->connecting = _print_status_cb;
- parent_class->connected = _print_status_cb;
- parent_class->disconnected = _print_status_cb;
+ parent_class->connected = _connected_cb;
+ parent_class->disconnected = _disconnected_cb;
param_spec = g_param_spec_string ("server", "server", "campfire server to connect to",NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_SERVER, param_spec);
diff --git a/src/kindling-connection.h b/src/kindling-connection.h
index 92d237f..380e37f 100644
--- a/src/kindling-connection.h
+++ b/src/kindling-connection.h
@@ -23,6 +23,7 @@ telepathy-kindling is free software: you can redistribute it and/or modify it
#include <glib-object.h>
#include <telepathy-glib/base-protocol.h>
#include <telepathy-glib/contacts-mixin.h>
+#include <libsoup/soup.h>
G_BEGIN_DECLS
@@ -52,7 +53,7 @@ struct _KindlingConnection
GType kindling_connection_get_type (void) G_GNUC_CONST;
const gchar * const *kindling_connection_get_implemented_interfaces (void);
-
+void kindling_connection_list_rooms(KindlingConnection *self, SoupSessionCallback cb, gpointer data);
G_END_DECLS
#endif /* _KINDLING_CONNECTION_H_ */
diff --git a/src/kindling-muc-manager.c b/src/kindling-muc-manager.c
index 7003fe4..6ed565d 100644
--- a/src/kindling-muc-manager.c
+++ b/src/kindling-muc-manager.c
@@ -40,6 +40,7 @@ typedef struct _KindlingMUCManagerPrivate KindlingMUCManagerPrivate;
struct _KindlingMUCManagerPrivate {
KindlingConnection *conn;
GHashTable *channels;
+ guint timeout_id;
};
#define KINDLING_MUC_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), KINDLING_TYPE_MUC_MANAGER, KindlingMUCManagerPrivate))
@@ -51,6 +52,9 @@ static void kindling_muc_manager_set_property(GObject *obj, guint prop_id, const
case PROP_CONNECTION:
priv->conn = g_value_get_object(value);
break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
+ break;
}
}
@@ -84,20 +88,49 @@ kindling_muc_manager_finalize (GObject *object)
G_OBJECT_CLASS (kindling_muc_manager_parent_class)->finalize (object);
}
+static void
+_list_channels_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) {
+ g_printf("got room list:\n\t%s\n",msg->response_body->data);
+}
+static gboolean _poll_channels_cb (gpointer data) {
+ KindlingMUCManager *manager = KINDLING_MUC_MANAGER(data);
+ KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(manager);
+ KindlingConnection *conn = priv->conn;
+ g_printf("polling for channels\n");
+ kindling_connection_list_rooms (conn, _list_channels_cb, manager);
+ return TRUE;
+}
+void kindling_muc_manager_connected(KindlingMUCManager *manager) {
+ KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(manager);
+ _poll_channels_cb(manager);
+ priv->timeout_id = g_timeout_add_seconds (300, _poll_channels_cb, manager);
+}
+
+void kindling_muc_manager_disconnected(KindlingMUCManager *manager) {
+ KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(manager);
+ g_source_remove (priv->timeout_id);
+}
static void kindling_muc_manager_foreach_channel(TpChannelManager *manager, TpExportableChannelFunc func, gpointer data) {
g_printf("foreach channel\n");
}
-static const gchar * const muc_channel_allowed_properties[] = {
- TP_IFACE_CHANNEL ".TargetHandle",
- TP_IFACE_CHANNEL ".TargetID",
+static const gchar * const muc_channel_allowed_properties[] = {
+ TP_PROP_CHANNEL_TARGET_HANDLE,
+ TP_PROP_CHANNEL_TARGET_ID,
+ TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_CHANNELS,
+ TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_INVITEE_HANDLES,
+ TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INITIAL_INVITEE_IDS,
+ TP_PROP_CHANNEL_INTERFACE_CONFERENCE_INVITATION_MESSAGE,
+ TP_PROP_CHANNEL_INTERFACE_ROOM_ROOM_NAME,
+ TP_PROP_CHANNEL_INTERFACE_ROOM_SERVER,
+
NULL
};
static void kindling_muc_manager_type_foreach_channel_class(GType type, TpChannelManagerTypeChannelClassFunc func, gpointer data) {
- g_printf("foreach type channel class\n");
+ g_printf("foreach type channel class %s\n", g_type_name (type));
GHashTable *table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)tp_g_value_slice_free);
GValue *channel_type_value, *handle_type_value;
@@ -145,7 +178,7 @@ kindling_muc_manager_class_init (KindlingMUCManagerClass *klass)
object_class->get_property = kindling_muc_manager_get_property;
object_class->finalize = kindling_muc_manager_finalize;
- param_spec = g_param_spec_string ("connection", "connection", "kindling connection",NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ param_spec = g_param_spec_object ("connection", "connection", "kindling connection", KINDLING_TYPE_CONNECTION, G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
}
static void _muc_manager_iface_init(gpointer g_iface, gpointer iface_data) {
diff --git a/src/kindling-muc-manager.h b/src/kindling-muc-manager.h
index 5a9d357..97472b3 100644
--- a/src/kindling-muc-manager.h
+++ b/src/kindling-muc-manager.h
@@ -50,6 +50,9 @@ struct _KindlingMUCManager
GType kindling_muc_manager_get_type (void) G_GNUC_CONST;
+void kindling_muc_manager_connected(KindlingMUCManager *manager);
+void kindling_muc_manager_disconnected(KindlingMUCManager *manager);
+
G_END_DECLS
#endif /* _KINDLING_MUC_MANAGER_H_ */