mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	Replace direct access to channel name with accessor functions
There are many benefits to making the ast_channel an opaque handle, from
increasing maintainability to presenting ways to kill masquerades. This patch
kicks things off by taking things a field at a time, renaming the field to
'__do_not_use_${fieldname}' and then writing setters/getters and converting the
existing code to using them. When all fields are done, we can move ast_channel
to a C file from channel.h and lop off the '__do_not_use_'.
This patch sets up main/channel_interal_api.c to be the only file that actually
accesses the ast_channel's fields directly. The intent would be for any API
functions in channel.c to use the accessor functions. No more monkeying around
with channel internals. We should use our own APIs.
The interesting changes in this patch are the addition of
channel_internal_api.c, the moving of the AST_DATA stuff from channel.c to
channel_internal_api.c (note: the AST_DATA stuff will have to be reworked to
use accessor functions when ast_channel is really opaque), and some re-working
of the way channel iterators/callbacks are handled so as to avoid creating fake
ast_channels on the stack to pass in matching data by directly accessing fields
(since "name" is a stringfield and the fake channel doesn't init the
stringfields, you can't use the ast_channel_name_set() function). I went with
ast_channel_name(chan) for a getter, and ast_channel_name_set(chan, name) for a
setter.
The majority of the grunt-work for this change was done by writing a semantic
patch using Coccinelle ( http://coccinelle.lip6.fr/ ).
Review: https://reviewboard.asterisk.org/r/1655/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350223 65c4cc65-6c06-0410-ace0-fbb531ad65f3
			
			
This commit is contained in:
		| @@ -123,12 +123,12 @@ static void audiohook_inheritance_fixup(void *data, struct ast_channel *old_chan | ||||
| 	struct inheritable_audiohook *audiohook = NULL; | ||||
| 	struct audiohook_inheritance_datastore *datastore = data; | ||||
|  | ||||
| 	ast_debug(2, "inheritance fixup occurring for channels %s(%p) and %s(%p)", old_chan->name, old_chan, new_chan->name, new_chan); | ||||
| 	ast_debug(2, "inheritance fixup occurring for channels %s(%p) and %s(%p)", ast_channel_name(old_chan), old_chan, ast_channel_name(new_chan), new_chan); | ||||
|  | ||||
| 	AST_LIST_TRAVERSE(&datastore->allowed_list, audiohook, list) { | ||||
| 		ast_audiohook_move_by_source(old_chan, new_chan, audiohook->source); | ||||
| 		ast_debug(3, "Moved audiohook %s from %s(%p) to %s(%p)\n", | ||||
| 			audiohook->source, old_chan->name, old_chan, new_chan->name, new_chan); | ||||
| 			audiohook->source, ast_channel_name(old_chan), old_chan, ast_channel_name(new_chan), new_chan); | ||||
| 	} | ||||
| 	return; | ||||
| } | ||||
| @@ -234,10 +234,10 @@ static int func_inheritance_write(struct ast_channel *chan, const char *function | ||||
| 		ast_channel_unlock(chan); | ||||
| 		/* In the case where we cannot find the datastore, we can take a few shortcuts */ | ||||
| 		if (!allow) { | ||||
| 			ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name); | ||||
| 			ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, ast_channel_name(chan)); | ||||
| 			return 0; | ||||
| 		} else if (!(inheritance_datastore = setup_inheritance_datastore(chan))) { | ||||
| 			ast_log(LOG_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", chan->name); | ||||
| 			ast_log(LOG_WARNING, "Unable to set up audiohook inheritance datastore on channel %s\n", ast_channel_name(chan)); | ||||
| 			return -1; | ||||
| 		} else { | ||||
| 			return setup_inheritable_audiohook(inheritance_datastore, data); | ||||
| @@ -252,10 +252,10 @@ static int func_inheritance_write(struct ast_channel *chan, const char *function | ||||
| 	AST_LIST_TRAVERSE_SAFE_BEGIN(&inheritance_datastore->allowed_list, inheritable_audiohook, list) { | ||||
| 		if (!strcasecmp(inheritable_audiohook->source, data)) { | ||||
| 			if (allow) { | ||||
| 				ast_debug(2, "Audiohook source %s is already set up to be inherited from channel %s\n", data, chan->name); | ||||
| 				ast_debug(2, "Audiohook source %s is already set up to be inherited from channel %s\n", data, ast_channel_name(chan)); | ||||
| 				return 0; | ||||
| 			} else { | ||||
| 				ast_debug(2, "Removing inheritability of audiohook %s from channel %s\n", data, chan->name); | ||||
| 				ast_debug(2, "Removing inheritability of audiohook %s from channel %s\n", data, ast_channel_name(chan)); | ||||
| 				AST_LIST_REMOVE_CURRENT(list); | ||||
| 				ast_free(inheritable_audiohook); | ||||
| 				return 0; | ||||
| @@ -273,7 +273,7 @@ static int func_inheritance_write(struct ast_channel *chan, const char *function | ||||
| 	if (allow) { | ||||
| 		return setup_inheritable_audiohook(inheritance_datastore, data); | ||||
| 	} else { | ||||
| 		ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, chan->name); | ||||
| 		ast_debug(1, "Audiohook %s is already set to not be inheritable on channel %s\n", data, ast_channel_name(chan)); | ||||
| 		return 0; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -333,7 +333,7 @@ static int func_channel_read(struct ast_channel *chan, const char *function, | ||||
| 	else if (!strcasecmp(data, "musicclass")) | ||||
| 		locked_copy_string(chan, buf, chan->musicclass, len); | ||||
| 	else if (!strcasecmp(data, "name")) { | ||||
| 		locked_copy_string(chan, buf, chan->name, len); | ||||
| 		locked_copy_string(chan, buf, ast_channel_name(chan), len); | ||||
| 	} else if (!strcasecmp(data, "parkinglot")) | ||||
| 		locked_copy_string(chan, buf, chan->parkinglot, len); | ||||
| 	else if (!strcasecmp(data, "state")) | ||||
| @@ -361,7 +361,7 @@ static int func_channel_read(struct ast_channel *chan, const char *function, | ||||
| 	else if (!strcasecmp(data, "userfield") && chan->data) | ||||
| 		locked_copy_string(chan, buf, chan->userfield, len); | ||||
| 	else if (!strcasecmp(data, "channame") && chan->data) | ||||
| 		locked_copy_string(chan, buf, chan->name, len); | ||||
| 		locked_copy_string(chan, buf, ast_channel_name(chan), len); | ||||
| 	else if (!strcasecmp(data, "linkedid")) { | ||||
| 		ast_channel_lock(chan); | ||||
| 		if (ast_strlen_zero(chan->linkedid)) { | ||||
| @@ -377,7 +377,7 @@ static int func_channel_read(struct ast_channel *chan, const char *function, | ||||
| 		ast_channel_lock(chan); | ||||
| 		p = ast_bridged_channel(chan); | ||||
| 		if (p || chan->tech || chan->cdr) /* dummy channel? if so, we hid the peer name in the language */ | ||||
| 			ast_copy_string(buf, (p ? p->name : ""), len); | ||||
| 			ast_copy_string(buf, (p ? ast_channel_name(p) : ""), len); | ||||
| 		else { | ||||
| 			/* a dummy channel can still pass along bridged peer info via | ||||
|                            the BRIDGEPEER variable */ | ||||
| @@ -593,14 +593,14 @@ static int func_channels_read(struct ast_channel *chan, const char *function, ch | ||||
|  | ||||
| 	while ((c = ast_channel_iterator_next(iter))) { | ||||
| 		ast_channel_lock(c); | ||||
| 		if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) { | ||||
| 			size_t namelen = strlen(c->name); | ||||
| 		if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) { | ||||
| 			size_t namelen = strlen(ast_channel_name(c)); | ||||
| 			if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) { | ||||
| 				if (!ast_strlen_zero(buf)) { | ||||
| 					strcat(buf, " "); | ||||
| 					buflen++; | ||||
| 				} | ||||
| 				strcat(buf, c->name); | ||||
| 				strcat(buf, ast_channel_name(c)); | ||||
| 				buflen += namelen; | ||||
| 			} else { | ||||
| 				ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space.  Output will be truncated!\n"); | ||||
|   | ||||
| @@ -140,7 +140,7 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram | ||||
| 	} | ||||
|  | ||||
| 	if (show_frame) { | ||||
| 		ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name); | ||||
| 		ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", ast_channel_name(chan)); | ||||
| 		print_frame(frame); | ||||
| 	} | ||||
| 	return frame; | ||||
|   | ||||
| @@ -259,7 +259,7 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c | ||||
| 		"Variable: SHARED(%s)\r\n" | ||||
| 		"Value: %s\r\n" | ||||
| 		"Uniqueid: %s\r\n",  | ||||
| 		chan ? chan->name : "none", args.var, value,  | ||||
| 		chan ? ast_channel_name(chan) : "none", args.var, value,  | ||||
| 		chan ? chan->uniqueid : "none"); | ||||
|  | ||||
| 	ast_channel_unlock(chan); | ||||
|   | ||||
| @@ -127,7 +127,7 @@ static int group_count_function_read(struct ast_channel *chan, const char *cmd, | ||||
| 	} | ||||
|  | ||||
| 	if ((count = ast_app_group_get_count(group, category)) == -1) { | ||||
| 		ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name); | ||||
| 		ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan)); | ||||
| 	} else { | ||||
| 		snprintf(buf, len, "%d", count); | ||||
| 		ret = 0; | ||||
|   | ||||
| @@ -205,13 +205,13 @@ static void *lock_broker(void *unused) | ||||
| static int ast_channel_hash_cb(const void *obj, const int flags) | ||||
| { | ||||
| 	const struct ast_channel *chan = obj; | ||||
| 	return ast_str_case_hash(chan->name); | ||||
| 	return ast_str_case_hash(ast_channel_name(chan)); | ||||
| } | ||||
|  | ||||
| static int ast_channel_cmp_cb(void *obj, void *arg, int flags) | ||||
| { | ||||
| 	struct ast_channel *chan = obj, *cmp_args = arg; | ||||
| 	return strcasecmp(chan->name, cmp_args->name) ? 0 : CMP_MATCH; | ||||
| 	return strcasecmp(ast_channel_name(chan), ast_channel_name(cmp_args)) ? 0 : CMP_MATCH; | ||||
| } | ||||
|  | ||||
| static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
| @@ -224,7 +224,7 @@ static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
| 	struct timespec three_seconds = { .tv_sec = 3 }; | ||||
|  | ||||
| 	if (!lock_store) { | ||||
| 		ast_debug(1, "Channel %s has no lock datastore, so we're allocating one.\n", chan->name); | ||||
| 		ast_debug(1, "Channel %s has no lock datastore, so we're allocating one.\n", ast_channel_name(chan)); | ||||
| 		lock_store = ast_datastore_alloc(&lock_info, NULL); | ||||
| 		if (!lock_store) { | ||||
| 			ast_log(LOG_ERROR, "Unable to allocate new datastore.  No locks will be obtained.\n"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user