mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 05:08:03 +01:00
Drop tagging for legacy user agents
This commit is contained in:
committed by
ravi-signal
parent
59bc2c5535
commit
c06313dd2e
@@ -7,25 +7,14 @@ package org.whispersystems.textsecuregcm.util.ua;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class UserAgentUtil {
|
||||
|
||||
private static final Pattern STANDARD_UA_PATTERN = Pattern.compile("^Signal-(Android|Desktop|iOS)/([^ ]+)( (.+))?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static final Map<ClientPlatform, Pattern> LEGACY_PATTERNS_BY_PLATFORM = new EnumMap<>(ClientPlatform.class);
|
||||
|
||||
static {
|
||||
LEGACY_PATTERNS_BY_PLATFORM.put(ClientPlatform.ANDROID, Pattern.compile("^Signal-Android ([^ ]+)( (.+))?$", Pattern.CASE_INSENSITIVE));
|
||||
LEGACY_PATTERNS_BY_PLATFORM.put(ClientPlatform.DESKTOP, Pattern.compile("^Signal Desktop (.+)$", Pattern.CASE_INSENSITIVE));
|
||||
LEGACY_PATTERNS_BY_PLATFORM.put(ClientPlatform.IOS, Pattern.compile("^Signal/([^ ]+)( (.+))?$", Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
|
||||
public static UserAgent parseUserAgentString(final String userAgentString) throws UnrecognizedUserAgentException {
|
||||
if (StringUtils.isBlank(userAgentString)) {
|
||||
throw new UnrecognizedUserAgentException("User-Agent string is blank");
|
||||
@@ -37,12 +26,6 @@ public class UserAgentUtil {
|
||||
if (standardUserAgent != null) {
|
||||
return standardUserAgent;
|
||||
}
|
||||
|
||||
final UserAgent legacyUserAgent = parseLegacyUserAgentString(userAgentString);
|
||||
|
||||
if (legacyUserAgent != null) {
|
||||
return legacyUserAgent;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
throw new UnrecognizedUserAgentException(e);
|
||||
}
|
||||
@@ -60,27 +43,4 @@ public class UserAgentUtil {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static UserAgent parseLegacyUserAgentString(final String userAgentString) {
|
||||
for (final Map.Entry<ClientPlatform, Pattern> entry : LEGACY_PATTERNS_BY_PLATFORM.entrySet()) {
|
||||
final ClientPlatform platform = entry.getKey();
|
||||
final Pattern pattern = entry.getValue();
|
||||
final Matcher matcher = pattern.matcher(userAgentString);
|
||||
|
||||
if (matcher.matches()) {
|
||||
final UserAgent userAgent;
|
||||
|
||||
if (matcher.groupCount() > 1) {
|
||||
userAgent = new UserAgent(platform, new Semver(matcher.group(1)), StringUtils.stripToNull(matcher.group(matcher.groupCount())));
|
||||
} else {
|
||||
userAgent = new UserAgent(platform, new Semver(matcher.group(1)));
|
||||
}
|
||||
|
||||
return userAgent;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user