Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:01 2007

Asterisk developer's documentation :: Codename Pineapple


asterisk.h File Reference


Detailed Description

Asterisk main include file. File version handling, generic pbx functions.

Definition in file asterisk.h.

#include "asterisk/autoconfig.h"
#include "asterisk/compat.h"
#include "asterisk/paths.h"

Include dependency graph for asterisk.h:

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

Go to the source code of this file.

Defines

#define AST_DIR_MODE   0777
#define AST_FILE_MODE   0666
#define ASTERISK_FILE_VERSION(file, version)
 Register/unregister a source code file with the core.
#define DEFAULT_LANGUAGE   "en"
#define DEFAULT_SAMPLE_RATE   8000
#define DEFAULT_SAMPLES_PER_MS   ((DEFAULT_SAMPLE_RATE)/1000)

Functions

int ast_add_profile (const char *, uint64_t scale)
 support for event profiling
void ast_builtins_init (void)
 initialize the _full_cmd string in * each of the builtins.
void ast_channels_init (void)
int64_t ast_mark (int, int start1_stop0)
int ast_module_reload (const char *name)
 Reload asterisk modules.
int64_t ast_profile (int, int64_t)
int ast_register_atexit (void(*func)(void))
 Register a function to be executed before Asterisk exits.
void ast_register_file_version (const char *file, const char *version)
 Register the version of a source code file with the core.
int ast_set_priority (int)
 We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.
int ast_term_init (void)
void ast_unregister_atexit (void(*func)(void))
 Unregister a function registered with ast_register_atexit().
void ast_unregister_file_version (const char *file)
 Unregister a source code file from the core.
int astdb_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)
int reload_logger (int)
void threadstorage_init (void)

Variables

char ast_config_AST_AGI_DIR [PATH_MAX]
char ast_config_AST_CONFIG_DIR [PATH_MAX]
char ast_config_AST_CONFIG_FILE [PATH_MAX]
char ast_config_AST_CTL [PATH_MAX]
char ast_config_AST_CTL_GROUP [PATH_MAX]
char ast_config_AST_CTL_OWNER [PATH_MAX]
char ast_config_AST_CTL_PERMISSIONS [PATH_MAX]
char ast_config_AST_DATA_DIR [PATH_MAX]
char ast_config_AST_DB [PATH_MAX]
char ast_config_AST_KEY_DIR [PATH_MAX]
char ast_config_AST_LOG_DIR [PATH_MAX]
char ast_config_AST_MODULE_DIR [PATH_MAX]
char ast_config_AST_MONITOR_DIR [PATH_MAX]
char ast_config_AST_PID [PATH_MAX]
char ast_config_AST_RUN_DIR [PATH_MAX]
char ast_config_AST_SOCKET [PATH_MAX]
char ast_config_AST_SPOOL_DIR [PATH_MAX]
char ast_config_AST_SYSTEM_NAME [20]
char ast_config_AST_VAR_DIR [PATH_MAX]


Define Documentation

#define AST_DIR_MODE   0777
 

Definition at line 38 of file asterisk.h.

#define AST_FILE_MODE   0666
 

Definition at line 41 of file asterisk.h.

Referenced by __ast_play_and_record(), ast_lock_path(), ast_monitor_start(), cli_audio_convert(), copy(), dbinit(), handle_recordfile(), and try_firmware().

#define ASTERISK_FILE_VERSION file,
version   ) 
 

Register/unregister a source code file with the core.

Parameters:
file the source file name
version the version string (typically a CVS revision keyword string)
This macro will place a file-scope constructor and destructor into the source of the module using it; this will cause the version of this file to registered with the Asterisk core (and unregistered) at the appropriate times.

Example:

 ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")

Note:
The dollar signs above have been protected with backslashes to keep CVS from modifying them in this file; under normal circumstances they would not be present and CVS would expand the Revision keyword into the file's revision number.

Definition at line 180 of file asterisk.h.

#define DEFAULT_LANGUAGE   "en"
 

Definition at line 44 of file asterisk.h.

#define DEFAULT_SAMPLE_RATE   8000
 

Definition at line 46 of file asterisk.h.

Referenced by setformat(), and sound_thread().

#define DEFAULT_SAMPLES_PER_MS   ((DEFAULT_SAMPLE_RATE)/1000)
 

Definition at line 47 of file asterisk.h.

Referenced by ast_stream_fastforward(), and ast_stream_rewind().


Function Documentation

int ast_add_profile const char *  name,
uint64_t  scale
 

support for event profiling

Returns:
Returns the identifier of the counter.

Definition at line 364 of file asterisk.c.

References ast_calloc, ast_realloc, ast_strdup, profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, profile_data::max_size, profile_entry::name, prof_data, profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

00365 {
00366    int l = sizeof(struct profile_data);
00367    int n = 10; /* default entries */
00368 
00369    if (prof_data == NULL) {
00370       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00371       if (prof_data == NULL)
00372          return -1;
00373       prof_data->entries = 0;
00374       prof_data->max_size = n;
00375    }
00376    if (prof_data->entries >= prof_data->max_size) {
00377       void *p;
00378       n = prof_data->max_size + 20;
00379       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00380       if (p == NULL)
00381          return -1;
00382       prof_data = p;
00383       prof_data->max_size = n;
00384    }
00385    n = prof_data->entries++;
00386    prof_data->e[n].name = ast_strdup(name);
00387    prof_data->e[n].value = 0;
00388    prof_data->e[n].events = 0;
00389    prof_data->e[n].mark = 0;
00390    prof_data->e[n].scale = scale;
00391    return n;
00392 }

void ast_builtins_init void   ) 
 

initialize the _full_cmd string in * each of the builtins.

Provided by cli.c

Definition at line 1046 of file cli.c.

References ast_cli_register_multiple(), builtins, cli_cli, ast_cli_entry::cmda, and set_full_cmd().

01047 {
01048    struct ast_cli_entry *e;
01049 
01050    for (e = builtins; e->cmda[0] != NULL; e++)
01051       set_full_cmd(e);
01052 
01053    ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry));
01054 }

void ast_channels_init void   ) 
 

Provided by channel.c

Definition at line 4290 of file channel.c.

References ast_cli_register_multiple(), and cli_channel.

04291 {
04292    ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
04293 }

int64_t ast_mark int  ,
int  start1_stop0
 

Definition at line 426 of file asterisk.c.

References profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, prof_data, rdtsc(), profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

00427 {
00428    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00429       return 0;
00430    if (startstop == 1)
00431       prof_data->e[i].mark = rdtsc();
00432    else {
00433       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00434       if (prof_data->e[i].scale > 1)
00435          prof_data->e[i].mark /= prof_data->e[i].scale;
00436       prof_data->e[i].value += prof_data->e[i].mark;
00437       prof_data->e[i].events++;
00438    }
00439    return prof_data->e[i].mark;
00440 }

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 519 of file loader.c.

References ast_mutex_trylock(), and ast_verbose().

Referenced by action_updateconfig(), and handle_reload().

00520 {
00521    struct ast_module *cur;
00522    int res = 0; /* return value. 0 = not found, others, see below */
00523    int i;
00524 
00525    if (ast_mutex_trylock(&reloadlock)) {
00526       ast_verbose("The previous reload command didn't finish yet\n");
00527       return -1;  /* reload already in progress */
00528    }
00529 
00530    /* Call "predefined" reload here first */
00531    for (i = 0; reload_classes[i].name; i++) {
00532       if (!name || !strcasecmp(name, reload_classes[i].name)) {
00533          reload_classes[i].reload_fn();   /* XXX should check error ? */
00534          res = 2; /* found and reloaded */
00535       }
00536    }
00537    ast_lastreloadtime = time(NULL);
00538 
00539    if (name && res)
00540       return res;
00541 
00542    AST_LIST_LOCK(&module_list);
00543    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00544       const struct ast_module_info *info = cur->info;
00545 
00546       if (name && resource_name_match(name, cur->resource))
00547          continue;
00548 
00549       if (!ast_test_flag(cur, FLAG_RUNNING | FLAG_DECLINED))
00550          continue;
00551 
00552       if (!info->reload) { /* cannot be reloaded */
00553          if (res < 1)   /* store result if possible */
00554             res = 1; /* 1 = no reload() method */
00555          continue;
00556       }
00557 
00558       res = 2;
00559       if (option_verbose > 2)
00560          ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", cur->resource, info->description);
00561       info->reload();
00562    }
00563    AST_LIST_UNLOCK(&module_list);
00564 
00565    ast_mutex_unlock(&reloadlock);
00566 
00567    return res;
00568 }

int64_t ast_profile int  ,
int64_t 
 

Definition at line 394 of file asterisk.c.

References profile_data::e, profile_data::entries, profile_entry::events, prof_data, profile_entry::scale, and profile_entry::value.

00395 {
00396    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00397       return 0;
00398    if (prof_data->e[i].scale > 1)
00399       delta /= prof_data->e[i].scale;
00400    prof_data->e[i].value += delta;
00401    prof_data->e[i].events++;
00402    return prof_data->e[i].value;
00403 }

int ast_register_atexit void(*)(void)  func  ) 
 

Register a function to be executed before Asterisk exits.

Parameters:
func The callback function to use.
Returns:
Zero on success, -1 on error.

Definition at line 571 of file asterisk.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_unregister_atexit().

Referenced by do_reload(), and load_module().

00572 {
00573    int res = -1;
00574    struct ast_atexit *ae;
00575    ast_unregister_atexit(func);  
00576    AST_LIST_LOCK(&atexits);
00577    if ((ae = ast_calloc(1, sizeof(*ae)))) {
00578       AST_LIST_INSERT_HEAD(&atexits, ae, list);
00579       ae->func = func;
00580       res = 0;
00581    }
00582    AST_LIST_UNLOCK(&atexits);
00583    return res;
00584 }

void ast_register_file_version const char *  file,
const char *  version
 

Register the version of a source code file with the core.

Parameters:
file the source file name
version the version string (typically a CVS revision keyword string)
Returns:
nothing
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to register a file with the core.

Definition at line 248 of file asterisk.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_strdupa, and ast_strip_quoted().

00249 {
00250    struct file_version *new;
00251    char *work;
00252    size_t version_length;
00253 
00254    work = ast_strdupa(version);
00255    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00256    version_length = strlen(work) + 1;
00257    
00258    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00259       return;
00260 
00261    new->file = file;
00262    new->version = (char *) new + sizeof(*new);
00263    memcpy(new->version, work, version_length);
00264    AST_LIST_LOCK(&file_versions);
00265    AST_LIST_INSERT_HEAD(&file_versions, new, list);
00266    AST_LIST_UNLOCK(&file_versions);
00267 }

int ast_set_priority int   ) 
 

We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.

Provided by asterisk.c

Definition at line 1055 of file asterisk.c.

References ast_log(), ast_verbose(), and LOG_WARNING.

Referenced by ast_safe_system(), launch_script(), and spawn_mp3().

01056 {
01057    struct sched_param sched;
01058    memset(&sched, 0, sizeof(sched));
01059 #ifdef __linux__
01060    if (pri) {  
01061       sched.sched_priority = 10;
01062       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01063          ast_log(LOG_WARNING, "Unable to set high priority\n");
01064          return -1;
01065       } else
01066          if (option_verbose)
01067             ast_verbose("Set to realtime thread\n");
01068    } else {
01069       sched.sched_priority = 0;
01070       if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
01071          ast_log(LOG_WARNING, "Unable to set normal priority\n");
01072          return -1;
01073       }
01074    }
01075 #else
01076    if (pri) {
01077       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01078          ast_log(LOG_WARNING, "Unable to set high priority\n");
01079          return -1;
01080       } else
01081          if (option_verbose)
01082             ast_verbose("Set to high priority\n");
01083    } else {
01084       if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
01085          ast_log(LOG_WARNING, "Unable to set normal priority\n");
01086          return -1;
01087       }
01088    }
01089 #endif
01090    return 0;
01091 }

int ast_term_init void   ) 
 

Provided by term.c

Definition at line 75 of file term.c.

References ast_opt_console, ast_opt_no_color, and ast_opt_no_fork.

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

void ast_unregister_atexit void(*)(void)  func  ) 
 

Unregister a function registered with ast_register_atexit().

Parameters:
func The callback function to unregister.

Definition at line 586 of file asterisk.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and ast_atexit::func.

Referenced by ast_register_atexit(), and do_reload().

00587 {
00588    struct ast_atexit *ae;
00589    AST_LIST_LOCK(&atexits);
00590    AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
00591       if (ae->func == func) {
00592          AST_LIST_REMOVE_CURRENT(&atexits, list);
00593          break;
00594       }
00595    }
00596    AST_LIST_TRAVERSE_SAFE_END
00597    AST_LIST_UNLOCK(&atexits);
00598 }

void ast_unregister_file_version const char *  file  ) 
 

Unregister a source code file from the core.

Parameters:
file the source file name
Returns:
nothing
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to automatically unregister the file when the module is unloaded.

Definition at line 269 of file asterisk.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and free.

00270 {
00271    struct file_version *find;
00272 
00273    AST_LIST_LOCK(&file_versions);
00274    AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00275       if (!strcasecmp(find->file, file)) {
00276          AST_LIST_REMOVE_CURRENT(&file_versions, list);
00277          break;
00278       }
00279    }
00280    AST_LIST_TRAVERSE_SAFE_END;
00281    AST_LIST_UNLOCK(&file_versions);
00282    if (find)
00283       free(find);
00284 }

int astdb_init void   ) 
 

Provided by db.c

Definition at line 640 of file db.c.

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

00641 {
00642    dbinit();
00643    ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry));
00644    ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
00645    ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
00646    ast_manager_register("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");
00647    ast_manager_register("DBDelTree", EVENT_FLAG_SYSTEM, manager_dbdeltree, "Delete DB Tree");
00648    return 0;
00649 }

void close_logger void   ) 
 

Provided by logger.c

Definition at line 825 of file logger.c.

References ast_cond_signal(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, close_logger_thread, eventlog, logchannel::fileptr, logcond, and qlog.

00826 {
00827    struct logchannel *f = NULL;
00828 
00829    /* Stop logger thread */
00830    AST_LIST_LOCK(&logmsgs);
00831    close_logger_thread = 1;
00832    ast_cond_signal(&logcond);
00833    AST_LIST_UNLOCK(&logmsgs);
00834 
00835    AST_LIST_LOCK(&logchannels);
00836 
00837    if (eventlog) {
00838       fclose(eventlog);
00839       eventlog = NULL;
00840    }
00841 
00842    if (qlog) {
00843       fclose(qlog);
00844       qlog = NULL;
00845    }
00846 
00847    AST_LIST_TRAVERSE(&logchannels, f, list) {
00848       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
00849          fclose(f->fileptr);
00850          f->fileptr = NULL;
00851       }
00852    }
00853 
00854    closelog(); /* syslog */
00855 
00856    AST_LIST_UNLOCK(&logchannels);
00857 
00858    return;
00859 }

int dnsmgr_init void   ) 
 

Provided by dnsmgr.c

Definition at line 336 of file dnsmgr.c.

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

00337 {
00338    if (!(sched = sched_context_create())) {
00339       ast_log(LOG_ERROR, "Unable to create schedule context.\n");
00340       return -1;
00341    }
00342    ast_cli_register(&cli_reload);
00343    ast_cli_register(&cli_status);
00344    return do_reload(1);
00345 }

int dnsmgr_reload void   ) 
 

Provided by dnsmgr.c

Definition at line 347 of file dnsmgr.c.

References do_reload().

00348 {
00349    return do_reload(0);
00350 }

void dnsmgr_start_refresh void   ) 
 

Provided by dnsmgr.c

Definition at line 251 of file dnsmgr.c.

References ast_sched_add_variable(), ast_sched_del(), master_refresh_info, refresh_list(), and sched.

00252 {
00253    if (refresh_sched > -1) {
00254       ast_sched_del(sched, refresh_sched);
00255       refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
00256    }
00257 }

int init_framer void   ) 
 

Provided by frame.c

Definition at line 930 of file frame.c.

References ast_cli_register_multiple(), and my_clis.

00931 {
00932    ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry));
00933    return 0;   
00934 }

int init_logger void   ) 
 

Provided by logger.c

Definition at line 779 of file logger.c.

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

00780 {
00781    char tmp[256];
00782    int res = 0;
00783 
00784    /* auto rotate if sig SIGXFSZ comes a-knockin */
00785    (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
00786 
00787    /* start logger thread */
00788    ast_cond_init(&logcond, NULL);
00789    if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
00790       ast_cond_destroy(&logcond);
00791       return -1;
00792    }
00793 
00794    /* register the logger cli commands */
00795    ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry));
00796 
00797    mkdir(ast_config_AST_LOG_DIR, 0755);
00798   
00799    /* create log channels */
00800    init_logger_chain();
00801 
00802    /* create the eventlog */
00803    if (logfiles.event_log) {
00804       mkdir(ast_config_AST_LOG_DIR, 0755);
00805       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
00806       eventlog = fopen(tmp, "a");
00807       if (eventlog) {
00808          ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
00809          if (option_verbose)
00810             ast_verbose("Asterisk Event Logger Started %s\n", tmp);
00811       } else {
00812          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
00813          res = -1;
00814       }
00815    }
00816 
00817    if (logfiles.queue_log) {
00818       snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
00819       qlog = fopen(tmp, "a");
00820       ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
00821    }
00822    return res;
00823 }

int load_modules unsigned  int  ) 
 

Provided by loader.c

Definition at line 696 of file loader.c.

References add_to_load_order(), ast_config_load(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_TRAVERSE, ast_log(), AST_MODULE_CONFIG, ast_variable_browse(), ast_verbose(), embedding, LOG_DEBUG, ast_variable::name, ast_variable::next, option_debug, option_verbose, and ast_variable::value.

00697 {
00698    struct ast_config *cfg;
00699    struct ast_module *mod;
00700    struct load_order_entry *order;
00701    struct ast_variable *v;
00702    unsigned int load_count;
00703    struct load_order load_order;
00704    int res = 0;
00705 #if LOADABLE_MODULES
00706    struct dirent *dirent;
00707    DIR *dir;
00708 #endif
00709 
00710    /* all embedded modules have registered themselves by now */
00711    embedding = 0;
00712 
00713    if (option_verbose)
00714       ast_verbose("Asterisk Dynamic Loader Starting:\n");
00715 
00716    AST_LIST_TRAVERSE(&module_list, mod, entry) {
00717       if (option_debug > 1)
00718          ast_log(LOG_DEBUG, "Embedded module found: %s\n", mod->resource);
00719    }
00720 
00721    if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
00722       ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
00723       return 0;
00724    }
00725 
00726    AST_LIST_HEAD_INIT_NOLOCK(&load_order);
00727 
00728    /* first, find all the modules we have been explicitly requested to load */
00729    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00730       if (!strcasecmp(v->name, preload_only ? "preload" : "load"))
00731          add_to_load_order(v->value, &load_order);
00732    }
00733 
00734    /* check if 'autoload' is on */
00735    if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
00736       /* if so, first add all the embedded modules to the load order */
00737       AST_LIST_TRAVERSE(&module_list, mod, entry)
00738          order = add_to_load_order(mod->resource, &load_order);
00739 
00740 #if LOADABLE_MODULES
00741       /* if we are allowed to load dynamic modules, scan the directory for
00742          for all available modules and add them as well */
00743       if ((dir  = opendir(ast_config_AST_MODULE_DIR))) {
00744          while ((dirent = readdir(dir))) {
00745             int ld = strlen(dirent->d_name);
00746 
00747             /* Must end in .so to load it.  */
00748 
00749             if (ld < 4)
00750                continue;
00751 
00752             if (strcasecmp(dirent->d_name + ld - 3, ".so"))
00753                 continue;
00754 
00755             add_to_load_order(dirent->d_name, &load_order);
00756 
00757          }
00758 
00759          closedir(dir);
00760       } else {
00761          if (!ast_opt_quiet)
00762             ast_log(LOG_WARNING, "Unable to open modules directory '%s'.\n",
00763                ast_config_AST_MODULE_DIR);
00764       }
00765 #endif
00766    }
00767 
00768    /* now scan the config for any modules we are prohibited from loading and
00769       remove them from the load order */
00770    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00771       if (strcasecmp(v->name, "noload"))
00772          continue;
00773 
00774       AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00775          if (!resource_name_match(order->resource, v->value)) {
00776             AST_LIST_REMOVE_CURRENT(&load_order, entry);
00777             free(order->resource);
00778             free(order);
00779          }
00780       }
00781       AST_LIST_TRAVERSE_SAFE_END;
00782    }
00783 
00784    /* we are done with the config now, all the information we need is in the
00785       load_order list */
00786    ast_config_destroy(cfg);
00787 
00788    load_count = 0;
00789    AST_LIST_TRAVERSE(&load_order, order, entry)
00790       load_count++;
00791 
00792    if (load_count)
00793       ast_log(LOG_NOTICE, "%d modules will be loaded.\n", load_count);
00794 
00795    /* first, load only modules that provide global symbols */
00796    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00797       switch (load_resource(order->resource, 1)) {
00798       case AST_MODULE_LOAD_SUCCESS:
00799       case AST_MODULE_LOAD_DECLINE:
00800          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00801          free(order->resource);
00802          free(order);
00803          break;
00804       case AST_MODULE_LOAD_FAILURE:
00805          res = -1;
00806          goto done;
00807       case AST_MODULE_LOAD_SKIP:
00808          /* try again later */
00809          break;
00810       }
00811    }
00812    AST_LIST_TRAVERSE_SAFE_END;
00813 
00814    /* now load everything else */
00815    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00816       switch (load_resource(order->resource, 0)) {
00817       case AST_MODULE_LOAD_SUCCESS:
00818       case AST_MODULE_LOAD_DECLINE:
00819          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00820          free(order->resource);
00821          free(order);
00822          break;
00823       case AST_MODULE_LOAD_FAILURE:
00824          res = -1;
00825          goto done;
00826       case AST_MODULE_LOAD_SKIP:
00827          /* should not happen */
00828          break;
00829       }
00830    }
00831    AST_LIST_TRAVERSE_SAFE_END;
00832 
00833 done:
00834    while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) {
00835       free(order->resource);
00836       free(order);
00837    }
00838 
00839    return res;
00840 }

int load_pbx void   ) 
 

Provided by pbx.c

Definition at line 5948 of file pbx.c.

References ast_cli_register_multiple(), ast_log(), ast_register_application(), ast_verbose(), builtins, LOG_ERROR, option_verbose, pbx_cli, and VERBOSE_PREFIX_1.

05949 {
05950    int x;
05951 
05952    /* Initialize the PBX */
05953    if (option_verbose) {
05954       ast_verbose( "Asterisk PBX Core Initializing\n");
05955       ast_verbose( "Registering builtin applications:\n");
05956    }
05957    ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
05958 
05959    /* Register builtin applications */
05960    for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
05961       if (option_verbose)
05962          ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
05963       if (ast_register_application(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description)) {
05964          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
05965          return -1;
05966       }
05967    }
05968    
05969    /* Register manager application */
05970    ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
05971    return 0;
05972 }

int reload_logger int   ) 
 

Provided by logger.c

Definition at line 397 of file logger.c.

References ast_config_AST_LOG_DIR, AST_LIST_LOCK, AST_LIST_TRAVERSE, logchannel::disabled, EVENT_FLAG_SYSTEM, eventlog, logchannel::filename, logchannel::fileptr, manager_event, and qlog.

Referenced by handle_logger_reload(), handle_logger_rotate(), and logger_print_normal().

00398 {
00399    char old[PATH_MAX] = "";
00400    char new[PATH_MAX];
00401    int event_rotate = rotate, queue_rotate = rotate;
00402    struct logchannel *f;
00403    FILE *myf;
00404    int x, res = 0;
00405 
00406    AST_LIST_LOCK(&logchannels);
00407 
00408    if (eventlog) 
00409       fclose(eventlog);
00410    else 
00411       event_rotate = 0;
00412    eventlog = NULL;
00413 
00414    if (qlog) 
00415       fclose(qlog);
00416    else 
00417       queue_rotate = 0;
00418    qlog = NULL;
00419 
00420    mkdir(ast_config_AST_LOG_DIR, 0755);
00421 
00422    AST_LIST_TRAVERSE(&logchannels, f, list) {
00423       if (f->disabled) {
00424          f->disabled = 0;  /* Re-enable logging at reload */
00425          manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
00426       }
00427       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
00428          fclose(f->fileptr);  /* Close file */
00429          f->fileptr = NULL;
00430          if (rotate) {
00431             ast_copy_string(old, f->filename, sizeof(old));
00432             
00433             if (!rotatetimestamp) { 
00434                for (x = 0; ; x++) {
00435                   snprintf(new, sizeof(new), "%s.%d", f->filename, x);
00436                   myf = fopen(new, "r");
00437                   if (myf)
00438                      fclose(myf);
00439                   else
00440                      break;
00441                }
00442             } else 
00443                snprintf(new, sizeof(new), "%s.%ld", f->filename, (long)time(NULL));
00444 
00445             /* do it */
00446             if (rename(old,new))
00447                fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
00448          }
00449       }
00450    }
00451 
00452    filesize_reload_needed = 0;
00453    
00454    init_logger_chain();
00455 
00456    if (logfiles.event_log) {
00457       snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
00458       if (event_rotate) {
00459          if (!rotatetimestamp) { 
00460             for (x=0;;x++) {
00461                snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, EVENTLOG,x);
00462                myf = fopen(new, "r");
00463                if (myf)    /* File exists */
00464                   fclose(myf);
00465                else
00466                   break;
00467             }
00468          } else 
00469             snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, EVENTLOG,(long)time(NULL));
00470    
00471          /* do it */
00472          if (rename(old,new))
00473             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
00474       }
00475 
00476       eventlog = fopen(old, "a");
00477       if (eventlog) {
00478          ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
00479          if (option_verbose)
00480             ast_verbose("Asterisk Event Logger restarted\n");
00481       } else {
00482          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
00483          res = -1;
00484       }
00485    }
00486 
00487    if (logfiles.queue_log) {
00488       snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
00489       if (queue_rotate) {
00490          if (!rotatetimestamp) { 
00491             for (x = 0; ; x++) {
00492                snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, queue_log_name, x);
00493                myf = fopen(new, "r");
00494                if (myf)    /* File exists */
00495                   fclose(myf);
00496                else
00497                   break;
00498             }
00499    
00500          } else 
00501             snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, queue_log_name,(long)time(NULL));
00502          /* do it */
00503          if (rename(old, new))
00504             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
00505       }
00506 
00507       qlog = fopen(old, "a");
00508       if (qlog) {
00509          ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
00510          ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n");
00511          if (option_verbose)
00512             ast_verbose("Asterisk Queue Logger restarted\n");
00513       } else {
00514          ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
00515          res = -1;
00516       }
00517    }
00518 
00519    AST_LIST_UNLOCK(&logchannels);
00520 
00521    return res;
00522 }

void threadstorage_init void   ) 
 

Provided by threadstorage.c

Definition at line 222 of file threadstorage.c.

00223 {
00224 }


Variable Documentation

char ast_config_AST_AGI_DIR[PATH_MAX]
 

Definition at line 209 of file asterisk.c.

char ast_config_AST_CONFIG_DIR[PATH_MAX]
 

Definition at line 201 of file asterisk.c.

char ast_config_AST_CONFIG_FILE[PATH_MAX]
 

Definition at line 202 of file asterisk.c.

char ast_config_AST_CTL[PATH_MAX]
 

Definition at line 220 of file asterisk.c.

char ast_config_AST_CTL_GROUP[PATH_MAX]
 

Definition at line 219 of file asterisk.c.

char ast_config_AST_CTL_OWNER[PATH_MAX]
 

Definition at line 218 of file asterisk.c.

char ast_config_AST_CTL_PERMISSIONS[PATH_MAX]
 

Definition at line 217 of file asterisk.c.

char ast_config_AST_DATA_DIR[PATH_MAX]
 

Definition at line 207 of file asterisk.c.

char ast_config_AST_DB[PATH_MAX]
 

Definition at line 210 of file asterisk.c.

char ast_config_AST_KEY_DIR[PATH_MAX]
 

Definition at line 211 of file asterisk.c.

char ast_config_AST_LOG_DIR[PATH_MAX]
 

Definition at line 208 of file asterisk.c.

char ast_config_AST_MODULE_DIR[PATH_MAX]
 

Definition at line 203 of file asterisk.c.

char ast_config_AST_MONITOR_DIR[PATH_MAX]
 

Definition at line 205 of file asterisk.c.

char ast_config_AST_PID[PATH_MAX]
 

Definition at line 212 of file asterisk.c.

char ast_config_AST_RUN_DIR[PATH_MAX]
 

Definition at line 214 of file asterisk.c.

char ast_config_AST_SOCKET[PATH_MAX]
 

Definition at line 213 of file asterisk.c.

char ast_config_AST_SPOOL_DIR[PATH_MAX]
 

Definition at line 204 of file asterisk.c.

char ast_config_AST_SYSTEM_NAME[20]
 

Definition at line 221 of file asterisk.c.

char ast_config_AST_VAR_DIR[PATH_MAX]
 

Definition at line 206 of file asterisk.c.


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen