comparison libpurple/protocols/novell/nmmessage.c @ 15373:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 44b4e8bd759b
comparison
equal deleted inserted replaced
15372:f79e0f4df793 15373:5fe8042783c1
1 /*
2 * nmmessage.c
3 *
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.
9 *
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.
14 *
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
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
47 nm_message_add_ref(NMMessage * msg)
48 {
49 if (msg)
50 msg->ref_count++;
51 }
52
53 void
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 }