| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-21 07:06:25 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  |  * Copyright (C) 2003, Jefferson Noxon | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  |  * Jefferson Noxon <jeff@debian.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +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 Database access functions | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							|  |  |  |  * \author Jefferson Noxon <jeff@debian.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/astdb.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-25 15:40:38 +00:00
										 |  |  | /*! \todo XXX Remove this application after 1.4 is relased */ | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | static char *d_descrip = | 
					
						
							| 
									
										
										
										
											2006-11-16 23:20:52 +00:00
										 |  |  | "  DBdel(family/key): This application will delete a key from the Asterisk\n" | 
					
						
							| 
									
										
										
										
											2006-05-25 15:40:38 +00:00
										 |  |  | "database.\n" | 
					
						
							|  |  |  | "  This application has been DEPRECATED in favor of the DB_DELETE function.\n"; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *dt_descrip = | 
					
						
							| 
									
										
										
										
											2005-11-11 13:34:38 +00:00
										 |  |  | "  DBdeltree(family[/keytree]): This application will delete a family or keytree\n" | 
					
						
							|  |  |  | "from the Asterisk database\n"; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *d_app = "DBdel"; | 
					
						
							|  |  |  | static char *dt_app = "DBdeltree"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *d_synopsis = "Delete a key from the database"; | 
					
						
							|  |  |  | static char *dt_synopsis = "Delete a family or keytree from the database"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-05 03:16:07 +00:00
										 |  |  | static int deltree_exec(struct ast_channel *chan, void *data) | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	char *argv, *family, *keytree; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	argv = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-05-05 03:16:07 +00:00
										 |  |  | 	if (strchr(argv, '/')) { | 
					
						
							|  |  |  | 		family = strsep(&argv, "/"); | 
					
						
							|  |  |  | 		keytree = strsep(&argv, "\0"); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 		if (!family || !keytree) { | 
					
						
							|  |  |  | 			ast_debug(1, "Ignoring; Syntax error in argument\n"); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-26 19:48:14 +00:00
										 |  |  | 		if (ast_strlen_zero(keytree)) | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 			keytree = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		family = argv; | 
					
						
							|  |  |  | 		keytree = 0; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (keytree) | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "DBdeltree: family=%s\n", family); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 	if (ast_db_deltree(family, keytree)) | 
					
						
							|  |  |  | 		ast_verb(3, "DBdeltree: Error deleting key from database.\n"); | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-05 03:16:07 +00:00
										 |  |  | static int del_exec(struct ast_channel *chan, void *data) | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	char *argv, *family, *key; | 
					
						
							| 
									
										
										
										
											2006-05-25 15:40:38 +00:00
										 |  |  | 	static int deprecation_warning = 0; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-05-25 15:40:38 +00:00
										 |  |  | 	if (!deprecation_warning) { | 
					
						
							|  |  |  | 		deprecation_warning = 1; | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	argv = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:22:42 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-05-05 03:16:07 +00:00
										 |  |  | 	if (strchr(argv, '/')) { | 
					
						
							|  |  |  | 		family = strsep(&argv, "/"); | 
					
						
							|  |  |  | 		key = strsep(&argv, "\0"); | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 		if (!family || !key) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 			ast_debug(1, "Ignoring; Syntax error in argument\n"); | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "DBdel: family=%s, key=%s\n", family, key); | 
					
						
							|  |  |  | 		if (ast_db_del(family, key)) | 
					
						
							|  |  |  | 			ast_verb(3, "DBdel: Error deleting key from database.\n"); | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "Ignoring, no parameters\n"); | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	int retval; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-05 03:16:07 +00:00
										 |  |  | 	retval = ast_unregister_application(dt_app); | 
					
						
							|  |  |  | 	retval |= ast_unregister_application(d_app); | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	return retval; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	int retval; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-08 17:52:43 +00:00
										 |  |  | 	retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip); | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-07-09 16:19:00 +00:00
										 |  |  | 	return retval; | 
					
						
							| 
									
										
										
										
											2003-03-07 06:00:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions"); |