/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/version/SMPPVersion50.java

http://mobicents.googlecode.com/ · 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. package org.mobicents.protocols.smpp.version;
  23. import org.mobicents.protocols.smpp.message.CommandId;
  24. public class SMPPVersion50 extends AbstractSMPPVersion {
  25. private static final long serialVersionUID = 2L;
  26. private static final int MAX_MSG_LENGTH = 255;
  27. public SMPPVersion50() {
  28. super(0x50, "SMPP version 5.0");
  29. }
  30. public int getMaxLength(MandatoryParameter mandatoryParameter) {
  31. switch (mandatoryParameter) {
  32. case SHORT_MESSAGE:
  33. return MAX_MSG_LENGTH;
  34. default:
  35. return Integer.MAX_VALUE;
  36. }
  37. }
  38. public boolean isSupportTLV() {
  39. return true;
  40. }
  41. public boolean isSupported(int commandId) {
  42. // Turn off the msb, which is used to signify a response packet..
  43. switch (commandId & 0x7fffffff) {
  44. case CommandId.ALERT_NOTIFICATION:
  45. case CommandId.BIND_RECEIVER:
  46. case CommandId.BIND_TRANSCEIVER:
  47. case CommandId.BIND_TRANSMITTER:
  48. case CommandId.BROADCAST_SM:
  49. case CommandId.CANCEL_BROADCAST_SM:
  50. case CommandId.CANCEL_SM:
  51. case CommandId.DATA_SM:
  52. case CommandId.DELIVER_SM:
  53. case CommandId.ENQUIRE_LINK:
  54. case CommandId.GENERIC_NACK:
  55. case CommandId.OUTBIND:
  56. case CommandId.QUERY_BROADCAST_SM:
  57. case CommandId.QUERY_SM:
  58. case CommandId.REPLACE_SM:
  59. case CommandId.SUBMIT_MULTI:
  60. case CommandId.SUBMIT_SM:
  61. case CommandId.UNBIND:
  62. return true;
  63. default:
  64. return false;
  65. }
  66. }
  67. public void validateMessage(byte[] message, int start, int length) {
  68. if (message != null && length > MAX_MSG_LENGTH) {
  69. throw new VersionException("Message is too long: " + length);
  70. }
  71. }
  72. public void validateMessageId(String messageId) {
  73. if (messageId != null && messageId.length() > 64) {
  74. throw new VersionException("Invalid message ID: " + messageId);
  75. }
  76. }
  77. public void validatePriorityFlag(int priority) {
  78. if (priority < 0 || priority > 4) {
  79. throw new VersionException(
  80. "Invalid message priority: " + priority);
  81. }
  82. }
  83. public void validateRegisteredDelivery(int registeredDelivery) {
  84. // See comments in SMPPVersion34 for info on the following
  85. // check.
  86. if (registeredDelivery < 0 || registeredDelivery > 0x1f) {
  87. throw new VersionException(
  88. "Invalid registered delivery: " + registeredDelivery);
  89. }
  90. }
  91. public void validateNumberOfDests(int num) {
  92. if (num < 0 || num > 255) {
  93. throw new VersionException(
  94. "Invalid number of destinations: " + num);
  95. }
  96. }
  97. }