/
mms_message.c
117 lines (109 loc) · 2.66 KB
/
mms_message.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "mms_message.h"
/* Logging */
#define MMS_LOG_MODULE_NAME mms_message_log
#include "mms_lib_log.h"
MMS_LOG_MODULE_DEFINE("mms-message");
static
void
mms_message_part_free(
gpointer data,
gpointer user_data)
{
MMSMessagePart* part = data;
MMSMessage* msg = user_data;
g_free(part->content_type);
g_free(part->content_id);
if (part->file) {
if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) remove(part->file);
g_free(part->file);
}
if (part->orig) {
if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) remove(part->orig);
g_free(part->orig);
}
g_free(part);
}
static
void
mms_message_finalize(
MMSMessage* msg)
{
MMS_VERBOSE_("%p", msg);
g_free(msg->id);
g_free(msg->message_id);
g_free(msg->from);
g_strfreev(msg->to);
g_strfreev(msg->cc);
g_free(msg->subject);
g_free(msg->cls);
g_slist_foreach(msg->parts, mms_message_part_free, msg);
g_slist_free(msg->parts);
if (msg->parts_dir) {
if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) {
if (rmdir(msg->parts_dir) == 0) {
MMS_VERBOSE("Deleted %s", msg->parts_dir);
}
}
g_free(msg->parts_dir);
}
if (msg->msg_dir) {
if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) {
if (rmdir(msg->msg_dir) == 0) {
MMS_VERBOSE("Deleted %s", msg->msg_dir);
}
}
g_free(msg->msg_dir);
}
}
MMSMessage*
mms_message_new()
{
MMSMessage* msg = g_new0(MMSMessage, 1);
MMS_VERBOSE_("%p", msg);
msg->ref_count = 1;
msg->priority = MMS_PRIORITY_NORMAL;
return msg;
}
MMSMessage*
mms_message_ref(
MMSMessage* msg)
{
if (msg) {
MMS_ASSERT(msg->ref_count > 0);
g_atomic_int_inc(&msg->ref_count);
}
return msg;
}
void
mms_message_unref(
MMSMessage* msg)
{
if (msg) {
MMS_ASSERT(msg->ref_count > 0);
if (g_atomic_int_dec_and_test(&msg->ref_count)) {
mms_message_finalize(msg);
g_free(msg);
}
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/