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