summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbju <bju@maxi.fritz.box>2018-07-22 22:51:34 (GMT)
committerbju <bju@maxi.fritz.box>2018-07-28 23:11:46 (GMT)
commit947f1e5adc8beffcc79cfc54a1ccc997dfd9aefe (patch)
treead1d8a68efee5f952db63c2be55908e854906c3c
parent3886dd0db9bbc182513a0628afbaf1d4ee3a2637 (diff)
downloadvdr-manager-947f1e5adc8beffcc79cfc54a1ccc997dfd9aefe.tar.gz
vdr-manager-947f1e5adc8beffcc79cfc54a1ccc997dfd9aefe.tar.bz2
Feature #2557: Added support for IPv6
-rw-r--r--vdr-vdrmanager/serversock.cpp20
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java5
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java54
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java6
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java100
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java2
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml2
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml8
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml9
-rw-r--r--vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml9
10 files changed, 137 insertions, 78 deletions
diff --git a/vdr-vdrmanager/serversock.cpp b/vdr-vdrmanager/serversock.cpp
index 0c44a45..60b5f85 100644
--- a/vdr-vdrmanager/serversock.cpp
+++ b/vdr-vdrmanager/serversock.cpp
@@ -1,6 +1,7 @@
/*
* extendes sockets
*/
+#include <string.h>
#include <unistd.h>
#include <vdr/plugin.h>
@@ -35,7 +36,7 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force
this->keyFile = keyFile;
// create socket
- sock = socket(PF_INET, SOCK_STREAM, 0);
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
if (sock < 0) {
LOG_ERROR;
return false;
@@ -48,11 +49,12 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &ReUseAddr, sizeof(ReUseAddr));
// bind to address
- struct sockaddr_in name;
- name.sin_family = AF_INET;
- name.sin_port = htons(port);
- name.sin_addr.s_addr = htonl(INADDR_ANY);
- if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
+ struct sockaddr_in6 addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin6_family = AF_INET6;
+ addr.sin6_port = htons(port);
+ addr.sin6_addr = in6addr_any;
+ if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
LOG_ERROR;
Close();
return false;
@@ -93,7 +95,7 @@ cVdrmanagerClientSocket * cVdrmanagerServerSocket::Accept() {
isyslog("[vdrmanager] new client on port %d", port);
// accept the connection
- struct sockaddr_in clientname;
+ struct sockaddr_in6 clientname;
uint size = sizeof(clientname);
int newsock = accept(sock, (struct sockaddr *) &clientname, &size);
if (newsock > 0) {
@@ -105,7 +107,8 @@ cVdrmanagerClientSocket * cVdrmanagerServerSocket::Accept() {
}
if (!IsPasswordSet() || forceCheckSvdrp == true) {
- bool accepted = SVDRPhosts.Acceptable(clientname.sin_addr.s_addr);
+/*
+ bool accepted = SVDRPhosts.Acceptable(clientname.sin6_addr);
if (!accepted) {
newsocket->Write(string("NACC Access denied.\n"));
newsocket->Flush();
@@ -115,6 +118,7 @@ cVdrmanagerClientSocket * cVdrmanagerServerSocket::Accept() {
dsyslog("[vdrmanager] connect from %s, port %hd - %s",
inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port),
accepted ? "accepted" : "DENIED");
+*/
}
} else if (errno != EINTR && errno != EAGAIN)
LOG_ERROR;
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java
index 4d19d0e..6904402 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java
@@ -10,7 +10,6 @@ import android.text.TextUtils;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.StringUtils;
-import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.db.DBAccess;
/**
@@ -162,6 +161,10 @@ public class Preferences {
return getCurrentVdr().getStreamingPassword();
}
+ public String getIp46Mode() {
+ return getCurrentVdr().getIp46Mode();
+ }
+
/**
* Properties singleton
*/
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java
index 619bb9e..ad53fd5 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java
@@ -201,6 +201,9 @@ public class Vdr {
@DatabaseField(columnName="enableRemote")
private boolean enableRemote = true;
+
+ @DatabaseField(columnName="ip46Mode")
+ private String ip46Mode = "ip4";
public String getServerTimeZone() {
return serverTimeZone;
@@ -498,6 +501,14 @@ public class Vdr {
this.timeout = timeout;
}
+ public String getIp46Mode() {
+ return ip46Mode;
+ }
+
+ public void setIp46Mode(final String ip46Mode) {
+ this.ip46Mode = ip46Mode;
+ }
+
private static <T> T get(Map<String, Object> map, String key) {
return get(map, key, null);
}
@@ -566,6 +577,7 @@ public class Vdr {
map.put("vdr_port", port);
map.put("vdr_password", password);
map.put("vdr_secure", secure);
+ map.put("vdr_ip46_mode", ip46Mode);
map.put("limit_channels", filterChannels);
map.put("last_channel", channelFilter);
@@ -611,47 +623,6 @@ public class Vdr {
public void set(Map<String, Object> map) {
init(map);
-/*
- name = get(map, "vdr_name");
- host = get(map, "vdr_host");
- port = getInteger(map, "vdr_port");
- password = get(map, "vdr_password");
- secure = getBoolean(map, "vdr_secure");
-
- filterChannels = getBoolean(map, "limit_channels");
- channelFilter = get(map, "last_channel");
-
- wakeupEnabled = getBoolean(map, "key_wakeup_enabled");
- wakeupUrl = get(map, "key_wakeup_url");
- wakeupUser = get(map, "key_wakeup_user");
- wakeupPassword = get(map, "key_wakeup_password");
- wakeupMethod = get(map, "key_wakeup_method");
- wolCustomBroadcast = get(map, "key_wol_custom_broadcast");
- mac = get(map, "key_wakeup_wol_mac");
-
- connectionTimeout = getInteger(map, "key_conntimeout_key");
- readTimeout = getInteger(map, "key_vdr_readtimeout");
- timeout = getInteger(map, "key_vdr_timeout");
-
- timerPreMargin = getInteger(map, "timer_pre_start_buffer"
- );
- timerPostMargin = getInteger(map, "timer_post_end_buffer");
- timerDefaultPriority = getInteger(map, "timer_default_priority");
- timerDefaultLifetime = getInteger(map, "timer_default_lifetime");
-
- streamPort = getInteger(map, "streamingport");
- streamingPassword = get(map, "key_streaming_password");
- streamingUsername = get(map, "key_streaming_username");
- encoding = get(map, "key_vdr_encoding");
- streamFormat = get(map, "livetv_streamformat");
- remuxCommand = get(map, "remux_command");
- remuxParameter = get(map, "remux_parameter");
- enableRemux = getBoolean(map, "remux_enable");
-
- enableRecStreaming = getBoolean(map, "key_rec_stream_enable");
- livePort = getInteger(map, "key_live_port");
- recStreamMethod = get(map, "key_recstream_method");
- */
}
public void init(Map<String, Object> map) {
@@ -660,6 +631,7 @@ public class Vdr {
port = getInteger(map, "vdr_port", 6420);
password = get(map, "vdr_password", "");
secure = getBoolean(map, "vdr_secure");
+ ip46Mode = get(map, "vdr_ip46_mode");
filterChannels = getBoolean(map, "limit_channels", true);
channelFilter = get(map, "last_channel", "");
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java
index 0e529dc..a8305d9 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java
@@ -32,7 +32,7 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
// any time you make changes to your database objects, you may have to
// increase the database version
// Version 3 since 0.6
- private static final int DATABASE_VERSION = 6;
+ private static final int DATABASE_VERSION = 7;
private RuntimeExceptionDao<Vdr, Integer> vdrDAO = null;
@@ -130,6 +130,10 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
getVdrDAO().executeRaw("ALTER TABLE `vdr` ADD COLUMN svdrpHost varchar");
}
+ if (oldVersion < 7) {
+ getVdrDAO().executeRaw("ALTER TABLE `vdr` ADD COLUMN ip46Mode varchar");
+ }
+
} catch (SQLException e) {
Log.e(DBAccess.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
index 31fa0f4..f415d3a 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
@@ -1,13 +1,17 @@
package de.bjusystems.vdrmanager.utils.svdrp;
+import android.util.Log;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
-import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -16,9 +20,6 @@ import java.util.TimerTask;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;
-import android.content.Context;
-import android.sax.StartElementListener;
-import android.util.Log;
import de.bjusystems.vdrmanager.app.C;
import de.bjusystems.vdrmanager.data.Preferences;
@@ -224,20 +225,69 @@ public abstract class SvdrpClient<Result> {
// connect
informListener(SvdrpEvent.CONNECTING);
- if (prefs.isSecure()) {
- socket = new MySSLSocketFactory(false,
- certificateProblemListener).createSocket();
- } else {
- socket = new Socket();
+ InetAddress ip4address = null;
+ InetAddress ip6address = null;
+
+ final InetAddress[] addresses = InetAddress.getAllByName(prefs.getHost());
+ for (final InetAddress address : addresses) {
+ if (address instanceof Inet4Address) {
+ ip4address = address;
+ } else if (address instanceof Inet6Address) {
+ ip6address = address;
+ }
}
- socket.connect(
- new InetSocketAddress(prefs.getHost(), prefs
- .getPort()),
- prefs.getConnectionTimeout() * 1000);// 8 secs for connect
- if (abort) {
- informListener(SvdrpEvent.ABORTED);
+ List<InetAddress> addressToTry = new ArrayList<>();
+
+ switch (prefs.getIp46Mode()) {
+ case "ip4":
+ addressToTry.add(ip4address);
+ break;
+ case "ip6":
+ addressToTry.add(ip6address);
+ break;
+ case "ip46":
+ addressToTry.add(ip4address);
+ addressToTry.add(ip6address);
+ break;
+ case "ip64":
+ addressToTry.add(ip6address);
+ addressToTry.add(ip4address);
+ break;
}
+
+ Exception exception = null;
+ for (final InetAddress inetAddress : addressToTry) {
+ if (inetAddress == null) {
+ continue;
+ }
+ if (abort) {
+ break;
+ }
+
+ try {
+ initSocket(prefs);
+ socket.connect(new InetSocketAddress(
+ inetAddress,
+ prefs.getPort()),
+ prefs.getConnectionTimeout() * 1000);
+ break;
+ } catch (Exception e) {
+ socket.close();
+ Log.w(TAG, "Couldn't connect to " + inetAddress.getHostAddress());
+ exception = e;
+ }
+ }
+
+ if (!socket.isConnected()) {
+ if (abort) {
+ informListener(SvdrpEvent.ABORTED);
+ } else {
+ informListener(SvdrpEvent.CONNECT_ERROR);
+ }
+ return false;
+ }
+
//
socket.setSoTimeout(prefs.getReadTimeout() * 1000);// 15 sec for
// each read
@@ -261,14 +311,6 @@ public abstract class SvdrpClient<Result> {
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
- } catch (final SocketTimeoutException sote) {
- Log.w(TAG, sote);
- if (abort) {
- informListener(SvdrpEvent.ABORTED);
- } else {
- informListener(SvdrpEvent.CONNECTION_TIMEOUT);
- }
- return false;
} catch (final Exception e) {
Log.w(TAG, e);
@@ -293,6 +335,18 @@ public abstract class SvdrpClient<Result> {
return true;
}
+ private void initSocket(final Preferences prefs) throws Exception {
+ if (socket != null) {
+ socket.close();
+ }
+ if (prefs.isSecure()) {
+ socket = new MySSLSocketFactory(false,
+ certificateProblemListener).createSocket();
+ } else {
+ socket = new Socket();
+ }
+ }
+
/**
* Disconnect from SVDRP if connected
*
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
index 0b99b04..12a1f3e 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
@@ -6,8 +6,6 @@ import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
-import java.io.IOException;
-
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Preferences;
import de.bjusystems.vdrmanager.utils.http.HttpHelper;
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml
index 0ae6b80..7a7d365 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml
@@ -137,6 +137,8 @@ herrlado&lt;herrlado@gmail.com&gt;</string>
<string name="vdr_password_summary">Passwort für das VDR Plugin</string>
<string name="vdr_ssl_title">Sichere Verbindung</string>
<string name="vdr_ssl_summary">Verwende SSL für Verbindungen (aktuell nicht implementiert)</string>
+ <string name="vdr_ip46_mode_title">IPv4/6 Auswahl</string>
+ <string name="vdr_ip46_mode_summary">IPv4/6 Auswahl-Modus</string>
<!-- channel filter preferences -->
<string name="channel_filter_preferences">Kanaleinstellungen</string>
<string name="channel_filter_filter_title">Begrenze Kanäle</string>
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml
index c0398bd..d53afcb 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml
@@ -46,8 +46,12 @@
<item>has</item>
<item>hls</item>
</array>
-
-
+ <string-array name="vdr_ip46_mode_values">
+ <item>ip4</item>
+ <item>ip6</item>
+ <item>ip46</item>
+ <item>ip64</item>
+ </string-array>
</resources> \ No newline at end of file
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml
index 5176908..3a21c46 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml
@@ -148,6 +148,15 @@
<string name="vdr_password_summary">Password for the VDR plugin</string>
<string name="vdr_ssl_title">Secure connect</string>
<string name="vdr_ssl_summary">Use SSL for connections</string>
+ <string name="vdr_ip46_mode_title">IPv4/6 selection</string>
+ <string name="vdr_ip46_mode_summary">IPv4/6 selection mode</string>
+
+ <string-array name="vdr_ip46_mode">
+ <item>Use only IPv4</item>
+ <item>Use only IPv6</item>
+ <item>Prefer IPv4 over IPv6</item>
+ <item>Prefer IPv6 over IPv4</item>
+ </string-array>
<!-- channel filter preferences -->
<string name="channel_filter_preferences">Channel settings</string>
diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml
index efd13f8..b221b3f 100644
--- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml
+++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml
@@ -32,6 +32,15 @@
android:enabled="true"
android:summary="@string/vdr_ssl_summary"
android:title="@string/vdr_ssl_title" />
+
+ <ListPreference
+ android:entries="@array/vdr_ip46_mode"
+ android:entryValues="@array/vdr_ip46_mode_values"
+ android:defaultValue="ip4_only"
+ android:key="vdr_ip46_mode"
+ android:title="@string/vdr_ip46_mode_title"
+ android:summary="@string/vdr_ip46_mode_summary"/>
+
</PreferenceCategory>
<PreferenceCategory
android:key="filter_preferences"