[Asterisk-cvs] asterisk/funcs func_db.c,1.1,1.2
russell at lists.digium.com
russell at lists.digium.com
Wed May 18 19:33:21 CDT 2005
Update of /usr/cvsroot/asterisk/funcs
In directory mongoose.digium.com:/tmp/cvs-serv8474/funcs
Modified Files:
func_db.c
Log Message:
add DB_EXISTS function to be able to check if a key exists in the database
Index: func_db.c
===================================================================
RCS file: /usr/cvsroot/asterisk/funcs/func_db.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- func_db.c 8 May 2005 17:08:25 -0000 1.1
+++ func_db.c 18 May 2005 23:38:25 -0000 1.2
@@ -102,3 +102,47 @@
.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,
+};
More information about the svn-commits
mailing list