libpurple/protocols/demo/purpledemoprotocolim.c

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 41285
cc3c735c14f4
parent 41284
7b29786ffdc7
child 41968
2fc2db360044
permissions
-rw-r--r--

Split apart demo's PurpleProtocolClient implementation

41284
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
1 /*
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
4 *
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
9 *
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
14 *
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
17 */
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
18
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
20
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
21 #include "purpledemoprotocol.h"
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
22 #include "purpledemoprotocolim.h"
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
23
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
24 /******************************************************************************
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
25 * PurpleProtocolIM Implementation
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
26 *****************************************************************************/
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
27 typedef struct {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
28 PurpleConnection *connection;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
29 PurpleMessage *message;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
30 } PurpleDemoProtocolIMInfo;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
31
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
32 static void
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
33 purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
34 g_object_unref(info->message);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
35 g_free(info);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
36 }
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
37
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
38 static gboolean
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
39 purple_demo_protocol_echo_im_cb(gpointer data)
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
40 {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
41 PurpleDemoProtocolIMInfo *info = data;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
42 const char *who = NULL;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
43 PurpleMessageFlags flags;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
44 GDateTime *timestamp = NULL;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
45
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
46 /* Turn outgoing message back incoming. */
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
47 who = purple_message_get_recipient(info->message);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
48 flags = purple_message_get_flags(info->message);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
49 flags &= ~PURPLE_MESSAGE_SEND;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
50 flags |= PURPLE_MESSAGE_RECV;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
51 timestamp = purple_message_get_timestamp(info->message);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
52
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
53 purple_serv_got_im(info->connection, who,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
54 purple_message_get_contents(info->message), flags,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
55 g_date_time_to_unix(timestamp));
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
56
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
57 g_date_time_unref(timestamp);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
58
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
59 return FALSE;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
60 }
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
61
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
62 static gint
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
63 purple_demo_protocol_send_im(PurpleProtocolIM *im, PurpleConnection *conn,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
64 PurpleMessage *msg)
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
65 {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
66 const gchar *who = purple_message_get_recipient(msg);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
67
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
68 if(purple_strequal(who, "Echo")) {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
69 PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
70
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
71 info->connection = conn;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
72 info->message = g_object_ref(msg);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
73
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
74 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
75 purple_demo_protocol_echo_im_cb, info,
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
76 (GDestroyNotify)purple_demo_protocol_im_info_free);
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
77 }
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
78
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
79 return 1;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
80 }
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
81
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
82 void
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
83 purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface) {
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
84 iface->send = purple_demo_protocol_send_im;
7b29786ffdc7 Split apart the demo's PurpleProtocolIM implementation
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
diff changeset
85 }

mercurial