naev 0.11.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 <pcre2.h>
#include "physfs.h"
#include "array.h"
#include "log.h"

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.
 
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.
 
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 = NULL
 
static char ** blk_blacklists_re = NULL
 
static char ** blk_blacklists = NULL
 
static char ** blk_dirnames = NULL
 
static BlkFileblk_fs = NULL
 
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 255 of file physfs_archiver_blacklist.c.

◆ blacklist_exit()

void blacklist_exit ( void )

Exits the blacklist system and cleans up as necessary.

Definition at line 270 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 201 of file physfs_archiver_blacklist.c.

◆ blk_closeArchive()

static void blk_closeArchive ( void * opaque)
static

Definition at line 374 of file physfs_archiver_blacklist.c.

◆ blk_destroy()

static void blk_destroy ( struct PHYSFS_Io * io)
static

Definition at line 425 of file physfs_archiver_blacklist.c.

◆ blk_duplicate()

static struct PHYSFS_Io * blk_duplicate ( struct PHYSFS_Io * io)
static

Definition at line 414 of file physfs_archiver_blacklist.c.

◆ blk_enumerate()

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

Definition at line 329 of file physfs_archiver_blacklist.c.

◆ blk_enumerateCallback()

static 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 122 of file physfs_archiver_blacklist.c.

◆ blk_flush()

static int blk_flush ( struct PHYSFS_Io * io)
static

Definition at line 419 of file physfs_archiver_blacklist.c.

◆ blk_length()

static PHYSFS_sint64 blk_length ( struct PHYSFS_Io * io)
static

Definition at line 408 of file physfs_archiver_blacklist.c.

◆ blk_matches()

static 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 298 of file physfs_archiver_blacklist.c.

◆ blk_openArchive()

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

Definition at line 318 of file physfs_archiver_blacklist.c.

◆ blk_openRead()

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

Definition at line 349 of file physfs_archiver_blacklist.c.

◆ blk_read()

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

Definition at line 379 of file physfs_archiver_blacklist.c.

◆ blk_seek()

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

Definition at line 395 of file physfs_archiver_blacklist.c.

◆ blk_stat()

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

Definition at line 360 of file physfs_archiver_blacklist.c.

◆ blk_tell()

static PHYSFS_sint64 blk_tell ( struct PHYSFS_Io * io)
static

Definition at line 402 of file physfs_archiver_blacklist.c.

◆ blk_unsupported()

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

Definition at line 311 of file physfs_archiver_blacklist.c.

◆ blk_unsupportedIO()

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

Definition at line 304 of file physfs_archiver_blacklist.c.

◆ blk_write()

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

Definition at line 387 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 50 of file physfs_archiver_blacklist.c.

◆ blk_blacklists

char** blk_blacklists = NULL
static

List of blacklisted files (for direct access).

Definition at line 32 of file physfs_archiver_blacklist.c.

◆ blk_blacklists_re

char** blk_blacklists_re = NULL
static

Original regex strings.

Definition at line 31 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 33 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 82 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 98 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 110 of file physfs_archiver_blacklist.c.

◆ blk_fs

BlkFile* blk_fs = NULL
static

Fake filesystem structure of directory-file pairs.

Definition at line 34 of file physfs_archiver_blacklist.c.

◆ blk_match

pcre2_match_data* blk_match = NULL
static

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.