Create binary versions of signature functions
[asterisk/asterisk.git] / res / res_indications.c
index 3ed4c08..b289612 100755 (executable)
@@ -18,7 +18,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
-#include <pthread.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -133,7 +132,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
        char buf[256];
        int found_country = 0;
 
-       if (ast_pthread_mutex_lock(&tzlock)) {
+       if (ast_mutex_lock(&tzlock)) {
                ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
                return 0;
        }
@@ -144,7 +143,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
                for (tz=tone_zones; tz; tz=tz->next) {
                        ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
                }
-               ast_pthread_mutex_unlock(&tzlock);
+               ast_mutex_unlock(&tzlock);
                return 0;
        }
        /* there was a request for specific country(ies), lets humor them */
@@ -164,7 +163,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
                                        j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadance[i]);
                                }
                                if (tz->nrringcadance) j--;
-                               strncpy(buf+j,"\n",sizeof(buf)-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);
@@ -174,7 +173,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
        }
        if (!found_country)
                ast_cli(fd,"No countries matched your criteria.\n");
-       ast_pthread_mutex_unlock(&tzlock);
+       ast_mutex_unlock(&tzlock);
        return -1;
 }
 
@@ -238,17 +237,18 @@ static int ind_load_module(void)
                tones = malloc(sizeof(struct tone_zone));
                if (!tones) {
                        ast_log(LOG_WARNING,"Out of memory\n");
+                       ast_destroy(cfg);
                        return -1;
                }
                memset(tones,0,sizeof(struct tone_zone));
-               strncpy(tones->country,cxt,sizeof(tones->country));
+               strncpy(tones->country,cxt,sizeof(tones->country) - 1);
 
                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")) {
-                               char *ring,*rings = strdupa(v->value);
+                               char *ring,*rings = ast_strdupa(v->value);
                                c = rings;
                                ring = strsep(&c,",");
                                while (ring) {
@@ -261,6 +261,7 @@ static int ind_load_module(void)
                                        tmp = realloc(tones->ringcadance,(tones->nrringcadance+1)*sizeof(int));
                                        if (!tmp) {
                                                ast_log(LOG_WARNING, "Out of memory\n");
+                                               ast_destroy(cfg);
                                                return -1;
                                        }
                                        tones->ringcadance = tmp;
@@ -270,17 +271,18 @@ static int ind_load_module(void)
                                        ring = strsep(&c,",");
                                }
                        } else if (!strcasecmp(v->name,"alias")) {
-                               char *countries = strdupa(v->value);
+                               char *countries = ast_strdupa(v->value);
                                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);
                                                return -1;
                                        }
                                        memset(azone,0,sizeof(struct tone_zone));
-                                       strncpy(azone->country,country,sizeof(azone->country));
+                                       strncpy(azone->country, country, sizeof(azone->country) - 1);
                                        strncpy(azone->alias, cxt, sizeof(azone->alias)-1);
                                        if (ast_register_indication_country(azone)) {
                                                ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno);
@@ -303,6 +305,7 @@ static int ind_load_module(void)
                                ts = malloc(sizeof(struct tone_zone_sound));
                                if (!ts) {
                                        ast_log(LOG_WARNING, "Out of memory\n");
+                                       ast_destroy(cfg);
                                        return -1;
                                }
                                ts->next = NULL;