1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* table.h -- Code for handling the archive's table section.
Copyright (C) 2017 Jakob Kreuze, All Rights Reserved.
This file is part of Nekopack.
Nekopack is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Nekopack is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "io.h"
/* Structure representing one segment associated with a File entry. */
struct segment {
uint32_t compressed; /* Whether or not the segment is compressed. */
uint64_t offset; /* Offset to the segment's beginning. */
uint64_t compressed_size; /* Size of compressed segment. */
uint64_t decompressed_size; /* Size of decompressed segment. */
};
/* Structure representing an entry in the archive's table section. */
struct table_entry {
uint32_t key; /* File-specific key for encryption. */
uint64_t ctime; /* Timestamp of creation time. */
uint64_t segment_count; /* Number of segments. */
char *filename; /* String containing file's name. */
struct segment **segments; /* Array of associated segments. */
struct table_entry *next; /* Pointer to the next entry. */
};
/* Reads the contents of a File chunk. If there is an entry with a
matching key in the linked list specified by `root`, that structure
will be modified. Otherwise, a new entry will be created and appended
to the linked list. */
void read_file(struct stream *s, struct table_entry *root);
/* Reads the contents of an eliF chunk. If there is an entry with a
matching key in the linked list specified by `root`, that structure
will be modified. Otherwise, a new entry will be created and appended
to the linked list. */
void read_elif(struct stream *s, struct table_entry *root);
/* Returns the root of a linked list containing all of the files listed
in the archive's table section. */
struct table_entry *read_table(struct stream *s);
/* Dumps the XP3 table specified by `root` into `s`. */
void dump_table(struct stream *s, struct table_entry *root);
/* Inserts the file specified by `path` into the table linked list
specified by `root`. */
struct table_entry *add_file(struct table_entry *root, char *path);
/* Traverses `root` for a node with the given key. If the linked list
lacks a node with the key, a new node is created and appended. */
struct table_entry *get_node(struct table_entry *root, uint32_t key);
/* Inserts `e` to the end of the linked list specified by `root`. */
void entry_append(struct table_entry *root, struct table_entry *e);
/* Frees every entry in the linked list specified by `cur`. */
void entry_free(struct table_entry *cur);
|