Thu Oct 11 06:47:22 2012

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_cli_perms_init (int reload)
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_indications_init (void)
 Load indications module.
int ast_indications_reload (void)
 Reload indications module.
int ast_module_reload (const char *name)
 Reload asterisk modules.
int ast_plc_reload (void)
 Reload genericplc configuration value from codecs.conf.
void ast_process_pending_reloads (void)
 Process reload requests received during startup.
int ast_ssl_init (void)
int ast_term_init (void)
int ast_test_init (void)
int ast_timing_init (void)
int ast_tps_init (void)
int ast_xmldoc_load_documentation (void)
 Load XML documentation. Provided by xmldoc.c.
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 319 of file autoservice.c.

References as_cond, and ast_cond_init().

Referenced by main().

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

void ast_builtins_init ( void   ) 

initialize the _full_cmd string in * each of the builtins.

Provided by cli.c

Definition at line 1725 of file cli.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

void ast_channels_init ( void   ) 

Provided by channel.c

Definition at line 5942 of file channel.c.

References ARRAY_LEN, ast_cli_register_multiple(), ast_plc_reload(), and cli_channel.

Referenced by main().

int ast_cli_perms_init ( int  reload  ) 

Provided by cli.c

Definition at line 1602 of file cli.c.

References ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_free, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_mutex_trylock(), ast_mutex_unlock(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdup, ast_strlen_zero(), ast_variable_browse(), cli_perm::command, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEUNCHANGED, destroy_user_perms(), usergroup_cli_perm::gid, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, cli_perm::permit, usergroup_cli_perm::perms, perms_config, usergroup_cli_perm::uid, and ast_variable::value.

Referenced by handle_cli_reload_permissions(), and main().

01603 {
01604    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
01605    struct ast_config *cfg;
01606    char *cat = NULL;
01607    struct ast_variable *v;
01608    struct usergroup_cli_perm *user_group, *cp_entry;
01609    struct cli_perm *perm = NULL;
01610    struct passwd *pw;
01611    struct group *gr;
01612 
01613    if (ast_mutex_trylock(&permsconfiglock)) {
01614       ast_log(LOG_NOTICE, "You must wait until last 'cli reload permissions' command finish\n");
01615       return 1;
01616    }
01617 
01618    cfg = ast_config_load2(perms_config, "" /* core, can't reload */, config_flags);
01619    if (!cfg) {
01620       ast_mutex_unlock(&permsconfiglock);
01621       return 1;
01622    } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
01623       ast_mutex_unlock(&permsconfiglock);
01624       return 0;
01625    }
01626 
01627    /* free current structures. */
01628    destroy_user_perms();
01629 
01630    while ((cat = ast_category_browse(cfg, cat))) {
01631       if (!strcasecmp(cat, "general")) {
01632          /* General options */
01633          for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01634             if (!strcasecmp(v->name, "default_perm")) {
01635                cli_default_perm = (!strcasecmp(v->value, "permit")) ? 1: 0;
01636             }
01637          }
01638          continue;
01639       }
01640 
01641       /* users or groups */
01642       gr = NULL, pw = NULL;
01643       if (cat[0] == '@') {
01644          /* This is a group */
01645          gr = getgrnam(&cat[1]);
01646          if (!gr) {
01647             ast_log (LOG_WARNING, "Unknown group '%s'\n", &cat[1]);
01648             continue;
01649          }
01650       } else {
01651          /* This is a user */
01652          pw = getpwnam(cat);
01653          if (!pw) {
01654             ast_log (LOG_WARNING, "Unknown user '%s'\n", cat);
01655             continue;
01656          }
01657       }
01658       user_group = NULL;
01659       /* Check for duplicates */
01660       AST_RWLIST_WRLOCK(&cli_perms);
01661       AST_LIST_TRAVERSE(&cli_perms, cp_entry, list) {
01662          if ((pw && cp_entry->uid == pw->pw_uid) || (gr && cp_entry->gid == gr->gr_gid)) {
01663             /* if it is duplicated, just added this new settings, to 
01664             the current list. */
01665             user_group = cp_entry;
01666             break;
01667          }
01668       }
01669       AST_RWLIST_UNLOCK(&cli_perms);
01670 
01671       if (!user_group) {
01672          /* alloc space for the new user config. */
01673          user_group = ast_calloc(1, sizeof(*user_group));
01674          if (!user_group) {
01675             continue;
01676          }
01677          user_group->uid = (pw ? pw->pw_uid : -1);
01678          user_group->gid = (gr ? gr->gr_gid : -1);
01679          user_group->perms = ast_calloc(1, sizeof(*user_group->perms));
01680          if (!user_group->perms) {
01681             ast_free(user_group);
01682             continue;
01683          }
01684       }
01685       for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
01686          if (ast_strlen_zero(v->value)) {
01687             /* we need to check this condition cause it could break security. */
01688             ast_log(LOG_WARNING, "Empty permit/deny option in user '%s'\n", cat);
01689             continue;
01690          }
01691          if (!strcasecmp(v->name, "permit")) {
01692             perm = ast_calloc(1, sizeof(*perm));
01693             if (perm) {
01694                perm->permit = 1;
01695                perm->command = ast_strdup(v->value);
01696             }
01697          } else if (!strcasecmp(v->name, "deny")) {
01698             perm = ast_calloc(1, sizeof(*perm));
01699             if (perm) {
01700                perm->permit = 0;
01701                perm->command = ast_strdup(v->value);
01702             }
01703          } else {
01704             /* up to now, only 'permit' and 'deny' are possible values. */
01705             ast_log(LOG_WARNING, "Unknown '%s' option\n", v->name);
01706             continue;
01707          }
01708          if (perm) {
01709             /* Added the permission to the user's list. */
01710             AST_LIST_INSERT_TAIL(user_group->perms, perm, list);
01711             perm = NULL;
01712          }
01713       }
01714       AST_RWLIST_WRLOCK(&cli_perms);
01715       AST_RWLIST_INSERT_TAIL(&cli_perms, user_group, list);
01716       AST_RWLIST_UNLOCK(&cli_perms);
01717    }
01718 
01719    ast_config_destroy(cfg);
01720    ast_mutex_unlock(&permsconfiglock);
01721    return 0;
01722 }

int ast_device_state_engine_init ( void   ) 

Initialize the device state engine in separate thread.

Provided by devicestate.c

Definition at line 725 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().

00726 {
00727    ast_cond_init(&change_pending, NULL);
00728    if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
00729       ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
00730       return -1;
00731    }
00732 
00733    return 0;
00734 }

int ast_event_init ( void   ) 

Provided by event.c

Definition at line 1486 of file event.c.

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

Referenced by main().

01487 {
01488    int i;
01489 
01490    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01491       AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
01492    }
01493 
01494    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01495       if (!ast_event_cache[i].hash_fn) {
01496          /* This event type is not cached. */
01497          continue;
01498       }
01499 
01500       if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
01501             ast_event_hash, ast_event_cmp))) {
01502          return -1;
01503       }
01504    }
01505 
01506    if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
01507       return -1;
01508    }
01509 
01510    ast_cli_register_multiple(event_cli, ARRAY_LEN(event_cli));
01511 
01512    return 0;
01513 }

int ast_features_init ( void   ) 

Provided by features.c

Definition at line 5280 of file features.c.

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

Referenced by main().

05281 {
05282    int res;
05283 
05284    ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);
05285 
05286    parkinglots = ao2_container_alloc(7, parkinglot_hash_cb, parkinglot_cmp_cb);
05287 
05288    if ((res = load_config()))
05289       return res;
05290    ast_cli_register_multiple(cli_features, ARRAY_LEN(cli_features));
05291    ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
05292    res = ast_register_application2(parkedcall, park_exec, NULL, NULL, NULL);
05293    if (!res)
05294       res = ast_register_application2(parkcall, park_call_exec, NULL, NULL, NULL);
05295    if (!res) {
05296       ast_manager_register("ParkedCalls", 0, manager_parking_status, "List parked calls");
05297       ast_manager_register2("Park", EVENT_FLAG_CALL, manager_park, "Park a channel", mandescr_park); 
05298       ast_manager_register2("Bridge", EVENT_FLAG_CALL, action_bridge, "Bridge two channels already in the PBX", mandescr_bridge);
05299    }
05300 
05301    res |= ast_devstate_prov_add("Park", metermaidstate);
05302 
05303    return res;
05304 }

int ast_file_init ( void   ) 

Provided by file.c

Definition at line 1476 of file file.c.

Referenced by main().

01477 {
01478    ast_cli_register_multiple(cli_file, ARRAY_LEN(cli_file));
01479    return 0;
01480 }

int ast_http_init ( void   ) 

Provided by http.c

Definition at line 1047 of file http.c.

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

Referenced by main().

int ast_http_reload ( void   ) 

Provided by http.c

Definition at line 1038 of file http.c.

References __ast_http_load().

01039 {
01040    return __ast_http_load(1);
01041 }

int ast_indications_init ( void   ) 

Load indications module.

Provided by indications.c

Definition at line 1106 of file indications.c.

References ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_tone_zone_cmp(), ast_tone_zone_hash(), load_indications(), and NUM_TONE_ZONE_BUCKETS.

Referenced by main().

01107 {
01108    if (!(ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,
01109          ast_tone_zone_hash, ast_tone_zone_cmp))) {
01110       return -1;
01111    }
01112 
01113    if (load_indications(0)) {
01114       return -1;
01115    }
01116 
01117    ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
01118 
01119    return 0;
01120 }

int ast_indications_reload ( void   ) 

Reload indications module.

Provided by indications.c

Definition at line 1123 of file indications.c.

References load_indications().

01124 {
01125    return load_indications(1);
01126 }

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 640 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().

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

int ast_plc_reload ( void   ) 

Reload genericplc configuration value from codecs.conf.

Implementation is in main/channel.c

Definition at line 5926 of file channel.c.

References ast_config_destroy(), ast_config_load2(), AST_OPT_FLAG_GENERIC_PLC, ast_options, ast_set2_flag, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, ast_variable::value, and var.

Referenced by ast_channels_init().

05927 {
05928    struct ast_variable *var;
05929    struct ast_flags config_flags = { 0 };
05930    struct ast_config *cfg = ast_config_load2("codecs.conf", "channel", config_flags);
05931    if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
05932       return 0;
05933    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
05934       if (!strcasecmp(var->name, "genericplc")) {
05935          ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC);
05936       }
05937    }
05938    ast_config_destroy(cfg);
05939    return 0;
05940 }

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 575 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().

00576 {
00577    struct reload_queue_item *item;
00578 
00579    if (!ast_fully_booted) {
00580       return;
00581    }
00582 
00583    AST_LIST_LOCK(&reload_queue);
00584 
00585    if (do_full_reload) {
00586       do_full_reload = 0;
00587       AST_LIST_UNLOCK(&reload_queue);
00588       ast_log(LOG_NOTICE, "Executing deferred reload request.\n");
00589       ast_module_reload(NULL);
00590       return;
00591    }
00592 
00593    while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) {
00594       ast_log(LOG_NOTICE, "Executing deferred reload request for module '%s'.\n", item->module);
00595       ast_module_reload(item->module);
00596       ast_free(item);
00597    }
00598 
00599    AST_LIST_UNLOCK(&reload_queue);
00600 }

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 83 of file term.c.

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

Referenced by main().

00084 {
00085    char *term = getenv("TERM");
00086    char termfile[256] = "";
00087    char buffer[512] = "";
00088    int termfd = -1, parseokay = 0, i;
00089 
00090    if (ast_opt_no_color) {
00091       return 0;
00092    }
00093 
00094    if (!ast_opt_console) {
00095       /* If any remote console is not compatible, we'll strip the color codes at that point */
00096       vt100compat = 1;
00097       goto end;
00098    }
00099 
00100    if (!term) {
00101       return 0;
00102    }
00103 
00104    for (i = 0;; i++) {
00105       if (termpath[i] == NULL) {
00106          break;
00107       }
00108       snprintf(termfile, sizeof(termfile), "%s/%c/%s", termpath[i], *term, term);
00109       termfd = open(termfile, O_RDONLY);
00110       if (termfd > -1) {
00111          break;
00112       }
00113    }
00114    if (termfd > -1) {
00115       int actsize = read(termfd, buffer, sizeof(buffer) - 1);
00116       short sz_names = convshort(buffer + 2);
00117       short sz_bools = convshort(buffer + 4);
00118       short n_nums   = convshort(buffer + 6);
00119 
00120       /* if ((sz_names + sz_bools) & 1)
00121          sz_bools++; */
00122 
00123       if (sz_names + sz_bools + n_nums < actsize) {
00124          /* Offset 13 is defined in /usr/include/term.h, though we do not
00125           * include it here, as it conflicts with include/asterisk/term.h */
00126          short max_colors = convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
00127          if (max_colors > 0) {
00128             vt100compat = 1;
00129          }
00130          parseokay = 1;
00131       }
00132       close(termfd);
00133    }
00134 
00135    if (!parseokay) {
00136       /* These comparisons should not be substrings nor case-insensitive, as
00137        * terminal types are very particular about how they treat suffixes and
00138        * capitalization.  For example, terminal type 'linux-m' does NOT
00139        * support color, while 'linux' does.  Not even all vt100* terminals
00140        * support color, either (e.g. 'vt100+fnkeys'). */
00141       if (!strcmp(term, "linux")) {
00142          vt100compat = 1;
00143       } else if (!strcmp(term, "xterm")) {
00144          vt100compat = 1;
00145       } else if (!strcmp(term, "xterm-color")) {
00146          vt100compat = 1;
00147       } else if (!strncmp(term, "Eterm", 5)) {
00148          /* Both entries which start with Eterm support color */
00149          vt100compat = 1;
00150       } else if (!strcmp(term, "vt100")) {
00151          vt100compat = 1;
00152       } else if (!strncmp(term, "crt", 3)) {
00153          /* Both crt terminals support color */
00154          vt100compat = 1;
00155       }
00156    }
00157 
00158 end:
00159    if (vt100compat) {
00160       /* Make commands show up in nice colors */
00161       if (ast_opt_light_background) {
00162          snprintf(prepdata, sizeof(prepdata), "%c[%dm", ESC, COLOR_BROWN);
00163          snprintf(enddata, sizeof(enddata), "%c[%dm", ESC, COLOR_BLACK);
00164          snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
00165       } else if (ast_opt_force_black_background) {
00166          snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
00167          snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
00168          snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
00169       } else {
00170          snprintf(prepdata, sizeof(prepdata), "%c[%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN);
00171          snprintf(enddata, sizeof(enddata), "%c[%d;%dm", ESC, ATTR_RESET, COLOR_WHITE);
00172          snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
00173       }
00174    }
00175    return 0;
00176 }

int ast_test_init ( void   ) 

Provided by test.c

Definition at line 889 of file test.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00890 {
00891 #ifdef TEST_FRAMEWORK
00892    /* Register cli commands */
00893    ast_cli_register_multiple(test_cli, ARRAY_LEN(test_cli));
00894 #endif
00895 
00896    return 0;
00897 }

int ast_timing_init ( void   ) 

Provided by timing.c

Definition at line 288 of file timing.c.

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

Referenced by main().

00289 {
00290    if (!(timing_interfaces = ast_heap_create(2, timing_holder_cmp, 0))) {
00291       return -1;
00292    }
00293 
00294    return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
00295 }

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 ast_xmldoc_load_documentation ( void   ) 

Load XML documentation. Provided by xmldoc.c.

Return values:
1 on error.
0 on success.

Referenced by main().

int astdb_init ( void   ) 

int astobj2_init ( void   ) 

Provided by astobj2.c

Definition at line 1125 of file astobj2.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

01126 {
01127 #ifdef AO2_DEBUG
01128    ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
01129 #endif
01130 
01131    return 0;
01132 }

void close_logger ( void   ) 

Provided by logger.c

Definition at line 1058 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().

01060 {
01061    struct logchannel *f = NULL;
01062 
01063    /* Stop logger thread */
01064    AST_LIST_LOCK(&logmsgs);
01065    close_logger_thread = 1;
01066    ast_cond_signal(&logcond);
01067    AST_LIST_UNLOCK(&logmsgs);
01068 
01069    if (logthread != AST_PTHREADT_NULL)
01070       pthread_join(logthread, NULL);
01071 
01072    AST_RWLIST_WRLOCK(&logchannels);
01073 
01074    if (eventlog) {
01075       fclose(eventlog);
01076       eventlog = NULL;
01077    }
01078 
01079    if (qlog) {
01080       fclose(qlog);
01081       qlog = NULL;
01082    }
01083 
01084    AST_RWLIST_TRAVERSE(&logchannels, f, list) {
01085       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
01086          fclose(f->fileptr);
01087          f->fileptr = NULL;
01088       }
01089    }
01090 
01091    closelog(); /* syslog */
01092 
01093    AST_RWLIST_UNLOCK(&logchannels);
01094 
01095    return;

int dnsmgr_init ( void   ) 

Provided by dnsmgr.c

Definition at line 352 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().

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

int dnsmgr_reload ( void   ) 

Provided by dnsmgr.c

Definition at line 364 of file dnsmgr.c.

References do_reload().

00365 {
00366    return do_reload(0);
00367 }

void dnsmgr_start_refresh ( void   ) 

Provided by dnsmgr.c

Definition at line 246 of file dnsmgr.c.

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

Referenced by main().

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

int init_framer ( void   ) 

Provided by frame.c

Definition at line 968 of file frame.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00969 {
00970    ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
00971    return 0;   
00972 }

int init_logger ( void   ) 

Provided by logger.c

Definition at line 1014 of file logger.c.

References ARRAY_LEN, 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().

01016 {
01017    char tmp[256];
01018    int res = 0;
01019 
01020    /* auto rotate if sig SIGXFSZ comes a-knockin */
01021    sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
01022 
01023    /* start logger thread */
01024    ast_cond_init(&logcond, NULL);
01025    if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
01026       ast_cond_destroy(&logcond);
01027       return -1;
01028    }
01029 
01030    /* register the logger cli commands */
01031    ast_cli_register_multiple(cli_logger, ARRAY_LEN(cli_logger));
01032 
01033    ast_mkdir(ast_config_AST_LOG_DIR, 0777);
01034   
01035    /* create log channels */
01036    init_logger_chain(0 /* locked */);
01037 
01038    /* create the eventlog */
01039    if (logfiles.event_log) {
01040       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
01041       eventlog = fopen(tmp, "a");
01042       if (eventlog) {
01043          ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
01044          ast_verb(1, "Asterisk Event Logger Started %s\n", tmp);
01045       } else {
01046          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
01047          res = -1;
01048       }
01049    }
01050 
01051    if (logfiles.queue_log) {
01052       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
01053       qlog = fopen(tmp, "a");
01054       ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
01055    }
01056    return res;

int load_modules ( unsigned  int  ) 

Provided by loader.c

Definition at line 944 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, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, 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().

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

int load_pbx ( void   ) 

Provided by pbx.c

Definition at line 9378 of file pbx.c.

References __ast_custom_function_register(), ARRAY_LEN, 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().

09379 {
09380    int x;
09381 
09382    /* Initialize the PBX */
09383    ast_verb(1, "Asterisk PBX Core Initializing\n");
09384    if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
09385       ast_log(LOG_WARNING, "failed to create pbx-core taskprocessor\n");
09386    }
09387 
09388    ast_verb(1, "Registering builtin applications:\n");
09389    ast_cli_register_multiple(pbx_cli, ARRAY_LEN(pbx_cli));
09390    __ast_custom_function_register(&exception_function, NULL);
09391 
09392    /* Register builtin applications */
09393    for (x = 0; x < ARRAY_LEN(builtins); x++) {
09394       ast_verb(1, "[%s]\n", builtins[x].name);
09395       if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) {
09396          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
09397          return -1;
09398       }
09399    }
09400 
09401    /* Register manager application */
09402    ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
09403 
09404    if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL,
09405          AST_EVENT_IE_END))) {
09406       return -1;
09407    }
09408 
09409    return 0;
09410 }

void threadstorage_init ( void   ) 

Provided by threadstorage.c

Definition at line 31 of file threadstorage.c.

Referenced by main().

00032 {
00033 }


Generated on Thu Oct 11 06:47:22 2012 for Asterisk - the Open Source PBX by  doxygen 1.5.6