libpurple/purpleprotocolconversation.c

Tue, 12 Sep 2023 01:46:27 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 12 Sep 2023 01:46:27 -0500
changeset 42319
98931e2d3ca2
child 42325
9e5c583e13de
permissions
-rw-r--r--

Create the initial PurpleProtocolConversation

This interface will handle all protocol interactions for conversations now that
we are flattening their object hierarchy.

Testing Done:
Ran the unit tests under valgrind.

Reviewed at https://reviews.imfreedom.org/r/2611/

42319
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpleprotocolconversation.h"
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /******************************************************************************
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 * GInterface Implementation
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 *****************************************************************************/
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 G_DEFINE_INTERFACE(PurpleProtocolConversation, purple_protocol_conversation,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 PURPLE_TYPE_PROTOCOL)
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 static void
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 purple_protocol_conversation_default_init(G_GNUC_UNUSED PurpleProtocolConversationInterface *iface)
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 }
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 /******************************************************************************
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 * Public API
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 *****************************************************************************/
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 void
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 purple_protocol_conversation_send_message_async(PurpleProtocolConversation *protocol,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 PurpleConversation *conversation,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 PurpleMessage *message,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 GCancellable *cancellable,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 GAsyncReadyCallback callback,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 gpointer data)
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 PurpleProtocolConversationInterface *iface = NULL;
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 g_return_if_fail(PURPLE_IS_PROTOCOL_CONVERSATION(protocol));
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 g_return_if_fail(PURPLE_IS_CONVERSATION(conversation));
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 g_return_if_fail(PURPLE_IS_MESSAGE(message));
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 iface = PURPLE_PROTOCOL_CONVERSATION_GET_IFACE(protocol);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 if(iface != NULL && iface->send_message_async != NULL) {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 iface->send_message_async(protocol, conversation, message, cancellable,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 callback, data);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 } else {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 g_warning("%s does not implement send_message_async",
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 G_OBJECT_TYPE_NAME(protocol));
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 }
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 }
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 gboolean
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 purple_protocol_conversation_send_message_finish(PurpleProtocolConversation *protocol,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 GAsyncResult *result,
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 GError **error)
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 PurpleProtocolConversationInterface *iface = NULL;
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONVERSATION(protocol), FALSE);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 iface = PURPLE_PROTOCOL_CONVERSATION_GET_IFACE(protocol);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 if(iface != NULL && iface->send_message_finish != NULL) {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 return iface->send_message_finish(protocol, result, error);
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 } else {
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 g_warning("%s does not implement send_message_finish",
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 G_OBJECT_TYPE_NAME(protocol));
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 }
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 return FALSE;
98931e2d3ca2 Create the initial PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 }

mercurial