From adc4c2932ec7039a6b7effeace098e5bc46861c6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 27 Jan 2013 18:43:41 +0000 Subject: [PATCH] luci-0.11: merge r9648, r9649 and r9654 --- libs/web/src/po2lmo.c | 29 +++++++++++++++++------------ libs/web/src/template_lmo.c | 17 ++++++++++------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/libs/web/src/po2lmo.c b/libs/web/src/po2lmo.c index fb607a46f..0da792b68 100644 --- a/libs/web/src/po2lmo.c +++ b/libs/web/src/po2lmo.c @@ -84,8 +84,8 @@ static int extract_string(const char *src, char *dest, int len) static int cmp_index(const void *a, const void *b) { - uint32_t x = ntohl(((const lmo_entry_t *)a)->key_id); - uint32_t y = ntohl(((const lmo_entry_t *)b)->key_id); + uint32_t x = ((const lmo_entry_t *)a)->key_id; + uint32_t y = ((const lmo_entry_t *)b)->key_id; if (x < y) return -1; @@ -95,6 +95,12 @@ static int cmp_index(const void *a, const void *b) return 0; } +static void print_uint32(uint32_t x, FILE *out) +{ + uint32_t y = htonl(x); + print(&y, sizeof(uint32_t), 1, out); +} + static void print_index(void *array, int n, FILE *out) { lmo_entry_t *e; @@ -103,10 +109,10 @@ static void print_index(void *array, int n, FILE *out) for (e = array; n > 0; n--, e++) { - print(&e->key_id, sizeof(uint32_t), 1, out); - print(&e->val_id, sizeof(uint32_t), 1, out); - print(&e->offset, sizeof(uint32_t), 1, out); - print(&e->length, sizeof(uint32_t), 1, out); + print_uint32(e->key_id, out); + print_uint32(e->val_id, out); + print_uint32(e->offset, out); + print_uint32(e->length, out); } } @@ -202,10 +208,10 @@ int main(int argc, char *argv[]) if (!array) die("Out of memory"); - entry->key_id = htonl(key_id); - entry->val_id = htonl(val_id); - entry->offset = htonl(offset); - entry->length = htonl(strlen(val)); + entry->key_id = key_id; + entry->val_id = val_id; + entry->offset = offset; + entry->length = strlen(val); length = strlen(val) + ((4 - (strlen(val) % 4)) % 4); @@ -226,8 +232,7 @@ int main(int argc, char *argv[]) if( offset > 0 ) { - offset = htonl(offset); - print(&offset, sizeof(uint32_t), 1, out); + print_uint32(offset, out); fsync(fileno(out)); fclose(out); } diff --git a/libs/web/src/template_lmo.c b/libs/web/src/template_lmo.c index 7fcd2cda1..27205a722 100644 --- a/libs/web/src/template_lmo.c +++ b/libs/web/src/template_lmo.c @@ -123,8 +123,8 @@ lmo_archive_t * lmo_open(const char *file) if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED) goto err; - idx_offset = *((const uint32_t *) - (ar->mmap + ar->size - sizeof(uint32_t))); + idx_offset = ntohl(*((const uint32_t *) + (ar->mmap + ar->size - sizeof(uint32_t)))); if (idx_offset >= ar->size) goto err; @@ -244,6 +244,7 @@ int lmo_change_catalog(const char *lang) static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash) { unsigned int m, l, r; + uint32_t k; l = 0; r = ar->length - 1; @@ -255,10 +256,12 @@ static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash) if (r < l) break; - if (ar->index[m].key_id == hash) + k = ntohl(ar->index[m].key_id); + + if (k == hash) return &ar->index[m]; - if (ar->index[m].key_id > hash) + if (k > hash) { if (!m) break; @@ -283,14 +286,14 @@ int lmo_translate(const char *key, int keylen, char **out, int *outlen) if (!key || !_lmo_active_catalog) return -2; - hash = htonl(lmo_canon_hash(key, keylen)); + hash = lmo_canon_hash(key, keylen); for (ar = _lmo_active_catalog->archives; ar; ar = ar->next) { if ((e = lmo_find_entry(ar, hash)) != NULL) { - *out = ar->mmap + e->offset; - *outlen = e->length; + *out = ar->mmap + ntohl(e->offset); + *outlen = ntohl(e->length); return 0; } } -- 2.25.1