| 1 |
#pragma once |
| 2 |
#include <apt-pkg/cachefile.h> |
| 3 |
#include <apt-pkg/indexfile.h> |
| 4 |
#include <apt-pkg/pkgcache.h> |
| 5 |
#include <apt-pkg/pkgrecords.h> |
| 6 |
#include <apt-pkg/pkgsystem.h> |
| 7 |
#include <apt-pkg/sourcelist.h> |
| 8 |
#include <memory> |
| 9 |
#include "rust/cxx.h" |
| 10 |
|
| 11 |
#include "package.h" |
| 12 |
#include "types.h" |
| 13 |
|
| 14 |
struct IndexFile { |
| 15 |
pkgIndexFile* ptr; |
| 16 |
|
| 17 |
String archive_uri(str filename) const { return ptr->ArchiveURI(std::string(filename)); } |
| 18 |
bool is_trusted() const { return ptr->IsTrusted(); } |
| 19 |
|
| 20 |
IndexFile(pkgIndexFile* file) : ptr(file){}; |
| 21 |
}; |
| 22 |
|
| 23 |
struct Parser { |
| 24 |
pkgRecords::Parser& ptr; |
| 25 |
|
| 26 |
String short_desc() const { return handle_string(ptr.ShortDesc()); } |
| 27 |
String long_desc() const { return handle_string(ptr.LongDesc()); } |
| 28 |
String filename() const { return ptr.FileName(); } |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
String get_field(String field) const { return handle_string(ptr.RecordField(field.c_str())); } |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
String hash_find(String hash_type) const { |
| 42 |
auto hashes = ptr.Hashes(); |
| 43 |
auto hash = hashes.find(hash_type.c_str()); |
| 44 |
if (hash == NULL) { throw std::runtime_error("Hash Not Found"); } |
| 45 |
return handle_string(hash->HashValue()); |
| 46 |
} |
| 47 |
|
| 48 |
Parser(pkgRecords::Parser& parser) : ptr(parser){}; |
| 49 |
}; |
| 50 |
|
| 51 |
struct PkgRecords { |
| 52 |
pkgRecords mutable records; |
| 53 |
|
| 54 |
UniquePtr<Parser> ver_lookup(const VerFileIterator& file) const { |
| 55 |
return std::make_unique<Parser>(records.Lookup(file)); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
UniquePtr<Parser> desc_lookup(const DescIterator& desc) const { |
| 60 |
return std::make_unique<Parser>(records.Lookup(desc.FileList())); |
| 61 |
} |
| 62 |
|
| 63 |
PkgRecords(pkgCacheFile* cache) : records(*cache->GetPkgCache()){}; |
| 64 |
}; |