/* Ensure that the RA library NAME is loaded.
 *
 * If FUNC is non-NULL, set *FUNC to the address of the svn_ra_NAME__init
 * function of the library.
 *
 * If COMPAT_FUNC is non-NULL, set *COMPAT_FUNC to the address of the
 * svn_ra_NAME_init compatibility init function of the library.
 *
 * ### todo: Any RA libraries implemented from this point forward
 * ### don't really need an svn_ra_NAME_init compatibility function.
 * ### Currently, load_ra_module() will error if no such function is
 * ### found, but it might be more friendly to simply set *COMPAT_FUNC
 * ### to null (assuming COMPAT_FUNC itself is non-null).
 */
static svn_error_t *
load_ra_module(svn_ra__init_func_t *func,
               svn_ra_init_func_t *compat_func,
               const char *ra_name, apr_pool_t *pool)
{
  if (func)
    *func = NULL;
  if (compat_func)
    *compat_func = NULL;

#if defined(SVN_USE_DSO) && APR_HAS_DSO
  {
    apr_dso_handle_t *dso;
    apr_dso_handle_sym_t symbol;
    const char *libname;
    const char *funcname;
    const char *compat_funcname;
    apr_status_t status;

    libname = apr_psprintf(pool, "libsvn_ra_%s-%d.so.0",
                           ra_name, SVN_VER_MAJOR);
    funcname = apr_psprintf(pool, "svn_ra_%s__init", ra_name);
    compat_funcname = apr_psprintf(pool, "svn_ra_%s_init", ra_name);

    /* find/load the specified library */
    SVN_ERR(svn_dso_load(&dso, libname));
    if (! dso)
      return SVN_NO_ERROR;

    /* find the initialization routines */
    if (func)
      {
        status = apr_dso_sym(&symbol, dso, funcname);
        if (status)
          {
            return svn_error_wrap_apr(status,
                                      _("'%s' does not define '%s()'"),
                                      libname, funcname);
          }

        *func = (svn_ra__init_func_t) symbol;
      }

    if (compat_func)
      {
        status = apr_dso_sym(&symbol, dso, compat_funcname);
        if (status)
          {
            return svn_error_wrap_apr(status,
                                      _("'%s' does not define '%s()'"),
                                      libname, compat_funcname);
          }

        *compat_func = (svn_ra_init_func_t) symbol;
      }
  }
#endif /* APR_HAS_DSO */

  return SVN_NO_ERROR;
}
示例#2
0
文件: plugin.c 项目: ICRAR/gridding
void*
dfGetPluginMethod(
	df_plugin handle, 
	const char* name, 
	df_status* status)
{
	void* method;
    apr_status_t apr_status;
    char apr_errstr[256];

	df_plugin_t* p = (df_plugin_t*)handle;
	if(!p)
	{
		if(status)(*status) = DF_INVALID_PLUGIN;
		return NULL;
	}
	
	apr_status = apr_dso_sym(&method, p->handle, name);
	if(apr_status != APR_SUCCESS)
	{
		if(status)(*status) = DF_INVALID_VALUE;
	    apr_dso_error(p->handle, apr_errstr, 256);
		dfLogError(p->context, DF_INVALID_VALUE, "Failed to load function from plugin: %s", apr_errstr);
	    return NULL;
	}

	if(status)(*status) = DF_SUCCESS;
	return method;
}
示例#3
0
void*  Shlib::getSymbol(const char* name) {
    apr_dso_handle_sym_t symbol;
    CHECK_APR_SUCCESS(apr_dso_sym(&symbol,
                                  static_cast<apr_dso_handle_t*>(handle),
                                  name));
    return (void*) symbol;
}
示例#4
0
static void test_dso_sym(abts_case *tc, void *data)
{
    apr_dso_handle_t *h = NULL;
    apr_dso_handle_sym_t func1 = NULL;
    apr_status_t status;
    void (*function)(char str[256]);
    char teststr[256];
    char errstr[256];

    status = apr_dso_load(&h, modname, p);
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    ABTS_PTR_NOTNULL(tc, h);

    status = apr_dso_sym(&func1, h, "print_hello");
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    ABTS_PTR_NOTNULL(tc, func1);

    if (!tc->failed) {
        function = (void (*)(char *))func1;
        (*function)(teststr);
        ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr);
    }

    apr_dso_unload(h);
}
示例#5
0
APU_DECLARE(apr_status_t) apr_dbd_get_driver(apr_pool_t *pool, const char *name,
                                             const apr_dbd_driver_t **driver)
{
#if APR_DSO_BUILD
    char path[80];
    apr_dso_handle_t *dlhandle = NULL;
#endif
    apr_status_t rv;

   *driver = apr_hash_get(drivers, name, APR_HASH_KEY_STRING);
    if (*driver) {
        return APR_SUCCESS;
    }

#if APR_DSO_BUILD

#if APR_HAS_THREADS
    rv = apr_thread_mutex_lock(mutex);
    if (rv != APR_SUCCESS) {
        goto unlock;
    }
    *driver = apr_hash_get(drivers, name, APR_HASH_KEY_STRING);
    if (*driver) {
        goto unlock;
    }
#endif

#ifdef WIN32
    sprintf(path, "apr_dbd_%s.dll", name);
#else
    sprintf(path, "apr_dbd_%s.so", name);
#endif
    rv = apr_dso_load(&dlhandle, path, pool);
    if (rv != APR_SUCCESS) { /* APR_EDSOOPEN */
        goto unlock;
    }
    sprintf(path, "apr_dbd_%s_driver", name);
    rv = apr_dso_sym((void*)driver, dlhandle, path);
    if (rv != APR_SUCCESS) { /* APR_ESYMNOTFOUND */
        apr_dso_unload(dlhandle);
        goto unlock;
    }
    if ((*driver)->init) {
        (*driver)->init(pool);
    }
    apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);

unlock:
#if APR_HAS_THREADS
    apr_thread_mutex_unlock(mutex);
#endif

#else	/* APR_DSO_BUILD - so if it wasn't already loaded, it's NOTIMPL */
    rv = APR_ENOTIMPL;
#endif

    return rv;
}
示例#6
0
static void initialize() {
	static bool initialized = false;	
	if (!initialized) {
		apr_dso_handle_t* hprog = 0;
		LLAPRPool pool;
		pool.create();
#if LL_WINDOWS
		apr_dso_load(&hprog, "libtcmalloc_minimal.dll", pool());
#else
		apr_dso_load(&hprog, 0, pool());
#endif
		apr_dso_sym((apr_dso_handle_sym_t*)&MallocExtension_GetNumericProperty,
			hprog, "MallocExtension_GetNumericProperty");
		apr_dso_sym((apr_dso_handle_sym_t*)&MallocExtension_GetStats,
			hprog, "MallocExtension_GetStats");
		initialized = true;
	}	
}
/** 
 * Dynamically loads the plugin and runs the plugin's init function.
 *
 * @param[in] plugin_file Name of plugin dll/dylib/so. TODO:DOC is this correct? see .h
 * @return 0 if successful, APR error code or error code from the plugin's init function on failure.
 */
int LLPluginInstance::load(const std::string& plugin_dir, std::string &plugin_file)
{
	pluginInitFunction init_function = NULL;
	
	if ( plugin_dir.length() )
	{
#if LL_WINDOWS
		// VWR-21275:
		// *SOME* Windows systems fail to load the Qt plugins if the current working
		// directory is not the same as the directory with the Qt DLLs in.
		// This should not cause any run time issues since we are changing the cwd for the
		// plugin shell process and not the viewer.
		// Changing back to the previous directory is not necessary since the plugin shell
		// quits once the plugin exits.
		_chdir( plugin_dir.c_str() );	
#endif
	};

	int result = apr_dso_load(&mDSOHandle,
					  plugin_file.c_str(),
					  gAPRPoolp);
	if(result != APR_SUCCESS)
	{
		char buf[1024];
		apr_dso_error(mDSOHandle, buf, sizeof(buf));

		LL_WARNS("PluginInstance") << "apr_dso_load of " << plugin_file << " failed with error " << result << " , additional info string: " << buf << LL_ENDL;

	}

	if(result == APR_SUCCESS)
	{
		result = apr_dso_sym((apr_dso_handle_sym_t*)&init_function,
						 mDSOHandle,
						 PLUGIN_INIT_FUNCTION_NAME);

		if(result != APR_SUCCESS)
		{
			LL_WARNS("PluginInstance") << "apr_dso_sym failed with error " << result << LL_ENDL;
		}
	}

	if(result == APR_SUCCESS)
	{
		result = init_function(staticReceiveMessage, (void*)this, &mPluginSendMessageFunction, &mPluginUserData);

		if((result != APR_SUCCESS) || (mPluginUserData == NULL))
		{
			LL_WARNS("PluginInstance") << "call to init function failed with error " << result << LL_ENDL;
		}
	}

	return (int)result;
}
static apt_bool_t plugin_logger_load(apr_dso_handle_t *plugin)
{
	apr_dso_handle_sym_t func_handle = NULL;
	if(apr_dso_sym(&func_handle,plugin,MRCP_PLUGIN_LOGGER_SYM_NAME) != APR_SUCCESS) {
		return FALSE;
	}

	if(func_handle) {
		apt_logger_t *logger = apt_log_instance_get();
		mrcp_plugin_log_accessor_f log_accessor;
		log_accessor = (mrcp_plugin_log_accessor_f)(intptr_t)func_handle;
		log_accessor(logger);
	}
	return TRUE;
}
示例#9
0
static void test_unload_library(abts_case *tc, void *data)
{
    apr_dso_handle_t *h = NULL;
    apr_status_t status;
    char errstr[256];
    apr_dso_handle_sym_t func1 = NULL;

    status = apr_dso_load(&h, libname, p);
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    ABTS_PTR_NOTNULL(tc, h);

    status = apr_dso_unload(h);
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);

    status = apr_dso_sym(&func1, h, "print_hello");
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status));
}
示例#10
0
static void test_unload_library(CuTest *tc)
{
    apr_dso_handle_t *h = NULL;
    apr_status_t status;
    char errstr[256];
    apr_dso_handle_sym_t func1 = NULL;

    status = apr_dso_load(&h, libname, p);
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    CuAssertPtrNotNull(tc, h);

    status = apr_dso_unload(h);
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);

    status = apr_dso_sym(&func1, h, "print_hello");
    CuAssertIntEquals(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status));
}
示例#11
0
static mrcp_plugin_creator_f plugin_creator_load(apr_dso_handle_t *plugin)
{
	apr_dso_handle_sym_t func_handle = NULL;
	mrcp_plugin_creator_f plugin_creator = NULL;
	
	if(apr_dso_sym(&func_handle,plugin,MRCP_PLUGIN_ENGINE_SYM_NAME) == APR_SUCCESS) {
		if(func_handle) {
			plugin_creator = (mrcp_plugin_creator_f)(intptr_t)func_handle;
		}
	}
	else {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load DSO Symbol: "MRCP_PLUGIN_ENGINE_SYM_NAME);
		return NULL;
	}

	return plugin_creator;
}
示例#12
0
static svn_error_t *
load_module(fs_init_func_t *initfunc, const char *name, apr_pool_t *pool)
{
  *initfunc = NULL;

#if defined(SVN_USE_DSO) && APR_HAS_DSO
  {
    apr_dso_handle_t *dso;
    apr_dso_handle_sym_t symbol;
    const char *libname;
    const char *funcname;
    apr_status_t status;
    const char *p;

    /* Demand a simple alphanumeric name so that the generated DSO
       name is sensible. */
    for (p = name; *p; ++p)
      if (!svn_ctype_isalnum(*p))
        return svn_error_createf(SVN_ERR_FS_UNKNOWN_FS_TYPE, NULL,
                                 _("Invalid name for FS type '%s'"),
                                 name);

    libname = apr_psprintf(pool, "libsvn_fs_%s-%d.so.%d",
                           name, SVN_VER_MAJOR, SVN_SOVERSION);
    funcname = apr_psprintf(pool, "svn_fs_%s__init", name);

    /* Find/load the specified library.  If we get an error, assume
       the library doesn't exist.  The library will be unloaded when
       pool is destroyed. */
    SVN_ERR(svn_dso_load(&dso, libname));
    if (! dso)
      return SVN_NO_ERROR;

    /* find the initialization routine */
    status = apr_dso_sym(&symbol, dso, funcname);
    if (status)
      return svn_error_wrap_apr(status, _("'%s' does not define '%s()'"),
                                libname, funcname);

    *initfunc = (fs_init_func_t) symbol;
  }
#endif /* APR_HAS_DSO */

  return SVN_NO_ERROR;
}
示例#13
0
static int
iconv_dlopen(const char *name, const char *symbol, void **hpp, void **dpp, apr_pool_t *ctx)
{
	apr_dso_handle_t *handle;
	void *data;

	/* dlopen */
	if (apr_dso_load(&handle, name, ctx) != APR_SUCCESS) {
		return EINVAL;
	}
	/* dlsym */
	if ( apr_dso_sym(&data, handle, symbol) == APR_SUCCESS) {
		*hpp = handle;
		*dpp = data;
		return 0;
	}
	apr_dso_unload(handle);
	return EINVAL;
}
示例#14
0
/** 
 * Dynamically loads the plugin and runs the plugin's init function.
 *
 * @param[in] plugin_file Name of plugin dll/dylib/so. TODO:DOC is this correct? see .h
 * @return 0 if successful, APR error code or error code from the plugin's init function on failure.
 */
int LLPluginInstance::load(std::string &plugin_file)
{
	pluginInitFunction init_function = NULL;
	
	int result = apr_dso_load(&mDSOHandle,
					  plugin_file.c_str(),
					  gAPRPoolp);
	if(result != APR_SUCCESS)
	{
		char buf[1024];
		apr_dso_error(mDSOHandle, buf, sizeof(buf));

		LL_WARNS("Plugin") << "apr_dso_load of " << plugin_file << " failed with error " << result << " , additional info string: " << buf << LL_ENDL;
		
	}
	
	if(result == APR_SUCCESS)
	{
		result = apr_dso_sym((apr_dso_handle_sym_t*)&init_function,
						 mDSOHandle,
						 PLUGIN_INIT_FUNCTION_NAME);

		if(result != APR_SUCCESS)
		{
			LL_WARNS("Plugin") << "apr_dso_sym failed with error " << result << LL_ENDL;
		}
	}
	
	if(result == APR_SUCCESS)
	{
		result = init_function(staticReceiveMessage, (void*)this, &mPluginSendMessageFunction, &mPluginUserData);

		if(result != APR_SUCCESS)
		{
			LL_WARNS("Plugin") << "call to init function failed with error " << result << LL_ENDL;
		}
	}
	
	return (int)result;
}
示例#15
0
static apt_bool_t plugin_version_load(apr_dso_handle_t *plugin)
{
	apr_dso_handle_sym_t version_handle = NULL;
	if(apr_dso_sym(&version_handle,plugin,MRCP_PLUGIN_VERSION_SYM_NAME) != APR_SUCCESS) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Version Info Found: %s", MRCP_PLUGIN_VERSION_SYM_NAME);
		return FALSE;
	}
	
	if(version_handle) {
		mrcp_plugin_version_t *version = (mrcp_plugin_version_t*)version_handle;
		if(mrcp_plugin_version_check(version)) {
			return TRUE;
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Incompatible Plugin Version Found [%d.%d.%d] < ["PLUGIN_VERSION_STRING"]",
				version->major,
				version->minor,
				version->patch);
		}
	}
	return FALSE;
}
示例#16
0
static void test_dso_sym_return_value(CuTest *tc)
{
    apr_dso_handle_t *h = NULL;
    apr_dso_handle_sym_t func1 = NULL;
    apr_status_t status;
    int (*function)(int);
    char errstr[256];

    status = apr_dso_load(&h, modname, p);
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    CuAssertPtrNotNull(tc, h);

    status = apr_dso_sym(&func1, h, "count_reps");
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    CuAssertPtrNotNull(tc, func1);

    function = (int (*)(int))func1;
    status = (*function)(5);
    CuAssertIntEquals(tc, 5, status);

    apr_dso_unload(h);
}
示例#17
0
static void test_dso_sym(CuTest *tc)
{
    apr_dso_handle_t *h = NULL;
    apr_dso_handle_sym_t func1 = NULL;
    apr_status_t status;
    void (*function)(char str[256]);
    char teststr[256];
    char errstr[256];

    status = apr_dso_load(&h, modname, p);
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    CuAssertPtrNotNull(tc, h);

    status = apr_dso_sym(&func1, h, "print_hello");
    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    CuAssertPtrNotNull(tc, func1);

    function = (void (*)(char *))func1;
    (*function)(teststr);
    CuAssertStrEquals(tc, "Hello - I'm a DSO!\n", teststr);

    apr_dso_unload(h);
}
示例#18
0
static const char *mod_websocket_conf_handler(cmd_parms *cmd, void *confv, const char *path, const char *name)
{
  websocket_config_rec *conf = (websocket_config_rec *) confv;
  char *response;

  if ((conf != NULL) && (path != NULL) && (name != NULL)) {
    apr_dso_handle_t *res_handle = NULL;
    apr_dso_handle_sym_t sym;

    if (apr_dso_load(&res_handle, ap_server_root_relative(cmd->pool, path), cmd->pool) == APR_SUCCESS) {
      if ((apr_dso_sym(&sym, res_handle, name) == APR_SUCCESS) && (sym != NULL)) {
        WebSocketPlugin *plugin = ((WS_Init)sym)();
        if ((plugin != NULL) &&
            (plugin->version == 0) &&
            (plugin->size >= sizeof(WebSocketPlugin)) &&
            (plugin->on_message != NULL)) { /* Require an on_message handler */
          conf->res_handle = res_handle;
          conf->plugin = plugin;
          apr_pool_cleanup_register(cmd->pool, conf, mod_websocket_cleanup_config, apr_pool_cleanup_null);
          response = NULL;
        } else {
          apr_dso_unload(res_handle);
          response = "Invalid response from initialization function";
        }
      } else {
        apr_dso_unload(res_handle);
        response = "Could not find initialization function in module";
      }
    } else {
      response = "Could not open WebSocket handler module";
    }
  } else {
    response = "Invalid parameters";
  }
  return response;
}
示例#19
0
static svn_error_t *
load_module(fs_init_func_t *initfunc, const char *name, apr_pool_t *pool)
{
  *initfunc = NULL;

#if defined(SVN_USE_DSO) && APR_HAS_DSO
  {
    apr_dso_handle_t *dso;
    apr_dso_handle_sym_t symbol;
    const char *libname;
    const char *funcname;
    apr_status_t status;

    libname = apr_psprintf(pool, "libsvn_fs_%s-%d.so.0",
                           name, SVN_VER_MAJOR);
    funcname = apr_psprintf(pool, "svn_fs_%s__init", name);

    /* Find/load the specified library.  If we get an error, assume
       the library doesn't exist.  The library will be unloaded when
       pool is destroyed. */
    SVN_ERR(svn_dso_load(&dso, libname));
    if (! dso)
      return SVN_NO_ERROR;

    /* find the initialization routine */
    status = apr_dso_sym(&symbol, dso, funcname);
    if (status)
      return svn_error_wrap_apr(status, _("'%s' does not define '%s()'"),
                                libname, funcname);

    *initfunc = (fs_init_func_t) symbol;
  }
#endif /* APR_HAS_DSO */

  return SVN_NO_ERROR;
}
示例#20
0
static void test_dso_sym_return_value(abts_case *tc, void *data)
{
    apr_dso_handle_t *h = NULL;
    apr_dso_handle_sym_t func1 = NULL;
    apr_status_t status;
    int (*function)(int);
    char errstr[256];

    status = apr_dso_load(&h, modname, p);
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    ABTS_PTR_NOTNULL(tc, h);

    status = apr_dso_sym(&func1, h, "count_reps");
    ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
    ABTS_PTR_NOTNULL(tc, func1);

    if (!tc->failed) {
        function = (int (*)(int))func1;
        status = (*function)(5);
        ABTS_INT_EQUAL(tc, 5, status);
    }

    apr_dso_unload(h);
}
示例#21
0
/** Register resource engine plugin */
MRCP_DECLARE(apt_bool_t) mrcp_server_plugin_register(mrcp_server_t *server, const char *path, const char *name)
{
	apr_dso_handle_t *plugin = NULL;
	apr_dso_handle_sym_t func_handle = NULL;
	apt_bool_t dso_err = FALSE;
	mrcp_plugin_creator_f plugin_creator = NULL;
	mrcp_resource_engine_t *engine;
	if(!path || !name) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Register Plugin: no name");
		return FALSE;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Register Plugin [%s] [%s]",path,name);
	if(apr_dso_load(&plugin,path,server->pool) == APR_SUCCESS) {
		if(apr_dso_sym(&func_handle,plugin,MRCP_PLUGIN_SYM_NAME) == APR_SUCCESS) {
			if(func_handle) {
				plugin_creator = (mrcp_plugin_creator_f)(intptr_t)func_handle;
			}
		}
		else {
			dso_err = TRUE;
		}
	}
	else {
		dso_err = TRUE;
	}

	if(dso_err == TRUE) {
		char derr[512] = "";
		apr_dso_error(plugin,derr,sizeof(derr));
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load DSO Symbol: %s", derr);
		apr_dso_unload(plugin);
		return FALSE;
	}

	if(!plugin_creator) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Entry Point Found for Plugin");
		apr_dso_unload(plugin);
		return FALSE;
	}

	engine = plugin_creator(server->pool);
	if(!engine) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Null Resource Engine");
		apr_dso_unload(plugin);
		return FALSE;
	}

	if(!mrcp_plugin_version_check(&engine->plugin_version)) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Incompatible Plugin Version [%d.%d.%d] < ["PLUGIN_VERSION_STRING"]",
			engine->plugin_version.major,
			engine->plugin_version.minor,
			engine->plugin_version.patch);
		apr_dso_unload(plugin);
		return FALSE;
	}

	mrcp_server_resource_engine_register(server,engine,name);
	apr_hash_set(server->plugin_table,name,APR_HASH_KEY_STRING,plugin);
	return TRUE;
}
    char *load_cpp_module( apr_pool_t *pool, server_rec *server, cpp_server_rec *server_rec, apr_hash_index_t *next)
    {
        apr_dso_handle_t *sohandle;
        apr_dso_handle_sym_t sosymbol;
	ApacheServerRec *pServer = new ApacheServerRec(server);
        cpp_factory_t *cur_handler;
	apr_ssize_t n_len;
	const void *n;
	void *p;
        char *name;
	char *path;
	apr_hash_this(next, &n, &n_len, &p);
	name = apr_pstrndup(pool, (char *)n, n_len);
        path = apr_pstrdup(pool, (char *)p);

        if ( apr_dso_load(&sohandle, path, pool) != APR_SUCCESS ) {
            char my_error[256];
            return apr_pstrcat( 
                pool, "Error Loading CPP SO ", path, " into server: ",
                apr_dso_error( sohandle, my_error, sizeof(my_error)),
                NULL);
        }

        /* Log the event */
        ap_log_perror( APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 
                       0, pool, 
                       "loaded CPP so: %s", name);

        if ( apr_dso_sym ( &sosymbol, sohandle, name) != APR_SUCCESS) {
            char my_error[256];
            return apr_pstrcat(
                pool, "Can't locate cpp_factory_t `", 
                name, "' in file ", path, ": ", 
                apr_dso_error(sohandle, my_error, sizeof(my_error)),
                NULL);
        }

        /* symbol should now be ref the factory structure with
         * the handler, input, output and protocol filters
         */
        cur_handler = (cpp_factory_t *) sosymbol;

        ApacheHandler *handler = cur_handler->handler_func ? 
            cur_handler->handler_func(pServer) : NULL;
        ApacheInputFilter *input_filter = cur_handler->input_filter_func ?
            cur_handler->input_filter_func(pServer) : NULL;
        ApacheOutputFilter *output_filter = cur_handler->output_filter_func ?
            cur_handler->output_filter_func(pServer) : NULL;
        ApacheProtocol *protocol = cur_handler->protocol_func ?
            cur_handler->protocol_func(pServer) : NULL;
        
        if( handler != NULL ) {
            apr_hash_set(server_rec->handler_hash, 
                         name, strlen(name), handler);
        }
        if( input_filter != NULL ) {
            apr_hash_set(server_rec->input_filter_hash, 
                         name, strlen(name), input_filter);
            apr_pool_cleanup_register(pool, (void *)input_filter, delete_input_filter,
                                      apr_pool_cleanup_null);
        }
        if( output_filter != NULL ) {
            apr_hash_set(server_rec->output_filter_hash, 
                         name, strlen(name), output_filter);
            apr_pool_cleanup_register(pool, (void *)output_filter, delete_output_filter,
                                      apr_pool_cleanup_null);
        }
        if( protocol != NULL ) {
            apr_hash_set(server_rec->protocol_hash, 
                         name, strlen(name), protocol);
            apr_pool_cleanup_register(pool, (void *)protocol, delete_protocol_handler,
                                      apr_pool_cleanup_null);
        }
        return NULL;
    }
示例#23
0
文件: apu_dso.c 项目: cmjonze/apr
apr_status_t apu_dso_load(apr_dso_handle_t **dlhandleptr,
                          apr_dso_handle_sym_t *dsoptr,
                          const char *module,
                          const char *modsym,
                          apr_pool_t *pool)
{
    apr_dso_handle_t *dlhandle = NULL;
    char *pathlist;
    char path[APR_PATH_MAX + 1];
    apr_array_header_t *paths;
    apr_pool_t *global;
    apr_status_t rv = APR_EDSOOPEN;
    char *eos = NULL;
    int i;

    *dsoptr = apr_hash_get(dsos, module, APR_HASH_KEY_STRING);
    if (*dsoptr) {
        return APR_EINIT;
    }

    /* The driver DSO must have exactly the same lifetime as the
     * drivers hash table; ignore the passed-in pool */
    global = apr_hash_pool_get(dsos);

    /* Retrieve our path search list or prepare for a single search */
    if ((apr_env_get(&pathlist, APR_DSOPATH, pool) != APR_SUCCESS)
          || (apr_filepath_list_split(&paths, pathlist, pool) != APR_SUCCESS))
        paths = apr_array_make(pool, 1, sizeof(char*));

#if defined(APR_DSO_LIBDIR)
    /* Always search our prefix path, but on some platforms such as
     * win32 this may be left undefined
     */
    (*((char **)apr_array_push(paths))) = APR_DSO_LIBDIR;
#endif

    for (i = 0; i < paths->nelts; ++i)
    {
#if defined(WIN32)
        /* Use win32 dso search semantics and attempt to
         * load the relative lib on the first pass.
         */
        if (!eos) {
            eos = path;
            --i;
        }
        else
#endif
        {
            eos = apr_cpystrn(path, ((char**)paths->elts)[i], sizeof(path));
            if ((eos > path) && (eos - path < sizeof(path) - 1))
                *(eos++) = '/';
        }
        apr_cpystrn(eos, module, sizeof(path) - (eos - path));

        rv = apr_dso_load(&dlhandle, path, global);
        if (dlhandleptr) {
            *dlhandleptr = dlhandle;
        }
        if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */
            break;
        }
#if defined(APR_DSO_LIBDIR)
        else if (i < paths->nelts - 1) {
#else
        else {   /* No APR_DSO_LIBDIR to skip */
#endif
             /* try with apr-APR_MAJOR_VERSION appended */
            eos = apr_cpystrn(eos,
                              "apr-" APR_STRINGIFY(APR_MAJOR_VERSION) "/",
                              sizeof(path) - (eos - path));

            apr_cpystrn(eos, module, sizeof(path) - (eos - path));

            rv = apr_dso_load(&dlhandle, path, global);
            if (dlhandleptr) {
                *dlhandleptr = dlhandle;
            }
            if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */
                break;
            }
        }
    }

    if (rv != APR_SUCCESS) /* APR_ESYMNOTFOUND */
        return rv;

    rv = apr_dso_sym(dsoptr, dlhandle, modsym);
    if (rv != APR_SUCCESS) { /* APR_ESYMNOTFOUND */
        apr_dso_unload(dlhandle);
    }
    else {
        module = apr_pstrdup(global, module);
        apr_hash_set(dsos, module, APR_HASH_KEY_STRING, *dsoptr);
    }
    return rv;
}
示例#24
0
static const char *load_module(cmd_parms *cmd, void *dummy,
                               const char *modname, const char *filename)
{
    apr_dso_handle_t *modhandle;
    apr_dso_handle_sym_t modsym;
    module *modp;
    const char *szModuleFile = ap_server_root_relative(cmd->pool, filename);
    so_server_conf *sconf;
    ap_module_symbol_t *modi;
    ap_module_symbol_t *modie;
    int i;
    const char *error;

    /* we need to setup this value for dummy to make sure that we don't try
     * to add a non-existant tree into the build when we return to
     * execute_now.
     */
    *(ap_directive_t **)dummy = NULL;

    if (!szModuleFile) {
        return apr_pstrcat(cmd->pool, "Invalid LoadModule path ",
                           filename, NULL);
    }

    /*
     * check for already existing module
     * If it already exists, we have nothing to do
     * Check both dynamically-loaded modules and statically-linked modules.
     */
    sconf = (so_server_conf *)ap_get_module_config(cmd->server->module_config,
                                                &so_module);
    modie = (ap_module_symbol_t *)sconf->loaded_modules->elts;
    for (i = 0; i < sconf->loaded_modules->nelts; i++) {
        modi = &modie[i];
        if (modi->name != NULL && strcmp(modi->name, modname) == 0) {
            ap_log_perror(APLOG_MARK, APLOG_WARNING, 0,
                          cmd->pool, "module %s is already loaded, skipping",
                          modname);
            return NULL;
        }
    }

    for (i = 0; ap_preloaded_modules[i]; i++) {
        const char *preload_name;
        apr_size_t preload_len;
        apr_size_t thismod_len;

        modp = ap_preloaded_modules[i];

        /* make sure we're comparing apples with apples
         * make sure name of preloaded module is mod_FOO.c
         * make sure name of structure being loaded is FOO_module
         */

        if (memcmp(modp->name, "mod_", 4)) {
            continue;
        }

        preload_name = modp->name + strlen("mod_");
        preload_len = strlen(preload_name) - 2;

        if (strlen(modname) <= strlen("_module")) {
            continue;
        }
        thismod_len = strlen(modname) - strlen("_module");
        if (strcmp(modname + thismod_len, "_module")) {
            continue;
        }

        if (thismod_len != preload_len) {
            continue;
        }

        if (!memcmp(modname, preload_name, preload_len)) {
            return apr_pstrcat(cmd->pool, "module ", modname,
                               " is built-in and can't be loaded",
                               NULL);
        }
    }

    modi = apr_array_push(sconf->loaded_modules);
    modi->name = modname;

    /*
     * Load the file into the Apache address space
     */
    if (apr_dso_load(&modhandle, szModuleFile, cmd->pool) != APR_SUCCESS) {
        char my_error[256];

        return apr_pstrcat(cmd->pool, "Cannot load ", szModuleFile,
                          " into server: ",
                          apr_dso_error(modhandle, my_error, sizeof(my_error)),
                          NULL);
    }
    ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, cmd->pool,
                 "loaded module %s", modname);

    /*
     * Retrieve the pointer to the module structure through the module name:
     * First with the hidden variant (prefix `AP_') and then with the plain
     * symbol name.
     */
    if (apr_dso_sym(&modsym, modhandle, modname) != APR_SUCCESS) {
        char my_error[256];

        return apr_pstrcat(cmd->pool, "Can't locate API module structure `",
                          modname, "' in file ", szModuleFile, ": ",
                          apr_dso_error(modhandle, my_error, sizeof(my_error)),
                          NULL);
    }
    modp = (module*) modsym;
    modp->dynamic_load_handle = (apr_dso_handle_t *)modhandle;
    modi->modp = modp;

    /*
     * Make sure the found module structure is really a module structure
     *
     */
    if (modp->magic != MODULE_MAGIC_COOKIE) {
        return apr_pstrcat(cmd->pool, "API module structure `", modname,
                          "' in file ", szModuleFile, " is garbled -"
                          " perhaps this is not an Apache module DSO?", NULL);
    }

    /*
     * Add this module to the Apache core structures
     */
    error = ap_add_loaded_module(modp, cmd->pool);
    if (error) {
        return error;
    }

    /*
     * Register a cleanup in the config apr_pool_t (normally pconf). When
     * we do a restart (or shutdown) this cleanup will cause the
     * shared object to be unloaded.
     */
    apr_pool_cleanup_register(cmd->pool, modi, unload_module, apr_pool_cleanup_null);

    /*
     * Finally we need to run the configuration process for the module
     */
    ap_single_module_configure(cmd->pool, cmd->server, modp);

    return NULL;
}
示例#25
0
文件: switch_apr.c 项目: gujun/sscore
SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym, switch_dso_handle_t *handle, const char *symname)
{
	return apr_dso_sym(ressym, handle, symname);
}
示例#26
0
/*
 * Initialise a HOTP authentication stack.
 *
 */
dynalogin_result_t dynalogin_init(dynalogin_session_t **session,
		apr_pool_t *pool, apr_hash_t *config)
{
	apr_status_t ret;
	dynalogin_session_t *h;
	char *ds_module_name;
	char *ds_module_filename;
	char *ds_sym_name;

	*session = NULL;

	if(oath_init() != OATH_OK)
	{
		ERRMSG("libhotp init failed");
		return DYNALOGIN_ERROR;
	}

	if(pool == NULL)
	{
		return DYNALOGIN_ERROR;
	}

	/* pool is not required, APR will create a root pool if it
	 * is NULL.
	 * Maybe we don't need a config and can run on defaults? */
	if(config == NULL)
	{
		ERRMSG("no config");
		return DYNALOGIN_ERROR;
	}

	if((h = (dynalogin_session_t *)apr_pcalloc(pool, sizeof(dynalogin_session_t)))
			== NULL)
		return DYNALOGIN_ERROR;
	h->pool = pool;

	syslog(LOG_DEBUG, "looking in %s for modules", PKGLIBDIR);

	GET_STRING_PARAM(ds_module_name, config, DYNALOGIN_PARAM_DSNAME)

	ds_module_filename = apr_psprintf(h->pool, "%s%c%s.so",
			PKGLIBDIR, DIR_SEPARATOR, ds_module_name);
	ds_sym_name = apr_psprintf(h->pool, "%s_module", ds_module_name);
	if(ds_module_filename==NULL || ds_sym_name==NULL)
		return DYNALOGIN_ERROR;

	if(apr_dso_load(&h->dso_handle,
			ds_module_filename, h->pool)!=APR_SUCCESS)
		return DYNALOGIN_ERROR;

	if(apr_dso_sym((apr_dso_handle_sym_t *)&(h->datasource), h->dso_handle, ds_sym_name)
			!=APR_SUCCESS)
	{
		apr_dso_unload(h->dso_handle);
		return DYNALOGIN_ERROR;
	}

	if(h->datasource->init != NULL)
		if(h->datasource->init(h->pool, config) != DYNALOGIN_SUCCESS)
		{
			apr_dso_unload(h->dso_handle);
			return DYNALOGIN_ERROR;
		}

	GET_INT_PARAM_DEF(h->hotp_digits, config, DYNALOGIN_PARAM_HOTP_DIGITS, DEFAULT_HOTP_DIGITS)
	GET_INT_PARAM_DEF(h->hotp_window, config, DYNALOGIN_PARAM_HOTP_WINDOW, DEFAULT_HOTP_WINDOW)

	GET_INT_PARAM_DEF(h->totp_digits, config, DYNALOGIN_PARAM_TOTP_DIGITS, DEFAULT_TOTP_DIGITS)
	GET_INT_PARAM_DEF(h->totp_window, config, DYNALOGIN_PARAM_TOTP_WINDOW, DEFAULT_TOTP_WINDOW)
	GET_INT_PARAM_DEF(h->totp_x, config, DYNALOGIN_PARAM_TOTP_X, DEFAULT_TOTP_X)
	GET_INT_PARAM_DEF(h->totp_t0, config, DYNALOGIN_PARAM_TOTP_T0, DEFAULT_TOTP_T0)

	*session = h;

	return DYNALOGIN_SUCCESS;
}
/** 
 * Dynamically loads the plugin and runs the plugin's init function.
 *
 * @param[in] plugin_file Name of plugin dll/dylib/so. TODO:DOC is this correct? see .h
 * @return 0 if successful, APR error code or error code from the plugin's init function on failure.
 */
int LLPluginInstance::load(const std::string& plugin_dir, std::string &plugin_file)
{
	pluginInitFunction init_function = NULL;
	
	if ( plugin_dir.length() )
	{
#if LL_WINDOWS
		// VWR-21275:
		// *SOME* Windows systems fail to load the Qt plugins if the current working
		// directory is not the same as the directory with the Qt DLLs in.
		// This should not cause any run time issues since we are changing the cwd for the
		// plugin shell process and not the viewer.
		// Changing back to the previous directory is not necessary since the plugin shell
		// quits once the plugin exits.
		_chdir( plugin_dir.c_str() );	
#endif
	};

#if LL_LINUX && defined(LL_STANDALONE)
    void *dso_handle = dlopen(plugin_file.c_str(), RTLD_NOW | RTLD_GLOBAL);
    int result = (!dso_handle)?APR_EDSOOPEN:apr_os_dso_handle_put(&mDSOHandle,
            dso_handle, LLAPRRootPool::get()());
#else
	int result = apr_dso_load(&mDSOHandle,
					  plugin_file.c_str(),
					  LLAPRRootPool::get()());
#endif
	if(result != APR_SUCCESS)
	{
		char buf[1024];
#if LL_LINUX && defined(LL_STANDALONE)
		if (!dso_handle)
		{
			char* error = dlerror();
			buf[0] = 0;
			if (error)
			{
				strncpy(buf, error, sizeof(buf));
			}
			buf[sizeof(buf) - 1] = 0;
		}
		else
#endif
		{
			apr_dso_error(mDSOHandle, buf, sizeof(buf));
		}

#if LL_LINUX && defined(LL_STANDALONE)
		LL_WARNS("Plugin") << "plugin load " << plugin_file << " failed with error " << result << " , additional info string: " << buf << LL_ENDL;
#else
		LL_WARNS("Plugin") << "apr_dso_load of " << plugin_file << " failed with error " << result << " , additional info string: " << buf << LL_ENDL;
#endif
	}
	
	if(result == APR_SUCCESS)
	{
		result = apr_dso_sym((apr_dso_handle_sym_t*)&init_function,
						 mDSOHandle,
						 PLUGIN_INIT_FUNCTION_NAME);

		if(result != APR_SUCCESS)
		{
			LL_WARNS("Plugin") << "apr_dso_sym failed with error " << result << LL_ENDL;
		}
	}
	
	if(result == APR_SUCCESS)
	{
		result = init_function(&LLPluginInstance::staticReceiveMessage, this, &mReceiveMessageFunction, &mPluginObject);

		if(result != 0)
		{
			LL_WARNS("Plugin") << "call to init function failed with error " << result << LL_ENDL;
		}
	}
	
	return (int)result;
}