Sat Aug 6 00:39:19 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: 47782 $")
00034 
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <unistd.h>
00039 #include <sys/types.h>
00040 
00041 #include "asterisk/options.h"
00042 #include "asterisk/file.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/channel.h"
00045 #include "asterisk/pbx.h"
00046 #include "asterisk/module.h"
00047 #include "asterisk/astdb.h"
00048 #include "asterisk/lock.h"
00049 #include "asterisk/options.h"
00050 
00051 /*! \todo XXX Remove this application after 1.4 is relased */
00052 static char *d_descrip =
00053 "  DBdel(family/key): This application will delete a key from the Asterisk\n"
00054 "database.\n"
00055 "  This application has been DEPRECATED in favor of the DB_DELETE function.\n";
00056 
00057 static char *dt_descrip =
00058 "  DBdeltree(family[/keytree]): This application will delete a family or keytree\n"
00059 "from the Asterisk database\n";
00060 
00061 static char *d_app = "DBdel";
00062 static char *dt_app = "DBdeltree";
00063 
00064 static char *d_synopsis = "Delete a key from the database";
00065 static char *dt_synopsis = "Delete a family or keytree from the database";
00066 
00067 
00068 static int deltree_exec(struct ast_channel *chan, void *data)
00069 {
00070    char *argv, *family, *keytree;
00071    struct ast_module_user *u;
00072 
00073    u = ast_module_user_add(chan);
00074 
00075    argv = ast_strdupa(data);
00076 
00077    if (strchr(argv, '/')) {
00078       family = strsep(&argv, "/");
00079       keytree = strsep(&argv, "\0");
00080          if (!family || !keytree) {
00081             ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
00082             ast_module_user_remove(u);
00083             return 0;
00084          }
00085       if (ast_strlen_zero(keytree))
00086          keytree = 0;
00087    } else {
00088       family = argv;
00089       keytree = 0;
00090    }
00091 
00092    if (option_verbose > 2) {
00093       if (keytree)
00094          ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s, keytree=%s\n", family, keytree);
00095       else
00096          ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s\n", family);
00097    }
00098 
00099    if (ast_db_deltree(family, keytree)) {
00100       if (option_verbose > 2)
00101          ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n");
00102    }
00103 
00104    ast_module_user_remove(u);
00105 
00106    return 0;
00107 }
00108 
00109 static int del_exec(struct ast_channel *chan, void *data)
00110 {
00111    char *argv, *family, *key;
00112    struct ast_module_user *u;
00113    static int deprecation_warning = 0;
00114 
00115    u = ast_module_user_add(chan);
00116 
00117    if (!deprecation_warning) {
00118       deprecation_warning = 1;
00119       ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
00120    }
00121 
00122    argv = ast_strdupa(data);
00123 
00124    if (strchr(argv, '/')) {
00125       family = strsep(&argv, "/");
00126       key = strsep(&argv, "\0");
00127       if (!family || !key) {
00128          ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
00129          ast_module_user_remove(u);
00130          return 0;
00131       }
00132       if (option_verbose > 2)
00133          ast_verbose(VERBOSE_PREFIX_3 "DBdel: family=%s, key=%s\n", family, key);
00134       if (ast_db_del(family, key)) {
00135          if (option_verbose > 2)
00136             ast_verbose(VERBOSE_PREFIX_3 "DBdel: Error deleting key from database.\n");
00137       }
00138    } else {
00139       ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
00140    }
00141 
00142    ast_module_user_remove(u);
00143    
00144    return 0;
00145 }
00146 
00147 static int unload_module(void)
00148 {
00149    int retval;
00150 
00151    retval = ast_unregister_application(dt_app);
00152    retval |= ast_unregister_application(d_app);
00153 
00154    return retval;
00155 }
00156 
00157 static int load_module(void)
00158 {
00159    int retval;
00160 
00161    retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
00162    retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
00163    
00164    return retval;
00165 }
00166 
00167 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");

Generated on Sat Aug 6 00:39:19 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7