Sat, 09 Aug 2025 00:19:03 +0800
Another Minor Milestone Reached, Conversation Creation & Recv works now
| 0 | 1 | /* |
| 2 | * Purple Satori Plugin - Satori Protocol Plugin for Purple3 | |
| 3 | * Copyright (C) 2025 Gong Zhile | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #include <glib.h> | |
| 20 | #include <glib-object.h> | |
| 21 | #include <glib/gi18n-lib.h> | |
| 22 | #include <json-glib/json-glib.h> | |
| 23 | ||
| 24 | #include <gio/gio.h> | |
| 25 | #include <libsoup/soup.h> | |
| 26 | #include <libsoup/soup-session.h> | |
| 27 | #include <libsoup/soup-message.h> | |
| 28 | #include <libsoup/soup-types.h> | |
| 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 | 31 | |
| 32 | #include "purplesatoriconnection.h" | |
| 33 | #include "purplesatoriprotocolcontacts.h" | |
| 34 | #include "satorimessage.h" | |
| 35 | #include "satoritypes.h" | |
| 36 | #include "satoriapi.h" | |
| 37 | ||
| 38 | struct _PurpleSatoriConnection { | |
| 39 | PurpleConnection parent; | |
| 40 | SoupSession *session; | |
| 41 | ||
| 42 | SoupWebsocketConnection *wscon; | |
| 43 | gboolean wsidented; | |
| 44 | }; | |
| 45 | ||
| 46 | G_DEFINE_DYNAMIC_TYPE_EXTENDED(PurpleSatoriConnection, purple_satori_connection, | |
| 47 | PURPLE_TYPE_CONNECTION, G_TYPE_FLAG_FINAL, {}); | |
| 48 | ||
| 49 | /****************************************************************************** | |
|
1
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
50 | * PurpleConversation Helpers |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
51 | *****************************************************************************/ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
52 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
53 | static void |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
54 | 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
|
55 | SatoriUser *user, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
56 | SatoriChannel *chan, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
57 | JsonObject *msg_obj) |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
58 | { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
59 | PurpleConversation *conversation = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
60 | 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
|
61 | PurpleConversationMember *mbr = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
62 | 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
|
63 | con, conversation, user); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
64 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
65 | 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
|
66 | msg_obj, "id", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
67 | const gchar *text = 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, "content", "Invalid Message"); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
69 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
70 | 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
|
71 | 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
|
72 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
73 | PurpleMessage *message = purple_message_new(mbr, text); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
74 | if (id) purple_message_set_id(message, id); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
75 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
76 | if (created_at) { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
77 | 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
|
78 | 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
|
79 | g_date_time_unref(ts); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
80 | } 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
|
81 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
82 | 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
|
83 | g_clear_object(&message); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
84 | } |
|
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 | /****************************************************************************** |
| 0 | 87 | * PurpleConnection WS Callbacks |
| 88 | *****************************************************************************/ | |
| 89 | ||
| 90 | static void | |
| 91 | satori_ws_on_closed(SoupWebsocketConnection *wscon, PurpleSatoriConnection *data) | |
| 92 | { | |
| 93 | PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(data); | |
| 94 | PurpleAccount *acc = purple_connection_get_account(PURPLE_CONNECTION(con)); | |
| 95 | purple_account_disconnect(acc); | |
| 96 | ||
| 97 | con->wscon = NULL; | |
| 98 | } | |
| 99 | ||
| 100 | static void | |
| 101 | satori_ws_on_message(SoupWebsocketConnection *wscon, gint type, | |
| 102 | GBytes *message, PurpleSatoriConnection *con) | |
| 103 | { | |
| 104 | PurpleAccount *acc = purple_connection_get_account( | |
| 105 | PURPLE_CONNECTION(con)); | |
| 106 | ||
| 107 | if (type != SOUP_WEBSOCKET_DATA_TEXT) { | |
| 108 | purple_debug_warning("satori", "unexpected data recv from ws"); | |
| 109 | return; | |
| 110 | } | |
| 111 | ||
| 112 | gsize sz; | |
| 113 | const gchar *ptr = g_bytes_get_data(message, &sz); | |
| 114 | ||
| 115 | /* g_print("Received text data: %s\n", ptr); */ | |
| 116 | ||
| 117 | JsonParser *parser = json_parser_new(); | |
| 118 | if (!json_parser_load_from_data(parser, ptr, sz, NULL)) { | |
| 119 | purple_debug_warning("satori", "bad json received from ws"); | |
| 120 | g_object_unref(parser); | |
| 121 | return; | |
| 122 | } | |
| 123 | ||
| 124 | JsonObject *root = json_node_get_object(json_parser_get_root(parser)); | |
| 125 | JsonObject *body = json_object_get_object_member(root, "body"); | |
| 126 | SatoriWebsocketOpcode op = json_object_get_int_member(root, "op"); | |
| 127 | ||
| 128 | switch (op) { | |
| 129 | ||
| 130 | case SATORI_WEBSOCKET_OP_READY: | |
| 131 | { | |
| 132 | purple_account_connected(acc); | |
| 133 | ||
| 134 | JsonArray *logins = json_object_get_array_member(body, "logins"); | |
| 135 | JsonObject *user_obj = json_object_get_object_member( | |
| 136 | json_array_get_object_element(logins, 0), "user"); | |
| 137 | SatoriUser user = { 0 }; | |
| 138 | ||
| 139 | if (!user_obj) break; | |
| 140 | satori_user_from_json(user_obj, &user); | |
| 141 | ||
| 142 | PurpleContactInfo *ci = purple_account_get_contact_info(acc); | |
| 143 | purple_contact_info_set_id(ci, user.id); | |
| 144 | purple_contact_info_set_display_name(ci, user.nick | |
| 145 | ? user.nick : user.name); | |
| 146 | ||
| 147 | 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
|
148 | satori_refresh_conversations(con, NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
149 | break; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
150 | } |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
151 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
152 | case SATORI_WEBSOCKET_OP_EVENT: |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
153 | { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
154 | 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
|
155 | 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
|
156 | 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
|
157 | body, "message"); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
158 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
159 | 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
|
160 | 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
|
161 | "user"); |
|
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 | if (!usr_obj) |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
164 | usr_obj = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
165 | 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
|
166 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
167 | if (!usr_obj) break; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
168 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
169 | JsonObject *chan_obj = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
170 | 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
|
171 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
172 | if (!chan_obj) break; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
173 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
174 | SatoriChannel chan; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
175 | SatoriUser usr; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
176 | 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
|
177 | 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
|
178 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
179 | 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
|
180 | } |
| 0 | 181 | break; |
| 182 | } | |
| 183 | ||
| 184 | default: /* ignored */ | |
| 185 | break; | |
| 186 | ||
| 187 | } | |
| 188 | ||
| 189 | g_object_unref(parser); | |
| 190 | } | |
| 191 | ||
| 192 | static void | |
| 193 | satori_ws_on_connection(SoupSession *session, GAsyncResult *res, gpointer data) | |
| 194 | { | |
| 195 | PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(data); | |
| 196 | PurpleAccount *acc = purple_connection_get_account(PURPLE_CONNECTION(con)); | |
| 197 | GError *err = NULL; | |
| 198 | ||
| 199 | con->wscon = soup_session_websocket_connect_finish(session, res, &err); | |
| 200 | if (err) { | |
| 201 | purple_account_disconnect_with_error(acc, err); | |
| 202 | return; | |
| 203 | } | |
| 204 | ||
| 205 | g_signal_connect(con->wscon, "message", | |
| 206 | G_CALLBACK(satori_ws_on_message), con); | |
| 207 | g_signal_connect(con->wscon, "closed", | |
| 208 | G_CALLBACK(satori_ws_on_closed), con); | |
| 209 | ||
| 210 | GBytes *frame = satori_message_gen_ident(NULL, 0); | |
| 211 | soup_websocket_connection_send_text(con->wscon, | |
| 212 | g_bytes_get_data(frame, NULL)); | |
| 213 | g_bytes_unref(frame); | |
| 214 | } | |
| 215 | ||
| 216 | /****************************************************************************** | |
| 217 | * PurpleConnection Implementation | |
| 218 | *****************************************************************************/ | |
| 219 | static gboolean | |
| 220 | purple_satori_connection_connect(PurpleConnection *connection, | |
| 221 | G_GNUC_UNUSED GError **error) | |
| 222 | { | |
| 223 | PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(connection); | |
| 224 | ||
| 225 | if (con->wscon) | |
| 226 | g_object_unref(con->wscon); | |
| 227 | ||
| 228 | SoupMessage *svmsg = satori_message_new("GET", PURPLE_SATORI_WSURL); | |
| 229 | soup_session_websocket_connect_async( | |
| 230 | con->session, svmsg, | |
| 231 | NULL, NULL, 0, NULL, | |
| 232 | (GAsyncReadyCallback) satori_ws_on_connection, | |
| 233 | con); | |
| 234 | ||
| 235 | /* purple_account_connected(account); */ | |
| 236 | /* purple_satori_contacts_load(account); */ | |
| 237 | ||
| 238 | return TRUE; | |
| 239 | } | |
| 240 | ||
| 241 | static gboolean | |
| 242 | purple_satori_connection_disconnect(PurpleConnection *connection, | |
| 243 | G_GNUC_UNUSED GError **error) | |
| 244 | { | |
| 245 | PurpleSatoriConnection *con = PURPLE_SATORI_CONNECTION(connection); | |
| 246 | if (!con->wscon) return TRUE; | |
| 247 | ||
| 248 | g_signal_handlers_disconnect_by_data(con->wscon, con); | |
| 249 | soup_websocket_connection_close(con->wscon, | |
| 250 | SOUP_WEBSOCKET_CLOSE_NO_STATUS, NULL); | |
| 251 | con->wscon = NULL; | |
| 252 | return TRUE; | |
| 253 | } | |
| 254 | ||
| 255 | /****************************************************************************** | |
| 256 | * GObject Implementation | |
| 257 | *****************************************************************************/ | |
| 258 | static void | |
| 259 | purple_satori_connection_init(PurpleSatoriConnection *connection) { | |
| 260 | connection->session = soup_session_new(); | |
| 261 | connection->wscon = NULL; | |
| 262 | } | |
| 263 | ||
| 264 | static void | |
| 265 | purple_satori_connection_class_finalize(G_GNUC_UNUSED PurpleSatoriConnectionClass *klass) { | |
| 266 | } | |
| 267 | ||
| 268 | static void | |
| 269 | purple_satori_connection_class_init(PurpleSatoriConnectionClass *klass) { | |
| 270 | PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass); | |
| 271 | ||
| 272 | connection_class->connect = purple_satori_connection_connect; | |
| 273 | connection_class->disconnect = purple_satori_connection_disconnect; | |
| 274 | } | |
| 275 | ||
| 276 | /****************************************************************************** | |
| 277 | * Internal API | |
| 278 | *****************************************************************************/ | |
| 279 | void | |
| 280 | purple_satori_connection_register(GPluginNativePlugin *plugin) { | |
| 281 | purple_satori_connection_register_type(G_TYPE_MODULE(plugin)); | |
| 282 | } | |
| 283 | ||
| 284 | /****************************************************************************** | |
| 285 | * Public API Implementation | |
| 286 | *****************************************************************************/ | |
| 287 | ||
| 288 | void | |
| 289 | purple_satori_connection_send_and_read_async(PurpleSatoriConnection *con, | |
| 290 | SoupMessage *msg, | |
| 291 | int io_priority, | |
| 292 | GCancellable *cancellable, | |
| 293 | GAsyncReadyCallback callback, | |
| 294 | gpointer user_data) | |
| 295 | { | |
| 296 | soup_session_send_and_read_async(con->session, msg, io_priority, | |
| 297 | cancellable, callback, user_data); | |
| 298 | } |