Skip to content
This repository was archived by the owner on Jul 12, 2021. It is now read-only.

Commit 28dae8c

Browse files
committed
Resurrected the UCP transport
1 parent 1ed6976 commit 28dae8c

File tree

5 files changed

+766
-0
lines changed

5 files changed

+766
-0
lines changed

src/main/java/org/marre/SmsSender.java

+69
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,75 @@ public static SmsSender getGsmSender(String portName) throws SmsException
176176
return new SmsSender("org.marre.sms.transport.gsm.GsmTransport", props);
177177
}
178178

179+
/**
180+
* Convenience method to create a SmsSender object that knows how to send
181+
* messages with a UCP SMSC.
182+
*
183+
* @param address
184+
* A string with the ip address or host name of the SMSC
185+
* @param port
186+
* An integer with the ip port on which the SMSC listens
187+
* @return A SmsSender object that uses the UcpTranport to send messages
188+
* @throws SmsException
189+
*/
190+
public static SmsSender getUcpSender(String address, int port) throws SmsException
191+
{
192+
//Liquidterm: strict input checking is done in the UcpTransport class
193+
Properties props = new Properties();
194+
props.setProperty("smsj.ucp.ip.host", address);
195+
props.setProperty("smsj.ucp.ip.port", Integer.toString(port));
196+
return new SmsSender("org.marre.sms.transport.ucp.UcpTransport", props);
197+
}
198+
199+
/**
200+
* Convenience method to create a SmsSender object that knows how to send
201+
* messages with a UCP SMSC.
202+
*
203+
* @param address
204+
* A string with the ip address or host name of the SMSC
205+
* @param port
206+
* An integer with the ip port on which the SMSC listens
207+
* @param ucp60Uid
208+
* A string containing the UCP60 userid
209+
* @param ucp60Pwd
210+
* A string containing the UCP60 password
211+
*
212+
* @return A SmsSender object that uses the UcpTranport to send messages
213+
*
214+
* @throws SmsException
215+
*/
216+
public static SmsSender getUcpSender(String address, int port, String ucp60Uid, String ucp60Pwd)
217+
throws SmsException
218+
{
219+
//Liquidterm: strict input checking is done in the UcpTransport class
220+
Properties props = new Properties();
221+
props.setProperty("smsj.ucp.ip.host", address);
222+
props.setProperty("smsj.ucp.ip.port", Integer.toString(port));
223+
props.setProperty("smsj.ucp.ucp60.uid", ucp60Uid);
224+
props.setProperty("smsj.ucp.ucp60.password", ucp60Pwd);
225+
return new SmsSender("org.marre.sms.transport.ucp.UcpTransport", props);
226+
}
227+
228+
/**
229+
* Convenience method to create a SmsSender object that knows how to send
230+
* messages with a UCP SMSC.
231+
*
232+
* @param propsFilename
233+
* A string containt a filename with the serialized Properties
234+
* object for the transport
235+
*
236+
* @return A SmsSender object that uses the UcpTranport to send messages
237+
*
238+
* @throws SmsException
239+
* @throws IOException
240+
*/
241+
public static SmsSender getUcpSender(String propsFilename) throws SmsException, IOException
242+
{
243+
Properties props = new Properties();
244+
props.load(new FileInputStream(propsFilename));
245+
return new SmsSender("org.marre.sms.transport.ucp.UcpTransport", props);
246+
}
247+
179248
/**
180249
* Sends an ordinary SMS to the given recipient.
181250
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.marre.sms.transport.ucp;
2+
3+
/**
4+
* @author Lorenz Barth
5+
*
6+
* To change this generated comment edit the template variable "typecomment":
7+
* Window>Preferences>Java>Templates. To enable and disable the creation of type
8+
* comments go to Window>Preferences>Java>Code Generation.
9+
*/
10+
public class UCPSeries60 extends UcpMsg
11+
{
12+
public static final byte OP_OPEN_SESSION = 60;
13+
14+
protected static final int FIELD_OADC = 0;
15+
protected static final int FIELD_OTON = 1;
16+
protected static final int FIELD_ONPI = 2;
17+
protected static final int FIELD_STYP = 3;
18+
protected static final int FIELD_PWD = 4;
19+
protected static final int FIELD_NPWD = 5;
20+
protected static final int FIELD_VERS = 6;
21+
protected static final int FIELD_LADC = 7;
22+
protected static final int FIELD_LTON = 8;
23+
protected static final int FIELD_LNPI = 9;
24+
protected static final int FIELD_OPID = 10;
25+
protected static final int FIELD_RES1 = 11;
26+
27+
/**
28+
* Constructor for UCPSeries60.
29+
*
30+
* @param operation
31+
*/
32+
public UCPSeries60(byte operation)
33+
{
34+
super(12);
35+
setOR('O');
36+
setOT(operation);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/* ***** BEGIN LICENSE BLOCK *****
2+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
3+
*
4+
* The contents of this file are subject to the Mozilla Public License Version
5+
* 1.1 (the "License"); you may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
* http://www.mozilla.org/MPL/
8+
*
9+
* Software distributed under the License is distributed on an "AS IS" basis,
10+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11+
* for the specific language governing rights and limitations under the
12+
* License.
13+
*
14+
* The Original Code is "SMS Library for the Java platform".
15+
*
16+
* The Initial Developer of the Original Code is Markus Eriksson.
17+
* Portions created by the Initial Developer are Copyright (C) 2002
18+
* the Initial Developer. All Rights Reserved.
19+
*
20+
* Contributor(s):
21+
*
22+
* Alternatively, the contents of this file may be used under the terms of
23+
* either the GNU General Public License Version 2 or later (the "GPL"), or
24+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25+
* in which case the provisions of the GPL or the LGPL are applicable instead
26+
* of those above. If you wish to allow use of your version of this file only
27+
* under the terms of either the GPL or the LGPL, and not to allow others to
28+
* use your version of this file under the terms of the MPL, indicate your
29+
* decision by deleting the provisions above and replace them with the notice
30+
* and other provisions required by the GPL or the LGPL. If you do not delete
31+
* the provisions above, a recipient may use your version of this file under
32+
* the terms of any one of the MPL, the GPL or the LGPL.
33+
*
34+
* ***** END LICENSE BLOCK ***** */
35+
package org.marre.sms.transport.ucp;
36+
37+
import java.io.ByteArrayOutputStream;
38+
import java.io.IOException;
39+
import java.io.OutputStream;
40+
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
43+
import org.marre.util.StringUtil;
44+
45+
/**
46+
* Baseclass for UcpMsg.
47+
*
48+
* @author Markus Eriksson
49+
* @version $Id$
50+
*/
51+
public abstract class UcpMsg
52+
{
53+
protected static final byte STX = (byte) 0x02;
54+
protected static final byte ETX = (byte) 0x03;
55+
56+
private static Logger log_ = LoggerFactory.getLogger(UcpMsg.class);
57+
58+
protected String[] ucpFields_;
59+
protected char or_; // 'O' or 'R'
60+
protected int trn_;
61+
protected byte ot_;
62+
63+
public UcpMsg(int nFields)
64+
{
65+
ucpFields_ = new String[nFields];
66+
}
67+
68+
public void setField(int field, String value)
69+
{
70+
ucpFields_[field] = value;
71+
}
72+
73+
public String getField(int field)
74+
{
75+
return ucpFields_[field];
76+
}
77+
78+
protected void setOR(char or)
79+
{
80+
or_ = or;
81+
}
82+
83+
protected void setOT(byte ot)
84+
{
85+
ot_ = ot;
86+
}
87+
88+
public void setTRN(int trn)
89+
{
90+
trn_ = trn;
91+
}
92+
93+
public byte calcChecksum(String data)
94+
{
95+
int checksum = 0;
96+
for (int i = 0; i < data.length(); i++)
97+
{
98+
checksum = (checksum + data.charAt(i)) % 256;
99+
}
100+
return (byte) (checksum & 0xff);
101+
}
102+
103+
public String buildCommand()
104+
{
105+
StringBuffer command = new StringBuffer(200);
106+
int length = 0;
107+
108+
// CALC LENGTH
109+
110+
// length = trn + len + o|r + ot
111+
length = 3 + 5 + 2 + 3;
112+
// length += data
113+
for (int i = 0; i < ucpFields_.length; i++)
114+
{
115+
if (ucpFields_[i] != null)
116+
{
117+
length += ucpFields_[i].length();
118+
}
119+
length += 1;
120+
}
121+
// length += checksum
122+
length += 3;
123+
124+
// HEADER (TRN/LEN/O|R/OT)
125+
126+
// TRN (2 num char)
127+
command.append(StringUtil.intToString(trn_, 2));
128+
command.append('/');
129+
// LEN (5 num char)
130+
command.append(StringUtil.intToString(length, 5));
131+
command.append('/');
132+
// O|R (Char 'O' or 'R')
133+
command.append(or_);
134+
command.append('/');
135+
// OT (2 num char)
136+
command.append(StringUtil.intToString(ot_, 2));
137+
command.append('/');
138+
139+
// DATA
140+
for (int i = 0; i < ucpFields_.length; i++)
141+
{
142+
if (ucpFields_[i] != null)
143+
{
144+
command.append(ucpFields_[i]);
145+
}
146+
command.append('/');
147+
}
148+
149+
// CHECKSUM
150+
command.append(StringUtil.byteToHexString(calcChecksum(command.toString())));
151+
152+
return command.toString();
153+
}
154+
155+
public void writeTo(OutputStream os) throws IOException
156+
{
157+
// STX
158+
os.write(STX);
159+
160+
// Command
161+
os.write(buildCommand().getBytes());
162+
163+
// ETX
164+
os.write(ETX);
165+
}
166+
167+
public byte[] getCommand()
168+
{
169+
ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
170+
try
171+
{
172+
writeTo(baos);
173+
}
174+
catch (IOException ex)
175+
{
176+
log_.debug("getCommand() - Failed to write to an ByteArrayOutputStream!");
177+
}
178+
return baos.toByteArray();
179+
}
180+
}

0 commit comments

Comments
 (0)