Fri Sep 25 19:28:22 2009

Asterisk developer's documentation


asterisk.h File Reference

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

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

Include dependency graph for asterisk.h:

Go to the source code of this file.

Defines

#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)
#define sched_setscheduler   __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
#define setpriority   __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__

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)
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)
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]


Detailed Description

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

Definition in file asterisk.h.


Define Documentation

#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 173 of file asterisk.h.

#define DEFAULT_LANGUAGE   "en"

Definition at line 34 of file asterisk.h.

#define DEFAULT_SAMPLE_RATE   8000

Definition at line 36 of file asterisk.h.

Referenced by check_header(), ogg_vorbis_open(), ogg_vorbis_rewrite(), setformat(), and write_header().

#define DEFAULT_SAMPLES_PER_MS   ((DEFAULT_SAMPLE_RATE)/1000)

Definition at line 37 of file asterisk.h.

Referenced by ast_stream_fastforward(), ast_stream_rewind(), and isAnsweringMachine().

#define sched_setscheduler   __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__

Definition at line 39 of file asterisk.h.

Referenced by ast_set_priority().

#define setpriority   __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__

Definition at line 38 of file asterisk.h.

Referenced by ast_set_priority().


Function Documentation

int ast_add_profile ( const char *  name,
uint64_t  scale 
)

support for event profiling

(note, this must be documented a lot more) ast_add_profile allocates a generic 'counter' with a given name, which can be shown with the command 'show profile <name>'

The counter accumulates positive or negative values supplied by ast_add_profile(), dividing them by the 'scale' value passed in the create call, and also counts the number of 'events'. Values can also be taked by the TSC counter on ia32 architectures, in which case you can mark the start of an event calling ast_mark(id, 1) and then the end of the event with ast_mark(id, 0). For non-i386 architectures, these two calls return 0.

support for event profiling

Returns:
Returns the identifier of the counter.

Definition at line 372 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, profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

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

void ast_builtins_init ( void   ) 

initialize the _full_cmd string in * each of the builtins.

Provided by cli.c

Definition at line 1499 of file cli.c.

References ast_cli_entry::_full_cmd, ast_cli_register_multiple(), ast_join(), ast_log(), ast_cli_entry::cmda, LOG_WARNING, and strdup.

Referenced by main().

01500 {
01501    struct ast_cli_entry *e;
01502 
01503    for (e = builtins; e->cmda[0] != NULL; e++) {
01504       char buf[80];
01505       ast_join(buf, sizeof(buf), e->cmda);
01506       e->_full_cmd = strdup(buf);
01507       if (!e->_full_cmd)
01508          ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf);
01509    }
01510 
01511    ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry));
01512 }

void ast_channels_init ( void   ) 

Provided by channel.c

Definition at line 4704 of file channel.c.

References ast_cli_register_multiple(), and cli_channel.

Referenced by main().

04705 {
04706    ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
04707 }

int64_t ast_mark ( int  ,
int  start1_stop0 
)

Definition at line 434 of file asterisk.c.

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

Referenced by extension_match_core().

00435 {
00436    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00437       return 0;
00438    if (startstop == 1)
00439       prof_data->e[i].mark = rdtsc();
00440    else {
00441       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00442       if (prof_data->e[i].scale > 1)
00443          prof_data->e[i].mark /= prof_data->e[i].scale;
00444       prof_data->e[i].value += prof_data->e[i].mark;
00445       prof_data->e[i].events++;
00446    }
00447    return prof_data->e[i].mark;
00448 }

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

References ast_lastreloadtime, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_trylock(), ast_mutex_unlock(), ast_verbose(), ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, option_verbose, ast_module_info::reload, resource_name_match(), ast_module::running, and VERBOSE_PREFIX_3.

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

00556 {
00557    struct ast_module *cur;
00558    int res = 0; /* return value. 0 = not found, others, see below */
00559    int i;
00560 
00561    if (ast_mutex_trylock(&reloadlock)) {
00562       ast_verbose("The previous reload command didn't finish yet\n");
00563       return -1;  /* reload already in progress */
00564    }
00565    ast_lastreloadtime = time(NULL);
00566 
00567    /* Call "predefined" reload here first */
00568    for (i = 0; reload_classes[i].name; i++) {
00569       if (!name || !strcasecmp(name, reload_classes[i].name)) {
00570          reload_classes[i].reload_fn();   /* XXX should check error ? */
00571          res = 2; /* found and reloaded */
00572       }
00573    }
00574 
00575    if (name && res) {
00576       ast_mutex_unlock(&reloadlock);
00577       return res;
00578    }
00579 
00580    AST_LIST_LOCK(&module_list);
00581    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00582       const struct ast_module_info *info = cur->info;
00583 
00584       if (name && resource_name_match(name, cur->resource))
00585          continue;
00586 
00587       if (!(cur->flags.running || cur->flags.declined))
00588          continue;
00589 
00590       if (!info->reload) { /* cannot be reloaded */
00591          if (res < 1)   /* store result if possible */
00592             res = 1; /* 1 = no reload() method */
00593          continue;
00594       }
00595 
00596       res = 2;
00597       if (option_verbose > 2)
00598          ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", cur->resource, info->description);
00599       info->reload();
00600    }
00601    AST_LIST_UNLOCK(&module_list);
00602 
00603    ast_mutex_unlock(&reloadlock);
00604 
00605    return res;
00606 }

int64_t ast_profile ( int  ,
int64_t   
)

Definition at line 402 of file asterisk.c.

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

00403 {
00404    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00405       return 0;
00406    if (prof_data->e[i].scale > 1)
00407       delta /= prof_data->e[i].scale;
00408    prof_data->e[i].value += delta;
00409    prof_data->e[i].events++;
00410    return prof_data->e[i].value;
00411 }

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 702 of file asterisk.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_unregister_atexit(), func, and ast_atexit::func.

Referenced by do_reload(), and load_module().

00703 {
00704    struct ast_atexit *ae;
00705 
00706    if (!(ae = ast_calloc(1, sizeof(*ae))))
00707       return -1;
00708 
00709    ae->func = func;
00710 
00711    ast_unregister_atexit(func);  
00712 
00713    AST_LIST_LOCK(&atexits);
00714    AST_LIST_INSERT_HEAD(&atexits, ae, list);
00715    AST_LIST_UNLOCK(&atexits);
00716 
00717    return 0;
00718 }

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 256 of file asterisk.c.

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

00257 {
00258    struct file_version *new;
00259    char *work;
00260    size_t version_length;
00261 
00262    work = ast_strdupa(version);
00263    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00264    version_length = strlen(work) + 1;
00265    
00266    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00267       return;
00268 
00269    new->file = file;
00270    new->version = (char *) new + sizeof(*new);
00271    memcpy(new->version, work, version_length);
00272    AST_LIST_LOCK(&file_versions);
00273    AST_LIST_INSERT_HEAD(&file_versions, new, list);
00274    AST_LIST_UNLOCK(&file_versions);
00275 }

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 1177 of file asterisk.c.

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

Referenced by app_exec(), ast_safe_system(), icesencode(), launch_script(), main(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), and spawn_ras().

01178 {
01179    struct sched_param sched;
01180    memset(&sched, 0, sizeof(sched));
01181 #ifdef __linux__
01182    if (pri) {  
01183       sched.sched_priority = 10;
01184       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01185          ast_log(LOG_WARNING, "Unable to set high priority\n");
01186          return -1;
01187       } else
01188          if (option_verbose)
01189             ast_verbose("Set to realtime thread\n");
01190    } else {
01191       sched.sched_priority = 0;
01192       /* According to the manpage, these parameters can never fail. */
01193       sched_setscheduler(0, SCHED_OTHER, &sched);
01194    }
01195 #else
01196    if (pri) {
01197       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01198          ast_log(LOG_WARNING, "Unable to set high priority\n");
01199          return -1;
01200       } else
01201          if (option_verbose)
01202             ast_verbose("Set to high priority\n");
01203    } else {
01204       /* According to the manpage, these parameters can never fail. */
01205       setpriority(PRIO_PROCESS, 0, 0);
01206    }
01207 #endif
01208    return 0;
01209 }

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, ast_opt_no_fork, ATTR_BRIGHT, ATTR_RESET, COLOR_BLACK, COLOR_BROWN, COLOR_WHITE, convshort(), and ESC.

Referenced by main().

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 720 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, free, func, and ast_atexit::func.

Referenced by ast_register_atexit(), and do_reload().

00721 {
00722    struct ast_atexit *ae = NULL;
00723 
00724    AST_LIST_LOCK(&atexits);
00725    AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
00726       if (ae->func == func) {
00727          AST_LIST_REMOVE_CURRENT(&atexits, list);
00728          break;
00729       }
00730    }
00731    AST_LIST_TRAVERSE_SAFE_END
00732    AST_LIST_UNLOCK(&atexits);
00733 
00734    if (ae)
00735       free(ae);
00736 }

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 277 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.

00278 {
00279    struct file_version *find;
00280 
00281    AST_LIST_LOCK(&file_versions);
00282    AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00283       if (!strcasecmp(find->file, file)) {
00284          AST_LIST_REMOVE_CURRENT(&file_versions, list);
00285          break;
00286       }
00287    }
00288    AST_LIST_TRAVERSE_SAFE_END;
00289    AST_LIST_UNLOCK(&file_versions);
00290    if (find)
00291       free(find);
00292 }

int astdb_init ( void   ) 

Provided by db.c

Definition at line 608 of file db.c.

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

Referenced by main().

00609 {
00610    dbinit();
00611    ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry));
00612    ast_manager_register("DBget", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
00613    ast_manager_register("DBput", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
00614    ast_manager_register("DBdel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");
00615    return 0;
00616 }

int astobj2_init ( void   ) 

Definition at line 712 of file astobj2.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00713 {
00714 #ifdef AO2_DEBUG
00715    ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
00716 #endif
00717 
00718    return 0;
00719 }

void close_logger ( void   ) 

Provided by logger.c

Definition at line 628 of file logger.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, eventlog, f, logchannel::fileptr, and qlog.

Referenced by quit_handler().

00629 {
00630    struct logchannel *f;
00631 
00632    AST_LIST_LOCK(&logchannels);
00633 
00634    if (eventlog) {
00635       fclose(eventlog);
00636       eventlog = NULL;
00637    }
00638 
00639    if (qlog) {
00640       fclose(qlog);
00641       qlog = NULL;
00642    }
00643 
00644    AST_LIST_TRAVERSE(&logchannels, f, list) {
00645       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
00646          fclose(f->fileptr);
00647          f->fileptr = NULL;
00648       }
00649    }
00650 
00651    closelog(); /* syslog */
00652 
00653    AST_LIST_UNLOCK(&logchannels);
00654 
00655    return;
00656 }

int dnsmgr_init ( void   ) 

Provided by dnsmgr.c

Definition at line 337 of file dnsmgr.c.

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

Referenced by main().

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

int dnsmgr_reload ( void   ) 

Provided by dnsmgr.c

Definition at line 348 of file dnsmgr.c.

References do_reload().

00349 {
00350    return do_reload(0);
00351 }

void dnsmgr_start_refresh ( void   ) 

Provided by dnsmgr.c

Definition at line 252 of file dnsmgr.c.

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

Referenced by main().

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

int init_framer ( void   ) 

Provided by frame.c

Definition at line 1040 of file frame.c.

References ast_cli_register_multiple().

Referenced by main().

01041 {
01042    ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry));
01043    return 0;   
01044 }

int init_logger ( void   ) 

Provided by logger.c

Definition at line 589 of file logger.c.

References ast_cli_register_multiple(), ast_config_AST_LOG_DIR, ast_log(), ast_queue_log(), ast_verbose(), cli_logger, errno, eventlog, EVENTLOG, handle_SIGXFSZ(), init_logger_chain(), LOG_ERROR, LOG_EVENT, logfiles, option_verbose, qlog, and QUEUELOG.

Referenced by main().

00590 {
00591    char tmp[256];
00592    int res = 0;
00593 
00594    /* auto rotate if sig SIGXFSZ comes a-knockin */
00595    (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
00596 
00597    /* register the logger cli commands */
00598    ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry));
00599 
00600    mkdir((char *)ast_config_AST_LOG_DIR, 0755);
00601   
00602    /* create log channels */
00603    init_logger_chain();
00604 
00605    /* create the eventlog */
00606    if (logfiles.event_log) {
00607       mkdir((char *)ast_config_AST_LOG_DIR, 0755);
00608       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
00609       eventlog = fopen((char *)tmp, "a");
00610       if (eventlog) {
00611          ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
00612          if (option_verbose)
00613             ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp);
00614       } else {
00615          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
00616          res = -1;
00617       }
00618    }
00619 
00620    if (logfiles.queue_log) {
00621       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
00622       qlog = fopen(tmp, "a");
00623       ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
00624    }
00625    return res;
00626 }

int load_modules ( unsigned  int  ) 

Provided by loader.c

Definition at line 745 of file loader.c.

References add_to_load_order(), ast_config_AST_MODULE_DIR, ast_config_destroy(), ast_config_load(), 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_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SKIP, AST_MODULE_LOAD_SUCCESS, ast_opt_quiet, ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verbose(), embedding, find_resource(), ast_module::flags, free, ast_module::lib, load_resource(), LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, option_verbose, load_order_entry::resource, resource_name_match(), ast_module::running, and ast_variable::value.

Referenced by main().

00746 {
00747    struct ast_config *cfg;
00748    struct ast_module *mod;
00749    struct load_order_entry *order;
00750    struct ast_variable *v;
00751    unsigned int load_count;
00752    struct load_order load_order;
00753    int res = 0;
00754 #ifdef LOADABLE_MODULES
00755    struct dirent *dirent;
00756    DIR *dir;
00757 #endif
00758 
00759    /* all embedded modules have registered themselves by now */
00760    embedding = 0;
00761 
00762    if (option_verbose)
00763       ast_verbose("Asterisk Dynamic Loader Starting:\n");
00764 
00765    AST_LIST_HEAD_INIT_NOLOCK(&load_order);
00766 
00767    AST_LIST_LOCK(&module_list);
00768 
00769    if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
00770       ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
00771       goto done;
00772    }
00773 
00774    /* first, find all the modules we have been explicitly requested to load */
00775    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00776       if (!strcasecmp(v->name, preload_only ? "preload" : "load"))
00777          add_to_load_order(v->value, &load_order);
00778    }
00779 
00780    /* check if 'autoload' is on */
00781    if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
00782       /* if so, first add all the embedded modules that are not already running to the load order */
00783       AST_LIST_TRAVERSE(&module_list, mod, entry) {
00784          /* if it's not embedded, skip it */
00785          if (mod->lib)
00786             continue;
00787 
00788          if (mod->flags.running)
00789             continue;
00790 
00791          order = add_to_load_order(mod->resource, &load_order);
00792       }
00793 
00794 #ifdef LOADABLE_MODULES
00795       /* if we are allowed to load dynamic modules, scan the directory for
00796          for all available modules and add them as well */
00797       if ((dir  = opendir(ast_config_AST_MODULE_DIR))) {
00798          while ((dirent = readdir(dir))) {
00799             int ld = strlen(dirent->d_name);
00800 
00801             /* Must end in .so to load it.  */
00802 
00803             if (ld < 4)
00804                continue;
00805 
00806             if (strcasecmp(dirent->d_name + ld - 3, ".so"))
00807                continue;
00808 
00809             /* if there is already a module by this name in the module_list,
00810                skip this file */
00811             if (find_resource(dirent->d_name, 0))
00812                continue;
00813 
00814             add_to_load_order(dirent->d_name, &load_order);
00815          }
00816 
00817          closedir(dir);
00818       } else {
00819          if (!ast_opt_quiet)
00820             ast_log(LOG_WARNING, "Unable to open modules directory '%s'.\n",
00821                ast_config_AST_MODULE_DIR);
00822       }
00823 #endif
00824    }
00825 
00826    /* now scan the config for any modules we are prohibited from loading and
00827       remove them from the load order */
00828    for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
00829       if (strcasecmp(v->name, "noload"))
00830          continue;
00831 
00832       AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00833          if (!resource_name_match(order->resource, v->value)) {
00834             AST_LIST_REMOVE_CURRENT(&load_order, entry);
00835             free(order->resource);
00836             free(order);
00837          }
00838       }
00839       AST_LIST_TRAVERSE_SAFE_END;
00840    }
00841 
00842    /* we are done with the config now, all the information we need is in the
00843       load_order list */
00844    ast_config_destroy(cfg);
00845 
00846    load_count = 0;
00847    AST_LIST_TRAVERSE(&load_order, order, entry)
00848       load_count++;
00849 
00850    if (load_count)
00851       ast_log(LOG_NOTICE, "%d modules will be loaded.\n", load_count);
00852 
00853    /* first, load only modules that provide global symbols */
00854    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00855       switch (load_resource(order->resource, 1)) {
00856       case AST_MODULE_LOAD_SUCCESS:
00857       case AST_MODULE_LOAD_DECLINE:
00858          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00859          free(order->resource);
00860          free(order);
00861          break;
00862       case AST_MODULE_LOAD_FAILURE:
00863          res = -1;
00864          goto done;
00865       case AST_MODULE_LOAD_SKIP:
00866          /* try again later */
00867          break;
00868       }
00869    }
00870    AST_LIST_TRAVERSE_SAFE_END;
00871 
00872    /* now load everything else */
00873    AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
00874       switch (load_resource(order->resource, 0)) {
00875       case AST_MODULE_LOAD_SUCCESS:
00876       case AST_MODULE_LOAD_DECLINE:
00877          AST_LIST_REMOVE_CURRENT(&load_order, entry);
00878          free(order->resource);
00879          free(order);
00880          break;
00881       case AST_MODULE_LOAD_FAILURE:
00882          res = -1;
00883          goto done;
00884       case AST_MODULE_LOAD_SKIP:
00885          /* should not happen */
00886          break;
00887       }
00888    }
00889    AST_LIST_TRAVERSE_SAFE_END;
00890 
00891 done:
00892    while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) {
00893       free(order->resource);
00894       free(order);
00895    }
00896 
00897    AST_LIST_UNLOCK(&module_list);
00898 
00899    return res;
00900 }

int load_pbx ( void   ) 

Provided by pbx.c

Definition at line 6116 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.

Referenced by main().

06117 {
06118    int x;
06119 
06120    /* Initialize the PBX */
06121    if (option_verbose) {
06122       ast_verbose( "Asterisk PBX Core Initializing\n");
06123       ast_verbose( "Registering builtin applications:\n");
06124    }
06125    ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
06126 
06127    /* Register builtin applications */
06128    for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
06129       if (option_verbose)
06130          ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
06131       if (ast_register_application(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description)) {
06132          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
06133          return -1;
06134       }
06135    }
06136    return 0;
06137 }

int reload_logger ( int   ) 

Provided by logger.c

Definition at line 368 of file logger.c.

References ast_config_AST_LOG_DIR, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_queue_log(), ast_verbose(), logchannel::disabled, errno, EVENT_FLAG_SYSTEM, EVENTLOG, eventlog, f, logchannel::filename, logchannel::fileptr, init_logger_chain(), LOG_ERROR, LOG_EVENT, logfiles, manager_event(), option_verbose, qlog, and QUEUELOG.

Referenced by ast_log(), handle_logger_rotate(), and logger_reload().

00369 {
00370    char old[PATH_MAX] = "";
00371    char new[PATH_MAX];
00372    int event_rotate = rotate, queue_rotate = rotate;
00373    struct logchannel *f;
00374    FILE *myf;
00375    int x, res = 0;
00376 
00377    AST_LIST_LOCK(&logchannels);
00378 
00379    if (eventlog) 
00380       fclose(eventlog);
00381    else 
00382       event_rotate = 0;
00383    eventlog = NULL;
00384 
00385    if (qlog) 
00386       fclose(qlog);
00387    else 
00388       queue_rotate = 0;
00389    qlog = NULL;
00390 
00391    mkdir((char *)ast_config_AST_LOG_DIR, 0755);
00392 
00393    AST_LIST_TRAVERSE(&logchannels, f, list) {
00394       if (f->disabled) {
00395          f->disabled = 0;  /* Re-enable logging at reload */
00396          manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
00397       }
00398       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
00399          fclose(f->fileptr);  /* Close file */
00400          f->fileptr = NULL;
00401          if (rotate) {
00402             ast_copy_string(old, f->filename, sizeof(old));
00403    
00404             for (x = 0; ; x++) {
00405                snprintf(new, sizeof(new), "%s.%d", f->filename, x);
00406                myf = fopen((char *)new, "r");
00407                if (myf)
00408                   fclose(myf);
00409                else
00410                   break;
00411             }
00412        
00413             /* do it */
00414             if (rename(old,new))
00415                fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
00416          }
00417       }
00418    }
00419 
00420    filesize_reload_needed = 0;
00421    
00422    init_logger_chain();
00423 
00424    if (logfiles.event_log) {
00425       snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
00426       if (event_rotate) {
00427          for (x=0;;x++) {
00428             snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
00429             myf = fopen((char *)new, "r");
00430             if (myf)    /* File exists */
00431                fclose(myf);
00432             else
00433                break;
00434          }
00435    
00436          /* do it */
00437          if (rename(old,new))
00438             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
00439       }
00440 
00441       eventlog = fopen(old, "a");
00442       if (eventlog) {
00443          ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
00444          if (option_verbose)
00445             ast_verbose("Asterisk Event Logger restarted\n");
00446       } else {
00447          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
00448          res = -1;
00449       }
00450    }
00451 
00452    if (logfiles.queue_log) {
00453       snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
00454       if (queue_rotate) {
00455          for (x = 0; ; x++) {
00456             snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, QUEUELOG, x);
00457             myf = fopen((char *)new, "r");
00458             if (myf)    /* File exists */
00459                fclose(myf);
00460             else
00461                break;
00462          }
00463    
00464          /* do it */
00465          if (rename(old, new))
00466             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
00467       }
00468 
00469       qlog = fopen(old, "a");
00470       if (qlog) {
00471          ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
00472          ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n");
00473          if (option_verbose)
00474             ast_verbose("Asterisk Queue Logger restarted\n");
00475       } else {
00476          ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
00477          res = -1;
00478       }
00479    }
00480 
00481    AST_LIST_UNLOCK(&logchannels);
00482 
00483    return res;
00484 }

void threadstorage_init ( void   ) 

Provided by threadstorage.c

Definition at line 224 of file threadstorage.c.

Referenced by main().

00225 {
00226 }


Variable Documentation

char ast_config_AST_AGI_DIR[PATH_MAX]

Definition at line 213 of file asterisk.c.

char ast_config_AST_CONFIG_DIR[PATH_MAX]

Definition at line 205 of file asterisk.c.

Definition at line 206 of file asterisk.c.

char ast_config_AST_CTL[PATH_MAX]

Definition at line 224 of file asterisk.c.

char ast_config_AST_CTL_GROUP[PATH_MAX]

Definition at line 223 of file asterisk.c.

char ast_config_AST_CTL_OWNER[PATH_MAX]

Definition at line 222 of file asterisk.c.

Definition at line 221 of file asterisk.c.

char ast_config_AST_DATA_DIR[PATH_MAX]

Definition at line 211 of file asterisk.c.

char ast_config_AST_DB[PATH_MAX]

Definition at line 214 of file asterisk.c.

char ast_config_AST_KEY_DIR[PATH_MAX]

Definition at line 215 of file asterisk.c.

char ast_config_AST_LOG_DIR[PATH_MAX]

Definition at line 212 of file asterisk.c.

char ast_config_AST_MODULE_DIR[PATH_MAX]

Definition at line 207 of file asterisk.c.

Definition at line 209 of file asterisk.c.

char ast_config_AST_PID[PATH_MAX]

Definition at line 216 of file asterisk.c.

char ast_config_AST_RUN_DIR[PATH_MAX]

Definition at line 218 of file asterisk.c.

char ast_config_AST_SOCKET[PATH_MAX]

Definition at line 217 of file asterisk.c.

char ast_config_AST_SPOOL_DIR[PATH_MAX]

Definition at line 208 of file asterisk.c.

Definition at line 225 of file asterisk.c.

char ast_config_AST_VAR_DIR[PATH_MAX]

Definition at line 210 of file asterisk.c.


Generated on Fri Sep 25 19:28:22 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.5