summaryrefslogtreecommitdiff
path: root/src/idle-connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/idle-connection.c')
-rw-r--r--src/idle-connection.c101
1 files changed, 91 insertions, 10 deletions
diff --git a/src/idle-connection.c b/src/idle-connection.c
index 8614d52..9ee8840 100644
--- a/src/idle-connection.c
+++ b/src/idle-connection.c
@@ -27,6 +27,7 @@
#include <time.h>
#include <dbus/dbus-glib.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
#define IDLE_DEBUG_FLAG IDLE_DEBUG_CONNECTION
#include "idle-contact-info.h"
@@ -40,7 +41,7 @@
#include "idle-server-connection.h"
#include "server-tls-manager.h"
-#include "extensions/extensions.h" /* Renaming */
+#include "extensions/extensions.h" /* IRCCommand */
#define DEFAULT_KEEPALIVE_INTERVAL 30 /* sec */
#define MISSED_KEEPALIVES_BEFORE_DISCONNECTING 3
@@ -64,12 +65,14 @@ static void _free_alias_pair(gpointer data, gpointer user_data)
static void _aliasing_iface_init(gpointer, gpointer);
static void _renaming_iface_init(gpointer, gpointer);
+static void irc_command_iface_init(gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE(IdleConnection, idle_connection, TP_TYPE_BASE_CONNECTION,
G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING, _aliasing_iface_init);
G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO, idle_contact_info_iface_init);
- G_IMPLEMENT_INTERFACE(IDLE_TYPE_SVC_CONNECTION_INTERFACE_RENAMING, _renaming_iface_init);
+ G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_RENAMING, _renaming_iface_init);
G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, tp_contacts_mixin_iface_init);
+ G_IMPLEMENT_INTERFACE(IDLE_TYPE_SVC_CONNECTION_INTERFACE_IRC_COMMAND1, irc_command_iface_init);
);
typedef struct _IdleOutputPendingMsg IdleOutputPendingMsg;
@@ -449,7 +452,7 @@ static void idle_connection_finalize (GObject *object) {
static const gchar * interfaces_always_present[] = {
TP_IFACE_CONNECTION_INTERFACE_ALIASING,
TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO,
- IDLE_IFACE_CONNECTION_INTERFACE_RENAMING,
+ TP_IFACE_CONNECTION_INTERFACE_RENAMING,
TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
TP_IFACE_CONNECTION_INTERFACE_CONTACTS,
NULL};
@@ -489,7 +492,6 @@ static void idle_connection_class_init(IdleConnectionClass *klass) {
parent_class->create_handle_repos = _iface_create_handle_repos;
parent_class->get_unique_connection_name = _iface_get_unique_connection_name;
- parent_class->create_channel_factories = NULL;
parent_class->create_channel_managers = _iface_create_channel_managers;
parent_class->connecting = NULL;
parent_class->connected = NULL;
@@ -566,7 +568,7 @@ static GPtrArray *_iface_create_channel_managers(TpBaseConnection *base) {
}
static void _iface_create_handle_repos(TpBaseConnection *self, TpHandleRepoIface **repos) {
- for (int i = 0; i < NUM_TP_HANDLE_TYPES; i++)
+ for (int i = 0; i < TP_NUM_HANDLE_TYPES; i++)
repos[i] = NULL;
idle_handle_repos_init(repos);
@@ -1085,7 +1087,7 @@ static IdleParserHandlerResult _nick_handler(IdleParser *parser, IdleParserMessa
tp_base_connection_set_self_handle(TP_BASE_CONNECTION(conn), new_handle);
}
- idle_svc_connection_interface_renaming_emit_renamed(IDLE_SVC_CONNECTION_INTERFACE_RENAMING(conn), old_handle, new_handle);
+ tp_svc_connection_interface_renaming_emit_renamed(conn, old_handle, new_handle);
idle_connection_emit_queued_aliases_changed(conn);
@@ -1433,11 +1435,15 @@ static gboolean _send_rename_request(IdleConnection *obj, const gchar *nick, DBu
return TRUE;
}
-static void idle_connection_request_rename(IdleSvcConnectionInterfaceRenaming *iface, const gchar *nick, DBusGMethodInvocation *context) {
+static void
+idle_connection_request_rename (TpSvcConnectionInterfaceRenaming *iface,
+ const gchar *nick,
+ DBusGMethodInvocation *context)
+{
IdleConnection *conn = IDLE_CONNECTION(iface);
if (_send_rename_request(conn, nick, context))
- idle_svc_connection_interface_renaming_return_from_request_rename(context);
+ tp_svc_connection_interface_renaming_return_from_request_rename(context);
}
static void idle_connection_set_aliases(TpSvcConnectionInterfaceAliasing *iface, GHashTable *aliases, DBusGMethodInvocation *context) {
@@ -1563,11 +1569,86 @@ static void _aliasing_iface_init(gpointer g_iface, gpointer iface_data) {
}
static void _renaming_iface_init(gpointer g_iface, gpointer iface_data) {
- IdleSvcConnectionInterfaceRenamingClass *klass = (IdleSvcConnectionInterfaceRenamingClass *) g_iface;
+ TpSvcConnectionInterfaceRenamingClass *klass = g_iface;
-#define IMPLEMENT(x) idle_svc_connection_interface_renaming_implement_##x (\
+#define IMPLEMENT(x) tp_svc_connection_interface_renaming_implement_##x (\
klass, idle_connection_##x)
IMPLEMENT(request_rename);
#undef IMPLEMENT
}
+typedef struct
+{
+ const gchar *command;
+ const gchar *error_msg;
+} IrcCommandCheck;
+
+static const IrcCommandCheck commands[] = {
+ { "INVITE", "Use the Group API on room channels" },
+ { "JOIN", "Use the Group API on room channels" },
+ { "KICK", "Use the Group API on room channels" },
+ { "PART", "Use the Group API on room channels" },
+ { "PRIVMSG", "Use text channels" },
+ { "QUIT", "Disconnect the connection" },
+ { "TOPIC", "Use the Subject API on room channels" },
+ { NULL, NULL }
+};
+
+/* Return FALSE and set @error if @command is not meant to be used with
+ * IRC_Command.Send() as we have proper Telepathy API for it. */
+static gboolean
+check_irc_command (IdleConnection *self,
+ const gchar *full_command,
+ GError **error)
+{
+ gchar **splitted;
+ guint i;
+
+ splitted = g_strsplit (full_command, " ", 0);
+
+ for (i = 0; commands[i].command != NULL; i++)
+ {
+ if (g_ascii_strcasecmp (splitted[0], commands[i].command) == 0)
+ {
+ g_set_error_literal (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+ commands[i].error_msg);
+
+ g_strfreev (splitted);
+ return FALSE;
+ }
+ }
+
+ g_strfreev (splitted);
+ return TRUE;
+}
+
+static void
+idle_connection_irc_command_send (IdleSvcConnectionInterfaceIRCCommand1 *iface,
+ const gchar *command,
+ DBusGMethodInvocation *context)
+{
+ IdleConnection *self = IDLE_CONNECTION(iface);
+ GError *error = NULL;
+
+ if (!check_irc_command (self, command, &error))
+ {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ return;
+ }
+
+ _send_with_priority (self, command, SERVER_CMD_NORMAL_PRIORITY);
+
+ dbus_g_method_return (context);
+}
+
+static void irc_command_iface_init(gpointer g_iface,
+ gpointer iface_data)
+{
+ IdleSvcConnectionInterfaceIRCCommand1Class *klass = g_iface;
+
+#define IMPLEMENT(x) idle_svc_connection_interface_irc_command1_implement_##x (\
+ klass, idle_connection_irc_command_##x)
+ IMPLEMENT(send);
+#undef IMPLEMENT
+}