2 * Copyright (C) 2010 Mirko Weber, Felix Bechstein
4 * This file is part of WebSMS.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 3 of the License, or (at your option) any later
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License along with
17 * this program; If not, see <http://www.gnu.org/licenses/>.
19 package de
.ub0r
.android
.andGMXsms
;
21 import java
.io
.Serializable
;
22 import java
.util
.Hashtable
;
24 import java
.util
.Vector
;
26 import org
.xmlrpc
.android
.XMLRPCClient
;
27 import org
.xmlrpc
.android
.XMLRPCException
;
28 import org
.xmlrpc
.android
.XMLRPCFault
;
30 import android
.content
.Context
;
31 import android
.util
.Log
;
32 import de
.ub0r
.android
.websms
.connector
.common
.WebSMSException
;
35 * AsyncTask to manage XMLRPC-Calls to sipgate.de remote-API.
39 public class ConnectorSipgate
extends Connector
{
40 /** Tag for output. */
41 private static final String TAG
= "WebSMS.Sipg";
43 /** Sipgate.de API URL. */
44 private static final String SIPGATE_URL
= "https://"
45 + "samurai.sipgate.net/RPC2";
46 /** Sipfate.de TEAM-API URL. */
47 private static final String SIPGATE_TEAM_URL
= "https://"
48 + "api.sipgate.net/RPC2";
51 * Create a Sipgate Connector.
58 protected ConnectorSipgate(final String u
, final String p
) {
59 super(null); // FIXME:
66 protected final boolean sendMessage() throws WebSMSException
{
67 Log
.d(TAG
, "sendMessage()");
70 XMLRPCClient client
= this.init();
71 Vector
<String
> remoteUris
= new Vector
<String
>();
72 for (int i
= 0; i
< this.to
.length
; i
++) {
73 if (this.to
[i
] != null && this.to
[i
].length() > 1) {
74 remoteUris
.add("sip:" + this.to
[i
].replaceAll("\\+", "")
76 Log
.d(TAG
, "Telefonnummer:" + remoteUris
.get(i
));
79 Hashtable
<String
, Serializable
> params
= new Hashtable
<String
, Serializable
>();
80 // FIXME: if (WebSMS.prefsSender.length() > 6) {
81 // String localUri = "sip:"
82 // + WebSMS.prefsSender.replaceAll("\\+", "")
84 // params.put("LocalUri", localUri);
86 params
.put("RemoteUri", remoteUris
);
87 params
.put("TOS", "text");
88 params
.put("Content", this.text
);
89 back
= client
.call("samurai.SessionInitiateMulti", params
);
90 Log
.d(TAG
, back
.toString());
91 } catch (XMLRPCFault e
) {
93 if (e
.getFaultCode() == HTTP_SERVICE_UNAUTHORIZED
) {
94 throw new WebSMSException(this.context
, R
.string
.log_error_pw
);
96 throw new WebSMSException(e
.toString());
97 } catch (XMLRPCException e
) {
99 throw new WebSMSException(e
.toString());
107 @SuppressWarnings("unchecked")
109 protected final boolean updateMessages() throws WebSMSException
{
110 Log
.d(TAG
, "updateMessage()");
111 Map
<String
, Object
> back
= null;
113 XMLRPCClient client
= this.init();
114 back
= (Map
<String
, Object
>) client
.call("samurai.BalanceGet");
115 Log
.d(TAG
, back
.toString());
116 if (back
.get("StatusCode").equals(new Integer(HTTP_SERVICE_OK
))) {
117 // FIXME WebSMS.SMS_BALANCE[SIPGATE] =
118 // String.format("%.2f \u20AC",
119 // ((Double) ((Map<String, Object>) back
120 // .get("CurrentBalance")).get("TotalIncludingVat")));
122 this.pushMessage(WebSMS
.MESSAGE_FREECOUNT
, null);
123 } catch (XMLRPCFault e
) {
125 if (e
.getFaultCode() == HTTP_SERVICE_UNAUTHORIZED
) {
126 throw new WebSMSException(this.context
, R
.string
.log_error_pw
);
128 throw new WebSMSException(e
.toString());
129 } catch (XMLRPCException e
) {
131 throw new WebSMSException(e
.toString());
138 * Sets up and instance of XMLRPCClient.
140 * @return the initialized XMLRPCClient
141 * @throws XMLRPCException
144 private XMLRPCClient
init() throws XMLRPCException
{
145 Log
.d(TAG
, "updateMessage()");
146 Context c
= this.context
;
147 final String version
= c
.getString(R
.string
.app_version
);
148 final String vendor
= c
.getString(R
.string
.author1
);
149 XMLRPCClient client
= null; // FIXME
150 // FIXME: if (WebSMS.prefsEnableSipgateTeam) {
151 // client = new XMLRPCClient(SIPGATE_TEAM_URL);
153 // client = new XMLRPCClient(SIPGATE_URL);
156 // FIXME: client.setBasicAuthentication(this.user, this.password);
159 Hashtable
<String
, String
> ident
= new Hashtable
<String
, String
>();
160 ident
.put("ClientName", TAG
);
161 ident
.put("ClientVersion", version
);
162 ident
.put("ClientVendor", vendor
);
163 back
= client
.call("samurai.ClientIdentify", ident
);
164 Log
.d(TAG
, back
.toString());
166 } catch (XMLRPCException e
) {
167 Log
.e(TAG
, "XMLRPCExceptin in init()", e
);