Commit 8d321f6c authored by Daniel Wolf's avatar Daniel Wolf

Added new Entity DNSTLSConfiguration

parent 74ce4155
package com.frostnerd.dnschanger.database;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
......@@ -10,11 +9,13 @@ import com.frostnerd.dnschanger.database.entities.DNSEntry;
import com.frostnerd.dnschanger.database.entities.DNSQuery;
import com.frostnerd.dnschanger.database.entities.DNSRule;
import com.frostnerd.dnschanger.database.entities.DNSRuleImport;
import com.frostnerd.dnschanger.database.entities.DNSTLSConfiguration;
import com.frostnerd.dnschanger.database.entities.IPPortPair;
import com.frostnerd.dnschanger.database.entities.Shortcut;
import com.frostnerd.utils.database.CursorWithDefaults;
import com.frostnerd.utils.database.orm.Entity;
import com.frostnerd.utils.database.orm.parser.ParsedEntity;
import com.frostnerd.utils.database.orm.parser.statementbuilder.tablemodification.AlterTableBuilder;
import com.frostnerd.utils.database.orm.statementoptions.queryoptions.WhereCondition;
import com.frostnerd.utils.general.Utils;
......@@ -31,7 +32,7 @@ import java.util.Set;
*/
public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper {
public static final String DATABASE_NAME = "data";
public static final int DATABASE_VERSION = 3;
public static final int DATABASE_VERSION = 4;
@NonNull
public static final Set<Class<? extends Entity>> entities = new HashSet<Class<? extends Entity>>(){{
add(DNSEntry.class);
......@@ -40,6 +41,7 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
add(DNSRuleImport.class);
add(IPPortPair.class);
add(Shortcut.class);
add(DNSTLSConfiguration.class);
}};
@Nullable
private static DatabaseHelper instance;
......@@ -71,6 +73,7 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
@Override
public void onBeforeUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
System.out.println("Updating from " + oldVersion + " to " + newVersion);
if(oldVersion <= 1){
List<Shortcut> shortcuts = new ArrayList<>();
List<DNSEntry> entries = new ArrayList<>();
......@@ -113,6 +116,13 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
onCreate(db);
for(DNSEntry entry: entries) insert(entry);
for(Shortcut shortcut: shortcuts) createShortcut(shortcut);
}else if(oldVersion <= 3) {
getSQLHandler(DNSTLSConfiguration.class).createTable(db);
AlterTableBuilder builder = new AlterTableBuilder(getTableName(DNSEntry.class));
findColumn(DNSEntry.class, "tlsconfig").createColumnStructure(builder);
for(String s: builder.getStatements()){
db.execSQL(s);
}
}
}
......
......@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
import com.frostnerd.dnschanger.database.serializers.IPPortSerializer;
import com.frostnerd.utils.database.orm.MultitonEntity;
import com.frostnerd.utils.database.orm.annotations.Default;
import com.frostnerd.utils.database.orm.annotations.Named;
import com.frostnerd.utils.database.orm.annotations.NotNull;
import com.frostnerd.utils.database.orm.annotations.RowID;
......@@ -55,6 +56,10 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
@Named(name = "customentry")
private boolean customEntry;
@Nullable
@Named(name = "tlsconfig")
private DNSTLSConfiguration dnsTLSConfiguration;
@Named(name = "id")
@RowID
private long ID;
......@@ -218,6 +223,19 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
return !(ip == null || ip.equals("")) && (entryAddressMatches(ip, dns1) || entryAddressMatches(ip, dns2) || entryAddressMatches(ip, dns1V6) || entryAddressMatches(ip, dns2V6));
}
public boolean supportsDNSOverTLS(){
return dnsTLSConfiguration != null;
}
@Nullable
public DNSTLSConfiguration getDnsTLSConfiguration() {
return dnsTLSConfiguration;
}
public void setDnsTLSConfiguration(@Nullable DNSTLSConfiguration dnsTLSConfiguration) {
this.dnsTLSConfiguration = dnsTLSConfiguration;
}
@Override
public String toString() {
return "DNSEntry{" +
......
package com.frostnerd.dnschanger.database.entities;
import com.frostnerd.utils.database.orm.MultitonEntity;
import com.frostnerd.utils.database.orm.annotations.Named;
import com.frostnerd.utils.database.orm.annotations.RowID;
import com.frostnerd.utils.database.orm.annotations.Table;
import lombok.NoArgsConstructor;
/**
* Copyright Daniel Wolf 2017
* All rights reserved.
* Code may NOT be used without proper permission, neither in binary nor in source form.
* All redistributions of this software in source code must retain this copyright header
* All redistributions of this software in binary form must visibly inform users about usage of this software
* <p>
* development@frostnerd.com
*/
@NoArgsConstructor
@Table(name = "DNSTLSConfiguration")
public class DNSTLSConfiguration extends MultitonEntity {
@Named(name = "id")
@RowID
private long ID;
@Named(name = "port")
private int port;
@Named(name = "host")
private String hostName;
public DNSTLSConfiguration(int port, String hostName) {
this.port = port;
this.hostName = hostName;
}
public int getPort() {
return port;
}
public long getID() {
return ID;
}
public String getHostName() {
return hostName;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment