File: jte.h

package info (click to toggle)
jigit 1.22-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,360 kB
  • sloc: ansic: 7,227; sh: 4,433; perl: 611; makefile: 157; lisp: 4
file content (209 lines) | stat: -rw-r--r-- 5,294 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * jte.c
 *
 * Copyright (c) 2004-2006 Steve McIntyre <steve@einval.com>
 * Copyright (c) 2010 Thomas Schmitt <scdbackup@gmx.net>
 * Copyright (c) 2010 George Danchev <danchev@spnet.net>
 *
 * Prototypes and declarations for JTE
 *
 * GNU GPL v2
 */

#ifndef _JTE_JTE_H_
#define _JTE_JTE_H_

/* The API environment handle which replaces the old global variables */
struct libjte_env;

#include <stdio.h>
#include <unistd.h>
#include <regex.h>
#include "checksum.h"

typedef int BOOL;


extern int write_jt_header(struct libjte_env *o,
                            FILE *template_file, FILE *jigdo_file);
extern int write_jt_footer(struct libjte_env *o);
extern int jtwrite(struct libjte_env *o,
                            void *buffer, int size, int count);
extern int write_jt_match_record(struct libjte_env *o,
                            char *filename, char *mirror_name, int sector_size,
                            off_t size, unsigned char *checksum);
extern int  list_file_in_jigdo(struct libjte_env *o,
                            char *filename, off_t size, char **realname,
                            unsigned char *checksum);
extern int  jte_add_exclude(struct libjte_env *o, char *pattern);
extern int  jte_add_include(struct libjte_env *o, char *pattern);
extern int  jte_add_mapping(struct libjte_env *o, char *arg);

int libjte_destroy_path_match_list(struct libjte_env *o, int flag);
int libjte_destroy_path_mapping(struct libjte_env *o, int flag);
int libjte_destroy_entry_list(struct libjte_env *o, int flag);
int libjte_destroy_checksum_list(struct libjte_env *o, int flag);

int libjte_report_no_mem(struct libjte_env *o, size_t size, int flag);


typedef enum _jtc_e
{
    JTE_TEMP_GZIP = 0,
    JTE_TEMP_BZIP2
} jtc_t;

struct _checksum_data
{
    enum checksum_types type;
    char *name;      /* the name of the checksum algorithm */
    int   raw_bytes; /* how many bytes needed to store the raw
		      * checksum */
    int   hex_bytes; /* how many chars needed to store it as a hex
		      * string, *not including* the NULL terminator */
    int   b64_bytes; /* how many chars needed to store it as a base64
		      * string, *not including* the NULL terminator */
};

#define ROUND_UP(N, S)      ((((N) + (S) - 1) / (S)) * (S))

#define MD5_BITS            128
#define MD5_BYTES           (MD5_BITS / 8)
#define HEX_MD5_BYTES       (MD5_BITS / 4)
#define BASE64_MD5_BYTES    ((ROUND_UP (MD5_BITS, 6)) / 6)

#define SHA256_BITS         256
#define SHA256_BYTES        (SHA256_BITS / 8)
#define HEX_SHA256_BYTES    (SHA256_BITS / 4)
#define BASE64_SHA256_BYTES ((ROUND_UP (SHA256_BITS, 6)) / 6)

static const struct _checksum_data check_algos[] = 
{
    {
		CHECK_MD5,
		"md5",
		MD5_BYTES,
		HEX_MD5_BYTES,
		BASE64_MD5_BYTES
	},
    {
		CHECK_SHA256,
		"sha256",
		SHA256_BYTES,
		HEX_SHA256_BYTES,
		BASE64_SHA256_BYTES
	},
    {
		NUM_CHECKSUMS,
		NULL,
		0,
		0,
		0
	}
};

#define MIN_JIGDO_FILE_SIZE 1024

/*	
	Simple list to hold the results of -jigdo-exclude and
	-jigdo-force-match command line options. Seems easiest to do this
	using regexps.
*/
struct path_match
{
    regex_t  match_pattern;
    char    *match_rule;
    struct path_match *next;
};

/* List of mappings e.g. Debian=/mirror/debian */
struct path_mapping
{
    char                *from;
    char                *to;
    struct path_mapping *next;
};

/* List of files that we've seen, ready to write into the template and
   jigdo files */
typedef struct _file_entry
{
    unsigned char      *checksum;
    off_t               file_length;
    uint64_t            rsyncsum;
    char               *filename;
} file_entry_t;

typedef struct _unmatched_entry
{
    off_t uncompressed_length;
} unmatched_entry_t;    

typedef struct _entry
{
    int entry_type; /* JTET_TYPE as above */
    struct _entry *next;
    union
    {
        file_entry_t      file;
        unmatched_entry_t chunk;
    } data;
} entry_t;

typedef struct _jigdo_file_entry_md5
{
    unsigned char type;
    unsigned char fileLen[6];
    unsigned char fileRsync[8];
    unsigned char fileMD5[MD5_BYTES];
} jigdo_file_entry_md5_t;

typedef struct _jigdo_file_entry_sha256
{
    unsigned char type;
    unsigned char fileLen[6];
    unsigned char fileRsync[8];
    unsigned char fileSHA256[SHA256_BYTES];
} jigdo_file_entry_sha256_t;

typedef struct _jigdo_chunk_entry
{
    unsigned char type;
    unsigned char skipLen[6];
} jigdo_chunk_entry_t;

typedef struct _jigdo_image_entry_md5
{
    unsigned char type;
    unsigned char imageLen[6];
    unsigned char imageMD5[MD5_BYTES];
    unsigned char blockLen[4];
} jigdo_image_entry_md5_t;

typedef struct _jigdo_image_entry_sha256
{
    unsigned char type;
    unsigned char imageLen[6];
    unsigned char imageSHA256[SHA256_BYTES];
    unsigned char blockLen[4];
} jigdo_image_entry_sha256_t;

typedef struct _checksum_list_entry
{
    struct _checksum_list_entry *next;
    unsigned char      *checksum;
    uint64_t            size;
    char               *filename;
} checksum_list_entry_t;


typedef struct _jigdo_msg_entry
{
    struct _jigdo_msg_entry *next;
    char *message;
} jigdo_msg_entry_t;
int libjte_add_msg_entry(struct libjte_env *o, char *message, int flag);
/* Destructor is API call  libjte_clear_msg_list() */

#endif
/*_JTE_JTE_H_*/