From 7db2bf7b51015a7e989ea5b0f4d9486dfd99d4bd Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 02 九月 2022 10:51:55 +0800
Subject: [PATCH] 使用equalsIgnoreCase代替equals,忽略大小写差异

---
 src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java |   31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
index 85f4684..3438893 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
@@ -4,7 +4,12 @@
 import com.genersoft.iot.vmp.utils.DateUtil;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.regex.Pattern;
 
 
 @Configuration("mediaConfig")
@@ -84,7 +89,7 @@
     }
 
     public String getHookIp() {
-        if (StringUtils.isEmpty(hookIp)){
+        if (ObjectUtils.isEmpty(hookIp)){
             return sipIp;
         }else {
             return hookIp;
@@ -158,15 +163,26 @@
     }
 
     public String getSdpIp() {
-        if (StringUtils.isEmpty(sdpIp)){
+        if (ObjectUtils.isEmpty(sdpIp)){
             return ip;
         }else {
-            return sdpIp;
+            if (isValidIPAddress(sdpIp)) {
+                return sdpIp;
+            }else {
+                // 鎸夌収鍩熷悕瑙f瀽
+                String hostAddress = null;
+                try {
+                    hostAddress = InetAddress.getByName(sdpIp).getHostAddress();
+                } catch (UnknownHostException e) {
+                    throw new RuntimeException(e);
+                }
+                return hostAddress;
+            }
         }
     }
 
     public String getStreamIp() {
-        if (StringUtils.isEmpty(streamIp)){
+        if (ObjectUtils.isEmpty(streamIp)){
             return ip;
         }else {
             return streamIp;
@@ -211,4 +227,11 @@
         return mediaServerItem;
     }
 
+    private boolean isValidIPAddress(String ipAddress) {
+        if ((ipAddress != null) && (!ipAddress.isEmpty())) {
+            return Pattern.matches("^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$", ipAddress);
+        }
+        return false;
+    }
+
 }

--
Gitblit v1.8.0