blob: dbc0e0eec81ff99f5113d3a176a09be28e45162c [file] [log] [blame]
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04001/**
Alexandre Lisionfed2a642014-01-10 12:05:47 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04003 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * If you own a pjsip commercial license you can also redistribute it
11 * and/or modify it under the terms of the GNU Lesser General Public License
12 * as an android library.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040022package org.sflphone.account;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040023
alision5cfc35d2013-07-11 15:11:39 -040024import java.util.ArrayList;
25import java.util.HashMap;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040026
Alexandre Lision4f906b22013-10-02 10:13:45 -040027import android.util.Log;
28
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040029public class AccountDetailTls implements AccountDetail {
Alexandre Savard68838112012-10-30 11:34:43 -040030
31 private static final String TAG = "AccountDetailTls";
32 public static final String BUNDLE_TAG = "TlsPreferenceArrayList";
Alexandre Lision8ad39592013-11-21 13:23:58 -050033
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040034 public static final String CONFIG_TLS_LISTENER_PORT = "TLS.listenerPort";
35 public static final String CONFIG_TLS_ENABLE = "TLS.enable";
36 public static final String CONFIG_TLS_CA_LIST_FILE = "TLS.certificateListFile";
37 public static final String CONFIG_TLS_CERTIFICATE_FILE = "TLS.certificateFile";
38 public static final String CONFIG_TLS_PRIVATE_KEY_FILE = "TLS.privateKeyFile";
39 public static final String CONFIG_TLS_PASSWORD = "TLS.password";
40 public static final String CONFIG_TLS_METHOD = "TLS.method";
41 public static final String CONFIG_TLS_CIPHERS = "TLS.ciphers";
42 public static final String CONFIG_TLS_SERVER_NAME = "TLS.serverName";
43 public static final String CONFIG_TLS_VERIFY_SERVER = "TLS.verifyServer";
44 public static final String CONFIG_TLS_VERIFY_CLIENT = "TLS.verifyClient";
45 public static final String CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE = "TLS.requireClientCertificate";
46 public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC = "TLS.negotiationTimeoutSec";
47 public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC = "TLS.negotiationTimemoutMsec";
Alexandre Lision8ad39592013-11-21 13:23:58 -050048
Alexandre Savard68838112012-10-30 11:34:43 -040049 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040050
Alexandre Lision8ad39592013-11-21 13:23:58 -050051 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040052 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
53
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050054 preference.add(new PreferenceEntry(CONFIG_TLS_LISTENER_PORT));
55 preference.add(new PreferenceEntry(CONFIG_TLS_ENABLE, true));
56 preference.add(new PreferenceEntry(CONFIG_TLS_CA_LIST_FILE));
57 preference.add(new PreferenceEntry(CONFIG_TLS_CERTIFICATE_FILE));
58 preference.add(new PreferenceEntry(CONFIG_TLS_PRIVATE_KEY_FILE));
59 preference.add(new PreferenceEntry(CONFIG_TLS_PASSWORD));
60 preference.add(new PreferenceEntry(CONFIG_TLS_METHOD));
61 preference.add(new PreferenceEntry(CONFIG_TLS_CIPHERS));
62 preference.add(new PreferenceEntry(CONFIG_TLS_SERVER_NAME));
63 preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_SERVER));
64 preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_CLIENT, true));
65 preference.add(new PreferenceEntry(CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, true));
66 preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC));
67 preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC));
Alexandre Savardae992932012-10-17 10:26:12 -040068
69 return preference;
70 }
71
Alexandre Lision8ad39592013-11-21 13:23:58 -050072 public AccountDetailTls(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040073 privateArray = getPreferenceEntries();
74
Alexandre Lision8ad39592013-11-21 13:23:58 -050075 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040076 p.mValue = pref.get(p.mKey);
77 }
78 }
79
Alexandre Lision8ad39592013-11-21 13:23:58 -050080 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -040081 return privateArray;
82 }
83
Alexandre Lision8ad39592013-11-21 13:23:58 -050084 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -040085 ArrayList<String> valueList = new ArrayList<String>();
86
Alexandre Lision8ad39592013-11-21 13:23:58 -050087 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040088 valueList.add(p.mValue);
89 }
90
91 return valueList;
92 }
93
Alexandre Lision8ad39592013-11-21 13:23:58 -050094 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -040095 HashMap<String, String> map = new HashMap<String, String>();
96
Alexandre Lision8ad39592013-11-21 13:23:58 -050097 for (AccountDetail.PreferenceEntry p : privateArray) {
98 if (p.mValue == null) {
Alexandre Lision059da9d2013-10-22 11:17:25 -040099 map.put(p.mKey, "");
100 } else {
101 map.put(p.mKey, p.mValue);
102 }
Alexandre Savard833616f2012-10-30 16:02:30 -0400103 }
104
105 return map;
106 }
107
Alexandre Lision8ad39592013-11-21 13:23:58 -0500108 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400109 String value = "";
110
Alexandre Lision8ad39592013-11-21 13:23:58 -0500111 for (AccountDetail.PreferenceEntry p : privateArray) {
112 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400113 value = p.mValue;
114 return value;
115 }
116 }
117
118 return value;
119 }
120
Alexandre Lision8ad39592013-11-21 13:23:58 -0500121 public void setDetailString(String key, String newValue) {
122 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400123 PreferenceEntry p = privateArray.get(i);
Alexandre Lision8ad39592013-11-21 13:23:58 -0500124 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400125 privateArray.get(i).mValue = newValue;
126 }
127 }
Alexandre Lision8ad39592013-11-21 13:23:58 -0500128
Alexandre Savard833616f2012-10-30 16:02:30 -0400129 }
130
Alexandre Lision8ad39592013-11-21 13:23:58 -0500131 public boolean getDetailBoolean(String key) {
132 for (AccountDetail.PreferenceEntry p : privateArray) {
133 if (p.mKey.equals(key)) {
134 return p.mValue.contentEquals("true");
135 }
136 }
137 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400138 }
139}