⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smpp.java

📁 today bought a book, reflected good to upload source code package. 1. Based on the struts of custome
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// FrontEnd Plus for JAD
// DeCompiled : Smpp.class

package sms;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import utils.*;

// Referenced classes of package sms:
//            SMSException, smppEncoder, smppRequest, smDL, 
//            smDLModification, queryAll, smppDispatcher, param, 
//            smppHeader, Message, Binding, smppSyncResponse, 
//            smppCommands, Errors, Receiver, AddCustomerResponse, 
//            Customer, AddDLResponse, Address, AddMemberResponse, 
//            Member, CancelResponse, ListResponse, ParameterResponse, 
//            ModCustomerResponse, GetCustomerResponse, SendResponse, BindResponse, 
//            GetDLResponse, GetMemberResponse, DetailsResponse, ReplaceResponse, 
//            StatusResponse, DelCustomerResponse, DelDLResponse, DelMemberResponse

public class Smpp extends semaphore
    implements smppCommands, Errors
{

    public static boolean encryption;
    private String cr;
    Receiver receiverTarget;
    private boolean debugon;
    private int lastSequenceNumber;
    private OutputStream out;
    Socket socket;
    fifo pendingRequests;
    table pendingResponses;
    private static String smscHost;
    private static int smscPort;
    private int bindtype;
    smppDispatcher dispatcher;
    boolean disconnected;
    int disconnectedError;

    public void add(AddCustomerResponse addcustomerresponse, Customer customer)
        throws SMSException, IOException
    {
        if(customer == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        try
        {
            smppencoder.addCustomer(customer);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(17, customer, addcustomerresponse), smppencoder);
    }

    public void add(Customer customer)
        throws SMSException, IOException
    {
        add(null, customer);
        getSyncResponse();
    }

    public void add(AddDLResponse adddlresponse, Address address, String s)
        throws SMSException, IOException
    {
        if(address == null || s == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        smDL smdl = new smDL();
        smdl.source = address;
        smdl.name = s;
        try
        {
            smppencoder.addDL(smdl);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(22, smdl, adddlresponse), smppencoder);
    }

    public void add(Address address, String s)
        throws SMSException, IOException
    {
        add(null, address, s);
        getSyncResponse();
    }

    public void add(AddMemberResponse addmemberresponse, Address address, String s, Member member)
        throws SMSException, IOException
    {
        if(address == null || s == null || member == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        smDLModification smdlmodification = new smDLModification(address, s, member, false);
        try
        {
            smppencoder.modDL(smdlmodification);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(23, smdlmodification, addmemberresponse), smppencoder);
    }

    public void add(Address address, String s, Member member)
        throws SMSException, IOException
    {
        add(null, address, s, member);
        getSyncResponse();
    }

    private void log(String s)
    {
        if(debugon)
            System.out.println("" + Thread.currentThread() + "  SENDER " + s);
    }

    public void cancel(CancelResponse cancelresponse, Message message)
        throws SMSException, IOException
    {
        if(message == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        try
        {
            smppencoder.cancel(message);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(8, message, cancelresponse), smppencoder);
    }

    public void cancel(Message message)
        throws IOException, SMSException
    {
        cancel(null, message);
        getSyncResponse();
    }

    public Smpp(String s, int i)
        throws UnknownHostException, IOException, socksException
    {
        super("SMPP");
        cr = "$Id: SMS JDK (tm) Version 2.0.1 Copyright (C) 1998 Noctor Consulting Limited. $";
        smppInit(s, i);
    }

    public Smpp()
        throws UnknownHostException, IOException, socksException, SMSException
    {
        super("SMPP");
        cr = "$Id: SMS JDK (tm) Version 2.0.1 Copyright (C) 1998 Noctor Consulting Limited. $";
        if(smscHost == null || smscPort == 0)
        {
            throw new SMSException(10001);
        } else
        {
            smppInit(smscHost, smscPort);
            return;
        }
    }

    public void list(ListResponse listresponse, Address address, int i)
        throws SMSException, IOException
    {
        if(i <= 0)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        queryAll queryall = new queryAll();
        queryall.source = address;
        queryall.count = (byte)i;
        try
        {
            smppencoder.queryAll(queryall);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(35, address, listresponse), smppencoder);
    }

    private void putRequest(smppRequest smpprequest, smppEncoder smppencoder)
        throws SMSException, IOException
    {
        if(debugon)
            log("Sending packet... " + Thread.currentThread());
        if(smppencoder == null)
        {
            sendPacket(smpprequest, null);
        } else
        {
            if(debugon)
                log("INCLUDED BODY: " + smppencoder);
            sendPacket(smpprequest, smppencoder.getBytes());
        }
        if(debugon)
            log("sent packet");
        if(smpprequest.thread != null)
        {
            if(smpprequest.thread.equals(dispatcher.dispatcherThread))
            {
                if(debugon)
                    log("Sending from dispatcher thread");
                try
                {
                    dispatcher.smppDispatch(smpprequest.sequenceNumber);
                    return;
                }
                catch(decoderException decoderexception)
                {
                    throw new IOException("protocol error:" + decoderexception);
                }
                catch(encoderException encoderexception)
                {
                    throw new SMSException(encoderexception);
                }
            }
            if(debugon)
                log("Suspending until response is received");
            Thread thread = Thread.currentThread();
            try
            {
                while(pendingResponses.get(thread) == null) 
                    Thread.yield();
            }
            catch(InterruptedException _ex) { }
            if(debugon)
                log("Suspend over");
        }
    }

    public String[] list(Address address, int i)
        throws SMSException, IOException
    {
        list(null, address, i);
        String as[] = (String[])getSyncResponse();
        return as;
    }

    public void parameter(ParameterResponse parameterresponse, String s)
        throws SMSException, IOException
    {
        if(s == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        param param1 = new param();
        param1.name = s;
        try
        {
            smppencoder.paramGet(param1);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(34, param1, parameterresponse), smppencoder);
    }

    public String parameter(String s)
        throws SMSException, IOException
    {
        parameter(null, s);
        return (String)getSyncResponse();
    }

    public void mod(ModCustomerResponse modcustomerresponse, Customer customer)
        throws SMSException, IOException
    {
        if(customer == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        try
        {
            smppencoder.modifyCustomer(customer);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(19, customer, modcustomerresponse), smppencoder);
    }

    public void mod(Customer customer)
        throws SMSException, IOException
    {
        mod(null, customer);
        getSyncResponse();
    }

    public void checkLink()
        throws SMSException, IOException
    {
        putRequest(new smppRequest(21, null, null), null);
        getSyncResponse();
    }

    private synchronized void sendPacket(smppRequest smpprequest, byte abyte0[])
        throws SMSException, IOException
    {
        try
        {
            if(debugon)
                log(" *** USE");
            use();
            if(debugon)
                log(" *** USING");
            if(disconnected)
                throw new SMSException(disconnectedError);
            if(bindtype == 0)
                throw new SMSException(10002);
            if(smpprequest.command == 6)
            {
                bindtype = 0;
                disconnected = true;
                disconnectedError = 10009;
            }
            if(smpprequest.target == null)
                smpprequest.thread = Thread.currentThread();
            if(bindtype == 1 && smpprequest.command != 1 && smpprequest.command != 6 && smpprequest.command != 21)
                throw new SMSException(10003);
            smppHeader smppheader = new smppHeader();
            if((smpprequest.command & 0x80000000) == 0)
            {
                lastSequenceNumber++;
                smppheader.sequence = lastSequenceNumber;
            }
            smppheader.command = smpprequest.command;
            smppheader.status = 0;
            if(abyte0 == null)
                smppheader.length = 16;
            else
                smppheader.length = 16 + abyte0.length;
            smpprequest.sequenceNumber = smppheader.sequence;
            if((smpprequest.command & 0x80000000) == 0)
                pendingRequests.push(smpprequest);
            smppEncoder smppencoder = new smppEncoder();
            try
            {
                smppencoder.smppHeader(smppheader);
            }
            catch(encoderException encoderexception)
            {
                throw new SMSException(encoderexception);
            }
            if(debugon)
                log("HEADER: " + smppencoder);
            byte abyte1[] = smppencoder.getBytes();
            byte abyte2[];
            if(abyte0 != null)
                abyte2 = new byte[abyte1.length + abyte0.length];
            else
                abyte2 = new byte[abyte1.length];
            for(int i = 0; i < abyte1.length; i++)
                abyte2[i] = abyte1[i];

            if(abyte0 != null)
            {
                for(int j = 0; j < abyte0.length; j++)
                    abyte2[j + abyte1.length] = abyte0[j];

            }
            out.write(abyte2);
        }
        catch(IOException _ex)
        {
            bindtype = 0;
            disconnected = true;
            disconnectedError = 10010;
            throw new IOException("SMSC Connection closed (remotely)");
        }
        catch(InterruptedException _ex)
        {
            throw new SMSException(10011);
        }
        finally
        {
            if(debugon)
                log("*** FINISH");
            finished();
            if(debugon)
                log("*** FINISHED");
        }
    }

    public void get(GetCustomerResponse getcustomerresponse, Customer customer)
        throws SMSException, IOException
    {
        if(customer == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        try
        {
            smppencoder.getCustomer(customer);
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
        putRequest(new smppRequest(20, customer, getcustomerresponse), smppencoder);
    }

    public void send(SendResponse sendresponse, Message message)
        throws SMSException, IOException
    {
        if(message == null)
            throw new SMSException(10014);
        smppEncoder smppencoder = new smppEncoder();
        try
        {
            if(message.recipients != null)
            {
                smppencoder.submitMulti(message);
                putRequest(new smppRequest(33, message, sendresponse), smppencoder);
                return;
            }
            if(debugon)
                log("encoding");
            smppencoder.submit(message);
            if(debugon)
                log("new request");
            smppRequest smpprequest = new smppRequest(4, message, sendresponse);
            if(debugon)
                log("put request");
            putRequest(smpprequest, smppencoder);
            if(debugon)
            {
                log("put request done");
                return;
            }
        }
        catch(encoderException encoderexception)
        {
            throw new SMSException(encoderexception);
        }
    }

    public void send(Message message)
        throws SMSException, IOException
    {
        send(null, message);
        getSyncResponse();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -