Creating tag for the release of asterisk-1.6.1-beta1
[asterisk-bristuff.git] / apps / app_db.c
blobf141209e9c2db2ec4c96bb3d192dd3e84e86c8c9
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 * Copyright (C) 2003, Jefferson Noxon
7 * Mark Spencer <markster@digium.com>
8 * Jefferson Noxon <jeff@debian.org>
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
16 * This program is free software, distributed under the terms of
17 * the GNU General Public License Version 2. See the LICENSE file
18 * at the top of the source tree.
21 /*! \file
23 * \brief Database access functions
25 * \author Mark Spencer <markster@digium.com>
26 * \author Jefferson Noxon <jeff@debian.org>
28 * \ingroup applications
31 #include "asterisk.h"
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35 #include "asterisk/file.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/astdb.h"
40 #include "asterisk/lock.h"
42 /*! \todo XXX Remove this application after 1.4 is relased */
43 static char *d_descrip =
44 " DBdel(family/key): This application will delete a key from the Asterisk\n"
45 "database.\n"
46 " This application has been DEPRECATED in favor of the DB_DELETE function.\n";
48 static char *dt_descrip =
49 " DBdeltree(family[/keytree]): This application will delete a family or keytree\n"
50 "from the Asterisk database\n";
52 static char *d_app = "DBdel";
53 static char *dt_app = "DBdeltree";
55 static char *d_synopsis = "Delete a key from the database";
56 static char *dt_synopsis = "Delete a family or keytree from the database";
59 static int deltree_exec(struct ast_channel *chan, void *data)
61 char *argv, *family, *keytree;
63 argv = ast_strdupa(data);
65 if (strchr(argv, '/')) {
66 family = strsep(&argv, "/");
67 keytree = strsep(&argv, "\0");
68 if (!family || !keytree) {
69 ast_debug(1, "Ignoring; Syntax error in argument\n");
70 return 0;
72 if (ast_strlen_zero(keytree))
73 keytree = 0;
74 } else {
75 family = argv;
76 keytree = 0;
79 if (keytree)
80 ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
81 else
82 ast_verb(3, "DBdeltree: family=%s\n", family);
84 if (ast_db_deltree(family, keytree))
85 ast_verb(3, "DBdeltree: Error deleting key from database.\n");
87 return 0;
90 static int del_exec(struct ast_channel *chan, void *data)
92 char *argv, *family, *key;
93 static int deprecation_warning = 0;
95 if (!deprecation_warning) {
96 deprecation_warning = 1;
97 ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
100 argv = ast_strdupa(data);
102 if (strchr(argv, '/')) {
103 family = strsep(&argv, "/");
104 key = strsep(&argv, "\0");
105 if (!family || !key) {
106 ast_debug(1, "Ignoring; Syntax error in argument\n");
107 return 0;
109 ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
110 if (ast_db_del(family, key))
111 ast_verb(3, "DBdel: Error deleting key from database.\n");
112 } else {
113 ast_debug(1, "Ignoring, no parameters\n");
116 return 0;
119 static int unload_module(void)
121 int retval;
123 retval = ast_unregister_application(dt_app);
124 retval |= ast_unregister_application(d_app);
126 return retval;
129 static int load_module(void)
131 int retval;
133 retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
134 retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
136 return retval;
139 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");