📄 registrar.java
字号:
/* * Registrar.java * * Created on June 27, 2002, 11:16 AM */package gov.nist.examples.bps.registrar;import javax.sip.*;import javax.sip.message.*; import javax.sip.header.*;import javax.sip.address.*;import java.util.*;import gov.nist.examples.bps.gateway.*;/** * * @author deruelle * @version 1.0 */public class Registrar { protected RegistrationsTable registrationsTable; // in seconds public static int EXPIRES_TIME_MIN=1; public static int EXPIRES_TIME_MAX=36000; protected String xmlRegistrationsFile; protected Gateway gateway; /** * Creates new Registrar */ public Registrar(Gateway gateway) { registrationsTable=new RegistrationsTable(this); this.gateway=gateway; } public void setExpiresTime(int expiresTime) { EXPIRES_TIME_MAX=expiresTime; } public RegistrationsTable getRegistrationsTable() { return registrationsTable; } /** Process the register message: add, remove, update the bindings * and manage also the expiration time. * @param Request Register message to set * @return int status code of the process of the Register. */ public synchronized void processRegister(Request request, SipProvider sipProvider, ServerTransaction serverTransaction ) { try{ MessageFactory messageFactory=gateway.getMessageFactory(); String key=getKey(request); // Add the key if it is a new user: if (GatewayDebug.debug){ GatewayDebug.println ("Registrar, processRegister(), key: \""+key+"\""); } if (key==null){ if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), key is null"+ " 400 INVALID REQUEST replied"); } Response response=messageFactory.createResponse (Response.BAD_REQUEST,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); return ; } // RFC 3261: 10.3: /* 6. The registrar checks whether the request contains the Contact header field. If not, it skips to the last step. If the Contact header field is present, the registrar checks if there is one Contact field value that contains the special value "*" and an Expires field. If the request has additional Contact fields or an expiration time other than zero, the request is invalid, and the server MUST return a 400 (Invalid Request) and skip the remaining steps. If not, the registrar checks whether the Call-ID agrees with the value stored for each binding. If not, it MUST remove the binding. If it does agree, it MUST remove the binding only if the CSeq in the request is higher than the value stored for that binding. Otherwise, the update MUST be aborted and the request fails. */ if ( !hasContactHeaders(request) ) { Vector contactHeaders=getContactHeaders(key); Response response=messageFactory.createResponse (Response.OK,request); if ( contactHeaders!=null ) { for (int i = 0 ; i < contactHeaders.size(); i++) { ContactHeader contact = (ContactHeader) contactHeaders.elementAt(i); response.addHeader(contact); } } if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"+response.toString()); } return; } // bug report by Alistair Coles if ( hasStar(request) ) { Vector contactHeaders=getContactHeaders(key); if (contactHeaders.size()>1) { if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), more than one contact header"+ " is present at the same time as a wild card."+ " 400 INVALID REQUEST replied"); } Response response=messageFactory.createResponse (Response.BAD_REQUEST,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"); GatewayDebug.print(response.toString()); } return ; } if ( !hasExpiresZero(request) ) { if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), expires time different from"+ " 0 with a wild card."+ " 400 INVALID REQUEST replied"); } Response response=messageFactory.createResponse (Response.BAD_REQUEST,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"); GatewayDebug.print(response.toString()); } return ; } if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), (* and expires=0) "+ " we remove the registration!!"); } registrationsTable.removeRegistration(key); Response response=messageFactory.createResponse (Response.OK,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"); GatewayDebug.print(response.toString()); } return; } if ( registrationsTable.hasRegistration(key) ) { registrationsTable.updateRegistration(key,request); Vector contactHeaders=getContactHeaders(key); Response response= messageFactory.createResponse(Response.OK,request); if ( contactHeaders!=null ) { for (int i = 0; i < contactHeaders.size(); i++) { ContactHeader contact = (ContactHeader) contactHeaders.elementAt(i); response.addHeader(contact); } } if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"); GatewayDebug.print(response.toString()); } } else { // Let's check the Expires header: if ( hasExpiresZero(request) ) { // This message is lost.... GatewayDebug.println("Registrar, processRegister(), "+ "we don't have any record for this REGISTER."); Response response=messageFactory.createResponse (Response.OK,request); if (serverTransaction!=null) serverTransaction.sendResponse(response); else sipProvider.sendResponse(response); if (GatewayDebug.debug) { GatewayDebug.println ("Registrar, processRegister(), response sent:"); GatewayDebug.print(response.toString()); } return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -