naev 0.12.5
physfs_archiver_blacklist.c File Reference

Archiver that allows us to blacklist certain files by creating empty versions of them. More...

#include "naev.h"
#include "physfs.h"
#include <pcre2.h>
#include "array.h"
#include "log.h"
Include dependency graph for physfs_archiver_blacklist.c:

Go to the source code of this file.

Data Structures

struct  BlkFile
 Represents a file in a directory. Used to enumerate files. More...

Macros

#define PCRE2_CODE_UNIT_WIDTH   8
#define BLACKLIST_FILENAME   "naev.BLACKLIST"

Functions

static PHYSFS_Io * blk_unsupportedIO (void *opaque, const char *filename)
static int blk_unsupported (void *opaque, const char *name)
static void * blk_openArchive (PHYSFS_Io *io, const char *name, int forWrite, int *claimed)
static PHYSFS_EnumerateCallbackResult blk_enumerate (void *opaque, const char *dirname, PHYSFS_EnumerateCallback cb, const char *origdir, void *callbackdata)
static PHYSFS_Io * blk_openRead (void *opaque, const char *fnm)
static int blk_stat (void *opaque, const char *fn, PHYSFS_Stat *stat)
static void blk_closeArchive (void *opaque)
static PHYSFS_sint64 blk_read (struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
static PHYSFS_sint64 blk_write (struct PHYSFS_Io *io, const void *buffer, PHYSFS_uint64 len)
static int blk_seek (struct PHYSFS_Io *io, PHYSFS_uint64 offset)
static PHYSFS_sint64 blk_tell (struct PHYSFS_Io *io)
static PHYSFS_sint64 blk_length (struct PHYSFS_Io *io)
static struct PHYSFS_Io * blk_duplicate (struct PHYSFS_Io *io)
static int blk_flush (struct PHYSFS_Io *io)
static void blk_destroy (struct PHYSFS_Io *io)
static int blk_enumerateCallback (void *data, const char *origdir, const char *fname)
 Used to build the blacklist and pseudo filesystem when iterating over real files.
static pcre2_code * regex_make (char *const *lst)
int blacklist_init (void)
 Initializes the blacklist system if necessary. If no plugin is blacklisting, it will not do anything.
int blacklist_append (const char *path)
 Appends a regex string to be blacklisted.
int whitelist_append (const char *path)
 Appends a regex string to be whitelisted.
void blacklist_exit (void)
 Exits the blacklist system and cleans up as necessary.
static int blk_matches (char **lst, const char *filename)
 Tries to match a string in an array of strings that are sorted.

Variables

static pcre2_code * blk_re = NULL
static pcre2_match_data * blk_match
static char ** blk_blacklists_re = NULL
static pcre2_code * wht_re = NULL
static pcre2_match_data * wht_match
static char ** wht_blacklists_re = NULL
static char ** blk_blacklists
static char ** blk_dirnames = NULL
static BlkFileblk_fs
static const PHYSFS_Archiver blk_archiver
 The archiver for blacklists.
static const PHYSFS_Io blk_emptyio
 Mimicks an empty file.
static const PHYSFS_Stat blk_emptystat
 Stat for an empty regular file.
static const PHYSFS_Stat blk_emptystatdir
 Stat for a fake directory.

Detailed Description

Archiver that allows us to blacklist certain files by creating empty versions of them.

Definition in file physfs_archiver_blacklist.c.

Macro Definition Documentation

◆ BLACKLIST_FILENAME

#define BLACKLIST_FILENAME   "naev.BLACKLIST"

Definition at line 19 of file physfs_archiver_blacklist.c.

◆ PCRE2_CODE_UNIT_WIDTH

#define PCRE2_CODE_UNIT_WIDTH   8

Definition at line 12 of file physfs_archiver_blacklist.c.

Function Documentation

◆ blacklist_append()

int blacklist_append ( const char * path)

Appends a regex string to be blacklisted.

Definition at line 319 of file physfs_archiver_blacklist.c.

◆ blacklist_exit()

void blacklist_exit ( void )

Exits the blacklist system and cleans up as necessary.

Definition at line 349 of file physfs_archiver_blacklist.c.

◆ blacklist_init()

int blacklist_init ( void )

Initializes the blacklist system if necessary. If no plugin is blacklisting, it will not do anything.

Returns
0 on success.

Definition at line 266 of file physfs_archiver_blacklist.c.

◆ blk_closeArchive()

void blk_closeArchive ( void * opaque)
static

Definition at line 462 of file physfs_archiver_blacklist.c.

◆ blk_destroy()

void blk_destroy ( struct PHYSFS_Io * io)
static

Definition at line 515 of file physfs_archiver_blacklist.c.

◆ blk_duplicate()

struct PHYSFS_Io * blk_duplicate ( struct PHYSFS_Io * io)
static

Definition at line 504 of file physfs_archiver_blacklist.c.

◆ blk_enumerate()

PHYSFS_EnumerateCallbackResult blk_enumerate ( void * opaque,
const char * dirname,
PHYSFS_EnumerateCallback cb,
const char * origdir,
void * callbackdata )
static

Definition at line 416 of file physfs_archiver_blacklist.c.

◆ blk_enumerateCallback()

int blk_enumerateCallback ( void * data,
const char * origdir,
const char * fname )
static

Used to build the blacklist and pseudo filesystem when iterating over real files.

Definition at line 137 of file physfs_archiver_blacklist.c.

◆ blk_flush()

int blk_flush ( struct PHYSFS_Io * io)
static

Definition at line 509 of file physfs_archiver_blacklist.c.

◆ blk_length()

PHYSFS_sint64 blk_length ( struct PHYSFS_Io * io)
static

Definition at line 498 of file physfs_archiver_blacklist.c.

◆ blk_matches()

int blk_matches ( char ** lst,
const char * filename )
static

Tries to match a string in an array of strings that are sorted.

Definition at line 382 of file physfs_archiver_blacklist.c.

◆ blk_openArchive()

void * blk_openArchive ( PHYSFS_Io * io,
const char * name,
int forWrite,
int * claimed )
static

Definition at line 403 of file physfs_archiver_blacklist.c.

◆ blk_openRead()

PHYSFS_Io * blk_openRead ( void * opaque,
const char * fnm )
static

Definition at line 437 of file physfs_archiver_blacklist.c.

◆ blk_read()

PHYSFS_sint64 blk_read ( struct PHYSFS_Io * io,
void * buf,
PHYSFS_uint64 len )
static

Definition at line 467 of file physfs_archiver_blacklist.c.

◆ blk_seek()

int blk_seek ( struct PHYSFS_Io * io,
PHYSFS_uint64 offset )
static

Definition at line 485 of file physfs_archiver_blacklist.c.

◆ blk_stat()

int blk_stat ( void * opaque,
const char * fn,
PHYSFS_Stat * stat )
static

Definition at line 448 of file physfs_archiver_blacklist.c.

◆ blk_tell()

PHYSFS_sint64 blk_tell ( struct PHYSFS_Io * io)
static

Definition at line 492 of file physfs_archiver_blacklist.c.

◆ blk_unsupported()

int blk_unsupported ( void * opaque,
const char * name )
static

Definition at line 396 of file physfs_archiver_blacklist.c.

◆ blk_unsupportedIO()

PHYSFS_Io * blk_unsupportedIO ( void * opaque,
const char * filename )
static

Definition at line 389 of file physfs_archiver_blacklist.c.

◆ blk_write()

PHYSFS_sint64 blk_write ( struct PHYSFS_Io * io,
const void * buffer,
PHYSFS_uint64 len )
static

Definition at line 476 of file physfs_archiver_blacklist.c.

◆ regex_make()

pcre2_code * regex_make ( char *const * lst)
static

Definition at line 231 of file physfs_archiver_blacklist.c.

◆ whitelist_append()

int whitelist_append ( const char * path)

Appends a regex string to be whitelisted.

Definition at line 334 of file physfs_archiver_blacklist.c.

Variable Documentation

◆ blk_archiver

const PHYSFS_Archiver blk_archiver
static
Initial value:
= {
.version = 0,
.info =
{
.extension = "BLACKLIST",
.description = "Naev blacklist archiver.",
.author = "Naev DevTeam",
.url = "https://naev.org",
.supportsSymlinks = 0,
},
.openArchive = blk_openArchive,
.enumerate = blk_enumerate,
.openRead = blk_openRead,
.openWrite = blk_unsupportedIO,
.openAppend = blk_unsupportedIO,
.remove = blk_unsupported,
.mkdir = blk_unsupported,
.stat = blk_stat,
.closeArchive = blk_closeArchive,
}

The archiver for blacklists.

Definition at line 61 of file physfs_archiver_blacklist.c.

◆ blk_blacklists

char** blk_blacklists
static
Initial value:
=
NULL

List of blacklisted files (for direct access).

Definition at line 37 of file physfs_archiver_blacklist.c.

◆ blk_blacklists_re

char** blk_blacklists_re = NULL
static

Original regex strings.

Definition at line 32 of file physfs_archiver_blacklist.c.

◆ blk_dirnames

char** blk_dirnames = NULL
static

List of blacklisted directories (for direct access, necessary to enumerate).

Definition at line 39 of file physfs_archiver_blacklist.c.

◆ blk_emptyio

const PHYSFS_Io blk_emptyio
static
Initial value:
= {
.version = 0,
.opaque = NULL,
.read = blk_read,
.write = blk_write,
.seek = blk_seek,
.tell = blk_tell,
.length = blk_length,
.duplicate = blk_duplicate,
.flush = blk_flush,
.destroy = blk_destroy,
}

Mimicks an empty file.

Definition at line 96 of file physfs_archiver_blacklist.c.

◆ blk_emptystat

const PHYSFS_Stat blk_emptystat
static
Initial value:
= {
.filesize = 0,
.modtime = 0,
.createtime = 0,
.accesstime = 0,
.filetype = PHYSFS_FILETYPE_REGULAR,
.readonly = 1,
}

Stat for an empty regular file.

Definition at line 112 of file physfs_archiver_blacklist.c.

◆ blk_emptystatdir

const PHYSFS_Stat blk_emptystatdir
static
Initial value:
= {
.filesize = 0,
.modtime = 0,
.createtime = 0,
.accesstime = 0,
.filetype = PHYSFS_FILETYPE_DIRECTORY,
.readonly = 1,
}

Stat for a fake directory.

Definition at line 124 of file physfs_archiver_blacklist.c.

◆ blk_fs

BlkFile* blk_fs
static
Initial value:
=
NULL

Fake filesystem structure of directory-file pairs.

Definition at line 41 of file physfs_archiver_blacklist.c.

◆ blk_match

pcre2_match_data* blk_match
static
Initial value:
=
NULL

Stores the matching structure of the regex (for speed).

Definition at line 30 of file physfs_archiver_blacklist.c.

◆ blk_re

pcre2_code* blk_re = NULL
static

Stores the compiled regex.

Definition at line 29 of file physfs_archiver_blacklist.c.

◆ wht_blacklists_re

char** wht_blacklists_re = NULL
static

Original regex strings.

Definition at line 36 of file physfs_archiver_blacklist.c.

◆ wht_match

pcre2_match_data* wht_match
static
Initial value:
=
NULL

Stores the matching structure of the regex (for speed).

Definition at line 34 of file physfs_archiver_blacklist.c.

◆ wht_re

pcre2_code* wht_re = NULL
static

Stores the compiled regex.

Definition at line 33 of file physfs_archiver_blacklist.c.