📄 proxy.java
字号:
" it matches the proxy"); routes.remove(); break; } } } } } /* If the Request-URI contains a maddr parameter, the proxy MUST check to see if its value is in the set of addresses or domains the proxy is configured to be responsible for. If the Request-URI has a maddr parameter with a value the proxy is responsible for, and the request was received using the port and transport indicated (explicitly or by default) in the Request-URI, the proxy MUST strip the maddr and any non-default port or transport parameter and continue processing as if those values had not been present in the request. */ URI requestURI=request.getRequestURI(); if (requestURI.isSipURI()) { SipURI requestSipURI=(SipURI)requestURI; if (requestSipURI.getMAddrParam()!=null ) { // The domain the proxy is configured to be responsible for is defined // by stack_domain parameter in the configuration file: if (configuration.hasDomain(requestSipURI.getMAddrParam())) { if (ProxyDebug.debug) ProxyDebug.println("Proxy, processRequest(),"+ " The maddr contains a domain we are responsible for,"+ " we remove the mAddr parameter from the original"+ " request"); // We have to strip the madr parameter: requestSipURI.removeParameter("maddr"); // We have to strip the port parameter: if (requestSipURI.getPort()!=5060 && requestSipURI.getPort()!=-1) { requestSipURI.setPort(5060); } // We have to strip the transport parameter: requestSipURI.removeParameter("transport"); } else { // The Maddr parameter is not a domain we have to take // care of, we pass this check... } } else { // No Maddr parameter, we pass this check... } } else { // No SipURI, so no Maddr parameter, we pass this check... } /******************************************************************************//************* 3. Determine target(s) for the request (Section 16.5) **********//*****************************************************************************/ /* The set of targets will either be predetermined by the contents of the request or will be obtained from an abstract location service. Each target in the set is represented as a URI. */ Vector targetURIList=new Vector(); URI targetURI; /* If the Request-URI of the request contains an maddr parameter, the * Request-URI MUST be placed into the target set as the only target * URI, and the proxy MUST proceed to Section 16.6. */ if (requestURI.isSipURI()) { SipURI requestSipURI=(SipURI)requestURI; if (requestSipURI.getMAddrParam()!=null ) { targetURI=requestURI; targetURIList.addElement(targetURI); if (ProxyDebug.debug) ProxyDebug.println("Proxy, processRequest(),"+ " the only target is the Request-URI (mAddr parameter)"); // 4. Forward the request statefully: requestForwarding.forwardRequest(targetURIList,sipProvider, request,serverTransaction,true); return; } } /* If the domain of the Request-URI indicates a domain this element is not responsible for, the Request-URI MUST be placed into the target set as the only target, and the element MUST proceed to the task of Request Forwarding (Section 16.6). */ if (requestURI.isSipURI()) { SipURI requestSipURI=(SipURI)requestURI; if ( !configuration.hasDomain(requestSipURI.getHost() ) ) { if (ProxyDebug.debug) ProxyDebug.println("Proxy, processRequest(),"+ " we are not responsible for the domain: Let's check if we have"+ " a registration for this domain from another proxy"); // We have to check if another proxy did not registered // to us, in this case we have to use the contacts provided // by the registered proxy to create the targets: if (registrar.hasDomainRegistered(request)) { targetURIList=registrar.getDomainContactsURI(request); if (targetURIList!=null && !targetURIList.isEmpty()) { if (ProxyDebug.debug) { ProxyDebug.println("Proxy, processRequest(), we have"+ " a registration for this domain from another proxy"); } // 4. Forward the request statefully: requestForwarding.forwardRequest(targetURIList,sipProvider, request,serverTransaction,true); return; } else { targetURIList=new Vector(); ProxyDebug.println("Proxy, processRequest(),"+ " we are not responsible for the domain: the only target"+ " URI is given by the request-URI"); targetURI=requestURI; targetURIList.addElement(targetURI); } } else { ProxyDebug.println("Proxy, processRequest(),"+ " we are not responsible for the domain: the only target"+ " URI is given by the request-URI"); targetURI=requestURI; targetURIList.addElement(targetURI); } // 4. Forward the request statelessly: requestForwarding.forwardRequest(targetURIList,sipProvider, request,serverTransaction,false); return; } else { ProxyDebug.println("Proxy, processRequest(),"+ " we are responsible for the domain... Let's find the contact..."); } } // we use a SIP registrar: if ( request.getMethod().equals(Request.REGISTER) ) { if (ProxyDebug.debug) ProxyDebug.println("Incoming request Register"); // we call the RegisterProcessing: registrar.processRegister (request,sipProvider,serverTransaction); //Henrik: let the presenceserver do some processing too if ( isPresenceServer()) { presenceServer.processRegisterRequest (sipProvider, request, serverTransaction); } return; } /* If we receive a subscription targeted to a user that * is publishing its state here, send to presence server */ if ( isPresenceServer() && (request.getMethod().equals(Request.SUBSCRIBE))) { ProxyDebug.println("Incoming request Subscribe"); if (presenceServer.isStateAgent(request)) { Request clonedRequest=(Request)request.clone(); presenceServer.processSubscribeRequest(sipProvider, clonedRequest, serverTransaction); } else { // Do we know this guy? targetURIList = registrar.getContactsURI(request); if (targetURIList == null ) { // If not respond that we dont know him. ProxyDebug.println ("Proxy: received a Subscribe request to " + " a user in our domain that was not found, " + " responded 404"); Response response= messageFactory.createResponse (Response.NOT_FOUND,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); return; } else { ProxyDebug.println ("Trying to forward subscribe to " + targetURIList.toString() + "\n" + request.toString()); requestForwarding.forwardRequest (targetURIList,sipProvider, request,serverTransaction,false); } } return; } /** Received a Notify. * TOADD: Check if it match active VirtualSubscriptions and update it **/ if ( isPresenceServer() && (request.getMethod().equals (Request.NOTIFY) )) { System.out.println("Incoming request Notify"); Response response=messageFactory.createResponse(481,request); response.setReasonPhrase("Subscription does not exist"); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); ProxyDebug.println ("Proxy: received a Notify request. Probably wrong, responded 481"); return; } if ( isPresenceServer() && ( request.getMethod().equalsIgnoreCase("PUBLISH"))) { System.out.println("Incoming request Publish"); ProxyDebug.println("Proxy: received a Publish request."); Request clonedRequest=(Request)request.clone(); if (presenceServer.isStateAgent(clonedRequest)) { ProxyDebug.println("PresenceServer.isStateAgent"); } else { ProxyDebug.println("PresenceServer is NOT StateAgent"); } if (presenceServer.isStateAgent(clonedRequest)) { presenceServer.processPublishRequest(sipProvider, clonedRequest, serverTransaction); } else { Response response=messageFactory.createResponse(Response.NOT_FOUND,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); } return; } // Forward to next hop but dont reply OK right away for the // BYE. Bye is end-to-end not hop by hop! if (request.getMethod().equals(Request.BYE) ) { if (serverTransaction == null) { if (ProxyDebug.debug) ProxyDebug.println ("Proxy, null server transactin for BYE"); return; } Dialog d = serverTransaction.getDialog(); TransactionsMapping transactionsMapping = (TransactionsMapping) d.getApplicationData(); Dialog peerDialog = (Dialog) transactionsMapping.getPeerDialog (serverTransaction); Request clonedRequest = (Request) request.clone(); FromHeader from = (FromHeader) clonedRequest.getHeader(FromHeader.NAME); from.removeParameter("tag"); ToHeader to = (ToHeader) clonedRequest.getHeader(ToHeader.NAME); to.removeParameter("tag"); ViaHeader via = this.getStackViaHeader(); clonedRequest.addHeader(via); if ( peerDialog.getState() != null ) { ClientTransaction newct = sipProvider.getNewClientTransaction (clonedRequest); transactionsMapping.addMapping(serverTransaction,newct); peerDialog.sendRequest(newct); return; } else { // the peer dialog is not yet established so bail out. // this is a client error - client is sending BYE // before dialog establishment. if (ProxyDebug.debug) ProxyDebug.println ("Proxy, bad dialog state - BYE dropped"); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -