Wed Aug 18 22:33:40 2010

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: 103249 $")
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 /*! \todo XXX Remove this application after 1.4 is relased */
00043 static char *d_descrip =
00044 "  DBdel(family/key): This application will delete a key from the Asterisk\n"
00045 "database.\n"
00046 "  This application has been DEPRECATED in favor of the DB_DELETE function.\n";
00047 
00048 static char *dt_descrip =
00049 "  DBdeltree(family[/keytree]): This application will delete a family or keytree\n"
00050 "from the Asterisk database\n";
00051 
00052 static char *d_app = "DBdel";
00053 static char *dt_app = "DBdeltree";
00054 
00055 static char *d_synopsis = "Delete a key from the database";
00056 static char *dt_synopsis = "Delete a family or keytree from the database";
00057 
00058 
00059 static int deltree_exec(struct ast_channel *chan, void *data)
00060 {
00061    char *argv, *family, *keytree;
00062 
00063    argv = ast_strdupa(data);
00064 
00065    if (strchr(argv, '/')) {
00066       family = strsep(&argv, "/");
00067       keytree = strsep(&argv, "\0");
00068       if (!family || !keytree) {
00069          ast_debug(1, "Ignoring; Syntax error in argument\n");
00070          return 0;
00071       }
00072       if (ast_strlen_zero(keytree))
00073          keytree = 0;
00074    } else {
00075       family = argv;
00076       keytree = 0;
00077    }
00078 
00079    if (keytree)
00080       ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
00081    else
00082       ast_verb(3, "DBdeltree: family=%s\n", family);
00083 
00084    if (ast_db_deltree(family, keytree))
00085       ast_verb(3, "DBdeltree: Error deleting key from database.\n");
00086 
00087    return 0;
00088 }
00089 
00090 static int del_exec(struct ast_channel *chan, void *data)
00091 {
00092    char *argv, *family, *key;
00093    static int deprecation_warning = 0;
00094 
00095    if (!deprecation_warning) {
00096       deprecation_warning = 1;
00097       ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
00098    }
00099 
00100    argv = ast_strdupa(data);
00101 
00102    if (strchr(argv, '/')) {
00103       family = strsep(&argv, "/");
00104       key = strsep(&argv, "\0");
00105       if (!family || !key) {
00106          ast_debug(1, "Ignoring; Syntax error in argument\n");
00107          return 0;
00108       }
00109       ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
00110       if (ast_db_del(family, key))
00111          ast_verb(3, "DBdel: Error deleting key from database.\n");
00112    } else {
00113       ast_debug(1, "Ignoring, no parameters\n");
00114    }
00115 
00116    return 0;
00117 }
00118 
00119 static int unload_module(void)
00120 {
00121    int retval;
00122 
00123    retval = ast_unregister_application(dt_app);
00124    retval |= ast_unregister_application(d_app);
00125 
00126    return retval;
00127 }
00128 
00129 static int load_module(void)
00130 {
00131    int retval;
00132 
00133    retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
00134    retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
00135 
00136    return retval;
00137 }
00138 
00139 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");

Generated on Wed Aug 18 22:33:40 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7