blob: 3c45b9e132c02fb766396508bc8b440a7007a099 [file] [log] [blame]
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04001/**
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
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 Lision064e1e02013-10-01 16:18:42 -040027import org.sflphone.R;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040028
Alexandre Lision4f906b22013-10-02 10:13:45 -040029import android.util.Log;
30
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040031public class AccountDetailTls implements AccountDetail {
Alexandre Savard68838112012-10-30 11:34:43 -040032
33 private static final String TAG = "AccountDetailTls";
34 public static final String BUNDLE_TAG = "TlsPreferenceArrayList";
Alexandre Lision8ad39592013-11-21 13:23:58 -050035
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040036 public static final String CONFIG_TLS_LISTENER_PORT = "TLS.listenerPort";
37 public static final String CONFIG_TLS_ENABLE = "TLS.enable";
38 public static final String CONFIG_TLS_CA_LIST_FILE = "TLS.certificateListFile";
39 public static final String CONFIG_TLS_CERTIFICATE_FILE = "TLS.certificateFile";
40 public static final String CONFIG_TLS_PRIVATE_KEY_FILE = "TLS.privateKeyFile";
41 public static final String CONFIG_TLS_PASSWORD = "TLS.password";
42 public static final String CONFIG_TLS_METHOD = "TLS.method";
43 public static final String CONFIG_TLS_CIPHERS = "TLS.ciphers";
44 public static final String CONFIG_TLS_SERVER_NAME = "TLS.serverName";
45 public static final String CONFIG_TLS_VERIFY_SERVER = "TLS.verifyServer";
46 public static final String CONFIG_TLS_VERIFY_CLIENT = "TLS.verifyClient";
47 public static final String CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE = "TLS.requireClientCertificate";
48 public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC = "TLS.negotiationTimeoutSec";
49 public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC = "TLS.negotiationTimemoutMsec";
Alexandre Lision8ad39592013-11-21 13:23:58 -050050
Alexandre Savard68838112012-10-30 11:34:43 -040051 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040052
Alexandre Lision8ad39592013-11-21 13:23:58 -050053 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040054 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
55
56 preference.add(new PreferenceEntry(CONFIG_TLS_LISTENER_PORT, R.string.account_listener_port_label));
57 preference.add(new PreferenceEntry(CONFIG_TLS_ENABLE, R.string.account_tls_enabled_label, true));
58 preference.add(new PreferenceEntry(CONFIG_TLS_CA_LIST_FILE, R.string.account_tls_certificate_list_label));
59 preference.add(new PreferenceEntry(CONFIG_TLS_CERTIFICATE_FILE, R.string.account_tls_certificate_file_label));
60 preference.add(new PreferenceEntry(CONFIG_TLS_PRIVATE_KEY_FILE, R.string.account_tls_private_key_file_label));
61 preference.add(new PreferenceEntry(CONFIG_TLS_PASSWORD, R.string.account_tls_password_label));
62 preference.add(new PreferenceEntry(CONFIG_TLS_METHOD, R.string.account_tls_method_label));
63 preference.add(new PreferenceEntry(CONFIG_TLS_CIPHERS, R.string.account_tls_ciphers_label));
64 preference.add(new PreferenceEntry(CONFIG_TLS_SERVER_NAME, R.string.account_tls_server_name_label));
65 preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_SERVER, R.string.account_tls_verify_label, true));
66 preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_CLIENT, R.string.account_tls_verify_client_label, true));
67 preference.add(new PreferenceEntry(CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, R.string.account_tls_require_client_certificat_label, true));
68 preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, R.string.account_tls_negotiation_timeout_sec));
69 preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC, R.string.account_tls_negotiation_timeout_msec));
70
71 return preference;
72 }
73
Alexandre Lision8ad39592013-11-21 13:23:58 -050074 public AccountDetailTls() {
Alexandre Savard68838112012-10-30 11:34:43 -040075 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040076 }
77
Alexandre Lision8ad39592013-11-21 13:23:58 -050078 public AccountDetailTls(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040079 privateArray = getPreferenceEntries();
80
Alexandre Lision8ad39592013-11-21 13:23:58 -050081 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040082 p.mValue = pref.get(p.mKey);
83 }
84 }
85
Alexandre Lision8ad39592013-11-21 13:23:58 -050086 public AccountDetailTls(ArrayList<String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040087 privateArray = getPreferenceEntries();
88
Alexandre Lision8ad39592013-11-21 13:23:58 -050089 if (pref.size() != privateArray.size()) {
Alexandre Savard68838112012-10-30 11:34:43 -040090 Log.i(TAG, "Error list are not of equal size");
Alexandre Lision8ad39592013-11-21 13:23:58 -050091 } else {
Alexandre Savard68838112012-10-30 11:34:43 -040092 int index = 0;
Alexandre Lision8ad39592013-11-21 13:23:58 -050093 for (String s : pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040094 privateArray.get(index).mValue = s;
95 index++;
96 }
97 }
98 }
99
Alexandre Lision8ad39592013-11-21 13:23:58 -0500100 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -0400101 return privateArray;
102 }
103
Alexandre Lision8ad39592013-11-21 13:23:58 -0500104 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -0400105 ArrayList<String> valueList = new ArrayList<String>();
106
Alexandre Lision8ad39592013-11-21 13:23:58 -0500107 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -0400108 valueList.add(p.mValue);
109 }
110
111 return valueList;
112 }
113
Alexandre Lision8ad39592013-11-21 13:23:58 -0500114 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400115 HashMap<String, String> map = new HashMap<String, String>();
116
Alexandre Lision8ad39592013-11-21 13:23:58 -0500117 for (AccountDetail.PreferenceEntry p : privateArray) {
118 if (p.mValue == null) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400119 map.put(p.mKey, "");
120 } else {
121 map.put(p.mKey, p.mValue);
122 }
Alexandre Savard833616f2012-10-30 16:02:30 -0400123 }
124
125 return map;
126 }
127
Alexandre Lision8ad39592013-11-21 13:23:58 -0500128 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400129 String value = "";
130
Alexandre Lision8ad39592013-11-21 13:23:58 -0500131 for (AccountDetail.PreferenceEntry p : privateArray) {
132 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400133 value = p.mValue;
134 return value;
135 }
136 }
137
138 return value;
139 }
140
Alexandre Lision8ad39592013-11-21 13:23:58 -0500141 public void setDetailString(String key, String newValue) {
142 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400143 PreferenceEntry p = privateArray.get(i);
Alexandre Lision8ad39592013-11-21 13:23:58 -0500144 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400145 privateArray.get(i).mValue = newValue;
146 }
147 }
Alexandre Lision8ad39592013-11-21 13:23:58 -0500148
Alexandre Savard833616f2012-10-30 16:02:30 -0400149 }
150
Alexandre Lision8ad39592013-11-21 13:23:58 -0500151 public boolean getDetailBoolean(String key) {
152 for (AccountDetail.PreferenceEntry p : privateArray) {
153 if (p.mKey.equals(key)) {
154 return p.mValue.contentEquals("true");
155 }
156 }
157 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400158 }
159}