LibreOffice Module onlineupdate (master) 1
Functions
mar_read.c File Reference
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar.h>
#include <netinet/in.h>
Include dependency graph for mar_read.c:

Go to the source code of this file.

Functions

static uint32_t mar_hash_name (const char *name)
 
static int mar_insert_item (MarFile *mar, const char *name, int namelen, uint32_t offset, uint32_t length, uint32_t flags)
 
static int mar_consume_index (MarFile *mar, char **buf, const char *buf_end)
 
static int mar_read_index (MarFile *mar)
 
static MarFilemar_fpopen (FILE *fp)
 Internal shared code for mar_open and mar_wopen. More...
 
MarFilemar_open (const char *path)
 Open a MAR file for reading. More...
 
void mar_close (MarFile *mar)
 Close a MAR file that was opened using mar_open. More...
 
int get_mar_file_info_fp (FILE *fp, int *hasSignatureBlock, uint32_t *numSignatures, int *hasAdditionalBlocks, uint32_t *offsetAdditionalBlocks, uint32_t *numAdditionalBlocks)
 Determines the MAR file information. More...
 
int read_product_info_block (char *path, struct ProductInformationBlock *infoBlock)
 Reads the product info block from the MAR file's additional block section. More...
 
int mar_read_product_info_block (MarFile *mar, struct ProductInformationBlock *infoBlock)
 Reads the product info block from the MAR file's additional block section. More...
 
const MarItemmar_find_item (MarFile *mar, const char *name)
 Find an item in the MAR file by name. More...
 
int mar_enum_items (MarFile *mar, MarItemCallback callback, void *closure)
 Enumerate all MAR items via callback function. More...
 
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. More...
 
int get_mar_file_info (const char *path, int *hasSignatureBlock, uint32_t *numSignatures, int *hasAdditionalBlocks, uint32_t *offsetAdditionalBlocks, uint32_t *numAdditionalBlocks)
 Determines the MAR file information. More...
 

Function Documentation

◆ get_mar_file_info()

int get_mar_file_info ( const char *  path,
int hasSignatureBlock,
uint32_t *  numSignatures,
int hasAdditionalBlocks,
uint32_t *  offsetAdditionalBlocks,
uint32_t *  numAdditionalBlocks 
)

Determines the MAR file information.

Determines MAR file information.

Parameters
pathThe path of the MAR file to check.
hasSignatureBlockOptional out parameter specifying if the MAR file has a signature block or not.
numSignaturesOptional out parameter for storing the number of signatures in the MAR file.
hasAdditionalBlocksOptional out parameter specifying if the MAR file has additional blocks or not.
offsetAdditionalBlocksOptional out parameter for the offset to the first additional block. Value is only valid if hasAdditionalBlocks is not equal to 0.
numAdditionalBlocksOptional out parameter for the number of additional blocks. Value is only valid if has_additional_blocks is not equal to 0.
Returns
0 on success and non-zero on failure.

Definition at line 551 of file mar_read.c.

References FILE, and get_mar_file_info_fp().

Referenced by main(), mar_repackage_and_sign(), refresh_product_info_block(), and strip_signature_block().

◆ get_mar_file_info_fp()

int get_mar_file_info_fp ( FILE *  fp,
int hasSignatureBlock,
uint32_t *  numSignatures,
int hasAdditionalBlocks,
uint32_t *  offsetAdditionalBlocks,
uint32_t *  numAdditionalBlocks 
)

Determines the MAR file information.

Parameters
fpAn opened MAR file in read mode.
hasSignatureBlockOptional out parameter specifying if the MAR file has a signature block or not.
numSignaturesOptional out parameter for storing the number of signatures in the MAR file.
hasAdditionalBlocksOptional out parameter specifying if the MAR file has additional blocks or not.
offsetAdditionalBlocksOptional out parameter for the offset to the first additional block. Value is only valid if hasAdditionalBlocks is not equal to 0.
numAdditionalBlocksOptional out parameter for the number of additional blocks. Value is only valid if hasAdditionalBlocks is not equal to 0.
Returns
0 on success and non-zero on failure.

Definition at line 231 of file mar_read.c.

References i, MAR_ID_SIZE, MAX_SIGNATURES, ntohl(), and SIGNATURE_BLOCK_OFFSET.

Referenced by get_mar_file_info(), and mar_read_product_info_block().

◆ mar_close()

void mar_close ( MarFile mar)

Close a MAR file that was opened using mar_open.

Parameters
marThe MarFile object to close.

Definition at line 195 of file mar_read.c.

References MarFile_::fp, i, MarFile_::item_table, MarItem_::next, and TABLESIZE.

Referenced by ArchiveReader::Close(), main(), mar_extract(), mar_fpopen(), and mar_test().

◆ mar_consume_index()

static int mar_consume_index ( MarFile mar,
char **  buf,
const char *  buf_end 
)
static

Definition at line 60 of file mar_read.c.

References length, mar_insert_item(), name, and ntohl().

Referenced by mar_read_index().

◆ mar_enum_items()

int mar_enum_items ( MarFile mar,
MarItemCallback  callback,
void *  data 
)

Enumerate all MAR items via callback function.

Parameters
marThe MAR file to enumerate.
callbackThe function to call for each MAR item.
dataA caller specified value that is passed along to the callback function.
Returns
0 if the enumeration ran to completion. Otherwise, any non-zero return value from the callback is returned.

Definition at line 497 of file mar_read.c.

References i, MarFile_::item_table, MarItem_::next, and TABLESIZE.

Referenced by mar_extract(), and mar_test().

◆ mar_find_item()

const MarItem * mar_find_item ( MarFile mar,
const char *  item 
)

Find an item in the MAR file by name.

Parameters
marThe MarFile object to query.
itemThe name of the item to query.
Returns
A const reference to a MAR item or NULL if not found.

Definition at line 484 of file mar_read.c.

References MarFile_::item_table, mar_hash_name(), name, MarItem_::name, and MarItem_::next.

Referenced by ArchiveReader::ExtractFile(), and ArchiveReader::ExtractFileToStream().

◆ mar_fpopen()

static MarFile * mar_fpopen ( FILE *  fp)
static

Internal shared code for mar_open and mar_wopen.

On failure, will fclose(fp).

Definition at line 147 of file mar_read.c.

References MarFile_::fp, MarFile_::item_table, mar_close(), mar_read_index(), and NULL.

Referenced by mar_open().

◆ mar_hash_name()

static uint32_t mar_hash_name ( const char *  name)
static

Definition at line 22 of file mar_read.c.

References name, and TABLESIZE.

Referenced by mar_find_item(), and mar_insert_item().

◆ mar_insert_item()

static int mar_insert_item ( MarFile mar,
const char *  name,
int  namelen,
uint32_t  offset,
uint32_t  length,
uint32_t  flags 
)
static

◆ mar_open()

MarFile * mar_open ( const char *  path)

Open a MAR file for reading.

Parameters
pathSpecifies the path to the MAR file to open. This path must be compatible with fopen.
Returns
NULL if an error occurs.

Definition at line 167 of file mar_read.c.

References FILE, mar_fpopen(), and NULL.

Referenced by main(), mar_extract(), mar_test(), and ArchiveReader::Open().

◆ mar_read()

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.

Parameters
marThe MAR file to read.
itemThe MAR item to read.
offsetThe byte offset relative to the start of the item.
bufA pointer to a buffer to copy the data into.
bufsizeThe length of the buffer to copy the data into.
Returns
The number of bytes written or a negative value if an error occurs.

Definition at line 514 of file mar_read.c.

References MarFile_::fp, MarItem_::length, and MarItem_::offset.

Referenced by ArchiveReader::ExtractItemToStream(), and mar_test_callback().

◆ mar_read_index()

static int mar_read_index ( MarFile mar)
static

Definition at line 107 of file mar_read.c.

References MarFile_::fp, mar_consume_index(), MAR_ID, MAR_ID_SIZE, and ntohl().

Referenced by mar_fpopen().

◆ mar_read_product_info_block()

int mar_read_product_info_block ( MarFile mar,
struct ProductInformationBlock infoBlock 
)

Reads the product info block from the MAR file's additional block section.

The caller is responsible for freeing the fields in infoBlock if the return is successful.

Parameters
infoBlockOut parameter for where to store the result to
Returns
0 on success, -1 on failure

Definition at line 394 of file mar_read.c.

References MarFile_::fp, get_mar_file_info_fp(), i, ProductInformationBlock::MARChannelID, ntohl(), NULL, PRODUCT_INFO_BLOCK_ID, and ProductInformationBlock::productVersion.

Referenced by read_product_info_block(), and ArchiveReader::VerifyProductInformation().

◆ read_product_info_block()

int read_product_info_block ( char *  path,
struct ProductInformationBlock infoBlock 
)

Reads the product info block from the MAR file's additional block section.

The caller is responsible for freeing the fields in infoBlock if the return is successful.

Parameters
infoBlockOut parameter for where to store the result to
Returns
0 on success, -1 on failure

Definition at line 369 of file mar_read.c.

References MarFile_::fp, and mar_read_product_info_block().

Referenced by main().