Janitor, use ARRAY_LEN() when possible.
[asterisk/asterisk.git] / res / res_indications.c
old mode 100755 (executable)
new mode 100644 (file)
index b289612..eb61a02
-/** @file res_indications.c 
- *
- * Asterisk -- A telephony toolkit for Linux.
+/*
+ * Asterisk -- An open source telephony toolkit.
  *
- * Load the indications
- * 
  * Copyright (C) 2002, Pauline Middelink
  *
- * Pauline Middelink <middelink@polyware.nl>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
  *
  * This program is free software, distributed under the terms of
- * the GNU General Public License
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file res_indications.c 
+ *
+ * \brief Load the indications
+ * 
+ * \author Pauline Middelink <middelink@polyware.nl>
  *
  * Load the country specific dialtones into the asterisk PBX.
  */
  
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <asterisk/lock.h>
-#include <asterisk/file.h>
-#include <asterisk/cli.h>
-#include <asterisk/logger.h>
-#include <asterisk/config.h>
-#include <asterisk/channel.h>
-#include <asterisk/pbx.h>
-#include <asterisk/module.h>
-#include <asterisk/translate.h>
-#include <asterisk/indications.h>
-
-
-// Globals
-static const char dtext[] = "Indications Configuration";
-static const char config[] = "indications.conf";
+#include "asterisk.h"
 
-/*
- * Help for commands provided by this module ...
- */
-static char help_add_indication[] =
-"Usage: add indication <country> <indication> \"<tonelist>\"\n"
-"       Add the given indication to the country.\n";
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-static char help_remove_indication[] =
-"Usage: remove indication <country> <indication>\n"
-"       Remove the given indication from the country.\n";
+#include <ctype.h>
+#include <sys/stat.h>
 
-static char help_show_indications[] =
-"Usage: show indications [<country> ...]\n"
-"       Show either a condensed for of all country/indications, or the\n"
-"       indications for the specified countries.\n";
+#include "asterisk/lock.h"
+#include "asterisk/file.h"
+#include "asterisk/cli.h"
+#include "asterisk/config.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/translate.h"
+#include "asterisk/indications.h"
+#include "asterisk/utils.h"
+
+/*** DOCUMENTATION
+       <application name="PlayTones" language="en_US">
+               <synopsis>
+                       Play a tone list.
+               </synopsis>
+               <syntax>
+                       <parameter name="arg" required="true">
+                               <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
+                               configuration file, or a directly specified list of frequencies and durations.</para>
+                       </parameter>
+               </syntax>
+               <description>
+                       <para>Plays a tone list. Execution will continue with the next step immediately,
+                       while the tones continue to play.</para>
+                       <para>See the sample <filename>indications.conf</filename> for a description of the
+                       specification of a tonelist.</para>
+               </description>
+               <see-also>
+                       <ref type="application">StopPlayTones</ref>
+               </see-also>
+       </application>
+       <application name="StopPlayTones" language="en_US">
+               <synopsis>
+                       Stop playing a tone list.
+               </synopsis>
+               <syntax />
+               <description>
+                       <para>Stop playing a tone list, initiated by PlayTones().</para>
+               </description>
+               <see-also>
+                       <ref type="application">PlayTones</ref>
+               </see-also>
+       </application>
+ ***/
+
+/* Globals */
+static const char config[] = "indications.conf";
 
 /*
  * Implementation of functions provided by this module
  */
 
-/*
- * ADD INDICATION command stuff
+/*!
+ * \brief Add a country to indication
+ * \param e the ast_cli_entry for this CLI command
+ * \param cmd the reason we are being called
+ * \param a the arguments being passed to us
  */
-static int handle_add_indication(int fd, int argc, char *argv[])
+static char *handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-       struct tone_zone *tz;
+       struct ind_tone_zone *tz;
        int created_country = 0;
-       if (argc != 5) return RESULT_SHOWUSAGE;
 
-       tz = ast_get_indication_zone(argv[2]);
+       switch (cmd) {
+       case CLI_INIT:
+               e->command = "indication add";
+               e->usage =
+                       "Usage: indication add <country> <indication> \"<tonelist>\"\n"
+                       "       Add the given indication to the country.\n";
+               return NULL;
+       case CLI_GENERATE:
+               return NULL;
+       }
+
+       if (a->argc != 5)
+               return CLI_SHOWUSAGE;
+
+       tz = ast_get_indication_zone(a->argv[2]);
        if (!tz) {
                /* country does not exist, create it */
-               ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n",argv[2]);
-
-               tz = malloc(sizeof(struct tone_zone));
-               if (!tz) {
-                       ast_log(LOG_WARNING, "Out of memory\n");
-                       return -1;
+               ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n", a->argv[2]);
+               
+               if (!(tz = ast_calloc(1, sizeof(*tz)))) {
+                       return CLI_FAILURE;
                }
-               memset(tz,0,sizeof(struct tone_zone));
-               strncpy(tz->country,argv[2],sizeof(tz->country)-1);
+               ast_copy_string(tz->country, a->argv[2], sizeof(tz->country));
                if (ast_register_indication_country(tz)) {
                        ast_log(LOG_WARNING, "Unable to register new country\n");
-                       free(tz);
-                       return -1;
+                       ast_free(tz);
+                       return CLI_FAILURE;
                }
                created_country = 1;
        }
-       if (ast_register_indication(tz,argv[3],argv[4])) {
-               ast_log(LOG_WARNING, "Unable to register indication %s/%s\n",argv[2],argv[3]);
+       if (ast_register_indication(tz, a->argv[3], a->argv[4])) {
+               ast_log(LOG_WARNING, "Unable to register indication %s/%s\n", a->argv[2], a->argv[3]);
                if (created_country)
-                       ast_unregister_indication_country(argv[2]);
-               return -1;
+                       ast_unregister_indication_country(a->argv[2]);
+               return CLI_FAILURE;
        }
-       return 0;
+       return CLI_SUCCESS;
 }
 
-/*
- * REMOVE INDICATION command stuff
+/*!
+ * \brief Remove a country from indication
+ * \param e the ast_cli_entry for this CLI command
+ * \param cmd the reason we are being called
+ * \param a the arguments being passed to us
  */
-static int handle_remove_indication(int fd, int argc, char *argv[])
+static char *handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-       struct tone_zone *tz;
-       if (argc != 3 && argc != 4) return RESULT_SHOWUSAGE;
+       struct ind_tone_zone *tz;
+
+       switch (cmd) {
+       case CLI_INIT:
+               e->command = "indication remove";
+               e->usage =
+                       "Usage: indication remove <country> <indication>\n"
+                       "       Remove the given indication from the country.\n";
+               return NULL;
+       case CLI_GENERATE:
+               return NULL;
+       }
+
+       if (a->argc != 3 && a->argc != 4)
+               return CLI_SHOWUSAGE;
 
-       if (argc == 3) {
+       if (a->argc == 3) {
                /* remove entiry country */
-               if (ast_unregister_indication_country(argv[2])) {
-                       ast_log(LOG_WARNING, "Unable to unregister indication country %s\n",argv[2]);
-                       return -1;
+               if (ast_unregister_indication_country(a->argv[2])) {
+                       ast_log(LOG_WARNING, "Unable to unregister indication country %s\n", a->argv[2]);
+                       return CLI_FAILURE;
                }
-               return 0;
+               return CLI_SUCCESS;
        }
 
-       tz = ast_get_indication_zone(argv[2]);
+       tz = ast_get_indication_zone(a->argv[2]);
        if (!tz) {
-               ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n",argv[2],argv[3]);
-               return -1;
+               ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n", a->argv[2], a->argv[3]);
+               return CLI_FAILURE;
        }
-       if (ast_unregister_indication(tz,argv[3])) {
-               ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n",argv[2],argv[3]);
-               return -1;
+       if (ast_unregister_indication(tz, a->argv[3])) {
+               ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n", a->argv[2], a->argv[3]);
+               return CLI_FAILURE;
        }
-       return 0;
+       return CLI_SUCCESS;
 }
 
-/*
- * SHOW INDICATIONS command stuff
+/*!
+ * \brief Show the current indications
+ * \param e the ast_cli_entry for this CLI command
+ * \param cmd the reason we are being called
+ * \param a the arguments being passed to us
  */
-static int handle_show_indications(int fd, int argc, char *argv[])
+static char *handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-       struct tone_zone *tz;
+       struct ind_tone_zone *tz = NULL;
        char buf[256];
        int found_country = 0;
 
-       if (ast_mutex_lock(&tzlock)) {
-               ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
-               return 0;
+       switch (cmd) {
+       case CLI_INIT:
+               e->command = "indication show";
+               e->usage =
+                       "Usage: indication show [<country> ...]\n"
+                       "       Display either a condensed for of all country/indications, or the\n"
+                       "       indications for the specified countries.\n";
+               return NULL;
+       case CLI_GENERATE:
+               return NULL;
        }
-       if (argc == 2) {
+
+       if (a->argc == 2) {
                /* no arguments, show a list of countries */
-               ast_cli(fd,"Country Alias   Description\n"
-                          "===========================\n");
-               for (tz=tone_zones; tz; tz=tz->next) {
-                       ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
-               }
-               ast_mutex_unlock(&tzlock);
-               return 0;
+               ast_cli(a->fd, "Country Alias   Description\n");
+               ast_cli(a->fd, "===========================\n");
+               while ((tz = ast_walk_indications(tz)))
+                       ast_cli(a->fd, "%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
+               return CLI_SUCCESS;
        }
        /* there was a request for specific country(ies), lets humor them */
-       for (tz=tone_zones; tz; tz=tz->next) {
-               int i,j;
-               for (i=2; i<argc; i++) {
-                       if (strcasecmp(tz->country,argv[i])==0 &&
-                           !tz->alias[0]) {
-                               struct tone_zone_sound* ts;
+       while ((tz = ast_walk_indications(tz))) {
+               int i, j;
+               for (i = 2; i < a->argc; i++) {
+                       if (strcasecmp(tz->country, a->argv[i]) == 0 && !tz->alias[0]) {
+                               struct ind_tone_zone_sound *ts;
                                if (!found_country) {
                                        found_country = 1;
-                                       ast_cli(fd,"Country Indication      PlayList\n"
-                                                  "=====================================\n");
+                                       ast_cli(a->fd, "Country Indication      PlayList\n");
+                                       ast_cli(a->fd, "=====================================\n");
+                               }
+                               j = snprintf(buf, sizeof(buf), "%-7.7s %-15.15s ", tz->country, "<ringcadence>");
+                               for (i = 0; i < tz->nrringcadence; i++) {
+                                       j += snprintf(buf + j, sizeof(buf) - j, "%d,", tz->ringcadence[i]);
                                }
-                               j = snprintf(buf,sizeof(buf),"%-7.7s %-15.15s ",tz->country,"<ringcadance>");
-                               for (i=0; i<tz->nrringcadance; i++) {
-                                       j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadance[i]);
+                               if (tz->nrringcadence)
+                                       j--;
+                               ast_copy_string(buf + j, "\n", sizeof(buf) - j);
+                               ast_cli(a->fd, "%s", buf);
+                               AST_LIST_TRAVERSE(&tz->tones, ts, list) {
+                                       ast_cli(a->fd, "%-7.7s %-15.15s %s\n", tz->country, ts->name, ts->data);
                                }
-                               if (tz->nrringcadance) j--;
-                               strncpy(buf+j,"\n",sizeof(buf)-j-1);
-                               ast_cli(fd,buf);
-                               for (ts=tz->tones; ts; ts=ts->next)
-                                       ast_cli(fd,"%-7.7s %-15.15s %s\n",tz->country,ts->name,ts->data);
                                break;
                        }
                }
        }
        if (!found_country)
-               ast_cli(fd,"No countries matched your criteria.\n");
-       ast_mutex_unlock(&tzlock);
-       return -1;
+               ast_cli(a->fd, "No countries matched your criteria.\n");
+       return CLI_SUCCESS;
 }
 
-/*
- * Playtones command stuff
+/*!
+ * \brief play tone for indication country
+ * \param chan ast_channel to play the sounds back to
+ * \param data contains tone to play
  */
 static int handle_playtones(struct ast_channel *chan, void *data)
 {
-       struct tone_zone_sound *ts;
+       struct ind_tone_zone_sound *ts;
        int res;
 
        if (!data || !((char*)data)[0]) {
@@ -199,8 +266,10 @@ static int handle_playtones(struct ast_channel *chan, void *data)
        return res;
 }
 
-/*
- * StopPlaylist command stuff
+/*!
+ * \brief Stop tones playing
+ * \param chan 
+ * \param data 
  */
 static int handle_stopplaytones(struct ast_channel *chan, void *data)
 {
@@ -208,23 +277,28 @@ static int handle_stopplaytones(struct ast_channel *chan, void *data)
        return 0;
 }
 
-/*
- * Load module stuff
- */
-static int ind_load_module(void)
+/*! \brief load indications module */
+static int ind_load_module(int reload)
 {
        struct ast_config *cfg;
        struct ast_variable *v;
        char *cxt;
        char *c;
-       struct tone_zone *tones;
+       struct ind_tone_zone *tones;
        const char *country = NULL;
+       struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
        /* that the following cast is needed, is yuk! */
        /* yup, checked it out. It is NOT written to. */
-       cfg = ast_load((char *)config);
-       if (!cfg)
+       cfg = ast_config_load((char *)config, config_flags);
+       if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
+               return -1;
+       } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
                return 0;
+       }
+
+       if (reload)
+               ast_unregister_indication_country(NULL);
 
        /* Use existing config to populate the Indication table */
        cxt = ast_category_browse(cfg, NULL);
@@ -233,40 +307,36 @@ static int ind_load_module(void)
                if (!strcasecmp(cxt, "general")) {
                        cxt = ast_category_browse(cfg, cxt);
                        continue;
-               }
-               tones = malloc(sizeof(struct tone_zone));
-               if (!tones) {
-                       ast_log(LOG_WARNING,"Out of memory\n");
-                       ast_destroy(cfg);
+               }               
+               if (!(tones = ast_calloc(1, sizeof(*tones)))) {
+                       ast_config_destroy(cfg);
                        return -1;
                }
-               memset(tones,0,sizeof(struct tone_zone));
-               strncpy(tones->country,cxt,sizeof(tones->country) - 1);
+               ast_copy_string(tones->country,cxt,sizeof(tones->country));
 
                v = ast_variable_browse(cfg, cxt);
                while(v) {
                        if (!strcasecmp(v->name, "description")) {
-                               strncpy(tones->description, v->value, sizeof(tones->description)-1);
-                       } else if (!strcasecmp(v->name,"ringcadance")) {
+                               ast_copy_string(tones->description, v->value, sizeof(tones->description));
+                       } else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) {
                                char *ring,*rings = ast_strdupa(v->value);
                                c = rings;
                                ring = strsep(&c,",");
                                while (ring) {
                                        int *tmp, val;
                                        if (!isdigit(ring[0]) || (val=atoi(ring))==-1) {
-                                               ast_log(LOG_WARNING,"Invalid ringcadance given '%s' at line %d.\n",ring,v->lineno);
+                                               ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d.\n",ring,v->lineno);
                                                ring = strsep(&c,",");
                                                continue;
-                                       }
-                                       tmp = realloc(tones->ringcadance,(tones->nrringcadance+1)*sizeof(int));
-                                       if (!tmp) {
-                                               ast_log(LOG_WARNING, "Out of memory\n");
-                                               ast_destroy(cfg);
+                                       }                                       
+                                       if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) {
+                                               ast_config_destroy(cfg);
+                                               ast_destroy_indication_zone(tones);
                                                return -1;
                                        }
-                                       tones->ringcadance = tmp;
-                                       tmp[tones->nrringcadance] = val;
-                                       tones->nrringcadance++;
+                                       tones->ringcadence = tmp;
+                                       tmp[tones->nrringcadence] = val;
+                                       tones->nrringcadence++;
                                        /* next item */
                                        ring = strsep(&c,",");
                                }
@@ -275,136 +345,108 @@ static int ind_load_module(void)
                                c = countries;
                                country = strsep(&c,",");
                                while (country) {
-                                       struct tone_zone* azone = malloc(sizeof(struct tone_zone));
-                                       if (!azone) {
-                                               ast_log(LOG_WARNING,"Out of memory\n");
-                                               ast_destroy(cfg);
+                                       struct ind_tone_zone* azone;
+                                       if (!(azone = ast_calloc(1, sizeof(*azone)))) {
+                                               ast_config_destroy(cfg);
+                                               ast_destroy_indication_zone(tones);
                                                return -1;
                                        }
-                                       memset(azone,0,sizeof(struct tone_zone));
-                                       strncpy(azone->country, country, sizeof(azone->country) - 1);
-                                       strncpy(azone->alias, cxt, sizeof(azone->alias)-1);
+                                       ast_copy_string(azone->country, country, sizeof(azone->country));
+                                       ast_copy_string(azone->alias, cxt, sizeof(azone->alias));
                                        if (ast_register_indication_country(azone)) {
                                                ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno);
-                                               free(tones);
+                                               ast_destroy_indication_zone(tones);
                                        }
                                        /* next item */
                                        country = strsep(&c,",");
                                }
                        } else {
-                               // add tone to country
-                               struct tone_zone_sound *ps,*ts;
-                               for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) {
-                                       if (strcasecmp(v->name,ts->name)==0) {
+                               struct ind_tone_zone_sound *ts;
+
+                               /* add tone to country */
+                               AST_LIST_TRAVERSE(&tones->tones, ts, list) {
+                                       if (!strcasecmp(v->name, ts->name)) {
                                                /* already there */
-                                               ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped.\n",v->name);
+                                               ast_log(LOG_NOTICE, "Duplicate entry '%s' skipped.\n", v->name);
                                                goto out;
                                        }
                                }
+
                                /* not there, add it to the back */
-                               ts = malloc(sizeof(struct tone_zone_sound));
-                               if (!ts) {
-                                       ast_log(LOG_WARNING, "Out of memory\n");
-                                       ast_destroy(cfg);
+                               if (!(ts = ast_calloc(1, sizeof(*ts)))) {
+                                       ast_config_destroy(cfg);
                                        return -1;
                                }
-                               ts->next = NULL;
-                               ts->name = strdup(v->name);
-                               ts->data = strdup(v->value);
-                               if (ps)
-                                       ps->next = ts;
-                               else
-                                       tones->tones = ts;
+                               ts->name = ast_strdup(v->name);
+                               ts->data = ast_strdup(v->value);
+
+                               AST_LIST_INSERT_TAIL(&tones->tones, ts, list);
                        }
 out:                   v = v->next;
                }
-               if (tones->description[0] || tones->alias[0] || tones->tones) {
+               if (tones->description[0] || tones->alias[0] || !AST_LIST_EMPTY(&tones->tones)) {
                        if (ast_register_indication_country(tones)) {
                                ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno);
-                               free(tones);
+                               ast_destroy_indication_zone(tones);
                        }
-               } else free(tones);
+               } else {
+                       ast_destroy_indication_zone(tones);
+               }
 
                cxt = ast_category_browse(cfg, cxt);
        }
 
        /* determine which country is the default */
        country = ast_variable_retrieve(cfg,"general","country");
-       if (!country || !*country || ast_set_indication_country(country))
+       if (ast_strlen_zero(country) || ast_set_indication_country(country)) {
                ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n");
+       }
 
-       ast_destroy(cfg);
+       ast_config_destroy(cfg);
        return 0;
 }
 
-/*
- * CLI entries for commands provided by this module
- */
-static struct ast_cli_entry add_indication_cli =
-       { { "add", "indication", NULL }, handle_add_indication,
-               "Add the given indication to the country", help_add_indication,
-               NULL };
-
-static struct ast_cli_entry remove_indication_cli =
-       { { "remove", "indication", NULL }, handle_remove_indication,
-               "Remove the given indication from the country", help_remove_indication,
-               NULL };
-
-static struct ast_cli_entry show_indications_cli =
-       { { "show", "indications", NULL }, handle_show_indications,
-               "Show a list of all country/indications", help_show_indications,
-               NULL };
+/*! \brief CLI entries for commands provided by this module */
+static struct ast_cli_entry cli_indications[] = {
+       AST_CLI_DEFINE(handle_cli_indication_add,    "Add the given indication to the country"),
+       AST_CLI_DEFINE(handle_cli_indication_remove, "Remove the given indication from the country"),
+       AST_CLI_DEFINE(handle_cli_indication_show,   "Display a list of all countries/indications")
+};
 
-/*
- * Standard module functions ...
- */
-int unload_module(void)
+/*! \brief Unload indicators module */
+static int unload_module(void)
 {
        /* remove the registed indications... */
        ast_unregister_indication_country(NULL);
 
        /* and the functions */
-       ast_cli_unregister(&add_indication_cli);
-       ast_cli_unregister(&remove_indication_cli);
-       ast_cli_unregister(&show_indications_cli);
-       ast_unregister_application("Playlist");
-       ast_unregister_application("StopPlaylist");
+       ast_cli_unregister_multiple(cli_indications, ARRAY_LEN(cli_indications));
+       ast_unregister_application("PlayTones");
+       ast_unregister_application("StopPlayTones");
        return 0;
 }
 
-int load_module(void)
-{
-       if (ind_load_module()) return -1;
-       ast_cli_register(&add_indication_cli);
-       ast_cli_register(&remove_indication_cli);
-       ast_cli_register(&show_indications_cli);
-       ast_register_application("Playtones", handle_playtones, "Play a tone list","Play a tone list, either registered (through indications.conf) or a direct list of tones and durations.");
-       ast_register_application("StopPlaytones", handle_stopplaytones, "Stop playing a tone list","Stop playing a tone list");
-
-       return 0;
-}
 
-int reload(void)
+/*! \brief Load indications module */
+static int load_module(void)
 {
-       /* remove the registed indications... */
-       ast_unregister_indication_country(NULL);
+       if (ind_load_module(0))
+               return AST_MODULE_LOAD_DECLINE; 
+       ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
+       ast_register_application_xml("PlayTones", handle_playtones);
+       ast_register_application_xml("StopPlayTones", handle_stopplaytones);
 
-       return ind_load_module();
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
-char *description(void)
+/*! \brief Reload indications module */
+static int reload(void)
 {
-       /* that the following cast is needed, is yuk! */
-       return (char*)dtext;
+       return ind_load_module(1);
 }
 
-int usecount(void)
-{
-       return 0;
-}
-
-char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Region-specific tones",
+               .load = load_module,
+               .unload = unload_module,
+               .reload = reload,
+              );