17#define PCRE2_CODE_UNIT_WIDTH 8
24#include "physfs_archiver_blacklist.h"
33 xmlNodePtr node, parent;
38 parent = doc->xmlChildrenNode;
41 nfile_concatPaths( buf,
sizeof(buf), plg->
mountpoint, file );
42 ERR( _(
"Malformed '%s' file: does not contain elements"), buf);
46 xmlr_attr_strd( parent,
"name", plg->
name );
47 if (plg->
name == NULL)
48 WARN(_(
"Plugin '%s' has no name!"), path);
50 node = parent->xmlChildrenNode;
54 xmlr_strd( node,
"author", plg->
author );
55 xmlr_strd( node,
"version", plg->
version );
58 xmlr_int( node,
"priority", plg->
priority );
59 if (xml_isNode( node,
"blacklist" )) {
63 if (xml_isNode( node,
"total_conversion" )) {
67 "^spob_virtual/.*\\.xml",
69 "^commodities/.*\\.xml",
75 "^asteroids/.*\\.xml",
77 "^map_decorator/.*\\.xml",
81 for (
int i=0; blk[i]!=NULL; i++)
86 WARN(_(
"Plugin '%s' has unknown metadata node '%s'!"),path,xml_get(node));
87 }
while (xml_nextNode(node));
122 PHYSFS_stat(
"plugins", &stat );
123 if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) {
125 char **files = PHYSFS_enumerateFiles(
"plugins" );
126 for (
char **f = files; *f != NULL; f++) {
129 nfile_concatPaths( buf,
PATH_MAX, PHYSFS_getWriteDir(),
"plugins", *f );
133 if (PHYSFS_mount( buf, NULL, 0 )==0) {
134 WARN(_(
"Failed to mount plugin '%s': %s"), buf,
135 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode()) ));
144 PHYSFS_stat(
"plugin.xml", &stat );
145 realdir = PHYSFS_getRealDir(
"plugin.xml" );
146 if ((stat.filetype == PHYSFS_FILETYPE_REGULAR) &&
147 realdir && strcmp(realdir,buf)==0)
150 WARN(_(
"Plugin '%s' does not have a valid '%s'!"), buf,
"plugin.xml");
154 plg->
author = strdup(_(
"Unknown"));
156 plg->
version = strdup(_(
"Unknown"));
160 PHYSFS_freeList(files);
164 for (
int i=0; i<n; i++)
165 PHYSFS_unmount( plugins[i].mountpoint );
174 for (
int i=n-1; i>=0; i--)
175 PHYSFS_mount( plugins[i].mountpoint, NULL, 0 );
178 DEBUG(
"Loaded plugins:");
179 for (
int i=0; i<n; i++) {
185 nfile_concatPaths( buf,
PATH_MAX, PHYSFS_getWriteDir(),
"plugins" );
202 free( p->description );
203 free( p->compatibility );
204 free( p->mountpoint );
220 if (plg->
name != NULL)
236 PCRE2_SIZE erroroffset;
238 pcre2_match_data *match_data;
240 if (plugins[i].compatibility == NULL)
243 re = pcre2_compile( (PCRE2_SPTR)plugins[i].compatibility, PCRE2_ZERO_TERMINATED, 0, &errornumber, &erroroffset, NULL );
245 PCRE2_UCHAR buffer[256];
246 pcre2_get_error_message( errornumber, buffer,
sizeof(buffer) );
247 WARN(_(
"Plugin '%s' PCRE2 compilation failed at offset %d: %s"),
plugin_name(&plugins[i]), (
int)erroroffset, buffer );
252 match_data = pcre2_match_data_create_from_pattern( re, NULL );
253 int rc = pcre2_match( re, (PCRE2_SPTR)version, strlen(version), 0, 0, match_data, NULL );
254 pcre2_match_data_free( match_data );
257 case PCRE2_ERROR_NOMATCH:
258 WARN(
"Plugin '%s' does not support Naev version '%s'.",
plugin_name(&plugins[i]), version);
262 WARN(_(
"Matching error %d"), rc );
270 pcre2_code_free( re );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
int nfile_dirMakeExist(const char *path)
Creates a directory if it doesn't exist.
int nfile_fileExists(const char *path)
Checks to see if a file exists.
int nfile_dirExists(const char *path)
Checks to see if a directory exists.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
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.
int plugin_init(void)
Initialize and loads all the available plugins.
int plugin_check(void)
Checks to see if the plugins are self-declared compatible with Naev.
const char * plugin_name(const plugin_t *plg)
Tries to tget the name of a plugin.
static int plugin_parse(plugin_t *plg, const char *file, const char *path)
Parses a plugin description file.
void plugin_exit(void)
Exits the plugin stuff.
static int plugin_cmp(const void *a, const void *b)
For qsort on plugins.
const plugin_t * plugin_list(void)
Returns the list of all the plugins.