/*
- * Copyright (C) 2016-2020 Tobias Brunner
+ * Copyright (C) 2016-2025 Tobias Brunner
*
* Copyright (C) secunet Security Networks AG
*
flags |= VpnProfile.FLAGS_IPv6_TRANSPORT;
}
+ JSONObject proxy = obj.optJSONObject("proxy");
+ if (proxy != null)
+ {
+ profile.setProxyHost(proxy.optString("host"));
+ profile.setProxyPort(getInteger(proxy, "port", 1, 65535));
+ profile.setProxyExclusions(getFlatStringList(proxy, "exclusions"));
+ }
+
JSONObject split = obj.optJSONObject("split-tunneling");
if (split != null)
{
profile.setSplitTunneling(st == 0 ? null : st);
}
/* only one of these can be set, prefer specific apps */
- String selectedApps = getApps(obj.optJSONArray("apps"));
- String excludedApps = getApps(obj.optJSONArray("excluded-apps"));
+ String selectedApps = getFlatStringList(obj, "apps");
+ String excludedApps = getFlatStringList(obj, "excluded-apps");
if (!TextUtils.isEmpty(selectedApps))
{
profile.setSelectedApps(selectedApps);
private String getSubnets(JSONObject split, String key) throws JSONException
{
- ArrayList<String> subnets = new ArrayList<>();
- JSONArray arr = split.optJSONArray(key);
- if (arr != null)
- {
- for (int i = 0; i < arr.length(); i++)
- { /* replace all spaces, e.g. in "192.168.1.1 - 192.168.1.10" */
- subnets.add(arr.getString(i).replace(" ", ""));
- }
- }
- else
- {
- String value = split.optString(key, null);
- if (!TextUtils.isEmpty(value))
- {
- subnets.add(value);
- }
- }
- if (subnets.size() > 0)
+ ArrayList<String> subnets = getStringList(split, key);
+ if (!subnets.isEmpty())
{
String joined = TextUtils.join(" ", subnets);
IPRangeSet ranges = IPRangeSet.fromString(joined);
private String getAddressList(JSONObject obj, String key) throws JSONException
{
- ArrayList<String> addrs = new ArrayList<>();
- JSONArray arr = obj.optJSONArray(key);
- if (arr != null)
- {
- for (int i = 0; i < arr.length(); i++)
- {
- String addr = arr.getString(i).replace(" ", "");
- addrs.add(addr);
- }
- }
- else
- {
- String value = obj.optString(key, null);
- if (!TextUtils.isEmpty(value))
- {
- Collections.addAll(addrs, value.split("\\s+"));
- }
- }
- if (addrs.size() > 0)
+ ArrayList<String> addrs = getStringList(obj, key);
+ if (!addrs.isEmpty())
{
for (String addr : addrs)
{
return null;
}
- private String getApps(JSONArray arr) throws JSONException
+ private String getFlatStringList(JSONObject obj, String key) throws JSONException
{
- ArrayList<String> apps = new ArrayList<>();
+ ArrayList<String> list = getStringList(obj, key);
+ if (!list.isEmpty())
+ {
+ return TextUtils.join(" ", list);
+ }
+ return null;
+ }
+
+ /**
+ * Return a list of strings, either retrieved from an array or from a space-separated string.
+ */
+ private ArrayList<String> getStringList(JSONObject obj, String key) throws JSONException
+ {
+ ArrayList<String> list = new ArrayList<>();
+ JSONArray arr = obj.optJSONArray(key);
if (arr != null)
{
for (int i = 0; i < arr.length(); i++)
+ { /* replace all spaces, including e.g. in "192.168.1.1 - 192.168.1.10" */
+ list.add(arr.getString(i).replace(" ", ""));
+ }
+ }
+ else
+ {
+ String value = obj.optString(key, null);
+ if (!TextUtils.isEmpty(value))
{
- apps.add(arr.getString(i));
+ Collections.addAll(list, value.split("\\s+"));
}
}
- return TextUtils.join(" ", apps);
+ return list;
}
/**