From 11f4b3c4f7e78d622ed4bc46014dc3dcf0642b77 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 30 Sep 2016 11:27:44 +0800 Subject: [PATCH] FS-9575 fix windows build random() is a posix ext not available on windows --- src/switch_msrp.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index af7bcffd93..d31b5bd4b8 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -32,6 +32,7 @@ #include #include #include +#include #define MSRP_BUFF_SIZE SWITCH_RTP_MAX_BUF_LEN #define DEBUG_MSRP 0 @@ -1118,20 +1119,15 @@ static void *SWITCH_THREAD_FUNC msrp_listener(switch_thread_t *thread, void *obj return NULL; } -void random_string(char *buf, switch_size_t size) +void random_string(char *buf, uint16_t size) { - long val[4]; - int x; - - for (x = 0; x < 4; x++) - val[x] = random(); - snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); - *(buf+size) = '\0'; + switch_stun_random_string(buf, size, NULL); } +#define MSRP_TRANS_ID_LEN 16 SWITCH_DECLARE(switch_status_t) switch_msrp_send(switch_msrp_session_t *ms, msrp_msg_t *msrp_msg) { - char transaction_id[32]; + char transaction_id[MSRP_TRANS_ID_LEN + 1] = { 0 }; char buf[MSRP_BUFF_SIZE]; switch_size_t len; char *to_path = msrp_msg->headers[MSRP_H_TO_PATH] ? msrp_msg->headers[MSRP_H_TO_PATH] : ms->remote_path; @@ -1139,7 +1135,7 @@ SWITCH_DECLARE(switch_status_t) switch_msrp_send(switch_msrp_session_t *ms, msrp if (!from_path) return SWITCH_STATUS_SUCCESS; - random_string(transaction_id, 16); + random_string(transaction_id, MSRP_TRANS_ID_LEN); sprintf(buf, "MSRP %s SEND\r\nTo-Path: %s\r\nFrom-Path: %s\r\n" "Content-Type: %s\r\n"