Mon Jun 27 16:50:46 2011

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 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 199479 $")
00034 
00035 #include "asterisk/file.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/astdb.h"
00040 #include "asterisk/lock.h"
00041 
00042 /*** DOCUMENTATION
00043    <application name="DBdel" language="en_US">
00044       <synopsis>
00045          Delete a key from the asterisk database.
00046       </synopsis>
00047       <syntax argsep="/">
00048          <parameter name="family" required="true" />
00049          <parameter name="key" required="true" />
00050       </syntax>
00051       <description>
00052          <para>This application will delete a <replaceable>key</replaceable> from the Asterisk
00053          database.</para>
00054          <note><para>This application has been DEPRECATED in favor of the DB_DELETE function.</para></note>
00055       </description>
00056       <see-also>
00057          <ref type="function">DB_DELETE</ref>
00058          <ref type="application">DBdeltree</ref>
00059          <ref type="function">DB</ref>
00060       </see-also>
00061    </application>
00062    <application name="DBdeltree" language="en_US">
00063       <synopsis>
00064          Delete a family or keytree from the asterisk database.
00065       </synopsis>
00066       <syntax argsep="/">
00067          <parameter name="family" required="true" />
00068          <parameter name="keytree" />
00069       </syntax>
00070       <description>
00071          <para>This application will delete a <replaceable>family</replaceable> or <replaceable>keytree</replaceable>
00072          from the Asterisk database.</para>
00073       </description>
00074       <see-also>
00075          <ref type="function">DB_DELETE</ref>
00076          <ref type="application">DBdel</ref>
00077          <ref type="function">DB</ref>
00078       </see-also>
00079    </application>
00080  ***/
00081 
00082 static const char d_app[] = "DBdel";
00083 static const char dt_app[] = "DBdeltree";
00084 
00085 static int deltree_exec(struct ast_channel *chan, const char *data)
00086 {
00087    char *argv, *family, *keytree;
00088 
00089    argv = ast_strdupa(data);
00090 
00091    if (strchr(argv, '/')) {
00092       family = strsep(&argv, "/");
00093       keytree = strsep(&argv, "\0");
00094       if (!family || !keytree) {
00095          ast_debug(1, "Ignoring; Syntax error in argument\n");
00096          return 0;
00097       }
00098       if (ast_strlen_zero(keytree))
00099          keytree = 0;
00100    } else {
00101       family = argv;
00102       keytree = 0;
00103    }
00104 
00105    if (keytree)
00106       ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
00107    else
00108       ast_verb(3, "DBdeltree: family=%s\n", family);
00109 
00110    if (ast_db_deltree(family, keytree))
00111       ast_verb(3, "DBdeltree: Error deleting key from database.\n");
00112 
00113    return 0;
00114 }
00115 
00116 static int del_exec(struct ast_channel *chan, const char *data)
00117 {
00118    char *argv, *family, *key;
00119    static int deprecation_warning = 0;
00120 
00121    if (!deprecation_warning) {
00122       deprecation_warning = 1;
00123       ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
00124    }
00125 
00126    argv = ast_strdupa(data);
00127 
00128    if (strchr(argv, '/')) {
00129       family = strsep(&argv, "/");
00130       key = strsep(&argv, "\0");
00131       if (!family || !key) {
00132          ast_debug(1, "Ignoring; Syntax error in argument\n");
00133          return 0;
00134       }
00135       ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
00136       if (ast_db_del(family, key))
00137          ast_verb(3, "DBdel: Error deleting key from database.\n");
00138    } else {
00139       ast_debug(1, "Ignoring, no parameters\n");
00140    }
00141 
00142    return 0;
00143 }
00144 
00145 static int unload_module(void)
00146 {
00147    int retval;
00148 
00149    retval = ast_unregister_application(dt_app);
00150    retval |= ast_unregister_application(d_app);
00151 
00152    return retval;
00153 }
00154 
00155 static int load_module(void)
00156 {
00157    int retval;
00158 
00159    retval = ast_register_application_xml(d_app, del_exec);
00160    retval |= ast_register_application_xml(dt_app, deltree_exec);
00161 
00162    return retval;
00163 }
00164 
00165 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");

Generated on Mon Jun 27 16:50:46 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7