etesyncadapter.cpp 6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

Shashwat Jolly's avatar
Shashwat Jolly committed
18
#include "etesyncadapter.h"
19

Shashwat Jolly's avatar
Shashwat Jolly committed
20
21
22
#include "etesync_debug.h"

QString QStringFromCharPtr(const CharPtr &str)
23
{
Shashwat Jolly's avatar
Shashwat Jolly committed
24
    if (str.get() == NULL) {
25
26
        return QString();
    }
27
    QString ret = QString::fromUtf8(str.get());
28
29
30
31
32
33
    return ret;
}

QString etesync_auth_get_token(const EteSync *etesync, const QString &username,
                               const QString &password)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
34
35
    CharPtr token(etesync_auth_get_token(etesync, charArrFromQString(username), charArrFromQString(password)));
    return QStringFromCharPtr(token);
36
37
38
39
40
}

qint32 etesync_auth_invalidate_token(const EteSync *etesync,
                                     const QString &token)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
41
    return etesync_auth_invalidate_token(etesync, charArrFromQString(token));
42
43
}

44
45
46
47
EteSyncCollectionInfoPtr etesync_collection_info_new(const QString &col_type,
                                                     const QString &display_name,
                                                     const QString &description,
                                                     qint32 color)
48
{
49
    return EteSyncCollectionInfoPtr(etesync_collection_info_new(charArrFromQString(col_type), charArrFromQString(display_name), charArrFromQString(description), color));
50
51
}

Shashwat Jolly's avatar
Shashwat Jolly committed
52
QString etesync_crypto_derive_key(const EteSync *etesync, const QString &salt,
53
54
                                  const QString &password)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
55
56
    CharPtr ret(etesync_crypto_derive_key(etesync, charArrFromQString(salt), charArrFromQString(password)));
    return QStringFromCharPtr(ret);
57
58
}

59
60
61
EteSyncEntryPtr etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
                                              const EteSyncSyncEntry *sync_entry,
                                              const QString &prev_uid)
62
{
63
    return EteSyncEntryPtr(etesync_entry_from_sync_entry(crypto_manager, sync_entry, charArrFromQString(prev_uid)));
64
65
}

66
67
68
EteSyncSyncEntryPtr etesync_entry_get_sync_entry(const EteSyncEntry *entry,
                                                 const EteSyncCryptoManager *crypto_manager,
                                                 const QString &prev_uid)
69
{
70
    return EteSyncSyncEntryPtr(etesync_entry_get_sync_entry(entry, crypto_manager, charArrFromQString(prev_uid)));
71
72
73
74
75
76
}

qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
                                    const EteSyncEntry *const *entries,
                                    const QString &prev_uid)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
77
    return etesync_entry_manager_create(entry_manager, entries, charArrFromQString(prev_uid));
78
79
}

80
81
std::vector<EteSyncEntryPtr> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
                                                        const QString &prev_uid, uintptr_t limit)
82
{
83
84
85
86
87
88
89
    auto entries = etesync_entry_manager_list(entry_manager, charArrFromQString(prev_uid), limit);
    std::vector<EteSyncEntryPtr> rv;
    while (*entries) {
        rv.emplace_back(EteSyncEntryPtr{*entries});
        ++entries;
    }
    return rv;
90
91
}

92
93
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
                                                 const QString &journal_uid)
94
{
95
    return EteSyncEntryManagerPtr(etesync_entry_manager_new(etesync, charArrFromQString(journal_uid)));
96
97
}

98
99
100
EteSyncCryptoManagerPtr etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
                                                           const QString &key,
                                                           const EteSyncAsymmetricKeyPair *keypair)
101
{
102
    return EteSyncCryptoManagerPtr(etesync_journal_get_crypto_manager(journal, charArrFromQString(key), keypair));
103
104
}

105
106
EteSyncJournalPtr etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
                                                const QString &journal_uid)
107
{
108
    return EteSyncJournalPtr(etesync_journal_manager_fetch(journal_manager, charArrFromQString(journal_uid)));
109
110
}

111
EteSyncJournalPtr etesync_journal_new(const QString &uid, uint8_t version)
112
{
113
    return EteSyncJournalPtr(etesync_journal_new(charArrFromQString(uid), version));
114
115
}

116
EteSyncPtr etesync_new(const QString &client_name, const QString &server_url)
117
{
118
    return EteSyncPtr(etesync_new(charArrFromQString(client_name), charArrFromQString(server_url)));
119
120
121
122
}

void etesync_set_auth_token(EteSync *etesync, const QString &token)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
123
    etesync_set_auth_token(etesync, charArrFromQString(token));
124
125
}

126
127
EteSyncSyncEntryPtr etesync_sync_entry_new(const QString &action,
                                           const QString &content)
128
{
129
    return EteSyncSyncEntryPtr(etesync_sync_entry_new(charArrFromQString(action), charArrFromQString(content)));
130
131
}

132
133
EteSyncCryptoManagerPtr etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
                                                             const QString &key)
134
{
135
    return EteSyncCryptoManagerPtr(etesync_user_info_get_crypto_manager(user_info, charArrFromQString(key)));
136
137
}

138
139
EteSyncUserInfoPtr etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
                                                   const QString &owner)
140
{
141
    return EteSyncUserInfoPtr(etesync_user_info_manager_fetch(user_info_manager, charArrFromQString(owner)));
142
}
143

144
EteSyncUserInfoPtr etesync_user_info_new(const QString &owner, uint8_t version)
145
{
146
    return EteSyncUserInfoPtr(etesync_user_info_new(charArrFromQString(owner), version));
147
}