| 1 | /* |
| 2 | * Asterisk -- An open source telephony toolkit. |
| 3 | * |
| 4 | * Copyright (C) 2024, Maksim Nesterov |
| 5 | * |
| 6 | * See http://www.asterisk.org for more information about |
| 7 | * the Asterisk project. Please do not directly contact |
| 8 | * any of the maintainers of this project for assistance; |
| 9 | * the project provides a web site, mailing lists and IRC |
| 10 | * channels for your use. |
| 11 | * |
| 12 | * This program is free software, distributed under the terms of |
| 13 | * the GNU General Public License Version 2. See the LICENSE file |
| 14 | * at the top of the source tree. |
| 15 | */ |
| 16 | |
| 17 | /*! \file |
| 18 | * |
| 19 | * \brief UUID dialplan function |
| 20 | * |
| 21 | * \author Maksim Nesterov <[email protected]> |
| 22 | * |
| 23 | * \ingroup functions |
| 24 | */ |
| 25 | |
| 26 | /*** MODULEINFO |
| 27 | <support_level>extended</support_level> |
| 28 | ***/ |
| 29 | |
| 30 | #include "asterisk.h" |
| 31 | |
| 32 | #include "asterisk/module.h" |
| 33 | #include "asterisk/pbx.h" |
| 34 | #include "asterisk/uuid.h" |
| 35 | |
| 36 | /*** DOCUMENTATION |
| 37 | <function name="UUID" language="en_US"> |
| 38 | <synopsis> |
| 39 | Generates an UUID. |
| 40 | </synopsis> |
| 41 | <syntax> |
| 42 | </syntax> |
| 43 | <description> |
| 44 | <para>Returns a version 4 (random) Universally Unique Identifier (UUID) as a string.</para> |
| 45 | <example title="Generate an UUID"> |
| 46 | same => n,Set(uuid=${UUID()}) |
| 47 | </example> |
| 48 | </description> |
| 49 | </function> |
| 50 | ***/ |
| 51 | |
| 52 | static int uuid(struct ast_channel *chan, const char *cmd, char *data, |
| 53 | char *buf, size_t len) |
| 54 | { |
| 55 | ast_uuid_generate_str(buf, AST_UUID_STR_LEN); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static struct ast_custom_function uuid_function = { |
| 60 | .name = "UUID", |
| 61 | .read = uuid, |
| 62 | .read_max = AST_UUID_STR_LEN, |
| 63 | }; |
| 64 | |
| 65 | static int unload_module(void) |
| 66 | { |
| 67 | return ast_custom_function_unregister(&uuid_function); |
| 68 | } |
| 69 | |
| 70 | static int load_module(void) |
| 71 | { |
| 72 | return ast_custom_function_register(&uuid_function); |
| 73 | } |
| 74 | |
| 75 | AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, |
| 76 | "UUID generation dialplan function"); |