Mercurial > pidgin
annotate src/protocols/novell/nmevent.c @ 9820:fa8111c03283
[gaim-migrate @ 10691]
Nicer looking info display from Mike Stoddard of Novell
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 22 Aug 2004 17:13:05 +0000 |
parents | 54fb1f466953 |
children | 96e98bb4ded5 |
rev | line source |
---|---|
8675 | 1 /* |
2 * nmevent.c | |
3 * | |
8933 | 4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; version 2 of the License. | |
8675 | 9 * |
8933 | 10 * This program 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 | |
13 * GNU General Public License for more details. | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 * |
8933 | 15 * You should have received a copy of the GNU General Public License |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 | 28 #include "nmrtf.h" |
8675 | 29 |
30 struct _NMEvent | |
31 { | |
32 | |
33 /* Event type */ | |
34 int type; | |
35 | |
36 /* The DN of the event source */ | |
37 char *source; | |
38 | |
39 /* Timestamp of the event */ | |
40 guint32 gmt; | |
41 | |
42 /* Conference to associate with the event */ | |
43 NMConference *conference; | |
44 | |
45 /* User record to associate with the event */ | |
46 NMUserRecord *user_record; | |
47 | |
48 /* Text associated with the event */ | |
49 char *text; | |
50 | |
51 /* Reference count for event structure */ | |
52 int ref_count; | |
53 | |
54 }; | |
55 | |
56 /* Handle getdetails response and set the new user record into the event */ | |
57 static void | |
58 _got_user_for_event(NMUser * user, NMERR_T ret_val, | |
59 gpointer resp_data, gpointer user_data) | |
60 { | |
61 NMUserRecord *user_record; | |
62 NMEvent *event; | |
63 nm_event_cb cb; | |
64 | |
65 if (user == NULL) | |
66 return; | |
67 | |
68 user_record = resp_data; | |
69 event = user_data; | |
70 | |
71 if (ret_val == NM_OK) { | |
72 if (event && user_record) { | |
73 | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
74 /* Add the user record to the event structure |
8675 | 75 * and make the callback. |
76 */ | |
77 nm_event_set_user_record(event, user_record); | |
78 if ((cb = nm_user_get_event_callback(user))) { | |
79 cb(user, event); | |
80 } | |
81 } | |
82 | |
83 } else { | |
84 /* Cleanup resp_data */ | |
85 | |
86 } | |
87 | |
88 /* Clean up */ | |
89 if (event) | |
90 nm_release_event(event); | |
91 | |
92 } | |
93 | |
94 /* Handle getdetails response, set the new user record into the event | |
95 * and add the user record as a participant in the conference | |
96 */ | |
97 static void | |
98 _got_user_for_conference(NMUser * user, NMERR_T ret_val, | |
99 gpointer resp_data, gpointer user_data) | |
100 { | |
101 NMUserRecord *user_record = resp_data; | |
102 NMEvent *event = user_data; | |
103 NMConference *conference; | |
104 nm_event_cb cb; | |
105 | |
106 if (user == NULL) | |
107 return; | |
108 | |
109 if (event && user_record) { | |
110 | |
111 conference = nm_event_get_conference(event); | |
112 if (conference) { | |
113 | |
114 /* Add source of event as recip of the conference */ | |
115 nm_conference_add_participant(conference, user_record); | |
116 | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
117 /* Add the user record to the event structure |
8675 | 118 * and make the callback. |
119 */ | |
120 nm_event_set_user_record(event, user_record); | |
121 if ((cb = nm_user_get_event_callback(user))) { | |
122 cb(user, event); | |
123 } | |
124 } | |
125 } | |
126 | |
127 if (event) | |
128 nm_release_event(event); | |
129 } | |
130 | |
131 /* Read the receive message event, set up the event object, and | |
132 * get details for the event source if we don't have them yet. | |
133 */ | |
134 static NMERR_T | |
135 handle_receive_message(NMUser * user, NMEvent * event, gboolean autoreply) | |
136 { | |
137 NMConference *conference; | |
138 NMUserRecord *user_record; | |
139 NMConn *conn; | |
140 NMERR_T rc = NM_OK; | |
141 guint32 size = 0, flags = 0; | |
142 char *msg = NULL; | |
143 char *nortf = NULL; | |
144 char *guid = NULL; | |
145 | |
146 conn = nm_user_get_conn(user); | |
147 | |
148 /* Read the conference guid */ | |
8874 | 149 rc = nm_read_uint32(conn, &size); |
8675 | 150 if (rc == NM_OK) { |
151 guid = g_new0(char, size + 1); | |
152 rc = nm_read_all(conn, guid, size); | |
153 } | |
154 | |
155 /* Read the conference flags */ | |
156 if (rc == NM_OK) { | |
8874 | 157 rc = nm_read_uint32(conn, &flags); |
8675 | 158 } |
159 | |
160 /* Read the message text */ | |
161 if (rc == NM_OK) { | |
8874 | 162 rc = nm_read_uint32(conn, &size); |
8675 | 163 if (rc == NM_OK) { |
164 | |
165 msg = g_new0(char, size + 1); | |
166 rc = nm_read_all(conn, msg, size); | |
167 | |
168 gaim_debug(GAIM_DEBUG_INFO, "novell", "Message is %s\n", msg); | |
169 | |
170 /* Auto replies are not in RTF format! */ | |
171 if (!autoreply) { | |
9268 | 172 NMRtfContext *ctx; |
8675 | 173 |
9268 | 174 ctx = nm_rtf_init(); |
175 nortf = nm_rtf_strip_formatting(ctx, msg); | |
176 nm_rtf_deinit(ctx); | |
8675 | 177 |
178 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
179 "Message without RTF is %s\n", nortf); | |
180 | |
181 /* Store the event data */ | |
182 nm_event_set_text(event, nortf); | |
183 | |
184 } else { | |
185 | |
186 /* Store the event data */ | |
187 nm_event_set_text(event, msg); | |
188 } | |
189 } | |
190 } | |
191 | |
192 /* Check to see if we already know about the conference */ | |
193 conference = nm_conference_list_find(user, guid); | |
194 if (conference) { | |
195 | |
196 nm_conference_set_flags(conference, flags); | |
197 nm_event_set_conference(event, conference); | |
198 | |
199 /* Add a reference to the user record in our event object */ | |
200 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
201 if (user_record) { | |
202 nm_event_set_user_record(event, user_record); | |
203 } | |
204 | |
205 } else { | |
206 | |
207 /* This is a new conference, so create one and add it to our list */ | |
208 conference = nm_create_conference(guid); | |
209 nm_conference_set_flags(conference, flags); | |
210 | |
211 /* Add a reference to the conference in the event */ | |
212 nm_event_set_conference(event, conference); | |
213 | |
214 /* Add new conference to the conference list */ | |
215 nm_conference_list_add(user, conference); | |
216 | |
217 /* Check to see if we have details for the event source yet */ | |
218 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
219 if (user_record) { | |
220 | |
221 /* We do so add the user record as a recipient of the conference */ | |
222 nm_conference_add_participant(conference, user_record); | |
223 | |
224 /* Add a reference to the user record in our event object */ | |
225 nm_event_set_user_record(event, user_record); | |
226 | |
227 } else { | |
228 | |
229 /* Need to go to the server to get details for the user */ | |
230 rc = nm_send_get_details(user, nm_event_get_source(event), | |
231 _got_user_for_conference, event); | |
232 if (rc == NM_OK) | |
233 rc = -1; /* Not done processing the event yet! */ | |
234 } | |
235 | |
236 nm_release_conference(conference); | |
237 } | |
238 | |
239 if (msg) | |
240 g_free(msg); | |
241 | |
242 if (nortf) | |
243 g_free(nortf); | |
244 | |
245 if (guid) | |
246 g_free(guid); | |
247 | |
248 return rc; | |
249 } | |
250 | |
251 /* Read the invite event, set up the event object, and | |
252 * get details for the event source if we don't have them yet. | |
253 */ | |
254 static NMERR_T | |
255 handle_conference_invite(NMUser * user, NMEvent * event) | |
256 { | |
257 NMERR_T rc = NM_OK; | |
258 guint32 size = 0; | |
259 char *guid = NULL; | |
260 char *msg = NULL; | |
261 NMConn *conn; | |
262 NMUserRecord *user_record; | |
263 | |
264 conn = nm_user_get_conn(user); | |
265 | |
266 /* Read the conference guid */ | |
8874 | 267 rc = nm_read_uint32(conn, &size); |
8675 | 268 if (rc == NM_OK) { |
269 guid = g_new0(char, size + 1); | |
270 rc = nm_read_all(conn, guid, size); | |
271 } | |
272 | |
273 /* Read the the message */ | |
274 if (rc == NM_OK) { | |
8874 | 275 rc = nm_read_uint32(conn, &size); |
8675 | 276 if (rc == NM_OK) { |
277 msg = g_new0(char, size + 1); | |
278 rc = nm_read_all(conn, msg, size); | |
279 } | |
280 } | |
281 | |
282 /* Store the event data */ | |
283 if (rc == NM_OK) { | |
284 NMConference *conference; | |
285 | |
286 nm_event_set_text(event, msg); | |
287 | |
288 conference = nm_conference_list_find(user, guid); | |
289 if (conference == NULL) { | |
290 conference = nm_create_conference(guid); | |
291 | |
292 /* Add new conference to the list and the event */ | |
293 nm_conference_list_add(user, conference); | |
294 nm_event_set_conference(event, conference); | |
295 | |
296 /* Check to see if we have details for the event source yet */ | |
297 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
298 if (user_record) { | |
299 | |
300 /* Add a reference to the user record in our event object */ | |
301 nm_event_set_user_record(event, user_record); | |
302 | |
303 } else { | |
304 | |
305 /* Need to go to the server to get details for the user */ | |
306 rc = nm_send_get_details(user, nm_event_get_source(event), | |
307 _got_user_for_event, event); | |
308 if (rc == NM_OK) | |
309 rc = -1; /* Not done processing the event yet! */ | |
310 } | |
311 | |
312 nm_release_conference(conference); | |
313 | |
314 } | |
315 } | |
316 | |
317 if (msg) | |
318 g_free(msg); | |
319 | |
320 if (guid) | |
321 g_free(guid); | |
322 | |
323 return rc; | |
324 } | |
325 | |
326 /* Read the invite notify event, set up the event object, and | |
327 * get details for the event source if we don't have them yet. | |
328 */ | |
329 static NMERR_T | |
330 handle_conference_invite_notify(NMUser * user, NMEvent * event) | |
331 { | |
332 NMERR_T rc = NM_OK; | |
333 guint32 size = 0; | |
334 char *guid = NULL; | |
335 NMConn *conn; | |
336 NMConference *conference; | |
337 NMUserRecord *user_record; | |
338 | |
339 conn = nm_user_get_conn(user); | |
340 | |
341 /* Read the conference guid */ | |
8874 | 342 rc = nm_read_uint32(conn, &size); |
8675 | 343 if (rc == NM_OK) { |
344 guid = g_new0(char, size + 1); | |
345 rc = nm_read_all(conn, guid, size); | |
346 } | |
347 | |
348 conference = nm_conference_list_find(user, guid); | |
349 if (conference) { | |
350 nm_event_set_conference(event, conference); | |
351 | |
352 /* Check to see if we have details for the event source yet */ | |
353 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
354 if (user_record) { | |
355 | |
356 /* Add a reference to the user record in our event object */ | |
357 nm_event_set_user_record(event, user_record); | |
358 | |
359 } else { | |
360 | |
361 /* Need to go to the server to get details for the user */ | |
362 rc = nm_send_get_details(user, nm_event_get_source(event), | |
363 _got_user_for_event, event); | |
364 if (rc == NM_OK) | |
365 rc = -1; /* Not done processing the event yet! */ | |
366 } | |
367 | |
368 } else { | |
369 rc = NMERR_CONFERENCE_NOT_FOUND; | |
370 } | |
371 | |
372 | |
373 if (guid) | |
374 g_free(guid); | |
375 | |
376 return rc; | |
377 } | |
378 | |
379 /* Read the conference reject event and set up the event object */ | |
380 static NMERR_T | |
381 handle_conference_reject(NMUser * user, NMEvent * event) | |
382 { | |
383 NMERR_T rc = NM_OK; | |
384 guint32 size = 0; | |
385 char *guid = NULL; | |
386 NMConn *conn; | |
387 NMConference *conference; | |
388 | |
389 conn = nm_user_get_conn(user); | |
390 | |
391 /* Read the conference guid */ | |
8874 | 392 rc = nm_read_uint32(conn, &size); |
8675 | 393 if (rc == NM_OK) { |
394 guid = g_new0(char, size + 1); | |
395 rc = nm_read_all(conn, guid, size); | |
396 } | |
397 | |
398 if (rc == NM_OK) { | |
399 conference = nm_conference_list_find(user, guid); | |
400 if (conference) { | |
401 nm_event_set_conference(event, conference); | |
402 } else { | |
403 rc = NMERR_CONFERENCE_NOT_FOUND; | |
404 } | |
405 } | |
406 | |
407 if (guid) | |
408 g_free(guid); | |
409 | |
410 return rc; | |
411 } | |
412 | |
413 /* Read the conference left event, set up the event object, and | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
414 * remove the conference from the list if there are no more |
8675 | 415 * participants |
416 */ | |
417 static NMERR_T | |
418 handle_conference_left(NMUser * user, NMEvent * event) | |
419 { | |
420 NMERR_T rc = NM_OK; | |
421 guint32 size = 0, flags = 0; | |
422 char *guid = NULL; | |
423 NMConference *conference; | |
424 NMConn *conn; | |
425 | |
426 conn = nm_user_get_conn(user); | |
427 | |
428 /* Read the conference guid */ | |
8874 | 429 rc = nm_read_uint32(conn, &size); |
8675 | 430 if (rc == NM_OK) { |
431 guid = g_new0(char, size + 1); | |
432 rc = nm_read_all(conn, guid, size); | |
433 } | |
434 | |
435 /* Read the conference flags */ | |
436 if (rc == NM_OK) { | |
8874 | 437 rc = nm_read_uint32(conn, &flags); |
8675 | 438 } |
439 | |
440 if (rc == NM_OK) { | |
441 conference = nm_conference_list_find(user, guid); | |
442 if (conference) { | |
443 nm_event_set_conference(event, conference); | |
444 nm_conference_set_flags(conference, flags); | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
445 |
8675 | 446 nm_conference_remove_participant(conference, nm_event_get_source(event)); |
447 if (nm_conference_get_participant_count(conference) == 0) { | |
448 nm_conference_list_remove(user, conference); | |
449 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
450 |
8675 | 451 } else { |
452 rc = NMERR_CONFERENCE_NOT_FOUND; | |
453 } | |
454 } | |
455 | |
456 if (guid) | |
457 g_free(guid); | |
458 | |
459 return rc; | |
460 } | |
461 | |
462 /* Read the conference closed, set up the event object, and | |
463 * remove the conference from the list | |
464 */ | |
465 static NMERR_T | |
466 handle_conference_closed(NMUser * user, NMEvent * event) | |
467 { | |
468 NMERR_T rc = NM_OK; | |
469 guint32 size = 0; | |
470 char *guid = NULL; | |
471 NMConference *conference; | |
472 NMConn *conn; | |
473 | |
474 conn = nm_user_get_conn(user); | |
475 | |
476 /* Read the conference guid */ | |
8874 | 477 rc = nm_read_uint32(conn, &size); |
8675 | 478 if (rc == NM_OK) { |
479 guid = g_new0(char, size + 1); | |
480 rc = nm_read_all(conn, guid, size); | |
481 } | |
482 | |
483 if (rc == NM_OK) { | |
484 conference = nm_conference_list_find(user, guid); | |
485 if (conference) { | |
486 nm_event_set_conference(event, conference); | |
487 nm_conference_list_remove(user, conference); | |
488 } else { | |
489 rc = NMERR_CONFERENCE_NOT_FOUND; | |
490 } | |
491 } | |
492 | |
493 if (guid) | |
494 g_free(guid); | |
495 | |
496 return rc; | |
497 } | |
498 | |
499 /* Read the conference joined event, set up the event object, and | |
500 * get details for the event source if we don't have them yet. | |
501 */ | |
502 static NMERR_T | |
503 handle_conference_joined(NMUser * user, NMEvent * event) | |
504 { | |
505 NMERR_T rc = NM_OK; | |
506 guint32 size = 0, flags = 0; | |
507 char *guid = NULL; | |
508 NMConn *conn; | |
509 NMConference *conference; | |
510 NMUserRecord *user_record; | |
511 | |
512 conn = nm_user_get_conn(user); | |
513 | |
514 /* Read the conference guid */ | |
8874 | 515 rc = nm_read_uint32(conn, &size); |
8675 | 516 if (rc == NM_OK) { |
517 guid = g_new0(char, size + 1); | |
518 rc = nm_read_all(conn, guid, size); | |
519 } | |
520 | |
521 /* Read the conference flags */ | |
522 if (rc == NM_OK) { | |
8874 | 523 rc = nm_read_uint32(conn, &flags); |
8675 | 524 } |
525 | |
526 if (rc == NM_OK) { | |
527 conference = nm_conference_list_find(user, guid); | |
528 if (conference) { | |
529 nm_conference_set_flags(conference, flags); | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
530 |
8675 | 531 nm_event_set_conference(event, conference); |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
532 |
8675 | 533 /* Add the new user to the participants list */ |
534 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
535 if (user_record) { | |
8933 | 536 nm_conference_remove_participant(conference, |
537 nm_user_record_get_dn(user_record)); | |
8675 | 538 nm_conference_add_participant(conference, user_record); |
539 } else { | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
540 |
8675 | 541 /* Need to go to the server to get details for the user */ |
542 rc = nm_send_get_details(user, nm_event_get_source(event), | |
543 _got_user_for_conference, event); | |
544 if (rc == NM_OK) | |
545 rc = -1; /* Not done processing the event yet! */ | |
546 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
547 |
8675 | 548 } else { |
549 rc = NMERR_CONFERENCE_NOT_FOUND; | |
550 } | |
551 } | |
552 | |
553 if (guid) | |
554 g_free(guid); | |
555 | |
556 return rc; | |
557 } | |
558 | |
559 /* Read the typing event and set up the event object */ | |
560 static NMERR_T | |
561 handle_typing(NMUser * user, NMEvent * event) | |
562 { | |
563 NMERR_T rc = NM_OK; | |
564 guint32 size = 0; | |
565 char *guid = NULL; | |
566 NMConference *conference; | |
567 NMConn *conn; | |
568 | |
569 conn = nm_user_get_conn(user); | |
570 | |
571 /* Read the conference guid */ | |
8874 | 572 rc = nm_read_uint32(conn, &size); |
8675 | 573 if (rc == NM_OK) { |
574 guid = g_new0(char, size + 1); | |
575 rc = nm_read_all(conn, guid, size); | |
576 } | |
577 | |
578 if (rc == NM_OK) { | |
579 conference = nm_conference_list_find(user, guid); | |
580 if (conference) { | |
581 nm_event_set_conference(event, conference); | |
582 } else { | |
583 rc = NMERR_CONFERENCE_NOT_FOUND; | |
584 } | |
585 } | |
586 | |
587 if (guid) | |
588 g_free(guid); | |
589 | |
590 return rc; | |
591 } | |
592 | |
593 /* Read the event, set up the event object, and update | |
594 * the status in the user record (for the event source) | |
595 */ | |
596 static NMERR_T | |
597 handle_status_change(NMUser * user, NMEvent * event) | |
598 { | |
599 NMERR_T rc = NM_OK; | |
600 guint16 status; | |
601 guint32 size; | |
602 char *text = NULL; | |
603 NMUserRecord *user_record; | |
604 NMConn *conn; | |
605 | |
606 conn = nm_user_get_conn(user); | |
607 | |
608 /* Read new status */ | |
8874 | 609 rc = nm_read_uint16(conn, &status); |
8675 | 610 if (rc == NM_OK) { |
611 | |
612 /* Read the status text */ | |
8874 | 613 rc = nm_read_uint32(conn, &size); |
8675 | 614 if (rc == NM_OK) { |
615 if (size > 0) { | |
616 text = g_new0(char, size + 1); | |
617 rc = nm_read_all(conn, text, size); | |
618 } | |
619 } | |
620 } | |
621 | |
622 if (rc == NM_OK) { | |
623 nm_event_set_text(event, text); | |
624 | |
625 /* Get a reference to the user record and store the new status */ | |
626 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
627 if (user_record) { | |
628 nm_event_set_user_record(event, user_record); | |
629 nm_user_record_set_status(user_record, status, text); | |
630 } | |
631 } | |
632 | |
633 if (text) | |
634 g_free(text); | |
635 | |
636 return rc; | |
637 } | |
638 | |
639 /* Read the undeliverable event */ | |
640 static NMERR_T | |
641 handle_undeliverable_status(NMUser * user, NMEvent * event) | |
642 { | |
643 NMERR_T rc = NM_OK; | |
644 guint32 size = 0; | |
645 char *guid = NULL; | |
646 NMConn *conn; | |
647 | |
648 conn = nm_user_get_conn(user); | |
649 | |
650 /* Read the conference guid */ | |
8874 | 651 rc = nm_read_uint32(conn, &size); |
8675 | 652 if (rc == NM_OK) { |
653 guid = g_new0(char, size + 1); | |
654 rc = nm_read_all(conn, guid, size); | |
655 } | |
656 | |
657 if (guid) | |
658 g_free(guid); | |
659 | |
660 return rc; | |
661 } | |
662 | |
663 /******************************************************************************* | |
664 * Event API -- see header file for comments | |
665 ******************************************************************************/ | |
666 | |
667 NMEvent * | |
668 nm_create_event(int type, const char *source, guint32 gmt) | |
669 { | |
670 NMEvent *event = g_new0(NMEvent, 1); | |
671 | |
672 event->type = type; | |
673 event->gmt = gmt; | |
674 | |
675 if (source) | |
676 event->source = g_strdup(source); | |
677 | |
678 event->ref_count = 1; | |
679 | |
680 return event; | |
681 } | |
682 | |
683 void | |
684 nm_release_event(NMEvent * event) | |
685 { | |
686 if (event == NULL) { | |
687 return; | |
688 } | |
689 | |
690 if (--(event->ref_count) == 0) { | |
691 | |
692 if (event->source) | |
693 g_free(event->source); | |
694 | |
695 if (event->conference) | |
696 nm_release_conference(event->conference); | |
697 | |
698 if (event->user_record) | |
699 nm_release_user_record(event->user_record); | |
700 | |
701 if (event->text) | |
702 g_free(event->text); | |
703 | |
704 g_free(event); | |
705 } | |
706 } | |
707 | |
708 | |
709 NMConference * | |
710 nm_event_get_conference(NMEvent * event) | |
711 { | |
712 if (event) | |
713 return event->conference; | |
714 else | |
715 return NULL; | |
716 } | |
717 | |
718 void | |
719 nm_event_set_conference(NMEvent * event, NMConference * conference) | |
720 { | |
721 if (event && conference) { | |
722 nm_conference_add_ref(conference); | |
723 event->conference = conference; | |
724 } | |
725 } | |
726 | |
727 NMUserRecord * | |
728 nm_event_get_user_record(NMEvent * event) | |
729 { | |
730 if (event) | |
731 return event->user_record; | |
732 else | |
733 return NULL; | |
734 } | |
735 | |
736 void | |
737 nm_event_set_user_record(NMEvent * event, NMUserRecord * user_record) | |
738 { | |
739 if (event && user_record) { | |
740 nm_user_record_add_ref(user_record); | |
741 event->user_record = user_record; | |
742 } | |
743 } | |
744 | |
745 const char * | |
746 nm_event_get_text(NMEvent * event) | |
747 { | |
748 if (event) | |
749 return event->text; | |
750 else | |
751 return NULL; | |
752 } | |
753 | |
754 void | |
755 nm_event_set_text(NMEvent * event, const char *text) | |
756 { | |
757 if (event) { | |
758 if (text) | |
759 event->text = g_strdup(text); | |
760 else | |
761 event->text = NULL; | |
762 } | |
763 } | |
764 | |
765 const char * | |
766 nm_event_get_source(NMEvent * event) | |
767 { | |
768 if (event) | |
769 return event->source; | |
770 else | |
771 return NULL; | |
772 } | |
773 | |
774 int | |
775 nm_event_get_type(NMEvent * event) | |
776 { | |
777 if (event) | |
778 return event->type; | |
779 else | |
780 return -1; | |
781 } | |
782 | |
783 guint32 | |
784 nm_event_get_gmt(NMEvent * event) | |
785 { | |
786 if (event) | |
787 return event->gmt; | |
788 else | |
789 return (guint32)-1; | |
790 } | |
791 | |
792 NMERR_T | |
793 nm_process_event(NMUser * user, int type) | |
794 { | |
795 NMERR_T rc = NM_OK; | |
796 guint32 size = 0; | |
797 NMEvent *event = NULL; | |
798 char *source = NULL; | |
799 nm_event_cb cb; | |
800 NMConn *conn; | |
801 | |
802 if (user == NULL) | |
803 return NMERR_BAD_PARM; | |
804 | |
805 if (type < NMEVT_START || type > NMEVT_STOP) | |
806 return NMERR_PROTOCOL; | |
807 | |
808 conn = nm_user_get_conn(user); | |
809 | |
810 /* Read the event source */ | |
8874 | 811 rc = nm_read_uint32(conn, &size); |
8675 | 812 if (rc == NM_OK) { |
813 if (size > 0) { | |
814 source = g_new0(char, size); | |
815 | |
816 rc = nm_read_all(conn, source, size); | |
817 } | |
818 } | |
819 | |
820 /* Read the event data */ | |
821 if (rc == NM_OK) { | |
822 event = nm_create_event(type, source, time(0)); | |
823 | |
824 if (event) { | |
825 | |
826 switch (type) { | |
827 case NMEVT_STATUS_CHANGE: | |
828 rc = handle_status_change(user, event); | |
829 break; | |
830 | |
831 case NMEVT_RECEIVE_MESSAGE: | |
832 rc = handle_receive_message(user, event, FALSE); | |
833 break; | |
834 | |
835 case NMEVT_RECEIVE_AUTOREPLY: | |
836 rc = handle_receive_message(user, event, TRUE); | |
837 break; | |
838 | |
839 case NMEVT_USER_TYPING: | |
840 case NMEVT_USER_NOT_TYPING: | |
841 rc = handle_typing(user, event); | |
842 break; | |
843 | |
844 case NMEVT_CONFERENCE_LEFT: | |
845 rc = handle_conference_left(user, event); | |
846 break; | |
847 | |
848 case NMEVT_CONFERENCE_CLOSED: | |
849 rc = handle_conference_closed(user, event); | |
850 break; | |
851 | |
852 case NMEVT_CONFERENCE_JOINED: | |
853 rc = handle_conference_joined(user, event); | |
854 break; | |
855 | |
856 case NMEVT_CONFERENCE_INVITE: | |
857 rc = handle_conference_invite(user, event); | |
858 break; | |
859 | |
860 case NMEVT_CONFERENCE_REJECT: | |
861 rc = handle_conference_reject(user, event); | |
862 break; | |
863 | |
864 case NMEVT_CONFERENCE_INVITE_NOTIFY: | |
865 rc = handle_conference_invite_notify(user, event); | |
866 break; | |
867 | |
868 case NMEVT_UNDELIVERABLE_STATUS: | |
869 rc = handle_undeliverable_status(user, event); | |
870 break; | |
871 | |
872 case NMEVT_INVALID_RECIPIENT: | |
873 /* Nothing else to read, just callback */ | |
874 break; | |
875 | |
876 case NMEVT_USER_DISCONNECT: | |
877 /* Nothing else to read, just callback */ | |
878 break; | |
879 | |
880 case NMEVT_SERVER_DISCONNECT: | |
881 /* Nothing else to read, just callback */ | |
882 break; | |
883 | |
884 case NMEVT_RECEIVE_FILE: | |
885 case NMEVT_CONTACT_ADD: | |
886 /* Safely ignored for now */ | |
887 break; | |
888 | |
889 default: | |
890 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
891 "Unknown event %d received.\n", type); | |
892 rc = NMERR_PROTOCOL; | |
893 break; | |
894 } | |
895 } | |
896 } | |
897 | |
898 if (rc == (NMERR_T)-1) { | |
899 /* -1 means that we are not ready to callback yet. */ | |
900 rc = NM_OK; | |
901 } else if (rc == NM_OK && (cb = nm_user_get_event_callback(user))) { | |
902 | |
903 cb(user, event); | |
904 | |
905 if (event) | |
906 nm_release_event(event); | |
907 } else { | |
908 if (event) | |
909 nm_release_event(event); | |
910 } | |
911 | |
912 /* Cleanup */ | |
913 if (source) | |
914 g_free(source); | |
915 | |
916 return rc; | |
917 } |