You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by he...@apache.org on 2022/11/22 11:26:01 UTC
[inlong] branch master updated: [INLONG-6602][DataProxy] Fix the IP config was invalid (#6603)
This is an automated email from the ASF dual-hosted git repository.
healchow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new ceba86044 [INLONG-6602][DataProxy] Fix the IP config was invalid (#6603)
ceba86044 is described below
commit ceba860443df121c9a05601ddd623f439f4495bc
Author: Goson Zhang <46...@qq.com>
AuthorDate: Tue Nov 22 19:25:56 2022 +0800
[INLONG-6602][DataProxy] Fix the IP config was invalid (#6603)
---
.../apache/inlong/dataproxy/source/BaseSource.java | 1 +
.../inlong/dataproxy/source/ConfStringUtils.java | 61 ----------------------
.../inlong/dataproxy/utils/ConfStringUtils.java | 12 +++--
3 files changed, 9 insertions(+), 65 deletions(-)
diff --git a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/BaseSource.java b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/BaseSource.java
index 8fed4bbc3..b790fae69 100644
--- a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/BaseSource.java
+++ b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/BaseSource.java
@@ -41,6 +41,7 @@ import org.apache.inlong.dataproxy.consts.ConfigConstants;
import org.apache.inlong.common.monitor.MonitorIndex;
import org.apache.inlong.common.monitor.MonitorIndexExt;
import org.apache.inlong.dataproxy.metrics.DataProxyMetricItemSet;
+import org.apache.inlong.dataproxy.utils.ConfStringUtils;
import org.apache.inlong.dataproxy.utils.FailoverChannelProcessorHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/ConfStringUtils.java b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/ConfStringUtils.java
deleted file mode 100644
index 0d61db518..000000000
--- a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/ConfStringUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.dataproxy.source;
-
-public class ConfStringUtils {
-
- /**
- * Check ip format
- *
- * @param ip ip
- * @return Boolean
- */
- public static boolean isValidIp(String ip) {
- if (ip == null || ip.trim().isEmpty()) {
- return false;
- }
- boolean b = false;
- ip = ip.trim();
- if (ip.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) {
- String[] s = ip.split("\\.");
- if (Integer.parseInt(s[0]) < 255) {
- if (Integer.parseInt(s[1]) < 255) {
- if (Integer.parseInt(s[2]) < 255) {
- if (Integer.parseInt(s[3]) < 255) {
- b = true;
- }
- }
- }
- }
- }
- return b;
- }
-
- /**
- * Check ip port
- *
- * @param port Port
- * @return Boolean
- */
- public static boolean isValidPort(int port) {
- if (port < 0 || port > 65535) {
- return false;
- }
- return true;
- }
-}
diff --git a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/ConfStringUtils.java b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/ConfStringUtils.java
index 3ad6d6ba2..9f5cb34bc 100644
--- a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/ConfStringUtils.java
+++ b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/ConfStringUtils.java
@@ -30,10 +30,14 @@ public class ConfStringUtils {
ip = ip.trim();
if (ip.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) {
String[] s = ip.split("\\.");
- if (Integer.parseInt(s[0]) < 255) {
- if (Integer.parseInt(s[1]) < 255) {
- if (Integer.parseInt(s[2]) < 255) {
- if (Integer.parseInt(s[3]) < 255) {
+ int number0 = Integer.parseInt(s[0]);
+ int number1 = Integer.parseInt(s[1]);
+ int number2 = Integer.parseInt(s[2]);
+ int number3 = Integer.parseInt(s[3]);
+ if (number0 >= 0 && number0 <= 255) {
+ if (number1 >= 0 && number1 <= 255) {
+ if (number2 >= 0 && number2 <= 255) {
+ if (number3 >= 0 && number3 <= 255) {
b = true;
}
}