Mon, 10 Feb 2014 16:22:00 +0530
Merged default branch
| 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 |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15435
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8675 | 18 | * |
| 19 | */ | |
| 20 | ||
| 21 | #include "nmmessage.h" | |
| 22 | ||
| 23 | struct _NMMessage | |
| 24 | { | |
| 25 | NMConference *conference; | |
| 26 | char *text; | |
| 27 | guint32 ref_count; | |
| 28 | }; | |
| 29 | ||
| 30 | ||
| 31 | /** Message API **/ | |
| 32 | ||
| 33 | NMMessage * | |
| 34 | nm_create_message(const char *text) | |
| 35 | { | |
| 36 | NMMessage *msg = g_new0(NMMessage, 1); | |
| 37 | ||
| 38 | if (text) | |
| 39 | msg->text = g_strdup(text); | |
| 40 | ||
| 41 | msg->ref_count = 1; | |
| 42 | return msg; | |
| 43 | } | |
| 44 | ||
| 45 | void | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
46 | nm_message_add_ref(NMMessage * msg) |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
47 | { |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
48 | if (msg) |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
49 | msg->ref_count++; |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
50 | } |
|
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 | void |
| 8675 | 53 | nm_release_message(NMMessage * msg) |
| 54 | { | |
| 55 | if (msg && (--(msg->ref_count) == 0)) { | |
| 56 | if (msg->text) | |
| 57 | g_free(msg->text); | |
| 58 | ||
| 59 | if (msg->conference) | |
| 60 | nm_release_conference(msg->conference); | |
| 61 | ||
| 62 | g_free(msg); | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | const char * | |
| 67 | nm_message_get_text(NMMessage * msg) | |
| 68 | { | |
| 69 | if (msg == NULL) | |
| 70 | return NULL; | |
| 71 | ||
| 72 | return msg->text; | |
| 73 | } | |
| 74 | ||
| 75 | void | |
| 76 | nm_message_set_conference(NMMessage * msg, NMConference * conf) | |
| 77 | { | |
| 78 | if (msg == NULL || conf == NULL) | |
| 79 | return; | |
| 80 | ||
| 81 | /* Need to ref the conference first so that it doesn't | |
| 82 | * get released out from under us | |
| 83 | */ | |
| 84 | nm_conference_add_ref(conf); | |
| 85 | ||
| 86 | msg->conference = conf; | |
| 87 | } | |
| 88 | ||
| 89 | NMConference * | |
| 90 | nm_message_get_conference(NMMessage * msg) | |
| 91 | { | |
| 92 | if (msg == NULL) | |
| 93 | return NULL; | |
| 94 | ||
| 95 | return msg->conference; | |
| 96 | } |