# HG changeset patch
# Node ID 4240d744800c
# Parent  c47df057a426
diff --git a/libpurple/protocols/demo/meson.build b/libpurple/protocols/demo/meson.build
--- a/libpurple/protocols/demo/meson.build
+++ b/libpurple/protocols/demo/meson.build
@@ -5,6 +5,10 @@ DEMO_SOURCES = [
 	'purpledemoplugin.h',
 	'purpledemoprotocol.c',
 	'purpledemoprotocol.h',
+	'purpledemoprotocolclient.c',
+	'purpledemoprotocolclient.h',
+	'purpledemoprotocolim.c',
+	'purpledemoprotocolim.h',
 ]
 
 if DYNAMIC_DEMO
diff --git a/libpurple/protocols/demo/purpledemoprotocol.c b/libpurple/protocols/demo/purpledemoprotocol.c
--- a/libpurple/protocols/demo/purpledemoprotocol.c
+++ b/libpurple/protocols/demo/purpledemoprotocol.c
@@ -21,6 +21,8 @@
 #include <glib/gi18n-lib.h>
 
 #include "purpledemoprotocol.h"
+#include "purpledemoprotocolclient.h"
+#include "purpledemoprotocolim.h"
 
 #include "purpledemocontacts.h"
 
@@ -29,98 +31,6 @@ struct _PurpleDemoProtocol {
 };
 
 /******************************************************************************
- * 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 *
-purple_demo_protocol_status_text(PurpleProtocolClient *client,
-                                 PurpleBuddy *buddy)
-{
-	PurplePresence *presence = NULL;
-	PurpleStatus *status = NULL;
-	const gchar *message = NULL;
-	gchar *ret = NULL;
-
-	presence = purple_buddy_get_presence(buddy);
-	status = purple_presence_get_active_status(presence);
-
-	message = purple_status_get_attr_string(status, "message");
-	if(message != NULL) {
-		ret = g_markup_escape_text(message, -1);
-		purple_util_chrreplace(ret, '\n', ' ');
-	}
-
-	return ret;
-}
-
-static void
-purple_demo_protocol_client_init(PurpleProtocolClientInterface *iface) {
-	iface->status_text = purple_demo_protocol_status_text;
-}
-
-/******************************************************************************
  * PurpleProtocol Implementation
  *****************************************************************************/
 static void
@@ -171,7 +81,7 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED(
 	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
diff --git a/libpurple/protocols/demo/purpledemoprotocolclient.h b/libpurple/protocols/demo/purpledemoprotocolclient.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolclient.h
@@ -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_CLIENT_H
+#define PURPLE_DEMO_PROTOCOL_CLIENT_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_GNUC_INTERNAL void purple_demo_protocol_client_init(PurpleProtocolClientInterface *iface);
+
+#endif /* PURPLE_DEMO_PROTOCOL_CLIENT_H */
diff --git a/libpurple/protocols/demo/purpledemoprotocolclient.c b/libpurple/protocols/demo/purpledemoprotocolclient.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolclient.c
@@ -0,0 +1,51 @@
+/*
+ * 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 "purpledemoprotocolclient.h"
+
+/******************************************************************************
+ * PurpleProtocolClient Implementation
+ *****************************************************************************/
+static gchar *
+purple_demo_protocol_status_text(PurpleProtocolClient *client,
+                                 PurpleBuddy *buddy)
+{
+	PurplePresence *presence = NULL;
+	PurpleStatus *status = NULL;
+	const gchar *message = NULL;
+	gchar *ret = NULL;
+
+	presence = purple_buddy_get_presence(buddy);
+	status = purple_presence_get_active_status(presence);
+
+	message = purple_status_get_attr_string(status, "message");
+	if(message != NULL) {
+		ret = g_markup_escape_text(message, -1);
+		purple_util_chrreplace(ret, '\n', ' ');
+	}
+
+	return ret;
+}
+
+void
+purple_demo_protocol_client_init(PurpleProtocolClientInterface *iface) {
+	iface->status_text = purple_demo_protocol_status_text;
+}
diff --git a/libpurple/protocols/demo/purpledemoprotocolim.h b/libpurple/protocols/demo/purpledemoprotocolim.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolim.h
@@ -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 */
diff --git a/libpurple/protocols/demo/purpledemoprotocolim.c b/libpurple/protocols/demo/purpledemoprotocolim.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolim.c
@@ -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;
+}
