From 8ec097a28186ba6fb461dc1213e65d208ec773f3 Mon Sep 17 00:00:00 2001 From: Maksim Nesterov Date: Sun, 1 Dec 2024 19:42:50 +0000 Subject: [PATCH] func_uuid: Add a new dialplan function to generate UUIDs This function is useful for uniquely identifying calls, recordings, and other entities in distributed environments, as well as for generating an argument for the AudioSocket application. --- funcs/func_uuid.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 funcs/func_uuid.c diff --git a/funcs/func_uuid.c b/funcs/func_uuid.c new file mode 100644 index 0000000000..05dfde37e5 --- /dev/null +++ b/funcs/func_uuid.c @@ -0,0 +1,76 @@ +/* +* Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2024, Maksim Nesterov + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief UUID dialplan function + * + * \author Maksim Nesterov + * + * \ingroup functions + */ + +/*** MODULEINFO + extended + ***/ + +#include "asterisk.h" + +#include "asterisk/module.h" +#include "asterisk/pbx.h" +#include "asterisk/uuid.h" + +/*** DOCUMENTATION + + + Generates an UUID. + + + + + Returns a version 4 (random) Universally Unique Identifier (UUID) as a string. + + same => n,Set(uuid=${UUID()}) + + + + ***/ + +static int uuid(struct ast_channel *chan, const char *cmd, char *data, + char *buf, size_t len) +{ + ast_uuid_generate_str(buf, AST_UUID_STR_LEN); + return 0; +} + +static struct ast_custom_function uuid_function = { + .name = "UUID", + .read = uuid, + .read_max = AST_UUID_STR_LEN, +}; + +static int unload_module(void) +{ + return ast_custom_function_unregister(&uuid_function); +} + +static int load_module(void) +{ + return ast_custom_function_register(&uuid_function); +} + +AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, + "UUID generation dialplan function");