Sat Mar 10 01:53:56 2012

Asterisk developer's documentation


app_db.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  * Copyright (C) 2003, Jefferson Noxon
00006  *
00007  * Mark Spencer <markster@digium.com>
00008  * Jefferson Noxon <jeff@debian.org>
00009  *
00010  * See http://www.asterisk.org for more information about
00011  * the Asterisk project. Please do not directly contact
00012  * any of the maintainers of this project for assistance;
00013  * the project provides a web site, mailing lists and IRC
00014  * channels for your use.
00015  *
00016  * This program is free software, distributed under the terms of
00017  * the GNU General Public License Version 2. See the LICENSE file
00018  * at the top of the source tree.
00019  */
00020 
00021 /*! \file
00022  *
00023  * \brief Database access functions
00024  *
00025  * \author Mark Spencer <markster@digium.com>
00026  * \author Jefferson Noxon <jeff@debian.org>
00027  *
00028  * \ingroup applications
00029  */
00030 
00031 /*** MODULEINFO
00032    <support_level>core</support_level>
00033  ***/
00034 
00035 #include "asterisk.h"
00036 
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00038 
00039 #include "asterisk/file.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/astdb.h"
00044 #include "asterisk/lock.h"
00045 
00046 /*** DOCUMENTATION
00047    <application name="DBdel" language="en_US">
00048       <synopsis>
00049          Delete a key from the asterisk database.
00050       </synopsis>
00051       <syntax argsep="/">
00052          <parameter name="family" required="true" />
00053          <parameter name="key" required="true" />
00054       </syntax>
00055       <description>
00056          <para>This application will delete a <replaceable>key</replaceable> from the Asterisk
00057          database.</para>
00058          <note><para>This application has been DEPRECATED in favor of the DB_DELETE function.</para></note>
00059       </description>
00060       <see-also>
00061          <ref type="function">DB_DELETE</ref>
00062          <ref type="application">DBdeltree</ref>
00063          <ref type="function">DB</ref>
00064       </see-also>
00065    </application>
00066    <application name="DBdeltree" language="en_US">
00067       <synopsis>
00068          Delete a family or keytree from the asterisk database.
00069       </synopsis>
00070       <syntax argsep="/">
00071          <parameter name="family" required="true" />
00072          <parameter name="keytree" />
00073       </syntax>
00074       <description>
00075          <para>This application will delete a <replaceable>family</replaceable> or <replaceable>keytree</replaceable>
00076          from the Asterisk database.</para>
00077       </description>
00078       <see-also>
00079          <ref type="function">DB_DELETE</ref>
00080          <ref type="application">DBdel</ref>
00081          <ref type="function">DB</ref>
00082       </see-also>
00083    </application>
00084  ***/
00085 
00086 static const char d_app[] = "DBdel";
00087 static const char dt_app[] = "DBdeltree";
00088 
00089 static int deltree_exec(struct ast_channel *chan, const char *data)
00090 {
00091    char *argv, *family, *keytree;
00092 
00093    argv = ast_strdupa(data);
00094 
00095    if (strchr(argv, '/')) {
00096       family = strsep(&argv, "/");
00097       keytree = strsep(&argv, "\0");
00098       if (!family || !keytree) {
00099          ast_debug(1, "Ignoring; Syntax error in argument\n");
00100          return 0;
00101       }
00102       if (ast_strlen_zero(keytree))
00103          keytree = 0;
00104    } else {
00105       family = argv;
00106       keytree = 0;
00107    }
00108 
00109    if (keytree)
00110       ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
00111    else
00112       ast_verb(3, "DBdeltree: family=%s\n", family);
00113 
00114    if (ast_db_deltree(family, keytree))
00115       ast_verb(3, "DBdeltree: Error deleting key from database.\n");
00116 
00117    return 0;
00118 }
00119 
00120 static int del_exec(struct ast_channel *chan, const char *data)
00121 {
00122    char *argv, *family, *key;
00123    static int deprecation_warning = 0;
00124 
00125    if (!deprecation_warning) {
00126       deprecation_warning = 1;
00127       ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
00128    }
00129 
00130    argv = ast_strdupa(data);
00131 
00132    if (strchr(argv, '/')) {
00133       family = strsep(&argv, "/");
00134       key = strsep(&argv, "\0");
00135       if (!family || !key) {
00136          ast_debug(1, "Ignoring; Syntax error in argument\n");
00137          return 0;
00138       }
00139       ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
00140       if (ast_db_del(family, key))
00141          ast_verb(3, "DBdel: Error deleting key from database.\n");
00142    } else {
00143       ast_debug(1, "Ignoring, no parameters\n");
00144    }
00145 
00146    return 0;
00147 }
00148 
00149 static int unload_module(void)
00150 {
00151    int retval;
00152 
00153    retval = ast_unregister_application(dt_app);
00154    retval |= ast_unregister_application(d_app);
00155 
00156    return retval;
00157 }
00158 
00159 static int load_module(void)
00160 {
00161    int retval;
00162 
00163    retval = ast_register_application_xml(d_app, del_exec);
00164    retval |= ast_register_application_xml(dt_app, deltree_exec);
00165 
00166    return retval;
00167 }
00168 
00169 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");

Generated on Sat Mar 10 01:53:56 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7