pathmanager.c File Reference

#include "pathmanager_p.h"
#include "binreloc.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 DIRSEP   "/"
#define DIRSEP_C   '/'

Functions

int GWEN_PathManager_AddPath (const char *callingLib, const char *destLib, const char *pathName, const char *pathValue)
int GWEN_PathManager_AddPathFromWinReg (const char *callingLib, const char *destLib, const char *pathName, const char *keypath, 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)
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 ()
int GWEN_PathManager_ModuleInit ()
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

#define DIRSEP   "/"

#define DIRSEP_C   '/'

Definition at line 55 of file pathmanager.c.

Referenced by _br_find_exe(), br_build_path(), br_dirname(), and GWEN_PathManager_AddRelPath().


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:
callingLib The name of the library that adds this path entry.
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
pathValue The actual directory path that should be added to this registered path.
rm path 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 126 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_AddPathFromWinReg(), GWEN_PathManager_AddRelPath(), GWEN_PluginManager_AddPath(), and GWEN_PluginManager_AddPathFromWinReg().

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

Add a directory path entry to a registered path entry in the global GWEN_PathManager by looking up the directory path in the Windows registry.

On non-windows platforms, the function does nothing and returns zero, so you can safely call this in your multi-platform code.

Note: Gwenhywfar-2.6.0 and older used to lookup the paths under HKEY_CURRENT_USER, but with gwen-2.6.1 this was changed to HKEY_LOCAL_MACHINE because we're talking about installation paths as opposed to per-user configuration settings.

Parameters:
callingLib The name of the library that adds this path entry.
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
keypath The key's path in the windows registry under HKEY_LOCAL_MACHINE, e.g. "Software\MyProgram\Paths".
varname The variable name of the string variable with the actual directory path.
Returns:
Zero on success, or nonzero if the pathName or the registry key was not found.

Definition at line 499 of file pathmanager.c.

References DBG_INFO, GWEN_LOGDOMAIN, GWEN_PathManager_AddPath(), and MAX_PATH.

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:
callingLib The name of the library that adds this path entry.
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
pathValue The actual directory path relative to the prefix of the current working directory that should be added to this registered path.
rm The 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 167 of file pathmanager.c.

References br_find_prefix, DBG_ERROR, DBG_INFO, DIRSEP, DIRSEP_C, GWEN_Buffer_AppendString(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_Directory_GetHomeDirectory(), GWEN_ERROR_GENERIC, GWEN_ERROR_INVALID, GWEN_ERROR_IO, GWEN_LOGDOMAIN, GWEN_PathManager_AddPath(), GWEN_PathManager_RelModeCwd, GWEN_PathManager_RelModeExe, GWEN_PathManager_RelModeHome, and NULL.

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:
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
Returns:
Zero on success, or GWEN_ERROR_INVALID if the pathName already exists.

Definition at line 78 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().

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:
destLib The name of the library that this path is supposed to belong to.
pathName A 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 453 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_Crypt_Token_ModuleInit(), GWEN_DBIO_ModuleInit(), GWEN_I18N_ModuleInit(), GWEN_Io_LayerTls_Prepare(), GWEN_PluginManager_GetPaths(), GWEN_PluginManager_GetPluginDescrs(), GWEN_PluginManager_LoadPlugin(), 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:
callingLib The name of the library that adds this path entry.
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
pathValue The actual directory path that should be added to this registered path.

Definition at line 307 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().

int GWEN_PathManager_ModuleFini (  ) 

Definition at line 70 of file pathmanager.c.

References gwen__paths, and GWEN_DB_Group_free().

Referenced by GWEN_Fini().

int GWEN_PathManager_ModuleInit (  ) 

Definition at line 62 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:
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
Returns:
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 430 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:
callingLib The name of the library that added this path entry.
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
pathValue The 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 344 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:
callingLib The name of the library that added path entries.
Returns:
Zero on success.

Definition at line 391 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:
destLib The name of the library that this path is supposed to belong to.
pathName A string identifier for this registered path.
Returns:
Zero on success, or GWEN_ERROR_NOT_FOUND if the pathName was not found.

Definition at line 102 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]


Generated on Wed Jul 9 13:12:30 2008 for gwenhywfar by  doxygen 1.5.6