aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_db.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-18 23:38:25 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-18 23:38:25 +0000
commit52b212d27c8d1c9680713ae138ddb1a28d01e98b (patch)
tree5059fee9fbe8381abf579b7956922303138a998c /funcs/func_db.c
parent0c41b8af7dea44e8b0291f6fdd36bb7526441423 (diff)
add DB_EXISTS function to be able to check if a key exists in the database
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5715 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_db.c')
-rwxr-xr-xfuncs/func_db.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/funcs/func_db.c b/funcs/func_db.c
index ab83eb564..abee5d185 100755
--- a/funcs/func_db.c
+++ b/funcs/func_db.c
@@ -102,3 +102,47 @@ struct ast_custom_function db_function = {
.write = function_db_write,
};
+static char *function_db_exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ int argc;
+ char *args;
+ char *argv[2];
+ char *family;
+ char *key;
+
+ if (!data || ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
+ return buf;
+ }
+
+ args = ast_strdupa(data);
+ argc = ast_separate_app_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
+
+ if (argc > 1) {
+ family = argv[0];
+ key = argv[1];
+ } else {
+ ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
+ return buf;
+ }
+
+ if (ast_db_get(family, key, buf, len-1))
+ ast_copy_string(buf, "0", len);
+ else
+ ast_copy_string(buf, "1", len);
+
+ return buf;
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function db_exists_function = {
+ .name = "DB_EXISTS",
+ .synopsis = "Check to see if a key exists in the Asterisk database",
+ .syntax = "DB_EXISTS(<family>/<key>)",
+ .desc = "This function will check to see if a key exists in the Asterisk\n"
+ "database. If it exists, the function will return \"1\". If not,\n"
+ "it will return \"0\".",
+ .read = function_db_exists,
+};