Skip to content

Commit c5c9bb7

Browse files
committed
set up vendors
1 parent 58db5e3 commit c5c9bb7

File tree

5 files changed

+307
-0
lines changed

5 files changed

+307
-0
lines changed

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
VERSION ?= 1.6.1
2+
3+
all: vendor/xar/lib/libxar.a
4+
go build -tags vendor
5+
6+
vendor/xar/lib/libxar.a: vendor/xar
7+
cd vendor/xar && ./configure
8+
${MAKE} -C vendor/xar
9+
10+
vendor/xar: vendor/cache.tar.gz
11+
tar xf vendor/cache.tar.gz -C vendor
12+
mv vendor/xar-${VERSION} vendor/xar
13+
14+
vendor/cache.tar.gz:
15+
mkdir -p vendor
16+
curl -LRo vendor/cache.tar.gz https://github.com/downloads/mackyle/xar/xar-${VERSION}.tar.gz
17+
18+
clean:
19+
rm -rf vendor/xar vendor/cache.tar.gz
20+
21+
.PHONY: clean

vendor/.gitkeep

Whitespace-only changes.

vendor/.touch

Whitespace-only changes.

xar.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package xar
2+
3+
// #cgo !vendor LDFLAGS: -lxar
4+
// #cgo vendor CFLAGS: -Ivendor/xar/include
5+
// #cgo vendor LDFLAGS: -Lvendor/xar/lib -lxar
6+
// #include <xar/xar.h>
7+
import "C"

xar.h

+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
/*
2+
* Copyright (c) 2005 Rob Braun
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the name of Rob Braun nor the names of his contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
/*
30+
* 03-Apr-2005
31+
* DRI: Rob Braun <[email protected]>
32+
*/
33+
/*
34+
* Portions Copyright 2006, Apple Computer, Inc.
35+
* Christopher Ryan <[email protected]>
36+
*/
37+
38+
#ifndef _XAR_H_
39+
#define _XAR_H_
40+
41+
#define XAR_VERSION "1.6.1"
42+
#define XAR_VERSION_NUM 0x01060180
43+
44+
#include <sys/types.h>
45+
#include <stdint.h>
46+
#include <sys/stat.h>
47+
48+
#ifdef __cplusplus
49+
extern "C" {
50+
#endif
51+
52+
#pragma pack(4)
53+
54+
struct xar_header {
55+
uint32_t magic;
56+
uint16_t size;
57+
uint16_t version;
58+
uint64_t toc_length_compressed;
59+
uint64_t toc_length_uncompressed;
60+
uint32_t cksum_alg;
61+
};
62+
63+
struct xar_header_ex { /* Only used when cksum_alg == XAR_CKSUM_OTHER */
64+
uint32_t magic;
65+
uint16_t size; /* Must be multiple of 4, but may be any multiple ok so long as Nul terminated toc_cksum_name value is included */
66+
uint16_t version;
67+
uint64_t toc_length_compressed;
68+
uint64_t toc_length_uncompressed;
69+
uint32_t cksum_alg;
70+
char toc_cksum_name[36]; /* Nul terminated and padded toc checksum style attribute value. */
71+
/* Must not be "none" or empty string "" if cksum_alg == XAR_CKSUM_OTHER */
72+
};
73+
74+
#pragma pack()
75+
76+
typedef struct xar_header xar_header_t;
77+
typedef struct xar_header_ex xar_header_ex_t;
78+
79+
#define XAR_HEADER_MAGIC 0x78617221
80+
#define XAR_EA_FORK "ea"
81+
82+
#define XAR_CKSUM_NONE 0
83+
#define XAR_CKSUM_SHA1 1
84+
#define XAR_CKSUM_MD5 2
85+
#define XAR_CKSUM_OTHER 3 /* Must not be used for "none", should not be used for "sha1" or "md5" */
86+
87+
typedef void *xar_errctx_t;
88+
typedef const struct __xar_file_t *xar_file_t;
89+
typedef const struct __xar_iter_t *xar_iter_t;
90+
typedef const struct __xar_t *xar_t;
91+
typedef const struct __xar_subdoc_t *xar_subdoc_t;
92+
typedef const struct __xar_signature_t *xar_signature_t;
93+
94+
typedef struct {
95+
char *next_out;
96+
unsigned int avail_out;
97+
98+
unsigned long long total_in;
99+
unsigned long long total_out;
100+
101+
void *state;
102+
} xar_stream;
103+
104+
typedef int32_t (*err_handler)(int32_t severit, int32_t instance, xar_errctx_t ctx, void *usrctx);
105+
/* the signed_data must be allocated durring the callback and will be released by the xar lib after the callback */
106+
typedef int32_t (*xar_signer_callback)(xar_signature_t sig, void *context, uint8_t *data, uint32_t length, uint8_t **signed_data, uint32_t *signed_len);
107+
108+
#define READ 0
109+
#define WRITE 1
110+
111+
/* xar stream return codes */
112+
#define XAR_STREAM_OK 0
113+
#define XAR_STREAM_END 1
114+
#define XAR_STREAM_ERR -1
115+
116+
/* Valid xar options & values */
117+
#define XAR_OPT_OWNERSHIP "ownership" /* setting owner/group behavior */
118+
#define XAR_OPT_VAL_SYMBOLIC "symbolic" /* set owner/group based on names */
119+
#define XAR_OPT_VAL_NUMERIC "numeric" /* set owner/group based on uid/gid */
120+
121+
#define XAR_OPT_TOCCKSUM "toc-cksum" /* set the toc checksum algorithm */
122+
#define XAR_OPT_FILECKSUM "file-chksum" /* set the file checksum algorithm */
123+
#define XAR_OPT_VAL_NONE "none"
124+
#define XAR_OPT_VAL_MD5 "md5"
125+
#define XAR_OPT_VAL_SHA1 "sha1"
126+
#define XAR_OPT_VAL_SHA224 "sha224"
127+
#define XAR_OPT_VAL_SHA256 "sha256"
128+
#define XAR_OPT_VAL_SHA384 "sha384"
129+
#define XAR_OPT_VAL_SHA512 "sha512"
130+
/* Actually any valid hash function name that returns non-NULL from EVP_get_digestbyname can be used as a value */
131+
132+
#define XAR_OPT_COMPRESSION "compression" /* set the file compression type */
133+
#define XAR_OPT_COMPRESSIONARG "compression-arg" /* set the compression opts */
134+
#define XAR_OPT_VAL_GZIP "gzip"
135+
#define XAR_OPT_VAL_BZIP "bzip2"
136+
#define XAR_OPT_VAL_LZMA "lzma"
137+
#define XAR_OPT_VAL_XZ "xz"
138+
139+
#define XAR_OPT_RSIZE "rsize" /* Read io buffer size */
140+
141+
#define XAR_OPT_COALESCE "coalesce" /* Coalesce identical heap blocks */
142+
#define XAR_OPT_LINKSAME "linksame" /* Hardlink identical files */
143+
144+
#define XAR_OPT_PROPINCLUDE "prop-include" /* File property to include */
145+
#define XAR_OPT_PROPEXCLUDE "prop-exclude" /* File property to exclude */
146+
147+
#define XAR_OPT_SAVESUID "savesuid" /* Preserve setuid/setgid bits */
148+
#define XAR_OPT_VAL_TRUE "true"
149+
#define XAR_OPT_VAL_FALSE "false"
150+
151+
#define XAR_OPT_RECOMPRESS "recompress" /* Allow recompression (true/false) */
152+
153+
#define XAR_OPT_EXTRACTSTDOUT "extract-stdout" /* Extract data to stdout instead of file (true/false) */
154+
155+
#define XAR_OPT_STRIPCOMPONENTS "strip-components" /* Number of components to strip on extraction (default 0) */
156+
157+
/* Use xar_open("",WRITE) to get an xar_t to use xar_opt_get on to fetch this then xar_close it if an xar_t is not otherwise available */
158+
/* Older versions will return NULL from xar_open("",WRITE), current versions will not but only xar_opt_get and xar_close should be called on the result */
159+
#define XAR_OPT_XARLIBVERSION "xar-library-version" /* Library's XAR_VERSION_NUM (as 0xVALUE string [%i scanf format, strtol base 0], get only) */
160+
161+
/* Note that this option is forced to true whenever XAR_CKSUM_OTHER is in effect */
162+
#define XAR_OPT_RFC6713FORMAT "rfc6713-format" /* Generate application/zlib instead of application/x-gzip encoding styles (true/false) */
163+
164+
/* xar signing algorithms */
165+
#define XAR_SIG_SHA1RSA 1
166+
167+
168+
/* xar error handler macros */
169+
#define XAR_SEVERITY_DEBUG 1
170+
#define XAR_SEVERITY_INFO 2
171+
#define XAR_SEVERITY_NORMAL 3
172+
#define XAR_SEVERITY_WARNING 4
173+
#define XAR_SEVERITY_NONFATAL 5
174+
#define XAR_SEVERITY_FATAL 6
175+
176+
#define XAR_ERR_ARCHIVE_CREATION 1
177+
#define XAR_ERR_ARCHIVE_EXTRACTION 2
178+
179+
xar_t xar_open(const char *file, int32_t flags);
180+
int xar_close(xar_t x);
181+
xar_file_t xar_add(xar_t x, const char *path);
182+
183+
xar_file_t xar_add_frombuffer(xar_t x, xar_file_t parent, const char *name, char *buffer, size_t length);
184+
xar_file_t xar_add_folder(xar_t x, xar_file_t f, const char *name, struct stat *info);
185+
xar_file_t xar_add_frompath(xar_t x, xar_file_t parent, const char *name, const char *realpath);
186+
187+
xar_file_t xar_add_from_archive(xar_t x, xar_file_t parent, const char *name, xar_t sourcearchive, xar_file_t sourcefile);
188+
189+
int32_t xar_extract(xar_t x, xar_file_t f);
190+
int32_t xar_extract_tofile(xar_t x, xar_file_t f, const char *path);
191+
int32_t xar_extract_tobuffer(xar_t x, xar_file_t f, char **buffer);
192+
int32_t xar_extract_tobuffersz(xar_t x, xar_file_t f, char **buffer, size_t *size);
193+
int32_t xar_extract_tostream_init(xar_t x, xar_file_t f, xar_stream *stream);
194+
int32_t xar_extract_tostream(xar_stream *stream);
195+
int32_t xar_extract_tostream_end(xar_stream *stream);
196+
197+
int32_t xar_verify(xar_t x, xar_file_t f);
198+
199+
200+
const char *xar_opt_get(xar_t x, const char *option);
201+
int32_t xar_opt_set(xar_t x, const char *option, const char *value);
202+
int32_t xar_opt_unset(xar_t x, const char *option);
203+
204+
int32_t xar_prop_set(xar_file_t f, const char *key, const char *value);
205+
int32_t xar_prop_create(xar_file_t f, const char *key, const char *value);
206+
int32_t xar_prop_get(xar_file_t f, const char *key, const char **value);
207+
208+
xar_iter_t xar_iter_new(void);
209+
void xar_iter_free(xar_iter_t i);
210+
211+
const char *xar_prop_first(xar_file_t f, xar_iter_t i);
212+
const char *xar_prop_next(xar_iter_t i);
213+
214+
void xar_prop_unset(xar_file_t f, const char *key);
215+
xar_file_t xar_file_first(xar_t x, xar_iter_t i);
216+
xar_file_t xar_file_next(xar_iter_t i);
217+
218+
const char *xar_attr_get(xar_file_t f, const char *prop, const char *key);
219+
int32_t xar_attr_set(xar_file_t f, const char *prop, const char *key, const char *value);
220+
const char *xar_attr_first(xar_file_t f, const char *prop, xar_iter_t i);
221+
const char *xar_attr_next(xar_iter_t i);
222+
223+
xar_subdoc_t xar_subdoc_new(xar_t x, const char *name);
224+
int32_t xar_subdoc_prop_set(xar_subdoc_t s, const char *key, const char *value);
225+
int32_t xar_subdoc_prop_get(xar_subdoc_t s, const char *key, const char **value);
226+
int32_t xar_subdoc_attr_set(xar_subdoc_t s, const char *prop, const char *key, const char *value);
227+
const char *xar_subdoc_attr_get(xar_subdoc_t s, const char *prop, const char *key);
228+
xar_subdoc_t xar_subdoc_first(xar_t x);
229+
xar_subdoc_t xar_subdoc_next(xar_subdoc_t s);
230+
const char *xar_subdoc_name(xar_subdoc_t s);
231+
int32_t xar_subdoc_copyout(xar_subdoc_t s, unsigned char **, unsigned int *);
232+
int32_t xar_subdoc_copyin(xar_subdoc_t s, const unsigned char *, unsigned int);
233+
void xar_subdoc_remove(xar_subdoc_t s);
234+
235+
/* signature api for adding various signature types */
236+
xar_signature_t xar_signature_new(xar_t x,const char *type, int32_t length, xar_signer_callback callback, void *callback_context);
237+
238+
const char *xar_signature_type(xar_signature_t s);
239+
240+
xar_signature_t xar_signature_first(xar_t x);
241+
xar_signature_t xar_signature_next(xar_signature_t s);
242+
243+
int32_t xar_signature_add_x509certificate(xar_signature_t sig, const uint8_t *cert_data, uint32_t cert_len );
244+
245+
int32_t xar_signature_get_x509certificate_count(xar_signature_t sig);
246+
int32_t xar_signature_get_x509certificate_data(xar_signature_t sig, int32_t index, const uint8_t **cert_data, uint32_t *cert_len);
247+
248+
int32_t xar_signature_copy_signed_data(xar_signature_t sig, uint8_t **data, uint32_t *length, uint8_t **signed_data, uint32_t *signed_length, uint64_t *signed_offset);
249+
250+
/* Helper functions - caller must free returned memory */
251+
char *xar_get_size(xar_t x, xar_file_t f);
252+
char *xar_get_type(xar_t x, xar_file_t f);
253+
char *xar_get_mode(xar_t x, xar_file_t f);
254+
char *xar_get_owner(xar_t x, xar_file_t f);
255+
char *xar_get_group(xar_t x, xar_file_t f);
256+
char *xar_get_mtime(xar_t x, xar_file_t f);
257+
258+
/* These are for xar modules and should never be needed from a calling app */
259+
void xar_register_errhandler(xar_t x, err_handler callback, void *usrctx);
260+
xar_t xar_err_get_archive(xar_errctx_t ctx);
261+
xar_file_t xar_err_get_file(xar_errctx_t ctx);
262+
const char *xar_err_get_string(xar_errctx_t ctx);
263+
int xar_err_get_errno(xar_errctx_t ctx);
264+
void xar_err_set_file(xar_t x, xar_file_t f);
265+
void xar_err_set_string(xar_t x, const char *str);
266+
void xar_err_set_errno(xar_t x, int e);
267+
void xar_err_new(xar_t x);
268+
int32_t xar_err_callback(xar_t x, int32_t sev, int32_t err);
269+
270+
void xar_serialize(xar_t x, const char *file);
271+
char *xar_get_path(xar_file_t f);
272+
uint64_t xar_get_heap_offset(xar_t x);
273+
uint64_t xar_ntoh64(uint64_t num);
274+
275+
#ifdef __cplusplus
276+
}
277+
#endif
278+
279+
#endif /* _XAR_H_ */

0 commit comments

Comments
 (0)