make configuration variable const so they are not accidentally
authorLuigi Rizzo <rizzo@icir.org>
Tue, 18 Dec 2007 10:24:58 +0000 (10:24 +0000)
committerLuigi Rizzo <rizzo@icir.org>
Tue, 18 Dec 2007 10:24:58 +0000 (10:24 +0000)
modified.
This requires casting the strings in asterisk.c when writing to
them, so we do it through a macro to do it consistently.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@93603 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
include/asterisk/paths.h
main/asterisk.c
res/res_crypto.c
res/res_monitor.c
utils/ael_main.c
utils/conf2ael.c
utils/extconf.c

index 467dcd7..d6fa8f9 100644 (file)
@@ -2907,7 +2907,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin,
        char regseconds[20];
        char *tablename = NULL;
 
-       char *sysname = ast_config_AST_SYSTEM_NAME;
+       const char *sysname = ast_config_AST_SYSTEM_NAME;
        char *syslabel = NULL;
 
        time_t nowtime = time(NULL) + expirey;
index f539c07..7c5f5aa 100644 (file)
 
 #ifndef _ASTERISK_PATHS_H
 #define _ASTERISK_PATHS_H
+#
+extern const char ast_config_AST_CONFIG_DIR[PATH_MAX];
+extern const char ast_config_AST_CONFIG_FILE[PATH_MAX];
+extern const char ast_config_AST_MODULE_DIR[PATH_MAX];
+extern const char ast_config_AST_SPOOL_DIR[PATH_MAX];
+extern const char ast_config_AST_MONITOR_DIR[PATH_MAX];
+extern const char ast_config_AST_VAR_DIR[PATH_MAX];
+extern const char ast_config_AST_DATA_DIR[PATH_MAX];
+extern const char ast_config_AST_LOG_DIR[PATH_MAX];
+extern const char ast_config_AST_AGI_DIR[PATH_MAX];
+extern const char ast_config_AST_DB[PATH_MAX];
+extern const char ast_config_AST_KEY_DIR[PATH_MAX];
+extern const char ast_config_AST_PID[PATH_MAX];
+extern const char ast_config_AST_SOCKET[PATH_MAX];
+extern const char ast_config_AST_RUN_DIR[PATH_MAX];
+extern const char ast_config_AST_RUN_GROUP[PATH_MAX];
+extern const char ast_config_AST_RUN_USER[PATH_MAX];
+extern const char ast_config_AST_SYSTEM_NAME[20];
+
+#if 0 /* only used in main/asterisk.c */
+extern const char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
+extern const char ast_config_AST_CTL_OWNER[PATH_MAX];
+extern const char ast_config_AST_CTL_GROUP[PATH_MAX];
+extern const char ast_config_AST_CTL[PATH_MAX];
+#endif
 
-extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
-extern char ast_config_AST_CONFIG_FILE[PATH_MAX];
-extern char ast_config_AST_MODULE_DIR[PATH_MAX];
-extern char ast_config_AST_SPOOL_DIR[PATH_MAX];
-extern char ast_config_AST_MONITOR_DIR[PATH_MAX];
-extern char ast_config_AST_VAR_DIR[PATH_MAX];
-extern char ast_config_AST_DATA_DIR[PATH_MAX];
-extern char ast_config_AST_LOG_DIR[PATH_MAX];
-extern char ast_config_AST_AGI_DIR[PATH_MAX];
-extern char ast_config_AST_DB[PATH_MAX];
-extern char ast_config_AST_KEY_DIR[PATH_MAX];
-extern char ast_config_AST_PID[PATH_MAX];
-extern char ast_config_AST_SOCKET[PATH_MAX];
-extern char ast_config_AST_RUN_DIR[PATH_MAX];
-extern char ast_config_AST_RUN_GROUP[PATH_MAX];
-extern char ast_config_AST_RUN_USER[PATH_MAX];
-extern char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
-extern char ast_config_AST_CTL_OWNER[PATH_MAX];
-extern char ast_config_AST_CTL_GROUP[PATH_MAX];
-extern char ast_config_AST_CTL[PATH_MAX];
-extern char ast_config_AST_SYSTEM_NAME[20];
 
 #endif /* _ASTERISK_PATHS_H */
index ae82512..d869d3c 100644 (file)
@@ -92,6 +92,7 @@ int daemon(int, int);  /* defined in libresolv of all places */
 #include <sys/loadavg.h>
 #endif
 
+#include "asterisk/paths.h"    /* we define here the variables so better agree on the prototype */
 #include "asterisk/network.h"
 #include "asterisk/cli.h"
 #include "asterisk/channel.h"
@@ -199,27 +200,27 @@ static int ast_el_add_history(char *);
 static int ast_el_read_history(char *);
 static int ast_el_write_history(char *);
 
-char ast_config_AST_CONFIG_DIR[PATH_MAX];
-char ast_config_AST_CONFIG_FILE[PATH_MAX];
-char ast_config_AST_MODULE_DIR[PATH_MAX];
-char ast_config_AST_SPOOL_DIR[PATH_MAX];
-char ast_config_AST_MONITOR_DIR[PATH_MAX];
-char ast_config_AST_VAR_DIR[PATH_MAX];
-char ast_config_AST_DATA_DIR[PATH_MAX];
-char ast_config_AST_LOG_DIR[PATH_MAX];
-char ast_config_AST_AGI_DIR[PATH_MAX];
-char ast_config_AST_DB[PATH_MAX];
-char ast_config_AST_KEY_DIR[PATH_MAX];
-char ast_config_AST_PID[PATH_MAX];
-char ast_config_AST_SOCKET[PATH_MAX];
-char ast_config_AST_RUN_DIR[PATH_MAX];
-char ast_config_AST_RUN_USER[PATH_MAX];
-char ast_config_AST_RUN_GROUP[PATH_MAX];
-char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
-char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
-char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
-char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
-char ast_config_AST_SYSTEM_NAME[20] = "";
+const char ast_config_AST_CONFIG_DIR[PATH_MAX];
+const char ast_config_AST_CONFIG_FILE[PATH_MAX];
+const char ast_config_AST_MODULE_DIR[PATH_MAX];
+const char ast_config_AST_SPOOL_DIR[PATH_MAX];
+const char ast_config_AST_MONITOR_DIR[PATH_MAX];
+const char ast_config_AST_VAR_DIR[PATH_MAX];
+const char ast_config_AST_DATA_DIR[PATH_MAX];
+const char ast_config_AST_LOG_DIR[PATH_MAX];
+const char ast_config_AST_AGI_DIR[PATH_MAX];
+const char ast_config_AST_DB[PATH_MAX];
+const char ast_config_AST_KEY_DIR[PATH_MAX];
+const char ast_config_AST_PID[PATH_MAX];
+const char ast_config_AST_SOCKET[PATH_MAX];
+const char ast_config_AST_RUN_DIR[PATH_MAX];
+const char ast_config_AST_RUN_USER[PATH_MAX];
+const char ast_config_AST_RUN_GROUP[PATH_MAX];
+static const char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
+static const char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
+static const char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
+static const char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
+const char ast_config_AST_SYSTEM_NAME[20] = "";
 
 extern const char *ast_build_hostname;
 extern const char *ast_build_kernel;
@@ -2419,19 +2420,20 @@ static void ast_readconfig(void)
                cfg = ast_config_load(config, config_flags);
 
        /* init with buildtime config */
-       ast_copy_string(ast_config_AST_CONFIG_DIR, DEFAULT_CONFIG_DIR, sizeof(ast_config_AST_CONFIG_DIR));
-       ast_copy_string(ast_config_AST_SPOOL_DIR, DEFAULT_SPOOL_DIR, sizeof(ast_config_AST_SPOOL_DIR));
-       ast_copy_string(ast_config_AST_MODULE_DIR, DEFAULT_MODULE_DIR, sizeof(ast_config_AST_MODULE_DIR));
-       snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
-       ast_copy_string(ast_config_AST_VAR_DIR, DEFAULT_VAR_DIR, sizeof(ast_config_AST_VAR_DIR));
-       ast_copy_string(ast_config_AST_DATA_DIR, DEFAULT_DATA_DIR, sizeof(ast_config_AST_DATA_DIR));
-       ast_copy_string(ast_config_AST_LOG_DIR, DEFAULT_LOG_DIR, sizeof(ast_config_AST_LOG_DIR));
-       ast_copy_string(ast_config_AST_AGI_DIR, DEFAULT_AGI_DIR, sizeof(ast_config_AST_AGI_DIR));
-       ast_copy_string(ast_config_AST_DB, DEFAULT_DB, sizeof(ast_config_AST_DB));
-       ast_copy_string(ast_config_AST_KEY_DIR, DEFAULT_KEY_DIR, sizeof(ast_config_AST_KEY_DIR));
-       ast_copy_string(ast_config_AST_PID, DEFAULT_PID, sizeof(ast_config_AST_PID));
-       ast_copy_string(ast_config_AST_SOCKET, DEFAULT_SOCKET, sizeof(ast_config_AST_SOCKET));
-       ast_copy_string(ast_config_AST_RUN_DIR, DEFAULT_RUN_DIR, sizeof(ast_config_AST_RUN_DIR));
+#define _SETVAR(dst, src)      ast_copy_string((char *)dst, src, sizeof(dst))
+       _SETVAR(ast_config_AST_CONFIG_DIR, DEFAULT_CONFIG_DIR);
+       _SETVAR(ast_config_AST_SPOOL_DIR, DEFAULT_SPOOL_DIR);
+       _SETVAR(ast_config_AST_MODULE_DIR, DEFAULT_MODULE_DIR);
+       snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
+       _SETVAR(ast_config_AST_VAR_DIR, DEFAULT_VAR_DIR);
+       _SETVAR(ast_config_AST_DATA_DIR, DEFAULT_DATA_DIR);
+       _SETVAR(ast_config_AST_LOG_DIR, DEFAULT_LOG_DIR);
+       _SETVAR(ast_config_AST_AGI_DIR, DEFAULT_AGI_DIR);
+       _SETVAR(ast_config_AST_DB, DEFAULT_DB);
+       _SETVAR(ast_config_AST_KEY_DIR, DEFAULT_KEY_DIR);
+       _SETVAR(ast_config_AST_PID, DEFAULT_PID);
+       _SETVAR(ast_config_AST_SOCKET, DEFAULT_SOCKET);
+       _SETVAR(ast_config_AST_RUN_DIR, DEFAULT_RUN_DIR);
 
        /* no asterisk.conf? no problem, use buildtime config! */
        if (!cfg) {
@@ -2440,45 +2442,45 @@ static void ast_readconfig(void)
 
        for (v = ast_variable_browse(cfg, "files"); v; v = v->next) {
                if (!strcasecmp(v->name, "astctlpermissions"))
-                       ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS));
+                       _SETVAR(ast_config_AST_CTL_PERMISSIONS, v->value);
                else if (!strcasecmp(v->name, "astctlowner"))
-                       ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER));
+                       _SETVAR(ast_config_AST_CTL_OWNER, v->value);
                else if (!strcasecmp(v->name, "astctlgroup"))
-                       ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP));
+                       _SETVAR(ast_config_AST_CTL_GROUP, v->value);
                else if (!strcasecmp(v->name, "astctl"))
-                       ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL));
+                       _SETVAR(ast_config_AST_CTL, v->value);
        }
 
        for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) {
                if (!strcasecmp(v->name, "astetcdir")) {
-                       ast_copy_string(ast_config_AST_CONFIG_DIR, v->value, sizeof(ast_config_AST_CONFIG_DIR));
+                       _SETVAR(ast_config_AST_CONFIG_DIR, v->value);
                } else if (!strcasecmp(v->name, "astspooldir")) {
-                       ast_copy_string(ast_config_AST_SPOOL_DIR, v->value, sizeof(ast_config_AST_SPOOL_DIR));
-                       snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
+                       _SETVAR(ast_config_AST_SPOOL_DIR, v->value);
+                       snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
                } else if (!strcasecmp(v->name, "astvarlibdir")) {
-                       ast_copy_string(ast_config_AST_VAR_DIR, v->value, sizeof(ast_config_AST_VAR_DIR));
+                       _SETVAR(ast_config_AST_VAR_DIR, v->value);
                        if (!found.dbdir)
-                               snprintf(ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+                               snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
                } else if (!strcasecmp(v->name, "astdbdir")) {
-                       snprintf(ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+                       snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
                        found.dbdir = 1;
                } else if (!strcasecmp(v->name, "astdatadir")) {
-                       ast_copy_string(ast_config_AST_DATA_DIR, v->value, sizeof(ast_config_AST_DATA_DIR));
+                       _SETVAR(ast_config_AST_DATA_DIR, v->value);
                        if (!found.keydir)
-                               snprintf(ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+                               snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
                } else if (!strcasecmp(v->name, "astkeydir")) {
-                       snprintf(ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+                       snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
                        found.keydir = 1;
                } else if (!strcasecmp(v->name, "astlogdir")) {
-                       ast_copy_string(ast_config_AST_LOG_DIR, v->value, sizeof(ast_config_AST_LOG_DIR));
+                       _SETVAR(ast_config_AST_LOG_DIR, v->value);
                } else if (!strcasecmp(v->name, "astagidir")) {
-                       ast_copy_string(ast_config_AST_AGI_DIR, v->value, sizeof(ast_config_AST_AGI_DIR));
+                       _SETVAR(ast_config_AST_AGI_DIR, v->value);
                } else if (!strcasecmp(v->name, "astrundir")) {
-                       snprintf(ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
-                       snprintf(ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
-                       ast_copy_string(ast_config_AST_RUN_DIR, v->value, sizeof(ast_config_AST_RUN_DIR));
+                       snprintf((char *)ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
+                       snprintf((char *)ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
+                       _SETVAR(ast_config_AST_RUN_DIR, v->value);
                } else if (!strcasecmp(v->name, "astmoddir")) {
-                       ast_copy_string(ast_config_AST_MODULE_DIR, v->value, sizeof(ast_config_AST_MODULE_DIR));
+                       _SETVAR(ast_config_AST_MODULE_DIR, v->value);
                }
        }
 
@@ -2561,19 +2563,19 @@ static void ast_readconfig(void)
                        set_ulimit(option_maxfiles);
                /* What user to run as */
                } else if (!strcasecmp(v->name, "runuser")) {
-                       ast_copy_string(ast_config_AST_RUN_USER, v->value, sizeof(ast_config_AST_RUN_USER));
+                       _SETVAR(ast_config_AST_RUN_USER, v->value);
                /* What group to run as */
                } else if (!strcasecmp(v->name, "rungroup")) {
-                       ast_copy_string(ast_config_AST_RUN_GROUP, v->value, sizeof(ast_config_AST_RUN_GROUP));
+                       _SETVAR(ast_config_AST_RUN_GROUP, v->value);
                } else if (!strcasecmp(v->name, "systemname")) {
-                       ast_copy_string(ast_config_AST_SYSTEM_NAME, v->value, sizeof(ast_config_AST_SYSTEM_NAME));
+                       _SETVAR(ast_config_AST_SYSTEM_NAME, v->value);
                } else if (!strcasecmp(v->name, "autosystemname")) {
                        if (ast_true(v->value)) {
                                if (!gethostname(hostname, sizeof(hostname) - 1))
-                                       ast_copy_string(ast_config_AST_SYSTEM_NAME, hostname, sizeof(ast_config_AST_SYSTEM_NAME));
+                                       _SETVAR(ast_config_AST_SYSTEM_NAME, hostname);
                                else {
                                        if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){
-                                               ast_copy_string(ast_config_AST_SYSTEM_NAME, "localhost", sizeof(ast_config_AST_SYSTEM_NAME));
+                                               _SETVAR(ast_config_AST_SYSTEM_NAME, "localhost");
                                        }
                                        ast_log(LOG_ERROR, "Cannot obtain hostname for this system.  Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME);
                                }
@@ -2636,7 +2638,7 @@ int main(int argc, char *argv[])
        int num;
        int isroot = 1;
        char *buf;
-       char *runuser = NULL, *rungroup = NULL;
+       const char *runuser = NULL, *rungroup = NULL;
 
        /* Remember original args for restart */
        if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
@@ -2732,7 +2734,7 @@ int main(int argc, char *argv[])
                        xarg = optarg;
                        break;
                case 'C':
-                       ast_copy_string(ast_config_AST_CONFIG_FILE, optarg, sizeof(ast_config_AST_CONFIG_FILE));
+                       _SETVAR(ast_config_AST_CONFIG_FILE, optarg);
                        ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
                        break;
                case 'I':
index fc7f08a..f1a2234 100644 (file)
@@ -146,7 +146,7 @@ static struct ast_key *__ast_key_get(const char *kname, int ktype)
  * \retval key on success.
  * \retval NULL on failure.
 */
-static struct ast_key *try_load_key(char *dir, char *fname, int ifd, int ofd, int *not2)
+static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, int ofd, int *not2)
 {
        int ktype = 0, found = 0;
        char *c = NULL, ffname[256];
index 617b7b6..3ce3b6d 100644 (file)
@@ -320,7 +320,7 @@ int ast_monitor_stop(struct ast_channel *chan, int need_lock)
                        const char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
                        char *name = chan->monitor->filename_base;
                        int directory = strchr(name, '/') ? 1 : 0;
-                       char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
+                       const char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
                        const char *execute, *execute_args;
 
                        /* Set the execute application */
index 830b838..68b5dc4 100644 (file)
@@ -82,8 +82,8 @@ struct namelist *globalvars_last;
 
 int conts=0, extens=0, priors=0;
 char last_exten[18000];
-char ast_config_AST_CONFIG_DIR[PATH_MAX];
-char ast_config_AST_VAR_DIR[PATH_MAX];
+const char ast_config_AST_CONFIG_DIR[PATH_MAX];
+const char ast_config_AST_VAR_DIR[PATH_MAX];
 
 void ast_cli_register_multiple(void);
 int ast_add_extension2(struct ast_context *con,
@@ -514,14 +514,14 @@ int main(int argc, char **argv)
        }
 
        if( use_curr_dir ) {
-               strcpy(ast_config_AST_CONFIG_DIR, ".");
+               strcpy((char *)ast_config_AST_CONFIG_DIR, ".");
                localized_use_local_dir();
        }
        else {
-               strcpy(ast_config_AST_CONFIG_DIR, "/etc/asterisk");
+               strcpy((char *)ast_config_AST_CONFIG_DIR, "/etc/asterisk");
                localized_use_conf_dir();
        }
-       strcpy(ast_config_AST_VAR_DIR, "/var/lib/asterisk");
+       strcpy((char *)ast_config_AST_VAR_DIR, "/var/lib/asterisk");
        
        if( dump_extensions ) {
                dumpfile = fopen("extensions.conf.aeldump","w");
index 4983b5b..b8cae75 100644 (file)
@@ -63,7 +63,7 @@ void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *sta
 int all_bits_set(unsigned int *word, int bitsperword, int totalbits);
 extern char *days[];
 extern char *months[];
-char ast_config_AST_CONFIG_DIR[PATH_MAX];
+const char ast_config_AST_CONFIG_DIR[PATH_MAX];
 
 char *config = "extensions.conf";
 
@@ -79,7 +79,7 @@ char ast_config_AST_SYSTEM_NAME[20] = ""; */
 /*! Go no deeper than this through includes (not counting loops) */
 #define AST_PBX_MAX_STACK      128
 /* static AST_RWLIST_HEAD_STATIC(acf_root, ast_custom_function); */
-extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
+//extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
 
 void ast_register_file_version(const char *file, const char *version)
 {
@@ -363,7 +363,7 @@ int main(int argc, char **argv)
        if (!localdir)
                printf(" (You could use -d the use the extensions.conf in the current directory!)\n");
 
-       strcpy(ast_config_AST_CONFIG_DIR,"/etc/asterisk");
+       strcpy((char *)ast_config_AST_CONFIG_DIR,"/etc/asterisk");
        
        printf("Loading %s/%s...\n", ast_config_AST_CONFIG_DIR, config);
 
index c6e8cf6..4621e34 100644 (file)
@@ -53,7 +53,7 @@
 # include <glob.h>
 #endif
 
-static char ast_config_AST_CONFIG_DIR[PATH_MAX] = {"/etc/asterisk"};
+static const char ast_config_AST_CONFIG_DIR[PATH_MAX] = {"/etc/asterisk"};
 #define AST_API_MODULE  1 /* gimme the inline defs! */
 struct ast_channel 
 {