etesyncadapter.cpp 5.59 KB
Newer Older
1
/*
2
3
4
 * SPDX-FileCopyrightText: 2020 Shashwat Jolly <shashwat.jolly@gmail.com>
 * 
 * SPDX-License-Identifier: GPL-2.0-or-later
5
6
 */

Shashwat Jolly's avatar
Shashwat Jolly committed
7
#include "etesyncadapter.h"
8

Shashwat Jolly's avatar
Shashwat Jolly committed
9
10
11
#include "etesync_debug.h"

QString QStringFromCharPtr(const CharPtr &str)
12
{
13
    if (str.get() == nullptr) {
14
15
        return QString();
    }
16
    QString ret = QString::fromUtf8(str.get());
17
18
19
20
21
22
    return ret;
}

QString etesync_auth_get_token(const EteSync *etesync, const QString &username,
                               const QString &password)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
23
24
    CharPtr token(etesync_auth_get_token(etesync, charArrFromQString(username), charArrFromQString(password)));
    return QStringFromCharPtr(token);
25
26
27
28
29
}

qint32 etesync_auth_invalidate_token(const EteSync *etesync,
                                     const QString &token)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
30
    return etesync_auth_invalidate_token(etesync, charArrFromQString(token));
31
32
}

33
34
35
36
EteSyncCollectionInfoPtr etesync_collection_info_new(const QString &col_type,
                                                     const QString &display_name,
                                                     const QString &description,
                                                     qint32 color)
37
{
38
    return EteSyncCollectionInfoPtr(etesync_collection_info_new(charArrFromQString(col_type), charArrFromQString(display_name), charArrFromQString(description), color));
39
40
}

Shashwat Jolly's avatar
Shashwat Jolly committed
41
QString etesync_crypto_derive_key(const EteSync *etesync, const QString &salt,
42
43
                                  const QString &password)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
44
45
    CharPtr ret(etesync_crypto_derive_key(etesync, charArrFromQString(salt), charArrFromQString(password)));
    return QStringFromCharPtr(ret);
46
47
}

48
49
50
EteSyncEntryPtr etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
                                              const EteSyncSyncEntry *sync_entry,
                                              const QString &prev_uid)
51
{
52
    return EteSyncEntryPtr(etesync_entry_from_sync_entry(crypto_manager, sync_entry, charArrFromQString(prev_uid)));
53
54
}

55
56
57
EteSyncSyncEntryPtr etesync_entry_get_sync_entry(const EteSyncEntry *entry,
                                                 const EteSyncCryptoManager *crypto_manager,
                                                 const QString &prev_uid)
58
{
59
    return EteSyncSyncEntryPtr(etesync_entry_get_sync_entry(entry, crypto_manager, charArrFromQString(prev_uid)));
60
61
62
63
64
65
}

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

69
70
std::pair<std::vector<EteSyncEntryPtr>, bool> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
                                                                         const QString &prev_uid, uintptr_t limit)
71
{
72
    std::vector<EteSyncEntryPtr> rv;
73
    bool err = false;
74
    auto entries = etesync_entry_manager_list(entry_manager, charArrFromQString(prev_uid), limit);
75
76
    if (!entries) {
        err = true;
77
        return make_pair(std::move(rv), err);
78
    }
79
80
81
82
    while (*entries) {
        rv.emplace_back(EteSyncEntryPtr{*entries});
        ++entries;
    }
83
    return make_pair(std::move(rv), err);
84
85
}

86
87
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
                                                 const QString &journal_uid)
88
{
89
    return EteSyncEntryManagerPtr(etesync_entry_manager_new(etesync, charArrFromQString(journal_uid)));
90
91
}

92
93
94
EteSyncCryptoManagerPtr etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
                                                           const QString &key,
                                                           const EteSyncAsymmetricKeyPair *keypair)
95
{
96
    return EteSyncCryptoManagerPtr(etesync_journal_get_crypto_manager(journal, charArrFromQString(key), keypair));
97
98
}

99
100
EteSyncJournalPtr etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
                                                const QString &journal_uid)
101
{
102
    return EteSyncJournalPtr(etesync_journal_manager_fetch(journal_manager, charArrFromQString(journal_uid)));
103
104
}

105
EteSyncJournalPtr etesync_journal_new(const QString &uid, uint8_t version)
106
{
107
    return EteSyncJournalPtr(etesync_journal_new(charArrFromQString(uid), version));
108
109
}

110
EteSyncPtr etesync_new(const QString &client_name, const QString &server_url)
111
{
112
    return EteSyncPtr(etesync_new(charArrFromQString(client_name), charArrFromQString(server_url)));
113
114
115
116
}

void etesync_set_auth_token(EteSync *etesync, const QString &token)
{
Shashwat Jolly's avatar
Shashwat Jolly committed
117
    etesync_set_auth_token(etesync, charArrFromQString(token));
118
119
}

120
121
EteSyncSyncEntryPtr etesync_sync_entry_new(const QString &action,
                                           const QString &content)
122
{
123
    return EteSyncSyncEntryPtr(etesync_sync_entry_new(charArrFromQString(action), charArrFromQString(content)));
124
125
}

126
127
EteSyncCryptoManagerPtr etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
                                                             const QString &key)
128
{
129
    return EteSyncCryptoManagerPtr(etesync_user_info_get_crypto_manager(user_info, charArrFromQString(key)));
130
131
}

132
133
EteSyncUserInfoPtr etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
                                                   const QString &owner)
134
{
135
    return EteSyncUserInfoPtr(etesync_user_info_manager_fetch(user_info_manager, charArrFromQString(owner)));
136
}
137

138
EteSyncUserInfoPtr etesync_user_info_new(const QString &owner, uint8_t version)
139
{
140
    return EteSyncUserInfoPtr(etesync_user_info_new(charArrFromQString(owner), version));
141
}