#define SWITCH_UUID_FORMATTED_LENGTH 36
#define SWITCH_MD5_DIGESTSIZE 16
+#define SWITCH_MD5_DIGEST_STRING_SIZE 33
/**
* Format a UUID into a string, following the standard format
* @param inputLen The length of the message block
*/
SWITCH_DECLARE(switch_status_t) switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen);
+SWITCH_DECLARE(switch_status_t) switch_md5_string(char digest_str[SWITCH_MD5_DIGEST_STRING_SIZE], const void *input, switch_size_t inputLen);
/** @} */
return SWITCH_STATUS_SUCCESS;
}
+
+
+SWITCH_STANDARD_API(md5_function)
+{
+ char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
+
+ if (switch_strlen_zero(cmd)) {
+ stream->write_function(stream, "%s", "!err!");
+ } else {
+ switch_md5_string(digest, (void *) cmd, strlen(cmd));
+ stream->write_function(stream, "%s", digest);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_STANDARD_API(url_decode_function)
{
char *reply = "";
switch_api_interface_t *commands_api_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ SWITCH_ADD_API(commands_api_interface, "md5", "md5", md5_function, "<data>");
SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]");
SWITCH_ADD_API(commands_api_interface, "strftime_tz", "strftime_tz", strftime_tz_api_function, "<Timezone_name> [format string]");
SWITCH_ADD_API(commands_api_interface, "originate", "Originate a Call", originate_function, ORIGINATE_SYNTAX);
if (!auth && (thepass || thehash) && mypass) {
if (thehash) {
- unsigned char digest[SWITCH_MD5_DIGESTSIZE] = { 0 };
+ char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
char *lpbuf = switch_mprintf("%s:%s:%s", myid, domain_name, mypass);
- switch_md5(digest, (void *) lpbuf, strlen(lpbuf));
+ switch_md5_string(digest, (void *) lpbuf, strlen(lpbuf));
if (!strcmp(digest, thehash)) {
auth++;
}
return apr_md5(digest, input, inputLen);
}
+SWITCH_DECLARE(switch_status_t) switch_md5_string(char digest_str[SWITCH_MD5_DIGEST_STRING_SIZE], const void *input, switch_size_t inputLen)
+{
+ unsigned char digest[SWITCH_MD5_DIGESTSIZE];
+ apr_status_t status = apr_md5(digest, input, inputLen);
+ int x;
+
+ digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';
+
+ for( x = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
+ switch_snprintf(digest_str + (x * 2), 3, "%02x", digest[x]);
+ }
+
+ return status;
+}
/* FIFO queues (apr-util) */