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

📄 registerprocessing.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * Large portions of this software are based upon public domain software
 * https://sip-communicator.dev.java.net/
 *
 */
package net.sourceforge.gjtapi.raw.sipprovider.sip;

import net.sourceforge.gjtapi.raw.sipprovider.common.Console;
import java.text.*;
import java.util.*;
import javax.sip.*;
import javax.sip.address.*;
import javax.sip.header.*;
import javax.sip.message.*;
import net.sourceforge.gjtapi.raw.sipprovider.sip.security.SipSecurityException;

/**
 * <p>Title: SIP COMMUNICATOR-1.1</p>
 * <p>Description: JAIN-SIP-1.1 Audio/Video Phone Application</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Organisation: LSIIT Laboratory (http://lsiit.u-strasbg.fr)</p>
 * <p>Network Research Team (http://www-r2.u-strasbg.fr))</p>
 * <p>Louis Pasteur University - Strasbourg - France</p>
 * @author Emil Ivov
 * @version 1.1
 */
public class RegisterProcessing
{
    private static final Console console =
        Console.getConsole(RegisterProcessing.class);
    private SipManager sipManCallback = null;
    private Request registerRequest = null;
    private boolean isRegistered = false;

    private Timer reRegisterTimer = new Timer();

    public RegisterProcessing(SipManager sipManCallback)
    {
        this.sipManCallback = sipManCallback;
    }

    void setSipManagerCallBack(SipManager sipManCallback)
    {
        this.sipManCallback = sipManCallback;
    }

    public void processOK(ClientTransaction clientTransatcion, Response response)
    {
        try {
            console.logEntry();
            isRegistered = true;
            FromHeader fromHeader =
                ( (FromHeader) response.getHeader(FromHeader.NAME));
            Address address = fromHeader.getAddress();
            ExpiresHeader expires = response.getExpires();
            //expires may be null
            //fix by Luca Bincoletto <Luca.Bincoletto@tilab.com>
            if (expires != null && expires.getExpires() == 0) {
                sipManCallback.fireUnregistered(address.toString());
            }
            else {
                sipManCallback.fireRegistered(address.toString());
            }
        }
        finally {
            console.logExit();
        }
    }

    public void processTimeout(Transaction transatcion, Request request)
    {
        try {
            console.logEntry();
            isRegistered = true;
            FromHeader fromHeader =
                ( (FromHeader) request.getHeader(FromHeader.NAME));
            Address address = fromHeader.getAddress();
            sipManCallback.fireUnregistered("Request timeouted for: " +
                                            address.toString());
        }
        finally {
            console.logExit();
        }

    }

    public void processNotImplemented(ClientTransaction transatcion, Response response)
    {
        try {
            console.logEntry();
            isRegistered = true;
            FromHeader fromHeader =
                ( (FromHeader) response.getHeader(FromHeader.NAME));
            Address address = fromHeader.getAddress();
            sipManCallback.fireUnregistered("Server returned NOT_IMPLEMENTED. "
                                            + address.toString());
        }
        finally {
            console.logExit();
        }

    }

    /**
     * Attempts to re-ogenerate the corresponding request with the proper
     * credentials and terminates the call if it fails.
     *
     * @param clientTransaction the corresponding transaction
     * @param response the challenge
     */
    public void processAuthenticationChallenge(ClientTransaction clientTransaction,
                                        Response response)
    {
        try {
            console.logEntry();

            Request register = clientTransaction.getRequest();

            Request reoriginatedRequest = null;

            ClientTransaction retryTran = sipManCallback.sipSecurityManager.
                handleChallenge(response,
                                clientTransaction.getBranchId(),
                                register);

            //Dialog dialog = clientTransaction.getDialog();


            retryTran.sendRequest();
			return;
        }
        catch (SipSecurityException exc) {
            sipManCallback.fireCommunicationsError(
                new CommunicationsException("Authorization failed!", exc));
        }
        catch (Exception exc) {
            sipManCallback.fireCommunicationsError(
                new CommunicationsException("Failed to resend a request "
                                            + "after a security challenge!",
                                            exc)
                );
        }
        finally {
            //tell the others we couldn't register
            Request register = clientTransaction.getRequest();

            sipManCallback.
                fireUnregistered(
                    ( (FromHeader) register.getHeader(FromHeader.NAME)).
                        getAddress().toString());
            console.logExit();
        }
    }


    public synchronized void register(String registrarAddress, int registrarPort,
                  String registrarTransport, int expires) throws
        CommunicationsException
    {
        try
        {
            console.logEntry();

            //From
            FromHeader fromHeader = sipManCallback.getFromHeader();
            Address fromAddress = fromHeader.getAddress();
            sipManCallback.fireRegistering(fromAddress.toString());
            //Request URI
            SipURI requestURI = null;
            try {
                requestURI = sipManCallback.addressFactory.createSipURI(null,
                    registrarAddress);
            }
            catch (ParseException ex) {
                console.error("Bad registrar address:" + registrarAddress, ex);
                throw new CommunicationsException(
                    "Bad registrar address:"
                    + registrarAddress,
                    ex);
            }
            catch (NullPointerException ex) {
            //Do not throw an exc, we should rather silently notify the user
            //	throw new CommunicationsException(
            //		"A registrar address was not specified!", ex);
                sipManCallback.fireUnregistered(fromAddress.getURI().toString() +
                                                " (registrar not specified)");
                return;
            }
            requestURI.setPort(registrarPort);
            try {
                requestURI.setTransportParam(registrarTransport);
            }
            catch (ParseException ex) {
                console.error(registrarTransport
                              + " is not a valid transport!", ex);
                throw new CommunicationsException(
                    registrarTransport + " is not a valid transport!", ex);
            }
            //Call ID Header
            CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
            //CSeq Header
            CSeqHeader cSeqHeader = null;
            try {
                cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1,
                    Request.REGISTER);
            }
            catch (ParseException ex) {
                //Should never happen
                console.error("Corrupt Sip Stack");
                Console.showError("Corrupt Sip Stack");
            }
            catch (InvalidArgumentException ex) {
                //Should never happen
                console.error("The application is corrupt");
                Console.showError("The application is corrupt!");

⌨️ 快捷键说明

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