Skip to content

Commit

Permalink
Delete more unused code (from hexmap.c).
Browse files Browse the repository at this point in the history
Change-Id: I44357245484605d05fe73cfc880db2ef1dd7ba35
  • Loading branch information
grke committed Jun 22, 2022
1 parent 3229eb8 commit 8499353
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 289 deletions.
107 changes: 0 additions & 107 deletions src/hexmap.c
Original file line number Diff line number Diff line change
@@ -1,117 +1,10 @@
#include "burp.h"
#include "hexmap.h"

// FIX THIS: Should be set in configure somewhere.
#include <openssl/md5.h>

#define HEXMAP_SIZE 256

static uint8_t hexmap1[HEXMAP_SIZE];
static uint8_t hexmap2[HEXMAP_SIZE];

uint8_t md5sum_of_empty_string[MD5_DIGEST_LENGTH];

static void do_hexmap_init(uint8_t *hexmap, uint8_t shift)
{
uint8_t i;
uint8_t h;
memset(hexmap, 0, HEXMAP_SIZE);
for(i='0', h=0x00; i<='9'; i++, h++) hexmap[i]=h<<shift;
for(i='a', h=0x0A; i<='f'; i++, h++) hexmap[i]=h<<shift;
for(i='A', h=0x0A; i<='F'; i++, h++) hexmap[i]=h<<shift;
}

void hexmap_init(void)
{
do_hexmap_init(hexmap1, 4);
do_hexmap_init(hexmap2, 0);
md5str_to_bytes("D41D8CD98F00B204E9800998ECF8427E",
md5sum_of_empty_string);
}

static void str_to_bytes(const char *str, uint8_t *bytes, size_t len)
{
static uint8_t bpos;
static uint8_t spos;

for(bpos=0, spos=0; bpos<len && str[spos]; )
{
if(str[spos]=='/')
{
spos++;
continue;
}
#if BYTE_ORDER == LITTLE_ENDIAN
bytes[bpos++] = hexmap1[(uint8_t)str[spos]]
| hexmap2[(uint8_t)str[spos+1]];
#elif BYTE_ORDER == BIG_ENDIAN
bytes[bpos-bpos%4+3-bpos%4] = hexmap1[(uint8_t)str[spos]]
| hexmap2[(uint8_t)str[spos+1]];
bpos+=1;
#else
#error byte order not supported
#endif
spos+=2;
}
}

void md5str_to_bytes(const char *md5str, uint8_t *bytes)
{
str_to_bytes(md5str, bytes, MD5_DIGEST_LENGTH);
}

char *bytes_to_md5str(uint8_t *bytes)
{
static char str[64];
snprintf(str, sizeof(str), "%016" PRIx64 "%016" PRIx64,
htobe64(*(uint64_t *)bytes), htobe64(*(uint64_t *)(bytes+8)));
return str;
}

uint64_t savepathstr_with_sig_to_uint64(const char *savepathstr)
{
uint8_t b[sizeof(uint64_t)];
str_to_bytes(savepathstr, b, sizeof(b));
return htobe64(*(uint64_t *)&b);
}

static char *savepathstr_make(uint64_t *be_bytes)
{
static char str[15];
uint8_t *b=(uint8_t *)be_bytes;
snprintf(str, sizeof(str), "%02X%02X/%02X%02X/%02X%02X",
b[0], b[1], b[2], b[3], b[4], b[5]);
return str;
}

char *uint64_to_savepathstr(uint64_t bytes)
{
uint64_t be_bytes=htobe64(bytes);
return savepathstr_make(&be_bytes);
}

char *uint64_to_savepathstr_with_sig(uint64_t bytes)
{
static char str[20];
uint64_t be_bytes=htobe64(bytes);
uint8_t *b=(uint8_t *)&be_bytes;
snprintf(str, sizeof(str), "%02X%02X/%02X%02X/%02X%02X/%02X%02X",
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
return str;
}

char *uint64_to_savepathstr_with_sig_uint(uint64_t bytes, uint16_t *sig)
{
char *str;
uint64_t be_bytes=htobe64(bytes);
uint8_t *b=(uint8_t *)&be_bytes;
str=savepathstr_make(&be_bytes);
*sig = b[6] << 8;
*sig |= b[7];
return str;
}

uint64_t uint64_to_savepath_hash_key(uint64_t bytes)
{
return bytes & 0xFFFFFFFFFFFF0000;
}
11 changes: 0 additions & 11 deletions src/hexmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@

#include "burp.h"

extern uint8_t md5sum_of_empty_string[];

extern void hexmap_init(void);

extern void md5str_to_bytes(const char *md5str, uint8_t *bytes);
extern char *bytes_to_md5str(uint8_t *bytes);

extern uint64_t savepathstr_with_sig_to_uint64(const char *savepathstr);
extern char *uint64_to_savepathstr(uint64_t bytes);
extern char *uint64_to_savepathstr_with_sig(uint64_t bytes);
extern char *uint64_to_savepathstr_with_sig_uint(uint64_t bytes, uint16_t *sig);
extern uint64_t uint64_to_savepath_hash_key(uint64_t bytes);

#endif
1 change: 0 additions & 1 deletion src/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ int real_main(int argc, char *argv[])
goto end;

base64_init();
hexmap_init();

if(mode==BURP_MODE_SERVER)
{
Expand Down
1 change: 0 additions & 1 deletion utest/client/test_backup_phase2.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ static void run_test(int expected_ret,

prng_init(0);
base64_init();
hexmap_init();

as=setup_async();
confs=setup_conf();
Expand Down
1 change: 0 additions & 1 deletion utest/server/monitor/test_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ static struct sdirs *setup(void)
struct sdirs *sdirs;
prng_init(0);
base64_init();
hexmap_init();
fail_unless(!recursive_delete(BASE));
fail_unless((sdirs=sdirs_alloc())!=NULL);
do_sdirs_init(sdirs);
Expand Down
2 changes: 0 additions & 2 deletions utest/server/test_backup_phase2.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ static void run_test(int expected_ret,
struct slist *slist=NULL;
prng_init(0);
base64_init();
hexmap_init();
setup(&as, &sdirs, &confs);
asfd=asfd_mock_setup(&reads, &writes);
as->asfd_add(as, asfd);
Expand Down Expand Up @@ -349,7 +348,6 @@ static void run_test_changed(int expected_ret,
struct slist *slist=NULL;
prng_init(0);
base64_init();
hexmap_init();
setup(&as, &sdirs, &confs);
asfd=asfd_mock_setup(&reads, &writes);
as->asfd_add(as, asfd);
Expand Down
1 change: 0 additions & 1 deletion utest/server/test_dpth.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static void assert_components(struct dpth *dpth,
static struct dpth *setup(void)
{
struct dpth *dpth;
hexmap_init();
fail_unless(recursive_delete(basepath)==0);
fail_unless((dpth=dpth_alloc())!=NULL);
assert_components(dpth, 0, 0, 0);
Expand Down
2 changes: 0 additions & 2 deletions utest/server/test_manio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ static void test_manifest(int phase)
int entries=1000;
prng_init(0);
base64_init();
hexmap_init();
recursive_delete(path);

slist=build_manifest(path, entries, phase);
Expand Down Expand Up @@ -124,7 +123,6 @@ static void test_manifest_tell_seek(int phase)
int entries=1000;
prng_init(0);
base64_init();
hexmap_init();
recursive_delete(path);

slist=build_manifest(path, entries, phase);
Expand Down
1 change: 0 additions & 1 deletion utest/server/test_restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ static void run_test(int expected_ret,
char *dir_for_notify=NULL;
prng_init(0);
base64_init();
hexmap_init();
setup(&as, &sdirs, &confs);
set_string(confs[OPT_BACKUP], "1");
asfd=asfd_mock_setup(&reads, &writes);
Expand Down
3 changes: 0 additions & 3 deletions utest/server/test_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ static void last_good_entry(void setup_slist(struct slist *, int *))

prng_init(0);
base64_init();
hexmap_init();
fail_unless(!recursive_delete(path));

fail_unless((slist=slist_alloc())!=NULL);
Expand Down Expand Up @@ -430,7 +429,6 @@ static void go_past_entry(void setup_slist(struct slist *, int *))

prng_init(0);
base64_init();
hexmap_init();
fail_unless(!recursive_delete(path));

fail_unless((slist=slist_alloc())!=NULL);
Expand Down Expand Up @@ -616,7 +614,6 @@ static void go_before_entry(

prng_init(0);
base64_init();
hexmap_init();
fail_unless(!recursive_delete(path));

fail_unless((slist=slist_alloc())!=NULL);
Expand Down
Loading

0 comments on commit 8499353

Please sign in to comment.