~ubuntuone-control-tower/ubuntuone-client/trunk

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-metadata.c

  • Committer: Tarmac
  • Author(s): Diego Sarmentero, Rodney Dawes
  • Date: 2014-04-11 14:23:37 UTC
  • mfrom: (1403.1.8 ubuntuone-client)
  • Revision ID: tarmac-20140411142337-vg6lk4a6a5au0jag
- Show a message when the client is started indicating that the service will be suspended on June 1st.
- After June 1st, don't contact the server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Syncdaemon API
3
 
 *
4
 
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5
 
 *
6
 
 * Copyright 2010-2012 Canonical Ltd.
7
 
 *
8
 
 * This program is free software: you can redistribute it and/or modify it
9
 
 * under the terms of the GNU General Public License version 3, as published
10
 
 * by the Free Software Foundation.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
14
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
 
 * PURPOSE.  See the GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License along
18
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *
20
 
 * In addition, as a special exception, the copyright holders give
21
 
 * permission to link the code of portions of this program with the
22
 
 * OpenSSL library under certain conditions as described in each
23
 
 * individual source file, and distribute linked combinations
24
 
 * including the two.
25
 
 * You must obey the GNU General Public License in all respects
26
 
 * for all of the code used other than OpenSSL.  If you modify
27
 
 * file(s) with this exception, you may extend this exception to your
28
 
 * version of the file(s), but you are not obligated to do so.  If you
29
 
 * do not wish to do so, delete this exception statement from your
30
 
 * version.  If you delete this exception statement from all source
31
 
 * files in the program, then also delete it here.
32
 
 *
33
 
 */
34
 
 
35
 
#include "syncdaemon-metadata.h"
36
 
 
37
 
G_DEFINE_TYPE(SyncdaemonMetadata, syncdaemon_metadata, G_TYPE_OBJECT)
38
 
 
39
 
struct _SyncdaemonMetadataPrivate {
40
 
        gchar *path;
41
 
        gchar *local_hash;
42
 
        gchar *server_hash;
43
 
        gchar *share_id;
44
 
        gchar *node_id;
45
 
        gboolean is_synced;
46
 
        gboolean is_dir;
47
 
};
48
 
 
49
 
static void
50
 
syncdaemon_metadata_finalize (GObject *object)
51
 
{
52
 
        SyncdaemonMetadata *metadata = SYNCDAEMON_METADATA (object);
53
 
 
54
 
        if (metadata->priv != NULL) {
55
 
                if (metadata->priv->path != NULL)
56
 
                        g_free (metadata->priv->path);
57
 
 
58
 
                if (metadata->priv->local_hash != NULL)
59
 
                        g_free (metadata->priv->local_hash);
60
 
 
61
 
                if (metadata->priv->server_hash != NULL)
62
 
                        g_free (metadata->priv->server_hash);
63
 
 
64
 
                if (metadata->priv->share_id != NULL)
65
 
                        g_free (metadata->priv->share_id);
66
 
 
67
 
                if (metadata->priv->node_id != NULL)
68
 
                        g_free (metadata->priv->node_id);
69
 
 
70
 
                g_free (metadata->priv);
71
 
        }
72
 
 
73
 
        G_OBJECT_CLASS (syncdaemon_metadata_parent_class)->finalize (object);
74
 
}
75
 
 
76
 
static void
77
 
syncdaemon_metadata_class_init (SyncdaemonMetadataClass *klass)
78
 
{
79
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
80
 
 
81
 
        object_class->finalize = syncdaemon_metadata_finalize;
82
 
}
83
 
 
84
 
static void
85
 
syncdaemon_metadata_init (SyncdaemonMetadata *metadata)
86
 
{
87
 
        metadata->priv = g_new0 (SyncdaemonMetadataPrivate, 1);
88
 
}
89
 
 
90
 
/**
91
 
 * syncdaemon_metadata_new:
92
 
 */
93
 
SyncdaemonMetadata *
94
 
syncdaemon_metadata_new (void)
95
 
{
96
 
        return g_object_new (SYNCDAEMON_TYPE_METADATA, NULL);
97
 
}
98
 
 
99
 
/**
100
 
 * syncdaemon_metadata_new_from_hash_table:
101
 
 */
102
 
SyncdaemonMetadata *
103
 
syncdaemon_metadata_new_from_hash_table (GHashTable *hash)
104
 
{
105
 
        SyncdaemonMetadata *metadata;
106
 
 
107
 
        metadata = g_object_new (SYNCDAEMON_TYPE_METADATA, NULL);
108
 
        if (hash != NULL) {
109
 
                syncdaemon_metadata_set_path (metadata, g_hash_table_lookup (hash, "path"));
110
 
                syncdaemon_metadata_set_local_hash (metadata, g_hash_table_lookup (hash, "local_hash"));
111
 
                syncdaemon_metadata_set_server_hash (metadata, g_hash_table_lookup (hash, "server_hash"));
112
 
                syncdaemon_metadata_set_share_id (metadata, g_hash_table_lookup (hash, "share_id"));
113
 
                syncdaemon_metadata_set_node_id (metadata, g_hash_table_lookup (hash, "node_id"));
114
 
                syncdaemon_metadata_set_is_synced (
115
 
                        metadata,
116
 
                        g_strcmp0 (g_hash_table_lookup (hash, "quick_tree_synced"), "synced") == 0);
117
 
                metadata->priv->is_dir = g_strcmp0 (g_hash_table_lookup (hash, "is_dir"), "True") == 0;
118
 
                /* FIXME: we ignore the other values in the hash table since none of our
119
 
                   clients use them for now */
120
 
        }
121
 
 
122
 
        return metadata;
123
 
}
124
 
 
125
 
/**
126
 
 * syncdaemon_metadata_get_path:
127
 
 */
128
 
const gchar *
129
 
syncdaemon_metadata_get_path (SyncdaemonMetadata *metadata)
130
 
{
131
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), NULL);
132
 
 
133
 
        return (const gchar *) metadata->priv->path;
134
 
}
135
 
 
136
 
/**
137
 
 * syncdaemon_metadata_set_path:
138
 
 */
139
 
void
140
 
syncdaemon_metadata_set_path (SyncdaemonMetadata *metadata, const gchar *path)
141
 
{
142
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
143
 
 
144
 
        if (metadata->priv->path != NULL)
145
 
                g_free (metadata->priv->path);
146
 
 
147
 
        metadata->priv->path = g_strdup (path);
148
 
}
149
 
 
150
 
/**
151
 
 * syncdaemon_metadata_get_local_hash:
152
 
 */
153
 
const gchar *
154
 
syncdaemon_metadata_get_local_hash (SyncdaemonMetadata *metadata)
155
 
{
156
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), NULL);
157
 
 
158
 
        return (const gchar *) metadata->priv->local_hash;
159
 
}
160
 
 
161
 
/**
162
 
 * syncdaemon_metadata_set_local_hash:
163
 
 */
164
 
void
165
 
syncdaemon_metadata_set_local_hash (SyncdaemonMetadata *metadata, const gchar *local_hash)
166
 
{
167
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
168
 
 
169
 
        if (metadata->priv->local_hash != NULL)
170
 
                g_free (metadata->priv->local_hash);
171
 
 
172
 
        metadata->priv->local_hash = g_strdup (local_hash);
173
 
}
174
 
 
175
 
/**
176
 
 * syncdaemon_metadata_get_server_hash:
177
 
 */
178
 
const gchar *
179
 
syncdaemon_metadata_get_server_hash (SyncdaemonMetadata *metadata)
180
 
{
181
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), NULL);
182
 
 
183
 
        return (const gchar *) metadata->priv->server_hash;
184
 
}
185
 
 
186
 
/**
187
 
 * syncdaemon_metadata_set_server_hash:
188
 
 */
189
 
void
190
 
syncdaemon_metadata_set_server_hash (SyncdaemonMetadata *metadata, const gchar *server_hash)
191
 
{
192
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
193
 
 
194
 
        if (metadata->priv->server_hash != NULL)
195
 
                g_free (metadata->priv->server_hash);
196
 
 
197
 
        metadata->priv->server_hash = g_strdup (server_hash);
198
 
}
199
 
 
200
 
/**
201
 
 * syncdaemon_metadata_get_share_id:
202
 
 */
203
 
const gchar *
204
 
syncdaemon_metadata_get_share_id (SyncdaemonMetadata *metadata)
205
 
{
206
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), NULL);
207
 
 
208
 
        return (const gchar *) metadata->priv->share_id;
209
 
}
210
 
 
211
 
/**
212
 
 * syncdaemon_metadata_set_share_id:
213
 
 */
214
 
void
215
 
syncdaemon_metadata_set_share_id (SyncdaemonMetadata *metadata, const gchar *share_id)
216
 
{
217
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
218
 
 
219
 
        if (metadata->priv->share_id != NULL)
220
 
                g_free (metadata->priv->share_id);
221
 
 
222
 
        metadata->priv->share_id = g_strdup (share_id);
223
 
}
224
 
 
225
 
/**
226
 
 * syncdaemon_metadata_get_node_id:
227
 
 */
228
 
const gchar *
229
 
syncdaemon_metadata_get_node_id (SyncdaemonMetadata *metadata)
230
 
{
231
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), NULL);
232
 
 
233
 
        return (const gchar *) metadata->priv->node_id;
234
 
}
235
 
 
236
 
/**
237
 
 * syncdaemon_metadata_set_node_id:
238
 
 */
239
 
void
240
 
syncdaemon_metadata_set_node_id (SyncdaemonMetadata *metadata, const gchar *node_id)
241
 
{
242
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
243
 
 
244
 
        if (metadata->priv->node_id != NULL)
245
 
                g_free (metadata->priv->node_id);
246
 
 
247
 
        metadata->priv->node_id = g_strdup (node_id);
248
 
}
249
 
 
250
 
/**
251
 
 * syncdaemon_metadata_get_is_synced:
252
 
 */
253
 
gboolean
254
 
syncdaemon_metadata_get_is_synced (SyncdaemonMetadata *metadata)
255
 
{
256
 
        gchar *local, *server;
257
 
        gboolean is_updated;
258
 
 
259
 
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), FALSE);
260
 
 
261
 
        /* If it's a dir, we have the 'quick_tree_synced' value */
262
 
        if (metadata->priv->is_dir)
263
 
                return metadata->priv->is_synced;
264
 
 
265
 
        local = metadata->priv->local_hash;
266
 
        server = metadata->priv->server_hash;
267
 
 
268
 
        is_updated = local && server && *local && *server &&
269
 
                g_strcmp0 (local, server) == 0;
270
 
 
271
 
        return is_updated;
272
 
}
273
 
 
274
 
/**
275
 
 * syncdaemon_metadata_set_is_synced:
276
 
 */
277
 
void
278
 
syncdaemon_metadata_set_is_synced (SyncdaemonMetadata *metadata, gboolean is_synced)
279
 
{
280
 
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
281
 
 
282
 
        metadata->priv->is_synced = is_synced;
283
 
}
284