Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/include/switch_apr.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,14 @@ SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
*/
SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid);

/**
*
* @param uuid
* @param version
* @return switch_status_t
*/
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_version(switch_uuid_t *uuid, int version);

/**
* Parse a standard-format string into a UUID
* @param uuid The resulting UUID
Expand Down
1 change: 1 addition & 0 deletions src/include/switch_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ SWITCH_DECLARE(const char *) switch_inet_ntop(int af, void const *src, char *dst
#endif

SWITCH_DECLARE(char *) switch_uuid_str(char *buf, switch_size_t len);
SWITCH_DECLARE(char *) switch_uuid_str_version(char *buf, switch_size_t len, int version);
SWITCH_DECLARE(char *) switch_format_number(const char *num);

SWITCH_DECLARE(unsigned int) switch_atoui(const char *nptr);
Expand Down
14 changes: 12 additions & 2 deletions src/mod/applications/mod_commands/mod_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -3173,11 +3173,21 @@ SWITCH_STANDARD_API(tone_detect_session_function)
return SWITCH_STATUS_SUCCESS;
}

#define UUID_GENERATE_SYNTAX "<create_uuid> [4|7]"
SWITCH_STANDARD_API(uuid_function)
{
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];

switch_uuid_str(uuid_str, sizeof(uuid_str));
int version = 0;
if (!zstr(cmd)) {
version = atoi(cmd);
}

if (version) {
switch_uuid_str_version(uuid_str, sizeof(uuid_str), version);
} else {
switch_uuid_str(uuid_str, sizeof(uuid_str));
}

stream->write_function(stream, "%s", uuid_str);
return SWITCH_STATUS_SUCCESS;
Expand Down Expand Up @@ -7609,7 +7619,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "cond", "Evaluate a conditional", cond_function, "<expr> ? <true val> : <false val>");
SWITCH_ADD_API(commands_api_interface, "console_complete", "", console_complete_function, "<line>");
SWITCH_ADD_API(commands_api_interface, "console_complete_xml", "", console_complete_xml_function, "<line>");
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_GENERATE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "db_cache", "Manage db cache", db_cache_function, "status");
SWITCH_ADD_API(commands_api_interface, "domain_data", "Find domain data", domain_data_function, "<domain> [var|param|attr] <name>");
SWITCH_ADD_API(commands_api_interface, "domain_exists", "Check if a domain exists", domain_exists_function, "<domain>");
Expand Down
34 changes: 29 additions & 5 deletions src/switch_apr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,17 +1151,41 @@ SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
#endif
}

#ifndef WIN32
#define uuidv4_new(uuid) uuid_generate(uuid->data);
#else
#define uuidv4_new(uuid) UuidCreate((UUID *)uuid);
#endif

SWITCH_DECLARE(switch_status_t) switch_uuid_generate_version(switch_uuid_t *uuid, int version)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_mutex_lock(runtime.uuid_mutex);

switch(version) {
case 4:
uuidv4_new(uuid);
break;
case 7:
uuidv7_new(uuid->data);
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Unsupported UUID version %d\n", version);
status = SWITCH_STATUS_FALSE;
}
switch_mutex_unlock(runtime.uuid_mutex);

return status;
}


SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid)
{
switch_mutex_lock(runtime.uuid_mutex);
if (runtime.uuid_version == 7) {
uuidv7_new(uuid->data);
} else {
#ifndef WIN32
uuid_generate(uuid->data);
#else
UuidCreate((UUID *)uuid);
#endif
uuidv4_new(uuid);
}

switch_mutex_unlock(runtime.uuid_mutex);
Expand Down
15 changes: 15 additions & 0 deletions src/switch_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,21 @@ SWITCH_DECLARE(char *) switch_uuid_str(char *buf, switch_size_t len)
return buf;
}

SWITCH_DECLARE(char *) switch_uuid_str_version(char *buf, switch_size_t len, int version)
{
switch_uuid_t uuid;

if (len < (SWITCH_UUID_FORMATTED_LENGTH + 1)) {
switch_snprintf(buf, len, "INVALID");
} else if (switch_uuid_generate_version(&uuid, version) != SWITCH_STATUS_SUCCESS) {
switch_snprintf(buf, len, "INVALID");
} else {
switch_uuid_format(buf, &uuid);
}

return buf;
}


SWITCH_DECLARE(char *) switch_format_number(const char *num)
{
Expand Down