diff options
author | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
---|---|---|
committer | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
commit | b2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch) | |
tree | cf58939393a9032182c4fbc4441164a9456e82f8 /ldap/servers/slapd/dynalib.c | |
download | ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.gz ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.xz ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.zip |
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/servers/slapd/dynalib.c')
-rw-r--r-- | ldap/servers/slapd/dynalib.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/ldap/servers/slapd/dynalib.c b/ldap/servers/slapd/dynalib.c new file mode 100644 index 00000000..4839a17b --- /dev/null +++ b/ldap/servers/slapd/dynalib.c @@ -0,0 +1,86 @@ +/** BEGIN COPYRIGHT BLOCK + * Copyright 2001 Sun Microsystems, Inc. + * Portions copyright 1999, 2001-2003 Netscape Communications Corporation. + * All rights reserved. + * END COPYRIGHT BLOCK **/ +/* dynalib.c - dynamic library routines */ + +#include <stdio.h> +#include "prlink.h" +#include "slap.h" +#if defined(SOLARIS) +#include <dlfcn.h> /* dlerror */ +#endif + + +static struct dynalib { + char *dl_name; + PRLibrary *dl_handle; +} **libs = NULL; + +static void symload_report_error( char *libpath, char *symbol, char *plugin, + int libopen ); + +void * +sym_load( char *libpath, char *symbol, char *plugin, int report_errors ) +{ + int i; + void *handle; + + for ( i = 0; libs != NULL && libs[i] != NULL; i++ ) { + if ( strcasecmp( libs[i]->dl_name, libpath ) == 0 ) { + handle = PR_FindSymbol( libs[i]->dl_handle, symbol ); + if ( NULL == handle && report_errors ) { + symload_report_error( libpath, symbol, plugin, 1 /* lib open */ ); + } + return handle; + } + } + + if ( (handle = PR_LoadLibrary( libpath )) == NULL ) { + if ( report_errors ) { + symload_report_error( libpath, symbol, plugin, 0 /* lib not open */ ); + } + return( NULL ); + } + + libs = (struct dynalib **) slapi_ch_realloc( (char *) libs, (i + 2) * + sizeof(struct dynalib) ); + libs[i] = (struct dynalib *) slapi_ch_malloc( sizeof(struct dynalib) ); + libs[i]->dl_name = slapi_ch_strdup( libpath ); + libs[i]->dl_handle = handle; + libs[ i + 1 ] = NULL; + + handle = PR_FindSymbol( libs[i]->dl_handle, symbol ); + if ( NULL == handle && report_errors ) { + symload_report_error( libpath, symbol, plugin, 1 /* lib open */ ); + } + return handle; +} + + +static void +symload_report_error( char *libpath, char *symbol, char *plugin, int libopen ) +{ + char *errtext = NULL; + PRInt32 errlen, err; + + errlen = PR_GetErrorTextLength(); + if ( errlen > 0 ) { + errtext = slapi_ch_malloc( errlen ); + if (( err = PR_GetErrorText( errtext )) > 0 ) { + LDAPDebug( LDAP_DEBUG_ANY, SLAPI_COMPONENT_NAME_NSPR " error %d: %s\n", + PR_GetError(), errtext, 0 ); + } + slapi_ch_free( (void **)&errtext ); + } + if ( libopen ) { + LDAPDebug( LDAP_DEBUG_ANY, + "Could not load symbol \"%s\" from \"%s\" for plugin %s\n", + symbol, libpath, plugin ); + } else { + LDAPDebug( LDAP_DEBUG_ANY, + "Could not open library \"%s\" for plugin %s\n", + libpath, plugin, 0 ); + } +} |