/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/version/SMPPVersion50.java
Java | 111 lines | 73 code | 14 blank | 24 comment | 14 complexity | 16275dbd571c3ee9e09376ed507d4c75 MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.protocols.smpp.version; 24 25import org.mobicents.protocols.smpp.message.CommandId; 26 27public class SMPPVersion50 extends AbstractSMPPVersion { 28 private static final long serialVersionUID = 2L; 29 private static final int MAX_MSG_LENGTH = 255; 30 31 public SMPPVersion50() { 32 super(0x50, "SMPP version 5.0"); 33 } 34 35 public int getMaxLength(MandatoryParameter mandatoryParameter) { 36 switch (mandatoryParameter) { 37 case SHORT_MESSAGE: 38 return MAX_MSG_LENGTH; 39 40 default: 41 return Integer.MAX_VALUE; 42 } 43 } 44 45 public boolean isSupportTLV() { 46 return true; 47 } 48 49 public boolean isSupported(int commandId) { 50 // Turn off the msb, which is used to signify a response packet.. 51 switch (commandId & 0x7fffffff) { 52 case CommandId.ALERT_NOTIFICATION: 53 case CommandId.BIND_RECEIVER: 54 case CommandId.BIND_TRANSCEIVER: 55 case CommandId.BIND_TRANSMITTER: 56 case CommandId.BROADCAST_SM: 57 case CommandId.CANCEL_BROADCAST_SM: 58 case CommandId.CANCEL_SM: 59 case CommandId.DATA_SM: 60 case CommandId.DELIVER_SM: 61 case CommandId.ENQUIRE_LINK: 62 case CommandId.GENERIC_NACK: 63 case CommandId.OUTBIND: 64 case CommandId.QUERY_BROADCAST_SM: 65 case CommandId.QUERY_SM: 66 case CommandId.REPLACE_SM: 67 case CommandId.SUBMIT_MULTI: 68 case CommandId.SUBMIT_SM: 69 case CommandId.UNBIND: 70 return true; 71 72 default: 73 return false; 74 } 75 } 76 77 public void validateMessage(byte[] message, int start, int length) { 78 if (message != null && length > MAX_MSG_LENGTH) { 79 throw new VersionException("Message is too long: " + length); 80 } 81 } 82 83 public void validateMessageId(String messageId) { 84 if (messageId != null && messageId.length() > 64) { 85 throw new VersionException("Invalid message ID: " + messageId); 86 } 87 } 88 89 public void validatePriorityFlag(int priority) { 90 if (priority < 0 || priority > 4) { 91 throw new VersionException( 92 "Invalid message priority: " + priority); 93 } 94 } 95 96 public void validateRegisteredDelivery(int registeredDelivery) { 97 // See comments in SMPPVersion34 for info on the following 98 // check. 99 if (registeredDelivery < 0 || registeredDelivery > 0x1f) { 100 throw new VersionException( 101 "Invalid registered delivery: " + registeredDelivery); 102 } 103 } 104 105 public void validateNumberOfDests(int num) { 106 if (num < 0 || num > 255) { 107 throw new VersionException( 108 "Invalid number of destinations: " + num); 109 } 110 } 111}