Beispiel #1
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);
}
Beispiel #2
0
df_plugin 
dfLoadPlugin(
    df_context handle, 
    const char* name, 
    df_plugin_type type,
    df_status* status)
{
	df_context_t* context;
	apr_dso_handle_t* dso;
    apr_status_t apr_status;
    char apr_errstr[256];

	context = DF_STATIC_CAST(df_context_t*, handle);
	
	apr_status = apr_dso_load(&dso, name, context->pool);
	if(apr_status != APR_SUCCESS)
	{
	    apr_dso_error(dso, apr_errstr, 256);
		dfLogError(handle, DF_INVALID_PLUGIN, "Failed to load plugin: %s", apr_errstr);
	    return NULL;
	}

	df_plugin_t* p = dfAllocate(handle, sizeof(df_plugin_t), status);
	if(!p)
		return NULL;
			
	if(name)
		p->name = dfCreateSymbol(handle, name, strlen(name), status);
		
	p->handle = dso;
	p->context = handle;	
	p->type = type;
	return (df_plugin)p;
}
Beispiel #3
0
static const char *dso_load(cmd_parms *cmd, apr_dso_handle_t **modhandlep,
                            const char *filename, const char **used_filename)
{
    int retry = 0;
    const char *fullname = ap_server_root_relative(cmd->temp_pool, filename);
    char my_error[256];
    if (filename != NULL && ap_strchr_c(filename, '/') == NULL) {
        /* retry on error without path to use dlopen()'s search path */
        retry = 1;
    }

    if (fullname == NULL && !retry) {
        return apr_psprintf(cmd->temp_pool, "Invalid %s path %s",
                            cmd->cmd->name, filename);
    }
    *used_filename = fullname;
    if (apr_dso_load(modhandlep, fullname, cmd->pool) == APR_SUCCESS) {
        return NULL;
    }
    if (retry) {
        *used_filename = filename;
        if (apr_dso_load(modhandlep, filename, cmd->pool) == APR_SUCCESS)
            return NULL;
    }

    return apr_pstrcat(cmd->temp_pool, "Cannot load ", filename,
                        " into server: ",
                        apr_dso_error(*modhandlep, my_error, sizeof(my_error)),
                        NULL);
}
Beispiel #4
0
static const char *load_file(cmd_parms *cmd, void *dummy, const char *filename)
{
    apr_dso_handle_t *handle;
    const char *file;

    file = ap_server_root_relative(cmd->pool, filename);

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

    if (apr_dso_load(&handle, file, cmd->pool) != APR_SUCCESS) {
        char my_error[256];

        return apr_pstrcat(cmd->pool, "Cannot load ", filename,
                          " into server: ",
                          apr_dso_error(handle, my_error, sizeof(my_error)),
                          NULL);
    }

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
                 "loaded file %s", filename);

    return NULL;
}
Beispiel #5
0
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;
}
Beispiel #6
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));
}
Beispiel #7
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));
}
bool ll_apr_warn_status(apr_status_t status, apr_dso_handle_t *handle)
{
    bool result = ll_apr_warn_status(status);
    // Despite observed truncation of actual Mac dylib load errors, increasing
    // this buffer to more than MAX_STRING doesn't help: it appears that APR
    // stores the output in a fixed 255-character internal buffer. (*sigh*)
    char buf[MAX_STRING];           /* Flawfinder: ignore */
    apr_dso_error(handle, buf, sizeof(buf));
    LL_WARNS("APR") << "APR: " << buf << LL_ENDL;
    return result;
}
/** 
 * 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;
}
Beispiel #10
0
static void test_load_module(CuTest *tc)
{
    apr_dso_handle_t *h = NULL;
    apr_status_t status;
    char errstr[256];

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

    apr_dso_unload(h);
}
Beispiel #11
0
static void test_load_module(abts_case *tc, void *data)
{
    apr_dso_handle_t *h = NULL;
    apr_status_t status;
    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);

    apr_dso_unload(h);
}
Beispiel #12
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);
}
Beispiel #13
0
void lt_server_logger_print_apr_dso( int priority,
        apr_dso_handle_t * handle,
        const char * format, ... )
{
    va_list ap;
    char error[1025];
    if( priority > _logger_priority ) return;
    va_start( ap, format );
    vprintf( format, ap );
    va_end( ap );
    apr_dso_error( handle, error, 1024 );
    printf( "APR DSO ERROR: %s\n", error );
    fflush( stdout );
}
Beispiel #14
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);
}
Beispiel #15
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);
}
Beispiel #16
0
static svn_error_t *
svn_dso_load_internal(apr_dso_handle_t **dso, const char *fname)
{
  *dso = apr_hash_get(dso_cache, fname, APR_HASH_KEY_STRING);

  /* First check to see if we've been through this before...  We do this
     to avoid calling apr_dso_load multiple times for a given library,
     which would result in wasting small amounts of memory each time. */
  if (*dso == NOT_THERE)
    {
      *dso = NULL;
      return SVN_NO_ERROR;
    }

  /* If we got nothing back from the cache, try and load the library. */
  if (! *dso)
    {
      apr_status_t status = apr_dso_load(dso, fname, dso_pool);
      if (status)
        {
#ifdef SVN_DEBUG_DSO
          char buf[1024];
          fprintf(stderr,
                  "Dynamic loading of '%s' failed with the following error:\n%s\n",
                  fname,
                  apr_dso_error(*dso, buf, 1024));
#endif
          *dso = NULL;

          /* It wasn't found, so set the special "we didn't find it" value. */
          apr_hash_set(dso_cache,
                       apr_pstrdup(dso_pool, fname),
                       APR_HASH_KEY_STRING,
                       NOT_THERE);

          return SVN_NO_ERROR;
        }

      /* Stash the dso so we can use it next time. */
      apr_hash_set(dso_cache,
                   apr_pstrdup(dso_pool, fname),
                   APR_HASH_KEY_STRING,
                   *dso);
    }

  return SVN_NO_ERROR;
}
Beispiel #17
0
df_status
dfUnloadPlugin(
	df_plugin handle)
{
    apr_status_t apr_status;
    char apr_errstr[256];

	df_plugin_t* p = (df_plugin_t*)handle;
	if(!p) return DF_INVALID_PLUGIN;

	apr_status = apr_dso_unload(p->handle);
	if(apr_status != APR_SUCCESS)
	{
	    apr_dso_error(p->handle, apr_errstr, 256);
		dfLogError(p->context, DF_INVALID_PLUGIN, "Failed to load plugin: %s", apr_errstr);
	    return DF_INVALID_PLUGIN;
	}
	
	return DF_SUCCESS;
}
/** Load engine plugin */
MRCP_DECLARE(mrcp_engine_t*) mrcp_engine_loader_plugin_load(mrcp_engine_loader_t *loader, const char *path, const char *name)
{
	apr_dso_handle_t *plugin = NULL;
	mrcp_plugin_creator_f plugin_creator = NULL;
	mrcp_engine_t *engine = NULL;
	if(!path || !name) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load Plugin: invalid params");
		return NULL;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Load Plugin [%s] [%s]",path,name);
	if(apr_dso_load(&plugin,path,loader->pool) != APR_SUCCESS) {
		char derr[512] = "";
		apr_dso_error(plugin,derr,sizeof(derr));
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load DSO: %s", derr);
		return NULL;
	}

	if(plugin_version_load(plugin) != TRUE) {
		apr_dso_unload(plugin);
		return NULL;
	}

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

	plugin_logger_load(plugin);

	apr_hash_set(loader->plugins,name,APR_HASH_KEY_STRING,plugin);

	engine = plugin_creator(loader->pool);
	if(!engine) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create MRCP Engine");
	}

	return engine;
}
Beispiel #19
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;
}
Beispiel #20
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;
    }
Beispiel #22
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;
}
/** 
 * 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;
}
Beispiel #24
0
SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize)
{
	return apr_dso_error(dso, buf, bufsize);
}