Merge "res_musiconhold: Start playlist after initial announcement"
[asterisk/asterisk.git] / apps / app_db.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  * Copyright (C) 2003, Jefferson Noxon
6  *
7  * Mark Spencer <markster@digium.com>
8  * Jefferson Noxon <jeff@debian.org>
9  *
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.
15  *
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.
19  */
20
21 /*! \file
22  *
23  * \brief Database access functions
24  *
25  * \author Mark Spencer <markster@digium.com>
26  * \author Jefferson Noxon <jeff@debian.org>
27  *
28  * \ingroup applications
29  */
30
31 /*** MODULEINFO
32         <support_level>core</support_level>
33  ***/
34
35 #include "asterisk.h"
36
37 #include "asterisk/file.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/astdb.h"
42 #include "asterisk/lock.h"
43
44 /*** DOCUMENTATION
45         <application name="DBdel" language="en_US">
46                 <synopsis>
47                         Delete a key from the asterisk database.
48                 </synopsis>
49                 <syntax argsep="/">
50                         <parameter name="family" required="true" />
51                         <parameter name="key" required="true" />
52                 </syntax>
53                 <description>
54                         <para>This application will delete a <replaceable>key</replaceable> from the Asterisk
55                         database.</para>
56                         <note><para>This application has been DEPRECATED in favor of the DB_DELETE function.</para></note>
57                 </description>
58                 <see-also>
59                         <ref type="function">DB_DELETE</ref>
60                         <ref type="application">DBdeltree</ref>
61                         <ref type="function">DB</ref>
62                 </see-also>
63         </application>
64         <application name="DBdeltree" language="en_US">
65                 <synopsis>
66                         Delete a family or keytree from the asterisk database.
67                 </synopsis>
68                 <syntax argsep="/">
69                         <parameter name="family" required="true" />
70                         <parameter name="keytree" />
71                 </syntax>
72                 <description>
73                         <para>This application will delete a <replaceable>family</replaceable> or <replaceable>keytree</replaceable>
74                         from the Asterisk database.</para>
75                 </description>
76                 <see-also>
77                         <ref type="function">DB_DELETE</ref>
78                         <ref type="application">DBdel</ref>
79                         <ref type="function">DB</ref>
80                 </see-also>
81         </application>
82  ***/
83
84 static const char d_app[] = "DBdel";
85 static const char dt_app[] = "DBdeltree";
86
87 static int deltree_exec(struct ast_channel *chan, const char *data)
88 {
89         char *argv, *family, *keytree;
90
91         argv = ast_strdupa(data);
92
93         if (strchr(argv, '/')) {
94                 family = strsep(&argv, "/");
95                 keytree = strsep(&argv, "\0");
96                 if (!family || !keytree) {
97                         ast_debug(1, "Ignoring; Syntax error in argument\n");
98                         return 0;
99                 }
100                 if (ast_strlen_zero(keytree))
101                         keytree = 0;
102         } else {
103                 family = argv;
104                 keytree = 0;
105         }
106
107         if (keytree) {
108                 ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
109         } else {
110                 ast_verb(3, "DBdeltree: family=%s\n", family);
111         }
112
113         if (ast_db_deltree(family, keytree) < 0) {
114                 ast_verb(3, "DBdeltree: Error deleting key from database.\n");
115         }
116
117         return 0;
118 }
119
120 static int del_exec(struct ast_channel *chan, const char *data)
121 {
122         char *argv, *family, *key;
123         static int deprecation_warning = 0;
124
125         if (!deprecation_warning) {
126                 deprecation_warning = 1;
127                 ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
128         }
129
130         argv = ast_strdupa(data);
131
132         if (strchr(argv, '/')) {
133                 family = strsep(&argv, "/");
134                 key = strsep(&argv, "\0");
135                 if (!family || !key) {
136                         ast_debug(1, "Ignoring; Syntax error in argument\n");
137                         return 0;
138                 }
139                 ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
140                 if (ast_db_del(family, key))
141                         ast_verb(3, "DBdel: Error deleting key from database.\n");
142         } else {
143                 ast_debug(1, "Ignoring, no parameters\n");
144         }
145
146         return 0;
147 }
148
149 static int unload_module(void)
150 {
151         int retval;
152
153         retval = ast_unregister_application(dt_app);
154         retval |= ast_unregister_application(d_app);
155
156         return retval;
157 }
158
159 static int load_module(void)
160 {
161         int retval;
162
163         retval = ast_register_application_xml(d_app, del_exec);
164         retval |= ast_register_application_xml(dt_app, deltree_exec);
165
166         return retval;
167 }
168
169 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");