Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
| 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 22 | package org.sflphone.account; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 23 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 26 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 27 | import org.sflphone.R; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 28 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 31 | public class AccountDetailTls implements AccountDetail { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 32 | |
| 33 | private static final String TAG = "AccountDetailTls"; |
| 34 | public static final String BUNDLE_TAG = "TlsPreferenceArrayList"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 35 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 36 | 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"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 50 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 51 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 52 | |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 53 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() |
| 54 | { |
| 55 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 56 | |
| 57 | preference.add(new PreferenceEntry(CONFIG_TLS_LISTENER_PORT, R.string.account_listener_port_label)); |
| 58 | preference.add(new PreferenceEntry(CONFIG_TLS_ENABLE, R.string.account_tls_enabled_label, true)); |
| 59 | preference.add(new PreferenceEntry(CONFIG_TLS_CA_LIST_FILE, R.string.account_tls_certificate_list_label)); |
| 60 | preference.add(new PreferenceEntry(CONFIG_TLS_CERTIFICATE_FILE, R.string.account_tls_certificate_file_label)); |
| 61 | preference.add(new PreferenceEntry(CONFIG_TLS_PRIVATE_KEY_FILE, R.string.account_tls_private_key_file_label)); |
| 62 | preference.add(new PreferenceEntry(CONFIG_TLS_PASSWORD, R.string.account_tls_password_label)); |
| 63 | preference.add(new PreferenceEntry(CONFIG_TLS_METHOD, R.string.account_tls_method_label)); |
| 64 | preference.add(new PreferenceEntry(CONFIG_TLS_CIPHERS, R.string.account_tls_ciphers_label)); |
| 65 | preference.add(new PreferenceEntry(CONFIG_TLS_SERVER_NAME, R.string.account_tls_server_name_label)); |
| 66 | preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_SERVER, R.string.account_tls_verify_label, true)); |
| 67 | preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_CLIENT, R.string.account_tls_verify_client_label, true)); |
| 68 | preference.add(new PreferenceEntry(CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, R.string.account_tls_require_client_certificat_label, true)); |
| 69 | preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, R.string.account_tls_negotiation_timeout_sec)); |
| 70 | preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC, R.string.account_tls_negotiation_timeout_msec)); |
| 71 | |
| 72 | return preference; |
| 73 | } |
| 74 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 75 | public AccountDetailTls() |
| 76 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 77 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 78 | } |
| 79 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 80 | public AccountDetailTls(HashMap<String, String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 81 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 82 | privateArray = getPreferenceEntries(); |
| 83 | |
| 84 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 85 | p.mValue = pref.get(p.mKey); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public AccountDetailTls(ArrayList<String> pref) |
| 90 | { |
| 91 | privateArray = getPreferenceEntries(); |
| 92 | |
| 93 | if(pref.size() != privateArray.size()) { |
| 94 | Log.i(TAG, "Error list are not of equal size"); |
| 95 | } |
| 96 | else { |
| 97 | int index = 0; |
| 98 | for(String s : pref) { |
| 99 | privateArray.get(index).mValue = s; |
| 100 | index++; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() |
| 106 | { |
| 107 | return privateArray; |
| 108 | } |
| 109 | |
| 110 | public ArrayList<String> getValuesOnly() |
| 111 | { |
| 112 | ArrayList<String> valueList = new ArrayList<String>(); |
| 113 | |
| 114 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 115 | valueList.add(p.mValue); |
| 116 | } |
| 117 | |
| 118 | return valueList; |
| 119 | } |
| 120 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 121 | public HashMap<String, String> getDetailsHashMap() |
| 122 | { |
| 123 | HashMap<String, String> map = new HashMap<String, String>(); |
| 124 | |
| 125 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 126 | map.put(p.mKey, p.mValue); |
| 127 | } |
| 128 | |
| 129 | return map; |
| 130 | } |
| 131 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 132 | public String getDetailString(String key) |
| 133 | { |
| 134 | String value = ""; |
| 135 | |
| 136 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 137 | if(p.mKey.equals(key)) { |
| 138 | value = p.mValue; |
| 139 | return value; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return value; |
| 144 | } |
| 145 | |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 146 | public void setDetailString(String key, String newValue) |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 147 | { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 148 | for(int i = 0 ; i < privateArray.size() ; ++i) { |
| 149 | PreferenceEntry p = privateArray.get(i); |
| 150 | if(p.mKey.equals(key)) { |
| 151 | privateArray.get(i).mValue = newValue; |
| 152 | } |
| 153 | } |
| 154 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 157 | public boolean getDetailBoolean() |
| 158 | { |
| 159 | return true; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 160 | } |
| 161 | } |