gwenhywfar  4.3.3
Defines | Functions | Variables
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>

Go to the source code of this file.

Defines

#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_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

Define Documentation

Definition at line 29 of file pathmanager.c.


Function Documentation

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 117 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().

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 612 of file pathmanager.c.

Referenced by GWEN_Init().

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.

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 158 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().

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 69 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().

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 440 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_DlgInput_new(), GWEN_DlgMessage_new(), GWEN_DlgProgress_new(), and GWEN_DlgShowBox_new().

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 502 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.

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 394 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 GWEN_ConfigMgr_ModuleInit(), GWEN_Crypt_Token_ModuleInit(), GWEN_DBIO_ModuleInit(), GWEN_Dialog_AddMediaPathsFromPathManager(), GWEN_I18N_ModuleInit(), GWEN_PluginManager_GetPaths(), GWEN_PluginManager_GetPluginDescrs(), GWEN_PluginManager_LoadPlugin(), GWEN_SyncIo_Tls_Prepare(), and print_paths().

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 248 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_PluginManager_InsertPath().

Definition at line 61 of file pathmanager.c.

References gwen__paths, and GWEN_DB_Group_free().

Referenced by GWEN_Fini().

Definition at line 53 of file pathmanager.c.

References gwen__paths, and GWEN_DB_Group_new().

Referenced by GWEN_Init().

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 371 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.

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 285 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().

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 332 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().

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 93 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().


Variable Documentation

GWEN_DB_NODE* gwen__paths = 0 [static]