X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fcatalog.c;h=41d450b1544d6fbf2e8e140e016b2b42c2625cc2;hb=cc821d02a37c8c76aaf15bae2d33fee1bdc4b2e0;hp=02dedc4e9319ab5de5499e8e3e8e186eae09f0a3;hpb=e3b9d9c8027a7c4c55cf1614e0fe9423fad69e8f;p=elogind.git diff --git a/src/journal/catalog.c b/src/journal/catalog.c index 02dedc4e9..41d450b15 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -64,7 +64,7 @@ typedef struct CatalogItem { le64_t offset; } CatalogItem; -unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { +static unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { const CatalogItem *i = p; uint64_t u; size_t l, sz; @@ -81,7 +81,7 @@ unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_S return (unsigned long) u; } -int catalog_compare_func(const void *a, const void *b) { +static int catalog_compare_func(const void *a, const void *b) { const CatalogItem *i = a, *j = b; unsigned k; @@ -95,6 +95,11 @@ int catalog_compare_func(const void *a, const void *b) { return strcmp(i->language, j->language); } +const struct hash_ops catalog_hash_ops = { + .hash = catalog_hash_func, + .compare = catalog_compare_func +}; + static int finish_item( Hashmap *h, struct strbuf *sb, @@ -159,6 +164,37 @@ int catalog_file_lang(const char* filename, char **lang) { return 1; } +static int catalog_entry_lang(const char* filename, int line, + const char* t, const char* deflang, char **lang) { + size_t c; + + c = strlen(t); + if (c == 0) { + log_error("[%s:%u] Language too short.", filename, line); + return -EINVAL; + } + if (c > 31) { + log_error("[%s:%u] language too long.", filename, line); + return -EINVAL; + } + + if (deflang) { + if (streq(t, deflang)) { + log_warning("[%s:%u] language specified unnecessarily", + filename, line); + return 0; + } else + log_warning("[%s:%u] language differs from default for file", + filename, line); + } + + *lang = strdup(t); + if (!*lang) + return -ENOMEM; + + return 0; +} + int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *payload = NULL; @@ -238,25 +274,9 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) { if (with_language) { t = strstrip(line + 2 + 1 + 32 + 1); - c = strlen(t); - if (c <= 0) { - log_error("[%s:%u] Language too short.", path, n); - return -EINVAL; - } - if (c > 31) { - log_error("[%s:%u] language too long.", path, n); - return -EINVAL; - } - - if (deflang) { - log_warning("[%s:%u] language %s", path, n, - streq(t, deflang) ? - "specified unnecessarily" : - "differs from default for file"); - lang = strdup(t); - if (!lang) - return -ENOMEM; - } + r = catalog_entry_lang(path, n, t, deflang, &lang); + if (r < 0) + return r; } got_id = true; @@ -392,7 +412,7 @@ int catalog_update(const char* database, const char* root, const char* const* di unsigned n; long r; - h = hashmap_new(catalog_hash_func, catalog_compare_func); + h = hashmap_new(&catalog_hash_ops); sb = strbuf_new(); if (!h || !sb) {