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

📄 presenceserver.java

📁 The source code for this package is located in src/gov/nist/sip/proxy. The proxy is a pure JAIN-SIP
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                sipProvider.sendResponse(response);                return;            }                        Dialog dialog = serverTransaction.getDialog();            if(dialog == null) {                responseCode = Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST;                response = messageFactory.createResponse(responseCode, notify);                serverTransaction.sendResponse(response);                return;            }                        //Send to presentityManager            responseCode = presentityManager.processNotify(notify, dialog);                        //Reply to notifier            response = messageFactory.createResponse(responseCode,notify);            serverTransaction.sendResponse(response);                        logger.debug("processNotifyRequest(), response sent:" +            response.toString());                                }        catch (Exception e) {            e.printStackTrace();        }    }                    //*****************************    //   RESPONSE PROCESSING    //*****************************                    /** If the response is not a class 2xx response, we might want to try again or terminate     *  all subscriptions to this UA. Otherwise hand over the recently created dialog to     *  the presentityManager.     */    public void processSubscribeResponse(Response response, ClientTransaction clientTransaction) {                if (logger.isDebugEnabled()) {            logger.debug("PresenceServer:processSubscribeResponse: received a response\n" + response);        }                try {                    } catch(Exception e) {            e.printStackTrace();        }    }                /** Do nothing?     *     */    public void processNotifyResponse(Response response, ClientTransaction clientTransaction) {                if (logger.isDebugEnabled()) {            logger.debug("PresenceServer:processNotifyResponse: received a response\n" + response);        }                try {                    } catch(Exception e) {            e.printStackTrace();        }    }                    //*****************************    //   SEND METHODS    //*****************************            /**     *  Sends an options request to the UA     */    protected void sendOptionsRequest(String toURI) {            }                        /**     *  Sends an Subscribe request to an external ESC     *     */    protected void sendSubscribeRequest(String toURI,    int expires, Dialog dialog) {            }            protected void sendNotifyRequest(Subscriber subscriber) {                if (logger.isDebugEnabled()) {            logger.debug("PresenceServer:sendNotifyRequest to " +            subscriber.getSubscriberURL());        }        try {                        HeaderFactory hf        = proxy.getHeaderFactory();            MessageFactory mf       = proxy.getMessageFactory();            Dialog dialog           = subscriber.getDialog();                        if(dialog == null) {                logger.debug("PresenceServer:sendNotifyRequest: dialog doesn't exist, nothing sent");                return;            }                        //First perform some checks            String subscriptionState = subscriber.getSubscriptionState();            String notifyBody = subscriber.removeNotifyBody();                        if(notifyBody==null || notifyBody.equals("")) {                if (!subscriptionState.equalsIgnoreCase("terminated")) {                    logger.debug                    ("PresenceServer:sendNotifyRequest: " +                    "   NotifyBody is null \n" +                    "   subscriptionState = " + subscriptionState +                    "   Nothing sent");                    return;                }            }                                                //Create the Notify request and add som headers            Request notify = dialog.createRequest(Request.NOTIFY);                        //Add Event Header            notify.addHeader(hf.createEventHeader("presence"));                        //Create SubscriptionState Header (add later)            SubscriptionStateHeader ssH =            hf.createSubscriptionStateHeader(subscriptionState);                        if ((subscriptionState.equalsIgnoreCase(SubscriptionStateHeader.ACTIVE)) ||            (subscriptionState.equalsIgnoreCase(SubscriptionStateHeader.PENDING))) {                                //Add expires parameter to Subscription state header                ssH.setExpires(subscriber.getExpiresTime());                                //Add Presence-info and Content-Type Header.                //The media type should be derived from the Registration request                ContentTypeHeader ctH = hf.createContentTypeHeader("application", "pidf+xml");                notify.setContent(notifyBody, ctH);                                //Add Authorization Header?            } else {                logger.debug("subscription state is " +                subscriptionState);            }                        //Add SubscriptionStateHeader            notify.addHeader(ssH);                        ClientTransaction clientTransaction =            proxy.getSipProvider().getNewClientTransaction(notify);                        //Send Notify            dialog.sendRequest(clientTransaction);                        if(logger.isDebugEnabled()) {                logger.debug("PresenceServer:sendNotifyRequest. Request sent: \n" + notify.toString());            }                                } catch(Exception e) {            e.printStackTrace();        }    }                        //*****************************    //   GETTERS & SETTERS    //*****************************            public PresentityManager getPresentityManager() {        return presentityManager;    }            public int getExpiresTime() {        return expiresTime;    }        /**     *  returns true if the notifier of this subscription     *  is publishing it's state here and if the subscriber     *  understands pidf+xml (modify if the server starts handling     *  new formats)     *  <h3ToDo</h3><ul>     *    <li>Should not only check if the notifier is registered, but if he actually     *        is publishing his state info, instead of assuming it. This means that the     *        registrations in registrations.xml must indicate this.</li>     *   </ul>     **/    public boolean isStateAgent(Request request) {        String notifierKey = getKey(request, "To");                if (presentityManager.hasNotifier(notifierKey)) {            if(request.getMethod().equalsIgnoreCase("PUBLISH") ) {                return true;            } else if(request.getMethod().equals(Request.SUBSCRIBE) ) {                //Check acceptheaders for "application/pidf+xml, else forward                Iterator  acceptHeaders = request.getHeaders(AcceptHeader.NAME);                while (acceptHeaders.hasNext()) {                    AcceptHeader acceptHeader = (AcceptHeader)acceptHeaders.next();                    if(acceptHeader.getContentType().equals("application") &&                    acceptHeader.getContentSubType().equals("pidf+xml"))                        return true;                }                return false;            }        }   else {            logger.debug("could not find notifier record for "            + notifierKey);            return false;        }        return false;    }        /** Returns true if the registration records the from header as being a buddy. So OK     * to report that buddy has not yet registered.     */    public boolean isBuddy( Request request ) {        String notifierKey = getKey(request, "To");        if (proxy.getRegistrar().hasRegistration(notifierKey)) {            Registration registration = proxy.getRegistrar().getRegistration(notifierKey);            String subscriberKey = getKey(request,"From");            if (registration.isMyBuddy(subscriberKey)) return true;            else return false;        }  else return false;    }                //*****************************    //   UTILITY METHODS    //*****************************                    /**     * Returns the value of a named header     * @author deruelle     */    private  String getKey(Message message,String header) {        try{            Address address=null;            if (header.equals("From") ) {                FromHeader fromHeader=(FromHeader)                message.getHeader(FromHeader.NAME);                address=fromHeader.getAddress();                            }            else                if (header.equals("To") ) {                    ToHeader toHeader=(ToHeader)message.getHeader(ToHeader.NAME);                    address=toHeader.getAddress();                                    }                        javax.sip.address.URI cleanedUri=null;            if (address==null) {                cleanedUri= getCleanUri( ((Request)message).getRequestURI());            }            else {                // We have to build the key, all                // URI parameters MUST be removed:                cleanedUri = getCleanUri(address.getURI());            }                        if (cleanedUri==null) return null;                        String  keyresult=cleanedUri.toString();            logger.debug("DEBUG, PresenceServer, getKey(), the key is: " +            keyresult);            return keyresult.toLowerCase();                    }        catch(Exception e) {            e.printStackTrace();            return null;        }    }            /**     * Helper for getKey. Removes parameters from URI     * @author deruelle     */    private static URI getCleanUri(URI uri) {        if (uri instanceof SipURI) {            SipURI sipURI=(SipURI)uri.clone();                        Iterator iterator=sipURI.getParameterNames();            while (iterator!=null && iterator.hasNext()) {                String name=(String)iterator.next();                sipURI.removeParameter(name);            }            return  sipURI;        }        else return  uri;    }            /** Stop the presentity manager.     */    public void stop() {        this.presentityManager.stop();    }        //*****************************    //   OLD METHODS    //    // Required by other parts of the proxy    // Should deprecate.    //*****************************            /**     *  This is only here because RequestValidation.java and the Registrar needs it.     *  Should deprecate.     *  @return True only if authorization gives 200 OK     */    public boolean hasAuthorization(Request request) {        //everybody is accepted for now. Note that we can get into a        // conflict with method authorize() if we're not careful        return true;    }                    }

⌨️ 快捷键说明

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