| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Channel Variables | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com>  | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 20:27:51 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:12:19 +00:00
										 |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							| 
									
										
										
										
											2005-06-06 20:27:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/chanvars.h"
 | 
					
						
							| 
									
										
										
										
											2005-10-05 21:11:17 +00:00
										 |  |  | #include "asterisk/strings.h"
 | 
					
						
							| 
									
										
										
										
											2006-02-15 01:48:54 +00:00
										 |  |  | #include "asterisk/utils.h"
 | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-14 22:42:17 +00:00
										 |  |  | #ifdef MALLOC_DEBUG
 | 
					
						
							|  |  |  | struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function) | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2004-10-24 02:53:24 +00:00
										 |  |  | struct ast_var_t *ast_var_assign(const char *name, const char *value) | 
					
						
							| 
									
										
										
										
											2008-10-14 22:42:17 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-02-15 01:48:54 +00:00
										 |  |  | {	 | 
					
						
							| 
									
										
										
										
											2002-07-26 15:44:05 +00:00
										 |  |  | 	struct ast_var_t *var; | 
					
						
							| 
									
										
										
										
											2006-02-15 01:48:54 +00:00
										 |  |  | 	int name_len = strlen(name) + 1; | 
					
						
							|  |  |  | 	int value_len = strlen(value) + 1; | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-14 22:42:17 +00:00
										 |  |  | #ifdef MALLOC_DEBUG
 | 
					
						
							|  |  |  | 	if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) { | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-02-15 01:48:54 +00:00
										 |  |  | 	if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) { | 
					
						
							| 
									
										
										
										
											2008-10-14 22:42:17 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 01:48:54 +00:00
										 |  |  | 	ast_copy_string(var->name, name, name_len); | 
					
						
							|  |  |  | 	var->value = var->name + name_len; | 
					
						
							|  |  |  | 	ast_copy_string(var->value, value, value_len); | 
					
						
							| 
									
										
										
										
											2004-11-01 15:48:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | 	return var; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | void ast_var_delete(struct ast_var_t *var) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-05 21:11:17 +00:00
										 |  |  | 	if (var) | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(var); | 
					
						
							| 
									
										
										
										
											2002-07-26 15:44:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | const char *ast_var_name(const struct ast_var_t *var) | 
					
						
							| 
									
										
										
										
											2004-11-01 02:23:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | 	const char *name; | 
					
						
							| 
									
										
										
										
											2004-11-01 02:23:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | 	if (var == NULL || (name = var->name) == NULL) | 
					
						
							| 
									
										
										
										
											2004-11-01 02:23:28 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	/* Return the name without the initial underscores */ | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | 	if (name[0] == '_') { | 
					
						
							|  |  |  | 		name++; | 
					
						
							|  |  |  | 		if (name[0] == '_') | 
					
						
							|  |  |  | 			name++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-11-01 02:23:28 +00:00
										 |  |  | 	return name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | const char *ast_var_full_name(const struct ast_var_t *var) | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-05 21:11:17 +00:00
										 |  |  | 	return (var ? var->name : NULL); | 
					
						
							| 
									
										
										
										
											2002-07-26 15:44:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-03 19:25:33 +00:00
										 |  |  | const char *ast_var_value(const struct ast_var_t *var) | 
					
						
							| 
									
										
										
										
											2002-10-22 15:31:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-05 21:11:17 +00:00
										 |  |  | 	return (var ? var->value : NULL); | 
					
						
							| 
									
										
										
										
											2002-07-26 15:44:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-05 21:11:17 +00:00
										 |  |  | 
 |