libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

extractor_plugpath.c File Reference

determine path where plugins are installed More...

#include "platform.h"
#include "extractor.h"
#include <dirent.h>
#include <sys/types.h>
#include <signal.h>
#include <ltdl.h>
#include "extractor_plugpath.h"
#include "extractor_logging.h"
Include dependency graph for extractor_plugpath.c:

Go to the source code of this file.

Data Structures

struct  SearchContext
 
struct  DefaultLoaderContext
 

Typedefs

typedef void(* EXTRACTOR_PathProcessor) (void *cls, const char *path)
 

Functions

static char * cut_bin (char *in)
 
static char * get_path_from_PATH ()
 
static char * append_to_dir (const char *path, const char *fname)
 
static void get_installation_paths (EXTRACTOR_PathProcessor pp, void *pp_cls)
 
static void find_plugin_in_path (void *cls, const char *path)
 
char * EXTRACTOR_find_plugin_ (const char *short_name)
 
static void load_plugins_from_dir (void *cls, const char *path)
 
struct EXTRACTOR_PluginListEXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags)
 

Detailed Description

determine path where plugins are installed

Author
Christian Grothoff

Definition in file extractor_plugpath.c.

Typedef Documentation

◆ EXTRACTOR_PathProcessor

typedef void(* EXTRACTOR_PathProcessor) (void *cls, const char *path)

Function to call on paths.

Parameters
clsclosure
patha directory path

Definition at line 42 of file extractor_plugpath.c.

Function Documentation

◆ append_to_dir()

static char* append_to_dir ( const char *  path,
const char *  fname 
)
static

Create a filename by appending 'fname' to 'path'.

Parameters
paththe base path
fnamethe filename to append
Returns
'$path/$fname', NULL on error

Definition at line 413 of file extractor_plugpath.c.

References NULL.

Referenced by find_plugin_in_path(), and get_installation_paths().

◆ cut_bin()

static char* cut_bin ( char *  in)
static

Remove a trailing '/bin/' from 'in' (if present).

Parameters
ininput string, modified
Returns
NULL if 'in' is NULL, otherwise 'in' with '/bin/' removed

Definition at line 53 of file extractor_plugpath.c.

References NULL.

Referenced by get_path_from_PATH().

◆ EXTRACTOR_find_plugin_()

char* EXTRACTOR_find_plugin_ ( const char *  short_name)

Given a short name of a library (i.e. "mime"), find the full path of the respective plugin.

Definition at line 593 of file extractor_plugpath.c.

References find_plugin_in_path(), get_installation_paths(), NULL, SearchContext::path, and SearchContext::short_name.

Referenced by EXTRACTOR_plugin_add(), and EXTRACTOR_plugin_load_().

◆ EXTRACTOR_plugin_add_defaults()

struct EXTRACTOR_PluginList* EXTRACTOR_plugin_add_defaults ( enum EXTRACTOR_Options  flags)

Load the default set of plugins. The default can be changed by setting the LIBEXTRACTOR_LIBRARIES environment variable. If it is set to "env", then this function will return #EXTRACTOR_plugin_add_config(NULL, env, flags). Otherwise, it will load all of the installed plugins and return them.

Parameters
flagsoptions for all of the plugins loaded
Returns
the default set of plugins, NULL if no plugins were found

Definition at line 683 of file extractor_plugpath.c.

References EXTRACTOR_plugin_add_config(), DefaultLoaderContext::flags, get_installation_paths(), getenv(), load_plugins_from_dir(), NULL, and DefaultLoaderContext::res.

Referenced by main().

◆ find_plugin_in_path()

static void find_plugin_in_path ( void *  cls,
const char *  path 
)
static

Load all plugins from the given directory.

Parameters
clspointer to the "struct EXTRACTOR_PluginList*" to extend
pathpath to a directory with plugins

Definition at line 540 of file extractor_plugpath.c.

References append_to_dir(), LOG_STRERROR, NULL, SearchContext::path, and SearchContext::short_name.

Referenced by EXTRACTOR_find_plugin_().

◆ get_installation_paths()

static void get_installation_paths ( EXTRACTOR_PathProcessor  pp,
void *  pp_cls 
)
static

Iterate over all paths where we expect to find GNU libextractor plugins.

Parameters
ppfunction to call for each path
pp_clscls argument for pp.

Definition at line 461 of file extractor_plugpath.c.

References append_to_dir(), get_path_from_PATH(), getenv(), LOG_STRERROR, and NULL.

Referenced by EXTRACTOR_find_plugin_(), and EXTRACTOR_plugin_add_defaults().

◆ get_path_from_PATH()

static char* get_path_from_PATH ( )
static

Return the actual path to a file found in the current PATH environment variable.

Returns
path to binary, NULL if not found

Definition at line 331 of file extractor_plugpath.c.

References cut_bin(), getenv(), LOG_STRERROR, and NULL.

Referenced by get_installation_paths().

◆ load_plugins_from_dir()

static void load_plugins_from_dir ( void *  cls,
const char *  path 
)
static

Load all plugins from the given directory.

Parameters
clspointer to the "struct EXTRACTOR_PluginList*" to extend
pathpath to a directory with plugins

Definition at line 629 of file extractor_plugpath.c.

References EXTRACTOR_plugin_add(), DefaultLoaderContext::flags, LOG_STRERROR, NULL, and DefaultLoaderContext::res.

Referenced by EXTRACTOR_plugin_add_defaults().