Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@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 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 32 | package org.sflphone.utils; |
| 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.HashMap; |
| 36 | import java.util.List; |
| 37 | import java.util.Set; |
| 38 | |
| 39 | import org.sflphone.account.AccountDetailAdvanced; |
| 40 | import org.sflphone.account.AccountDetailBasic; |
| 41 | import org.sflphone.account.AccountDetailSrtp; |
| 42 | import org.sflphone.account.AccountDetailTls; |
| 43 | import org.sflphone.service.ServiceConstants; |
| 44 | import org.sflphone.service.StringMap; |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 45 | import org.sflphone.service.StringVect; |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 46 | import org.sflphone.service.VectMap; |
| 47 | |
| 48 | public class SwigNativeConverter { |
| 49 | |
| 50 | /** |
| 51 | * Native to Swig |
| 52 | */ |
| 53 | |
| 54 | public static StringMap convertFromNativeToSwig(HashMap<String, String> nativemap) { |
| 55 | StringMap swigmap = new StringMap(); |
| 56 | |
| 57 | Set<String> keys = nativemap.keySet(); |
| 58 | for (String key : keys) { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 59 | if (nativemap.get(key) == null) { |
| 60 | swigmap.set(key, ""); |
| 61 | } else |
| 62 | swigmap.set(key, nativemap.get(key)); |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 63 | } |
| 64 | return swigmap; |
| 65 | } |
| 66 | |
| 67 | public static VectMap convertFromNativeToSwig(List creds) { |
| 68 | ArrayList<HashMap<String, String>> todecode = (ArrayList<HashMap<String, String>>) creds; |
| 69 | VectMap toReturn = new VectMap(); |
| 70 | |
| 71 | HashMap<String, String> nativeEntry; |
| 72 | |
| 73 | for (int i = 0; i < todecode.size(); ++i) { |
| 74 | nativeEntry = todecode.get(i); |
| 75 | StringMap entry = new StringMap(); |
| 76 | entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD)); |
| 77 | entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME)); |
| 78 | entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM)); |
| 79 | toReturn.add(entry); |
| 80 | } |
| 81 | return toReturn; |
| 82 | } |
| 83 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 84 | private static String tryToGet(StringMap smap, String key) { |
| 85 | if (smap.has_key(key)) { |
| 86 | return smap.get(key); |
| 87 | } else { |
| 88 | return ""; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public static HashMap<String, String> convertAccountToNative(StringMap swigmap) { |
| 93 | HashMap<String, String> nativemap = new HashMap<String, String>(); |
| 94 | |
| 95 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS)); |
| 96 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME)); |
| 97 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME)); |
| 98 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD)); |
| 99 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_ROUTESET, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_ROUTESET)); |
| 100 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_TYPE, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_TYPE)); |
| 101 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_ENABLE, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_ENABLE)); |
| 102 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_USERAGENT, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_USERAGENT)); |
| 103 | nativemap.put(AccountDetailBasic.CONFIG_ACCOUNT_AUTOANSWER, swigmap.get(AccountDetailBasic.CONFIG_ACCOUNT_AUTOANSWER)); |
| 104 | |
| 105 | nativemap |
| 106 | .put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_EXPIRE, swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_EXPIRE)); |
| 107 | nativemap.put(AccountDetailAdvanced.CONFIG_LOCAL_INTERFACE, swigmap.get(AccountDetailAdvanced.CONFIG_LOCAL_INTERFACE)); |
| 108 | nativemap.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, swigmap.get(AccountDetailAdvanced.CONFIG_STUN_SERVER)); |
| 109 | nativemap.put(AccountDetailAdvanced.CONFIG_ACCOUNT_MAILBOX, swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_MAILBOX)); |
| 110 | nativemap |
| 111 | .put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATUS, swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATUS)); |
| 112 | nativemap.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, |
| 113 | swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_CODE)); |
| 114 | nativemap.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, |
| 115 | swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_DESC)); |
| 116 | nativemap.put(AccountDetailAdvanced.CONFIG_ACCOUNT_DTMF_TYPE, swigmap.get(AccountDetailAdvanced.CONFIG_ACCOUNT_DTMF_TYPE)); |
| 117 | nativemap.put(AccountDetailAdvanced.CONFIG_KEEP_ALIVE_ENABLED, swigmap.get(AccountDetailAdvanced.CONFIG_KEEP_ALIVE_ENABLED)); |
| 118 | nativemap.put(AccountDetailAdvanced.CONFIG_LOCAL_PORT, swigmap.get(AccountDetailAdvanced.CONFIG_LOCAL_PORT)); |
| 119 | nativemap.put(AccountDetailAdvanced.CONFIG_PUBLISHED_ADDRESS, swigmap.get(AccountDetailAdvanced.CONFIG_PUBLISHED_ADDRESS)); |
| 120 | nativemap.put(AccountDetailAdvanced.CONFIG_PUBLISHED_PORT, swigmap.get(AccountDetailAdvanced.CONFIG_PUBLISHED_PORT)); |
| 121 | nativemap.put(AccountDetailAdvanced.CONFIG_PUBLISHED_SAMEAS_LOCAL, swigmap.get(AccountDetailAdvanced.CONFIG_PUBLISHED_SAMEAS_LOCAL)); |
| 122 | nativemap.put(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED, swigmap.get(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED)); |
| 123 | nativemap.put(AccountDetailAdvanced.CONFIG_RINGTONE_PATH, swigmap.get(AccountDetailAdvanced.CONFIG_RINGTONE_PATH)); |
| 124 | nativemap.put(AccountDetailAdvanced.CONFIG_STUN_ENABLE, swigmap.get(AccountDetailAdvanced.CONFIG_STUN_ENABLE)); |
| 125 | |
| 126 | nativemap.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, swigmap.get(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE)); |
| 127 | nativemap.put(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK, swigmap.get(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK)); |
| 128 | nativemap.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS, swigmap.get(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS)); |
| 129 | nativemap.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS_ONCE, swigmap.get(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS_ONCE)); |
| 130 | nativemap.put(AccountDetailSrtp.CONFIG_ZRTP_HELLO_HASH, swigmap.get(AccountDetailSrtp.CONFIG_ZRTP_HELLO_HASH)); |
| 131 | nativemap.put(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING, swigmap.get(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING)); |
| 132 | nativemap.put(AccountDetailSrtp.CONFIG_SRTP_ENABLE, swigmap.get(AccountDetailSrtp.CONFIG_SRTP_ENABLE)); |
| 133 | |
| 134 | nativemap.put(AccountDetailTls.CONFIG_TLS_CIPHERS, swigmap.get(AccountDetailTls.CONFIG_TLS_CIPHERS)); |
| 135 | nativemap.put(AccountDetailTls.CONFIG_TLS_LISTENER_PORT, swigmap.get(AccountDetailTls.CONFIG_TLS_LISTENER_PORT)); |
| 136 | nativemap.put(AccountDetailTls.CONFIG_TLS_METHOD, swigmap.get(AccountDetailTls.CONFIG_TLS_METHOD)); |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 137 | nativemap.put(AccountDetailTls.CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, swigmap.get(AccountDetailTls.CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC)); |
| 138 | nativemap.put(AccountDetailTls.CONFIG_TLS_PASSWORD, swigmap.get(AccountDetailTls.CONFIG_TLS_PASSWORD)); |
| 139 | nativemap.put(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE, swigmap.get(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)); |
| 140 | nativemap.put(AccountDetailTls.CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, swigmap.get(AccountDetailTls.CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE)); |
| 141 | nativemap.put(AccountDetailTls.CONFIG_TLS_SERVER_NAME, swigmap.get(AccountDetailTls.CONFIG_TLS_SERVER_NAME)); |
| 142 | nativemap.put(AccountDetailTls.CONFIG_TLS_VERIFY_CLIENT, swigmap.get(AccountDetailTls.CONFIG_TLS_VERIFY_CLIENT)); |
| 143 | nativemap.put(AccountDetailTls.CONFIG_TLS_VERIFY_SERVER, swigmap.get(AccountDetailTls.CONFIG_TLS_VERIFY_SERVER)); |
| 144 | nativemap.put(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE, swigmap.get(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)); |
| 145 | nativemap.put(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE, swigmap.get(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)); |
| 146 | nativemap.put(AccountDetailTls.CONFIG_TLS_ENABLE, swigmap.get(AccountDetailTls.CONFIG_TLS_ENABLE)); |
| 147 | |
| 148 | return nativemap; |
| 149 | } |
| 150 | |
| 151 | public static HashMap<String, String> convertCallDetailsToNative(StringMap swigmap) { |
| 152 | |
| 153 | HashMap<String, String> entry = new HashMap<String, String>(); |
| 154 | |
| 155 | entry.put(ServiceConstants.call.CALL_TYPE, tryToGet(swigmap, ServiceConstants.call.CALL_TYPE)); |
| 156 | entry.put(ServiceConstants.call.PEER_NUMBER, tryToGet(swigmap, ServiceConstants.call.PEER_NUMBER)); |
| 157 | entry.put(ServiceConstants.call.DISPLAY_NAME, tryToGet(swigmap, ServiceConstants.call.DISPLAY_NAME)); |
| 158 | entry.put(ServiceConstants.call.CALL_STATE, tryToGet(swigmap, ServiceConstants.call.CALL_STATE)); |
| 159 | entry.put(ServiceConstants.call.CONF_ID, tryToGet(swigmap, ServiceConstants.call.CONF_ID)); |
| 160 | entry.put(ServiceConstants.call.TIMESTAMP_START, tryToGet(swigmap, ServiceConstants.call.TIMESTAMP_START)); |
| 161 | entry.put(ServiceConstants.call.ACCOUNTID, tryToGet(swigmap, ServiceConstants.call.ACCOUNTID)); |
| 162 | |
| 163 | return entry; |
| 164 | } |
| 165 | |
| 166 | public static ArrayList<HashMap<String, String>> convertCredentialsToNative(VectMap map) { |
| 167 | |
| 168 | ArrayList<HashMap<String, String>> toReturn = new ArrayList<HashMap<String, String>>(); |
| 169 | |
| 170 | for (int i = 0; i < map.size(); ++i) { |
| 171 | StringMap entry = new StringMap(); |
| 172 | HashMap<String, String> nativeEntry = new HashMap<String, String>(); |
| 173 | entry = map.get(i); |
| 174 | nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD)); |
| 175 | nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME)); |
| 176 | nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_REALM, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM)); |
| 177 | toReturn.add(nativeEntry); |
| 178 | } |
| 179 | return toReturn; |
| 180 | } |
| 181 | |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 182 | public static ArrayList<String> convertSwigToNative(StringVect vector) { |
| 183 | ArrayList<String> toReturn = new ArrayList<String>(); |
| 184 | for (int i = 0; i < vector.size(); ++i) { |
| 185 | toReturn.add(vector.get(i)); |
| 186 | } |
| 187 | return toReturn; |
| 188 | } |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 189 | } |