📄 imuseragent.java
字号:
/* * InstantMessagingUserAgent.java * * Created on July 28, 2002, 8:23 AM */package gov.nist.sip.instantmessaging.presence;import javax.sip.*;import javax.sip.message.*; import javax.sip.header.*;import javax.sip.address.*;import java.util.*;import java.io.*;import gov.nist.sip.instantmessaging.*;import gov.nist.sip.instantmessaging.authentication.* ;/** * * @author olivier * @version 1.0 */public class IMUserAgent implements SipListener { private SipStack sipStack; private MessageFactory messageFactory; private AddressFactory addressFactory; private HeaderFactory headerFactory; private SipProvider sipProvider; private InstantMessagingGUI imGUI; private IMAckProcessing imAckProcessing; private IMRegisterProcessing imRegisterProcessing; private IMByeProcessing imByeProcessing; private IMSubscribeProcessing imSubscribeProcessing; private IMNotifyProcessing imNotifyProcessing; private IMInfoProcessing imInfoProcessing; private IMMessageProcessing imMessageProcessing; private ProxyAuthorizationHeader proxyAuthHeader; private PresenceManager presenceManager; private IMPublishProcessing imPublishProcessing; /** Creates new InstantMessagingUserAgent */ public IMUserAgent(InstantMessagingGUI imGUI) { this.imGUI=imGUI; imAckProcessing=new IMAckProcessing(this); imRegisterProcessing=new IMRegisterProcessing(this); imByeProcessing=new IMByeProcessing(this); imSubscribeProcessing=new IMSubscribeProcessing(this); imNotifyProcessing=new IMNotifyProcessing(this); imInfoProcessing=new IMInfoProcessing(this); imMessageProcessing=new IMMessageProcessing(this); imPublishProcessing=new IMPublishProcessing(this); presenceManager=new PresenceManager(this); proxyAuthHeader=null; } public PresenceManager getPresenceManager() { return presenceManager; } public IMAckProcessing getIMAckProcessing() { return imAckProcessing; } public IMRegisterProcessing getIMRegisterProcessing() { return imRegisterProcessing; } public IMByeProcessing getIMByeProcessing() { return imByeProcessing; } public IMSubscribeProcessing getIMSubscribeProcessing() { return imSubscribeProcessing; } public IMNotifyProcessing getIMNotifyProcessing() { return imNotifyProcessing; } public IMInfoProcessing getIMInfoProcessing() { return imInfoProcessing; } public IMMessageProcessing getIMMessageProcessing() { return imMessageProcessing; } public IMPublishProcessing getIMPublishProcessing() { return imPublishProcessing; } public SipStack getSipStack() { return sipStack; } public SipProvider getSipProvider() { return sipProvider; } public MessageFactory getMessageFactory() { return messageFactory; } public HeaderFactory getHeaderFactory() { return headerFactory; } public AddressFactory getAddressFactory() { return addressFactory; } public ProxyAuthorizationHeader getProxyAuthorizationHeader() { return proxyAuthHeader; } public String getRouterPath() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getRouterPath(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public String getOutputFile() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getOutputFile(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public String getProxyAddress() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getOutboundProxyAddress(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public int getProxyPort() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getOutboundProxyPort(); if (res==null || res.trim().equals("") ) { return -1; } else { try { int i=Integer.valueOf(res).intValue(); return i; } catch(Exception e) { return -1; } } } public String getRegistrarAddress() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getRegistrarAddress(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public int getRegistrarPort() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getRegistrarPort(); if (res==null || res.trim().equals("") ) { return -1; } else { try { int i=Integer.valueOf(res).intValue(); return i; } catch(Exception e) { return -1; } } } public String getIMAddress() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getIMAddress(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public int getIMPort() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getIMPort(); if (res==null || res.trim().equals("") ) { return -1; } else { try { int i=Integer.valueOf(res).intValue(); return i; } catch(Exception e) { return -1; } } } public String getIMProtocol() { ListenerInstantMessaging listenerIM= imGUI.getListenerInstantMessaging(); ConfigurationFrame configurationFrame=listenerIM.getConfigurationFrame(); String res=configurationFrame.getIMProtocol(); if (res==null || res.trim().equals("") ) { return null; } else return res.trim(); } public InstantMessagingGUI getInstantMessagingGUI() { return imGUI; } /*******************************************************************************//************ The methods for implementing the listener *************/ /*******************************************************************************/ public void processRequest(RequestEvent requestEvent) { try { Request request = requestEvent.getRequest(); Request requestCloned=(Request)request.clone(); ServerTransaction serverTransaction = requestEvent.getServerTransaction(); sipProvider = (SipProvider) requestEvent.getSource(); System.out.println ("\n\nRequest " + request.getMethod()+" received:\n" ); if (serverTransaction == null) serverTransaction = sipProvider.getNewServerTransaction(request); if (request.getMethod().equals(Request.ACK)) { imAckProcessing.processAck(requestCloned, serverTransaction); } else if (request.getMethod().equals(Request.BYE)) { imByeProcessing.processBye(requestCloned,serverTransaction); } else if (request.getMethod().equals("MESSAGE")) { imMessageProcessing.processMessage(requestCloned, serverTransaction); } else if (request.getMethod().equals("INFO")) { imInfoProcessing.processInfo(requestCloned,serverTransaction); } else if (request.getMethod().equals("SUBSCRIBE")) { imSubscribeProcessing.processSubscribe
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -