RTS API Documentation  1.10.11
Data Structures | Macros | Functions
+ Collaboration diagram for UUID Handling:

Data Structures

struct  switch_uuid_t
 

Macros

#define SWITCH_UUID_FORMATTED_LENGTH   256
 
#define SWITCH_MD5_DIGESTSIZE   16
 
#define SWITCH_MD5_DIGEST_STRING_SIZE   33
 

Functions

void switch_uuid_format (char *buffer, const switch_uuid_t *uuid)
 
void switch_uuid_get (switch_uuid_t *uuid)
 
switch_status_t switch_uuid_parse (switch_uuid_t *uuid, const char *uuid_str)
 
switch_status_t switch_md5 (unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
 
switch_status_t switch_md5_string (char digest_str[SWITCH_MD5_DIGEST_STRING_SIZE], const void *input, switch_size_t inputLen)
 

Detailed Description

Macro Definition Documentation

◆ SWITCH_MD5_DIGEST_STRING_SIZE

#define SWITCH_MD5_DIGEST_STRING_SIZE   33

Definition at line 548 of file switch_apr.h.

◆ SWITCH_MD5_DIGESTSIZE

#define SWITCH_MD5_DIGESTSIZE   16

Definition at line 547 of file switch_apr.h.

Referenced by switch_md5_string().

◆ SWITCH_UUID_FORMATTED_LENGTH

#define SWITCH_UUID_FORMATTED_LENGTH   256

Function Documentation

◆ switch_md5()

switch_status_t switch_md5 ( unsigned char  digest[SWITCH_MD5_DIGESTSIZE],
const void *  input,
switch_size_t  inputLen 
)

MD5 in one step

Parameters
digestThe final MD5 digest
inputThe message block to use
inputLenThe length of the message block

Definition at line 1175 of file switch_apr.c.

References SWITCH_STATUS_NOTIMPL, and SWITCH_STATUS_SUCCESS.

Referenced by switch_md5_string().

1176 {
1177 #if (defined(HAVE_LIBMD5) || defined(HAVE_LIBMD) || defined(HAVE_MD5INIT))
1178  MD5_CTX md5_context;
1179 
1180  MD5Init(&md5_context);
1181  MD5Update(&md5_context, input, inputLen);
1182  MD5Final(digest, &md5_context);
1183 
1184  return SWITCH_STATUS_SUCCESS;
1185 #elif defined(HAVE_LIBCRYPTO)
1186  #if OPENSSL_VERSION_NUMBER < 0x30000000
1187  MD5_CTX md5_context;
1188 
1189  MD5_Init(&md5_context);
1190  MD5_Update(&md5_context, input, inputLen);
1191  MD5_Final(digest, &md5_context);
1192  #else
1193  EVP_MD_CTX *md5_context;
1194 
1195  /* MD5_Init */
1196  md5_context = EVP_MD_CTX_new();
1197  EVP_DigestInit_ex(md5_context, EVP_md5(), NULL);
1198  /* MD5_Update */
1199  EVP_DigestUpdate(md5_context, input, inputLen);
1200  /* MD5_Final */
1201  EVP_DigestFinal_ex(md5_context, digest, NULL);
1202  EVP_MD_CTX_free(md5_context);
1203  #endif
1204 
1205  return SWITCH_STATUS_SUCCESS;
1206 #else
1207  return SWITCH_STATUS_NOTIMPL;
1208 #endif
1209 }

◆ switch_md5_string()

switch_status_t switch_md5_string ( char  digest_str[SWITCH_MD5_DIGEST_STRING_SIZE],
const void *  input,
switch_size_t  inputLen 
)

Definition at line 1211 of file switch_apr.c.

References b, switch_md5(), and SWITCH_MD5_DIGESTSIZE.

1212 {
1213  unsigned char digest[SWITCH_MD5_DIGESTSIZE];
1214  switch_status_t status = switch_md5(digest, input, inputLen);
1215  short i, x;
1216  uint8_t b;
1217 
1218  digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';
1219 
1220  for (x = i = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
1221  b = (digest[x] >> 4) & 15;
1222  digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
1223  b = digest[x] & 15;
1224  digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
1225  }
1226  digest_str[i] = '\0';
1227 
1228  return status;
1229 }
const cJSON *const b
Definition: switch_cJSON.h:243
#define SWITCH_MD5_DIGEST_STRING_SIZE
Definition: switch_apr.h:548
switch_status_t switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
Definition: switch_apr.c:1175
switch_status_t
Common return values.
#define SWITCH_MD5_DIGESTSIZE
Definition: switch_apr.h:547

◆ switch_uuid_format()

void switch_uuid_format ( char *  buffer,
const switch_uuid_t uuid 
)

Format a UUID into a string, following the standard format

Parameters
bufferThe buffer to place the formatted UUID string into. It must be at least APR_UUID_FORMATTED_LENGTH + 1 bytes long to hold the formatted UUID and a null terminator
uuidThe UUID to format

Definition at line 1140 of file switch_apr.c.

References buf, and switch_uuid_t::data.

Referenced by switch_core_init(), switch_core_perform_file_open(), switch_core_session_request_uuid(), switch_ivr_insert_file(), and switch_uuid_str().

1141 {
1142 #ifndef WIN32
1143  uuid_unparse_lower(uuid->data, buffer);
1144 #else
1145  RPC_CSTR buf;
1146  UuidToString((const UUID *) uuid, &buf);
1147  strcpy(buffer, (const char *) buf);
1148  RpcStringFree(&buf);
1149 #endif
1150 }
switch_byte_t switch_byte_t * buf
char * buffer
Definition: switch_cJSON.h:153
unsigned char data[16]
Definition: switch_apr.h:540

◆ switch_uuid_get()

void switch_uuid_get ( switch_uuid_t uuid)

Generate and return a (new) UUID

Parameters
uuidThe resulting UUID

Definition at line 1152 of file switch_apr.c.

References switch_uuid_t::data, runtime, switch_mutex_lock(), switch_mutex_unlock(), and switch_runtime::uuid_mutex.

Referenced by switch_core_init(), switch_core_perform_file_open(), switch_core_session_request_uuid(), switch_ivr_insert_file(), and switch_uuid_str().

1153 {
1155 #ifndef WIN32
1156  uuid_generate(uuid->data);
1157 #else
1158  UuidCreate((UUID *) uuid);
1159 #endif
1161 }
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * uuid_mutex
unsigned char data[16]
Definition: switch_apr.h:540

◆ switch_uuid_parse()

switch_status_t switch_uuid_parse ( switch_uuid_t uuid,
const char *  uuid_str 
)

Parse a standard-format string into a UUID

Parameters
uuidThe resulting UUID
uuid_strThe formatted UUID

Definition at line 1163 of file switch_apr.c.

References switch_uuid_t::data, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

1164 {
1165 #ifndef WIN32
1166  if (uuid_parse(uuid_str, uuid->data)) {
1167  return SWITCH_STATUS_FALSE;
1168  }
1169  return SWITCH_STATUS_SUCCESS;
1170 #else
1171  return UuidFromString((RPC_CSTR) uuid_str, (UUID *) uuid);
1172 #endif
1173 }
unsigned char data[16]
Definition: switch_apr.h:540