1
/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
5
#include "hex-binary.h"
7
#include "dsync-data.h"
10
dsync_mailbox_dup(pool_t pool, const struct dsync_mailbox *box)
12
struct dsync_mailbox *dest;
13
const char *const *cache_fields = NULL, *dup;
14
unsigned int i, count = 0;
16
dest = p_new(pool, struct dsync_mailbox, 1);
18
dest->name = p_strdup(pool, box->name);
20
if (array_is_created(&box->cache_fields))
21
cache_fields = array_get(&box->cache_fields, &count);
23
memset(&dest->cache_fields, 0, sizeof(dest->cache_fields));
25
p_array_init(&dest->cache_fields, pool, count);
26
for (i = 0; i < count; i++) {
27
dup = p_strdup(pool, cache_fields[i]);
28
array_append(&dest->cache_fields, &dup, 1);
34
struct dsync_message *
35
dsync_message_dup(pool_t pool, const struct dsync_message *msg)
37
struct dsync_message *dest;
38
const char **keywords;
39
unsigned int i, count;
41
dest = p_new(pool, struct dsync_message, 1);
43
dest->guid = p_strdup(pool, msg->guid);
44
if (msg->keywords != NULL) {
45
count = str_array_length(msg->keywords);
46
keywords = p_new(pool, const char *, count+1);
47
for (i = 0; i < count; i++)
48
keywords[i] = p_strdup(pool, msg->keywords[i]);
49
dest->keywords = keywords;
54
int dsync_mailbox_guid_cmp(const struct dsync_mailbox *box1,
55
const struct dsync_mailbox *box2)
57
return memcmp(box1->mailbox_guid.guid, box2->mailbox_guid.guid,
58
sizeof(box1->mailbox_guid.guid));
61
int dsync_mailbox_p_guid_cmp(struct dsync_mailbox *const *box1,
62
struct dsync_mailbox *const *box2)
64
return dsync_mailbox_guid_cmp(*box1, *box2);
67
int dsync_mailbox_name_sha1_cmp(const struct dsync_mailbox *box1,
68
const struct dsync_mailbox *box2)
72
ret = memcmp(box1->name_sha1.guid, box2->name_sha1.guid,
73
sizeof(box1->name_sha1.guid));
77
return strcmp(box1->name, box2->name);
80
int dsync_mailbox_p_name_sha1_cmp(struct dsync_mailbox *const *box1,
81
struct dsync_mailbox *const *box2)
83
return dsync_mailbox_name_sha1_cmp(*box1, *box2);
86
bool dsync_keyword_list_equals(const char *const *k1, const char *const *k2)
91
return k2 == NULL || k2[0] == NULL;
101
if (strcasecmp(k1[i], k2[i]) != 0)
106
bool dsync_guid_equals(const mailbox_guid_t *guid1,
107
const mailbox_guid_t *guid2)
109
return memcmp(guid1->guid, guid2->guid, sizeof(guid1->guid)) == 0;
112
int dsync_guid_cmp(const mailbox_guid_t *guid1, const mailbox_guid_t *guid2)
114
return memcmp(guid1->guid, guid2->guid, sizeof(guid1->guid));
117
const char *dsync_guid_to_str(const mailbox_guid_t *guid)
119
return mail_guid_128_to_string(guid->guid);
122
const char *dsync_get_guid_128_str(const char *guid, unsigned char *dest,
123
unsigned int dest_len)
125
uint8_t guid_128[MAIL_GUID_128_SIZE];
126
buffer_t guid_128_buf;
128
i_assert(dest_len >= MAIL_GUID_128_SIZE * 2 + 1);
129
buffer_create_data(&guid_128_buf, dest, dest_len);
130
mail_generate_guid_128_hash(guid, guid_128);
131
if (mail_guid_128_is_empty(guid_128))
133
binary_to_hex_append(&guid_128_buf, guid_128, sizeof(guid_128));
134
buffer_append_c(&guid_128_buf, '\0');
135
return guid_128_buf.data;
138
void dsync_str_sha_to_guid(const char *str, mailbox_guid_t *guid)
140
unsigned char sha[SHA1_RESULTLEN];
142
sha1_get_digest(str, strlen(str), sha);
143
memcpy(guid->guid, sha, I_MIN(sizeof(guid->guid), sizeof(sha)));