📄 smpppacket.java
字号:
/* * Java SMPP API * Copyright (C) 1998 - 2001 by Oran Kelly * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html * Java SMPP API author: orank@users.sf.net * Java SMPP API Homepage: http://smppapi.sourceforge.net/ */package ie.omk.smpp.message;import java.io.*;import java.net.SocketException;import ie.omk.smpp.SMPPException;import ie.omk.smpp.InvalidMessageIDException;import ie.omk.smpp.StringTooLongException;import ie.omk.smpp.util.AlphabetEncoding;import ie.omk.smpp.util.AlphabetFactory;import ie.omk.smpp.util.BinaryEncoding;import ie.omk.smpp.util.GSMConstants;import ie.omk.smpp.util.MessageEncoding;import ie.omk.smpp.util.SMPPDate;import ie.omk.smpp.util.SMPPIO;import ie.omk.debug.Debug;/** This is the abstract class that all SMPP messages are inherited from. * @author Oran Kelly * @version 1.0 */public abstract class SMPPPacket{ /** Command Id: Negative Acknowledgement */ public static final int ESME_NACK = 0x80000000; /** Command Id: Bind Receiver */ public static final int ESME_BNDRCV = 0x00000001; /** Command Id: Bind Receiver Response */ public static final int ESME_BNDRCV_RESP = 0x80000001; /** Command Id: Bind transmitter */ public static final int ESME_BNDTRN = 0x00000002; /** Command Id: Bind transmitter response */ public static final int ESME_BNDTRN_RESP = 0x80000002; /** Command Id: Unbind */ public static final int ESME_UBD = 0x00000006; /** Command Id: Unbind response */ public static final int ESME_UBD_RESP = 0x80000006; /** Command Id: Submit message */ public static final int ESME_SUB_SM = 0x00000004; /** Command Id: Submit message response */ public static final int ESME_SUB_SM_RESP = 0x80000004; /** Command Id: Submit multiple messages */ public static final int ESME_SUB_MULTI = 0x00000021; /** Command Id: Submit multi response */ public static final int ESME_SUB_MULTI_RESP = 0x80000021; /** Command Id: Deliver Short message */ public static final int SMSC_DELIVER_SM = 0x00000005; /** Command Id: Deliver message response */ public static final int SMSC_DELIVER_SM_RESP= 0x80000005; /** Command Id: Query message */ public static final int ESME_QUERY_SM = 0x00000003; /** Command Id: Query message response */ public static final int ESME_QUERY_SM_RESP = 0x80000003; /** Command Id: Query last messages */ public static final int ESME_QUERY_LAST_MSGS= 0x00000023; /** Command Id: Query last messages response */ public static final int ESME_QUERY_LAST_MSGS_RESP = 0x80000023; /** Command Id: Query message details */ public static final int ESME_QUERY_MSG_DETAILS = 0x00000024; /** Command Id: Query message details response */ public static final int ESME_QUERY_MSG_DETAILS_RESP = 0x80000024; /** Command Id: Cancel message */ public static final int ESME_CANCEL_SM = 0x00000008; /** Command Id: Cancel message response */ public static final int ESME_CANCEL_SM_RESP = 0x80000008; /** Command Id: Replace message */ public static final int ESME_REPLACE_SM = 0x00000007; /** Command Id: replace message response */ public static final int ESME_REPLACE_SM_RESP= 0x80000007; /** Command Id: Enquire Link */ public static final int ESME_QRYLINK = 0x00000015; /** Command Id: Enquire link respinse */ public static final int ESME_QRYLINK_RESP = 0x80000015; /** Command Id: Parameter retrieve */ public static final int ESME_PARAM_RETRIEVE = 0x00000022; /** Command Id: Paramater retrieve response */ public static final int ESME_PARAM_RETRIEVE_RESP = 0x80000022; /** Message state at Smsc: En route */ public static final int SM_STATE_EN_ROUTE = 1; /** Message state at Smsc: Delivered (final) */ public static final int SM_STATE_DELIVERED = 2; /** Message state at Smsc: Expired (final) */ public static final int SM_STATE_EXPIRED = 3; /** Message state at Smsc: Deleted (final) */ public static final int SM_STATE_DELETED = 4; /** Message state at Smsc: Undeliverable (final) */ public static final int SM_STATE_UNDELIVERABLE = 5; /** Message state at Smsc: Accepted */ public static final int SM_STATE_ACCEPTED = 6; /** Message state at Smsc: Invalid message (final) */ public static final int SM_STATE_INVALID = 7; /** Esm class: Mobile Terminated; Normal delivery, no address swapping */ public static final int SMC_MT = 1; /** Esm class: Mobile originated */ public static final int SMC_MO = 2; /** Esm class: Mobile Originated / Terminated */ public static final int SMC_MOMT = 3; /** Esm class: Delivery receipt, no address swapping */ public static final int SMC_RECEIPT = 4; /** Esm class: Predefined message */ public static final int SMC_DEFMSG = 8; /** Esm class: Normal delivery , address swapping on */ public static final int SMC_LOOPBACK_RECEIPT = 16; /** Esm class: Delivery receipt, address swapping on */ public static final int SMC_RECEIPT_SWAP = 20; /** Esm class: Store message, do not send to Kernel */ public static final int SMC_STORE = 32; /** Esm class: Store message and send to kernel */ public static final int SMC_STORE_FORWARD = 36; /** Esm class: Distribution submission */ public static final int SMC_DLIST = 64; /** Esm class: Multiple recipient submission */ public static final int SMC_MULTI = 128; /** Esm class: Distribution list and multiple recipient submission */ public static final int SMC_CAS_DL = 256; /** Esm class: Escalated message FFU */ public static final int SMC_ESCALATED = 512; /** Esm class: Submit with replace message */ public static final int SMC_SUBMIT_REPLACE = 1024; /** Esm class: Memory capacity error */ public static final int SMC_MCE = 2048; /** Esme error code: No error */ public static final int ESME_ROK = 0; /** Command ID. */ protected int commandId = 0; /** Command status. */ protected int commandStatus = 0; /** Packet sequence number. */ protected int sequenceNum = 0; /* Almost all packets use one or more of these. * These attributes were all stuck in here for easier maintenance... * instead of altering 5 different packets, just alter it here!! * Special cases like SubmitMulti and QueryMsgDetailsResp maintain * their own destination tables. Any packets that wish to use * these attribs should override the appropriate methods defined * below to be public and just call super.method() */ /** Source address */ protected SmeAddress source = null; /** Destination address */ protected SmeAddress destination = null; /** The short message data */ protected byte[] message = null; /** Service type for this msg */ protected String serviceType = null; /** Scheduled delivery time */ protected SMPPDate deliveryTime = null; /** Scheduled expiry time */ protected SMPPDate expiryTime = null; /** Date of reaching final state */ protected SMPPDate finalDate = null; /** Smsc allocated message Id */ protected String messageId = null; /** Status of message */ protected int messageStatus = 0; /** Error associated with message */ protected int errorCode = 0; /** Message priority. In v3.3, this is boolean, either '1' or '0' */ protected int priority = 0; /** Registered delivery. */ protected boolean registered = false; /** Replace if present. */ protected boolean replaceIfPresent = false; /** ESM class. */ protected int esmClass = 0; /** GSM protocol ID. */ protected int protocolID = 0; /** GSM data coding (see GSM 03.38). */ public int dataCoding = 0; /** Default message number. */ public int defaultMsg = 0; /** Alphabet to use to encode this message's text. */ private AlphabetEncoding alphabet = AlphabetFactory.getDefaultAlphabet(); /** Create a new SMPPPacket with specified Id. * @param id Command Id value */ protected SMPPPacket(int id) { this(id, 0); } /** Create a new SMPPPacket with specified Id and sequence number. * @param id Command Id value * @param seqNum Command Sequence number */ protected SMPPPacket(int id, int seqNum) { this.commandId = id; this.sequenceNum = seqNum; } /** Read an SMPPPacket header from an InputStream * @param in InputStream to read from * @exception IOException if there's an error reading from the input * stream. */ protected SMPPPacket(InputStream in) throws java.io.IOException, ie.omk.smpp.SMPPException { int cmdLen = SMPPIO.readInt(in, 4); this.commandId = SMPPIO.readInt(in, 4); this.commandStatus = SMPPIO.readInt(in, 4); this.sequenceNum = SMPPIO.readInt(in, 4); } /** Return the number of bytes this packet would be encoded as to an * OutputStream. * @return The size in bytes of the packet */ public abstract int getCommandLen(); /** Get the length of the SMPP header. */ protected int getHeaderLen() { // 1 4-byte integer each for command length, id, status and sequence // number. return (16); } /** Get the Command Id of this SMPP packet. * @return The Command Id of this packet */ public int getCommandId() { return (commandId); } /** Get the status of this packet. * @return The error status of this packet (only relevent to Response * packets) */ public int getCommandStatus() { return (this.commandStatus); } /** Get the sequence number of this packet. * @return The sequence number of this SMPP packet */ public int getSequenceNum() { return (this.sequenceNum); } /** Set the sequence number of this packet. */ public void setSequenceNum(int sequenceNum) { this.sequenceNum = sequenceNum; } /** Set the source address. * Not used by all SMPP Packet types. * @see ie.omk.smpp.message.SubmitSM * @see ie.omk.smpp.message.DeliverSM * XXX Add other packets. */ public void setSource(SmeAddress s) { if(s != null) { this.source = s; Debug.d(this, "setSource", s, 4); } } /** Get the source address. * Not used by all SMPP Packet types. * @return The source address or null if it is not set. */ public SmeAddress getSource() { if(source != null) return (source); else return (null); } /** Set the destination address. * Not used by all SMPP Packet types. */ public void setDestination(SmeAddress s) { if(s != null) { this.destination = s; Debug.d(this, "setDestination", s, 4); } } /** Get the destination address. * Not used by all SMPP Packet types. * @return The destination address or null if it is not set. */ public SmeAddress getDestination() { if(destination != null) { return (destination); } else { return (null); } } /** Set the message flags. * Not used by all SMPP Packet types. * @see ie.omk.smpp.message.MsgFlags * @deprecated */ public void setMessageFlags(MsgFlags f) { if(f != null) { this.priority = (f.priority) ? 1 : 0; this.registered = f.registered; this.replaceIfPresent = f.replace_if_present; this.esmClass = f.esm_class; this.protocolID = f.protocol; this.dataCoding = f.data_coding; this.defaultMsg = f.default_msg; Debug.d(this, "setMessageFlags", f, 4); } } /** Set the 'priority' flag. * @see ie.omk.smpp.message.MsgFlags */ public void setPriority(boolean b) { this.priority = (b) ? 1 : 0; Debug.d(this, "setPriority", b, 4); } /** Set 'registered delivery' flag. * @see ie.omk.smpp.message.MsgFlags */ public void setRegistered(boolean b) { this.registered = b; Debug.d(this, "setRegistered", b, 4); } /** Set 'replace if present'. * @see ie.omk.smpp.message.MsgFlags */ public void setReplaceIfPresent(boolean b) { this.replaceIfPresent = b; Debug.d(this, "setReplaceIfPresent", b, 4); } /** Set the esm class of the message. * @see ie.omk.smpp.message.MsgFlags * @see ie.omk.smpp.util.GSMConstants */ public void setEsmClass(int c) { this.esmClass = c; Debug.d(this, "setEsmClass", c, 4); } /** Set the protocol Id in the message flags. * @see ie.omk.smpp.message.MsgFlags * @see ie.omk.smpp.util.GSMConstants * @deprecated ie.omk.smpp.message.SMPPPacket#setProtocolID */ public void setProtocolId(int id) { this.protocolID = id; Debug.d(this, "setProtocolId", id, 4); } /** Set the GSM protocol ID. * @see ie.omk.smpp.message.MsgFlags * @see ie.omk.smpp.util.GSMConstants */ public void setProtocolID(int id) { this.protocolID = id; Debug.d(this, "setProtocolID", id, 4); } /** Set the GSM data coding of the message. * @see ie.omk.smpp.message.MsgFlags * @see ie.omk.smpp.util.GSMConstants */ public void setDataCoding(int dc) { this.dataCoding = dc; Debug.d(this, "setDataCoding", dc, 4); } /** Set the default message id in the message flags. * @see ie.omk.smpp.message.MsgFlags */ public void setDefaultMsg(int id) { this.defaultMsg = id; Debug.d(this, "setDefaultMsg", id, 4); } /** Get the message flags. * @return The ie.omk.smpp.message.MsgFlags object. Never null. * @deprecated */ public MsgFlags getMessageFlags() { MsgFlags flags = new MsgFlags();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -