Thu Dec 17 13:34:00 2009

Asterisk developer's documentation


loader.c File Reference

Module Loader. More...

#include "asterisk.h"
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/cdr.h"
#include "asterisk/enum.h"
#include "asterisk/rtp.h"
#include "asterisk/http.h"
#include "asterisk/lock.h"
#include <dlfcn.h>
#include "asterisk/md5.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Data Structures

struct  ast_module
struct  ast_module_user
struct  load_order
struct  load_order_entry
struct  loadupdate
struct  module_list
struct  module_user_list
struct  reload_classes
struct  reload_queue
struct  reload_queue_item
struct  updaters

Defines

#define RTLD_NOW   0

Functions

ast_module_user__ast_module_user_add (struct ast_module *mod, struct ast_channel *chan)
void __ast_module_user_hangup_all (struct ast_module *mod)
void __ast_module_user_remove (struct ast_module *mod, struct ast_module_user *u)
static struct load_order_entryadd_to_load_order (const char *resource, struct load_order *load_order)
int ast_load_resource (const char *resource_name)
 Load a module.
int ast_loader_register (int(*v)(void))
 Add a procedure to be run when modules have been updated.
int ast_loader_unregister (int(*v)(void))
 Remove a procedure to be run when modules are updated.
char * ast_module_helper (const char *line, const char *word, int pos, int state, int rpos, int needsreload)
 Match modules names for the Asterisk cli.
ast_moduleast_module_ref (struct ast_module *mod)
void ast_module_register (const struct ast_module_info *info)
int ast_module_reload (const char *name)
 Reload asterisk modules.
void ast_module_shutdown (void)
 Run the unload() callback for all loaded modules.
void ast_module_unref (struct ast_module *mod)
void ast_module_unregister (const struct ast_module_info *info)
void ast_process_pending_reloads (void)
 Process reload requests received during startup.
int ast_unload_resource (const char *resource_name, enum ast_module_unload_mode force)
 Unload a module.
int ast_update_module_list (int(*modentry)(const char *module, const char *description, int usecnt, const char *like), const char *like)
 Ask for a list of modules, descriptions, and use counts.
void ast_update_use_count (void)
 Notify when usecount has been changed.
static struct ast_modulefind_resource (const char *resource, int do_lock)
static unsigned int inspect_module (const struct ast_module *mod)
static int key_matches (const unsigned char *key1, const unsigned char *key2)
static struct ast_moduleload_dynamic_module (const char *resource_in, unsigned int global_symbols_only)
int load_modules (unsigned int preload_only)
static enum ast_module_load_result load_resource (const char *resource_name, unsigned int global_symbols_only)
static int printdigest (const unsigned char *d)
static void queue_reload_request (const char *module)
static int resource_name_match (const char *name1_in, const char *name2_in)
static int translate_module_name (char *oldname, char *newname)
static void unload_dynamic_module (struct ast_module *mod)
static int verify_key (const unsigned char *key)

Variables

static char buildopt_sum [33] = AST_BUILDOPT_SUM
static int do_full_reload = 0
static unsigned int embedding = 1
static unsigned char expected_key []
static ast_mutex_t reloadlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER )
ast_moduleresource_being_loaded


Detailed Description

Module Loader.

Author:
Mark Spencer <markster@digium.com>

Kevin P. Fleming <kpfleming@digium.com>

Luigi Rizzo <rizzo@icir.org>

Definition in file loader.c.


Define Documentation

#define RTLD_NOW   0

Definition at line 61 of file loader.c.

Referenced by load_dynamic_module().


Function Documentation

struct ast_module_user* __ast_module_user_add ( struct ast_module mod,
struct ast_channel chan 
)

Definition at line 184 of file loader.c.

References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, ast_module_user::entry, ast_module::usecount, and ast_module::users.

00186 {
00187    struct ast_module_user *u = ast_calloc(1, sizeof(*u));
00188 
00189    if (!u)
00190       return NULL;
00191 
00192    u->chan = chan;
00193 
00194    AST_LIST_LOCK(&mod->users);
00195    AST_LIST_INSERT_HEAD(&mod->users, u, entry);
00196    AST_LIST_UNLOCK(&mod->users);
00197 
00198    ast_atomic_fetchadd_int(&mod->usecount, +1);
00199 
00200    ast_update_use_count();
00201 
00202    return u;
00203 }

void __ast_module_user_hangup_all ( struct ast_module mod  ) 

Definition at line 216 of file loader.c.

References ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_update_use_count(), ast_module_user::chan, ast_module_user::entry, free, ast_module::usecount, and ast_module::users.

Referenced by ast_unload_resource().

00217 {
00218    struct ast_module_user *u;
00219 
00220    AST_LIST_LOCK(&mod->users);
00221    while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) {
00222       ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD);
00223       ast_atomic_fetchadd_int(&mod->usecount, -1);
00224       free(u);
00225    }
00226    AST_LIST_UNLOCK(&mod->users);
00227 
00228         ast_update_use_count();
00229 }

void __ast_module_user_remove ( struct ast_module mod,
struct ast_module_user u 
)

Definition at line 205 of file loader.c.

References ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::entry, free, ast_module::usecount, and ast_module::users.

00206 {
00207    AST_LIST_LOCK(&mod->users);
00208    AST_LIST_REMOVE(&mod->users, u, entry);
00209    AST_LIST_UNLOCK(&mod->users);
00210    ast_atomic_fetchadd_int(&mod->usecount, -1);
00211    free(u);
00212 
00213    ast_update_use_count();
00214 }

static struct load_order_entry* add_to_load_order ( const char *  resource,
struct load_order load_order 
) [static]

Definition at line 797 of file loader.c.

References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_strdup, ast_module_user::entry, load_order_entry::resource, and resource_name_match().

Referenced by load_modules().

00798 {
00799    struct load_order_entry *order;
00800 
00801    AST_LIST_TRAVERSE(load_order, order, entry) {
00802       if (!resource_name_match(order->resource, resource))
00803          return NULL;
00804    }
00805 
00806    if (!(order = ast_calloc(1, sizeof(*order))))
00807       return NULL;
00808 
00809    order->resource = ast_strdup(resource);
00810    AST_LIST_INSERT_TAIL(load_order, order, entry);
00811 
00812    return order;
00813 }

int ast_load_resource ( const char *  resource_name  ) 

Load a module.

Parameters:
resource_name The name of the module to load.
This function is run by the PBX to load the modules. It performs all loading and initilization tasks. Basically, to load a module, just give it the name of the module and it will do the rest.

Returns:
See possible enum values for ast_module_load_result.

Definition at line 781 of file loader.c.

References AST_LIST_LOCK, AST_LIST_UNLOCK, and load_resource().

Referenced by file_ok_sel(), handle_load(), handle_load_deprecated(), and reload().

00782 {
00783        AST_LIST_LOCK(&module_list);
00784        load_resource(resource_name, 0);
00785        AST_LIST_UNLOCK(&module_list);
00786 
00787        return 0;
00788 }

int ast_loader_register ( int(*)(void)  updater  ) 

Add a procedure to be run when modules have been updated.

Parameters:
updater The function to run when modules have been updated.
This function adds the given function to a linked list of functions to be run when the modules are updated.

Returns:
Zero on success and -1 on failure.

Definition at line 1031 of file loader.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_malloc.

Referenced by show_console().

01032 {
01033    struct loadupdate *tmp;
01034 
01035    if (!(tmp = ast_malloc(sizeof(*tmp))))
01036       return -1;
01037 
01038    tmp->updater = v;
01039    AST_LIST_LOCK(&updaters);
01040    AST_LIST_INSERT_HEAD(&updaters, tmp, entry);
01041    AST_LIST_UNLOCK(&updaters);
01042 
01043    return 0;
01044 }

int ast_loader_unregister ( int(*)(void)  updater  ) 

Remove a procedure to be run when modules are updated.

Parameters:
updater The updater function to unregister.
This removes the given function from the updater list.

Returns:
Zero on success, -1 on failure.

Definition at line 1046 of file loader.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and loadupdate::updater.

Referenced by exit_now().

01047 {
01048    struct loadupdate *cur;
01049 
01050    AST_LIST_LOCK(&updaters);
01051    AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) {
01052       if (cur->updater == v)  {
01053          AST_LIST_REMOVE_CURRENT(&updaters, entry);
01054          break;
01055       }
01056    }
01057    AST_LIST_TRAVERSE_SAFE_END;
01058    AST_LIST_UNLOCK(&updaters);
01059 
01060    return cur ? 0 : -1;
01061 }

char* ast_module_helper ( const char *  line,
const char *  word,
int  pos,
int  state,
int  rpos,
int  needsreload 
)

Match modules names for the Asterisk cli.

Parameters:
line Unused by this function, but this should be the line we are matching.
word The partial name to match.
pos The position the word we are completing is in.
state The possible match to return.
rpos The position we should be matching. This should be the same as pos.
needsreload This should be 1 if we need to reload this module and 0 otherwise. This function will only return modules that are reloadble if this is 1.
Returns:
A possible completion of the partial match, or NULL if no matches were found.

Definition at line 517 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_module_user::entry, ast_module::info, name, ast_module_info::reload, ast_module::resource, and strdup.

Referenced by complete_mod_2(), complete_mod_3(), complete_mod_3_nr(), complete_mod_4(), and load_module().

00518 {
00519    struct ast_module *cur;
00520    int i, which=0, l = strlen(word);
00521    char *ret = NULL;
00522 
00523    if (pos != rpos)
00524       return NULL;
00525 
00526    AST_LIST_LOCK(&module_list);
00527    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00528       if (!strncasecmp(word, cur->resource, l) &&
00529           (cur->info->reload || !needsreload) &&
00530           ++which > state) {
00531          ret = strdup(cur->resource);
00532          break;
00533       }
00534    }
00535    AST_LIST_UNLOCK(&module_list);
00536 
00537    if (!ret) {
00538       for (i=0; !ret && reload_classes[i].name; i++) {
00539          if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state)
00540             ret = strdup(reload_classes[i].name);
00541       }
00542    }
00543 
00544    return ret;
00545 }

struct ast_module* ast_module_ref ( struct ast_module mod  ) 

Definition at line 1063 of file loader.c.

References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.

Referenced by __oh323_new(), alsa_new(), ast_iax2_new(), cli_audio_convert(), cli_audio_convert_deprecated(), complete_orig(), dahdi_new(), features_new(), fn_wrapper(), gtalk_new(), handle_orig(), mgcp_new(), newpvt(), oss_new(), phone_check_exception(), phone_new(), sip_new(), and skinny_new().

01064 {
01065    ast_atomic_fetchadd_int(&mod->usecount, +1);
01066    ast_update_use_count();
01067 
01068    return mod;
01069 }

void ast_module_register ( const struct ast_module_info info  ) 

Definition at line 122 of file loader.c.

References ast_calloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, embedding, ast_module_user::entry, ast_module::info, resource_being_loaded, and ast_module::users.

00123 {
00124    struct ast_module *mod;
00125 
00126    if (embedding) {
00127       if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1)))
00128          return;
00129       strcpy(mod->resource, info->name);
00130    } else {
00131       mod = resource_being_loaded;
00132    }
00133 
00134    mod->info = info;
00135    AST_LIST_HEAD_INIT(&mod->users);
00136 
00137    /* during startup, before the loader has been initialized,
00138       there are no threads, so there is no need to take the lock
00139       on this list to manipulate it. it is also possible that it
00140       might be unsafe to use the list lock at that point... so
00141       let's avoid it altogether
00142    */
00143    if (!embedding)
00144       AST_LIST_LOCK(&module_list);
00145 
00146    /* it is paramount that the new entry be placed at the tail of
00147       the list, otherwise the code that uses dlopen() to load
00148       dynamic modules won't be able to find out if the module it
00149       just opened was registered or failed to load
00150    */
00151    AST_LIST_INSERT_TAIL(&module_list, mod, entry);
00152 
00153    if (!embedding)
00154       AST_LIST_UNLOCK(&module_list);
00155 
00156    /* give the module a copy of its own handle, for later use in registrations and the like */
00157    *((struct ast_module **) &(info->self)) = mod;
00158 }

int ast_module_reload ( const char *  name  ) 

Reload asterisk modules.

Parameters:
name the name of the module to reload
This function reloads the specified module, or if no modules are specified, it will reload all loaded modules.

Note:
Modules are reloaded using their reload() functions, not unloading them and loading them again.
Returns:
Zero if the specified module was not found, 1 if the module was found but cannot be reloaded, -1 if a reload operation is already in progress, and 2 if the specfied module was found and reloaded.

Definition at line 612 of file loader.c.

References ast_fully_booted, ast_lastreloadtime, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_mutex_trylock(), ast_mutex_unlock(), ast_verbose(), ast_module::declined, ast_module_info::description, ast_module_user::entry, ast_module::flags, ast_module::info, LOG_NOTICE, option_verbose, queue_reload_request(), ast_module_info::reload, ast_module::resource, resource_name_match(), ast_module::running, and VERBOSE_PREFIX_3.

Referenced by action_updateconfig(), ast_process_pending_reloads(), handle_reload(), handle_reload_deprecated(), and monitor_sig_flags().

00613 {
00614    struct ast_module *cur;
00615    int res = 0; /* return value. 0 = not found, others, see below */
00616    int i;
00617 
00618    /* If we aren't fully booted, we just pretend we reloaded but we queue this
00619       up to run once we are booted up. */
00620    if (!ast_fully_booted) {
00621       queue_reload_request(name);
00622       return 0;
00623    }
00624 
00625    if (ast_mutex_trylock(&reloadlock)) {
00626       ast_verbose("The previous reload command didn't finish yet\n");
00627       return -1;  /* reload already in progress */
00628    }
00629    ast_lastreloadtime = time(NULL);
00630 
00631    /* Call "predefined" reload here first */
00632    for (i = 0; reload_classes[i].name; i++) {
00633       if (!name || !strcasecmp(name, reload_classes[i].name)) {
00634          reload_classes[i].reload_fn();   /* XXX should check error ? */
00635          res = 2; /* found and reloaded */
00636       }
00637    }
00638 
00639    if (name && res) {
00640       ast_mutex_unlock(&reloadlock);
00641       return res;
00642    }
00643 
00644    AST_LIST_LOCK(&module_list);
00645    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00646       const struct ast_module_info *info = cur->info;
00647 
00648       if (name && resource_name_match(name, cur->resource))
00649          continue;
00650 
00651       if (!cur->flags.running || cur->flags.declined) {
00652          if (!name)
00653             continue;
00654          ast_log(LOG_NOTICE, "The module '%s' was not properly initialized.  "
00655             "Before reloading the module, you must run \"module load %s\" "
00656             "and fix whatever is preventing the module from being initialized.\n",
00657             name, name);
00658          res = 2; /* Don't report that the module was not found */
00659          break;
00660       }
00661 
00662       if (!info->reload) { /* cannot be reloaded */
00663          if (res < 1)   /* store result if possible */
00664             res = 1; /* 1 = no reload() method */
00665          continue;
00666       }
00667 
00668       res = 2;
00669       if (option_verbose > 2)
00670          ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", cur->resource, info->description);
00671       info->reload();
00672    }
00673    AST_LIST_UNLOCK(&module_list);
00674 
00675    ast_mutex_unlock(&reloadlock);
00676 
00677    return res;
00678 }

void ast_module_shutdown ( void   ) 

Run the unload() callback for all loaded modules.

This function should be called when Asterisk is shutting down gracefully.

Definition at line 431 of file loader.c.

References AST_LIST_HEAD_DESTROY, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_module_user::entry, free, ast_module::info, ast_module_info::unload, and ast_module::users.

Referenced by quit_handler().

00432 {
00433    struct ast_module *mod;
00434    AST_LIST_HEAD_NOLOCK_STATIC(local_module_list, ast_module);
00435 
00436    /* We have to call the unload() callbacks in reverse order that the modules
00437     * exist in the module list so it is the reverse order of how they were
00438     * loaded. */
00439 
00440    AST_LIST_LOCK(&module_list);
00441    while ((mod = AST_LIST_REMOVE_HEAD(&module_list, entry)))
00442       AST_LIST_INSERT_HEAD(&local_module_list, mod, entry);
00443    AST_LIST_UNLOCK(&module_list);
00444 
00445    while ((mod = AST_LIST_REMOVE_HEAD(&local_module_list, entry))) {
00446       if (mod->info->unload)
00447          mod->info->unload();
00448       /* Since this should only be called when shutting down "gracefully",
00449        * all channels should be down before we get to this point, meaning
00450        * there will be no module users left. */
00451       AST_LIST_HEAD_DESTROY(&mod->users);
00452       free(mod);
00453    }
00454 }

void ast_module_unref ( struct ast_module mod  ) 

Definition at line 1071 of file loader.c.

References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.

Referenced by alsa_hangup(), ast_smdi_interface_destroy(), cli_audio_convert(), cli_audio_convert_deprecated(), complete_orig(), dahdi_destroy_channel_bynum(), dahdi_hangup(), destroy(), filestream_destructor(), gtalk_hangup(), handle_orig(), iax2_predestroy(), mgcp_hangup(), oh323_hangup(), oss_hangup(), phone_check_exception(), phone_hangup(), and sip_hangup().

01072 {
01073    ast_atomic_fetchadd_int(&mod->usecount, -1);
01074    ast_update_use_count();
01075 }

void ast_module_unregister ( const struct ast_module_info info  ) 

Definition at line 160 of file loader.c.

References AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_module_user::entry, free, ast_module::info, and ast_module::users.

00161 {
00162    struct ast_module *mod = NULL;
00163 
00164    /* it is assumed that the users list in the module structure
00165       will already be empty, or we cannot have gotten to this
00166       point
00167    */
00168    AST_LIST_LOCK(&module_list);
00169    AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
00170       if (mod->info == info) {
00171          AST_LIST_REMOVE_CURRENT(&module_list, entry);
00172          break;
00173       }
00174    }
00175    AST_LIST_TRAVERSE_SAFE_END;
00176    AST_LIST_UNLOCK(&module_list);
00177 
00178    if (mod) {
00179       AST_LIST_HEAD_DESTROY(&mod->users);
00180       free(mod);
00181    }
00182 }

void ast_process_pending_reloads ( void   ) 

Process reload requests received during startup.

This function requests that the loader execute the pending reload requests that were queued during server startup.

Note:
This function will do nothing if the server has not completely started up. Once called, the reload queue is emptied, and further invocations will have no affect.

Definition at line 547 of file loader.c.

References ast_free, ast_fully_booted, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_module_reload(), do_full_reload, ast_module_user::entry, LOG_NOTICE, and reload_queue_item::module.

Referenced by main().

00548 {
00549    struct reload_queue_item *item;
00550 
00551    if (!ast_fully_booted) {
00552       return;
00553    }
00554 
00555    AST_LIST_LOCK(&reload_queue);
00556 
00557    if (do_full_reload) {
00558       do_full_reload = 0;
00559       AST_LIST_UNLOCK(&reload_queue);
00560       ast_log(LOG_NOTICE, "Executing deferred reload request.\n");
00561       ast_module_reload(NULL);
00562       return;
00563    }
00564 
00565    while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) {
00566       ast_log(LOG_NOTICE, "Executing deferred reload request for module '%s'.\n", item->module);
00567       ast_module_reload(item->module);
00568       ast_free(item);
00569    }
00570 
00571    AST_LIST_UNLOCK(&reload_queue);
00572 }

int ast_unload_resource ( const char *  resource_name,
enum  ast_module_unload_mode 
)

Unload a module.

Parameters:
resource_name The name of the module to unload.
ast_module_unload_mode The force flag. This should be set using one of the AST_FORCE flags.
This function unloads a module. It will only unload modules that are not in use (usecount not zero), unless AST_FORCE_FIRM or AST_FORCE_HARD is specified. Setting AST_FORCE_FIRM or AST_FORCE_HARD will unload the module regardless of consequences (NOT RECOMMENDED).

Returns:
Zero on success, -1 on error.

Definition at line 456 of file loader.c.

References __ast_module_user_hangup_all(), AST_FORCE_FIRM, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_update_use_count(), ast_module::declined, find_resource(), ast_module::flags, ast_module::lib, LOG_WARNING, ast_module::running, unload_dynamic_module(), and ast_module::usecount.

Referenced by exit_now(), handle_unload(), handle_unload_deprecated(), reload(), and remove_module().

00457 {
00458    struct ast_module *mod;
00459    int res = -1;
00460    int error = 0;
00461 
00462    AST_LIST_LOCK(&module_list);
00463 
00464    if (!(mod = find_resource(resource_name, 0))) {
00465       AST_LIST_UNLOCK(&module_list);
00466       return 0;
00467    }
00468 
00469    if (!(mod->flags.running || mod->flags.declined))
00470       error = 1;
00471 
00472    if (!mod->lib) {
00473       ast_log(LOG_WARNING, "Unloading embedded modules is not supported.\n");
00474       error = 1;
00475    }
00476 
00477    if (!error && (mod->usecount > 0)) {
00478       if (force)
00479          ast_log(LOG_WARNING, "Warning:  Forcing removal of module '%s' with use count %d\n",
00480             resource_name, mod->usecount);
00481       else {
00482          ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name,
00483             mod->usecount);
00484          error = 1;
00485       }
00486    }
00487 
00488    if (!error) {
00489       __ast_module_user_hangup_all(mod);
00490       res = mod->info->unload();
00491 
00492       if (res) {
00493          ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
00494          if (force <= AST_FORCE_FIRM)
00495             error = 1;
00496          else
00497             ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
00498       }
00499    }
00500 
00501    if (!error)
00502       mod->flags.running = mod->flags.declined = 0;
00503 
00504    AST_LIST_UNLOCK(&module_list);
00505 
00506 #ifdef LOADABLE_MODULES
00507    if (!error)
00508       unload_dynamic_module(mod);
00509 #endif
00510 
00511    if (!error)
00512       ast_update_use_count();
00513 
00514    return res;
00515 }

int ast_update_module_list ( int(*)(const char *module, const char *description, int usecnt, const char *like)  modentry,
const char *  like 
)

Ask for a list of modules, descriptions, and use counts.

Parameters:
modentry A callback to an updater function.
like For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module.
Returns:
the number of modules loaded

Definition at line 1011 of file loader.c.

References AST_LIST_TRAVERSE, AST_LIST_TRYLOCK, AST_LIST_UNLOCK, ast_module_info::description, ast_module::info, ast_module::resource, and ast_module::usecount.

Referenced by handle_modlist(), and mod_update().

01013 {
01014    struct ast_module *cur;
01015    int unlock = -1;
01016    int total_mod_loaded = 0;
01017 
01018    if (AST_LIST_TRYLOCK(&module_list))
01019       unlock = 0;
01020 
01021    AST_LIST_TRAVERSE(&module_list, cur, entry) {
01022       total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like);
01023    }
01024 
01025    if (unlock)
01026       AST_LIST_UNLOCK(&module_list);
01027 
01028    return total_mod_loaded;
01029 }

void ast_update_use_count ( void   ) 

Notify when usecount has been changed.

This function calulates use counts and notifies anyone trying to keep track of them. It should be called whenever your module's usecount changes.

Note:
The LOCAL_USER macros take care of calling this function for you.

Definition at line 999 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.

Referenced by __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), agent_new(), ast_module_ref(), ast_module_unref(), ast_unload_resource(), exit_now(), load_module(), load_resource(), oh323_request(), sip_request_call(), and sipsock_read().

01000 {
01001    /* Notify any module monitors that the use count for a
01002       resource has changed */
01003    struct loadupdate *m;
01004 
01005    AST_LIST_LOCK(&updaters);
01006    AST_LIST_TRAVERSE(&updaters, m, entry)
01007       m->updater();
01008    AST_LIST_UNLOCK(&updaters);
01009 }

static struct ast_module* find_resource ( const char *  resource,
int  do_lock 
) [static]

Definition at line 311 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_module_user::entry, ast_module::resource, and resource_name_match().

Referenced by ast_unload_resource(), and load_resource().

00312 {
00313    struct ast_module *cur;
00314 
00315    if (do_lock)
00316       AST_LIST_LOCK(&module_list);
00317 
00318    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00319       if (!resource_name_match(resource, cur->resource))
00320          break;
00321    }
00322 
00323    if (do_lock)
00324       AST_LIST_UNLOCK(&module_list);
00325 
00326    return cur;
00327 }

static unsigned int inspect_module ( const struct ast_module mod  )  [static]

Definition at line 680 of file loader.c.

References ast_log(), AST_MODFLAG_BUILDSUM, ast_strlen_zero(), ast_test_flag, buildopt_sum, ast_module_info::buildopt_sum, ast_module_info::description, ast_module::info, ast_module_info::key, LOG_WARNING, ast_module::resource, and verify_key().

Referenced by load_resource().

00681 {
00682    if (!mod->info->description) {
00683       ast_log(LOG_WARNING, "Module '%s' does not provide a description.\n", mod->resource);
00684       return 1;
00685    }
00686 
00687    if (!mod->info->key) {
00688       ast_log(LOG_WARNING, "Module '%s' does not provide a license key.\n", mod->resource);
00689       return 1;
00690    }
00691 
00692    if (verify_key((unsigned char *) mod->info->key)) {
00693       ast_log(LOG_WARNING, "Module '%s' did not provide a valid license key.\n", mod->resource);
00694       return 1;
00695    }
00696 
00697    if (!ast_test_flag(mod->info, AST_MODFLAG_BUILDSUM)) {
00698       ast_log(LOG_WARNING, "Module '%s' was not compiled against a recent version of Asterisk and may cause instability.\n", mod->resource);
00699    } else if (!ast_strlen_zero(mod->info->buildopt_sum) &&
00700          strcmp(buildopt_sum, mod->info->buildopt_sum)) {
00701       ast_log(LOG_WARNING, "Module '%s' was not compiled with the same compile-time options as this version of Asterisk.\n", mod->resource);
00702       ast_log(LOG_WARNING, "Module '%s' will not be initialized as it may cause instability.\n", mod->resource);
00703       return 1;
00704    }
00705 
00706    return 0;
00707 }

static int key_matches ( const unsigned char *  key1,
const unsigned char *  key2 
) [static]

Definition at line 264 of file loader.c.

Referenced by verify_key().

00265 {
00266    int x;
00267 
00268    for (x = 0; x < 16; x++) {
00269       if (key1[x] != key2[x])
00270          return 0;
00271    }
00272 
00273    return 1;
00274 }

static struct ast_module* load_dynamic_module ( const char *  resource_in,
unsigned int  global_symbols_only 
) [static]

Definition at line 342 of file loader.c.

References ast_calloc, ast_config_AST_MODULE_DIR, AST_LIST_LAST, ast_log(), AST_MODFLAG_GLOBAL_SYMBOLS, ast_test_flag, free, ast_module::info, ast_module::lib, LOG_WARNING, resource_being_loaded, and RTLD_NOW.

Referenced by load_resource().

00343 {
00344    char fn[256];
00345    void *lib;
00346    struct ast_module *mod;
00347    char *resource = (char *) resource_in;
00348    unsigned int wants_global;
00349 
00350    if (strcasecmp(resource + strlen(resource) - 3, ".so")) {
00351       resource = alloca(strlen(resource_in) + 3);
00352            strcpy(resource, resource_in);
00353       strcat(resource, ".so");
00354    }
00355 
00356    snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_MODULE_DIR, resource);
00357 
00358    /* make a first load of the module in 'quiet' mode... don't try to resolve
00359       any symbols, and don't export any symbols. this will allow us to peek into
00360       the module's info block (if available) to see what flags it has set */
00361 
00362    if (!(resource_being_loaded = ast_calloc(1, sizeof(*resource_being_loaded) + strlen(resource) + 1)))
00363       return NULL;
00364 
00365    strcpy(resource_being_loaded->resource, resource);
00366 
00367    /* libopenh323 is buggy and segfaults on dlclose() when opened with
00368     * RTLD_LAZY. Workaround this until it gets fixed */
00369    if (!strcasecmp(resource, "chan_h323.so") ||
00370          !strcasecmp(resource, "chan_oh323.so"))
00371          lib = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
00372 
00373    if (!(lib = dlopen(fn, RTLD_LAZY | RTLD_LOCAL))) {
00374       ast_log(LOG_WARNING, "Error loading module '%s': %s\n", resource_in, dlerror());
00375       free(resource_being_loaded);
00376       return NULL;
00377    }
00378 
00379    /* the dlopen() succeeded, let's find out if the module
00380       registered itself */
00381    /* note that this will only work properly as long as
00382       ast_module_register() (which is called by the module's
00383       constructor) places the new module at the tail of the
00384       module_list
00385    */
00386    if (resource_being_loaded != (mod = AST_LIST_LAST(&module_list))) {
00387       ast_log(LOG_WARNING, "Module '%s' did not register itself during load\n", resource_in);
00388       /* no, it did not, so close it and return */
00389       while (!dlclose(lib));
00390       /* note that the module's destructor will call ast_module_unregister(),
00391          which will free the structure we allocated in resource_being_loaded */
00392       return NULL;
00393    }
00394 
00395    wants_global = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);
00396 
00397    /* if we are being asked only to load modules that provide global symbols,
00398       and this one does not, then close it and return */
00399    if (global_symbols_only && !wants_global) {
00400       while (!dlclose(lib));
00401       return NULL;
00402    }
00403 
00404    while (!dlclose(lib));
00405    resource_being_loaded = NULL;
00406 
00407    /* start the load process again */
00408 
00409    if (!(resource_being_loaded = ast_calloc(1, sizeof(*resource_being_loaded) + strlen(resource) + 1)))
00410       return NULL;
00411 
00412    strcpy(resource_being_loaded->resource, resource);
00413 
00414    if (!(lib = dlopen(fn, wants_global ? RTLD_LAZY | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL))) {
00415       ast_log(LOG_WARNING, "Error loading module '%s': %s\n", resource_in, dlerror());
00416       free(resource_being_loaded);
00417       return NULL;
00418    }
00419 
00420    /* since the module was successfully opened, and it registered itself
00421       the previous time we did that, we're going to assume it worked this
00422       time too :) */
00423 
00424    AST_LIST_LAST(&module_list)->lib = lib;
00425    resource_being_loaded = NULL;
00426 
00427    return AST_LIST_LAST(&module_list);
00428 }

int load_modules ( unsigned  int  ) 

Provided by loader.c

Definition at line 832 of file loader.c.

References add_to_load_order(), ast_config_load(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, ast_log(), AST_MODULE_CONFIG, ast_variable_browse(), ast_verbose(), embedding, LOG_WARNING, ast_variable::name, ast_variable::next, option_verbose, translate_module_name(), and ast_variable::value.

Referenced by main().

00833 {
00834    struct ast_config *cfg;
00835    struct ast_module *mod;
00836    struct load_order_entry *order;
00837    struct ast_variable *v;
00838    unsigned int load_count;
00839    struct load_order load_order;
00840    int res = 0;
00841 
00842    int translate_status;
00843    char newname[18]; /* although this would normally be 80, max length in translate_module_name is 18 */
00844 #ifdef LOADABLE_MODULES
00845    struct dirent *dirent;
00846    DIR *dir;
00847 #endif
00848 
00849    /* all embedded modules have registered themselves by now */
00850    embedding = 0;
00851 
00852    if (option_verbose)
00853       ast_verbose("Asterisk Dynamic Loader Starting:\n");
00854 
00855    AST_LIST_HEAD_INIT_NOLOCK(&load_order);
00856 
00857    AST_LIST_LOCK(&module_list);
00858 
00859    if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
00860       ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
00861       goto done;
00862    }
00863 
00864    /* first, find all the modules we have been explicitly requested to load */
00865    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00866       if (!strcasecmp(v->name, preload_only ? "preload" : "load")) {
00867          translate_status = translate_module_name(v->value, newname);
00868             if (!translate_status)
00869                ast_log(LOG_WARNING, "Use of old module name %s is deprecated, please use %s instead.\n", v->value, newname);
00870          add_to_load_order(translate_status ? v->value : newname, &load_order);
00871       }
00872    }
00873 
00874    /* check if 'autoload' is on */
00875    if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
00876       /* if so, first add all the embedded modules that are not already running to the load order */
00877       AST_LIST_TRAVERSE(&module_list, mod, entry) {
00878          /* if it's not embedded, skip it */
00879          if (mod->lib)
00880             continue;
00881 
00882          if (mod->flags.running)
00883             continue;
00884 
00885          order = add_to_load_order(mod->resource, &load_order);
00886       }
00887 
00888 #ifdef LOADABLE_MODULES
00889       /* if we are allowed to load dynamic modules, scan the directory for
00890          for all available modules and add them as well */
00891       if ((dir  = opendir(ast_config_AST_MODULE_DIR))) {
00892          while ((dirent = readdir(dir))) {
00893             int ld = strlen(dirent->d_name);
00894 
00895             /* Must end in .so to load it.  */
00896 
00897             if (ld < 4)
00898                continue;
00899 
00900             if (strcasecmp(dirent->d_name + ld - 3, ".so"))
00901                continue;
00902 
00903             /* if there is already a module by this name in the module_list,
00904                skip this file */
00905             if (find_resource(dirent->d_name, 0))
00906                continue;
00907 
00908             add_to_load_order(dirent->d_name, &load_order);
00909          }
00910 
00911          closedir(dir);
00912       } else {
00913          if (!ast_opt_quiet)
00914             ast_log(LOG_WARNING, "Unable to open modules directory '%s'.\n",
00915                ast_config_AST_MODULE_DIR);
00916       }
00917 #endif
00918    }
00919 
00920    /* now scan the config for any modules we are prohibited from loading and
00921       remove them from the load order */
00922    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00923       if (strcasecmp(v->name, "noload"))
00924          continue;
00925 
00926       AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00927          translate_status = translate_module_name(v->value, newname);
00928          if (!resource_name_match(order->resource, translate_status ? v->value : newname)) {
00929                if (!translate_status)
00930                   ast_log(LOG_WARNING, "Use of old module name %s is deprecated, please use %s instead.\n", v->value, newname);
00931             AST_LIST_REMOVE_CURRENT(&load_order, entry);
00932             free(order->resource);
00933             free(order);
00934          }
00935       }
00936       AST_LIST_TRAVERSE_SAFE_END;
00937    }
00938 
00939    /* we are done with the config now, all the information we need is in the
00940       load_order list */
00941    ast_config_destroy(cfg);
00942 
00943    load_count = 0;
00944    AST_LIST_TRAVERSE(&load_order, order, entry)
00945       load_count++;
00946 
00947    if (load_count)
00948       ast_log(LOG_NOTICE, "%d modules will be loaded.\n", load_count);
00949 
00950    /* first, load only modules that provide global symbols */
00951    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00952       switch (load_resource(order->resource, 1)) {
00953       case AST_MODULE_LOAD_SUCCESS:
00954       case AST_MODULE_LOAD_DECLINE:
00955          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00956          free(order->resource);
00957          free(order);
00958          break;
00959       case AST_MODULE_LOAD_FAILURE:
00960          res = -1;
00961          goto done;
00962       case AST_MODULE_LOAD_SKIP:
00963          /* try again later */
00964          break;
00965       }
00966    }
00967    AST_LIST_TRAVERSE_SAFE_END;
00968 
00969    /* now load everything else */
00970    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00971       switch (load_resource(order->resource, 0)) {
00972       case AST_MODULE_LOAD_SUCCESS:
00973       case AST_MODULE_LOAD_DECLINE:
00974          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00975          free(order->resource);
00976          free(order);
00977          break;
00978       case AST_MODULE_LOAD_FAILURE:
00979          res = -1;
00980          goto done;
00981       case AST_MODULE_LOAD_SKIP:
00982          /* should not happen */
00983          break;
00984       }
00985    }
00986    AST_LIST_TRAVERSE_SAFE_END;
00987 
00988 done:
00989    while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) {
00990       free(order->resource);
00991       free(order);
00992    }
00993 
00994    AST_LIST_UNLOCK(&module_list);
00995 
00996    return res;
00997 }

static enum ast_module_load_result load_resource ( const char *  resource_name,
unsigned int  global_symbols_only 
) [static]

Definition at line 709 of file loader.c.

References ast_fully_booted, ast_log(), AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SKIP, AST_MODULE_LOAD_SUCCESS, ast_opt_console, ast_test_flag, ast_update_use_count(), ast_verbose(), COLOR_BLACK, COLOR_BROWN, ast_module::declined, ast_module_info::description, find_resource(), ast_module::flags, ast_module::info, inspect_module(), ast_module_info::load, load_dynamic_module(), LOG_WARNING, option_verbose, ast_module::running, term_color(), unload_dynamic_module(), and VERBOSE_PREFIX_1.

Referenced by ast_load_resource().

00710 {
00711    struct ast_module *mod;
00712    enum ast_module_load_result res = AST_MODULE_LOAD_SUCCESS;
00713    char tmp[256];
00714 
00715    if ((mod = find_resource(resource_name, 0))) {
00716       if (mod->flags.running) {
00717          ast_log(LOG_WARNING, "Module '%s' already exists.\n", resource_name);
00718          return AST_MODULE_LOAD_DECLINE;
00719       }
00720       if (global_symbols_only && !ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS))
00721          return AST_MODULE_LOAD_SKIP;
00722    } else {
00723 #ifdef LOADABLE_MODULES
00724       if (!(mod = load_dynamic_module(resource_name, global_symbols_only))) {
00725          /* don't generate a warning message during load_modules() */
00726          if (!global_symbols_only) {
00727             ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);
00728             return AST_MODULE_LOAD_DECLINE;
00729          } else {
00730             return AST_MODULE_LOAD_SKIP;
00731          }
00732       }
00733 #else
00734       ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);
00735       return AST_MODULE_LOAD_DECLINE;
00736 #endif
00737    }
00738 
00739    if (inspect_module(mod)) {
00740       ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);
00741 #ifdef LOADABLE_MODULES
00742       unload_dynamic_module(mod);
00743 #endif
00744       return AST_MODULE_LOAD_DECLINE;
00745    }
00746 
00747    mod->flags.declined = 0;
00748 
00749    if (mod->info->load)
00750       res = mod->info->load();
00751 
00752    switch (res) {
00753    case AST_MODULE_LOAD_SUCCESS:
00754       if (!ast_fully_booted) {
00755          if (option_verbose)
00756             ast_verbose("%s => (%s)\n", resource_name, term_color(tmp, mod->info->description, COLOR_BROWN, COLOR_BLACK, sizeof(tmp)));
00757          if (ast_opt_console && !option_verbose)
00758             ast_verbose( ".");
00759       } else {
00760          if (option_verbose)
00761             ast_verbose(VERBOSE_PREFIX_1 "Loaded %s => (%s)\n", resource_name, mod->info->description);
00762       }
00763 
00764       mod->flags.running = 1;
00765 
00766       ast_update_use_count();
00767       break;
00768    case AST_MODULE_LOAD_DECLINE:
00769       mod->flags.declined = 1;
00770       break;
00771    case AST_MODULE_LOAD_FAILURE:
00772       break;
00773    case AST_MODULE_LOAD_SKIP:
00774       /* modules should never return this value */
00775       break;
00776    }
00777 
00778    return res;
00779 }

static int printdigest ( const unsigned char *  d  )  [static]

Definition at line 251 of file loader.c.

References ast_log(), and LOG_DEBUG.

Referenced by verify_key().

00252 {
00253    int x, pos;
00254    char buf[256]; /* large enough so we don't have to worry */
00255 
00256    for (pos = 0, x = 0; x < 16; x++)
00257       pos += sprintf(buf + pos, " %02x", *d++);
00258 
00259    ast_log(LOG_DEBUG, "Unexpected signature:%s\n", buf);
00260 
00261    return 0;
00262 }

static void queue_reload_request ( const char *  module  )  [static]

Definition at line 574 of file loader.c.

References ast_calloc, ast_free, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), do_full_reload, ast_module_user::entry, LOG_ERROR, and reload_queue_item::module.

Referenced by ast_module_reload().

00575 {
00576    struct reload_queue_item *item;
00577 
00578    AST_LIST_LOCK(&reload_queue);
00579 
00580    if (do_full_reload) {
00581       AST_LIST_UNLOCK(&reload_queue);
00582       return;
00583    }
00584 
00585    if (ast_strlen_zero(module)) {
00586       /* A full reload request (when module is NULL) wipes out any previous
00587          reload requests and causes the queue to ignore future ones */
00588       while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) {
00589          ast_free(item);
00590       }
00591       do_full_reload = 1;
00592    } else {
00593       /* No reason to add the same module twice */
00594       AST_LIST_TRAVERSE(&reload_queue, item, entry) {
00595          if (!strcasecmp(item->module, module)) {
00596             AST_LIST_UNLOCK(&reload_queue);
00597             return;
00598          }
00599       }
00600       item = ast_calloc(1, sizeof(*item) + strlen(module) + 1);
00601       if (!item) {
00602          ast_log(LOG_ERROR, "Failed to allocate reload queue item.\n");
00603          AST_LIST_UNLOCK(&reload_queue);
00604          return;
00605       }
00606       strcpy(item->module, module);
00607       AST_LIST_INSERT_TAIL(&reload_queue, item, entry);
00608    }
00609    AST_LIST_UNLOCK(&reload_queue);
00610 }

static int resource_name_match ( const char *  name1_in,
const char *  name2_in 
) [static]

Definition at line 293 of file loader.c.

References ast_strdupa.

Referenced by add_to_load_order(), ast_module_reload(), and find_resource().

00294 {
00295    char *name1 = (char *) name1_in;
00296    char *name2 = (char *) name2_in;
00297 
00298    /* trim off any .so extensions */
00299    if (!strcasecmp(name1 + strlen(name1) - 3, ".so")) {
00300       name1 = ast_strdupa(name1);
00301       name1[strlen(name1) - 3] = '\0';
00302    }
00303    if (!strcasecmp(name2 + strlen(name2) - 3, ".so")) {
00304       name2 = ast_strdupa(name2);
00305       name2[strlen(name2) - 3] = '\0';
00306    }
00307 
00308    return strcasecmp(name1, name2);
00309 }

static int translate_module_name ( char *  oldname,
char *  newname 
) [static]

Definition at line 815 of file loader.c.

References ast_copy_string().

Referenced by load_modules().

00816 {
00817    if (!strcasecmp(oldname, "app_zapbarge.so"))
00818       ast_copy_string(newname, "app_dahdibarge.so", 18);
00819    else if(!strcasecmp(oldname, "app_zapras.so"))
00820       ast_copy_string(newname, "app_dahdiras.so", 16);
00821    else if(!strcasecmp(oldname, "app_zapscan.so"))
00822       ast_copy_string(newname, "app_dahdiscan.so", 17);
00823    else if(!strcasecmp(oldname, "codec_zap.so"))
00824       ast_copy_string(newname, "codec_dahdi.so", 16);
00825    else
00826       return -1; /* no use for newname, oldname is fine */
00827 
00828    return 0;
00829 }

static void unload_dynamic_module ( struct ast_module mod  )  [static]

Definition at line 330 of file loader.c.

References ast_module::lib.

Referenced by ast_unload_resource(), and load_resource().

00331 {
00332    void *lib = mod->lib;
00333 
00334    /* WARNING: the structure pointed to by mod is going to
00335       disappear when this operation succeeds, so we can't
00336       dereference it */
00337 
00338    if (lib)
00339       while (!dlclose(lib));
00340 }

static int verify_key ( const unsigned char *  key  )  [static]

Definition at line 276 of file loader.c.

References expected_key, key_matches(), MD5Final(), MD5Init(), MD5Update(), and printdigest().

Referenced by inspect_module().

00277 {
00278    struct MD5Context c;
00279    unsigned char digest[16];
00280 
00281    MD5Init(&c);
00282    MD5Update(&c, key, strlen((char *)key));
00283    MD5Final(digest, &c);
00284 
00285    if (key_matches(expected_key, digest))
00286       return 0;
00287 
00288    printdigest(digest);
00289 
00290    return -1;
00291 }


Variable Documentation

char buildopt_sum[33] = AST_BUILDOPT_SUM [static]

Definition at line 75 of file loader.c.

Referenced by inspect_module().

int do_full_reload = 0 [static]

Definition at line 110 of file loader.c.

Referenced by ast_process_pending_reloads(), and queue_reload_request().

unsigned int embedding = 1 [static]

Definition at line 77 of file loader.c.

Referenced by ast_module_register(), and load_modules().

unsigned char expected_key[] [static]

Initial value:

{ 0x87, 0x76, 0x79, 0x35, 0x23, 0xea, 0x3a, 0xd3,
  0x25, 0x2a, 0xbb, 0x35, 0x87, 0xe4, 0x22, 0x24 }

Definition at line 71 of file loader.c.

Referenced by verify_key().

ast_mutex_t reloadlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static]

Definition at line 103 of file loader.c.

struct ast_module* resource_being_loaded

Definition at line 118 of file loader.c.

Referenced by ast_module_register(), and load_dynamic_module().


Generated on Thu Dec 17 13:34:01 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7