1 | package fr.sii.ogham.sms.splitter; | |
2 | ||
3 | import java.util.Random; | |
4 | ||
5 | /** | |
6 | * In the cellular phone industry, mobile phones and their networks sometimes | |
7 | * support concatenated short message service (or concatenated SMS) to overcome | |
8 | * the limitation on the number of characters that can be sent in a single SMS | |
9 | * text message transmission (which is usually 160). Using this method, long | |
10 | * messages are split into smaller messages by the sending device and recombined | |
11 | * at the receiving end. Each message is then billed separately. When the | |
12 | * feature works properly, it is nearly transparent to the user, appearing as a | |
13 | * single long text message. | |
14 | * | |
15 | * <p> | |
16 | * One way of sending concatenated SMS (CSMS) is to split the message into 153 | |
17 | * 7-bit character parts (134 octets), and sending each part with a User Data | |
18 | * Header (UDH) tacked onto the beginning. A UDH can be used for various | |
19 | * purposes and its contents and size varies accordingly, but a UDH for | |
20 | * concatenating SMSes look like this: | |
21 | * | |
22 | * <ul> | |
23 | * <li>Field 1 (1 octet): Length of User Data Header, in this case 05.</li> | |
24 | * <li>Field 2 (1 octet): Information Element Identifier, equal to 00 | |
25 | * (Concatenated short messages, 8-bit reference number)</li> | |
26 | * <li>Field 3 (1 octet): Length of the header, excluding the first two fields; | |
27 | * equal to 03</li> | |
28 | * <li>Field 4 (1 octet): 00-FF, CSMS reference number, must be same for all the | |
29 | * SMS parts in the CSMS</li> | |
30 | * <li>Field 5 (1 octet): 00-FF, total number of parts. The value shall remain | |
31 | * constant for every short message which makes up the concatenated short | |
32 | * message. If the value is zero then the receiving entity shall ignore the | |
33 | * whole information element</li> | |
34 | * <li>Field 6 (1 octet): 00-FF, this part's number in the sequence. The value | |
35 | * shall start at 1 and increment for every short message which makes up the | |
36 | * concatenated short message. If the value is zero or greater than the value in | |
37 | * Field 5 then the receiving entity shall ignore the whole information element. | |
38 | * [ETSI Specification: GSM 03.40 Version 5.3.0: July 1996]</li> | |
39 | * </ul> | |
40 | * | |
41 | * <p> | |
42 | * It is possible to use a 16 bit CSMS reference number in order to reduce the | |
43 | * probability that two different concatenated messages are sent with identical | |
44 | * reference numbers to a receiver. In this case, the User Data Header shall be: | |
45 | * | |
46 | * <ul> | |
47 | * <li>Field 1 (1 octet): Length of User Data Header (UDL), in this case | |
48 | * 06.</li> | |
49 | * <li>Field 2 (1 octet): Information Element Identifier, equal to 08 | |
50 | * (Concatenated short messages, 16-bit reference number)</li> | |
51 | * <li>Field 3 (1 octet): Length of the header, excluding the first two fields; | |
52 | * equal to 04</li> | |
53 | * <li>Field 4 (2 octets): 0000-FFFF, CSMS reference number, must be same for | |
54 | * all the SMS parts in the CSMS</li> | |
55 | * <li>Field 5 (1 octet): 00-FF, total number of parts. The value shall remain | |
56 | * constant for every short message which makes up the concatenated short | |
57 | * message. If the value is zero then the receiving entity shall ignore the | |
58 | * whole information element</li> | |
59 | * <li>Field 6 (1 octet): 00-FF, this part's number in the sequence. The value | |
60 | * shall start at 1 and increment for every short message which makes up the | |
61 | * concatenated short message. If the value is zero or greater than the value in | |
62 | * Field 5 then the receiving entity shall ignore the whole information element. | |
63 | * [ETSI Specification: GSM 03.40 Version 5.3.0: July 1996]</li> | |
64 | * </ul> | |
65 | * | |
66 | * <p> | |
67 | * This implementation generates a value using {@link Random} utility. | |
68 | * | |
69 | * @author Aurélien Baudet | |
70 | * | |
71 | */ | |
72 | public class RandomReferenceNumberGenerator implements ReferenceNumberGenerator { | |
73 | private final Random random; | |
74 | private final int length; | |
75 | ||
76 | /** | |
77 | * Uses a default {@link Random} to generate random reference numbers. The | |
78 | * generated reference is only one octet length. | |
79 | * | |
80 | * <p> | |
81 | * If you want a custom number generation, use | |
82 | * {@link #RandomReferenceNumberGenerator(Random)}. | |
83 | */ | |
84 | @SuppressWarnings("squid:S2245") | |
85 | public RandomReferenceNumberGenerator() { | |
86 | this(new Random()); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Use the provided {@link Random} to generate random reference numbers. The | |
91 | * generated reference is only one octet length. | |
92 | * | |
93 | * <p> | |
94 | * If you want to generate a reference number of two octets, use | |
95 | * {@link #RandomReferenceNumberGenerator(Random, int)}. | |
96 | * | |
97 | * @param random | |
98 | * used to generate random numbers | |
99 | */ | |
100 | public RandomReferenceNumberGenerator(Random random) { | |
101 | this(random, 1); | |
102 | } | |
103 | ||
104 | /** | |
105 | * Use the provided {@link Random} to generate random reference number byte | |
106 | * arrays. Each reference number byte array has a size of {@code length} | |
107 | * parameter. | |
108 | * | |
109 | * @param random | |
110 | * used to generate random numbers | |
111 | * @param length | |
112 | * the number of octets for each reference number | |
113 | */ | |
114 | public RandomReferenceNumberGenerator(Random random, int length) { | |
115 | super(); | |
116 | this.random = random; | |
117 | this.length = length; | |
118 | } | |
119 | ||
120 | @Override | |
121 | public byte[] generateReferenceNumber() { | |
122 | byte[] referenceNumber = new byte[length]; | |
123 |
2
1. generateReferenceNumber : removed call to java/util/Random::nextBytes → NO_COVERAGE 2. generateReferenceNumber : removed call to java/util/Random::nextBytes → SURVIVED |
random.nextBytes(referenceNumber); |
124 |
3
1. generateReferenceNumber : replaced return value with null for fr/sii/ogham/sms/splitter/RandomReferenceNumberGenerator::generateReferenceNumber → NO_COVERAGE 2. generateReferenceNumber : replaced return value with null for fr/sii/ogham/sms/splitter/RandomReferenceNumberGenerator::generateReferenceNumber → KILLED 3. generateReferenceNumber : replaced return value with null for fr/sii/ogham/sms/splitter/RandomReferenceNumberGenerator::generateReferenceNumber → KILLED |
return referenceNumber; |
125 | } | |
126 | ||
127 | } | |
Mutations | ||
123 |
1.1 2.2 |
|
124 |
1.1 2.2 3.3 |