Thu Sep 7 01:03:12 2017

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"

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 bcopy   0x__dont_use_bcopy__use_memmove_instead()
#define bzero   0x__dont_use_bzero__use_memset_instead""
#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
char * ast_complete_source_filename (const char *partial, int n)
int ast_fd_init (void)
const char * ast_file_version_find (const char *file)
 Find version for given module name.
int64_t ast_mark (int, int start1_stop0)
int ast_pbx_init (void)
int64_t ast_profile (int, int64_t)
int ast_register_atexit (void(*func)(void))
 Register a function to be executed before Asterisk exits.
int ast_register_cleanup (void(*func)(void))
 Register a function to be executed before Asterisk gracefully 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.
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.
void mask_string (char *, int, int, int)

Variables

char agimaskvar [PATH_MAX]
int agimaskvarend
int agimaskvarini
char readmaskvar [PATH_MAX]
int readmaskvarend
int readmaskvarini
char setmaskvar [PATH_MAX]
int setmaskvarend
int setmaskvarini

Detailed Description

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

Definition in file asterisk.h.


Define Documentation

#define AST_DIR_MODE   0777

Definition at line 33 of file asterisk.h.

#define AST_FILE_MODE   0666
#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 SVN 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 SVN from modifying them in this file; under normal circumstances they would not be present and SVN would expand the Revision keyword into the file's revision number.

Definition at line 188 of file asterisk.h.

#define bcopy   0x__dont_use_bcopy__use_memmove_instead()

Definition at line 248 of file asterisk.h.

#define bzero   0x__dont_use_bzero__use_memset_instead""

Definition at line 247 of file asterisk.h.

#define DEFAULT_LANGUAGE   "en"

Definition at line 39 of file asterisk.h.

Referenced by fileexists_core().

#define DEFAULT_SAMPLE_RATE   8000

Definition at line 41 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 42 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 44 of file asterisk.h.

Referenced by ast_set_priority().

#define setpriority   __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__

Definition at line 43 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 'core show profile <name>'

The counter accumulates positive or negative values supplied by

See also:
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 724 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().

00725 {
00726    int l = sizeof(struct profile_data);
00727    int n = 10; /* default entries */
00728 
00729    if (prof_data == NULL) {
00730       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00731       if (prof_data == NULL)
00732          return -1;
00733       prof_data->entries = 0;
00734       prof_data->max_size = n;
00735    }
00736    if (prof_data->entries >= prof_data->max_size) {
00737       void *p;
00738       n = prof_data->max_size + 20;
00739       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00740       if (p == NULL)
00741          return -1;
00742       prof_data = p;
00743       prof_data->max_size = n;
00744    }
00745    n = prof_data->entries++;
00746    prof_data->e[n].name = ast_strdup(name);
00747    prof_data->e[n].value = 0;
00748    prof_data->e[n].events = 0;
00749    prof_data->e[n].mark = 0;
00750    prof_data->e[n].scale = scale;
00751    return n;
00752 }

char* ast_complete_source_filename ( const char *  partial,
int  n 
)

Definition at line 371 of file asterisk.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, file_version::file, len(), and ast_atexit::list.

Referenced by handle_verbose().

00372 {
00373    struct file_version *find;
00374    size_t len = strlen(partial);
00375    int count = 0;
00376    char *res = NULL;
00377 
00378    AST_RWLIST_RDLOCK(&file_versions);
00379    AST_RWLIST_TRAVERSE(&file_versions, find, list) {
00380       if (!strncasecmp(find->file, partial, len) && ++count > n) {
00381          res = ast_strdup(find->file);
00382          break;
00383       }
00384    }
00385    AST_RWLIST_UNLOCK(&file_versions);
00386    return res;
00387 }

int ast_fd_init ( void   ) 

Provided by astfd.c

Definition at line 289 of file astfd.c.

Referenced by main().

00290 {
00291    return 0;
00292 }

const char* ast_file_version_find ( const char *  file  ) 

Find version for given module name.

Parameters:
file Module name (i.e. chan_sip.so)
Returns:
version string or NULL if the module is not found

Definition at line 390 of file asterisk.c.

References AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, ast_atexit::list, and file_version::version.

Referenced by manager_modulecheck().

00391 {
00392    struct file_version *iterator;
00393 
00394    AST_RWLIST_WRLOCK(&file_versions);
00395    AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
00396       if (!strcasecmp(iterator->file, file))
00397          break;
00398    }
00399    AST_RWLIST_UNLOCK(&file_versions);
00400    if (iterator)
00401       return iterator->version;
00402    return NULL;
00403 }

int64_t ast_mark ( int  ,
int  start1_stop0 
)

Definition at line 789 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 __ast_pthread_mutex_lock(), and extension_match_core().

00790 {
00791    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00792       return 0;
00793    if (startstop == 1)
00794       prof_data->e[i].mark = rdtsc();
00795    else {
00796       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00797       if (prof_data->e[i].scale > 1)
00798          prof_data->e[i].mark /= prof_data->e[i].scale;
00799       prof_data->e[i].value += prof_data->e[i].mark;
00800       prof_data->e[i].events++;
00801    }
00802    return prof_data->e[i].mark;
00803 }

int ast_pbx_init ( void   ) 

Provided by pbx.c

Definition at line 11317 of file pbx.c.

References ao2_container_alloc, ast_register_atexit(), HASH_EXTENHINT_SIZE, hint_cmp(), hint_hash(), hints, pbx_shutdown(), statecbs, and statecbs_cmp().

Referenced by main().

11318 {
11319    hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
11320    statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
11321 
11322    ast_register_atexit(pbx_shutdown);
11323 
11324    return (hints && statecbs) ? 0 : -1;
11325 }

int64_t ast_profile ( int  ,
int64_t   
)

Definition at line 754 of file asterisk.c.

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

00755 {
00756    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00757       return 0;
00758    if (prof_data->e[i].scale > 1)
00759       delta /= prof_data->e[i].scale;
00760    prof_data->e[i].value += delta;
00761    prof_data->e[i].events++;
00762    return prof_data->e[i].value;
00763 }

int ast_register_atexit ( void(*)(void)  func  ) 
int ast_register_cleanup ( void(*)(void)  func  ) 

Register a function to be executed before Asterisk gracefully exits.

Since:
1.8.29 If Asterisk is immediately shutdown (core stop now, or sending the TERM signal), the callback is not run. When the callbacks are run, they are run in sequence with ast_register_atexit() callbacks, in the reverse order of registration.
Parameters:
func The callback function to use.
Return values:
0 on success.
-1 on error.

Definition at line 1017 of file asterisk.c.

References ast_atexit::func, and register_atexit().

Referenced by ast_autoservice_init().

01018 {
01019    return register_atexit(func, 1);
01020 }

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

References ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdupa, ast_strip(), and ast_strip_quoted().

00333 {
00334    struct file_version *new;
00335    char *work;
00336    size_t version_length;
00337 
00338    work = ast_strdupa(version);
00339    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00340    version_length = strlen(work) + 1;
00341 
00342    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00343       return;
00344 
00345    new->file = file;
00346    new->version = (char *) new + sizeof(*new);
00347    memcpy(new->version, work, version_length);
00348    AST_RWLIST_WRLOCK(&file_versions);
00349    AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
00350    AST_RWLIST_UNLOCK(&file_versions);
00351 }

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

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

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

01665 {
01666    struct sched_param sched;
01667    memset(&sched, 0, sizeof(sched));
01668 #ifdef __linux__
01669    if (pri) {
01670       sched.sched_priority = 10;
01671       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01672          ast_log(LOG_WARNING, "Unable to set high priority\n");
01673          return -1;
01674       } else
01675          if (option_verbose)
01676             ast_verbose("Set to realtime thread\n");
01677    } else {
01678       sched.sched_priority = 0;
01679       /* According to the manpage, these parameters can never fail. */
01680       sched_setscheduler(0, SCHED_OTHER, &sched);
01681    }
01682 #else
01683    if (pri) {
01684       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01685          ast_log(LOG_WARNING, "Unable to set high priority\n");
01686          return -1;
01687       } else
01688          if (option_verbose)
01689             ast_verbose("Set to high priority\n");
01690    } else {
01691       /* According to the manpage, these parameters can never fail. */
01692       setpriority(PRIO_PROCESS, 0, 0);
01693    }
01694 #endif
01695    return 0;
01696 }

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

References __ast_unregister_atexit(), AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_atexit::func.

Referenced by do_reload(), and unload_module().

01023 {
01024    AST_LIST_LOCK(&atexits);
01025    __ast_unregister_atexit(func);
01026    AST_LIST_UNLOCK(&atexits);
01027 }

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

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, and ast_atexit::list.

00354 {
00355    struct file_version *find;
00356 
00357    AST_RWLIST_WRLOCK(&file_versions);
00358    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00359       if (!strcasecmp(find->file, file)) {
00360          AST_RWLIST_REMOVE_CURRENT(list);
00361          break;
00362       }
00363    }
00364    AST_RWLIST_TRAVERSE_SAFE_END;
00365    AST_RWLIST_UNLOCK(&file_versions);
00366 
00367    if (find)
00368       ast_free(find);
00369 }

void mask_string ( char *  ,
int  ,
int  ,
int   
)

Provided by pbx.c

Definition at line 4650 of file pbx.c.

References ast_strlen_zero().

Referenced by AST_LIST_HEAD(), handle_verbose(), pbx_extension_helper(), and run_agi().

04650                                                           {
04651    char *val;
04652    int i;
04653 
04654    if (!findeq) {
04655       val = str;
04656    } else {
04657       val = strchr(str, '=');
04658       val++;
04659    }
04660    if (!ast_strlen_zero(val)) {
04661       if (strlen(val) >= ini) {
04662          for (i=0; i<strlen(val); i++) {
04663             if ((i>=ini-1) && (i<end))
04664                val[i] = 'X';
04665          }
04666       }
04667    }
04668 }


Variable Documentation

char agimaskvar[PATH_MAX]

Definition at line 201 of file asterisk.c.

Referenced by pbx_extension_helper().

Definition at line 202 of file asterisk.c.

Referenced by ast_readconfig(), handle_verbose(), pbx_extension_helper(), and run_agi().

Definition at line 202 of file asterisk.c.

Referenced by handle_verbose(), pbx_extension_helper(), and run_agi().

char readmaskvar[PATH_MAX]

Definition at line 199 of file asterisk.c.

Definition at line 200 of file asterisk.c.

Referenced by AST_LIST_HEAD(), and ast_readconfig().

Definition at line 200 of file asterisk.c.

Referenced by AST_LIST_HEAD().

char setmaskvar[PATH_MAX]

Definition at line 197 of file asterisk.c.

Referenced by pbx_extension_helper().

Definition at line 198 of file asterisk.c.

Referenced by ast_readconfig(), and pbx_extension_helper().

Definition at line 198 of file asterisk.c.

Referenced by pbx_extension_helper().


Generated on 7 Sep 2017 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1