Add DBDel and DBDelTree manager commands. (issue #8516 reported by dprado)
authorJoshua Colp <jcolp@digium.com>
Thu, 25 Jan 2007 22:49:24 +0000 (22:49 +0000)
committerJoshua Colp <jcolp@digium.com>
Thu, 25 Jan 2007 22:49:24 +0000 (22:49 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@52308 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
main/db.c

diff --git a/CHANGES b/CHANGES
index 9c5e55f..fa487bb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -66,6 +66,7 @@ Changes since Asterisk 1.4-beta was branched:
   * Added 's' option to Page application.
   * Added the srvlookup option to iax.conf
   * Added 'E' and 'V' commands to ExternalIVR.
+  * Added 'DBDel' and 'DBDelTree' manager commands.
 
 SIP changes
 -----------
index e51b926..de53ab7 100644 (file)
--- a/main/db.c
+++ b/main/db.c
@@ -588,11 +588,62 @@ static int manager_dbget(struct mansession *s, const struct message *m)
        return 0;
 }
 
+static int manager_dbdel(struct mansession *s, const struct message *m)
+{
+       const char *family = astman_get_header(m, "Family");
+       const char *key = astman_get_header(m, "Key");
+       int res;
+
+       if (ast_strlen_zero(family)) {
+               astman_send_error(s, m, "No family specified.");
+               return 0;
+       }
+
+       if (ast_strlen_zero(key)) {
+               astman_send_error(s, m, "No key specified.");
+               return 0;
+       }
+
+       res = ast_db_del(family, key);
+       if (res)
+               astman_send_error(s, m, "Database entry not found");
+       else
+               astman_send_ack(s, m, "Key deleted successfully");
+
+       return 0;
+}
+
+static int manager_dbdeltree(struct mansession *s, const struct message *m)
+{
+       const char *family = astman_get_header(m, "Family");
+       const char *key = astman_get_header(m, "Key");
+       int res;
+
+       if (ast_strlen_zero(family)) {
+               astman_send_error(s, m, "No family specified.");
+               return 0;
+       }
+
+       if (!ast_strlen_zero(key))
+               res = ast_db_deltree(family, key);
+       else
+               res = ast_db_deltree(family, NULL);
+
+       if (res)
+               astman_send_error(s, m, "Database entry not found");
+       else
+               astman_send_ack(s, m, "Key tree deleted successfully");
+       
+       return 0;
+}
+
 int astdb_init(void)
 {
        dbinit();
        ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry));
        ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
        ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
+       ast_manager_register("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");
+       ast_manager_register("DBDelTree", EVENT_FLAG_SYSTEM, manager_dbdeltree, "Delete DB Tree");
        return 0;
 }