Progress on haggis_load_node
; Ensure local vars are at top of
functions;
This commit is contained in:
parent
47640e5818
commit
5b520b54e2
1 changed files with 45 additions and 13 deletions
54
src/haggis.c
54
src/haggis.c
|
@ -86,7 +86,8 @@ int haggis_load_device(FILE *stream, union haggis_ft *ft) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int haggis_store_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
int haggis_store_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
||||||
char flag;
|
u8 flag;
|
||||||
|
|
||||||
switch (cksum->tag) {
|
switch (cksum->tag) {
|
||||||
case md5:
|
case md5:
|
||||||
flag = 0;
|
flag = 0;
|
||||||
|
@ -119,7 +120,8 @@ int haggis_store_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int haggis_load_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
int haggis_load_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
||||||
char flag;
|
u8 flag;
|
||||||
|
|
||||||
if (fread(&flag, 1, 1, stream) != 1)
|
if (fread(&flag, 1, 1, stream) != 1)
|
||||||
return 1;
|
return 1;
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
|
@ -147,7 +149,8 @@ int haggis_load_cksum(FILE *stream, struct haggis_checksum *cksum) {
|
||||||
|
|
||||||
int validate_md5(struct haggis_file *file) {
|
int validate_md5(struct haggis_file *file) {
|
||||||
MD5_CTX ctx;
|
MD5_CTX ctx;
|
||||||
u8 digest[MD5_DIGEST_LENGTH];
|
u8 digest[16];
|
||||||
|
|
||||||
MD5Init(&ctx);
|
MD5Init(&ctx);
|
||||||
MD5Update(&ctx, file->data, (size_t)file->len.val);
|
MD5Update(&ctx, file->data, (size_t)file->len.val);
|
||||||
MD5Final(digest, &ctx);
|
MD5Final(digest, &ctx);
|
||||||
|
@ -160,6 +163,7 @@ int validate_md5(struct haggis_file *file) {
|
||||||
int validate_sha1(struct haggis_file *file) {
|
int validate_sha1(struct haggis_file *file) {
|
||||||
SHA1_CTX ctx;
|
SHA1_CTX ctx;
|
||||||
u8 digest[20];
|
u8 digest[20];
|
||||||
|
|
||||||
SHA1_Init(&ctx);
|
SHA1_Init(&ctx);
|
||||||
SHA1_Update(&ctx, file->data, (size_t)file->len.val);
|
SHA1_Update(&ctx, file->data, (size_t)file->len.val);
|
||||||
SHA1_Final(digest, &ctx);
|
SHA1_Final(digest, &ctx);
|
||||||
|
@ -171,6 +175,7 @@ int validate_sha1(struct haggis_file *file) {
|
||||||
int validate_sha1(struct haggis_file *file) {
|
int validate_sha1(struct haggis_file *file) {
|
||||||
SHA1_CTX ctx;
|
SHA1_CTX ctx;
|
||||||
u8 digest[20];
|
u8 digest[20];
|
||||||
|
|
||||||
SHA1Init(&ctx);
|
SHA1Init(&ctx);
|
||||||
SHA1Update(&ctx, file->data, (size_t)file->len.val);
|
SHA1Update(&ctx, file->data, (size_t)file->len.val);
|
||||||
SHA1Final(digest, &ctx);
|
SHA1Final(digest, &ctx);
|
||||||
|
@ -183,7 +188,8 @@ int validate_sha1(struct haggis_file *file) {
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly) || defined(__NetBSD__)
|
#if defined(__FreeBSD__) || defined(__DragonFly) || defined(__NetBSD__)
|
||||||
int validate_sha256(struct haggis_file *file) {
|
int validate_sha256(struct haggis_file *file) {
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
u8 digest[SHA256_DIGEST_LENGTH];
|
u8 digest[32];
|
||||||
|
|
||||||
SHA256_Init(&ctx);
|
SHA256_Init(&ctx);
|
||||||
SHA256_Update(&ctx, file->data, (size_t)file->len.val);
|
SHA256_Update(&ctx, file->data, (size_t)file->len.val);
|
||||||
SHA256_Final(digest, &ctx);
|
SHA256_Final(digest, &ctx);
|
||||||
|
@ -194,7 +200,8 @@ int validate_sha256(struct haggis_file *file) {
|
||||||
#elif defined(__linux__) || defined(__OpenBSD__)
|
#elif defined(__linux__) || defined(__OpenBSD__)
|
||||||
int validate_sha256(struct haggis_file *file) {
|
int validate_sha256(struct haggis_file *file) {
|
||||||
SHA2_CTX ctx;
|
SHA2_CTX ctx;
|
||||||
u8 digest[SHA256_DIGEST_LENGTH];
|
u8 digest[32];
|
||||||
|
|
||||||
SHA256Init(&ctx);
|
SHA256Init(&ctx);
|
||||||
SHA256Update(&ctx, file->data, (size_t)file->len.val);
|
SHA256Update(&ctx, file->data, (size_t)file->len.val);
|
||||||
SHA256Final(digest, &ctx);
|
SHA256Final(digest, &ctx);
|
||||||
|
@ -232,6 +239,7 @@ int haggis_store_file(FILE *stream, struct haggis_file *file) {
|
||||||
int haggis_load_file(FILE *stream, union haggis_ft *ft) {
|
int haggis_load_file(FILE *stream, union haggis_ft *ft) {
|
||||||
union u64 len;
|
union u64 len;
|
||||||
len.val = 0;
|
len.val = 0;
|
||||||
|
|
||||||
if (load_u64(stream, len) != 8)
|
if (load_u64(stream, len) != 8)
|
||||||
return 1;
|
return 1;
|
||||||
ft->file->len = len;
|
ft->file->len = len;
|
||||||
|
@ -315,17 +323,20 @@ int haggis_store_filetype(FILE *stream, struct haggis_filetype *filetype) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int haggis_load_link(FILE *stream, union haggis_ft *ft) {
|
int haggis_load_filename(FILE *stream, struct haggis_filename *n) {
|
||||||
union u16 len;
|
union u16 len;
|
||||||
|
char *name;
|
||||||
|
|
||||||
len.val = 0;
|
len.val = 0;
|
||||||
if (fread(len.bytes, 1, 2, stream) != 2)
|
if (fread(len.bytes, 1, 2, stream) != 2)
|
||||||
return 2;
|
return 2;
|
||||||
ft->target->len = len;
|
n->len = len;
|
||||||
u8 *target = malloc((size_t)len.val);
|
name = malloc((size_t)len.val);
|
||||||
if (fread(target, 1, (size_t)len.val, stream) != (size_t)len.val) {
|
if (fread(name, 1, (size_t)len.val, stream) != (size_t)len.val) {
|
||||||
free(target);
|
free(name);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
n->name = name;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,8 +350,10 @@ int haggis_load_filetype(
|
||||||
file->tag = 0;
|
file->tag = 0;
|
||||||
return haggis_load_file(stream, file->f_type);
|
return haggis_load_file(stream, file->f_type);
|
||||||
case hardlink:
|
case hardlink:
|
||||||
|
return haggis_load_filename(stream, file->f_type->target);
|
||||||
file->tag = 1;
|
file->tag = 1;
|
||||||
case softlink:
|
case softlink:
|
||||||
|
return haggis_load_filename(stream, file->f_type->target);
|
||||||
file->tag = 2;
|
file->tag = 2;
|
||||||
case directory:
|
case directory:
|
||||||
file->tag = 3;
|
file->tag = 3;
|
||||||
|
@ -367,6 +380,25 @@ int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
||||||
// todo
|
int res;
|
||||||
|
union u16 mode;
|
||||||
|
enum haggis_typeflag flag;
|
||||||
|
|
||||||
|
res = haggis_load_filename(stream, node->name);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
res = load_u32(stream, node->uid);
|
||||||
|
if (res != 4)
|
||||||
|
return 2;
|
||||||
|
res = load_u32(stream, node->gid);
|
||||||
|
if (res != 4)
|
||||||
|
return 2;
|
||||||
|
res = load_u64(stream, node->mtime);
|
||||||
|
if (res != 8)
|
||||||
|
return 2;
|
||||||
|
res = load_u16(stream, mode);
|
||||||
|
if (res != 2)
|
||||||
|
return 2;
|
||||||
|
//todo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue