9
9
import java .util .List ;
10
10
import java .util .Locale ;
11
11
12
+ import com .limelight .LimeLog ;
12
13
import com .limelight .nvstream .http .ComputerDetails ;
14
+ import com .limelight .nvstream .http .LimelightCryptoProvider ;
13
15
import com .limelight .nvstream .http .NvHTTP ;
14
16
15
17
import android .content .ContentValues ;
18
20
import android .database .sqlite .SQLiteDatabase ;
19
21
import android .database .sqlite .SQLiteException ;
20
22
23
+ import org .json .JSONArray ;
24
+ import org .json .JSONException ;
25
+ import org .json .JSONObject ;
26
+
21
27
public class ComputerDatabaseManager {
22
28
private static final String COMPUTER_DB_NAME = "computers3.db" ;
23
29
private static final String COMPUTER_TABLE_NAME = "Computers" ;
@@ -27,9 +33,6 @@ public class ComputerDatabaseManager {
27
33
private static final String MAC_ADDRESS_COLUMN_NAME = "MacAddress" ;
28
34
private static final String SERVER_CERT_COLUMN_NAME = "ServerCert" ;
29
35
30
- private static final char ADDRESS_DELIMITER = ';' ;
31
- private static final char PORT_DELIMITER = '_' ;
32
-
33
36
private SQLiteDatabase computerDb ;
34
37
35
38
public ComputerDatabaseManager (Context c ) {
@@ -75,13 +78,17 @@ public boolean updateComputer(ComputerDetails details) {
75
78
values .put (COMPUTER_UUID_COLUMN_NAME , details .uuid );
76
79
values .put (COMPUTER_NAME_COLUMN_NAME , details .name );
77
80
78
- StringBuilder addresses = new StringBuilder ();
79
- addresses .append (details .localAddress != null ? splitTupleToAddress (details .localAddress ) : "" );
80
- addresses .append (ADDRESS_DELIMITER ).append (details .remoteAddress != null ? splitTupleToAddress (details .remoteAddress ) : "" );
81
- addresses .append (ADDRESS_DELIMITER ).append (details .manualAddress != null ? splitTupleToAddress (details .manualAddress ) : "" );
82
- addresses .append (ADDRESS_DELIMITER ).append (details .ipv6Address != null ? splitTupleToAddress (details .ipv6Address ) : "" );
81
+ try {
82
+ JSONObject addresses = new JSONObject ();
83
+ addresses .put ("local" , ComputerDetails .AddressTuple .toJson ((details .localAddress )));
84
+ addresses .put ("remote" , ComputerDetails .AddressTuple .toJson ((details .remoteAddress )));
85
+ addresses .put ("manual" , ComputerDetails .AddressTuple .toJson ((details .manualAddress )));
86
+ addresses .put ("ipv6" , ComputerDetails .AddressTuple .toJson ((details .ipv6Address )));
87
+ values .put (ADDRESSES_COLUMN_NAME , addresses .toString ());
88
+ } catch (JSONException e ) {
89
+ LimeLog .warning ("JSON error, failed to write computer address information, " + e .getMessage ());
90
+ }
83
91
84
- values .put (ADDRESSES_COLUMN_NAME , addresses .toString ());
85
92
values .put (MAC_ADDRESS_COLUMN_NAME , details .macAddress );
86
93
try {
87
94
if (details .serverCert != null ) {
@@ -105,36 +112,20 @@ private static String readNonEmptyString(String input) {
105
112
return input ;
106
113
}
107
114
108
- private static ComputerDetails .AddressTuple splitAddressToTuple (String input ) {
109
- if (input == null ) {
110
- return null ;
111
- }
112
-
113
- String [] parts = input .split ("" +PORT_DELIMITER , -1 );
114
- if (parts .length == 1 ) {
115
- return new ComputerDetails .AddressTuple (parts [0 ], NvHTTP .DEFAULT_HTTP_PORT );
116
- }
117
- else {
118
- return new ComputerDetails .AddressTuple (parts [0 ], Integer .parseInt (parts [1 ]));
119
- }
120
- }
121
-
122
- private static String splitTupleToAddress (ComputerDetails .AddressTuple tuple ) {
123
- return tuple .address +PORT_DELIMITER +tuple .port ;
124
- }
125
-
126
115
private ComputerDetails getComputerFromCursor (Cursor c ) {
127
116
ComputerDetails details = new ComputerDetails ();
128
117
129
118
details .uuid = c .getString (0 );
130
119
details .name = c .getString (1 );
131
-
132
- String [] addresses = c .getString (2 ).split ("" +ADDRESS_DELIMITER , -1 );
133
-
134
- details .localAddress = splitAddressToTuple (readNonEmptyString (addresses [0 ]));
135
- details .remoteAddress = splitAddressToTuple (readNonEmptyString (addresses [1 ]));
136
- details .manualAddress = splitAddressToTuple (readNonEmptyString (addresses [2 ]));
137
- details .ipv6Address = splitAddressToTuple (readNonEmptyString (addresses [3 ]));
120
+ try {
121
+ JSONObject addresses = new JSONObject (c .getString (2 ));
122
+ details .localAddress = ComputerDetails .AddressTuple .fromJson (addresses .getJSONObject ("local" ));
123
+ details .remoteAddress = ComputerDetails .AddressTuple .fromJson (addresses .getJSONObject ("remote" ));
124
+ details .manualAddress = ComputerDetails .AddressTuple .fromJson (addresses .getJSONObject ("manual" ));
125
+ details .ipv6Address = ComputerDetails .AddressTuple .fromJson (addresses .getJSONObject ("ipv6" ));
126
+ } catch (JSONException e ) {
127
+ LimeLog .warning ("JSON error, failed to read computer address information, " + e .getMessage ());
128
+ }
138
129
139
130
// External port is persisted in the remote address field
140
131
if (details .remoteAddress != null ) {
0 commit comments