46 #include <netinet/in.h> 76 #define INITIAL_NUM_FILES 8 144 #define MOH_QUIET (1 << 0) 145 #define MOH_SINGLE (1 << 1) 146 #define MOH_CUSTOM (1 << 2) 147 #define MOH_RANDOMIZE (1 << 3) 148 #define MOH_SORTALPHA (1 << 4) 149 #define MOH_RANDSTART (MOH_RANDOMIZE | MOH_SORTALPHA) 150 #define MOH_SORTMODE (3 << 3) 152 #define MOH_CACHERTCLASSES (1 << 5) 153 #define MOH_ANNOUNCEMENT (1 << 6) 154 #define MOH_PREFERCHANNELCLASS (1 << 7) 157 #define MOH_NOTDELETED (1 << 30) 158 #define MOH_REALTIME (1 << 31) 193 unsigned int delete:1;
208 #define LOCAL_MPG_123 "/usr/local/bin/mpg123" 209 #define MPG_123 "/usr/bin/mpg123" 215 #define mohclass_ref(class,string) (ao2_t_ref((class), +1, (string)), class) 218 #define mohclass_unref(class,string) ({ ao2_t_ref((class), -1, (string)); (struct mohclass *) NULL; }) 220 #define mohclass_unref(class,string) _mohclass_unref(class, string, __FILE__,__LINE__,__PRETTY_FUNCTION__) 226 if (
__ao2_ref(dup, -1, tag, file, line, funcname) == 2) {
227 ast_log(
LOG_WARNING,
"Attempt to unref mohclass %p (%s) when only 1 ref remained, and class is still in a container! (at %s:%d (%s))\n",
228 class,
class->
name, file, line, funcname);
233 __ao2_ref(
class, -1, tag, file, line, funcname);
244 ast_verb(3,
"Started music on hold, class '%s', on channel '%s'\n",
247 json_object =
ast_json_pack(
"{s: s}",
"class", moh_class_name);
316 struct ast_vector_string *files;
356 for (tries = 0; tries < 20; tries++) {
367 state->
pos %= file_count;
372 for (tries = 0; tries < file_count; ++tries) {
379 state->
pos %= file_count;
382 if (tries == file_count) {
399 if (state->
samples > loc && loc) {
507 if (!state && (state =
ast_calloc(1,
sizeof(*state)))) {
529 memset(state, 0,
sizeof(*state));
565 const char *classname =
NULL;
569 class =
mohclass_unref(class, "Unreffing ao2_find from finding by digit");
570 ast_channel_musicclass_set(chan, classname);
597 if (!strcasecmp(
class->
dir,
"nodir")) {
601 if (!dir && strncasecmp(
class->
dir,
"http://", 7)) {
608 argv[argc++] =
"mpg123";
611 argv[argc++] =
"--mono";
613 argv[argc++] =
"8000";
617 argv[argc++] =
"2048";
623 argv[argc++] =
"4096";
625 argv[argc++] =
"8192";
631 argv[argc++] = argptr;
639 argv[argc++] = argptr;
644 if (!strncasecmp(
class->
dir,
"http://", 7)) {
646 argv[argc++] = fns[files];
649 while ((de = readdir(dir)) && (files <
MAX_MP3S)) {
650 if ((strlen(de->d_name) > 3) &&
652 (!strcasecmp(de->d_name + strlen(de->d_name) - 4,
".raw") ||
653 !strcasecmp(de->d_name + strlen(de->d_name) - 4,
".sln"))) ||
654 !strcasecmp(de->d_name + strlen(de->d_name) - 4,
".mp3"))) {
656 argv[argc++] = fns[files];
693 dup2(fds[1], STDOUT_FILENO);
703 setpgid(0, getpid());
705 execv(argv[0], argv);
712 execvp(
"mpg123", argv);
715 fprintf(stderr,
"MOH: exec failed: %s\n", strerror(
errno));
727 switch (kill_method) {
729 return killpg(pid, signum);
731 return kill(pid, signum);
739 if (
killer(pid, SIGHUP, kill_method) < 0) {
740 if (
errno == ESRCH) {
745 ast_debug(1,
"Sent HUP to pid %d%s\n", pid,
749 if (
killer(pid, SIGTERM, kill_method) < 0) {
750 if (
errno == ESRCH) {
755 ast_debug(1,
"Sent TERM to pid %d%s\n", pid,
759 if (
killer(pid, SIGKILL, kill_method) < 0) {
760 if (
errno == ESRCH) {
765 ast_debug(1,
"Sent KILL to pid %d%s\n", pid,
772 #define MOH_MS_INTERVAL 100 779 struct timeval deadline, tv_tmp;
782 deadline.tv_usec = 0;
784 pthread_testcancel();
812 pthread_testcancel();
823 pthread_testcancel();
839 if ((res2 = read(
class->
srcfd, sbuf, len)) != len) {
843 pthread_testcancel();
849 ast_debug(1,
"Read %d bytes of audio while expecting %d\n", res2, len);
854 pthread_testcancel();
859 if ((res = write(moh->
pipe[1], sbuf, res2)) != res2) {
860 ast_debug(1,
"Only wrote %d of %d bytes to pipe\n", res, res2);
884 if (sscanf(
args.duration,
"%30d", &timeout) == 1) {
891 class =
S_OR(args.class, NULL);
920 class =
S_OR(args.class, NULL);
934 #define get_mohbyname(a,b,c) _get_mohbyname(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__) 945 moh =
__ao2_find(mohclasses, &tmp_class, flags,
946 "get_mohbyname", file, lineno, funcname);
949 ast_log(
LOG_WARNING,
"Music on Hold class '%s' not found in memory. Verify your configuration.\n", name);
984 struct mohclass *
class = moh->parent;
996 moh->
parent =
class =
mohclass_unref(class, "unreffing moh->parent upon deactivation of generator");
1004 if (state && state->
class) {
1026 if (!state && (state =
ast_calloc(1,
sizeof(*state)))) {
1039 memset(state, 0,
sizeof(*state));
1094 struct ast_vector_string *files = obj;
1102 sizeof(
struct ast_vector_string),
1113 struct ast_vector_string *playlist_entries =
NULL;
1115 for (;
var; var = var->
next) {
1116 if (!strcasecmp(var->
name,
"name")) {
1118 }
else if (!strcasecmp(var->
name,
"mode")) {
1120 }
else if (!strcasecmp(var->
name,
"entry")) {
1124 if (!playlist_entries) {
1126 if (!playlist_entries) {
1137 char *last_pos_dot = strrchr(dup,
'.');
1138 char *last_pos_slash = strrchr(dup,
'/');
1139 if (last_pos_dot && last_pos_dot > last_pos_slash) {
1140 ast_log(
LOG_WARNING,
"The playlist entry '%s' may include an extension, which could prevent it from playing.\n",
1147 ast_log(
LOG_ERROR,
"Playlist entries must be a URL or an absolute path, '%s' provided.\n", var->
value);
1149 }
else if (!strcasecmp(var->
name,
"directory")) {
1151 }
else if (!strcasecmp(var->
name,
"application")) {
1153 }
else if (!strcasecmp(var->
name,
"announcement")) {
1156 }
else if (!strcasecmp(var->
name,
"digit") && (isdigit(*var->
value) || strchr(
"*#", *var->
value))) {
1158 }
else if (!strcasecmp(var->
name,
"random")) {
1159 static int deprecation_warning = 0;
1160 if (!deprecation_warning) {
1161 ast_log(
LOG_WARNING,
"Music on hold 'random' setting is deprecated in 14. Please use 'sort=random' instead.\n");
1162 deprecation_warning = 1;
1165 }
else if (!strcasecmp(var->
name,
"sort")) {
1166 if (!strcasecmp(var->
value,
"random")) {
1168 }
else if (!strcasecmp(var->
value,
"alpha")) {
1170 }
else if (!strcasecmp(var->
value,
"randstart")) {
1180 }
else if (!strcasecmp(var->
name,
"kill_escalation_delay")) {
1187 }
else if (!strcasecmp(var->
name,
"kill_method")) {
1188 if (!strcasecmp(var->
value,
"process")) {
1190 }
else if (!strcasecmp(var->
value,
"process_group")) {
1199 if (playlist_entries) {
1201 if (strcasecmp(mohclass->
mode,
"playlist")) {
1204 ao2_ref(playlist_entries, -1);
1213 mohclass->
files = playlist_entries;
1217 static int on_moh_file(
const char *directory,
const char *filename,
void *obj)
1219 struct ast_vector_string *files = obj;
1224 if (*filename ==
'.') {
1225 ast_debug(4,
"Skipping '%s/%s' because it starts with a dot\n",
1226 directory, filename);
1232 extension = strrchr(filename,
'.');
1234 ast_debug(4,
"Skipping '%s/%s' because it doesn't have an extension\n",
1235 directory, filename);
1240 if (strlen(extension) < 3) {
1241 ast_debug(4,
"Skipping '%s/%s' because it doesn't have at least a two " 1242 "character extension\n", directory, filename);
1249 (
int) (extension - filename), filename) < 0) {
1274 const char **s1 = (
const char **) a;
1275 const char **s2 = (
const char **) b;
1276 return strcasecmp(*s1, *s2);
1281 char dir_path[
PATH_MAX -
sizeof(
class->dir)];
1282 struct ast_vector_string *files;
1311 class->files = files;
1328 ast_verb(3,
"Files not found in %s for moh class:%s\n",
1343 if (!strcasecmp(c->
mode,
"files")) {
1358 if (strcmp(old->
dir, new->dir)) {
1360 }
else if (strcmp(old->
mode, new->mode)) {
1362 }
else if (strcmp(old->
args, new->args)) {
1364 }
else if (old->
flags != new->flags) {
1373 if (!strcasecmp(
class->
mode,
"custom")) {
1375 }
else if (!strcasecmp(
class->
mode,
"mp3nb")) {
1377 }
else if (!strcasecmp(
class->
mode,
"quietmp3nb")) {
1379 }
else if (!strcasecmp(
class->
mode,
"quietmp3")) {
1392 class->timer =
NULL;
1399 class->timer =
NULL;
1410 #define moh_register(moh, reload, unref) _moh_register(moh, reload, unref, __FILE__, __LINE__, __PRETTY_FUNCTION__) 1417 if (mohclass && !
moh_diff(mohclass, moh)) {
1419 mohclass =
mohclass_unref(mohclass,
"unreffing mohclass we just found by name");
1421 moh =
mohclass_unref(moh,
"unreffing potential new moh class (it is a duplicate)");
1424 }
else if (mohclass) {
1426 mohclass =
mohclass_unref(mohclass,
"unreffing mohclass we just found by name");
1432 if (!strcasecmp(moh->
mode,
"files")) {
1435 moh =
mohclass_unref(moh,
"unreffing potential new moh class (init_files_class failed)");
1439 }
else if (!strcasecmp(moh->
mode,
"playlist")) {
1448 moh =
mohclass_unref(moh,
"unreffing potential new moh class (no playlist entries)");
1452 }
else if (!strcasecmp(moh->
mode,
"mp3") || !strcasecmp(moh->
mode,
"mp3nb") ||
1453 !strcasecmp(moh->
mode,
"quietmp3") || !strcasecmp(moh->
mode,
"quietmp3nb") ||
1454 !strcasecmp(moh->
mode,
"httpmp3") || !strcasecmp(moh->
mode,
"custom")) {
1457 moh =
mohclass_unref(moh,
"unreffing potential new moh class (init_app_class_failed)");
1464 moh =
mohclass_unref(moh,
"unreffing potential new moh class (unknown mode)");
1469 ao2_t_link(mohclasses, moh,
"Adding class to container");
1472 moh =
mohclass_unref(moh,
"Unreffing new moh class because we just added it to the container");
1478 #define moh_unregister(a) _moh_unregister(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) 1481 ao2_t_unlink(mohclasses, moh,
"Removing class from container");
1515 int wordlen = strlen(word);
1524 if (cur->
realtime && !strncasecmp(cur->
name, word, wordlen) && ++which > state) {
1545 e->
command =
"moh unregister class";
1547 "Usage: moh unregister class <class>\n" 1548 " Unregisters a realtime moh class.\n";
1557 len = strlen(a->
argv[3]);
1573 ast_cli(a->
fd,
"No such realtime moh class '%s'\n", a->
argv[3]);
1583 #define moh_class_malloc() _moh_class_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__) 1590 "Allocating new moh class", file, line, funcname);
1594 class->kill_delay = 100000;
1615 char *category =
NULL;
1616 size_t entry_count = 0;
1634 if (entry_count == 0) {
1644 "Music on Hold class '%s' not found in memory/database. " 1645 "Verify your configuration.\n",
1659 int warn_if_not_in_memory = !realtime_possible;
1660 const char *classes[] = {
NULL,
NULL, interpclass,
"default"};
1664 classes[1] = mclass;
1666 classes[0] = mclass;
1685 for (i = 0; i <
ARRAY_LEN(classes); ++i) {
1687 mohclass =
get_mohbyname(classes[i], warn_if_not_in_memory, 0);
1688 if (!mohclass && realtime_possible) {
1691 if (mohclass || var) {
1708 if (!strcasecmp(mohclass->
mode,
"custom") || !strcasecmp(mohclass->
mode,
"playlist")) {
1709 strcpy(mohclass->
dir,
"nodir");
1712 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (no directory specified)");
1718 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (no mode specified)");
1723 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (no app specified for custom mode");
1729 if (state && state->
class) {
1740 mohclass =
mohclass_unref(mohclass,
"unreffing mohclass failed to register");
1746 time(&mohclass->
start);
1749 if (!strcasecmp(mohclass->
mode,
"files")) {
1759 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (moh_scan_files failed)");
1762 if (strchr(mohclass->
args,
'r')) {
1763 static int deprecation_warning = 0;
1764 if (!deprecation_warning) {
1765 ast_log(
LOG_WARNING,
"Music on hold 'application=r' setting is deprecated in 14. Please use 'sort=random' instead.\n");
1766 deprecation_warning = 1;
1770 }
else if (!strcasecmp(mohclass->
mode,
"playlist")) {
1778 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (no playlist entries)");
1781 }
else if (!strcasecmp(mohclass->
mode,
"mp3") || !strcasecmp(mohclass->
mode,
"mp3nb") || !strcasecmp(mohclass->
mode,
"quietmp3") || !strcasecmp(mohclass->
mode,
"quietmp3nb") || !strcasecmp(mohclass->
mode,
"httpmp3") || !strcasecmp(mohclass->
mode,
"custom")) {
1783 if (!strcasecmp(mohclass->
mode,
"custom"))
1785 else if (!strcasecmp(mohclass->
mode,
"mp3nb"))
1787 else if (!strcasecmp(mohclass->
mode,
"quietmp3nb"))
1789 else if (!strcasecmp(mohclass->
mode,
"quietmp3"))
1792 mohclass->
srcfd = -1;
1803 if (state && state->
class) {
1808 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (channel already has one)");
1814 if (mohclass->
timer) {
1818 mohclass =
mohclass_unref(mohclass,
"Unreffing potential mohclass (failed to create background thread)");
1824 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (unknown mode)");
1848 mohclass =
mohclass_unref(mohclass,
"unreffing potential mohclass (moh_scan_files failed)");
1868 ast_channel_latest_musicclass_set(chan, mohclass->
name);
1873 mohclass =
mohclass_unref(mohclass,
"unreffing local reference to mohclass in local_ast_moh_start");
1911 tid =
class->thread;
1913 pthread_cancel(tid);
1920 int bytes, tbytes = 0, stime = 0;
1924 stime = time(
NULL) + 2;
1928 (bytes = read(
class->
srcfd, buff, 8192)) && time(
NULL) < stime) {
1929 tbytes = tbytes + bytes;
1932 ast_debug(1,
"mpg123 pid %d and child died after %d bytes read\n",
1942 class->timer =
NULL;
1949 pthread_join(tid,
NULL);
2010 if (!strcasecmp(cat,
"general")) {
2012 if (!strcasecmp(var->
name,
"cachertclasses")) {
2014 }
else if (!strcasecmp(var->
name,
"preferchannelclass")) {
2037 class =
mohclass_unref(class, "unreffing potential mohclass (no directory)");
2043 class =
mohclass_unref(class, "unreffing potential mohclass (no mode)");
2048 class =
mohclass_unref(class, "unreffing potential mohclass (no app for custom mode)");
2068 ast_verb(2,
"Destroying musiconhold processes\n");
2082 "Usage: moh reload\n" 2083 " Reloads the MusicOnHold module.\n" 2084 " Alias for 'module reload res_musiconhold.so'\n";
2106 e->
command =
"moh show files";
2108 "Usage: moh show files\n" 2109 " Lists all loaded file-based MusicOnHold classes and their\n" 2121 struct ast_vector_string *files;
2149 e->
command =
"moh show classes";
2151 "Usage: moh show classes\n" 2152 " Lists all MusicOnHold classes.\n";
2193 const struct mohclass *
class = obj;
2200 struct mohclass *
class = obj, *class2 = arg;
2202 return strcasecmp(
class->
name, class2->name) ? 0 :
2229 "disabling music on hold.\n");
2271 class =
mohclass_unref(class, "unref of class from module unload callback");
2276 ast_log(
LOG_WARNING,
"Unable to unload res_musiconhold due to active MOH channels\n");
static int _moh_register(struct mohclass *moh, int reload, int unref, const char *file, int line, const char *funcname)
static int stop_moh_exec(struct ast_channel *chan, const char *data)
static struct ao2_container * mohclasses
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
struct ast_variable * ast_load_realtime(const char *family,...) attribute_sentinel
struct ast_variable * next
static void moh_release(struct ast_channel *chan, void *data)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
enum sip_cc_notify_state state
#define ast_channel_lock(chan)
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
char name[MAX_MUSICCLASS]
static struct ast_frame * moh_files_readframe(struct ast_channel *chan)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static int init_files_class(struct mohclass *class)
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
static int moh_digit_match(void *obj, void *arg, int flags)
static const char stop_moh[]
static void moh_post_start(struct ast_channel *chan, const char *moh_class_name)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
static int moh_files_generator(struct ast_channel *chan, void *data, int len, int samples)
static int moh_classes_delete_marked(void *obj, void *arg, int flags)
void *(* alloc)(struct ast_channel *chan, void *params)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
void * __ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
#define ast_pipe_nonblock(filedes)
Create a non-blocking pipe.
static int start_moh_exec(struct ast_channel *chan, const char *data)
#define ast_set2_flag(p, value, flag)
#define ast_test_flag(p, flag)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
static void moh_post_stop(struct ast_channel *chan)
Support for translation of data formats. translate.c.
#define moh_register(moh, reload, unref)
Time-related functions and macros.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
static int load_moh_classes(int reload)
struct mohdata::@467 list
struct stasis_message_type * ast_channel_moh_start_type(void)
Message type for starting music on hold on a channel.
#define ast_set_flag(p, flag)
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
descriptor for a cli entry.
#define ao2_callback(c, flags, cb_fn, arg)
#define CONFIG_STATUS_FILEINVALID
static struct ast_cli_entry cli_moh[]
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
Structure for variables, used for configurations and for channel variables.
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
static char * handle_cli_moh_unregister_class(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct ast_format * origwfmt
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
static int init_app_class(struct mohclass *class)
#define ao2_t_link(container, obj, tag)
Add an object to a container.
struct ast_timer * ast_timer_open(void)
Open a timer.
static int on_moh_file(const char *directory, const char *filename, void *obj)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define ao2_t_unlink(container, obj, tag)
Remove an object from a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define AST_VECTOR_COMPACT(vec)
Resize a vector so that its capacity is the same as its size.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct ast_filestream * ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis)
Opens stream for use in seeking, playing.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define ao2_alloc_options(data_size, destructor_fn, options)
static void * moh_files_alloc(struct ast_channel *chan, void *params)
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
void ast_channel_music_state_set(struct ast_channel *chan, void *value)
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
static int killer(pid_t pid, int signum, enum kill_methods kill_method)
void ast_cli(int fd, const char *fmt,...)
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
static struct mohclass * _moh_class_malloc(const char *file, int line, const char *funcname)
int ast_unregister_application(const char *app)
Unregister an application.
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
static void ast_moh_destroy(void)
static int moh_scan_files(struct mohclass *class)
#define ast_verb(level,...)
static struct mohdata * mohalloc(struct mohclass *cl)
void ast_uninstall_music_functions(void)
#define mohclass_ref(class, string)
#define AST_VECTOR_SORT(vec, cmp)
Sort a vector in-place.
struct ast_frame_subclass subclass
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Blob of data associated with a channel.
int args
This gets set in ast_cli_register()
static void local_ast_moh_cleanup(struct ast_channel *chan)
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_strlen_zero(foo)
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
#define ast_pthread_create_background(a, b, c, d)
static void moh_rescan_files(void)
Configuration File Parser.
static void local_ast_moh_stop(struct ast_channel *chan)
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
#define ast_debug(level,...)
Log a DEBUG message.
char save_pos_filename[PATH_MAX]
#define ast_config_load(filename, flags)
Load a config file.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
General Asterisk PBX channel definitions.
Asterisk file paths, configured in asterisk.conf.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
void ast_unregister_atexit(void(*func)(void))
Unregister a function registered with ast_register_atexit().
static int moh_filename_strcasecmp(const void *a, const void *b)
#define MOH_CACHERTCLASSES
#define AST_PTHREADT_NULL
#define ast_poll(a, b, c)
static char * handle_cli_moh_show_classes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void killpid(int pid, size_t delay, enum kill_methods kill_method)
structure to hold extensions
#define ao2_ref(o, delta)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
long int ast_random(void)
static struct mohclass * _get_mohbyname(const char *name, int warn, int flags, const char *file, int lineno, const char *funcname)
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
#define ast_strdupa(s)
duplicate a string in memory from the stack
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
A set of macros to manage forward-linked lists.
static void moh_handle_digit(struct ast_channel *chan, char digit)
static int moh_class_inuse(void *obj, void *arg, int flags)
static void moh_files_write_format_change(struct ast_channel *chan, void *data)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
#define ast_variable_new(name, value, filename)
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define MOH_PREFERCHANNELCLASS
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
static char * handle_cli_moh_show_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct ast_vector_string * files
Core PBX routines and definitions.
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
#define CONFIG_STATUS_FILEUNCHANGED
static int moh_diff(struct mohclass *old, struct mohclass *new)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
static const char start_moh[]
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
const char * ast_config_AST_DATA_DIR
struct ast_config * ast_load_realtime_multientry(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
static int play_moh_exec(struct ast_channel *chan, const char *data)
static struct mohclass * _mohclass_unref(struct mohclass *class, const char *tag, const char *file, int line, const char *funcname)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
static int unload_module(void)
static void moh_files_release(struct ast_channel *chan, void *data)
#define ao2_t_iterator_next(iter, tag)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
static int moh_class_cmp(void *obj, void *arg, int flags)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
static struct ast_generator moh_file_stream
#define ao2_iterator_next(iter)
#define moh_unregister(a)
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define ast_channel_unlock(chan)
static void parse(struct mgcp_request *req)
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
int ao2_match_by_addr(void *obj, void *arg, int flags)
A common ao2_callback is one that matches by address.
#define ast_calloc(num, len)
A wrapper for calloc()
struct ast_format * mohwfmt
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
int ast_closestream(struct ast_filestream *f)
Closes a stream.
static int moh_generate(struct ast_channel *chan, void *data, int len, int samples)
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
struct ast_format * format
#define ao2_t_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn, tag)
Allocate and initialize a hash container with the desired number of buckets.
enum kill_methods kill_method
void ast_install_music_functions(int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *))
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Module has failed to load, may be in an inconsistent state.
static int _moh_unregister(struct mohclass *moh, const char *file, int line, const char *funcname)
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
#define AST_VECTOR_GET_CMP(vec, value, cmp)
Get an element from a vector that matches the given comparison.
static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass)
Structure used to handle boolean flags.
struct mohclass::@465 members
#define ast_clear_flag(p, flag)
static void moh_file_vector_destructor(void *obj)
static struct ast_flags global_flags[1]
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
#define CONFIG_STATUS_FILEMISSING
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
static int moh_class_mark(void *obj, void *arg, int flags)
void ast_deactivate_generator(struct ast_channel *chan)
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
struct ast_format * origwfmt
char * strsep(char **str, const char *delims)
static int moh_class_hash(const void *obj, const int flags)
#define ao2_replace(dst, src)
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static unsigned char * buff
const char * ast_channel_name(const struct ast_channel *chan)
static struct ast_variable * load_realtime_musiconhold(const char *name)
static void moh_class_destructor(void *obj)
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
static char * handle_cli_moh_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
void * ast_channel_music_state(const struct ast_channel *chan)
Data structure associated with a single frame of data.
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
const char * ast_channel_language(const struct ast_channel *chan)
Abstract JSON element (object, array, string, int, ...).
#define mohclass_unref(class, string)
union ast_frame::@263 data
int ast_wait_for_input(int fd, int ms)
enum ast_frame_type frametype
static const char play_moh[]
static char * complete_mohclass_realtime(const char *line, const char *word, int pos, int state)
Support routing for 'moh unregister class' CLI This is in charge of generating all strings that match...
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct stasis_message_type * ast_channel_moh_stop_type(void)
Message type for stopping music on hold on a channel.
struct ast_format * format
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
static struct ast_generator mohgen
static struct mohclass * get_mohbydigit(char digit)
#define ast_file_read_dir(dir_name, on_file, obj)
Iterate over each file in a given directory.
char name[MAX_MUSICCLASS]
static void * monmp3thread(void *data)
static void * moh_alloc(struct ast_channel *chan, void *params)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define moh_class_malloc()
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
static int ast_moh_files_next(struct ast_channel *chan)
static int load_module(void)
Load the module.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Timing source management.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ast_variable_list_append(head, new_var)
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
#define get_mohbyname(a, b, c)
static struct ast_vector_string * moh_file_vector_alloc(int initial_capacity)
const char * ast_channel_musicclass(const struct ast_channel *chan)
#define ast_opt_high_priority
#define AST_APP_ARG(name)
Define an application argument.
static int spawn_mp3(struct mohclass *class)
#define ast_module_ref(mod)
Hold a reference to the module.