libpurple/protocols/gg/servconn.c

Fri, 01 May 2020 04:42:52 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 01 May 2020 04:42:52 -0500
changeset 40358
e6fe6fc1f516
parent 40195
fb4b0ae193c0
child 40538
222423055d93
permissions
-rw-r--r--

move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
7 * Rewritten from scratch during Google Summer of Code 2012
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
15 * This program is free software; you can redistribute it and/or modify
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
16 * it under the terms of the GNU General Public License as published by
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
17 * the Free Software Foundation; either version 2 of the License, or
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
20 * This program is distributed in the hope that it will be useful,
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
25 * You should have received a copy of the GNU General Public License
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
26 * along with this program; if not, write to the Free Software
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
29
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include "servconn.h"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 #include "utils.h"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34 #define GGP_SERVCONN_HISTORY_PREF "/plugins/prpl/gg/server_history"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
35 #define GGP_SERVCONN_HISTORY_MAXLEN 15
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 typedef struct
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 GList *server_history;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40 PurpleAccountOption *server_option;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41 } ggp_servconn_global_data;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43 static ggp_servconn_global_data global_data;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
44
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
45 void ggp_servconn_setup(PurpleAccountOption *server_option)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
47 purple_prefs_add_string(GGP_SERVCONN_HISTORY_PREF, "");
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
48
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
49 global_data.server_option = server_option;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50 global_data.server_history = ggp_strsplit_list(purple_prefs_get_string(
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
51 GGP_SERVCONN_HISTORY_PREF), ";", GGP_SERVCONN_HISTORY_MAXLEN + 1);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
52 global_data.server_history = ggp_list_truncate(
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
53 global_data.server_history, GGP_SERVCONN_HISTORY_MAXLEN,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
54 g_free);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
55
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
56 purple_account_option_string_set_hints(global_data.server_option,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
57 ggp_servconn_get_servers());
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
58 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
59
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
60 void ggp_servconn_cleanup(void)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
61 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
62 g_list_free_full(global_data.server_history, &g_free);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
63 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 void ggp_servconn_add_server(const gchar *server)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 GList *old_entry;
34350
89441dbabc83 Gadu-Gadu: initial GG11 conferences support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
68 gchar *joined;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
69
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70 old_entry = g_list_find_custom(global_data.server_history, server,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
71 (GCompareFunc)g_strcmp0);
35361
efdbd45604f1 Style: fix gg braces (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35357
diff changeset
72 if (old_entry) {
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
73 g_free(old_entry->data);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
74 global_data.server_history = g_list_delete_link(
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
75 global_data.server_history, old_entry);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
76 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
77
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
78 global_data.server_history = g_list_prepend(global_data.server_history,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79 g_strdup(server));
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 global_data.server_history = ggp_list_truncate(
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
81 global_data.server_history, GGP_SERVCONN_HISTORY_MAXLEN,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
82 g_free);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83
34350
89441dbabc83 Gadu-Gadu: initial GG11 conferences support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
84 joined = ggp_strjoin_list(";", global_data.server_history);
89441dbabc83 Gadu-Gadu: initial GG11 conferences support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
85 purple_prefs_set_string(GGP_SERVCONN_HISTORY_PREF, joined);
89441dbabc83 Gadu-Gadu: initial GG11 conferences support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
86 g_free(joined);
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
87 purple_account_option_string_set_hints(global_data.server_option,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
88 ggp_servconn_get_servers());
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
89 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
90
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
91 GSList * ggp_servconn_get_servers(void)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93 return ggp_list_copy_to_slist_deep(global_data.server_history,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
94 (GCopyFunc)g_strdup, NULL);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
95 }
35145
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
96
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
97 void
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
98 ggp_servconn_remote_disconnect(PurpleConnection *gc)
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
99 {
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
100 purple_debug_info("gg", "Server remotely closes connection");
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
101 purple_account_disconnect(purple_connection_get_account(gc));
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
102 }

mercurial