Wed, 25 May 2022 23:52:45 -0500
Remove prpl-gtalk from XMPP console
It no longer exists, and complicates the code a bit.
| 8675 | 1 | /* |
| 2 | * nmevent.c | |
| 3 | * | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
4 | * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
5 | * |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
6 | * This program is free software; you can redistribute it and/or modify |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
7 | * it under the terms of the GNU General Public License as published by |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
8 | * the Free Software Foundation; version 2 of the License. |
| 8675 | 9 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
13 | * GNU General Public License for more details. |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
16 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8675 | 18 | * |
| 19 | */ | |
| 20 | ||
| 21 | #include <glib.h> | |
| 22 | #include <string.h> | |
| 23 | #include <time.h> | |
| 24 | #include "nmevent.h" | |
| 25 | #include "nmfield.h" | |
| 26 | #include "nmconn.h" | |
| 27 | #include "nmuserrecord.h" | |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
28 | #include "nmrtf.h" |
| 8675 | 29 | |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
30 | #define MAX_UINT32 0xFFFFFFFF |
|
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
31 | |
| 8675 | 32 | struct _NMEvent |
| 33 | { | |
| 34 | ||
| 35 | /* Event type */ | |
| 36 | int type; | |
| 37 | ||
| 38 | /* The DN of the event source */ | |
| 39 | char *source; | |
| 40 | ||
| 41 | /* Timestamp of the event */ | |
| 42 | guint32 gmt; | |
| 43 | ||
| 44 | /* Conference to associate with the event */ | |
| 45 | NMConference *conference; | |
| 46 | ||
| 47 | /* User record to associate with the event */ | |
| 48 | NMUserRecord *user_record; | |
| 49 | ||
| 50 | /* Text associated with the event */ | |
| 51 | char *text; | |
| 52 | ||
| 53 | /* Reference count for event structure */ | |
| 54 | int ref_count; | |
| 55 | ||
| 56 | }; | |
| 57 | ||
| 58 | /* Handle getdetails response and set the new user record into the event */ | |
| 59 | static void | |
| 60 | _got_user_for_event(NMUser * user, NMERR_T ret_val, | |
| 61 | gpointer resp_data, gpointer user_data) | |
| 62 | { | |
| 63 | NMUserRecord *user_record; | |
| 64 | NMEvent *event; | |
| 65 | nm_event_cb cb; | |
| 66 | ||
| 67 | if (user == NULL) | |
| 68 | return; | |
| 69 | ||
| 70 | user_record = resp_data; | |
| 71 | event = user_data; | |
| 72 | ||
| 73 | if (ret_val == NM_OK) { | |
| 74 | if (event && user_record) { | |
| 75 | ||
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
76 | /* Add the user record to the event structure |
| 8675 | 77 | * and make the callback. |
| 78 | */ | |
| 79 | nm_event_set_user_record(event, user_record); | |
| 80 | if ((cb = nm_user_get_event_callback(user))) { | |
| 81 | cb(user, event); | |
| 82 | } | |
| 83 | } | |
| 84 | ||
| 85 | } else { | |
| 86 | /* Cleanup resp_data */ | |
| 87 | ||
| 88 | } | |
| 89 | ||
| 90 | /* Clean up */ | |
| 91 | if (event) | |
| 92 | nm_release_event(event); | |
| 93 | ||
| 94 | } | |
| 95 | ||
| 96 | /* Handle getdetails response, set the new user record into the event | |
| 97 | * and add the user record as a participant in the conference | |
| 98 | */ | |
| 99 | static void | |
| 100 | _got_user_for_conference(NMUser * user, NMERR_T ret_val, | |
| 101 | gpointer resp_data, gpointer user_data) | |
| 102 | { | |
| 103 | NMUserRecord *user_record = resp_data; | |
| 104 | NMEvent *event = user_data; | |
| 105 | NMConference *conference; | |
| 106 | nm_event_cb cb; | |
| 107 | ||
| 108 | if (user == NULL) | |
| 109 | return; | |
| 110 | ||
| 111 | if (event && user_record) { | |
| 112 | ||
| 113 | conference = nm_event_get_conference(event); | |
| 114 | if (conference) { | |
| 115 | ||
| 116 | /* Add source of event as recip of the conference */ | |
| 117 | nm_conference_add_participant(conference, user_record); | |
| 118 | ||
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
119 | /* Add the user record to the event structure |
| 8675 | 120 | * and make the callback. |
| 121 | */ | |
| 122 | nm_event_set_user_record(event, user_record); | |
| 123 | if ((cb = nm_user_get_event_callback(user))) { | |
| 124 | cb(user, event); | |
| 125 | } | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | if (event) | |
| 130 | nm_release_event(event); | |
| 131 | } | |
| 132 | ||
| 133 | /* Read the receive message event, set up the event object, and | |
| 134 | * get details for the event source if we don't have them yet. | |
| 135 | */ | |
| 136 | static NMERR_T | |
| 137 | handle_receive_message(NMUser * user, NMEvent * event, gboolean autoreply) | |
| 138 | { | |
| 139 | NMConference *conference; | |
| 140 | NMUserRecord *user_record; | |
| 141 | NMConn *conn; | |
| 142 | NMERR_T rc = NM_OK; | |
| 143 | guint32 size = 0, flags = 0; | |
| 144 | char *msg = NULL; | |
| 145 | char *nortf = NULL; | |
| 146 | char *guid = NULL; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
147 | GError *error = NULL; |
| 8675 | 148 | |
| 149 | conn = nm_user_get_conn(user); | |
| 150 | ||
| 151 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
152 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
153 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
154 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
155 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
156 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
157 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
158 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
159 | if (error == NULL) { |
| 8675 | 160 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
161 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
162 | user->cancellable, &error); |
| 8675 | 163 | } |
| 164 | ||
| 165 | /* Read the conference flags */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
166 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
167 | flags = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
168 | &error); |
| 8675 | 169 | } |
| 170 | ||
| 171 | /* Read the message text */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
172 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
173 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
174 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
175 | if (size > 100000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
176 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
177 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
178 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
179 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
180 | if (error == NULL) { |
| 8675 | 181 | msg = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
182 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), msg, size, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
183 | NULL, user->cancellable, &error); |
| 8675 | 184 | |
|
40765
a5381c20e802
Use specific purple_debug_* functions
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40146
diff
changeset
|
185 | purple_debug_info("novell", "Message is %s", msg); |
| 8675 | 186 | |
| 187 | /* Auto replies are not in RTF format! */ | |
| 188 | if (!autoreply) { | |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
189 | NMRtfContext *ctx; |
| 8675 | 190 | |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
191 | ctx = nm_rtf_init(); |
|
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
192 | nortf = nm_rtf_strip_formatting(ctx, msg); |
|
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
193 | nm_rtf_deinit(ctx); |
| 8675 | 194 | |
|
40765
a5381c20e802
Use specific purple_debug_* functions
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40146
diff
changeset
|
195 | purple_debug_info("novell", "Message without RTF is %s", nortf); |
| 8675 | 196 | |
| 197 | /* Store the event data */ | |
| 198 | nm_event_set_text(event, nortf); | |
| 199 | ||
| 200 | } else { | |
| 201 | ||
| 202 | /* Store the event data */ | |
| 203 | nm_event_set_text(event, msg); | |
| 204 | } | |
| 205 | } | |
| 206 | } | |
| 207 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
208 | if (error != NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
209 | if (error->code == G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
210 | rc = NM_OK; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
211 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
212 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
213 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
214 | g_error_free(error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
215 | return rc; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
216 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
217 | |
| 8675 | 218 | /* Check to see if we already know about the conference */ |
| 219 | conference = nm_conference_list_find(user, guid); | |
| 220 | if (conference) { | |
| 221 | ||
| 222 | nm_conference_set_flags(conference, flags); | |
| 223 | nm_event_set_conference(event, conference); | |
| 224 | ||
| 225 | /* Add a reference to the user record in our event object */ | |
| 226 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 227 | if (user_record) { | |
| 228 | nm_event_set_user_record(event, user_record); | |
| 229 | } | |
| 230 | ||
| 231 | } else { | |
| 232 | ||
| 233 | /* This is a new conference, so create one and add it to our list */ | |
| 234 | conference = nm_create_conference(guid); | |
| 235 | nm_conference_set_flags(conference, flags); | |
| 236 | ||
| 237 | /* Add a reference to the conference in the event */ | |
| 238 | nm_event_set_conference(event, conference); | |
| 239 | ||
| 240 | /* Add new conference to the conference list */ | |
| 241 | nm_conference_list_add(user, conference); | |
| 242 | ||
| 243 | /* Check to see if we have details for the event source yet */ | |
| 244 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 245 | if (user_record) { | |
| 246 | ||
| 247 | /* We do so add the user record as a recipient of the conference */ | |
| 248 | nm_conference_add_participant(conference, user_record); | |
| 249 | ||
| 250 | /* Add a reference to the user record in our event object */ | |
| 251 | nm_event_set_user_record(event, user_record); | |
| 252 | ||
| 253 | } else { | |
| 254 | ||
| 255 | /* Need to go to the server to get details for the user */ | |
| 256 | rc = nm_send_get_details(user, nm_event_get_source(event), | |
| 257 | _got_user_for_conference, event); | |
| 258 | if (rc == NM_OK) | |
| 259 | rc = -1; /* Not done processing the event yet! */ | |
| 260 | } | |
| 261 | ||
| 262 | nm_release_conference(conference); | |
| 263 | } | |
| 264 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
265 | g_free(msg); |
|
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
266 | g_free(nortf); |
|
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
267 | g_free(guid); |
| 8675 | 268 | |
| 269 | return rc; | |
| 270 | } | |
| 271 | ||
| 272 | /* Read the invite event, set up the event object, and | |
| 273 | * get details for the event source if we don't have them yet. | |
| 274 | */ | |
| 275 | static NMERR_T | |
| 276 | handle_conference_invite(NMUser * user, NMEvent * event) | |
| 277 | { | |
| 278 | NMERR_T rc = NM_OK; | |
| 279 | guint32 size = 0; | |
| 280 | char *guid = NULL; | |
| 281 | char *msg = NULL; | |
| 282 | NMConn *conn; | |
| 283 | NMUserRecord *user_record; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
284 | GError *error = NULL; |
| 8675 | 285 | |
| 286 | conn = nm_user_get_conn(user); | |
| 287 | ||
| 288 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
289 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
290 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
291 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
292 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
293 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
294 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
295 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
296 | if (error == NULL) { |
| 8675 | 297 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
298 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
299 | user->cancellable, &error); |
| 8675 | 300 | } |
| 301 | ||
| 302 | /* Read the the message */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
303 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
304 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
305 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
306 | if (size > 100000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
307 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
308 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
309 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
310 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
311 | if (error == NULL) { |
| 8675 | 312 | msg = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
313 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), msg, size, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
314 | NULL, user->cancellable, &error); |
| 8675 | 315 | } |
| 316 | } | |
| 317 | ||
| 318 | /* Store the event data */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
319 | if (error == NULL) { |
| 8675 | 320 | NMConference *conference; |
| 321 | ||
| 322 | nm_event_set_text(event, msg); | |
| 323 | ||
| 324 | conference = nm_conference_list_find(user, guid); | |
| 325 | if (conference == NULL) { | |
| 326 | conference = nm_create_conference(guid); | |
| 327 | ||
| 328 | /* Add new conference to the list and the event */ | |
| 329 | nm_conference_list_add(user, conference); | |
| 330 | nm_event_set_conference(event, conference); | |
| 331 | ||
| 332 | /* Check to see if we have details for the event source yet */ | |
| 333 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 334 | if (user_record) { | |
| 335 | ||
| 336 | /* Add a reference to the user record in our event object */ | |
| 337 | nm_event_set_user_record(event, user_record); | |
| 338 | ||
| 339 | } else { | |
| 340 | ||
| 341 | /* Need to go to the server to get details for the user */ | |
| 342 | rc = nm_send_get_details(user, nm_event_get_source(event), | |
| 343 | _got_user_for_event, event); | |
| 344 | if (rc == NM_OK) | |
| 345 | rc = -1; /* Not done processing the event yet! */ | |
| 346 | } | |
| 347 | ||
| 348 | nm_release_conference(conference); | |
| 349 | ||
| 350 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
351 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
352 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
353 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
354 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
355 | g_error_free(error); |
| 8675 | 356 | } |
| 357 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
358 | g_free(msg); |
|
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
359 | g_free(guid); |
| 8675 | 360 | |
| 361 | return rc; | |
| 362 | } | |
| 363 | ||
| 364 | /* Read the invite notify event, set up the event object, and | |
| 365 | * get details for the event source if we don't have them yet. | |
| 366 | */ | |
| 367 | static NMERR_T | |
| 368 | handle_conference_invite_notify(NMUser * user, NMEvent * event) | |
| 369 | { | |
| 370 | NMERR_T rc = NM_OK; | |
| 371 | guint32 size = 0; | |
| 372 | char *guid = NULL; | |
| 373 | NMConn *conn; | |
| 374 | NMConference *conference; | |
| 375 | NMUserRecord *user_record; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
376 | GError *error = NULL; |
| 8675 | 377 | |
| 378 | conn = nm_user_get_conn(user); | |
| 379 | ||
| 380 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
381 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
382 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
383 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
384 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
385 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
386 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
387 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
388 | if (error == NULL) { |
| 8675 | 389 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
390 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
391 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
392 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
393 | |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
394 | if (error != NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
395 | if (error->code == G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
396 | rc = NM_OK; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
397 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
398 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
399 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
400 | g_error_free(error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
401 | return rc; |
| 8675 | 402 | } |
| 403 | ||
| 404 | conference = nm_conference_list_find(user, guid); | |
| 405 | if (conference) { | |
| 406 | nm_event_set_conference(event, conference); | |
| 407 | ||
| 408 | /* Check to see if we have details for the event source yet */ | |
| 409 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 410 | if (user_record) { | |
| 411 | ||
| 412 | /* Add a reference to the user record in our event object */ | |
| 413 | nm_event_set_user_record(event, user_record); | |
| 414 | ||
| 415 | } else { | |
| 416 | ||
| 417 | /* Need to go to the server to get details for the user */ | |
| 418 | rc = nm_send_get_details(user, nm_event_get_source(event), | |
| 419 | _got_user_for_event, event); | |
| 420 | if (rc == NM_OK) | |
| 421 | rc = -1; /* Not done processing the event yet! */ | |
| 422 | } | |
| 423 | ||
| 424 | } else { | |
| 425 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 426 | } | |
| 427 | ||
| 428 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
429 | g_free(guid); |
| 8675 | 430 | |
| 431 | return rc; | |
| 432 | } | |
| 433 | ||
| 434 | /* Read the conference reject event and set up the event object */ | |
| 435 | static NMERR_T | |
| 436 | handle_conference_reject(NMUser * user, NMEvent * event) | |
| 437 | { | |
| 438 | NMERR_T rc = NM_OK; | |
| 439 | guint32 size = 0; | |
| 440 | char *guid = NULL; | |
| 441 | NMConn *conn; | |
| 442 | NMConference *conference; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
443 | GError *error = NULL; |
| 8675 | 444 | |
| 445 | conn = nm_user_get_conn(user); | |
| 446 | ||
| 447 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
448 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
449 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
450 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
451 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
452 | return NMERR_PROTOCOL; |
| 8675 | 453 | } |
| 454 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
455 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
456 | guid = g_new0(char, size + 1); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
457 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
458 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
459 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
460 | |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
461 | if (error == NULL) { |
| 8675 | 462 | conference = nm_conference_list_find(user, guid); |
| 463 | if (conference) { | |
| 464 | nm_event_set_conference(event, conference); | |
| 465 | } else { | |
| 466 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 467 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
468 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
469 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
470 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
471 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
472 | g_error_free(error); |
| 8675 | 473 | } |
| 474 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
475 | g_free(guid); |
| 8675 | 476 | |
| 477 | return rc; | |
| 478 | } | |
| 479 | ||
| 480 | /* Read the conference left event, set up the event object, and | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
481 | * remove the conference from the list if there are no more |
| 8675 | 482 | * participants |
| 483 | */ | |
| 484 | static NMERR_T | |
| 485 | handle_conference_left(NMUser * user, NMEvent * event) | |
| 486 | { | |
| 487 | NMERR_T rc = NM_OK; | |
| 488 | guint32 size = 0, flags = 0; | |
| 489 | char *guid = NULL; | |
| 490 | NMConference *conference; | |
| 491 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
492 | GError *error = NULL; |
| 8675 | 493 | |
| 494 | conn = nm_user_get_conn(user); | |
| 495 | ||
| 496 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
497 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
498 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
499 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
500 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
501 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
502 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
503 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
504 | if (error == NULL) { |
| 8675 | 505 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
506 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
507 | user->cancellable, &error); |
| 8675 | 508 | } |
| 509 | ||
| 510 | /* Read the conference flags */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
511 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
512 | flags = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
513 | &error); |
| 8675 | 514 | } |
| 515 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
516 | if (error == NULL) { |
| 8675 | 517 | conference = nm_conference_list_find(user, guid); |
| 518 | if (conference) { | |
| 519 | nm_event_set_conference(event, conference); | |
| 520 | nm_conference_set_flags(conference, flags); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
521 | |
| 8675 | 522 | nm_conference_remove_participant(conference, nm_event_get_source(event)); |
| 523 | if (nm_conference_get_participant_count(conference) == 0) { | |
| 524 | nm_conference_list_remove(user, conference); | |
| 525 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
526 | |
| 8675 | 527 | } else { |
| 528 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 529 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
530 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
531 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
532 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
533 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
534 | g_error_free(error); |
| 8675 | 535 | } |
| 536 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
537 | g_free(guid); |
| 8675 | 538 | |
| 539 | return rc; | |
| 540 | } | |
| 541 | ||
| 542 | /* Read the conference closed, set up the event object, and | |
| 543 | * remove the conference from the list | |
| 544 | */ | |
| 545 | static NMERR_T | |
| 546 | handle_conference_closed(NMUser * user, NMEvent * event) | |
| 547 | { | |
| 548 | NMERR_T rc = NM_OK; | |
| 549 | guint32 size = 0; | |
| 550 | char *guid = NULL; | |
| 551 | NMConference *conference; | |
| 552 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
553 | GError *error = NULL; |
| 8675 | 554 | |
| 555 | conn = nm_user_get_conn(user); | |
| 556 | ||
| 557 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
558 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
559 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
560 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
561 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
562 | return NMERR_PROTOCOL; |
| 8675 | 563 | } |
| 564 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
565 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
566 | guid = g_new0(char, size + 1); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
567 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
568 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
569 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
570 | |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
571 | if (error == NULL) { |
| 8675 | 572 | conference = nm_conference_list_find(user, guid); |
| 573 | if (conference) { | |
| 574 | nm_event_set_conference(event, conference); | |
| 575 | nm_conference_list_remove(user, conference); | |
| 576 | } else { | |
| 577 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 578 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
579 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
580 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
581 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
582 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
583 | g_error_free(error); |
| 8675 | 584 | } |
| 585 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
586 | g_free(guid); |
| 8675 | 587 | |
| 588 | return rc; | |
| 589 | } | |
| 590 | ||
| 591 | /* Read the conference joined event, set up the event object, and | |
| 592 | * get details for the event source if we don't have them yet. | |
| 593 | */ | |
| 594 | static NMERR_T | |
| 595 | handle_conference_joined(NMUser * user, NMEvent * event) | |
| 596 | { | |
| 597 | NMERR_T rc = NM_OK; | |
| 598 | guint32 size = 0, flags = 0; | |
| 599 | char *guid = NULL; | |
| 600 | NMConn *conn; | |
| 601 | NMConference *conference; | |
| 602 | NMUserRecord *user_record; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
603 | GError *error = NULL; |
| 8675 | 604 | |
| 605 | conn = nm_user_get_conn(user); | |
| 606 | ||
| 607 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
608 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
609 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
610 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
611 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
612 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
613 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
614 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
615 | if (error == NULL) { |
| 8675 | 616 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
617 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
618 | user->cancellable, &error); |
| 8675 | 619 | } |
| 620 | ||
| 621 | /* Read the conference flags */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
622 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
623 | flags = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
624 | &error); |
| 8675 | 625 | } |
| 626 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
627 | if (error == NULL) { |
| 8675 | 628 | conference = nm_conference_list_find(user, guid); |
| 629 | if (conference) { | |
| 630 | nm_conference_set_flags(conference, flags); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
631 | |
| 8675 | 632 | nm_event_set_conference(event, conference); |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
633 | |
| 8675 | 634 | /* Add the new user to the participants list */ |
| 635 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 636 | if (user_record) { | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
637 | nm_conference_remove_participant(conference, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
638 | nm_user_record_get_dn(user_record)); |
| 8675 | 639 | nm_conference_add_participant(conference, user_record); |
| 640 | } else { | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
641 | |
| 8675 | 642 | /* Need to go to the server to get details for the user */ |
| 643 | rc = nm_send_get_details(user, nm_event_get_source(event), | |
| 644 | _got_user_for_conference, event); | |
| 645 | if (rc == NM_OK) | |
| 646 | rc = -1; /* Not done processing the event yet! */ | |
| 647 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
648 | |
| 8675 | 649 | } else { |
| 650 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 651 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
652 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
653 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
654 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
655 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
656 | g_error_free(error); |
| 8675 | 657 | } |
| 658 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
659 | g_free(guid); |
| 8675 | 660 | |
| 661 | return rc; | |
| 662 | } | |
| 663 | ||
| 664 | /* Read the typing event and set up the event object */ | |
| 665 | static NMERR_T | |
| 666 | handle_typing(NMUser * user, NMEvent * event) | |
| 667 | { | |
| 668 | NMERR_T rc = NM_OK; | |
| 669 | guint32 size = 0; | |
| 670 | char *guid = NULL; | |
| 671 | NMConference *conference; | |
| 672 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
673 | GError *error = NULL; |
| 8675 | 674 | |
| 675 | conn = nm_user_get_conn(user); | |
| 676 | ||
| 677 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
678 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
679 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
680 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
681 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
682 | return NMERR_PROTOCOL; |
| 8675 | 683 | } |
| 684 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
685 | if (error == NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
686 | guid = g_new0(char, size + 1); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
687 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
688 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
689 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
690 | |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
691 | if (error == NULL) { |
| 8675 | 692 | conference = nm_conference_list_find(user, guid); |
| 693 | if (conference) { | |
| 694 | nm_event_set_conference(event, conference); | |
| 695 | } else { | |
| 696 | rc = NMERR_CONFERENCE_NOT_FOUND; | |
| 697 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
698 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
699 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
700 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
701 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
702 | g_error_free(error); |
| 8675 | 703 | } |
| 704 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
705 | g_free(guid); |
| 8675 | 706 | |
| 707 | return rc; | |
| 708 | } | |
| 709 | ||
| 710 | /* Read the event, set up the event object, and update | |
| 711 | * the status in the user record (for the event source) | |
| 712 | */ | |
| 713 | static NMERR_T | |
| 714 | handle_status_change(NMUser * user, NMEvent * event) | |
| 715 | { | |
| 716 | NMERR_T rc = NM_OK; | |
| 717 | guint16 status; | |
| 718 | guint32 size; | |
| 719 | char *text = NULL; | |
| 720 | NMUserRecord *user_record; | |
| 721 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
722 | GError *error = NULL; |
| 8675 | 723 | |
| 724 | conn = nm_user_get_conn(user); | |
| 725 | ||
| 726 | /* Read new status */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
727 | status = g_data_input_stream_read_uint16(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
728 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
729 | if (error == NULL) { |
| 8675 | 730 | |
| 731 | /* Read the status text */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
732 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
733 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
734 | if (size > 10000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
735 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
736 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
737 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
738 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
739 | if (error == NULL) { |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
740 | text = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
741 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), text, size, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
742 | NULL, user->cancellable, &error); |
| 8675 | 743 | } |
| 744 | } | |
| 745 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
746 | if (error == NULL) { |
| 8675 | 747 | nm_event_set_text(event, text); |
| 748 | ||
| 749 | /* Get a reference to the user record and store the new status */ | |
| 750 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 751 | if (user_record) { | |
| 752 | nm_event_set_user_record(event, user_record); | |
| 753 | nm_user_record_set_status(user_record, status, text); | |
| 754 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
755 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
756 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
757 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
758 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
759 | g_error_free(error); |
| 8675 | 760 | } |
| 761 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
762 | g_free(text); |
| 8675 | 763 | |
| 764 | return rc; | |
| 765 | } | |
| 766 | ||
| 767 | /* Read the undeliverable event */ | |
| 768 | static NMERR_T | |
| 769 | handle_undeliverable_status(NMUser * user, NMEvent * event) | |
| 770 | { | |
| 771 | NMERR_T rc = NM_OK; | |
| 772 | guint32 size = 0; | |
| 773 | char *guid = NULL; | |
| 774 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
775 | GError *error = NULL; |
| 8675 | 776 | |
| 777 | conn = nm_user_get_conn(user); | |
| 778 | ||
| 779 | /* Read the conference guid */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
780 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
781 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
782 | if (size > 1000) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
783 | g_clear_error(&error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
784 | return NMERR_PROTOCOL; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
785 | } |
|
9839
6eb627432e0c
[gaim-migrate @ 10716]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
786 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
787 | if (error == NULL) { |
| 8675 | 788 | guid = g_new0(char, size + 1); |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
789 | rc = g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
790 | NULL, user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
791 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
792 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
793 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
794 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
795 | g_error_free(error); |
| 8675 | 796 | } |
| 797 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
798 | g_free(guid); |
| 8675 | 799 | |
| 800 | return rc; | |
| 801 | } | |
| 802 | ||
| 803 | /******************************************************************************* | |
| 804 | * Event API -- see header file for comments | |
| 805 | ******************************************************************************/ | |
| 806 | ||
| 807 | NMEvent * | |
| 808 | nm_create_event(int type, const char *source, guint32 gmt) | |
| 809 | { | |
| 810 | NMEvent *event = g_new0(NMEvent, 1); | |
| 811 | ||
| 812 | event->type = type; | |
| 813 | event->gmt = gmt; | |
| 814 | ||
| 815 | if (source) | |
| 816 | event->source = g_strdup(source); | |
| 817 | ||
| 818 | event->ref_count = 1; | |
| 819 | ||
| 820 | return event; | |
| 821 | } | |
| 822 | ||
| 823 | void | |
| 824 | nm_release_event(NMEvent * event) | |
| 825 | { | |
| 826 | if (event == NULL) { | |
| 827 | return; | |
| 828 | } | |
| 829 | ||
| 830 | if (--(event->ref_count) == 0) { | |
| 831 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
832 | g_free(event->source); |
| 8675 | 833 | |
| 834 | if (event->conference) | |
| 835 | nm_release_conference(event->conference); | |
| 836 | ||
| 837 | if (event->user_record) | |
| 838 | nm_release_user_record(event->user_record); | |
| 839 | ||
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
840 | g_free(event->text); |
| 8675 | 841 | |
| 842 | g_free(event); | |
| 843 | } | |
| 844 | } | |
| 845 | ||
| 846 | ||
| 847 | NMConference * | |
| 848 | nm_event_get_conference(NMEvent * event) | |
| 849 | { | |
| 850 | if (event) | |
| 851 | return event->conference; | |
| 852 | else | |
| 853 | return NULL; | |
| 854 | } | |
| 855 | ||
| 856 | void | |
| 857 | nm_event_set_conference(NMEvent * event, NMConference * conference) | |
| 858 | { | |
| 859 | if (event && conference) { | |
| 860 | nm_conference_add_ref(conference); | |
| 861 | event->conference = conference; | |
| 862 | } | |
| 863 | } | |
| 864 | ||
| 865 | NMUserRecord * | |
| 866 | nm_event_get_user_record(NMEvent * event) | |
| 867 | { | |
| 868 | if (event) | |
| 869 | return event->user_record; | |
| 870 | else | |
| 871 | return NULL; | |
| 872 | } | |
| 873 | ||
| 874 | void | |
| 875 | nm_event_set_user_record(NMEvent * event, NMUserRecord * user_record) | |
| 876 | { | |
| 877 | if (event && user_record) { | |
| 878 | nm_user_record_add_ref(user_record); | |
| 879 | event->user_record = user_record; | |
| 880 | } | |
| 881 | } | |
| 882 | ||
| 883 | const char * | |
| 884 | nm_event_get_text(NMEvent * event) | |
| 885 | { | |
| 886 | if (event) | |
| 887 | return event->text; | |
| 888 | else | |
| 889 | return NULL; | |
| 890 | } | |
| 891 | ||
| 892 | void | |
| 893 | nm_event_set_text(NMEvent * event, const char *text) | |
| 894 | { | |
| 895 | if (event) { | |
| 896 | if (text) | |
| 897 | event->text = g_strdup(text); | |
| 898 | else | |
| 899 | event->text = NULL; | |
| 900 | } | |
| 901 | } | |
| 902 | ||
| 903 | const char * | |
| 904 | nm_event_get_source(NMEvent * event) | |
| 905 | { | |
| 906 | if (event) | |
| 907 | return event->source; | |
| 908 | else | |
| 909 | return NULL; | |
| 910 | } | |
| 911 | ||
| 912 | int | |
| 913 | nm_event_get_type(NMEvent * event) | |
| 914 | { | |
| 915 | if (event) | |
| 916 | return event->type; | |
| 917 | else | |
| 918 | return -1; | |
| 919 | } | |
| 920 | ||
| 13120 | 921 | time_t |
| 8675 | 922 | nm_event_get_gmt(NMEvent * event) |
| 923 | { | |
| 924 | if (event) | |
| 925 | return event->gmt; | |
| 926 | else | |
| 13120 | 927 | return (time_t)-1; |
| 8675 | 928 | } |
| 929 | ||
| 930 | NMERR_T | |
| 931 | nm_process_event(NMUser * user, int type) | |
| 932 | { | |
| 933 | NMERR_T rc = NM_OK; | |
| 934 | guint32 size = 0; | |
| 935 | NMEvent *event = NULL; | |
| 936 | char *source = NULL; | |
| 937 | nm_event_cb cb; | |
| 938 | NMConn *conn; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
939 | GError *error = NULL; |
| 8675 | 940 | |
| 941 | if (user == NULL) | |
| 942 | return NMERR_BAD_PARM; | |
| 943 | ||
| 944 | if (type < NMEVT_START || type > NMEVT_STOP) | |
| 945 | return NMERR_PROTOCOL; | |
| 946 | ||
| 947 | conn = nm_user_get_conn(user); | |
| 948 | ||
| 949 | /* Read the event source */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
950 | size = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
951 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
952 | if (error == NULL) { |
|
36180
44fd89158777
In Novell Groupwise, fix potential remote crash parsing server message
Mark Doliner <mark@kingant.net>
parents:
19859
diff
changeset
|
953 | if (size > 1000000) { |
|
44fd89158777
In Novell Groupwise, fix potential remote crash parsing server message
Mark Doliner <mark@kingant.net>
parents:
19859
diff
changeset
|
954 | /* Size is larger than our 1MB sanity check. Ignore it. */ |
|
44fd89158777
In Novell Groupwise, fix potential remote crash parsing server message
Mark Doliner <mark@kingant.net>
parents:
19859
diff
changeset
|
955 | rc = NMERR_PROTOCOL; |
|
44fd89158777
In Novell Groupwise, fix potential remote crash parsing server message
Mark Doliner <mark@kingant.net>
parents:
19859
diff
changeset
|
956 | } else { |
| 8675 | 957 | source = g_new0(char, size); |
| 958 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
959 | rc = g_input_stream_read_all(G_INPUT_STREAM(conn->input), source, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
960 | size, NULL, user->cancellable, &error); |
| 8675 | 961 | } |
| 962 | } | |
| 963 | ||
| 964 | /* Read the event data */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
965 | if (error == NULL) { |
| 8675 | 966 | event = nm_create_event(type, source, time(0)); |
| 967 | ||
| 968 | if (event) { | |
| 969 | ||
| 970 | switch (type) { | |
| 971 | case NMEVT_STATUS_CHANGE: | |
| 972 | rc = handle_status_change(user, event); | |
| 973 | break; | |
| 974 | ||
| 975 | case NMEVT_RECEIVE_MESSAGE: | |
| 976 | rc = handle_receive_message(user, event, FALSE); | |
| 977 | break; | |
| 978 | ||
| 979 | case NMEVT_RECEIVE_AUTOREPLY: | |
| 980 | rc = handle_receive_message(user, event, TRUE); | |
| 981 | break; | |
| 982 | ||
| 983 | case NMEVT_USER_TYPING: | |
| 984 | case NMEVT_USER_NOT_TYPING: | |
| 985 | rc = handle_typing(user, event); | |
| 986 | break; | |
| 987 | ||
| 988 | case NMEVT_CONFERENCE_LEFT: | |
| 989 | rc = handle_conference_left(user, event); | |
| 990 | break; | |
| 991 | ||
| 992 | case NMEVT_CONFERENCE_CLOSED: | |
| 993 | rc = handle_conference_closed(user, event); | |
| 994 | break; | |
| 995 | ||
| 996 | case NMEVT_CONFERENCE_JOINED: | |
| 997 | rc = handle_conference_joined(user, event); | |
| 998 | break; | |
| 999 | ||
| 1000 | case NMEVT_CONFERENCE_INVITE: | |
| 1001 | rc = handle_conference_invite(user, event); | |
| 1002 | break; | |
| 1003 | ||
| 1004 | case NMEVT_CONFERENCE_REJECT: | |
| 1005 | rc = handle_conference_reject(user, event); | |
| 1006 | break; | |
| 1007 | ||
| 1008 | case NMEVT_CONFERENCE_INVITE_NOTIFY: | |
| 1009 | rc = handle_conference_invite_notify(user, event); | |
| 1010 | break; | |
| 1011 | ||
| 1012 | case NMEVT_UNDELIVERABLE_STATUS: | |
| 1013 | rc = handle_undeliverable_status(user, event); | |
| 1014 | break; | |
| 1015 | ||
| 1016 | case NMEVT_INVALID_RECIPIENT: | |
| 1017 | /* Nothing else to read, just callback */ | |
| 1018 | break; | |
| 1019 | ||
| 1020 | case NMEVT_USER_DISCONNECT: | |
| 1021 | /* Nothing else to read, just callback */ | |
| 1022 | break; | |
| 1023 | ||
| 1024 | case NMEVT_SERVER_DISCONNECT: | |
| 1025 | /* Nothing else to read, just callback */ | |
| 1026 | break; | |
| 1027 | ||
| 1028 | case NMEVT_RECEIVE_FILE: | |
| 1029 | case NMEVT_CONTACT_ADD: | |
| 1030 | /* Safely ignored for now */ | |
| 1031 | break; | |
| 1032 | ||
| 1033 | default: | |
|
40765
a5381c20e802
Use specific purple_debug_* functions
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40146
diff
changeset
|
1034 | purple_debug_info("novell", "Unknown event %d received.", type); |
| 8675 | 1035 | rc = NMERR_PROTOCOL; |
| 1036 | break; | |
| 1037 | } | |
| 1038 | } | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
1039 | } else { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
1040 | if (error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
1041 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
1042 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37425
diff
changeset
|
1043 | g_error_free(error); |
| 8675 | 1044 | } |
| 1045 | ||
| 1046 | if (rc == (NMERR_T)-1) { | |
| 1047 | /* -1 means that we are not ready to callback yet. */ | |
| 1048 | rc = NM_OK; | |
| 1049 | } else if (rc == NM_OK && (cb = nm_user_get_event_callback(user))) { | |
| 1050 | cb(user, event); | |
|
40146
66604f791698
Fix some possible leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
1051 | } |
| 8675 | 1052 | |
|
40146
66604f791698
Fix some possible leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
1053 | if (event) { |
|
66604f791698
Fix some possible leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
1054 | nm_release_event(event); |
| 8675 | 1055 | } |
| 1056 | ||
| 1057 | /* Cleanup */ | |
|
37425
5061721fd98f
Remove more NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents:
36180
diff
changeset
|
1058 | g_free(source); |
| 8675 | 1059 | |
| 1060 | return rc; | |
| 1061 | } |