Fix up the AGI doc dump CLI command and update the AGI commands tex file to not
[asterisk/asterisk.git] / res / res_indications.c
index 1188b05..7397218 100644 (file)
  * Load the country specific dialtones into the asterisk PBX.
  */
  
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/lock.h"
 #include "asterisk/file.h"
 #include "asterisk/cli.h"
@@ -50,7 +50,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/utils.h"
 
 /* Globals */
-static const char dtext[] = "Indications Configuration";
 static const char config[] = "indications.conf";
 
 /*
@@ -65,8 +64,8 @@ static char help_remove_indication[] =
 "       Remove the given indication from the country.\n";
 
 static char help_show_indications[] =
-"Usage: show indications [<country> ...]\n"
-"       Show either a condensed for of all country/indications, or the\n"
+"Usage: indication show [<country> ...]\n"
+"       Display either a condensed for of all country/indications, or the\n"
 "       indications for the specified countries.\n";
 
 char *playtones_desc=
@@ -86,7 +85,7 @@ char *playtones_desc=
  */
 static int handle_add_indication(int fd, int argc, char *argv[])
 {
-       struct tone_zone *tz;
+       struct ind_tone_zone *tz;
        int created_country = 0;
        if (argc != 5) return RESULT_SHOWUSAGE;
 
@@ -101,7 +100,7 @@ static int handle_add_indication(int fd, int argc, char *argv[])
                ast_copy_string(tz->country,argv[2],sizeof(tz->country));
                if (ast_register_indication_country(tz)) {
                        ast_log(LOG_WARNING, "Unable to register new country\n");
-                       free(tz);
+                       ast_free(tz);
                        return -1;
                }
                created_country = 1;
@@ -120,7 +119,7 @@ static int handle_add_indication(int fd, int argc, char *argv[])
  */
 static int handle_remove_indication(int fd, int argc, char *argv[])
 {
-       struct tone_zone *tz;
+       struct ind_tone_zone *tz;
        if (argc != 3 && argc != 4) return RESULT_SHOWUSAGE;
 
        if (argc == 3) {
@@ -149,31 +148,25 @@ static int handle_remove_indication(int fd, int argc, char *argv[])
  */
 static int handle_show_indications(int fd, int argc, char *argv[])
 {
-       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;
-       }
        if (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) {
+               while ( (tz = ast_walk_indications(tz) ) )
                        ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
-               }
-               ast_mutex_unlock(&tzlock);
                return 0;
        }
        /* there was a request for specific country(ies), lets humor them */
-       for (tz=tone_zones; tz; tz=tz->next) {
+       while ( (tz = ast_walk_indications(tz) ) ) {
                int i,j;
                for (i=2; i<argc; i++) {
                        if (strcasecmp(tz->country,argv[i])==0 &&
                            !tz->alias[0]) {
-                               struct tone_zone_sound* ts;
+                               struct ind_tone_zone_sound* ts;
                                if (!found_country) {
                                        found_country = 1;
                                        ast_cli(fd,"Country Indication      PlayList\n"
@@ -183,7 +176,8 @@ static int handle_show_indications(int fd, int argc, char *argv[])
                                for (i=0; i<tz->nrringcadence; i++) {
                                        j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadence[i]);
                                }
-                               if (tz->nrringcadence) j--;
+                               if (tz->nrringcadence)
+                                       j--;
                                ast_copy_string(buf+j,"\n",sizeof(buf)-j);
                                ast_cli(fd,buf);
                                for (ts=tz->tones; ts; ts=ts->next)
@@ -194,7 +188,6 @@ static int handle_show_indications(int fd, int argc, char *argv[])
        }
        if (!found_country)
                ast_cli(fd,"No countries matched your criteria.\n");
-       ast_mutex_unlock(&tzlock);
        return -1;
 }
 
@@ -203,7 +196,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
  */
 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]) {
@@ -238,14 +231,14 @@ static int ind_load_module(void)
        struct ast_variable *v;
        char *cxt;
        char *c;
-       struct tone_zone *tones;
+       struct ind_tone_zone *tones;
        const char *country = NULL;
 
        /* that the following cast is needed, is yuk! */
        /* yup, checked it out. It is NOT written to. */
        cfg = ast_config_load((char *)config);
        if (!cfg)
-               return 0;
+               return -1;
 
        /* Use existing config to populate the Indication table */
        cxt = ast_category_browse(cfg, NULL);
@@ -291,7 +284,7 @@ static int ind_load_module(void)
                                c = countries;
                                country = strsep(&c,",");
                                while (country) {
-                                       struct tone_zone* azone;
+                                       struct ind_tone_zone* azone;
                                        if (!(azone = ast_calloc(1, sizeof(*azone)))) {
                                                ast_config_destroy(cfg);
                                                return -1;
@@ -300,14 +293,14 @@ static int ind_load_module(void)
                                        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_free(tones);
                                        }
                                        /* next item */
                                        country = strsep(&c,",");
                                }
                        } else {
                                /* add tone to country */
-                               struct tone_zone_sound *ps,*ts;
+                               struct ind_tone_zone_sound *ps,*ts;
                                for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) {
                                        if (strcasecmp(v->name,ts->name)==0) {
                                                /* already there */
@@ -321,8 +314,8 @@ static int ind_load_module(void)
                                        return -1;
                                }
                                ts->next = NULL;
-                               ts->name = strdup(v->name);
-                               ts->data = strdup(v->value);
+                               ts->name = ast_strdup(v->name);
+                               ts->data = ast_strdup(v->value);
                                if (ps)
                                        ps->next = ts;
                                else
@@ -333,9 +326,9 @@ out:                        v = v->next;
                if (tones->description[0] || tones->alias[0] || 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_free(tones);
                        }
-               } else free(tones);
+               } else ast_free(tones);
 
                cxt = ast_category_browse(cfg, cxt);
        }
@@ -352,53 +345,48 @@ out:                      v = v->next;
 /*
  * CLI entries for commands provided by this module
  */
-static struct ast_cli_entry add_indication_cli =
-       { { "indication", "add", NULL }, handle_add_indication,
-               "Add the given indication to the country", help_add_indication,
-               NULL };
+static struct ast_cli_entry cli_indications[] = {
+       { { "indication", "add", NULL },
+       handle_add_indication, "Add the given indication to the country",
+       help_add_indication, NULL },
 
-static struct ast_cli_entry remove_indication_cli =
-       { { "indication", "remove", NULL }, handle_remove_indication,
-               "Remove the given indication from the country", help_remove_indication,
-               NULL };
+       { { "indication", "remove", 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 };
+       { { "indication", "show", NULL },
+       handle_show_indications, "Display a list of all countries/indications",
+       help_show_indications },
+};
 
 /*
  * Standard module functions ...
  */
-int unload_module(void)
+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_cli_unregister_multiple(cli_indications, sizeof(cli_indications) / sizeof(struct ast_cli_entry));
        ast_unregister_application("PlayTones");
        ast_unregister_application("StopPlayTones");
        return 0;
 }
 
 
-int load_module(void)
+static 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);
+       if (ind_load_module())
+               return AST_MODULE_LOAD_DECLINE; 
+       ast_cli_register_multiple(cli_indications, sizeof(cli_indications) / sizeof(struct ast_cli_entry));
        ast_register_application("PlayTones", handle_playtones, "Play a tone list", playtones_desc);
        ast_register_application("StopPlayTones", handle_stopplaytones, "Stop playing a tone list","Stop playing a tone list");
 
        return 0;
 }
 
-int reload(void)
+static int reload(void)
 {
        /* remove the registed indications... */
        ast_unregister_indication_country(NULL);
@@ -406,18 +394,8 @@ int reload(void)
        return ind_load_module();
 }
 
-char *description(void)
-{
-       /* that the following cast is needed, is yuk! */
-       return (char*)dtext;
-}
-
-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,
+              );