Sun, 20 May 2007 06:19:49 +0000
merge of 'b98e72d4089afb8a1879e5fe9627cfb132ee88de'
and 'b2836a24d81e7a1bd1d21b3aea8794b094391344'
| 8675 | 1 | /* |
| 2 | * nmmessage.c | |
| 3 | * | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
4 | * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
5 | * |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
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:
8684
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:
8684
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:
8684
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:
8684
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
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:
8684
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:
8684
diff
changeset
|
16 | * along with this program; if not, write to the Free Software |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 8675 | 18 | * |
| 19 | */ | |
| 20 | ||
| 21 | #include "nmmessage.h" | |
| 22 | ||
| 23 | struct _NMMessage | |
| 24 | { | |
| 25 | NMConference *conference; | |
| 26 | char *text; | |
| 27 | gpointer data; | |
| 28 | guint32 ref_count; | |
| 29 | }; | |
| 30 | ||
| 31 | ||
| 32 | /** Message API **/ | |
| 33 | ||
| 34 | NMMessage * | |
| 35 | nm_create_message(const char *text) | |
| 36 | { | |
| 37 | NMMessage *msg = g_new0(NMMessage, 1); | |
| 38 | ||
| 39 | if (text) | |
| 40 | msg->text = g_strdup(text); | |
| 41 | ||
| 42 | msg->ref_count = 1; | |
| 43 | return msg; | |
| 44 | } | |
| 45 | ||
| 46 | void | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
47 | nm_message_add_ref(NMMessage * msg) |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
48 | { |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
49 | if (msg) |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
50 | msg->ref_count++; |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
51 | } |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
52 | |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
53 | void |
| 8675 | 54 | nm_release_message(NMMessage * msg) |
| 55 | { | |
| 56 | if (msg && (--(msg->ref_count) == 0)) { | |
| 57 | if (msg->text) | |
| 58 | g_free(msg->text); | |
| 59 | ||
| 60 | if (msg->conference) | |
| 61 | nm_release_conference(msg->conference); | |
| 62 | ||
| 63 | g_free(msg); | |
| 64 | } | |
| 65 | } | |
| 66 | ||
| 67 | const char * | |
| 68 | nm_message_get_text(NMMessage * msg) | |
| 69 | { | |
| 70 | if (msg == NULL) | |
| 71 | return NULL; | |
| 72 | ||
| 73 | return msg->text; | |
| 74 | } | |
| 75 | ||
| 76 | void | |
| 77 | nm_message_set_conference(NMMessage * msg, NMConference * conf) | |
| 78 | { | |
| 79 | if (msg == NULL || conf == NULL) | |
| 80 | return; | |
| 81 | ||
| 82 | /* Need to ref the conference first so that it doesn't | |
| 83 | * get released out from under us | |
| 84 | */ | |
| 85 | nm_conference_add_ref(conf); | |
| 86 | ||
| 87 | msg->conference = conf; | |
| 88 | } | |
| 89 | ||
| 90 | NMConference * | |
| 91 | nm_message_get_conference(NMMessage * msg) | |
| 92 | { | |
| 93 | if (msg == NULL) | |
| 94 | return NULL; | |
| 95 | ||
| 96 | return msg->conference; | |
| 97 | } |