]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
all vm to auth from the same a1-hash param used by sip (part deux)
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 20 Oct 2008 23:27:29 +0000 (23:27 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 20 Oct 2008 23:27:29 +0000 (23:27 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10087 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_apr.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/switch_apr.c

index eccfc8dd654e6c0d422ca36d3d1ebca9fef2eed6..8e98893edae22ab703608b7198b9cc746884bd7d 100644 (file)
@@ -510,6 +510,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t
 #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
@@ -540,6 +541,7 @@ SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const cha
  * @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);
 
 /** @} */
 
index 38e5452de774ffbe269b1c4dc46fabc250309f58..0e49e644f2fcb0f91be6ecae584dcf870fc9cacf 100644 (file)
@@ -192,6 +192,22 @@ static switch_status_t _find_user(const char *cmd, switch_core_session_t *sessio
        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 = "";
@@ -2725,6 +2741,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        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);
index bfb93bf972182b0a33203025e8525b7189ced4bc..e61162b541b15be7ebd6c472cc20da07923d2a14 100644 (file)
@@ -2003,9 +2003,9 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro
 
                                        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++;
                                                        }
index 0afb5a3625d0fd7c9078daaeedec996d122ce354..d46b8608d06ce094ccb4c812eaa5c56a98a8c425 100644 (file)
@@ -813,6 +813,20 @@ SWITCH_DECLARE(switch_status_t) switch_md5(unsigned char digest[SWITCH_MD5_DIGES
        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) */