gwenhywfar 5.14.1
pathmanager.c File Reference
#include "pathmanager_p.h"
#include <gwenhywfar/db.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/directory.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
Include dependency graph for pathmanager.c:

Go to the source code of this file.

Macros

#define DISABLE_DEBUGLOG

Functions

int GWEN_PathManager_AddPath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue)
int GWEN_PathManager_AddPathFromWinReg (GWEN_UNUSED const char *callingLib, GWEN_UNUSED const char *destLib, GWEN_UNUSED const char *pathName, GWEN_UNUSED const char *keypath, GWEN_UNUSED const char *varname)
int GWEN_PathManager_AddRelPath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue, GWEN_PATHMANAGER_RELMODE rm)
int GWEN_PathManager_DefinePath (const char *destLib, const char *pathName)
int GWEN_PathManager_FindFile (const char *destLib, const char *pathName, const char *fileName, GWEN_BUFFER *fbuf)
int GWEN_PathManager_GetMatchingFilesRecursively (const char *destLib, const char *pathName, const char *subFolderName, GWEN_STRINGLIST *sl, const char *mask)
GWEN_STRINGLISTGWEN_PathManager_GetPaths (const char *destLib, const char *pathName)
int GWEN_PathManager_InsertPath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue)
int GWEN_PathManager_InsertRelPath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue, GWEN_PATHMANAGER_RELMODE rm)
int GWEN_PathManager_ModuleFini (void)
int GWEN_PathManager_ModuleInit (void)
int GWEN_PathManager_PathChanged (const char *destLib, const char *pathName)
int GWEN_PathManager_RemovePath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue)
int GWEN_PathManager_RemovePaths (const char *callingLib)
int GWEN_PathManager_UndefinePath (const char *destLib, const char *pathName)

Variables

static GWEN_DB_NODEgwen__paths =0

Macro Definition Documentation

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 29 of file pathmanager.c.

Function Documentation

◆ GWEN_PathManager_AddPath()

int GWEN_PathManager_AddPath ( const char * callingLib,
const char * destLib,
const char * pathName,
const char * pathValue )

Add a directory path entry to a registered path entry in the global GWEN_PathManager.

Parameters
callingLibThe name of the library that adds this path entry.
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
pathValueThe actual directory path that should be added to this registered path.
rmpath relative to what? (see GWEN_PathManager_RelModeCwd)
Returns
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 121 of file pathmanager.c.

References gwen__paths, GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DB_FLAGS_DEFAULT, GWEN_DB_GetGroup(), GWEN_DB_SetCharValue(), GWEN_Directory_OsifyPath(), GWEN_ERROR_NOT_FOUND, GWEN_PATH_FLAGS_CREATE_GROUP, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_Init(), GWEN_PathManager_AddRelPath(), and GWEN_PluginManager_AddPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_AddPathFromWinReg()

int GWEN_PathManager_AddPathFromWinReg ( GWEN_UNUSED const char * callingLib,
GWEN_UNUSED const char * destLib,
GWEN_UNUSED const char * pathName,
GWEN_UNUSED const char * keypath,
GWEN_UNUSED const char * varname )

Definition at line 716 of file pathmanager.c.

References GWEN_UNUSED.

Referenced by GWEN_Init().

Here is the caller graph for this function:

◆ GWEN_PathManager_AddRelPath()

int GWEN_PathManager_AddRelPath ( const char * callingLib,
const char * destLib,
const char * pathName,
const char * pathValue,
GWEN_PATHMANAGER_RELMODE rm )

Same as GWEN_PathManager_AddPath but the path to add is given relative to some directory. The "relmode" argument chooses the base directory to which the given sub-directory path is appended and the result is added to this PathManager:

  • RelModeCwd appends the path to the current working directory at the time of calling. So future changes to the CWD do not affect this setting.
  • RelModeExe appends the path to the prefix of the installation location of the calling executable. This function looks up the current working directory, removes the last component (i.e. the "/bin/") to get the prefix, then adds the given relative path to it.
  • RelModeHome appends the path to the return value of GWEN_Directory_GetHomeDirectory().

All three variantes will then add the resulting path to the PathManager.

Parameters
callingLibThe name of the library that adds this path entry.
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
pathValueThe actual directory path relative to the prefix of the current working directory that should be added to this registered path.
rmThe Flag to choose the starting directory to which the path is appended.
Returns
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 163 of file pathmanager.c.

References DBG_ERROR, DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR, GWEN_DIR_SEPARATOR_S, GWEN_Directory_GetHomeDirectory(), GWEN_Directory_GetPrefixDirectory(), GWEN_ERROR_INVALID, GWEN_ERROR_IO, GWEN_LOGDOMAIN, GWEN_PathManager_AddPath(), GWEN_PathManager_RelModeCwd, GWEN_PathManager_RelModeExe, and GWEN_PathManager_RelModeHome.

Referenced by GWEN_Init(), and GWEN_PluginManager_AddRelPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_DefinePath()

int GWEN_PathManager_DefinePath ( const char * destLib,
const char * pathName )

Register a path to be managed by the global GWEN_PathManager module. This must be done before calling one of the other functions of this group. The actual path is not yet set.

Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
Returns
Zero on success, or GWEN_ERROR_INVALID if the pathName already exists.

Definition at line 71 of file pathmanager.c.

References DBG_ERROR, gwen__paths, GWEN_DB_FLAGS_DEFAULT, GWEN_DB_GetGroup(), GWEN_ERROR_INVALID, GWEN_LOGDOMAIN, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_Init(), and GWEN_PluginManager_Register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_FindFile()

int GWEN_PathManager_FindFile ( const char * destLib,
const char * pathName,
const char * fileName,
GWEN_BUFFER * fbuf )

This functions tries to find a given file using all path entries under the registered pathName.

Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
fileNameName of the file (may contain partial paths, like in "dialogs/testdialog.xml"
fbufbuffer to receive the full path to access the file
Returns
0 on success (in that case fbuf will be filled), an error code otherwise.

Definition at line 541 of file pathmanager.c.

References DBG_DEBUG, DBG_INFO, gwen__paths, GWEN_Buffer_AppendBuffer(), GWEN_Buffer_AppendString(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_Buffer_Reset(), GWEN_DB_FindFirstGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_GetCharValue(), GWEN_DB_GetGroup(), GWEN_DIR_SEPARATOR_S, GWEN_ERROR_NOT_FOUND, GWEN_LOGDOMAIN, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_Dialog_CreateAndLoadWithPath(), GWEN_DlgInput_new(), and GWEN_DlgShowBox_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_GetMatchingFilesRecursively()

int GWEN_PathManager_GetMatchingFilesRecursively ( const char * destLib,
const char * pathName,
const char * subFolderName,
GWEN_STRINGLIST * sl,
const char * mask )

This function calls GWEN_Directory_GetMatchingFilesRecursively() on every path entry under the registered pathName.

Returns
0 if ok, error code on error
Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
subFolderNameif given then this folder name is appended to every path under the registered pathName before caling GWEN_Directory_GetMatchingFilesRecursively() on it. You can use this parameter to search only in specific sub folders of the paths.
slstring list to receive the paths of all matching files

Definition at line 604 of file pathmanager.c.

References DBG_DEBUG, gwen__paths, GWEN_Buffer_AppendString(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_Buffer_Reset(), GWEN_DB_FindFirstGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_GetCharValue(), GWEN_DB_GetGroup(), GWEN_DIR_SEPARATOR_S, GWEN_Directory_GetMatchingFilesRecursively(), GWEN_LOGDOMAIN, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Here is the call graph for this function:

◆ GWEN_PathManager_GetPaths()

GWEN_STRINGLIST * GWEN_PathManager_GetPaths ( const char * destLib,
const char * pathName )

Returns a string list of all path entries that exist under the registered pathName.

Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
Returns
A newly allocated GWEN_STRINGLIST with all added path entries, or NULL if no path entry or no registered pathName exists. Delete this list with GWEN_StringList_free() when no longer needed.

Definition at line 494 of file pathmanager.c.

References DBG_DEBUG, gwen__paths, GWEN_DB_FindFirstGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_GetCharValue(), GWEN_DB_GetGroup(), GWEN_LOGDOMAIN, GWEN_PATH_FLAGS_NAMEMUSTEXIST, GWEN_StringList_AppendString(), GWEN_StringList_Count(), GWEN_StringList_free(), and GWEN_StringList_new().

Referenced by _loadPluginDescrs(), _searchAndLoadModule(), buildFile2(), doBuildDefs(), GWEN_ConfigMgr_ModuleInit(), GWEN_Crypt_Token_ModuleInit(), GWEN_DBIO_ModuleInit(), GWEN_Dialog_AddMediaPathsFromPathManager(), GWEN_I18N_ModuleInit(), GWEN_PluginManager_GetPaths(), main(), and print_paths().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_InsertPath()

int GWEN_PathManager_InsertPath ( const char * callingLib,
const char * destLib,
const char * pathName,
const char * pathValue )

Insert a directory path entry to a registered path entry in the global GWEN_PathManager. While GWEN_PathManager_AddPath adds a path to the end of the list for this particular pathName this function here inserts it at the beginning of the list. This can be used e.g. to ensure that plugins/files from a given path take precedence over already added paths.

Parameters
callingLibThe name of the library that adds this path entry.
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
pathValueThe actual directory path that should be added to this registered path.

Definition at line 254 of file pathmanager.c.

References gwen__paths, GWEN_DB_FLAGS_DEFAULT, GWEN_DB_FLAGS_INSERT, GWEN_DB_GetGroup(), GWEN_DB_SetCharValue(), GWEN_ERROR_NOT_FOUND, GWEN_PATH_FLAGS_CREATE_GROUP, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_PathManager_InsertRelPath(), and GWEN_PluginManager_InsertPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_InsertRelPath()

int GWEN_PathManager_InsertRelPath ( const char * callingLib,
const char * destLib,
const char * pathName,
const char * pathValue,
GWEN_PATHMANAGER_RELMODE rm )

Same as GWEN_PathManager_InsertPath but the path to insert is given relative to some directory. The "relmode" argument chooses the base directory to which the given sub-directory path is appended and the result is added to this PathManager:

  • RelModeCwd appends the path to the current working directory at the time of calling. So future changes to the CWD do not affect this setting.
  • RelModeExe appends the path to the prefix of the installation location of the calling executable. This function looks up the current working directory, removes the last component (i.e. the "/bin/") to get the prefix, then adds the given relative path to it.
  • RelModeHome appends the path to the return value of GWEN_Directory_GetHomeDirectory().

All three variantes will then add the resulting path to the PathManager.

Parameters
callingLibThe name of the library that adds this path entry.
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
pathValueThe actual directory path relative to the prefix of the current working directory that should be added to this registered path.
rmThe Flag to choose the starting directory to which the path is appended.
Returns
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 292 of file pathmanager.c.

References DBG_ERROR, DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR, GWEN_DIR_SEPARATOR_S, GWEN_Directory_GetHomeDirectory(), GWEN_Directory_GetPrefixDirectory(), GWEN_ERROR_INVALID, GWEN_ERROR_IO, GWEN_LOGDOMAIN, GWEN_PathManager_InsertPath(), GWEN_PathManager_RelModeCwd, GWEN_PathManager_RelModeExe, and GWEN_PathManager_RelModeHome.

Referenced by GWEN_PluginManager_InsertRelPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_ModuleFini()

int GWEN_PathManager_ModuleFini ( void )

Definition at line 62 of file pathmanager.c.

References gwen__paths, and GWEN_DB_Group_free().

Referenced by GWEN_Fini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_ModuleInit()

int GWEN_PathManager_ModuleInit ( void )

Definition at line 53 of file pathmanager.c.

References gwen__paths, and GWEN_DB_Group_new().

Referenced by GWEN_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_PathChanged()

int GWEN_PathManager_PathChanged ( const char * destLib,
const char * pathName )

This function checks whether the path list for pathName has changed since the last call to this function (i.e. whether paths have been added, inserted or removed).

Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
Returns
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 470 of file pathmanager.c.

References gwen__paths, GWEN_DB_GetGroup(), GWEN_DB_GetNodeFlags(), GWEN_DB_NODE_FLAGS_DIRTY, GWEN_ERROR_NOT_FOUND, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Here is the call graph for this function:

◆ GWEN_PathManager_RemovePath()

int GWEN_PathManager_RemovePath ( const char * callingLib,
const char * destLib,
const char * pathName,
const char * pathValue )

Removes a directory path entry from a registered path entry in the global GWEN_PathManager.

Parameters
callingLibThe name of the library that added this path entry.
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
pathValueThe actual directory path that should be added to this registered path.
Returns
Zero on success, or nonzero if the pathName was not found.

Definition at line 382 of file pathmanager.c.

References gwen__paths, GWEN_DB_FindFirstGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_GetCharValue(), GWEN_DB_GetGroup(), GWEN_DB_Group_free(), GWEN_DB_UnlinkGroup(), GWEN_ERROR_NOT_FOUND, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_PluginManager_RemovePath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_PathManager_RemovePaths()

int GWEN_PathManager_RemovePaths ( const char * callingLib)

Removes all directory path entries that were registered by the callingLib from the global GWEN_PathManager.

Parameters
callingLibThe name of the library that added path entries.
Returns
Zero on success.

Definition at line 430 of file pathmanager.c.

References gwen__paths, GWEN_DB_DeleteGroup(), GWEN_DB_FindFirstGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_GetCharValue(), GWEN_DB_GetFirstGroup(), GWEN_DB_GetNextGroup(), GWEN_DB_Group_free(), and GWEN_DB_UnlinkGroup().

Here is the call graph for this function:

◆ GWEN_PathManager_UndefinePath()

int GWEN_PathManager_UndefinePath ( const char * destLib,
const char * pathName )

Unregister a path that was registered by GWEN_PathManager_DefinePath().

Parameters
destLibThe name of the library that this path is supposed to belong to.
pathNameA string identifier for this registered path.
Returns
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 96 of file pathmanager.c.

References gwen__paths, GWEN_DB_FLAGS_DEFAULT, GWEN_DB_GetGroup(), GWEN_DB_Group_free(), GWEN_DB_UnlinkGroup(), GWEN_ERROR_NOT_FOUND, and GWEN_PATH_FLAGS_NAMEMUSTEXIST.

Referenced by GWEN_PluginManager_Unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ gwen__paths