purplesatoriprotocol.c

Sun, 10 Aug 2025 23:53:22 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:53:22 +0800
changeset 3
33a7b189a2c6
parent 0
cc7c1f9d20f7
permissions
-rw-r--r--

Various improvement, Support configuration from UI

0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
1 /*
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
2 * Purple Satori Plugin - Satori Protocol Plugin for Purple3
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
3 * Copyright (C) 2025 Gong Zhile
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
4 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
9 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
13 * Lesser General Public License for more details.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
14 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
17 */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
18
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
20
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
21 #include "purplesatoriprotocol.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
22
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
23 #include "glib.h"
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
24 #include "purplesatoriconnection.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
25 #include "purplesatoriprotocolcontacts.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
26 #include "purplesatoriprotocolconversation.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
27
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
28 struct _PurpleSatoriProtocol {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
29 PurpleProtocol parent;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
30 };
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
31
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
32 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
33 * PurpleProtocol Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
34 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
35 static PurpleConnection *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
36 purple_satori_protocol_create_connection(PurpleProtocol *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
37 PurpleAccount *account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
38 const char *password,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
39 G_GNUC_UNUSED GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
40 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
41 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
42 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
43
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
44 return g_object_new(PURPLE_SATORI_TYPE_CONNECTION,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
45 "protocol", protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
46 "account", account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
47 "password", password,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
48 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
49
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
50 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
51
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
52 static GList *
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
53 purple_satori_protocol_get_account_options(G_GNUC_UNUSED PurpleProtocol *protocol)
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
54 {
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
55 PurpleAccountOption *option = NULL;
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
56 GList *options = NULL;
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
57
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
58 option = purple_account_option_string_new(_("Satori Platform"), "platform",
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
59 "QQ");
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
60 options = g_list_append(options, option);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
61
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
62 option = purple_account_option_bool_new(_("Secure Connection (HTTPS)"),
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
63 "https", FALSE);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
64 options = g_list_append(options, option);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
65
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
66 option = purple_account_option_string_new(_("API Host"),
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
67 "host", "127.0.0.1:5600");
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
68 options = g_list_append(options, option);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
69
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
70 option = purple_account_option_string_new(_("API Path"), "path", "/v1"),
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
71 options = g_list_append(options, option);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
72
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
73 option = purple_account_option_string_new(_("API Token"), "token", NULL);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
74 purple_account_option_string_set_masked(option, TRUE);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
75 options = g_list_append(options, option);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
76
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
77 return options;
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
78 }
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
79
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
80 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
81 * GObject Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
82 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
83 G_DEFINE_DYNAMIC_TYPE_EXTENDED(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
84 PurpleSatoriProtocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
85 purple_satori_protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
86 PURPLE_TYPE_PROTOCOL,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
87 G_TYPE_FLAG_FINAL,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
88 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONTACTS,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
89 purple_satori_protocol_contacts_init)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
90 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONVERSATION,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
91 purple_satori_protocol_conversation_init))
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
92
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
93 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
94 purple_satori_protocol_init(G_GNUC_UNUSED PurpleSatoriProtocol *protocol) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
95 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
96
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
97 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
98 purple_satori_protocol_class_finalize(G_GNUC_UNUSED PurpleSatoriProtocolClass *klass) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
99 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
100
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
101 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
102 purple_satori_protocol_class_init(PurpleSatoriProtocolClass *klass) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
103 PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
104
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 0
diff changeset
105 protocol_class->get_account_options = purple_satori_protocol_get_account_options;
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
106 protocol_class->create_connection = purple_satori_protocol_create_connection;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
107 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
108
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
109 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
110 * Local Exports
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
111 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
112 void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
113 purple_satori_protocol_register(GPluginNativePlugin *plugin) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
114 purple_satori_protocol_register_type(G_TYPE_MODULE(plugin));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
115 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
116
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
117 PurpleProtocol *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
118 purple_satori_protocol_new(void) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
119 return g_object_new(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
120 PURPLE_SATORI_TYPE_PROTOCOL,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
121 "id", "prpl-satori",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
122 "name", "Satori",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
123 "description", "Satori Protocol Plugin for Purple 3",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
124 "icon-name", "im-purple-satori",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
125 "icon-resource-path", "/im/pidgin/libpurple/protocols/satori/icons",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
126 "options", OPT_PROTO_NO_PASSWORD,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
127 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
128 }

mercurial