Split apart the demo's PurpleProtocolIM implementation

Sat, 12 Mar 2022 23:00:44 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Sat, 12 Mar 2022 23:00:44 -0600
changeset 41284
7b29786ffdc7
parent 41283
8da781550c96
child 41285
cc3c735c14f4

Split apart the demo's PurpleProtocolIM implementation

libpurple/protocols/demo/meson.build file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocol.c file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocolim.c file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocolim.h file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/demo/meson.build	Sat Mar 12 20:22:26 2022 -0600
+++ b/libpurple/protocols/demo/meson.build	Sat Mar 12 23:00:44 2022 -0600
@@ -5,6 +5,8 @@
 	'purpledemoplugin.h',
 	'purpledemoprotocol.c',
 	'purpledemoprotocol.h',
+	'purpledemoprotocolim.c',
+	'purpledemoprotocolim.h',
 ]
 
 if DYNAMIC_DEMO
--- a/libpurple/protocols/demo/purpledemoprotocol.c	Sat Mar 12 20:22:26 2022 -0600
+++ b/libpurple/protocols/demo/purpledemoprotocol.c	Sat Mar 12 23:00:44 2022 -0600
@@ -21,6 +21,7 @@
 #include <glib/gi18n-lib.h>
 
 #include "purpledemoprotocol.h"
+#include "purpledemoprotocolim.h"
 
 #include "purpledemocontacts.h"
 
@@ -29,69 +30,6 @@
 };
 
 /******************************************************************************
- * PurpleProtocolIM Implementation
- *****************************************************************************/
-typedef struct {
-	PurpleConnection *connection;
-	PurpleMessage *message;
-} PurpleDemoProtocolIMInfo;
-
-static void
-purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
-	g_object_unref(info->message);
-	g_free(info);
-}
-
-static gboolean
-purple_demo_protocol_echo_im_cb(gpointer data)
-{
-	PurpleDemoProtocolIMInfo *info = data;
-	const char *who = NULL;
-	PurpleMessageFlags flags;
-	GDateTime *timestamp = NULL;
-
-	/* Turn outgoing message back incoming. */
-	who = purple_message_get_recipient(info->message);
-	flags = purple_message_get_flags(info->message);
-	flags &= ~PURPLE_MESSAGE_SEND;
-	flags |= PURPLE_MESSAGE_RECV;
-	timestamp = purple_message_get_timestamp(info->message);
-
-	purple_serv_got_im(info->connection, who,
-	                   purple_message_get_contents(info->message), flags,
-	                   g_date_time_to_unix(timestamp));
-
-	g_date_time_unref(timestamp);
-
-	return FALSE;
-}
-
-static gint
-purple_demo_protocol_send_im(PurpleProtocolIM *im, PurpleConnection *conn,
-                             PurpleMessage *msg)
-{
-	const gchar *who = purple_message_get_recipient(msg);
-
-	if(purple_strequal(who, "Echo")) {
-		PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
-
-		info->connection = conn;
-		info->message = g_object_ref(msg);
-
-		g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
-		                purple_demo_protocol_echo_im_cb, info,
-		                (GDestroyNotify)purple_demo_protocol_im_info_free);
-	}
-
-	return 1;
-}
-
-static void
-purple_demo_protocol_im_iface_init(PurpleProtocolIMInterface *iface) {
-	iface->send = purple_demo_protocol_send_im;
-}
-
-/******************************************************************************
  * PurpleProtocolClient Implementation
  *****************************************************************************/
 static gchar *
@@ -171,7 +109,7 @@
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT,
 	                              purple_demo_protocol_client_init)
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
-	                              purple_demo_protocol_im_iface_init)
+	                              purple_demo_protocol_im_init)
 )
 
 static void
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/demo/purpledemoprotocolim.c	Sat Mar 12 23:00:44 2022 -0600
@@ -0,0 +1,85 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "purpledemoprotocol.h"
+#include "purpledemoprotocolim.h"
+
+/******************************************************************************
+ * PurpleProtocolIM Implementation
+ *****************************************************************************/
+typedef struct {
+	PurpleConnection *connection;
+	PurpleMessage *message;
+} PurpleDemoProtocolIMInfo;
+
+static void
+purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
+	g_object_unref(info->message);
+	g_free(info);
+}
+
+static gboolean
+purple_demo_protocol_echo_im_cb(gpointer data)
+{
+	PurpleDemoProtocolIMInfo *info = data;
+	const char *who = NULL;
+	PurpleMessageFlags flags;
+	GDateTime *timestamp = NULL;
+
+	/* Turn outgoing message back incoming. */
+	who = purple_message_get_recipient(info->message);
+	flags = purple_message_get_flags(info->message);
+	flags &= ~PURPLE_MESSAGE_SEND;
+	flags |= PURPLE_MESSAGE_RECV;
+	timestamp = purple_message_get_timestamp(info->message);
+
+	purple_serv_got_im(info->connection, who,
+	                   purple_message_get_contents(info->message), flags,
+	                   g_date_time_to_unix(timestamp));
+
+	g_date_time_unref(timestamp);
+
+	return FALSE;
+}
+
+static gint
+purple_demo_protocol_send_im(PurpleProtocolIM *im, PurpleConnection *conn,
+                             PurpleMessage *msg)
+{
+	const gchar *who = purple_message_get_recipient(msg);
+
+	if(purple_strequal(who, "Echo")) {
+		PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
+
+		info->connection = conn;
+		info->message = g_object_ref(msg);
+
+		g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+		                purple_demo_protocol_echo_im_cb, info,
+		                (GDestroyNotify)purple_demo_protocol_im_info_free);
+	}
+
+	return 1;
+}
+
+void
+purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface) {
+	iface->send = purple_demo_protocol_send_im;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/demo/purpledemoprotocolim.h	Sat Mar 12 23:00:44 2022 -0600
@@ -0,0 +1,28 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef PURPLE_DEMO_PROTOCOL_IM_H
+#define PURPLE_DEMO_PROTOCOL_IM_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_GNUC_INTERNAL void purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface);
+
+#endif /* PURPLE_DEMO_PROTOCOL_IM_H */

mercurial