LibreOffice Module onlineupdate (master) 1
mar.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim:set ts=2 sw=2 sts=2 et cindent: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#ifndef MAR_H__
8#define MAR_H__
9
10#include "mozilla/Assertions.h"
11#include <stdint.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/* We have a MAX_SIGNATURES limit so that an invalid MAR will never
18 * waste too much of either updater's or signmar's time.
19 * It is also used at various places internally and will affect memory usage.
20 * If you want to increase this value above 9 then you need to adjust parsing
21 * code in tool/mar.c.
22*/
23#define MAX_SIGNATURES 8
24#ifdef __cplusplus
25static_assert(MAX_SIGNATURES <= 9, "too many signatures");
26#else
27MOZ_STATIC_ASSERT(MAX_SIGNATURES <= 9, "too many signatures");
28#endif
29
31 const char *MARChannelID;
32 const char *productVersion;
33};
34
38typedef struct MarItem_ {
39 struct MarItem_ *next; /* private field */
40 uint32_t offset; /* offset into archive */
41 uint32_t length; /* length of data in bytes */
42 uint32_t flags; /* contains file mode bits */
43 char name[1]; /* file path */
45
46#define TABLESIZE 256
47
48struct MarFile_ {
51};
52
53typedef struct MarFile_ MarFile;
54
62typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data);
63
70MarFile *mar_open(const char *path);
71
72#ifdef _WIN32
73MarFile *mar_wopen(const wchar_t *path);
74#endif
75
80void mar_close(MarFile *mar);
81
88const MarItem *mar_find_item(MarFile *mar, const char *item);
89
99int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data);
100
111int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf,
112 int bufsize);
113
124int mar_create(const char *dest,
125 int numfiles,
126 char **files,
127 struct ProductInformationBlock *infoBlock);
128
135int mar_extract(const char *path);
136
137#define MAR_MAX_CERT_SIZE (16*1024) // Way larger than necessary
138
139/* Read the entire file (not a MAR file) into a newly-allocated buffer.
140 * This function does not write to stderr. Instead, the caller should
141 * write whatever error messages it sees fit. The caller must free the returned
142 * buffer using free().
143 *
144 * @param filePath The path to the file that should be read.
145 * @param maxSize The maximum valid file size.
146 * @param data On success, *data will point to a newly-allocated buffer
147 * with the file's contents in it.
148 * @param size On success, *size will be the size of the created buffer.
149 *
150 * @return 0 on success, -1 on error
151 */
152int mar_read_entire_file(const char * filePath,
153 uint32_t maxSize,
154 /*out*/ const uint8_t * *data,
155 /*out*/ uint32_t *size);
156
178 const uint8_t * const *certData,
179 const uint32_t *certDataSizes,
180 uint32_t certCount);
181
190int
192 struct ProductInformationBlock *infoBlock);
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif /* MAR_H__ */
#define TABLESIZE
Definition: mar.h:46
struct MarItem_ MarItem
The MAR item data structure.
int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf, int bufsize)
Read from MAR item at given offset up to bufsize bytes.
Definition: mar_read.c:514
void mar_close(MarFile *mar)
Close a MAR file that was opened using mar_open.
Definition: mar_read.c:195
MarFile * mar_open(const char *path)
Open a MAR file for reading.
Definition: mar_read.c:167
int mar_read_entire_file(const char *filePath, uint32_t maxSize, const uint8_t **data, uint32_t *size)
Definition: mar_verify.c:22
#define MAX_SIGNATURES
Definition: mar.h:23
int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data)
Enumerate all MAR items via callback function.
Definition: mar_read.c:497
int(* MarItemCallback)(MarFile *mar, const MarItem *item, void *data)
Signature of callback function passed to mar_enum_items.
Definition: mar.h:62
int mar_extract(const char *path)
Extract a MAR file to the current working directory.
Definition: mar_extract.c:73
MOZ_STATIC_ASSERT(MAX_SIGNATURES<=9, "too many signatures")
int mar_verify_signatures(MarFile *mar, const uint8_t *const *certData, const uint32_t *certDataSizes, uint32_t certCount)
Verifies a MAR file by verifying each signature with the corresponding certificate.
Definition: mar_verify.c:136
int mar_read_product_info_block(MarFile *mar, struct ProductInformationBlock *infoBlock)
Reads the product info block from the MAR file's additional block section.
Definition: mar_read.c:394
int mar_create(const char *dest, int numfiles, char **files, struct ProductInformationBlock *infoBlock)
Create a MAR file from a set of files.
Definition: mar_create.c:293
const MarItem * mar_find_item(MarFile *mar, const char *item)
Find an item in the MAR file by name.
Definition: mar_read.c:484
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
Definition: mar.h:48
FILE * fp
Definition: mar.h:49
MarItem * item_table[TABLESIZE]
Definition: mar.h:50
The MAR item data structure.
Definition: mar.h:38
uint32_t flags
Definition: mar.h:42
char name[1]
Definition: mar.h:43
uint32_t length
Definition: mar.h:41
uint32_t offset
Definition: mar.h:40
struct MarItem_ * next
Definition: mar.h:39
const char * productVersion
Definition: mar.h:32
const char * MARChannelID
Definition: mar.h:31