diff options
author | Kristian Høgsberg <krh@redhat.com> | 2008-06-23 09:59:08 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2008-06-23 09:59:08 -0400 |
commit | e7a9df418a6b680878e8e3c0b0129d0b07326ff0 (patch) | |
tree | c4edf4beefaead67bd4bcf5b7a66fe80612f6f53 /librazor | |
parent | 389289592f745d1d506417425211c44b7637b458 (diff) | |
parent | c778afefaa189c6aa8437fc00512f140a6a68efe (diff) |
Merge commit 'jbowes/master'
Diffstat (limited to 'librazor')
-rw-r--r-- | librazor/importer.c | 17 | ||||
-rw-r--r-- | librazor/razor-internal.h | 37 | ||||
-rw-r--r-- | librazor/razor.c | 153 | ||||
-rw-r--r-- | librazor/razor.h | 25 | ||||
-rw-r--r-- | librazor/root.c | 4 | ||||
-rw-r--r-- | librazor/rpm.c | 3 |
6 files changed, 210 insertions, 29 deletions
diff --git a/librazor/importer.c b/librazor/importer.c index eb75605..e2da1b7 100644 --- a/librazor/importer.c +++ b/librazor/importer.c @@ -54,6 +54,19 @@ razor_importer_finish_package(struct razor_importer *importer) } void +razor_importer_add_details(struct razor_importer *importer, + const char *summary, + const char *description, + const char *url, + const char *license) +{ + importer->package->summary = hashtable_tokenize(&importer->details_table, summary); + importer->package->description = hashtable_tokenize(&importer->details_table, description); + importer->package->url = hashtable_tokenize(&importer->details_table, url); + importer->package->license = hashtable_tokenize(&importer->details_table, license); +} + +void razor_importer_add_property(struct razor_importer *importer, const char *name, uint32_t flags, @@ -99,6 +112,10 @@ razor_importer_create(void) importer = zalloc(sizeof *importer); importer->set = razor_set_create(); hashtable_init(&importer->table, &importer->set->string_pool); + hashtable_init(&importer->details_table, + &importer->set->details_string_pool); + hashtable_init(&importer->file_table, + &importer->set->file_string_pool); return importer; } diff --git a/librazor/razor-internal.h b/librazor/razor-internal.h index bcc5e11..94eac41 100644 --- a/librazor/razor-internal.h +++ b/librazor/razor-internal.h @@ -61,26 +61,37 @@ struct razor_set_header { struct razor_set_section sections[0]; }; -#define RAZOR_MAGIC 0x7a7a7a7a +#define RAZOR_MAGIC 0x7a7a7a7a +#define RAZOR_DETAILS_MAGIC 0x7a7a7a7b +#define RAZOR_FILES_MAGIC 0x7a7a7a7c #define RAZOR_VERSION 1 -#define RAZOR_STRING_POOL 0 -#define RAZOR_PACKAGES 1 -#define RAZOR_PROPERTIES 2 -#define RAZOR_FILES 3 -#define RAZOR_PACKAGE_POOL 4 -#define RAZOR_PROPERTY_POOL 5 -#define RAZOR_FILE_POOL 6 +#define RAZOR_STRING_POOL 0 +#define RAZOR_PACKAGES 1 +#define RAZOR_PROPERTIES 2 +#define RAZOR_PACKAGE_POOL 3 +#define RAZOR_PROPERTY_POOL 4 + +#define RAZOR_DETAILS_STRING_POOL 0 + +#define RAZOR_FILES 0 +#define RAZOR_FILE_POOL 1 +#define RAZOR_FILE_STRING_POOL 2 struct razor_package { - uint32_t name : 24; - uint32_t flags : 8; + uint name : 24; + uint flags : 8; uint32_t version; uint32_t arch; + uint32_t summary; + uint32_t description; + uint32_t url; + uint32_t license; struct list_head properties; struct list_head files; }; + struct razor_property { uint32_t name; uint32_t flags; @@ -105,7 +116,11 @@ struct razor_set { struct array package_pool; struct array property_pool; struct array file_pool; + struct array file_string_pool; + struct array details_string_pool; struct razor_set_header *header; + struct razor_set_header *details_header; + struct razor_set_header *files_header; }; struct import_entry { @@ -123,6 +138,8 @@ struct import_directory { struct razor_importer { struct razor_set *set; struct hashtable table; + struct hashtable file_table; + struct hashtable details_table; struct razor_package *package; struct array properties; struct array files; diff --git a/librazor/razor.c b/librazor/razor.c index bb05700..53187a6 100644 --- a/librazor/razor.c +++ b/librazor/razor.c @@ -51,12 +51,19 @@ struct razor_set_section razor_sections[] = { { RAZOR_STRING_POOL, offsetof(struct razor_set, string_pool) }, { RAZOR_PACKAGES, offsetof(struct razor_set, packages) }, { RAZOR_PROPERTIES, offsetof(struct razor_set, properties) }, - { RAZOR_FILES, offsetof(struct razor_set, files) }, { RAZOR_PACKAGE_POOL, offsetof(struct razor_set, package_pool) }, { RAZOR_PROPERTY_POOL, offsetof(struct razor_set, property_pool) }, - { RAZOR_FILE_POOL, offsetof(struct razor_set, file_pool) }, }; +struct razor_set_section razor_files_sections[] = { + { RAZOR_FILES, offsetof(struct razor_set, files) }, + { RAZOR_FILE_POOL, offsetof(struct razor_set, file_pool) }, + { RAZOR_FILE_STRING_POOL, offsetof(struct razor_set, file_string_pool) }, +}; + +struct razor_set_section razor_details_sections[] = { + { RAZOR_DETAILS_STRING_POOL, offsetof(struct razor_set, details_string_pool) }, +}; struct razor_set * razor_set_create(void) { @@ -112,6 +119,62 @@ razor_set_open(const char *filename) } void +razor_set_open_details(struct razor_set *set, const char *filename) +{ + struct razor_set_section *s; + struct stat stat; + struct array *array; + int fd; + + fd = open(filename, O_RDONLY); + if (fstat(fd, &stat) < 0) + return; + set->details_header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (set->details_header == MAP_FAILED) + return; + + for (s = set->details_header->sections; ~s->type; s++) { + if (s->type >= ARRAY_SIZE(razor_details_sections)) + continue; + if (s->type != razor_details_sections[s->type].type) + continue; + array = (void *) set + razor_details_sections[s->type].offset; + array->data = (void *) set->details_header + s->offset; + array->size = s->size; + array->alloc = s->size; + } + close(fd); +} + +void +razor_set_open_files(struct razor_set *set, const char *filename) +{ + struct razor_set_section *s; + struct stat stat; + struct array *array; + int fd; + + fd = open(filename, O_RDONLY); + if (fstat(fd, &stat) < 0) + return; + set->files_header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (set->files_header == MAP_FAILED) + return; + + for (s = set->files_header->sections; ~s->type; s++) { + if (s->type >= ARRAY_SIZE(razor_files_sections)) + continue; + if (s->type != razor_files_sections[s->type].type) + continue; + array = (void *) set + razor_files_sections[s->type].offset; + array->data = (void *) set->files_header + s->offset; + array->size = s->size; + array->alloc = s->size; + } + close(fd); +} + +void razor_set_destroy(struct razor_set *set) { unsigned int size; @@ -130,11 +193,37 @@ razor_set_destroy(struct razor_set *set) } } + if (set->details_header) { + for (i = 0; set->details_header->sections[i].type; i++) + ; + size = set->details_header->sections[i].type; + munmap(set->details_header, size); + } else { + for (i = 0; i < ARRAY_SIZE(razor_details_sections); i++) { + a = (void *) set + razor_details_sections[i].offset; + free(a->data); + } + } + + if (set->files_header) { + for (i = 0; set->files_header->sections[i].type; i++) + ; + size = set->files_header->sections[i].type; + munmap(set->files_header, size); + } else { + for (i = 0; i < ARRAY_SIZE(razor_files_sections); i++) { + a = (void *) set + razor_files_sections[i].offset; + free(a->data); + } + } + free(set); } -int -razor_set_write_to_fd(struct razor_set *set, int fd) +static int +razor_set_write_sections_to_fd(struct razor_set *set, int fd, int magic, + struct razor_set_section *sections, + size_t array_size) { char data[4096]; struct razor_set_header *header = (struct razor_set_header *) data; @@ -143,14 +232,14 @@ razor_set_write_to_fd(struct razor_set *set, int fd) int i; memset(data, 0, sizeof data); - header->magic = RAZOR_MAGIC; + header->magic = magic; header->version = RAZOR_VERSION; offset = sizeof data; - for (i = 0; i < ARRAY_SIZE(razor_sections); i++) { - if (razor_sections[i].type != i) + for (i = 0; i < array_size; i++) { + if (sections[i].type != i) continue; - a = (void *) set + razor_sections[i].offset; + a = (void *) set + sections[i].offset; header->sections[i].type = i; header->sections[i].offset = offset; header->sections[i].size = a->size; @@ -163,10 +252,10 @@ razor_set_write_to_fd(struct razor_set *set, int fd) razor_write(fd, data, sizeof data); memset(data, 0, sizeof data); - for (i = 0; i < ARRAY_SIZE(razor_sections); i++) { - if (razor_sections[i].type != i) + for (i = 0; i < array_size; i++) { + if (sections[i].type != i) continue; - a = (void *) set + razor_sections[i].offset; + a = (void *) set + sections[i].offset; razor_write(fd, a->data, a->size); razor_write(fd, data, ALIGN(a->size, 4096) - a->size); } @@ -175,7 +264,31 @@ razor_set_write_to_fd(struct razor_set *set, int fd) } int -razor_set_write(struct razor_set *set, const char *filename) +razor_set_write_to_fd(struct razor_set *set, int fd, + enum razor_repo_file_type type) +{ + switch (type) { + case RAZOR_REPO_FILE_MAIN: + return razor_set_write_sections_to_fd(set, fd, RAZOR_MAGIC, + razor_sections, + ARRAY_SIZE(razor_sections)); + + case RAZOR_REPO_FILE_DETAILS: + return razor_set_write_sections_to_fd(set, fd, RAZOR_DETAILS_MAGIC, + razor_details_sections, + ARRAY_SIZE(razor_details_sections)); + case RAZOR_REPO_FILE_FILES: + return razor_set_write_sections_to_fd(set, fd, RAZOR_FILES_MAGIC, + razor_files_sections, + ARRAY_SIZE(razor_files_sections)); + default: + return -1; + } +} + +int +razor_set_write(struct razor_set *set, const char *filename, + enum razor_repo_file_type type) { int fd, status; @@ -183,7 +296,7 @@ razor_set_write(struct razor_set *set, const char *filename) if (fd < 0) return -1; - status = razor_set_write_to_fd(set, fd); + status = razor_set_write_to_fd(set, fd, type); if (status) { close(fd); return status; @@ -191,7 +304,6 @@ razor_set_write(struct razor_set *set, const char *filename) return close(fd); } - void razor_build_evr(char *evr_buf, int size, const char *epoch, const char *version, const char *release) @@ -269,6 +381,19 @@ razor_set_get_package(struct razor_set *set, const char *package) return p; } +void +razor_package_get_details(struct razor_set *set, struct razor_package *package, + const char **summary, const char **description, + const char **url, const char **license) +{ + const char *pool = set->details_string_pool.data; + + *summary = &pool[package->summary]; + *description = &pool[package->description]; + *url = &pool[package->url]; + *license = &pool[package->license]; +} + struct razor_entry * razor_set_find_entry(struct razor_set *set, struct razor_entry *dir, const char *pattern) diff --git a/librazor/razor.h b/librazor/razor.h index d8da00b..5040dc0 100644 --- a/librazor/razor.h +++ b/librazor/razor.h @@ -26,6 +26,12 @@ struct razor_set; struct razor_package; struct razor_property; +enum razor_repo_file_type { + RAZOR_REPO_FILE_MAIN, + RAZOR_REPO_FILE_DETAILS, + RAZOR_REPO_FILE_FILES +}; + enum razor_property_flags { RAZOR_PROPERTY_LESS = 1 << 0, RAZOR_PROPERTY_GREATER = 1 << 1, @@ -55,12 +61,22 @@ razor_property_type_to_string(struct razor_property *p); struct razor_set *razor_set_create(void); struct razor_set *razor_set_open(const char *filename); void razor_set_destroy(struct razor_set *set); -int razor_set_write_to_fd(struct razor_set *set, int fd); -int razor_set_write(struct razor_set *set, const char *filename); +int razor_set_write_to_fd(struct razor_set *set, int fd, + enum razor_repo_file_type type); +int razor_set_write(struct razor_set *set, const char *filename, + enum razor_repo_file_type type); + +void razor_set_open_details(struct razor_set *set, const char *filename); +void razor_set_open_files(struct razor_set *set, const char *filename); struct razor_package * razor_set_get_package(struct razor_set *set, const char *package); +void +razor_package_get_details(struct razor_set *set, struct razor_package *package, + const char **summary, const char **description, + const char **url, const char **license); + struct razor_package_iterator; struct razor_package_iterator * razor_package_iterator_create(struct razor_set *set); @@ -162,6 +178,11 @@ void razor_importer_begin_package(struct razor_importer *importer, const char *name, const char *version, const char *arch); +void razor_importer_add_details(struct razor_importer *importer, + const char *summary, + const char *description, + const char *url, + const char *license); void razor_importer_add_property(struct razor_importer *importer, const char *name, uint32_t flags, diff --git a/librazor/root.c b/librazor/root.c index 9e0ae26..6cef276 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -58,7 +58,7 @@ razor_root_create(const char *root) "a razor install root is already initialized\n"); return -1; } - if (razor_set_write(set, path) < 0) { + if (razor_set_write(set, path, RAZOR_REPO_FILE_MAIN) < 0) { fprintf(stderr, "could not write initial package set\n"); return -1; } @@ -138,7 +138,7 @@ razor_root_close(struct razor_root *root) void razor_root_update(struct razor_root *root, struct razor_set *next) { - razor_set_write_to_fd(next, root->fd); + razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN); root->next = next; /* Sync the new repo file so the new package set is on disk diff --git a/librazor/rpm.c b/librazor/rpm.c index 21fde8d..8bd5289 100644 --- a/librazor/rpm.c +++ b/librazor/rpm.c @@ -781,7 +781,7 @@ razor_rpm_close(struct razor_rpm *rpm) int razor_importer_add_rpm(struct razor_importer *importer, struct razor_rpm *rpm) { - const char *name, *version, *release, *arch; + const char *name, *version, *release, *arch, *summary; const uint32_t *epoch; char evr[128], buf[16]; @@ -790,6 +790,7 @@ razor_importer_add_rpm(struct razor_importer *importer, struct razor_rpm *rpm) version = razor_rpm_get_indirect(rpm, RPMTAG_VERSION, NULL); release = razor_rpm_get_indirect(rpm, RPMTAG_RELEASE, NULL); arch = razor_rpm_get_indirect(rpm, RPMTAG_ARCH, NULL); + summary = razor_rpm_get_indirect(rpm, RPMTAG_SUMMARY, NULL); if (epoch) { snprintf(buf, sizeof buf, "%u", ntohl(*epoch)); |