Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


app_db.c
Go to the documentation of this file.
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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 381364 $")
38 
39 #include "asterisk/file.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/astdb.h"
44 #include "asterisk/lock.h"
45 
46 /*** DOCUMENTATION
47  <application name="DBdel" language="en_US">
48  <synopsis>
49  Delete a key from the asterisk database.
50  </synopsis>
51  <syntax argsep="/">
52  <parameter name="family" required="true" />
53  <parameter name="key" required="true" />
54  </syntax>
55  <description>
56  <para>This application will delete a <replaceable>key</replaceable> from the Asterisk
57  database.</para>
58  <note><para>This application has been DEPRECATED in favor of the DB_DELETE function.</para></note>
59  </description>
60  <see-also>
61  <ref type="function">DB_DELETE</ref>
62  <ref type="application">DBdeltree</ref>
63  <ref type="function">DB</ref>
64  </see-also>
65  </application>
66  <application name="DBdeltree" language="en_US">
67  <synopsis>
68  Delete a family or keytree from the asterisk database.
69  </synopsis>
70  <syntax argsep="/">
71  <parameter name="family" required="true" />
72  <parameter name="keytree" />
73  </syntax>
74  <description>
75  <para>This application will delete a <replaceable>family</replaceable> or <replaceable>keytree</replaceable>
76  from the Asterisk database.</para>
77  </description>
78  <see-also>
79  <ref type="function">DB_DELETE</ref>
80  <ref type="application">DBdel</ref>
81  <ref type="function">DB</ref>
82  </see-also>
83  </application>
84  ***/
85 
86 static const char d_app[] = "DBdel";
87 static const char dt_app[] = "DBdeltree";
88 
89 static int deltree_exec(struct ast_channel *chan, const char *data)
90 {
91  char *argv, *family, *keytree;
92 
93  argv = ast_strdupa(data);
94 
95  if (strchr(argv, '/')) {
96  family = strsep(&argv, "/");
97  keytree = strsep(&argv, "\0");
98  if (!family || !keytree) {
99  ast_debug(1, "Ignoring; Syntax error in argument\n");
100  return 0;
101  }
102  if (ast_strlen_zero(keytree))
103  keytree = 0;
104  } else {
105  family = argv;
106  keytree = 0;
107  }
108 
109  if (keytree) {
110  ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
111  } else {
112  ast_verb(3, "DBdeltree: family=%s\n", family);
113  }
114 
115  if (ast_db_deltree(family, keytree) < 0) {
116  ast_verb(3, "DBdeltree: Error deleting key from database.\n");
117  }
118 
119  return 0;
120 }
121 
122 static int del_exec(struct ast_channel *chan, const char *data)
123 {
124  char *argv, *family, *key;
125  static int deprecation_warning = 0;
126 
127  if (!deprecation_warning) {
128  deprecation_warning = 1;
129  ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
130  }
131 
132  argv = ast_strdupa(data);
133 
134  if (strchr(argv, '/')) {
135  family = strsep(&argv, "/");
136  key = strsep(&argv, "\0");
137  if (!family || !key) {
138  ast_debug(1, "Ignoring; Syntax error in argument\n");
139  return 0;
140  }
141  ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
142  if (ast_db_del(family, key))
143  ast_verb(3, "DBdel: Error deleting key from database.\n");
144  } else {
145  ast_debug(1, "Ignoring, no parameters\n");
146  }
147 
148  return 0;
149 }
150 
151 static int unload_module(void)
152 {
153  int retval;
154 
155  retval = ast_unregister_application(dt_app);
156  retval |= ast_unregister_application(d_app);
157 
158  return retval;
159 }
160 
161 static int load_module(void)
162 {
163  int retval;
164 
165  retval = ast_register_application_xml(d_app, del_exec);
166  retval |= ast_register_application_xml(dt_app, deltree_exec);
167 
168  return retval;
169 }
170 
171 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
char * strsep(char **str, const char *delims)
static int load_module(void)
Definition: app_db.c:161
#define LOG_WARNING
Definition: logger.h:144
static int unload_module(void)
Definition: app_db.c:151
static const char dt_app[]
Definition: app_db.c:87
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
#define ast_verb(level,...)
Definition: logger.h:243
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static const char d_app[]
Definition: app_db.c:86
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: db.c:365
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
static int deltree_exec(struct ast_channel *chan, const char *data)
Definition: app_db.c:89
Persistant data storage (akin to *doze registry)
static int del_exec(struct ast_channel *chan, const char *data)
Definition: app_db.c:122
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged...
Definition: db.c:241
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180