diff options
author | Joe Barnett <jbarnett@stanfordalumni.org> | 2012-04-13 09:30:16 -0700 |
---|---|---|
committer | Joe Barnett <jbarnett@stanfordalumni.org> | 2012-04-13 09:30:16 -0700 |
commit | 8c5e3938b129358bde1023e884aa4451eb085000 (patch) | |
tree | c813b6f93353b6bcdca38003cfb0d8e4f3cfd2ae | |
parent | 10701fb72fb8acbe15127818df0715e44cf9bb3a (diff) |
more muc-manager impl'ed, still not listing channels yet though
-rw-r--r-- | src/kindling-connection.c | 72 | ||||
-rw-r--r-- | src/kindling-connection.h | 4 | ||||
-rw-r--r-- | src/kindling-muc-manager.c | 102 |
3 files changed, 169 insertions, 9 deletions
diff --git a/src/kindling-connection.c b/src/kindling-connection.c index 7c77fc8..bb072ef 100644 --- a/src/kindling-connection.c +++ b/src/kindling-connection.c @@ -117,14 +117,57 @@ static void _soup_authenticate_cb(SoupSession *session, SoupAuth *auth, gboolean retrying, gpointer user_data) { - g_printf("soup authenitcate\n"); KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(user_data); if (!retrying) { - soup_auth_authenticate(auth, priv->username, priv->password); + if (priv->api_token != NULL) { + g_printf("soup authenitcate with token\n"); + soup_auth_authenticate (auth, priv->api_token, "x"); + } else { + g_printf("soup authenitcate with username\n"); + soup_auth_authenticate(auth, priv->username, priv->password); + } } } +static GQuark _canon_nick_quark() { + static GQuark quark = 0; + + if (!quark) { + quark = g_quark_from_static_string ("canon-nick"); + } + return quark; +} + +static const gchar *gimme_an_alias (TpHandleRepoIface *repo, TpHandle handle) { + const char *alias = tp_handle_get_qdata (repo, handle, _canon_nick_quark()); + + if (alias != NULL) { + return alias; + } else { + return tp_handle_inspect(repo, handle); + } +} + + +static void conn_aliasing_fill_contact_attributes(GObject *obj, + const GArray *contacts, + GHashTable *attributes_hash) { + KindlingConnection *self = KINDLING_CONNECTION(obj); + TpHandleRepoIface *repo = tp_base_connection_get_handles (TP_BASE_CONNECTION(self), TP_HANDLE_TYPE_CONTACT); + guint i; + + for (i = 0; i < contacts->len; i++) { + TpHandle handle = g_array_index(contacts, TpHandle, i); + const gchar *alias = gimme_an_alias(repo, handle); + g_assert(alias != NULL); + tp_contacts_mixin_set_contact_attribute (attributes_hash, + handle, + TP_IFACE_CONNECTION_INTERFACE_ALIASING"/alias", + tp_g_value_slice_new_string (alias)); + } +} + static void kindling_connection_constructed (GObject *object) { g_printf("connection constructed\n"); KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(object); @@ -134,7 +177,9 @@ static void kindling_connection_constructed (GObject *object) { "authenticate", _soup_authenticate_cb, object); - /* TODO: Add initialization code here */ + tp_contacts_mixin_add_contact_attributes_iface (object, + TP_IFACE_CONNECTION_INTERFACE_ALIASING, + conn_aliasing_fill_contact_attributes); } static void @@ -177,7 +222,7 @@ static GPtrArray *_iface_create_channel_managers(TpBaseConnection *self) { 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, - // "connection", self, + "connection", self, NULL)); priv->password_manager = tp_simple_password_manager_new(self); g_ptr_array_add(managers, priv->password_manager); @@ -200,6 +245,19 @@ _soup_get_user_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { KindlingConnection *conn = KINDLING_CONNECTION(user_data); TpBaseConnection *base_conn = TP_BASE_CONNECTION(conn); KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(conn); + if (msg->status_code != 200) { + if (base_conn->status != TP_CONNECTION_STATUS_DISCONNECTED) { + GError *error = g_error_new(TP_ERRORS, TP_ERROR_PERMISSION_DENIED, "non 200 status code %d", msg->status_code); + + _connection_disconnect_with_gerror(conn, + TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED, + "debug-message", + error); + g_error_free(error); + + } + return; + } JsonParser *parser = json_parser_new(); GError *error = NULL; json_parser_load_from_data(parser, msg->response_body->data, -1, &error); @@ -225,7 +283,7 @@ _soup_get_user_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { if (priv->api_token == NULL) { if (base_conn->status != TP_CONNECTION_STATUS_DISCONNECTED) { - GError *error = g_error_new_literal(TP_ERRORS, 1, "no api token"); + GError *error = g_error_new(TP_ERRORS, TP_ERROR_PERMISSION_DENIED, "no api token"); _connection_disconnect_with_gerror(conn, TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED, @@ -285,6 +343,7 @@ static gboolean _iface_start_connecting(TpBaseConnection *self, GError **error) KindlingConnectionPrivate *priv = KINDLING_CONNECTION_GET_PRIVATE(self); TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (self, TP_HANDLE_TYPE_CONTACT); self->self_handle = tp_handle_ensure(contact_handles, priv->username, NULL, error); + g_printf("connecting with self handle %d\n", self->self_handle); if (!self->self_handle) { return FALSE; } @@ -299,6 +358,7 @@ static gboolean _iface_start_connecting(TpBaseConnection *self, GError **error) static void _iface_shut_down(TpBaseConnection *self) { g_printf("connection shut down\n"); + tp_base_connection_finish_shutdown(self); } static void _print_status_cb (TpBaseConnection *self) { @@ -335,5 +395,7 @@ kindling_connection_class_init (KindlingConnectionClass *klass) g_object_class_install_property (object_class, PROP_USERNAME, param_spec); param_spec = g_param_spec_string ("password", "password", "campfire password to auth with",NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_PASSWORD, param_spec); + + tp_contacts_mixin_class_init (object_class, G_STRUCT_OFFSET (KindlingConnectionClass, contacts)); } diff --git a/src/kindling-connection.h b/src/kindling-connection.h index ef188bb..92d237f 100644 --- a/src/kindling-connection.h +++ b/src/kindling-connection.h @@ -47,9 +47,7 @@ struct _KindlingConnectionClass struct _KindlingConnection { TpBaseConnection parent_instance; - TpContactsMixin contacts; - - + TpContactsMixin contacts; }; GType kindling_connection_get_type (void) G_GNUC_CONST; diff --git a/src/kindling-muc-manager.c b/src/kindling-muc-manager.c index af950e0..7003fe4 100644 --- a/src/kindling-muc-manager.c +++ b/src/kindling-muc-manager.c @@ -19,6 +19,10 @@ telepathy-kindling is free software: you can redistribute it and/or modify it #include "kindling-muc-manager.h" #include <telepathy-glib/channel-manager.h> +#include <telepathy-glib/interfaces.h> +#include <telepathy-glib/util.h> +#include <telepathy-glib/handle.h> +#include "kindling-connection.h" static void _muc_manager_iface_init(gpointer, gpointer); @@ -26,6 +30,43 @@ static void _muc_manager_iface_init(gpointer, gpointer); G_DEFINE_TYPE_WITH_CODE (KindlingMUCManager, kindling_muc_manager, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(TP_TYPE_CHANNEL_MANAGER, _muc_manager_iface_init)); + +enum { + PROP_CONNECTION = 1, + LAST_PROPERTY_ENUM +}; + +typedef struct _KindlingMUCManagerPrivate KindlingMUCManagerPrivate; +struct _KindlingMUCManagerPrivate { + KindlingConnection *conn; + GHashTable *channels; +}; + +#define KINDLING_MUC_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), KINDLING_TYPE_MUC_MANAGER, KindlingMUCManagerPrivate)) + +static void kindling_muc_manager_set_property(GObject *obj, guint prop_id, const GValue *value, GParamSpec *pspec) { + g_printf("muc-manager set prop %d\n", prop_id); + KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(obj); + switch (prop_id) { + case PROP_CONNECTION: + priv->conn = g_value_get_object(value); + break; + } +} + +static void kindling_muc_manager_get_property(GObject *obj, guint prop_id, GValue *value, GParamSpec *pspec) { + g_printf("muc-manager get prop %d\n", prop_id); + KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(obj); + switch (prop_id) { + case PROP_CONNECTION: + g_value_set_object(value, priv->conn); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); + break; + } + +} static void kindling_muc_manager_init (KindlingMUCManager *kindling_muc_manager) { @@ -34,6 +75,7 @@ kindling_muc_manager_init (KindlingMUCManager *kindling_muc_manager) /* TODO: Add initialization code here */ } + static void kindling_muc_manager_finalize (GObject *object) { @@ -43,17 +85,75 @@ kindling_muc_manager_finalize (GObject *object) G_OBJECT_CLASS (kindling_muc_manager_parent_class)->finalize (object); } + +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", + NULL +}; + +static void kindling_muc_manager_type_foreach_channel_class(GType type, TpChannelManagerTypeChannelClassFunc func, gpointer data) { + g_printf("foreach type channel class\n"); + 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; + + channel_type_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_static_string (channel_type_value, TP_IFACE_CHANNEL_TYPE_TEXT); + g_hash_table_insert (table, TP_IFACE_CHANNEL ".ChannelType", channel_type_value); + + handle_type_value = tp_g_value_slice_new (G_TYPE_UINT); + g_value_set_uint(handle_type_value, TP_HANDLE_TYPE_ROOM); + g_hash_table_insert(table, TP_IFACE_CHANNEL ".TargetHandleType", handle_type_value); + + func (type, table, muc_channel_allowed_properties, data); + g_hash_table_destroy(table); +} + +static void kindling_muc_manager_ensure_channel(TpChannelManager *manager, + gpointer request_token, + GHashTable *request_properties) { + g_printf("ensure channel\n"); +} + +static void kindling_muc_manager_request_channel(TpChannelManager *manager, + gpointer request_token, + GHashTable *request_properties) { + g_printf("request channel\n"); +} + +static void kindling_muc_manager_create_channel(TpChannelManager *manager, + gpointer request_token, + GHashTable *request_properties) { + g_printf("create channel\n"); +} + static void kindling_muc_manager_class_init (KindlingMUCManagerClass *klass) { g_printf("class init kindling muc manager\n"); GObjectClass* object_class = G_OBJECT_CLASS (klass); GObjectClass* parent_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + g_type_class_add_private (klass, sizeof(KindlingMUCManagerPrivate)); + + object_class->set_property = kindling_muc_manager_set_property; + 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); + g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); } - static void _muc_manager_iface_init(gpointer g_iface, gpointer iface_data) { g_printf("iface init kindling muc manager\n"); TpChannelManagerIface *iface = g_iface; + iface->foreach_channel = kindling_muc_manager_foreach_channel; + iface->type_foreach_channel_class = kindling_muc_manager_type_foreach_channel_class; + iface->ensure_channel = kindling_muc_manager_ensure_channel; + iface->request_channel = kindling_muc_manager_request_channel; + iface->create_channel = kindling_muc_manager_create_channel; } |