diff --git a/app.c b/app.c
index c9076725539388e733cee67813edf54d4ac1a380..60f60cec9a61f2117b88a76dc88451645ffb7309 100644
--- a/app.c
+++ b/app.c
@@ -1006,7 +1006,7 @@ int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordf
 
 /* Channel group core functions */
 
-int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max)
+int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max)
 {
 	int res=0;
 	char tmp[256];
@@ -1035,7 +1035,7 @@ int ast_app_group_split_group(char *data, char *group, int group_max, char *cate
 	return res;
 }
 
-int ast_app_group_set_channel(struct ast_channel *chan, char *data)
+int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
 {
 	int res=0;
 	char group[80] = "";
@@ -1049,13 +1049,13 @@ int ast_app_group_set_channel(struct ast_channel *chan, char *data)
 	return res;
 }
 
-int ast_app_group_get_count(char *group, char *category)
+int ast_app_group_get_count(const char *group, const char *category)
 {
 	struct ast_channel *chan;
 	int count = 0;
-	char *test;
+	const char *test;
 	char cat[80];
-	char *s;
+	const char *s;
 
 	if (ast_strlen_zero(group))
 		return 0;
@@ -1074,14 +1074,14 @@ int ast_app_group_get_count(char *group, char *category)
 	return count;
 }
 
-int ast_app_group_match_get_count(char *groupmatch, char *category)
+int ast_app_group_match_get_count(const char *groupmatch, const char *category)
 {
 	regex_t regexbuf;
 	struct ast_channel *chan;
 	int count = 0;
-	char *test;
+	const char *test;
 	char cat[80];
-	char *s;
+	const char *s;
 
 	if (ast_strlen_zero(groupmatch))
 		return 0;
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index 7d9061579d4a58d0b9946abe95a458057988bbb1..80b271ec0e37ba9a9089a06cf6c62e10d80c5d99 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -468,7 +468,7 @@ static int chanspy_exec(struct ast_channel *chan, void *data)
 		prev=NULL;
 		while(peer) {
 			if (peer != chan) {
-				char *group = NULL;
+				const char *group = NULL;
 				int igrp = 1;
 
 				if (peer == prev && !chosen) {
diff --git a/apps/app_groupcount.c b/apps/app_groupcount.c
index aa848c2d5460d14bfb50158496d238174c8c3b3a..0d35ca3945fc75b61afbb5f633cac8bac87a0523 100644
--- a/apps/app_groupcount.c
+++ b/apps/app_groupcount.c
@@ -56,7 +56,6 @@ static int group_count_exec(struct ast_channel *chan, void *data)
 	char group[80] = "";
 	char category[80] = "";
 	char ret[80] = "";
-	char *grp;
 	static int deprecation_warning = 0;
 
 	LOCAL_USER_ADD(u);
@@ -69,7 +68,7 @@ static int group_count_exec(struct ast_channel *chan, void *data)
 	ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
 
 	if (ast_strlen_zero(group)) {
-		grp = pbx_builtin_getvar_helper(chan, category);
+		const char *grp = pbx_builtin_getvar_helper(chan, category);
 		strncpy(group, grp, sizeof(group) - 1);
 	}
 
diff --git a/apps/app_macro.c b/apps/app_macro.c
index 72b75777cc6a612cc074314c031c83b1bb75e674..f36e979c508f192508ee282aa5bd48123d291617 100644
--- a/apps/app_macro.c
+++ b/apps/app_macro.c
@@ -89,6 +89,8 @@ LOCAL_USER_DECL;
 
 static int macro_exec(struct ast_channel *chan, void *data)
 {
+	const char *s;
+
 	char *tmp;
 	char *cur, *rest;
 	char *macro;
@@ -101,8 +103,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
 	int oldpriority;
 	char pc[80], depthc[12];
 	char oldcontext[AST_MAX_CONTEXT] = "";
-	char *offsets;
-	int offset, depth;
+	int offset, depth = 0;
 	int setmacrocontext=0;
 	int autoloopflag;
   
@@ -120,13 +121,9 @@ static int macro_exec(struct ast_channel *chan, void *data)
 	LOCAL_USER_ADD(u);
 
 	/* Count how many levels deep the rabbit hole goes */
-	tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
-	if (tmp) {
-		sscanf(tmp, "%d", &depth);
-	} else {
-		depth = 0;
-	}
-
+	s = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
+	if (s)
+		sscanf(s, "%d", &depth);
 	if (depth >= 7) {
 		ast_log(LOG_ERROR, "Macro():  possible infinite loop detected.  Returning early.\n");
 		LOCAL_USER_REMOVE(u);
@@ -193,12 +190,13 @@ static int macro_exec(struct ast_channel *chan, void *data)
 	chan->priority = 1;
 
 	while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) {
+		const char *s;
   		/* Save copy of old arguments if we're overwriting some, otherwise
 	   	let them pass through to the other macro */
   		snprintf(varname, sizeof(varname), "ARG%d", argc);
-		oldargs[argc] = pbx_builtin_getvar_helper(chan, varname);
-		if (oldargs[argc])
-			oldargs[argc] = strdup(oldargs[argc]);
+		s = pbx_builtin_getvar_helper(chan, varname);
+		if (s)
+			oldargs[argc] = strdup(s);
 		pbx_builtin_setvar_helper(chan, varname, cur);
 		argc++;
 	}
@@ -286,6 +284,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
 		ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
 		if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
 			/* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
+			const char *offsets;
 			ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
 			if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
 				/* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 3c9bad6f103f149118bf77e1d2190b640e8b42c1..fb5f660ea34a810f114f97042cd9dd1512c90e02 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -143,8 +143,8 @@ static struct ast_conference {
 	int locked;				/* Is the conference locked? */
 	pthread_t recordthread;			/* thread for recording */
 	pthread_attr_t attr;			/* thread attribute */
-	char *recordingfilename;		/* Filename to record the Conference into */
-	char *recordingformat;			/* Format to record the Conference in */
+	const char *recordingfilename;		/* Filename to record the Conference into */
+	const char *recordingformat;			/* Format to record the Conference in */
 	char pin[AST_MAX_EXTENSION];		/* If protected by a PIN */
 	char pinadmin[AST_MAX_EXTENSION];	/* If protected by a admin PIN */
 	struct ast_conference *next;
@@ -813,8 +813,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
 	int duration=20;
 	struct ast_dsp *dsp=NULL;
 	struct ast_app *app;
-	char *agifile;
-	char *agifiledefault = "conf-background.agi";
+	const char *agifile;
+	const char *agifiledefault = "conf-background.agi";
 	char meetmesecs[30] = "";
 	char exitcontext[AST_MAX_CONTEXT] = "";
 	char recordingtmp[AST_MAX_EXTENSION] = "";
@@ -1086,7 +1086,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
 		/* Find a pointer to the agi app and execute the script */
 		app = pbx_findapp("agi");
 		if (app) {
-			ret = pbx_exec(chan, app, agifile, 1);
+			char *s = ast_strdupa(agifile);
+			ret = pbx_exec(chan, app, s, 1);
 		} else {
 			ast_log(LOG_WARNING, "Could not find application (agi)\n");
 			ret = -2;
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 7f28a6ece6688c87f61db1d25a8189775045c42c..5564d0fcd18e244d47c474ef009c0a564f9a0825 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -1992,7 +1992,6 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
 	char oldcontext[AST_MAX_CONTEXT]="";
 	char queuename[256]="";
 	char *newnum;
-	char *monitorfilename;
 	struct ast_channel *peer;
 	struct ast_channel *which;
 	struct localuser *lpeer;
@@ -2209,7 +2208,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
 		}
 		/* Begin Monitoring */
 		if (qe->parent->monfmt && *qe->parent->monfmt) {
-			monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME");
+			const char *monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME");
 			if (pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC") || pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC_ARGS"))
 				which = qe->chan;
 			else
@@ -2845,7 +2844,7 @@ static int queue_exec(struct ast_channel *chan, void *data)
 	char *options = NULL;
 	char *url = NULL;
 	char *announceoverride = NULL;
-	char *user_priority;
+	const char *user_priority;
 	int prio;
 	char *queuetimeoutstr = NULL;
 	enum queue_result reason = QUEUE_UNKNOWN;
diff --git a/apps/app_stack.c b/apps/app_stack.c
index d24f2267fa46ecd9b48d8ec409ecb59a36113b96..ccf24b2b47194696a3e52075b412aebeea10e3f0 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -82,7 +82,7 @@ static int pop_exec(struct ast_channel *chan, void *data)
 
 static int return_exec(struct ast_channel *chan, void *data)
 {
-	char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
+	const char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
 
 	if (ast_strlen_zero(label)) {
 		ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");
diff --git a/apps/app_while.c b/apps/app_while.c
index 7c98afe807ab25c434f2821fa1cca51758a4ce12..1c91446aacb57d80525e69dd463c5389f479896f 100644
--- a/apps/app_while.c
+++ b/apps/app_while.c
@@ -122,7 +122,7 @@ static int execif_exec(struct ast_channel *chan, void *data) {
 #define VAR_SIZE 64
 
 
-static char *get_index(struct ast_channel *chan, const char *prefix, int index) {
+static const char *get_index(struct ast_channel *chan, const char *prefix, int index) {
 	char varname[VAR_SIZE];
 
 	snprintf(varname, VAR_SIZE, "%s_%d", prefix, index);
@@ -209,15 +209,15 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
 {
 	int res=0;
 	struct localuser *u;
-	char *while_pri = NULL;
-	char *goto_str = NULL, *my_name = NULL;
-	char *condition = NULL, *label = NULL;
+	const char *while_pri = NULL;
+	char *my_name = NULL;
+	const char *condition = NULL, *label = NULL;
 	char varname[VAR_SIZE], end_varname[VAR_SIZE];
 	const char *prefix = "WHILE";
 	size_t size=0;
 	int used_index_i = -1, x=0;
 	char used_index[VAR_SIZE] = "0", new_index[VAR_SIZE] = "0";
-	
+
 	if (!chan) {
 		/* huh ? */
 		return -1;
@@ -271,6 +271,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
 
 	if (!end && !ast_true(condition)) {
 		/* Condition Met (clean up helper vars) */
+		const char *goto_str;
 		pbx_builtin_setvar_helper(chan, varname, NULL);
 		pbx_builtin_setvar_helper(chan, my_name, NULL);
         snprintf(end_varname,VAR_SIZE,"END_%s",varname);
@@ -291,6 +292,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
 	}
 
 	if (!end && !while_pri) {
+		char *goto_str;
 		size = strlen(chan->context) + strlen(chan->exten) + 32;
 		goto_str = alloca(size);
 		memset(goto_str, 0, size);
@@ -302,6 +304,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
 		/* END of loop */
 		snprintf(end_varname, VAR_SIZE, "END_%s", varname);
 		if (! pbx_builtin_getvar_helper(chan, end_varname)) {
+			char *goto_str;
 			size = strlen(chan->context) + strlen(chan->exten) + 32;
 			goto_str = alloca(size);
 			memset(goto_str, 0, size);
diff --git a/apps/app_zapscan.c b/apps/app_zapscan.c
index ed0c779772544fb1cc2264636a317a18a4e3f28f..337f52815c665f5275343044eba68b8ed029cfaf 100644
--- a/apps/app_zapscan.c
+++ b/apps/app_zapscan.c
@@ -296,7 +296,6 @@ static int conf_exec(struct ast_channel *chan, void *data)
 	char confstr[80] = "", *tmp = NULL;
 	struct ast_channel *tempchan = NULL, *lastchan = NULL,*ichan = NULL;
 	struct ast_frame *f;
-	char *mygroup;
 	char *desired_group;
 	int input=0,search_group=0;
 	
@@ -335,6 +334,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
 			break;
 		
 		if (tempchan && search_group) {
+			const char *mygroup;
 			if((mygroup = pbx_builtin_getvar_helper(tempchan, "GROUP")) && (!strcmp(mygroup, desired_group))) {
 				ast_verbose(VERBOSE_PREFIX_3 "Found Matching Channel %s in group %s\n", tempchan->name, desired_group);
 			} else {
diff --git a/channel.c b/channel.c
index 85a2882ff1e8f928f54882aaf6b0823df070b93e..b9869df25351d07b63ed8034dfe42266e011ec80 100644
--- a/channel.c
+++ b/channel.c
@@ -2770,7 +2770,7 @@ void ast_change_name(struct ast_channel *chan, char *newname)
 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
 {
 	struct ast_var_t *current, *newvar;
-	char *varname;
+	const char *varname;
 
 	AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
 		int vartype = 0;
@@ -3159,7 +3159,7 @@ struct ast_channel *ast_bridged_channel(struct ast_channel *chan)
 	return bridged;
 }
 
-static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer, char *sound, int remain) 
+static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain) 
 {
 	int res=0, min=0, sec=0,check=0;
 
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index a754f8a8f787546ad4fc047464c8311868624172..dfde90f0f845e4be4b7041fd37e4dcd3a27af624 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -1686,7 +1686,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
 			     AST_APP_ARG(options);
 			     AST_APP_ARG(extension);
 		);
-	char *tmpoptions = NULL;
+	const char *tmpoptions = NULL;
 	char *context = NULL;
 	int play_announcement = 1;
 	char agent_goodbye[AST_MAX_FILENAME_LEN];
@@ -2231,7 +2231,7 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
 	int nowarnings = 0;
 	int changeoutgoing = 0;
 	int res = 0;
-	char agent[AST_MAX_AGENT], *tmp;
+	char agent[AST_MAX_AGENT];
 
 	if (data) {
 		if (strchr(data, 'd'))
@@ -2242,6 +2242,7 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
 			changeoutgoing = 1;
 	}
 	if (chan->cid.cid_num) {
+		const char *tmp;
 		char agentvar[AST_MAX_BUF];
 		snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num);
 		if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) {
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 74b5da3f90ecf5b37db87654847b96b98e37d43c..00a813ba2a4922c9e84e18401f258741b4a99d8c 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -9137,7 +9137,6 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
 	char odata[256];
 	char req[256];
 	char *ncontext;
-	char *dialstatus;
 	struct iax2_dpcache *dp;
 	struct ast_app *dial;
 #if 0
@@ -9145,7 +9144,7 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
 #endif
 	if (priority == 2) {
 		/* Indicate status, can be overridden in dialplan */
-		dialstatus = pbx_builtin_getvar_helper(chan, "DIALSTATUS");
+		const char *dialstatus = pbx_builtin_getvar_helper(chan, "DIALSTATUS");
 		if (dialstatus) {
 			dial = pbx_findapp(dialstatus);
 			if (dial) 
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 4447bd7ff4201db8153e05d70c5122c6739d6006..f22616891dc9ab24a6a9a1262354bc56bc39c1d2 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -889,7 +889,7 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
 	struct mgcp_endpoint *p;
 	struct mgcp_subchannel *sub;
 	char tone[50] = "";
-	char *distinctive_ring = NULL;
+	const char *distinctive_ring = NULL;
 	struct varshead *headp;
 	struct ast_var_t *current;
 
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c93f21fa3a585971d810950d65e6496b0b76f369..7b97b522074e1bc751d9ace4361b73127ce557d8 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -462,11 +462,11 @@ struct sip_pkt;
 
 /*! \brief Parameters to the transmit_invite function */
 struct sip_invite_param {
-	char *distinctive_ring;	/*!< Distinctive ring header */
+	const char *distinctive_ring;	/*!< Distinctive ring header */
 	char *osptoken;		/*!< OSP token for this call */
 	int addsipheaders;	/*!< Add extra SIP headers */
-	char *uri_options;	/*!< URI options to add to the URI */
-	char *vxml_url;		/*!< VXML url for Cisco phones */
+	const char *uri_options;	/*!< URI options to add to the URI */
+	const char *vxml_url;		/*!< VXML url for Cisco phones */
 	char *auth;		/*!< Authentication */
 	char *authheader;	/*!< Auth header */
 	enum sip_auth_type auth_type;	/*!< Authentication type */
@@ -2478,7 +2478,7 @@ static int sip_hangup(struct ast_channel *ast)
 static int sip_answer(struct ast_channel *ast)
 {
 	int res = 0,fmt;
-	char *codec;
+	const char *codec;
 	struct sip_pvt *p = ast->tech_pvt;
 
 	ast_mutex_lock(&p->lock);
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index 8902b57ae80dc5609ad18aedc2070da7bcf87cd2..3b8b9b81b10734b641db913f293b6b25b72bd94b 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -1932,7 +1932,7 @@ static int zt_call(struct ast_channel *ast, char *rdest, int timeout)
 			break;
 		case SIG_FEATDMF_TA:
 		{
-			char *cic = NULL, *ozz = NULL;
+			const char *cic, *ozz;
 
 			/* If you have to go through a Tandem Access point you need to use this */
 			ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
diff --git a/chanvars.c b/chanvars.c
index d01c9260b0ee47ae8578da7499a1e127db54b5a3..83b611d23460c418ae0f20eb732548ac6363078c 100644
--- a/chanvars.c
+++ b/chanvars.c
@@ -59,31 +59,27 @@ void ast_var_delete(struct ast_var_t *var)
 		free(var);
 }
 
-char *ast_var_name(struct ast_var_t *var)
+const char *ast_var_name(const struct ast_var_t *var)
 {
-	char *name;
+	const char *name;
 
-	if (var == NULL)
-		return NULL;
-	if (var->name == NULL)
+	if (var == NULL || (name = var->name) == NULL)
 		return NULL;
 	/* Return the name without the initial underscores */
-	if (var->name[0] == '_') {
-		if (var->name[1] == '_')
-			name = (char*)&(var->name[2]);
-		else
-			name = (char*)&(var->name[1]);
-	} else
-		name = var->name;
+	if (name[0] == '_') {
+		name++;
+		if (name[0] == '_')
+			name++;
+	}
 	return name;
 }
 
-char *ast_var_full_name(struct ast_var_t *var)
+const char *ast_var_full_name(const struct ast_var_t *var)
 {
 	return (var ? var->name : NULL);
 }
 
-char *ast_var_value(struct ast_var_t *var)
+const char *ast_var_value(const struct ast_var_t *var)
 {
 	return (var ? var->value : NULL);
 }
diff --git a/frame.c b/frame.c
index fa5538f36dd1fcc5f2a2bb6053b024fe5c3562e0..a5a9cfdf59bd7e365818a75d397773e153aea463 100644
--- a/frame.c
+++ b/frame.c
@@ -539,7 +539,7 @@ static struct ast_codec_alias_table {
 	{"g723.1","g723"},
 };
 
-static char *ast_expand_codec_alias(char *in) {
+static const char *ast_expand_codec_alias(const char *in) {
 	int x = 0;
 
 	for (x = 0; x < sizeof(ast_codec_alias_table) / sizeof(struct ast_codec_alias_table) ; x++) {
@@ -549,7 +549,7 @@ static char *ast_expand_codec_alias(char *in) {
 	return in;
 }
 
-int ast_getformatbyname(char *name)
+int ast_getformatbyname(const char *name)
 {
 	int x = 0, all = 0, format = 0;
 
diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c
index 0f07d832776611d42221d149a02397410005dbea..bf389a61dee5c580a139303477d1f431743e26fd 100644
--- a/funcs/func_groupcount.c
+++ b/funcs/func_groupcount.c
@@ -40,7 +40,7 @@ static char *group_count_function_read(struct ast_channel *chan, char *cmd, char
 	int count;
 	char group[80] = "";
 	char category[80] = "";
-	char *grp;
+	const char *grp;
 
 	ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
 
@@ -101,7 +101,7 @@ struct ast_custom_function group_match_count_function = {
 static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
 	char varname[256];
-	char *group;
+	const char *group;
 
 	if (!ast_strlen_zero(data)) {
 		snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data);
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index 38b1fdb73ff87e6e87dd7116e2909789fe9fdf85..b40c2ce4c71113896c93045bb4b68b3ca8b1173c 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -167,16 +167,16 @@ char *ast_read_textfile(const char *file);
 #define GROUP_CATEGORY_PREFIX "GROUP"
 
 /*! Split a group string into group and category, returning a default category if none is provided. */
-int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max);
+int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max);
 
 /*! Set the group for a channel, splitting the provided data into group and category, if specified. */
-int ast_app_group_set_channel(struct ast_channel *chan, char *data);
+int ast_app_group_set_channel(struct ast_channel *chan, const char *data);
 
 /*! Get the current channel count of the specified group and category. */
-int ast_app_group_get_count(char *group, char *category);
+int ast_app_group_get_count(const char *group, const char *category);
 
 /*! Get the current channel count of all groups that match the specified pattern and category. */
-int ast_app_group_match_get_count(char *groupmatch, char *category);
+int ast_app_group_match_get_count(const char *groupmatch, const char *category);
 
 /*!
   \brief Define an application argument
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 6a4ff373f77bf5eb9babc0c6b5d18b78861cf7e3..6829f83f6a013a917590a9d82aa6492014237873 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -454,9 +454,9 @@ struct ast_bridge_config {
 	long timelimit;
 	long play_warning;
 	long warning_freq;
-	char *warning_sound;
-	char *end_sound;
-	char *start_sound;
+	const char *warning_sound;
+	const char *end_sound;
+	const char *start_sound;
 	int firstpass;
 	unsigned int flags;
 };
diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h
index d31c05e8678c95d00665462084534acd05d67bae..63de58429c66473c632049fe9236f71b129263f5 100644
--- a/include/asterisk/chanvars.h
+++ b/include/asterisk/chanvars.h
@@ -35,8 +35,8 @@ AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
 
 struct ast_var_t *ast_var_assign(const char *name, const char *value);
 void ast_var_delete(struct ast_var_t *var);
-char *ast_var_name(struct ast_var_t *var);
-char *ast_var_full_name(struct ast_var_t *var);
-char *ast_var_value(struct ast_var_t *var);
+const char *ast_var_name(const struct ast_var_t *var);
+const char *ast_var_full_name(const struct ast_var_t *var);
+const char *ast_var_value(const struct ast_var_t *var);
 
 #endif /* _ASTERISK_CHANVARS_H */
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index ccba4153998798b755baad3a748ab439fd7b0750..62c0b0dc064645c86184b8076a2b47a135191cb8 100644
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -389,7 +389,7 @@ extern char* ast_getformatname_multiple(char *buf, size_t size, int format);
  * \param name string of format
  * \return This returns the form of the format in binary on success, 0 on error.
  */
-extern int ast_getformatbyname(char *name);
+extern int ast_getformatbyname(const char *name);
 
 /*! \brief Get a name from a format 
  * Gets a name from a format
diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h
index a105461741afb37deb2906cbb206581d473352fb..9332b9e6a339c959e39664d994697029bc7fa05c 100644
--- a/include/asterisk/pbx.h
+++ b/include/asterisk/pbx.h
@@ -605,7 +605,7 @@ struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
 
 int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
-extern char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
+extern const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
 extern void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
 extern void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);
 extern void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp);
@@ -620,11 +620,11 @@ int ast_extension_patmatch(const char *pattern, const char *data);
   set to 1, sets to auto fall through.  If newval set to 0, sets to no auto
   fall through (reads extension instead).  Returns previous value. */
 extern int pbx_set_autofallthrough(int newval);
-int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
+int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
 /* I can find neither parsable nor parseable at dictionary.com, but google gives me 169000 hits for parseable and only 49,800 for parsable */
 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
 int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
-int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
+int ast_async_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
 
 struct ast_custom_function* ast_custom_function_find(char *name);
 int ast_custom_function_unregister(struct ast_custom_function *acf);
diff --git a/manager.c b/manager.c
index ea813d64ad5a7f4137bceeb289991b3f0dfe507a..32b681789948d06c45ef2f1d5efd832dfa5baf18 100644
--- a/manager.c
+++ b/manager.c
@@ -726,7 +726,7 @@ static int action_getvar(struct mansession *s, struct message *m)
         char *name = astman_get_header(m, "Channel");
         char *varname = astman_get_header(m, "Variable");
 	char *id = astman_get_header(m,"ActionID");
-	char *varval;
+	const char *varval;
 	char *varval2=NULL;
 
 	if (!strlen(varname)) {
diff --git a/pbx.c b/pbx.c
index 8ba552def96ff97506a41016f5f3243fed00c5a8..f437b27a76f0c5ac12cb9360ed262b00d039702a 100644
--- a/pbx.c
+++ b/pbx.c
@@ -1129,9 +1129,9 @@ icky:
 				ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
 #endif
 				if (strcasecmp(ast_var_name(variables),var)==0) {
-					*ret=ast_var_value(variables);
-					if (*ret) {
-						ast_copy_string(workspace, *ret, workspacelen);
+					const char *s = ast_var_value(variables);
+					if (s) {
+						ast_copy_string(workspace, s, workspacelen);
 						*ret = workspace;
 					}
 					break;
@@ -1145,9 +1145,9 @@ icky:
 				ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
 #endif
 				if (strcasecmp(ast_var_name(variables),var)==0) {
-					*ret = ast_var_value(variables);
-					if (*ret) {
-						ast_copy_string(workspace, *ret, workspacelen);
+					const char *s = ast_var_value(variables);
+					if (s) {
+						ast_copy_string(workspace, s, workspacelen);
 						*ret = workspace;
 					}
 				}
@@ -2413,7 +2413,7 @@ static int __ast_pbx_run(struct ast_channel *c)
 					ast_cdr_update(c);
 			    }
 			} else {
-				char *status;
+				const char *status;
 
 				status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
 				if (!status)
@@ -5846,7 +5846,7 @@ static int pbx_builtin_goto(struct ast_channel *chan, void *data)
 int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size) 
 {
 	struct ast_var_t *variables;
-	char *var, *val;
+	const char *var, *val;
 	int total = 0;
 
 	if (!chan)
@@ -5870,7 +5870,7 @@ int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t
 	return total;
 }
 
-char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name) 
+const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name) 
 {
 	struct ast_var_t *variables;
 	struct varshead *headp;
@@ -6383,7 +6383,7 @@ int ast_context_verify_includes(struct ast_context *con)
 }
 
 
-static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *exten, int priority, int async) 
+static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async) 
 {
 	int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
 
@@ -6400,11 +6400,11 @@ static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *e
 		return -3;
 }
 
-int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
+int ast_goto_if_exists(struct ast_channel *chan, const char* context, const char *exten, int priority) {
 	return __ast_goto_if_exists(chan, context, exten, priority, 0);
 }
 
-int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
+int ast_async_goto_if_exists(struct ast_channel *chan, const char * context, const char *exten, int priority) {
 	return __ast_goto_if_exists(chan, context, exten, priority, 1);
 }
 
diff --git a/res/res_features.c b/res/res_features.c
index 052b4830b1ec7511ed5224e7208e9fc4df8002bc..93e94caf318e12df518fc4543830d8dd525a15bf 100644
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -180,18 +180,14 @@ struct ast_bridge_thread_obj
 static void check_goto_on_transfer(struct ast_channel *chan) 
 {
 	struct ast_channel *xferchan;
-	char *goto_on_transfer;
-
-	goto_on_transfer = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
+	const char *val = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
+	char *x, *goto_on_transfer;
+	struct ast_frame *f;
 
-	if (!ast_strlen_zero(goto_on_transfer) && (xferchan = ast_channel_alloc(0))) {
-		char *x;
-		struct ast_frame *f;
-		
+	if (!ast_strlen_zero(val) && (goto_on_transfer = ast_strdupa(val)) && (xferchan = ast_channel_alloc(0))) {
 		for (x = goto_on_transfer; x && *x; x++)
 			if (*x == '^')
 				*x = '|';
-
 		strcpy(xferchan->name, chan->name);
 		/* Make formats okay */
 		xferchan->readformat = chan->readformat;
@@ -446,7 +442,7 @@ int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int
 
 static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
 {
-	char *touch_monitor = NULL, *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_format = NULL;
+	char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL;
 	int x = 0;
 	size_t len;
 	struct ast_channel *caller_chan = NULL, *callee_chan = NULL;
@@ -494,11 +490,12 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee
 	}
 
 	if (caller_chan && callee_chan) {
-		touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT");
+		const char *touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT");
+		const char *touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
+
 		if (!touch_format)
 			touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_FORMAT");
 
-		touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
 		if (!touch_monitor)
 			touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR");
 		
@@ -541,7 +538,7 @@ static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *p
 {
 	struct ast_channel *transferer;
 	struct ast_channel *transferee;
-	char *transferer_real_context;
+	const char *transferer_real_context;
 	char newext[256];
 	int res;
 
@@ -670,7 +667,7 @@ static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, st
 	struct ast_channel *newchan, *xferchan=NULL;
 	int outstate=0;
 	struct ast_bridge_config bconfig;
-	char *transferer_real_context;
+	const char *transferer_real_context;
 	char xferto[256],dialstr[265];
 	char *cid_num;
 	char *cid_name;
@@ -981,7 +978,7 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
 	struct ast_flags features;
 	int res = FEATURE_RETURN_PASSDIGITS;
 	struct ast_call_feature *feature;
-	char *dynamic_features=pbx_builtin_getvar_helper(chan,"DYNAMIC_FEATURES");
+	const char *dynamic_features=pbx_builtin_getvar_helper(chan,"DYNAMIC_FEATURES");
 
 	if (sense == FEATURE_SENSE_CHAN)
 		ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);	
@@ -1047,9 +1044,7 @@ static void set_config_flags(struct ast_channel *chan, struct ast_channel *peer,
 	}
 	
 	if (chan && peer && !(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) {
-		char *dynamic_features;
-
-		dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
+		const char *dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
 
 		if (dynamic_features) {
 			char *tmp = ast_strdupa(dynamic_features);
@@ -1261,7 +1256,6 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
 	struct ast_option_header *aoh;
 	struct timeval start = { 0 , 0 };
 	struct ast_bridge_config backup_config;
-	char *monitor_exec;
 
 	memset(&backup_config, 0, sizeof(backup_config));
 
@@ -1274,14 +1268,24 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
 		pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
 
 	if (monitor_ok) {
+		const char *monitor_exec;
+		struct ast_channel *src = NULL;
 		if (!monitor_app) { 
 			if (!(monitor_app = pbx_findapp("Monitor")))
 				monitor_ok=0;
 		}
 		if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
-			pbx_exec(chan, monitor_app, monitor_exec, 1);
+			src = chan;
 		else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
-			pbx_exec(peer, monitor_app, monitor_exec, 1);
+			src = peer;
+		if (src) {
+			char *tmp = ast_strdupa(monitor_exec);
+			if (tmp) {
+				pbx_exec(src, monitor_app, tmp, 1);
+			} else {
+				ast_log(LOG_ERROR, "Monitor failed: out of memory\n");
+			}
+		}
 	}
 	
 	set_config_flags(chan, peer, config);
diff --git a/res/res_monitor.c b/res/res_monitor.c
index 35366bdf0f48fc9b406379edd5605722832db294..d805788eb65a3fe0129a4b14540d8e359325181f 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -212,7 +212,6 @@ int ast_monitor_start(	struct ast_channel *chan, const char *format_spec,
 /* Stop monitoring a channel */
 int ast_monitor_stop(struct ast_channel *chan, int need_lock)
 {
-	char *execute, *execute_args;
 	int delfiles = 0;
 
 	if (need_lock) {
@@ -261,6 +260,7 @@ int ast_monitor_stop(struct ast_channel *chan, int need_lock)
 			char *name = chan->monitor->filename_base;
 			int directory = strchr(name, '/') ? 1 : 0;
 			char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
+			const char *execute, *execute_args;
 
 			/* Set the execute application */
 			execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");