-
Notifications
You must be signed in to change notification settings - Fork 2
/
capi_db.cpp
421 lines (357 loc) · 12.4 KB
/
capi_db.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#include "main.h"
#include "elf.h"
#include "package.h"
#include "db.h"
#include "pkgdepdb.h"
#include "capi_algorithm.h"
using namespace pkgdepdb;
extern "C" {
pkgdepdb_db *pkgdepdb_db_new(pkgdepdb_cfg *cfg_) {
auto cfg = reinterpret_cast<Config*>(cfg_);
return reinterpret_cast<pkgdepdb_db*>(new DB(*cfg));
}
void pkgdepdb_db_delete(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
delete db;
}
pkgdepdb_bool pkgdepdb_db_load(pkgdepdb_db *db_, const char *filename) {
auto db = reinterpret_cast<DB*>(db_);
return db->Load(filename);
}
pkgdepdb_bool pkgdepdb_db_store(pkgdepdb_db *db_, const char *filename) {
auto db = reinterpret_cast<DB*>(db_);
return db->Store(filename);
}
unsigned int pkgdepdb_db_loaded_version(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->loaded_version_;
}
pkgdepdb_bool pkgdepdb_db_strict_linking(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->strict_linking_;
}
void pkgdepdb_db_set_strict_linking(pkgdepdb_db *db_, pkgdepdb_bool v) {
auto db = reinterpret_cast<DB*>(db_);
db->strict_linking_ = v;
}
const char* pkgdepdb_db_name(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->name_.c_str();
}
void pkgdepdb_db_set_name(pkgdepdb_db *db_, const char *v) {
auto db = reinterpret_cast<DB*>(db_);
db->name_ = v;
}
size_t pkgdepdb_db_library_path_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->library_path_.size();
}
size_t pkgdepdb_db_library_path_get(pkgdepdb_db *db_, const char **out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_get(*db, &DB::library_path_, out, off, count);
}
pkgdepdb_bool pkgdepdb_db_library_path_add(pkgdepdb_db *db_, const char *path)
{
auto db = reinterpret_cast<DB*>(db_);
return db->LD_Append(path);
}
pkgdepdb_bool pkgdepdb_db_library_path_insert(pkgdepdb_db *db_, size_t index,
const char *path)
{
auto db = reinterpret_cast<DB*>(db_);
return db->LD_Insert(path, index);
}
size_t pkgdepdb_db_library_path_insert_r(pkgdepdb_db *db_, size_t index,
size_t count, const char **paths)
{
auto db = reinterpret_cast<DB*>(db_);
std::set<string> pv;
for (size_t i = 0; i != count; ++i) {
string s(paths[i]);
fixpath(s);
pv.insert(s);
}
db->library_path_.insert(db->library_path_.begin() + index,
pv.begin(), pv.end());
/* STL SUCKS
std::make_move_iterator(pv.begin()),
std::make_move_iterator(pv.end()));
*/
return pv.size();
}
pkgdepdb_bool pkgdepdb_db_library_path_contains(pkgdepdb_db *db_,
const char *path)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_contains(db->library_path_, path);
}
pkgdepdb_bool pkgdepdb_db_library_path_del_s(pkgdepdb_db *db_, const char *path) {
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_del_s_one(db->library_path_, path) == 1;
}
pkgdepdb_bool pkgdepdb_db_library_path_del_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
return db->LD_Delete(index);
}
size_t pkgdepdb_db_library_path_del_r(pkgdepdb_db *db_, size_t index,
size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_del_r(db->library_path_, index, count);
}
pkgdepdb_bool pkgdepdb_db_library_path_set_i(pkgdepdb_db *db_, size_t index,
const char *v)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_set_i(db->library_path_, index, v);
}
size_t pkgdepdb_db_package_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->packages_.size();
}
pkgdepdb_pkg* pkgdepdb_db_package_find(pkgdepdb_db *db_, const char *name) {
auto db = reinterpret_cast<DB*>(db_);
return reinterpret_cast<pkgdepdb_pkg*>(db->FindPkg(name));
}
size_t pkgdepdb_db_package_get(pkgdepdb_db *db_, pkgdepdb_pkg **out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
auto len = db->packages_.size();
if (off >= len)
return 0;
size_t got = 0;
if (count > len - off)
count = len - off;
while (got < count)
out[got++] = reinterpret_cast<pkgdepdb_pkg*>(db->packages_[off++]);
return got;
}
pkgdepdb_bool pkgdepdb_db_package_install(pkgdepdb_db *db_, pkgdepdb_pkg *pkg_)
{
auto db = reinterpret_cast<DB*>(db_);
auto pkg = reinterpret_cast<Package*>(pkg_);
return db->InstallPackage(move(pkg)) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_delete_p(pkgdepdb_db *db_,
pkgdepdb_pkg *pkg_)
{
auto db = reinterpret_cast<DB*>(db_);
auto pkg = reinterpret_cast<Package*>(pkg_);
auto pkgiter = std::find(db->packages_.begin(), db->packages_.end(), pkg);
return db->DeletePackage(pkgiter) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_remove_p(pkgdepdb_db *db_,
pkgdepdb_pkg *pkg_)
{
auto db = reinterpret_cast<DB*>(db_);
auto pkg = reinterpret_cast<Package*>(pkg_);
auto pkgiter = std::find(db->packages_.begin(), db->packages_.end(), pkg);
return db->DeletePackage(pkgiter, false) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_delete_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
if (index >= db->packages_.size())
return 0;
return db->DeletePackage(db->packages_.begin() + index) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_remove_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
if (index >= db->packages_.size())
return 0;
return db->DeletePackage(db->packages_.begin() + index, false) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_delete_s(pkgdepdb_db *db_, const char *name)
{
auto db = reinterpret_cast<DB*>(db_);
return db->DeletePackage(name) ? 1 : 0;
}
pkgdepdb_bool pkgdepdb_db_package_is_broken(pkgdepdb_db *db_,
pkgdepdb_pkg *pkg_)
{
auto db = reinterpret_cast<DB*>(db_);
auto pkg = reinterpret_cast<Package*>(pkg_);
return db->IsBroken(pkg) ? 1 : 0;
}
size_t pkgdepdb_db_object_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->objects_.size();
}
size_t pkgdepdb_db_object_get(pkgdepdb_db *db_, pkgdepdb_elf *out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
if (off >= db->objects_.size())
return 0;
size_t got = 0;
for (auto i = db->objects_.begin() + off; i != db->objects_.end(); ++i) {
if (!count--)
return got;
rptr<Elf> **dest = reinterpret_cast<rptr<Elf>**>(&out[got++]);
if (*dest)
**dest = *i;
else
*dest = new rptr<Elf>(*i);
}
return got;
}
size_t pkgdepdb_db_ignored_files_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->ignore_file_rules_.size();
}
size_t pkgdepdb_db_ignored_files_get(pkgdepdb_db *d_, const char **out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(d_);
return pkgdepdb_strlist_get(*db, &DB::ignore_file_rules_, out, off, count);
}
pkgdepdb_bool pkgdepdb_db_ignored_files_add(pkgdepdb_db *db_, const char *file)
{
auto db = reinterpret_cast<DB*>(db_);
return db->IgnoreFile_Add(file);
}
size_t pkgdepdb_db_ignored_files_add_r(pkgdepdb_db *db_, size_t count,
const char **files)
{
auto db = reinterpret_cast<DB*>(db_);
size_t cnt = 0;
for (size_t i = 0; i != count; ++i)
cnt += db->IgnoreFile_Add(files[i]) ? 1 : 0;
return cnt;
}
pkgdepdb_bool pkgdepdb_db_ignored_files_contains(pkgdepdb_db *db_,
const char *file)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_contains(db->ignore_file_rules_, file);
}
pkgdepdb_bool pkgdepdb_db_ignored_files_del_s(pkgdepdb_db *db_,
const char *file)
{
auto db = reinterpret_cast<DB*>(db_);
return db->IgnoreFile_Delete(file);
}
pkgdepdb_bool pkgdepdb_db_ignored_files_del_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
return db->IgnoreFile_Delete(index);
}
size_t pkgdepdb_db_ignored_files_del_r(pkgdepdb_db *db_, size_t index,
size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_del_r(db->ignore_file_rules_, index, count);
}
size_t pkgdepdb_db_base_packages_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->base_packages_.size();
}
size_t pkgdepdb_db_base_packages_get(pkgdepdb_db *d_, const char **out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(d_);
return pkgdepdb_strlist_get(*db, &DB::base_packages_, out, off, count);
}
size_t pkgdepdb_db_base_packages_add(pkgdepdb_db *db_, const char *name) {
auto db = reinterpret_cast<DB*>(db_);
return db->BasePackages_Add(name);
}
size_t pkgdepdb_db_base_packages_add_r(pkgdepdb_db *db_, size_t count,
const char **names)
{
auto db = reinterpret_cast<DB*>(db_);
size_t cnt = 0;
for (size_t i = 0; i != count; ++i)
cnt += db->BasePackages_Add(names[i]) ? 1 : 0;
return cnt;
}
pkgdepdb_bool pkgdepdb_db_base_packages_contains(pkgdepdb_db *db_,
const char *name)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_contains(db->base_packages_, name);
}
pkgdepdb_bool pkgdepdb_db_base_packages_del_s(pkgdepdb_db *db_,
const char *name)
{
auto db = reinterpret_cast<DB*>(db_);
return db->BasePackages_Delete(name);
}
pkgdepdb_bool pkgdepdb_db_base_packages_del_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
return db->BasePackages_Delete(index);
}
size_t pkgdepdb_db_base_packages_del_r(pkgdepdb_db *db_, size_t index,
size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_del_r(db->base_packages_, index, count);
}
size_t pkgdepdb_db_assume_found_count(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->assume_found_rules_.size();
}
size_t pkgdepdb_db_assume_found_get(pkgdepdb_db *db_, const char **out,
size_t off, size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_get(*db, &DB::assume_found_rules_, out, off, count);
}
pkgdepdb_bool pkgdepdb_db_assume_found_add(pkgdepdb_db *db_, const char *lib) {
auto db = reinterpret_cast<DB*>(db_);
return db->AssumeFound_Add(lib);
}
size_t pkgdepdb_db_assume_found_add_r(pkgdepdb_db *db_, size_t count,
const char **libs)
{
auto db = reinterpret_cast<DB*>(db_);
size_t cnt = 0;
for (size_t i = 0; i != count; ++i)
cnt += db->AssumeFound_Add(libs[i]) ? 1 : 0;
return cnt;
}
pkgdepdb_bool pkgdepdb_db_assume_found_contains(pkgdepdb_db *db_,
const char *lib)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_contains(db->assume_found_rules_, lib);
}
pkgdepdb_bool pkgdepdb_db_assume_found_del_s(pkgdepdb_db *db_, const char *lib)
{
auto db = reinterpret_cast<DB*>(db_);
return db->AssumeFound_Delete(lib);
}
pkgdepdb_bool pkgdepdb_db_assume_found_del_i(pkgdepdb_db *db_, size_t index) {
auto db = reinterpret_cast<DB*>(db_);
return db->AssumeFound_Delete(index);
}
size_t pkgdepdb_db_assume_found_del_r(pkgdepdb_db *db_, size_t index,
size_t count)
{
auto db = reinterpret_cast<DB*>(db_);
return pkgdepdb_strlist_del_r(db->assume_found_rules_, index, count);
}
void pkgdepdb_db_relink_all(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->RelinkAll();
}
void pkgdepdb_db_fix_paths(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->FixPaths();
}
pkgdepdb_bool pkgdepdb_db_wipe_packages(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->WipePackages();
}
pkgdepdb_bool pkgdepdb_db_wipe_filelists(pkgdepdb_db *db_) {
auto db = reinterpret_cast<DB*>(db_);
return db->WipeFilelists();
}
pkgdepdb_bool pkgdepdb_db_object_is_broken(pkgdepdb_db *db_, pkgdepdb_elf elf_)
{
auto db = reinterpret_cast<DB*>(db_);
auto elf = *reinterpret_cast<rptr<Elf>*>(elf_);
return db->IsBroken(elf) ? 1 : 0;
}
} /* extern "C" */