app_amd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2003 - 2006, Aheeva Technology.
  5. *
  6. * Claude Klimos (claude.klimos@aheeva.com)
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. *
  18. * A license has been granted to Digium (via disclaimer) for the use of
  19. * this code.
  20. */
  21. /*! \file
  22. *
  23. * \brief Answering machine detection
  24. *
  25. * \author Claude Klimos (claude.klimos@aheeva.com)
  26. *
  27. * \ingroup applications
  28. */
  29. /*! \li \ref app_amd.c uses the configuration file \ref amd.conf
  30. * \addtogroup configuration_file Configuration Files
  31. */
  32. /*!
  33. * \page amd.conf amd.conf
  34. * \verbinclude amd.conf.sample
  35. */
  36. /*** MODULEINFO
  37. <support_level>extended</support_level>
  38. ***/
  39. #include "asterisk.h"
  40. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  41. #include "asterisk/module.h"
  42. #include "asterisk/lock.h"
  43. #include "asterisk/channel.h"
  44. #include "asterisk/dsp.h"
  45. #include "asterisk/pbx.h"
  46. #include "asterisk/config.h"
  47. #include "asterisk/app.h"
  48. #include "asterisk/format_cache.h"
  49. /*** DOCUMENTATION
  50. <application name="AMD" language="en_US">
  51. <synopsis>
  52. Attempt to detect answering machines.
  53. </synopsis>
  54. <syntax>
  55. <parameter name="initialSilence" required="false">
  56. <para>Is maximum initial silence duration before greeting.</para>
  57. <para>If this is exceeded set as MACHINE</para>
  58. </parameter>
  59. <parameter name="greeting" required="false">
  60. <para>is the maximum length of a greeting.</para>
  61. <para>If this is exceeded set as MACHINE</para>
  62. </parameter>
  63. <parameter name="afterGreetingSilence" required="false">
  64. <para>Is the silence after detecting a greeting.</para>
  65. <para>If this is exceeded set as HUMAN</para>
  66. </parameter>
  67. <parameter name="totalAnalysis Time" required="false">
  68. <para>Is the maximum time allowed for the algorithm</para>
  69. <para>to decide HUMAN or MACHINE</para>
  70. </parameter>
  71. <parameter name="miniumWordLength" required="false">
  72. <para>Is the minimum duration of Voice considered to be a word</para>
  73. </parameter>
  74. <parameter name="betweenWordSilence" required="false">
  75. <para>Is the minimum duration of silence after a word to
  76. consider the audio that follows to be a new word</para>
  77. </parameter>
  78. <parameter name="maximumNumberOfWords" required="false">
  79. <para>Is the maximum number of words in a greeting</para>
  80. <para>If this is exceeded set as MACHINE</para>
  81. </parameter>
  82. <parameter name="silenceThreshold" required="false">
  83. <para>How long do we consider silence</para>
  84. </parameter>
  85. <parameter name="maximumWordLength" required="false">
  86. <para>Is the maximum duration of a word to accept.</para>
  87. <para>If exceeded set as MACHINE</para>
  88. </parameter>
  89. </syntax>
  90. <description>
  91. <para>This application attempts to detect answering machines at the beginning
  92. of outbound calls. Simply call this application after the call
  93. has been answered (outbound only, of course).</para>
  94. <para>When loaded, AMD reads amd.conf and uses the parameters specified as
  95. default values. Those default values get overwritten when the calling AMD
  96. with parameters.</para>
  97. <para>This application sets the following channel variables:</para>
  98. <variablelist>
  99. <variable name="AMDSTATUS">
  100. <para>This is the status of the answering machine detection</para>
  101. <value name="MACHINE" />
  102. <value name="HUMAN" />
  103. <value name="NOTSURE" />
  104. <value name="HANGUP" />
  105. </variable>
  106. <variable name="AMDCAUSE">
  107. <para>Indicates the cause that led to the conclusion</para>
  108. <value name="TOOLONG">
  109. Total Time.
  110. </value>
  111. <value name="INITIALSILENCE">
  112. Silence Duration - Initial Silence.
  113. </value>
  114. <value name="HUMAN">
  115. Silence Duration - afterGreetingSilence.
  116. </value>
  117. <value name="LONGGREETING">
  118. Voice Duration - Greeting.
  119. </value>
  120. <value name="MAXWORDLENGTH">
  121. Word Count - maximum number of words.
  122. </value>
  123. </variable>
  124. </variablelist>
  125. </description>
  126. <see-also>
  127. <ref type="application">WaitForSilence</ref>
  128. <ref type="application">WaitForNoise</ref>
  129. </see-also>
  130. </application>
  131. ***/
  132. static const char app[] = "AMD";
  133. #define STATE_IN_WORD 1
  134. #define STATE_IN_SILENCE 2
  135. /* Some default values for the algorithm parameters. These defaults will be overwritten from amd.conf */
  136. static int dfltInitialSilence = 2500;
  137. static int dfltGreeting = 1500;
  138. static int dfltAfterGreetingSilence = 800;
  139. static int dfltTotalAnalysisTime = 5000;
  140. static int dfltMinimumWordLength = 100;
  141. static int dfltBetweenWordsSilence = 50;
  142. static int dfltMaximumNumberOfWords = 3;
  143. static int dfltSilenceThreshold = 256;
  144. static int dfltMaximumWordLength = 5000; /* Setting this to a large default so it is not used unless specify it in the configs or command line */
  145. /* Set to the lowest ms value provided in amd.conf or application parameters */
  146. static int dfltMaxWaitTimeForFrame = 50;
  147. static void isAnsweringMachine(struct ast_channel *chan, const char *data)
  148. {
  149. int res = 0;
  150. struct ast_frame *f = NULL;
  151. struct ast_dsp *silenceDetector = NULL;
  152. int dspsilence = 0, framelength = 0;
  153. RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);
  154. int inInitialSilence = 1;
  155. int inGreeting = 0;
  156. int voiceDuration = 0;
  157. int silenceDuration = 0;
  158. int iTotalTime = 0;
  159. int iWordsCount = 0;
  160. int currentState = STATE_IN_WORD;
  161. int consecutiveVoiceDuration = 0;
  162. char amdCause[256] = "", amdStatus[256] = "";
  163. char *parse = ast_strdupa(data);
  164. /* Lets set the initial values of the variables that will control the algorithm.
  165. The initial values are the default ones. If they are passed as arguments
  166. when invoking the application, then the default values will be overwritten
  167. by the ones passed as parameters. */
  168. int initialSilence = dfltInitialSilence;
  169. int greeting = dfltGreeting;
  170. int afterGreetingSilence = dfltAfterGreetingSilence;
  171. int totalAnalysisTime = dfltTotalAnalysisTime;
  172. int minimumWordLength = dfltMinimumWordLength;
  173. int betweenWordsSilence = dfltBetweenWordsSilence;
  174. int maximumNumberOfWords = dfltMaximumNumberOfWords;
  175. int silenceThreshold = dfltSilenceThreshold;
  176. int maximumWordLength = dfltMaximumWordLength;
  177. int maxWaitTimeForFrame = dfltMaxWaitTimeForFrame;
  178. AST_DECLARE_APP_ARGS(args,
  179. AST_APP_ARG(argInitialSilence);
  180. AST_APP_ARG(argGreeting);
  181. AST_APP_ARG(argAfterGreetingSilence);
  182. AST_APP_ARG(argTotalAnalysisTime);
  183. AST_APP_ARG(argMinimumWordLength);
  184. AST_APP_ARG(argBetweenWordsSilence);
  185. AST_APP_ARG(argMaximumNumberOfWords);
  186. AST_APP_ARG(argSilenceThreshold);
  187. AST_APP_ARG(argMaximumWordLength);
  188. );
  189. ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan),
  190. S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, "(N/A)"),
  191. S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "(N/A)"),
  192. ast_format_get_name(ast_channel_readformat(chan)));
  193. /* Lets parse the arguments. */
  194. if (!ast_strlen_zero(parse)) {
  195. /* Some arguments have been passed. Lets parse them and overwrite the defaults. */
  196. AST_STANDARD_APP_ARGS(args, parse);
  197. if (!ast_strlen_zero(args.argInitialSilence))
  198. initialSilence = atoi(args.argInitialSilence);
  199. if (!ast_strlen_zero(args.argGreeting))
  200. greeting = atoi(args.argGreeting);
  201. if (!ast_strlen_zero(args.argAfterGreetingSilence))
  202. afterGreetingSilence = atoi(args.argAfterGreetingSilence);
  203. if (!ast_strlen_zero(args.argTotalAnalysisTime))
  204. totalAnalysisTime = atoi(args.argTotalAnalysisTime);
  205. if (!ast_strlen_zero(args.argMinimumWordLength))
  206. minimumWordLength = atoi(args.argMinimumWordLength);
  207. if (!ast_strlen_zero(args.argBetweenWordsSilence))
  208. betweenWordsSilence = atoi(args.argBetweenWordsSilence);
  209. if (!ast_strlen_zero(args.argMaximumNumberOfWords))
  210. maximumNumberOfWords = atoi(args.argMaximumNumberOfWords);
  211. if (!ast_strlen_zero(args.argSilenceThreshold))
  212. silenceThreshold = atoi(args.argSilenceThreshold);
  213. if (!ast_strlen_zero(args.argMaximumWordLength))
  214. maximumWordLength = atoi(args.argMaximumWordLength);
  215. } else {
  216. ast_debug(1, "AMD using the default parameters.\n");
  217. }
  218. /* Find lowest ms value, that will be max wait time for a frame */
  219. if (maxWaitTimeForFrame > initialSilence)
  220. maxWaitTimeForFrame = initialSilence;
  221. if (maxWaitTimeForFrame > greeting)
  222. maxWaitTimeForFrame = greeting;
  223. if (maxWaitTimeForFrame > afterGreetingSilence)
  224. maxWaitTimeForFrame = afterGreetingSilence;
  225. if (maxWaitTimeForFrame > totalAnalysisTime)
  226. maxWaitTimeForFrame = totalAnalysisTime;
  227. if (maxWaitTimeForFrame > minimumWordLength)
  228. maxWaitTimeForFrame = minimumWordLength;
  229. if (maxWaitTimeForFrame > betweenWordsSilence)
  230. maxWaitTimeForFrame = betweenWordsSilence;
  231. /* Now we're ready to roll! */
  232. ast_verb(3, "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
  233. "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d] \n",
  234. initialSilence, greeting, afterGreetingSilence, totalAnalysisTime,
  235. minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold, maximumWordLength);
  236. /* Set read format to signed linear so we get signed linear frames in */
  237. readFormat = ao2_bump(ast_channel_readformat(chan));
  238. if (ast_set_read_format(chan, ast_format_slin) < 0 ) {
  239. ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", ast_channel_name(chan));
  240. pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
  241. pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
  242. return;
  243. }
  244. /* Create a new DSP that will detect the silence */
  245. if (!(silenceDetector = ast_dsp_new())) {
  246. ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to create silence detector :(\n", ast_channel_name(chan));
  247. pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
  248. pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
  249. return;
  250. }
  251. /* Set silence threshold to specified value */
  252. ast_dsp_set_threshold(silenceDetector, silenceThreshold);
  253. /* Now we go into a loop waiting for frames from the channel */
  254. while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
  255. /* If we fail to read in a frame, that means they hung up */
  256. if (!(f = ast_read(chan))) {
  257. ast_verb(3, "AMD: Channel [%s]. HANGUP\n", ast_channel_name(chan));
  258. ast_debug(1, "Got hangup\n");
  259. strcpy(amdStatus, "HANGUP");
  260. res = 1;
  261. break;
  262. }
  263. if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
  264. /* If the total time exceeds the analysis time then give up as we are not too sure */
  265. if (f->frametype == AST_FRAME_VOICE) {
  266. framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
  267. } else {
  268. framelength = 2 * maxWaitTimeForFrame;
  269. }
  270. iTotalTime += framelength;
  271. if (iTotalTime >= totalAnalysisTime) {
  272. ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
  273. ast_frfree(f);
  274. strcpy(amdStatus , "NOTSURE");
  275. sprintf(amdCause , "TOOLONG-%d", iTotalTime);
  276. break;
  277. }
  278. /* Feed the frame of audio into the silence detector and see if we get a result */
  279. if (f->frametype != AST_FRAME_VOICE)
  280. dspsilence += 2 * maxWaitTimeForFrame;
  281. else {
  282. dspsilence = 0;
  283. ast_dsp_silence(silenceDetector, f, &dspsilence);
  284. }
  285. if (dspsilence > 0) {
  286. silenceDuration = dspsilence;
  287. if (silenceDuration >= betweenWordsSilence) {
  288. if (currentState != STATE_IN_SILENCE ) {
  289. ast_verb(3, "AMD: Channel [%s]. Changed state to STATE_IN_SILENCE\n", ast_channel_name(chan));
  290. }
  291. /* Find words less than word duration */
  292. if (consecutiveVoiceDuration < minimumWordLength && consecutiveVoiceDuration > 0){
  293. ast_verb(3, "AMD: Channel [%s]. Short Word Duration: %d\n", ast_channel_name(chan), consecutiveVoiceDuration);
  294. }
  295. currentState = STATE_IN_SILENCE;
  296. consecutiveVoiceDuration = 0;
  297. }
  298. if (inInitialSilence == 1 && silenceDuration >= initialSilence) {
  299. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: silenceDuration:%d initialSilence:%d\n",
  300. ast_channel_name(chan), silenceDuration, initialSilence);
  301. ast_frfree(f);
  302. strcpy(amdStatus , "MACHINE");
  303. sprintf(amdCause , "INITIALSILENCE-%d-%d", silenceDuration, initialSilence);
  304. res = 1;
  305. break;
  306. }
  307. if (silenceDuration >= afterGreetingSilence && inGreeting == 1) {
  308. ast_verb(3, "AMD: Channel [%s]. HUMAN: silenceDuration:%d afterGreetingSilence:%d\n",
  309. ast_channel_name(chan), silenceDuration, afterGreetingSilence);
  310. ast_frfree(f);
  311. strcpy(amdStatus , "HUMAN");
  312. sprintf(amdCause , "HUMAN-%d-%d", silenceDuration, afterGreetingSilence);
  313. res = 1;
  314. break;
  315. }
  316. } else {
  317. consecutiveVoiceDuration += framelength;
  318. voiceDuration += framelength;
  319. /* If I have enough consecutive voice to say that I am in a Word, I can only increment the
  320. number of words if my previous state was Silence, which means that I moved into a word. */
  321. if (consecutiveVoiceDuration >= minimumWordLength && currentState == STATE_IN_SILENCE) {
  322. iWordsCount++;
  323. ast_verb(3, "AMD: Channel [%s]. Word detected. iWordsCount:%d\n", ast_channel_name(chan), iWordsCount);
  324. currentState = STATE_IN_WORD;
  325. }
  326. if (consecutiveVoiceDuration >= maximumWordLength){
  327. ast_verb(3, "AMD: Channel [%s]. Maximum Word Length detected. [%d]\n", ast_channel_name(chan), consecutiveVoiceDuration);
  328. ast_frfree(f);
  329. strcpy(amdStatus , "MACHINE");
  330. sprintf(amdCause , "MAXWORDLENGTH-%d", consecutiveVoiceDuration);
  331. break;
  332. }
  333. if (iWordsCount >= maximumNumberOfWords) {
  334. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: iWordsCount:%d\n", ast_channel_name(chan), iWordsCount);
  335. ast_frfree(f);
  336. strcpy(amdStatus , "MACHINE");
  337. sprintf(amdCause , "MAXWORDS-%d-%d", iWordsCount, maximumNumberOfWords);
  338. res = 1;
  339. break;
  340. }
  341. if (inGreeting == 1 && voiceDuration >= greeting) {
  342. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: voiceDuration:%d greeting:%d\n", ast_channel_name(chan), voiceDuration, greeting);
  343. ast_frfree(f);
  344. strcpy(amdStatus , "MACHINE");
  345. sprintf(amdCause , "LONGGREETING-%d-%d", voiceDuration, greeting);
  346. res = 1;
  347. break;
  348. }
  349. if (voiceDuration >= minimumWordLength ) {
  350. if (silenceDuration > 0)
  351. ast_verb(3, "AMD: Channel [%s]. Detected Talk, previous silence duration: %d\n", ast_channel_name(chan), silenceDuration);
  352. silenceDuration = 0;
  353. }
  354. if (consecutiveVoiceDuration >= minimumWordLength && inGreeting == 0) {
  355. /* Only go in here once to change the greeting flag when we detect the 1st word */
  356. if (silenceDuration > 0)
  357. ast_verb(3, "AMD: Channel [%s]. Before Greeting Time: silenceDuration: %d voiceDuration: %d\n", ast_channel_name(chan), silenceDuration, voiceDuration);
  358. inInitialSilence = 0;
  359. inGreeting = 1;
  360. }
  361. }
  362. }
  363. ast_frfree(f);
  364. }
  365. if (!res) {
  366. /* It took too long to get a frame back. Giving up. */
  367. ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
  368. strcpy(amdStatus , "NOTSURE");
  369. sprintf(amdCause , "TOOLONG-%d", iTotalTime);
  370. }
  371. /* Set the status and cause on the channel */
  372. pbx_builtin_setvar_helper(chan , "AMDSTATUS" , amdStatus);
  373. pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause);
  374. /* Restore channel read format */
  375. if (readFormat && ast_set_read_format(chan, readFormat))
  376. ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", ast_channel_name(chan));
  377. /* Free the DSP used to detect silence */
  378. ast_dsp_free(silenceDetector);
  379. return;
  380. }
  381. static int amd_exec(struct ast_channel *chan, const char *data)
  382. {
  383. isAnsweringMachine(chan, data);
  384. return 0;
  385. }
  386. static int load_config(int reload)
  387. {
  388. struct ast_config *cfg = NULL;
  389. char *cat = NULL;
  390. struct ast_variable *var = NULL;
  391. struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
  392. dfltSilenceThreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
  393. if (!(cfg = ast_config_load("amd.conf", config_flags))) {
  394. ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n");
  395. return -1;
  396. } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
  397. return 0;
  398. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  399. ast_log(LOG_ERROR, "Config file amd.conf is in an invalid format. Aborting.\n");
  400. return -1;
  401. }
  402. cat = ast_category_browse(cfg, NULL);
  403. while (cat) {
  404. if (!strcasecmp(cat, "general") ) {
  405. var = ast_variable_browse(cfg, cat);
  406. while (var) {
  407. if (!strcasecmp(var->name, "initial_silence")) {
  408. dfltInitialSilence = atoi(var->value);
  409. } else if (!strcasecmp(var->name, "greeting")) {
  410. dfltGreeting = atoi(var->value);
  411. } else if (!strcasecmp(var->name, "after_greeting_silence")) {
  412. dfltAfterGreetingSilence = atoi(var->value);
  413. } else if (!strcasecmp(var->name, "silence_threshold")) {
  414. dfltSilenceThreshold = atoi(var->value);
  415. } else if (!strcasecmp(var->name, "total_analysis_time")) {
  416. dfltTotalAnalysisTime = atoi(var->value);
  417. } else if (!strcasecmp(var->name, "min_word_length")) {
  418. dfltMinimumWordLength = atoi(var->value);
  419. } else if (!strcasecmp(var->name, "between_words_silence")) {
  420. dfltBetweenWordsSilence = atoi(var->value);
  421. } else if (!strcasecmp(var->name, "maximum_number_of_words")) {
  422. dfltMaximumNumberOfWords = atoi(var->value);
  423. } else if (!strcasecmp(var->name, "maximum_word_length")) {
  424. dfltMaximumWordLength = atoi(var->value);
  425. } else {
  426. ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n",
  427. app, cat, var->name, var->lineno);
  428. }
  429. var = var->next;
  430. }
  431. }
  432. cat = ast_category_browse(cfg, cat);
  433. }
  434. ast_config_destroy(cfg);
  435. ast_verb(3, "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
  436. "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d]\n",
  437. dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime,
  438. dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold, dfltMaximumWordLength);
  439. return 0;
  440. }
  441. static int unload_module(void)
  442. {
  443. return ast_unregister_application(app);
  444. }
  445. /*!
  446. * \brief Load the module
  447. *
  448. * Module loading including tests for configuration or dependencies.
  449. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  450. * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
  451. * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
  452. * configuration file or other non-critical problem return
  453. * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  454. */
  455. static int load_module(void)
  456. {
  457. if (load_config(0) || ast_register_application_xml(app, amd_exec)) {
  458. return AST_MODULE_LOAD_DECLINE;
  459. }
  460. return AST_MODULE_LOAD_SUCCESS;
  461. }
  462. static int reload(void)
  463. {
  464. if (load_config(1))
  465. return AST_MODULE_LOAD_DECLINE;
  466. return AST_MODULE_LOAD_SUCCESS;
  467. }
  468. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Answering Machine Detection Application",
  469. .support_level = AST_MODULE_SUPPORT_EXTENDED,
  470. .load = load_module,
  471. .unload = unload_module,
  472. .reload = reload,
  473. );