~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to camel/providers/imapp/camel-imapp-summary.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.10.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 128.
  • Revision ID: james.westby@ubuntu.com-20100517170206-xu1wmjuy40nt2sk0
Tags: upstream-2.30.1
ImportĀ upstreamĀ versionĀ 2.30.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4
 
 *
5
 
 *  Authors:
6
 
 *    Michael Zucchi <notzed@ximian.com>
7
 
 *    Dan Winship <danw@ximian.com>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or
10
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
11
 
 * License as published by the Free Software Foundation.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Lesser General Public
19
 
 * License along with this program; if not, write to the
20
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 
 * Boston, MA 02110-1301, USA.
22
 
 */
23
 
 
24
 
#ifdef HAVE_CONFIG_H
25
 
#include <config.h>
26
 
#endif
27
 
 
28
 
#include <errno.h>
29
 
#include <stdlib.h>
30
 
#include <string.h>
31
 
#include <unistd.h>
32
 
#include <sys/stat.h>
33
 
#include <sys/uio.h>
34
 
 
35
 
#include "camel-file-utils.h"
36
 
 
37
 
#include "camel-imapp-summary.h"
38
 
 
39
 
#define CAMEL_IMAPP_SUMMARY_VERSION (1)
40
 
 
41
 
static gint summary_header_load(CamelFolderSummary *, FILE *);
42
 
static gint summary_header_save(CamelFolderSummary *, FILE *);
43
 
 
44
 
static CamelMessageInfo *message_info_load(CamelFolderSummary *s, FILE *in);
45
 
static gint message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *info);
46
 
 
47
 
static void camel_imapp_summary_class_init(CamelIMAPPSummaryClass *klass);
48
 
static void camel_imapp_summary_init      (CamelIMAPPSummary *obj);
49
 
 
50
 
static CamelFolderSummaryClass *camel_imapp_summary_parent;
51
 
 
52
 
CamelType
53
 
camel_imapp_summary_get_type(void)
54
 
{
55
 
        static CamelType type = CAMEL_INVALID_TYPE;
56
 
 
57
 
        if (type == CAMEL_INVALID_TYPE) {
58
 
                type = camel_type_register(
59
 
                        camel_folder_summary_get_type(), "CamelIMAPPSummary",
60
 
                        sizeof(CamelIMAPPSummary),
61
 
                        sizeof(CamelIMAPPSummaryClass),
62
 
                        (CamelObjectClassInitFunc) camel_imapp_summary_class_init,
63
 
                        NULL,
64
 
                        (CamelObjectInitFunc) camel_imapp_summary_init,
65
 
                        NULL);
66
 
        }
67
 
 
68
 
        return type;
69
 
}
70
 
 
71
 
static void
72
 
camel_imapp_summary_class_init(CamelIMAPPSummaryClass *klass)
73
 
{
74
 
        CamelFolderSummaryClass *cfs_class =(CamelFolderSummaryClass *) klass;
75
 
 
76
 
        camel_imapp_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs(camel_folder_summary_get_type()));
77
 
 
78
 
        cfs_class->summary_header_load = summary_header_load;
79
 
        cfs_class->summary_header_save = summary_header_save;
80
 
        cfs_class->message_info_load = message_info_load;
81
 
        cfs_class->message_info_save = message_info_save;
82
 
}
83
 
 
84
 
static void
85
 
camel_imapp_summary_init(CamelIMAPPSummary *obj)
86
 
{
87
 
        CamelFolderSummary *s =(CamelFolderSummary *)obj;
88
 
 
89
 
        /* subclasses need to set the right instance data sizes */
90
 
        s->message_info_size = sizeof(CamelIMAPPMessageInfo);
91
 
        s->content_info_size = sizeof(CamelMessageContentInfo);
92
 
 
93
 
        /* and a unique file version */
94
 
        s->version += CAMEL_IMAPP_SUMMARY_VERSION;
95
 
}
96
 
 
97
 
/**
98
 
 * camel_imapp_summary_new:
99
 
 *
100
 
 * This will create a new CamelIMAPPSummary object and read in the
101
 
 * summary data from disk, if it exists.
102
 
 *
103
 
 * Return value: A new CamelIMAPPSummary object.
104
 
 **/
105
 
CamelFolderSummary *
106
 
camel_imapp_summary_new(void)
107
 
{
108
 
        CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY(camel_object_new(camel_imapp_summary_get_type()));
109
 
 
110
 
        return summary;
111
 
}
112
 
 
113
 
static gint
114
 
summary_header_load(CamelFolderSummary *s, FILE *in)
115
 
{
116
 
        CamelIMAPPSummary *ims = CAMEL_IMAPP_SUMMARY(s);
117
 
 
118
 
        if (camel_imapp_summary_parent->summary_header_load(s, in) == -1)
119
 
                return -1;
120
 
 
121
 
        /* Legacy version */
122
 
        if (s->version == 0x100c)
123
 
                return camel_file_util_decode_uint32(in, &ims->uidvalidity);
124
 
 
125
 
        if (camel_file_util_decode_fixed_int32(in, &ims->version) == -1
126
 
            || camel_file_util_decode_fixed_int32(in, &ims->uidvalidity) == -1)
127
 
                return -1;
128
 
 
129
 
        if (ims->version > CAMEL_IMAPP_SUMMARY_VERSION) {
130
 
                g_warning("Unkown summary version\n");
131
 
                errno = EINVAL;
132
 
                return -1;
133
 
        }
134
 
 
135
 
        return 0;
136
 
}
137
 
 
138
 
static gint
139
 
summary_header_save(CamelFolderSummary *s, FILE *out)
140
 
{
141
 
        CamelIMAPPSummary *ims = CAMEL_IMAPP_SUMMARY(s);
142
 
 
143
 
        if (camel_imapp_summary_parent->summary_header_save(s, out) == -1)
144
 
                return -1;
145
 
 
146
 
        if (camel_file_util_encode_fixed_int32(out, CAMEL_IMAPP_SUMMARY_VERSION) == -1
147
 
            || camel_file_util_encode_fixed_int32(out, ims->uidvalidity) == -1)
148
 
                return -1;
149
 
 
150
 
        return 0;
151
 
}
152
 
 
153
 
static CamelMessageInfo *
154
 
message_info_load(CamelFolderSummary *s, FILE *in)
155
 
{
156
 
        CamelMessageInfo *info;
157
 
        CamelIMAPPMessageInfo *iinfo;
158
 
 
159
 
        info = camel_imapp_summary_parent->message_info_load(s, in);
160
 
        if (info) {
161
 
                iinfo =(CamelIMAPPMessageInfo *)info;
162
 
 
163
 
                if (camel_file_util_decode_uint32(in, &iinfo->server_flags) == -1)
164
 
                        goto error;
165
 
        }
166
 
 
167
 
        return info;
168
 
error:
169
 
        camel_message_info_free(info);
170
 
        return NULL;
171
 
}
172
 
 
173
 
static gint
174
 
message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *info)
175
 
{
176
 
        CamelIMAPPMessageInfo *iinfo =(CamelIMAPPMessageInfo *)info;
177
 
 
178
 
        if (camel_imapp_summary_parent->message_info_save(s, out, info) == -1)
179
 
                return -1;
180
 
 
181
 
        return camel_file_util_encode_uint32(out, iinfo->server_flags);
182
 
}