purplesatoriconnection.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 1
98bcf06036b8
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.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
20 #include <glib-object.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
21 #include <glib/gi18n-lib.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
22 #include <json-glib/json-glib.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
23
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
24 #include <gio/gio.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
25 #include <libsoup/soup.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
26 #include <libsoup/soup-session.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
27 #include <libsoup/soup-message.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
28 #include <libsoup/soup-types.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
29 #include <libsoup/soup-websocket-connection.h>
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
30 #include <time.h>
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
31
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
32 #include "purplesatoriconnection.h"
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
33 #include "pango/pango-attributes.h"
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
34 #include "purplesatoriprotocolcontacts.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
35 #include "satorimessage.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
36 #include "satoritypes.h"
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
37 #include "satoriformat.h"
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
38 #include "satoriapi.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
39
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
40 struct _PurpleSatoriConnection {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
41 PurpleConnection parent;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
42 SoupSession *session;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
43
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
44 SoupWebsocketConnection *wscon;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
45 gboolean wsidented;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
46 };
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
47
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
48 G_DEFINE_DYNAMIC_TYPE_EXTENDED(PurpleSatoriConnection, purple_satori_connection,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
49 PURPLE_TYPE_CONNECTION, G_TYPE_FLAG_FINAL, {});
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
50
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
51 /******************************************************************************
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
52 * PurpleConversation Helpers
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
53 *****************************************************************************/
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
54
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
55 static void
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
56 purple_satori_handle_pending_message(PurpleSatoriConnection *con,
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
57 SatoriUser *user,
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
58 SatoriChannel *chan,
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
59 JsonObject *msg_obj)
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
60 {
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
61 PurpleConversation *conversation = \
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
62 purple_satori_add_conversation_from_chan(con, chan);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
63 PurpleConversationMember *mbr = \
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
64 purple_satori_add_conversation_member_from_user(
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
65 con, conversation, user);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
66
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
67 const gchar *id = json_object_get_string_member_with_default(
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
68 msg_obj, "id", NULL);
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
69 const gchar *html = json_object_get_string_member_with_default(
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
70 msg_obj, "content", "Invalid Message");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
71
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
72 time_t created_at = json_object_get_int_member_with_default(
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
73 msg_obj, "created_at", 0) / 1000; /* timestamp in mS */
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
74
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
75 PangoAttrList *attrs = pango_attr_list_new();
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
76 GString *text = NULL;
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
77 satori_format_html_to_purple(conversation, html, &text, attrs);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
78
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
79 PurpleMessage *message = purple_message_new(mbr, text->str);
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
80 if (id) purple_message_set_id(message, id);
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
81 purple_message_set_attributes(message, attrs);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
82
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
83 pango_attr_list_unref(attrs);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
84 g_free(text);
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
85
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
86 if (created_at) {
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
87 GDateTime *ts = g_date_time_new_from_unix_local(created_at);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
88 purple_message_set_timestamp(message, ts);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
89 g_date_time_unref(ts);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
90 } else purple_message_set_timestamp_now(message);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
91
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
92 purple_conversation_write_message(conversation, message);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
93 g_clear_object(&message);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
94 }
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
95
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
96 /******************************************************************************
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
97 * PurpleConnection WS Callbacks
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
98 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
99
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
100 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
101 satori_ws_on_closed(SoupWebsocketConnection *wscon, PurpleSatoriConnection *data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
102 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
103 PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
104 PurpleAccount *acc = purple_connection_get_account(PURPLE_CONNECTION(con));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
105 purple_account_disconnect(acc);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
106
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
107 con->wscon = NULL;
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 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
111 satori_ws_on_message(SoupWebsocketConnection *wscon, gint type,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
112 GBytes *message, PurpleSatoriConnection *con)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
113 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
114 PurpleAccount *acc = purple_connection_get_account(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
115 PURPLE_CONNECTION(con));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
116
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
117 if (type != SOUP_WEBSOCKET_DATA_TEXT) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
118 purple_debug_warning("satori", "unexpected data recv from ws");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
119 return;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
120 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
121
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
122 gsize sz;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
123 const gchar *ptr = g_bytes_get_data(message, &sz);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
124
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
125 JsonParser *parser = json_parser_new();
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
126 if (!json_parser_load_from_data(parser, ptr, sz, NULL)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
127 purple_debug_warning("satori", "bad json received from ws");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
128 g_object_unref(parser);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
129 return;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
130 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
131
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
132 JsonObject *root = json_node_get_object(json_parser_get_root(parser));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
133 JsonObject *body = json_object_get_object_member(root, "body");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
134 SatoriWebsocketOpcode op = json_object_get_int_member(root, "op");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
135
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
136 switch (op) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
137
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
138 case SATORI_WEBSOCKET_OP_READY:
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
139 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
140 purple_account_connected(acc);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
141
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
142 JsonArray *logins = json_object_get_array_member(body, "logins");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
143 JsonObject *user_obj = json_object_get_object_member(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
144 json_array_get_object_element(logins, 0), "user");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
145 SatoriUser user = { 0 };
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
146
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
147 if (!user_obj) break;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
148 satori_user_from_json(user_obj, &user);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
149
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
150 PurpleContactInfo *ci = purple_account_get_contact_info(acc);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
151 purple_contact_info_set_id(ci, user.id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
152 purple_contact_info_set_display_name(ci, user.nick
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
153 ? user.nick : user.name);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
154
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
155 PurplePresence *presence = purple_contact_info_get_presence(ci);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
156 purple_presence_set_primitive(presence,
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
157 PURPLE_PRESENCE_PRIMITIVE_AVAILABLE);
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
158
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
159 satori_refresh_buddy_contacts(con, NULL);
1
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
160 satori_refresh_conversations(con, NULL);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
161 break;
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
162 }
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
163
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
164 case SATORI_WEBSOCKET_OP_EVENT:
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
165 {
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
166 const gchar *type = json_object_get_string_member(body, "type");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
167 if (purple_strequal(type, "message-created")) {
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
168 JsonObject *obj = json_object_get_object_member(
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
169 body, "message");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
170
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
171 JsonObject *usr_obj = json_object_get_object_member(
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
172 json_object_get_object_member(body, "member"),
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
173 "user");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
174
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
175 if (!usr_obj)
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
176 usr_obj = \
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
177 json_object_get_object_member(body, "user");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
178
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
179 if (!usr_obj) break;
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
180
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
181 JsonObject *chan_obj = \
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
182 json_object_get_object_member(body, "channel");
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
183
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
184 if (!chan_obj) break;
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
185
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
186 SatoriChannel chan;
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
187 SatoriUser usr;
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
188 satori_channel_from_json(chan_obj, &chan);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
189 satori_user_from_json(usr_obj, &usr);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
190
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
191 purple_satori_handle_pending_message(con, &usr, &chan, obj);
98bcf06036b8 Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents: 0
diff changeset
192 }
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
193 break;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
194 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
195
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
196 default: /* ignored */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
197 break;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
198
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
199 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
200
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
201 g_object_unref(parser);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
202 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
203
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
204 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
205 satori_ws_on_connection(SoupSession *session, GAsyncResult *res, gpointer data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
206 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
207 PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
208 PurpleAccount *acc = purple_connection_get_account(PURPLE_CONNECTION(con));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
209 GError *err = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
210
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
211 con->wscon = soup_session_websocket_connect_finish(session, res, &err);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
212 if (err) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
213 purple_account_disconnect_with_error(acc, err);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
214 return;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
215 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
216
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
217 g_signal_connect(con->wscon, "message",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
218 G_CALLBACK(satori_ws_on_message), con);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
219 g_signal_connect(con->wscon, "closed",
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
220 G_CALLBACK(satori_ws_on_closed), con);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
221
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
222 GBytes *frame = satori_message_gen_ident(NULL, 0);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
223 soup_websocket_connection_send_text(con->wscon,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
224 g_bytes_get_data(frame, NULL));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
225 g_bytes_unref(frame);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
226 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
227
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
228 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
229 * PurpleConnection Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
230 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
231 static gboolean
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
232 purple_satori_connection_connect(PurpleConnection *connection,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
233 G_GNUC_UNUSED GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
234 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
235 PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(connection);
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
236 PurpleAccount *acc = purple_connection_get_account(connection);
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
237
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
238 if (con->wscon)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
239 g_object_unref(con->wscon);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
240
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
241 gchar *wsurl = \
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
242 g_strdup_printf("%s://%s%s/events",
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
243 purple_account_get_bool(acc, "https", FALSE) ? "wss" : "ws",
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
244 purple_account_get_string(acc, "host", "127.0.0.1:5600"),
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
245 purple_account_get_string(acc, "path", "/v1"));
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
246
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
247 SoupMessage *svmsg = soup_message_new("GET", wsurl);
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
248 soup_session_websocket_connect_async(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
249 con->session, svmsg,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
250 NULL, NULL, 0, NULL,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
251 (GAsyncReadyCallback) satori_ws_on_connection,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
252 con);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
253
3
33a7b189a2c6 Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents: 1
diff changeset
254 g_free(wsurl);
0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
255 return TRUE;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
256 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
257
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
258 static gboolean
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
259 purple_satori_connection_disconnect(PurpleConnection *connection,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
260 G_GNUC_UNUSED GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
261 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
262 PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(connection);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
263 if (!con->wscon) return TRUE;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
264
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
265 g_signal_handlers_disconnect_by_data(con->wscon, con);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
266 soup_websocket_connection_close(con->wscon,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
267 SOUP_WEBSOCKET_CLOSE_NO_STATUS, NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
268 con->wscon = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
269 return TRUE;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
270 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
271
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
272 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
273 * GObject Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
274 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
275 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
276 purple_satori_connection_init(PurpleSatoriConnection *connection) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
277 connection->session = soup_session_new();
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
278 connection->wscon = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
279 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
280
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
281 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
282 purple_satori_connection_class_finalize(G_GNUC_UNUSED PurpleSatoriConnectionClass *klass) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
283 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
284
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
285 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
286 purple_satori_connection_class_init(PurpleSatoriConnectionClass *klass) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
287 PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
288
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
289 connection_class->connect = purple_satori_connection_connect;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
290 connection_class->disconnect = purple_satori_connection_disconnect;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
291 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
292
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
293 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
294 * Internal API
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
295 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
296 void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
297 purple_satori_connection_register(GPluginNativePlugin *plugin) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
298 purple_satori_connection_register_type(G_TYPE_MODULE(plugin));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
299 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
300
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
301 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
302 * Public API Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
303 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
304
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
305 void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
306 purple_satori_connection_send_and_read_async(PurpleSatoriConnection *con,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
307 SoupMessage *msg,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
308 int io_priority,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
309 GCancellable *cancellable,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
310 GAsyncReadyCallback callback,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
311 gpointer user_data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
312 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
313 soup_session_send_and_read_async(con->session, msg, io_priority,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
314 cancellable, callback, user_data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
315 }

mercurial