app_amd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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 Length - max length of a single word.
  122. </value>
  123. <value name="MAXWORDS">
  124. Word Count - maximum number of words.
  125. </value>
  126. </variable>
  127. </variablelist>
  128. </description>
  129. <see-also>
  130. <ref type="application">WaitForSilence</ref>
  131. <ref type="application">WaitForNoise</ref>
  132. </see-also>
  133. </application>
  134. ***/
  135. static const char app[] = "AMD";
  136. #define STATE_IN_WORD 1
  137. #define STATE_IN_SILENCE 2
  138. /* Some default values for the algorithm parameters. These defaults will be overwritten from amd.conf */
  139. static int dfltInitialSilence = 2500;
  140. static int dfltGreeting = 1500;
  141. static int dfltAfterGreetingSilence = 800;
  142. static int dfltTotalAnalysisTime = 5000;
  143. static int dfltMinimumWordLength = 100;
  144. static int dfltBetweenWordsSilence = 50;
  145. static int dfltMaximumNumberOfWords = 3;
  146. static int dfltSilenceThreshold = 256;
  147. static int dfltMaximumWordLength = 5000; /* Setting this to a large default so it is not used unless specify it in the configs or command line */
  148. /* Set to the lowest ms value provided in amd.conf or application parameters */
  149. static int dfltMaxWaitTimeForFrame = 50;
  150. static void isAnsweringMachine(struct ast_channel *chan, const char *data)
  151. {
  152. int res = 0;
  153. struct ast_frame *f = NULL;
  154. struct ast_dsp *silenceDetector = NULL;
  155. int dspsilence = 0, framelength = 0;
  156. RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);
  157. int inInitialSilence = 1;
  158. int inGreeting = 0;
  159. int voiceDuration = 0;
  160. int silenceDuration = 0;
  161. int iTotalTime = 0;
  162. int iWordsCount = 0;
  163. int currentState = STATE_IN_WORD;
  164. int consecutiveVoiceDuration = 0;
  165. char amdCause[256] = "", amdStatus[256] = "";
  166. char *parse = ast_strdupa(data);
  167. /* Lets set the initial values of the variables that will control the algorithm.
  168. The initial values are the default ones. If they are passed as arguments
  169. when invoking the application, then the default values will be overwritten
  170. by the ones passed as parameters. */
  171. int initialSilence = dfltInitialSilence;
  172. int greeting = dfltGreeting;
  173. int afterGreetingSilence = dfltAfterGreetingSilence;
  174. int totalAnalysisTime = dfltTotalAnalysisTime;
  175. int minimumWordLength = dfltMinimumWordLength;
  176. int betweenWordsSilence = dfltBetweenWordsSilence;
  177. int maximumNumberOfWords = dfltMaximumNumberOfWords;
  178. int silenceThreshold = dfltSilenceThreshold;
  179. int maximumWordLength = dfltMaximumWordLength;
  180. int maxWaitTimeForFrame = dfltMaxWaitTimeForFrame;
  181. AST_DECLARE_APP_ARGS(args,
  182. AST_APP_ARG(argInitialSilence);
  183. AST_APP_ARG(argGreeting);
  184. AST_APP_ARG(argAfterGreetingSilence);
  185. AST_APP_ARG(argTotalAnalysisTime);
  186. AST_APP_ARG(argMinimumWordLength);
  187. AST_APP_ARG(argBetweenWordsSilence);
  188. AST_APP_ARG(argMaximumNumberOfWords);
  189. AST_APP_ARG(argSilenceThreshold);
  190. AST_APP_ARG(argMaximumWordLength);
  191. );
  192. ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan),
  193. S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, "(N/A)"),
  194. S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "(N/A)"),
  195. ast_format_get_name(ast_channel_readformat(chan)));
  196. /* Lets parse the arguments. */
  197. if (!ast_strlen_zero(parse)) {
  198. /* Some arguments have been passed. Lets parse them and overwrite the defaults. */
  199. AST_STANDARD_APP_ARGS(args, parse);
  200. if (!ast_strlen_zero(args.argInitialSilence))
  201. initialSilence = atoi(args.argInitialSilence);
  202. if (!ast_strlen_zero(args.argGreeting))
  203. greeting = atoi(args.argGreeting);
  204. if (!ast_strlen_zero(args.argAfterGreetingSilence))
  205. afterGreetingSilence = atoi(args.argAfterGreetingSilence);
  206. if (!ast_strlen_zero(args.argTotalAnalysisTime))
  207. totalAnalysisTime = atoi(args.argTotalAnalysisTime);
  208. if (!ast_strlen_zero(args.argMinimumWordLength))
  209. minimumWordLength = atoi(args.argMinimumWordLength);
  210. if (!ast_strlen_zero(args.argBetweenWordsSilence))
  211. betweenWordsSilence = atoi(args.argBetweenWordsSilence);
  212. if (!ast_strlen_zero(args.argMaximumNumberOfWords))
  213. maximumNumberOfWords = atoi(args.argMaximumNumberOfWords);
  214. if (!ast_strlen_zero(args.argSilenceThreshold))
  215. silenceThreshold = atoi(args.argSilenceThreshold);
  216. if (!ast_strlen_zero(args.argMaximumWordLength))
  217. maximumWordLength = atoi(args.argMaximumWordLength);
  218. } else {
  219. ast_debug(1, "AMD using the default parameters.\n");
  220. }
  221. /* Find lowest ms value, that will be max wait time for a frame */
  222. if (maxWaitTimeForFrame > initialSilence)
  223. maxWaitTimeForFrame = initialSilence;
  224. if (maxWaitTimeForFrame > greeting)
  225. maxWaitTimeForFrame = greeting;
  226. if (maxWaitTimeForFrame > afterGreetingSilence)
  227. maxWaitTimeForFrame = afterGreetingSilence;
  228. if (maxWaitTimeForFrame > totalAnalysisTime)
  229. maxWaitTimeForFrame = totalAnalysisTime;
  230. if (maxWaitTimeForFrame > minimumWordLength)
  231. maxWaitTimeForFrame = minimumWordLength;
  232. if (maxWaitTimeForFrame > betweenWordsSilence)
  233. maxWaitTimeForFrame = betweenWordsSilence;
  234. /* Now we're ready to roll! */
  235. ast_verb(3, "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
  236. "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d] \n",
  237. initialSilence, greeting, afterGreetingSilence, totalAnalysisTime,
  238. minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold, maximumWordLength);
  239. /* Set read format to signed linear so we get signed linear frames in */
  240. readFormat = ao2_bump(ast_channel_readformat(chan));
  241. if (ast_set_read_format(chan, ast_format_slin) < 0 ) {
  242. ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", ast_channel_name(chan));
  243. pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
  244. pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
  245. return;
  246. }
  247. /* Create a new DSP that will detect the silence */
  248. if (!(silenceDetector = ast_dsp_new())) {
  249. ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to create silence detector :(\n", ast_channel_name(chan));
  250. pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
  251. pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
  252. return;
  253. }
  254. /* Set silence threshold to specified value */
  255. ast_dsp_set_threshold(silenceDetector, silenceThreshold);
  256. /* Now we go into a loop waiting for frames from the channel */
  257. while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
  258. /* If we fail to read in a frame, that means they hung up */
  259. if (!(f = ast_read(chan))) {
  260. ast_verb(3, "AMD: Channel [%s]. HANGUP\n", ast_channel_name(chan));
  261. ast_debug(1, "Got hangup\n");
  262. strcpy(amdStatus, "HANGUP");
  263. res = 1;
  264. break;
  265. }
  266. if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
  267. /* If the total time exceeds the analysis time then give up as we are not too sure */
  268. if (f->frametype == AST_FRAME_VOICE) {
  269. framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
  270. } else {
  271. framelength = 2 * maxWaitTimeForFrame;
  272. }
  273. iTotalTime += framelength;
  274. if (iTotalTime >= totalAnalysisTime) {
  275. ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
  276. ast_frfree(f);
  277. strcpy(amdStatus , "NOTSURE");
  278. sprintf(amdCause , "TOOLONG-%d", iTotalTime);
  279. break;
  280. }
  281. /* Feed the frame of audio into the silence detector and see if we get a result */
  282. if (f->frametype != AST_FRAME_VOICE)
  283. dspsilence += 2 * maxWaitTimeForFrame;
  284. else {
  285. dspsilence = 0;
  286. ast_dsp_silence(silenceDetector, f, &dspsilence);
  287. }
  288. if (dspsilence > 0) {
  289. silenceDuration = dspsilence;
  290. if (silenceDuration >= betweenWordsSilence) {
  291. if (currentState != STATE_IN_SILENCE ) {
  292. ast_verb(3, "AMD: Channel [%s]. Changed state to STATE_IN_SILENCE\n", ast_channel_name(chan));
  293. }
  294. /* Find words less than word duration */
  295. if (consecutiveVoiceDuration < minimumWordLength && consecutiveVoiceDuration > 0){
  296. ast_verb(3, "AMD: Channel [%s]. Short Word Duration: %d\n", ast_channel_name(chan), consecutiveVoiceDuration);
  297. }
  298. currentState = STATE_IN_SILENCE;
  299. consecutiveVoiceDuration = 0;
  300. }
  301. if (inInitialSilence == 1 && silenceDuration >= initialSilence) {
  302. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: silenceDuration:%d initialSilence:%d\n",
  303. ast_channel_name(chan), silenceDuration, initialSilence);
  304. ast_frfree(f);
  305. strcpy(amdStatus , "MACHINE");
  306. sprintf(amdCause , "INITIALSILENCE-%d-%d", silenceDuration, initialSilence);
  307. res = 1;
  308. break;
  309. }
  310. if (silenceDuration >= afterGreetingSilence && inGreeting == 1) {
  311. ast_verb(3, "AMD: Channel [%s]. HUMAN: silenceDuration:%d afterGreetingSilence:%d\n",
  312. ast_channel_name(chan), silenceDuration, afterGreetingSilence);
  313. ast_frfree(f);
  314. strcpy(amdStatus , "HUMAN");
  315. sprintf(amdCause , "HUMAN-%d-%d", silenceDuration, afterGreetingSilence);
  316. res = 1;
  317. break;
  318. }
  319. } else {
  320. consecutiveVoiceDuration += framelength;
  321. voiceDuration += framelength;
  322. /* If I have enough consecutive voice to say that I am in a Word, I can only increment the
  323. number of words if my previous state was Silence, which means that I moved into a word. */
  324. if (consecutiveVoiceDuration >= minimumWordLength && currentState == STATE_IN_SILENCE) {
  325. iWordsCount++;
  326. ast_verb(3, "AMD: Channel [%s]. Word detected. iWordsCount:%d\n", ast_channel_name(chan), iWordsCount);
  327. currentState = STATE_IN_WORD;
  328. }
  329. if (consecutiveVoiceDuration >= maximumWordLength){
  330. ast_verb(3, "AMD: Channel [%s]. Maximum Word Length detected. [%d]\n", ast_channel_name(chan), consecutiveVoiceDuration);
  331. ast_frfree(f);
  332. strcpy(amdStatus , "MACHINE");
  333. sprintf(amdCause , "MAXWORDLENGTH-%d", consecutiveVoiceDuration);
  334. break;
  335. }
  336. if (iWordsCount >= maximumNumberOfWords) {
  337. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: iWordsCount:%d\n", ast_channel_name(chan), iWordsCount);
  338. ast_frfree(f);
  339. strcpy(amdStatus , "MACHINE");
  340. sprintf(amdCause , "MAXWORDS-%d-%d", iWordsCount, maximumNumberOfWords);
  341. res = 1;
  342. break;
  343. }
  344. if (inGreeting == 1 && voiceDuration >= greeting) {
  345. ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: voiceDuration:%d greeting:%d\n", ast_channel_name(chan), voiceDuration, greeting);
  346. ast_frfree(f);
  347. strcpy(amdStatus , "MACHINE");
  348. sprintf(amdCause , "LONGGREETING-%d-%d", voiceDuration, greeting);
  349. res = 1;
  350. break;
  351. }
  352. if (voiceDuration >= minimumWordLength ) {
  353. if (silenceDuration > 0)
  354. ast_verb(3, "AMD: Channel [%s]. Detected Talk, previous silence duration: %d\n", ast_channel_name(chan), silenceDuration);
  355. silenceDuration = 0;
  356. }
  357. if (consecutiveVoiceDuration >= minimumWordLength && inGreeting == 0) {
  358. /* Only go in here once to change the greeting flag when we detect the 1st word */
  359. if (silenceDuration > 0)
  360. ast_verb(3, "AMD: Channel [%s]. Before Greeting Time: silenceDuration: %d voiceDuration: %d\n", ast_channel_name(chan), silenceDuration, voiceDuration);
  361. inInitialSilence = 0;
  362. inGreeting = 1;
  363. }
  364. }
  365. }
  366. ast_frfree(f);
  367. }
  368. if (!res) {
  369. /* It took too long to get a frame back. Giving up. */
  370. ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
  371. strcpy(amdStatus , "NOTSURE");
  372. sprintf(amdCause , "TOOLONG-%d", iTotalTime);
  373. }
  374. /* Set the status and cause on the channel */
  375. pbx_builtin_setvar_helper(chan , "AMDSTATUS" , amdStatus);
  376. pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause);
  377. /* Restore channel read format */
  378. if (readFormat && ast_set_read_format(chan, readFormat))
  379. ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", ast_channel_name(chan));
  380. /* Free the DSP used to detect silence */
  381. ast_dsp_free(silenceDetector);
  382. return;
  383. }
  384. static int amd_exec(struct ast_channel *chan, const char *data)
  385. {
  386. isAnsweringMachine(chan, data);
  387. return 0;
  388. }
  389. static int load_config(int reload)
  390. {
  391. struct ast_config *cfg = NULL;
  392. char *cat = NULL;
  393. struct ast_variable *var = NULL;
  394. struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
  395. dfltSilenceThreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
  396. if (!(cfg = ast_config_load("amd.conf", config_flags))) {
  397. ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n");
  398. return -1;
  399. } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
  400. return 0;
  401. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  402. ast_log(LOG_ERROR, "Config file amd.conf is in an invalid format. Aborting.\n");
  403. return -1;
  404. }
  405. cat = ast_category_browse(cfg, NULL);
  406. while (cat) {
  407. if (!strcasecmp(cat, "general") ) {
  408. var = ast_variable_browse(cfg, cat);
  409. while (var) {
  410. if (!strcasecmp(var->name, "initial_silence")) {
  411. dfltInitialSilence = atoi(var->value);
  412. } else if (!strcasecmp(var->name, "greeting")) {
  413. dfltGreeting = atoi(var->value);
  414. } else if (!strcasecmp(var->name, "after_greeting_silence")) {
  415. dfltAfterGreetingSilence = atoi(var->value);
  416. } else if (!strcasecmp(var->name, "silence_threshold")) {
  417. dfltSilenceThreshold = atoi(var->value);
  418. } else if (!strcasecmp(var->name, "total_analysis_time")) {
  419. dfltTotalAnalysisTime = atoi(var->value);
  420. } else if (!strcasecmp(var->name, "min_word_length")) {
  421. dfltMinimumWordLength = atoi(var->value);
  422. } else if (!strcasecmp(var->name, "between_words_silence")) {
  423. dfltBetweenWordsSilence = atoi(var->value);
  424. } else if (!strcasecmp(var->name, "maximum_number_of_words")) {
  425. dfltMaximumNumberOfWords = atoi(var->value);
  426. } else if (!strcasecmp(var->name, "maximum_word_length")) {
  427. dfltMaximumWordLength = atoi(var->value);
  428. } else {
  429. ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n",
  430. app, cat, var->name, var->lineno);
  431. }
  432. var = var->next;
  433. }
  434. }
  435. cat = ast_category_browse(cfg, cat);
  436. }
  437. ast_config_destroy(cfg);
  438. ast_verb(3, "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
  439. "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d]\n",
  440. dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime,
  441. dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold, dfltMaximumWordLength);
  442. return 0;
  443. }
  444. static int unload_module(void)
  445. {
  446. return ast_unregister_application(app);
  447. }
  448. /*!
  449. * \brief Load the module
  450. *
  451. * Module loading including tests for configuration or dependencies.
  452. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  453. * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
  454. * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
  455. * configuration file or other non-critical problem return
  456. * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  457. */
  458. static int load_module(void)
  459. {
  460. if (load_config(0) || ast_register_application_xml(app, amd_exec)) {
  461. return AST_MODULE_LOAD_DECLINE;
  462. }
  463. return AST_MODULE_LOAD_SUCCESS;
  464. }
  465. static int reload(void)
  466. {
  467. if (load_config(1))
  468. return AST_MODULE_LOAD_DECLINE;
  469. return AST_MODULE_LOAD_SUCCESS;
  470. }
  471. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Answering Machine Detection Application",
  472. .support_level = AST_MODULE_SUPPORT_EXTENDED,
  473. .load = load_module,
  474. .unload = unload_module,
  475. .reload = reload,
  476. );