Wed Oct 28 11:51:09 2009

Asterisk developer's documentation


_private.h File Reference

Prototypes for public functions only of internal interest,. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ast_autoservice_init (void)
void ast_builtins_init (void)
 initialize the _full_cmd string in * each of the builtins.
void ast_channels_init (void)
int ast_device_state_engine_init (void)
 Initialize the device state engine in separate thread.
int ast_event_init (void)
int ast_features_init (void)
int ast_file_init (void)
int ast_http_init (void)
int ast_http_reload (void)
int ast_module_reload (const char *name)
 Reload asterisk modules.
void ast_process_pending_reloads (void)
 Process reload requests received during startup.
int ast_ssl_init (void)
int ast_term_init (void)
int ast_timing_init (void)
int ast_tps_init (void)
int astdb_init (void)
int astobj2_init (void)
void close_logger (void)
int dnsmgr_init (void)
int dnsmgr_reload (void)
void dnsmgr_start_refresh (void)
int init_framer (void)
int init_logger (void)
int load_modules (unsigned int)
int load_pbx (void)
void threadstorage_init (void)


Detailed Description

Prototypes for public functions only of internal interest,.

Definition in file _private.h.


Function Documentation

void ast_autoservice_init ( void   ) 

Provided by autoservice.c

Definition at line 318 of file autoservice.c.

References as_cond, and ast_cond_init().

Referenced by main().

00319 {
00320    ast_cond_init(&as_cond, NULL);
00321 }

void ast_builtins_init ( void   ) 

initialize the _full_cmd string in * each of the builtins.

Provided by cli.c

Definition at line 1251 of file cli.c.

References ast_cli_register_multiple(), and cli_cli.

Referenced by main().

01252 {
01253    ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry));
01254 }

void ast_channels_init ( void   ) 

Provided by channel.c

Definition at line 5479 of file channel.c.

References ARRAY_LEN, ast_cli_register_multiple(), and cli_channel.

Referenced by main().

int ast_device_state_engine_init ( void   ) 

Initialize the device state engine in separate thread.

Provided by devicestate.c

Definition at line 748 of file devicestate.c.

References ast_cond_init(), ast_log(), ast_pthread_create_background, change_thread, do_devstate_changes(), and LOG_ERROR.

Referenced by main().

00749 {
00750    ast_cond_init(&change_pending, NULL);
00751    if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
00752       ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
00753       return -1;
00754    }
00755 
00756    return 0;
00757 }

int ast_event_init ( void   ) 

Provided by event.c

Definition at line 1288 of file event.c.

References ao2_container_alloc, ast_event_cache, ast_event_cmp(), ast_event_hash(), ast_event_subs, AST_RWDLLIST_HEAD_INIT, ast_taskprocessor_get(), container, hash_fn, and NUM_CACHE_BUCKETS.

Referenced by main().

01289 {
01290    int i;
01291 
01292    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01293       AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
01294    }
01295 
01296    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01297       if (!ast_event_cache[i].hash_fn) {
01298          /* This event type is not cached. */
01299          continue;
01300       }
01301 
01302       if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
01303             ast_event_hash, ast_event_cmp))) {
01304          return -1;
01305       }
01306    }
01307 
01308    if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
01309       return -1;
01310    }
01311 
01312    return 0;
01313 }

int ast_features_init ( void   ) 

Provided by features.c

Definition at line 4578 of file features.c.

References action_bridge(), ao2_container_alloc, ast_cli_register_multiple(), ast_devstate_prov_add(), ast_manager_register, ast_manager_register2(), ast_pthread_create, ast_register_application2(), bridge_exec(), descrip, descrip2, do_parking_thread(), EVENT_FLAG_CALL, load_config(), manager_park(), manager_parking_status(), metermaidstate(), park_call_exec(), park_exec(), parkcall, parkedcall, parking_thread, parkinglot_cmp_cb(), parkinglot_hash_cb(), parkinglots, synopsis, and synopsis2.

Referenced by main().

04579 {
04580    int res;
04581 
04582    ast_register_application2(app_bridge, bridge_exec, bridge_synopsis, bridge_descrip, NULL);
04583 
04584    parkinglots = ao2_container_alloc(7, parkinglot_hash_cb, parkinglot_cmp_cb);
04585 
04586    if ((res = load_config()))
04587       return res;
04588    ast_cli_register_multiple(cli_features, sizeof(cli_features) / sizeof(struct ast_cli_entry));
04589    ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
04590    res = ast_register_application2(parkedcall, park_exec, synopsis, descrip, NULL);
04591    if (!res)
04592       res = ast_register_application2(parkcall, park_call_exec, synopsis2, descrip2, NULL);
04593    if (!res) {
04594       ast_manager_register("ParkedCalls", 0, manager_parking_status, "List parked calls");
04595       ast_manager_register2("Park", EVENT_FLAG_CALL, manager_park, "Park a channel", mandescr_park); 
04596       ast_manager_register2("Bridge", EVENT_FLAG_CALL, action_bridge, "Bridge two channels already in the PBX", mandescr_bridge);
04597    }
04598 
04599    res |= ast_devstate_prov_add("Park", metermaidstate);
04600 
04601    return res;
04602 }

int ast_file_init ( void   ) 

Provided by file.c

Definition at line 1394 of file file.c.

01395 {
01396    ast_cli_register_multiple(cli_file, sizeof(cli_file) / sizeof(struct ast_cli_entry));
01397    return 0;
01398 }

int ast_http_init ( void   ) 

Provided by http.c

Definition at line 1022 of file http.c.

References __ast_http_load(), ast_cli_register_multiple(), ast_http_uri_link(), cli_http, staticuri, and statusuri.

Referenced by main().

01023 {
01024    ast_http_uri_link(&statusuri);
01025    ast_http_uri_link(&staticuri);
01026    ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry));
01027 
01028    return __ast_http_load(0);
01029 }

int ast_http_reload ( void   ) 

Provided by http.c

Definition at line 1013 of file http.c.

References __ast_http_load().

01014 {
01015    return __ast_http_load(1);
01016 }

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:
0 if the specified module was not found.
Return values:
1 if the module was found but cannot be reloaded.
-1 if a reload operation is already in progress.
2 if the specfied module was found and reloaded.

Definition at line 623 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_tvnow(), ast_verb, ast_verbose, ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, LOG_NOTICE, queue_reload_request(), ast_module_info::reload, ast_module::resource, resource_name_match(), and ast_module::running.

Referenced by action_reload(), action_updateconfig(), ast_process_pending_reloads(), handle_reload(), manager_moduleload(), and monitor_sig_flags().

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

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 558 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, LOG_NOTICE, and reload_queue_item::module.

Referenced by main().

00559 {
00560    struct reload_queue_item *item;
00561 
00562    if (!ast_fully_booted) {
00563       return;
00564    }
00565 
00566    AST_LIST_LOCK(&reload_queue);
00567 
00568    if (do_full_reload) {
00569       do_full_reload = 0;
00570       AST_LIST_UNLOCK(&reload_queue);
00571       ast_log(LOG_NOTICE, "Executing deferred reload request.\n");
00572       ast_module_reload(NULL);
00573       return;
00574    }
00575 
00576    while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) {
00577       ast_log(LOG_NOTICE, "Executing deferred reload request for module '%s'.\n", item->module);
00578       ast_module_reload(item->module);
00579       ast_free(item);
00580    }
00581 
00582    AST_LIST_UNLOCK(&reload_queue);
00583 }

int ast_ssl_init ( void   ) 

Porvided by ssl.c

Definition at line 73 of file ssl.c.

References ast_calloc, and ast_mutex_init().

Referenced by main().

00074 {
00075 #ifdef HAVE_OPENSSL
00076    unsigned int i;
00077 
00078    SSL_library_init();
00079    SSL_load_error_strings();
00080    ERR_load_crypto_strings();
00081    ERR_load_BIO_strings();
00082    OpenSSL_add_all_algorithms();
00083 
00084    /* Make OpenSSL thread-safe. */
00085 
00086    CRYPTO_set_id_callback(ssl_threadid);
00087 
00088    ssl_num_locks = CRYPTO_num_locks();
00089    if (!(ssl_locks = ast_calloc(ssl_num_locks, sizeof(ssl_locks[0])))) {
00090       return -1;
00091    }
00092    for (i = 0; i < ssl_num_locks; i++) {
00093       ast_mutex_init(&ssl_locks[i]);
00094    }
00095    CRYPTO_set_locking_callback(ssl_lock);
00096 
00097 #endif /* HAVE_OPENSSL */
00098    return 0;
00099 }

int ast_term_init ( void   ) 

Provided by term.c

Definition at line 69 of file term.c.

References ast_opt_console, ast_opt_no_color, ast_opt_no_fork, ATTR_BRIGHT, ATTR_RESET, COLOR_BLACK, COLOR_BROWN, COLOR_WHITE, convshort(), and ESC.

Referenced by main().

00070 {
00071    char *term = getenv("TERM");
00072    char termfile[256] = "";
00073    char buffer[512] = "";
00074    int termfd = -1, parseokay = 0, i;
00075 
00076    if (!term)
00077       return 0;
00078    if (!ast_opt_console || ast_opt_no_color || !ast_opt_no_fork)
00079       return 0;
00080 
00081    for (i=0 ;; i++) {
00082       if (termpath[i] == NULL) {
00083          break;
00084       }
00085       snprintf(termfile, sizeof(termfile), "%s/%c/%s", termpath[i], *term, term);
00086       termfd = open(termfile, O_RDONLY);
00087       if (termfd > -1) {
00088          break;
00089       }
00090    }
00091    if (termfd > -1) {
00092       int actsize = read(termfd, buffer, sizeof(buffer) - 1);
00093       short sz_names = convshort(buffer + 2);
00094       short sz_bools = convshort(buffer + 4);
00095       short n_nums   = convshort(buffer + 6);
00096 
00097       /* if ((sz_names + sz_bools) & 1)
00098          sz_bools++; */
00099 
00100       if (sz_names + sz_bools + n_nums < actsize) {
00101          /* Offset 13 is defined in /usr/include/term.h, though we do not
00102           * include it here, as it conflicts with include/asterisk/term.h */
00103          short max_colors = convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
00104          if (max_colors > 0) {
00105             vt100compat = 1;
00106          }
00107          parseokay = 1;
00108       }
00109       close(termfd);
00110    }
00111 
00112    if (!parseokay) {
00113       /* These comparisons should not be substrings nor case-insensitive, as
00114        * terminal types are very particular about how they treat suffixes and
00115        * capitalization.  For example, terminal type 'linux-m' does NOT
00116        * support color, while 'linux' does.  Not even all vt100* terminals
00117        * support color, either (e.g. 'vt100+fnkeys'). */
00118       if (!strcmp(term, "linux")) {
00119          vt100compat = 1;
00120       } else if (!strcmp(term, "xterm")) {
00121          vt100compat = 1;
00122       } else if (!strcmp(term, "xterm-color")) {
00123          vt100compat = 1;
00124       } else if (!strncmp(term, "Eterm", 5)) {
00125          /* Both entries which start with Eterm support color */
00126          vt100compat = 1;
00127       } else if (!strcmp(term, "vt100")) {
00128          vt100compat = 1;
00129       } else if (!strncmp(term, "crt", 3)) {
00130          /* Both crt terminals support color */
00131          vt100compat = 1;
00132       }
00133    }
00134 
00135    if (vt100compat) {
00136       /* Make commands show up in nice colors */
00137       snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
00138       snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
00139       snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
00140    }
00141    return 0;
00142 }

int ast_timing_init ( void   ) 

Provided by timing.c

Definition at line 283 of file timing.c.

References ARRAY_LEN, ast_cli_register_multiple(), ast_heap_create(), and timing_holder_cmp().

Referenced by main().

00284 {
00285    if (!(timing_interfaces = ast_heap_create(2, timing_holder_cmp, 0))) {
00286       return -1;
00287    }
00288 
00289    return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
00290 }

int ast_tps_init ( void   ) 

Provided by taskprocessor.c

Definition at line 122 of file taskprocessor.c.

References ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_cond_init(), ast_log(), cli_ping_cond, LOG_ERROR, taskprocessor_clis, tps_cmp_cb(), tps_hash_cb(), TPS_MAX_BUCKETS, and tps_singletons.

Referenced by main().

00123 {
00124    if (!(tps_singletons = ao2_container_alloc(TPS_MAX_BUCKETS, tps_hash_cb, tps_cmp_cb))) {
00125       ast_log(LOG_ERROR, "taskprocessor container failed to initialize!\n");
00126       return -1;
00127    }
00128 
00129    ast_cond_init(&cli_ping_cond, NULL);
00130 
00131    ast_cli_register_multiple(taskprocessor_clis, ARRAY_LEN(taskprocessor_clis));
00132    return 0;
00133 }

int astdb_init ( void   ) 

Provided by db.c

Definition at line 665 of file db.c.

References ast_cli_register_multiple(), ast_manager_register, dbinit(), EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, manager_dbdel(), manager_dbdeltree(), manager_dbget(), and manager_dbput().

Referenced by main().

00666 {
00667    dbinit();
00668    ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry));
00669    ast_manager_register("DBGet", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_dbget, "Get DB Entry");
00670    ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
00671    ast_manager_register("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");
00672    ast_manager_register("DBDelTree", EVENT_FLAG_SYSTEM, manager_dbdeltree, "Delete DB Tree");
00673    return 0;
00674 }

int astobj2_init ( void   ) 

Provided by astobj2.c

Definition at line 1032 of file astobj2.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

01033 {
01034 #ifdef AO2_DEBUG
01035    ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
01036 #endif
01037 
01038    return 0;
01039 }

void close_logger ( void   ) 

Provided by logger.c

Definition at line 1042 of file logger.c.

References ast_cond_signal(), AST_LIST_LOCK, AST_LIST_UNLOCK, AST_PTHREADT_NULL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, close_logger_thread, eventlog, f, logchannel::fileptr, logchannel::list, logcond, logthread, and qlog.

Referenced by quit_handler().

01044 {
01045    struct logchannel *f = NULL;
01046 
01047    /* Stop logger thread */
01048    AST_LIST_LOCK(&logmsgs);
01049    close_logger_thread = 1;
01050    ast_cond_signal(&logcond);
01051    AST_LIST_UNLOCK(&logmsgs);
01052 
01053    if (logthread != AST_PTHREADT_NULL)
01054       pthread_join(logthread, NULL);
01055 
01056    AST_RWLIST_WRLOCK(&logchannels);
01057 
01058    if (eventlog) {
01059       fclose(eventlog);
01060       eventlog = NULL;
01061    }
01062 
01063    if (qlog) {
01064       fclose(qlog);
01065       qlog = NULL;
01066    }
01067 
01068    AST_RWLIST_TRAVERSE(&logchannels, f, list) {
01069       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
01070          fclose(f->fileptr);
01071          f->fileptr = NULL;
01072       }
01073    }
01074 
01075    closelog(); /* syslog */
01076 
01077    AST_RWLIST_UNLOCK(&logchannels);
01078 
01079    return;

int dnsmgr_init ( void   ) 

Provided by dnsmgr.c

Definition at line 350 of file dnsmgr.c.

References ast_cli_register(), ast_log(), cli_refresh, cli_reload, cli_status, do_reload(), LOG_ERROR, and sched_context_create().

Referenced by main().

00351 {
00352    if (!(sched = sched_context_create())) {
00353       ast_log(LOG_ERROR, "Unable to create schedule context.\n");
00354       return -1;
00355    }
00356    ast_cli_register(&cli_reload);
00357    ast_cli_register(&cli_status);
00358    ast_cli_register(&cli_refresh);
00359    return do_reload(1);
00360 }

int dnsmgr_reload ( void   ) 

Provided by dnsmgr.c

Definition at line 362 of file dnsmgr.c.

References do_reload().

00363 {
00364    return do_reload(0);
00365 }

void dnsmgr_start_refresh ( void   ) 

Provided by dnsmgr.c

Definition at line 244 of file dnsmgr.c.

References ast_sched_add_variable(), AST_SCHED_DEL, master_refresh_info, and refresh_list().

Referenced by main().

00245 {
00246    if (refresh_sched > -1) {
00247       AST_SCHED_DEL(sched, refresh_sched);
00248       refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
00249    }
00250 }

int init_framer ( void   ) 

Provided by frame.c

Definition at line 951 of file frame.c.

References ast_cli_register_multiple().

Referenced by main().

00952 {
00953    ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry));
00954    return 0;   
00955 }

int init_logger ( void   ) 

Provided by logger.c

Definition at line 998 of file logger.c.

References ast_cli_register_multiple(), ast_cond_destroy(), ast_cond_init(), ast_config_AST_LOG_DIR, ast_log(), ast_mkdir(), ast_pthread_create, ast_queue_log(), ast_verb, cli_logger, errno, eventlog, EVENTLOG, handle_SIGXFSZ(), init_logger_chain(), LOG_ERROR, LOG_EVENT, logcond, logfiles, logger_thread(), logthread, and qlog.

Referenced by main().

01000 {
01001    char tmp[256];
01002    int res = 0;
01003 
01004    /* auto rotate if sig SIGXFSZ comes a-knockin */
01005    (void) signal(SIGXFSZ, (void *) handle_SIGXFSZ);
01006 
01007    /* start logger thread */
01008    ast_cond_init(&logcond, NULL);
01009    if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
01010       ast_cond_destroy(&logcond);
01011       return -1;
01012    }
01013 
01014    /* register the logger cli commands */
01015    ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry));
01016 
01017    ast_mkdir(ast_config_AST_LOG_DIR, 0777);
01018   
01019    /* create log channels */
01020    init_logger_chain(0 /* locked */);
01021 
01022    /* create the eventlog */
01023    if (logfiles.event_log) {
01024       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
01025       eventlog = fopen(tmp, "a");
01026       if (eventlog) {
01027          ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
01028          ast_verb(1, "Asterisk Event Logger Started %s\n", tmp);
01029       } else {
01030          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
01031          res = -1;
01032       }
01033    }
01034 
01035    if (logfiles.queue_log) {
01036       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
01037       qlog = fopen(tmp, "a");
01038       ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
01039    }
01040    return res;

int load_modules ( unsigned  int  ) 

Provided by loader.c

Definition at line 927 of file loader.c.

References add_to_load_order(), ast_config_AST_MODULE_DIR, ast_config_destroy(), ast_config_load2(), ast_free, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), AST_MODULE_CONFIG, ast_opt_quiet, ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verb, dir, embedding, EVENT_FLAG_SYSTEM, find_resource(), ast_module::flags, ast_module::lib, load_resource_list(), LOG_NOTICE, LOG_WARNING, manager_event, ast_variable::name, ast_variable::next, load_order_entry::resource, ast_module::resource, resource_name_match(), ast_module::running, and ast_variable::value.

Referenced by main().

00928 {
00929    struct ast_config *cfg;
00930    struct ast_module *mod;
00931    struct load_order_entry *order;
00932    struct ast_variable *v;
00933    unsigned int load_count;
00934    struct load_order load_order;
00935    int res = 0;
00936    struct ast_flags config_flags = { 0 };
00937    int modulecount = 0;
00938 
00939 #ifdef LOADABLE_MODULES
00940    struct dirent *dirent;
00941    DIR *dir;
00942 #endif
00943 
00944    /* all embedded modules have registered themselves by now */
00945    embedding = 0;
00946 
00947    ast_verb(1, "Asterisk Dynamic Loader Starting:\n");
00948 
00949    AST_LIST_HEAD_INIT_NOLOCK(&load_order);
00950 
00951    AST_LIST_LOCK(&module_list);
00952 
00953    if (embedded_module_list.first) {
00954       module_list.first = embedded_module_list.first;
00955       module_list.last = embedded_module_list.last;
00956       embedded_module_list.first = NULL;
00957    }
00958 
00959    if (!(cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags))) {
00960       ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
00961       goto done;
00962    }
00963 
00964    /* first, find all the modules we have been explicitly requested to load */
00965    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00966       if (!strcasecmp(v->name, preload_only ? "preload" : "load")) {
00967          add_to_load_order(v->value, &load_order);
00968       }
00969    }
00970 
00971    /* check if 'autoload' is on */
00972    if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
00973       /* if so, first add all the embedded modules that are not already running to the load order */
00974       AST_LIST_TRAVERSE(&module_list, mod, entry) {
00975          /* if it's not embedded, skip it */
00976          if (mod->lib)
00977             continue;
00978 
00979          if (mod->flags.running)
00980             continue;
00981 
00982          order = add_to_load_order(mod->resource, &load_order);
00983       }
00984 
00985 #ifdef LOADABLE_MODULES
00986       /* if we are allowed to load dynamic modules, scan the directory for
00987          for all available modules and add them as well */
00988       if ((dir  = opendir(ast_config_AST_MODULE_DIR))) {
00989          while ((dirent = readdir(dir))) {
00990             int ld = strlen(dirent->d_name);
00991 
00992             /* Must end in .so to load it.  */
00993 
00994             if (ld < 4)
00995                continue;
00996 
00997             if (strcasecmp(dirent->d_name + ld - 3, ".so"))
00998                continue;
00999 
01000             /* if there is already a module by this name in the module_list,
01001                skip this file */
01002             if (find_resource(dirent->d_name, 0))
01003                continue;
01004 
01005             add_to_load_order(dirent->d_name, &load_order);
01006          }
01007 
01008          closedir(dir);
01009       } else {
01010          if (!ast_opt_quiet)
01011             ast_log(LOG_WARNING, "Unable to open modules directory '%s'.\n",
01012                ast_config_AST_MODULE_DIR);
01013       }
01014 #endif
01015    }
01016 
01017    /* now scan the config for any modules we are prohibited from loading and
01018       remove them from the load order */
01019    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
01020       if (strcasecmp(v->name, "noload"))
01021          continue;
01022 
01023       AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
01024          if (!resource_name_match(order->resource, v->value)) {
01025             AST_LIST_REMOVE_CURRENT(entry);
01026             ast_free(order->resource);
01027             ast_free(order);
01028          }
01029       }
01030       AST_LIST_TRAVERSE_SAFE_END;
01031    }
01032 
01033    /* we are done with the config now, all the information we need is in the
01034       load_order list */
01035    ast_config_destroy(cfg);
01036 
01037    load_count = 0;
01038    AST_LIST_TRAVERSE(&load_order, order, entry)
01039       load_count++;
01040 
01041    if (load_count)
01042       ast_log(LOG_NOTICE, "%d modules will be loaded.\n", load_count);
01043 
01044    /* first, load only modules that provide global symbols */
01045    if ((res = load_resource_list(&load_order, 1, &modulecount)) < 0) {
01046       goto done;
01047    }
01048 
01049    /* now load everything else */
01050    if ((res = load_resource_list(&load_order, 0, &modulecount)) < 0) {
01051       goto done;
01052    }
01053 
01054 done:
01055    while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) {
01056       ast_free(order->resource);
01057       ast_free(order);
01058    }
01059 
01060    AST_LIST_UNLOCK(&module_list);
01061    
01062    /* Tell manager clients that are aggressive at logging in that we're done
01063       loading modules. If there's a DNS problem in chan_sip, we might not
01064       even reach this */
01065    manager_event(EVENT_FLAG_SYSTEM, "ModuleLoadReport", "ModuleLoadStatus: Done\r\nModuleSelection: %s\r\nModuleCount: %d\r\n", preload_only ? "Preload" : "All", modulecount);
01066    
01067    return res;
01068 }

int load_pbx ( void   ) 

Provided by pbx.c

Definition at line 8686 of file pbx.c.

References __ast_custom_function_register(), ast_cli_register_multiple(), AST_EVENT_DEVICE_STATE, AST_EVENT_IE_END, ast_event_subscribe(), ast_log(), ast_manager_register2(), ast_register_application2(), ast_taskprocessor_get(), ast_verb, builtins, device_state_cb(), device_state_sub, EVENT_FLAG_CONFIG, EVENT_FLAG_REPORTING, exception_function, LOG_ERROR, LOG_WARNING, manager_show_dialplan(), mandescr_show_dialplan, and pbx_cli.

Referenced by main().

08687 {
08688    int x;
08689 
08690    /* Initialize the PBX */
08691    ast_verb(1, "Asterisk PBX Core Initializing\n");
08692    if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
08693       ast_log(LOG_WARNING, "failed to create pbx-core taskprocessor\n");
08694    }
08695 
08696    ast_verb(1, "Registering builtin applications:\n");
08697    ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
08698    __ast_custom_function_register(&exception_function, NULL);
08699 
08700    /* Register builtin applications */
08701    for (x = 0; x < sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
08702       ast_verb(1, "[%s]\n", builtins[x].name);
08703       if (ast_register_application2(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description, NULL)) {
08704          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
08705          return -1;
08706       }
08707    }
08708    
08709    /* Register manager application */
08710    ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
08711 
08712    if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL,
08713          AST_EVENT_IE_END))) {
08714       return -1;
08715    }
08716 
08717    return 0;
08718 }

void threadstorage_init ( void   ) 

Provided by threadstorage.c

Definition at line 31 of file threadstorage.c.

Referenced by main().

00032 {
00033 }


Generated on Wed Oct 28 11:51:09 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6