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

📄 sipprovider.java

📁 基于MJSIP的j2me客户端
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      // start udp
      if (transport_udp)
      {  try
         {  if (host_ipaddr==null) udp=new UdpTransport(host_port,this);
            else udp=new UdpTransport(host_port,host_ipaddr,this);
            printLog("udp is up",LogLevel.MEDIUM);
         }
         catch (Exception e)
         {  printException(e,LogLevel.HIGH);
         }
      }
      // start tcp
      if (transport_tcp)
      {  try
         {  if (host_ipaddr==null) tcp_server=new TcpServer(host_port,this);
            else tcp_server=new TcpServer(host_port,host_ipaddr,this);
            printLog("tcp is up",LogLevel.MEDIUM);
         }
         catch (Exception e)
         {  printException(e,LogLevel.HIGH);
         }
      }
      //printLog("transport is up",LogLevel.MEDIUM);
   }

   
   /** Stops the transport services. */ 
   private void stopTrasport()
   {  
      // stop udp
      if (udp!=null)
      {  printLog("udp is going down",LogLevel.LOWER);
         udp.halt();
         udp=null;
      }
      // stop tcp
      if (tcp_server!=null)
      {  printLog("tcp is going down",LogLevel.LOWER);
         tcp_server.halt();
         tcp_server=null;
      }
      if (connections!=null)
      {  printLog("connections are going down",LogLevel.LOWER);
         for (Enumeration e=connections.elements(); e.hasMoreElements(); )
         {  ConnectedTransport c=(ConnectedTransport)e.nextElement();
            c.halt();
         }
         connections=null;
      }
   }

   /** Stops the SipProviders. */ 
   public void halt()
   {  printLog("halt: SipProvider is going down",LogLevel.MEDIUM);
      stopTrasport();
      listeners=new Hashtable();
      exception_listeners=new HashSet();
   }


   /** Parses a single line (loaded from the config file) */
   public void parseLine(String line)
   {  String attribute;
      Parser par;
      int index=line.indexOf("=");
      if (index>0) {  attribute=line.substring(0,index).trim(); par=new Parser(line,index+1);  }
      else {  attribute=line; par=new Parser("");  }
      char[] delim={' ',','};
      
      if (attribute.equals("via_addr")) {  via_addr=par.getString(); return;  }
      if (attribute.equals("host_port")) {  host_port=par.getInt(); return; }
      if (attribute.equals("host_ifaddr")) {  host_ifaddr=par.getString(); return;  }
      if (attribute.equals("transport_protocols")) {  transport_protocols=par.getWordArray(delim); return;  }
      if (attribute.equals("nmax_connections")) {  nmax_connections=par.getInt(); return;  }
      if (attribute.equals("outbound_proxy"))
      {  String soaddr=par.getString();
         if (soaddr==null || soaddr.length()==0 || soaddr.equalsIgnoreCase(Configure.NONE) || soaddr.equalsIgnoreCase("NO-OUTBOUND")) outbound_proxy=null;
         else outbound_proxy=new SocketAddress(soaddr);
         return;
      }
      if (attribute.equals("log_all_packets")) { log_all_packets=(par.getString().toLowerCase().startsWith("y")); return; }

      // old parameters
      if (attribute.equals("host_addr")) System.err.println("WARNING: parameter 'host_addr' is no more supported; use 'via_addr' instead.");
      if (attribute.equals("all_interfaces")) System.err.println("WARNING: parameter 'all_interfaces' is no more supported; use 'host_iaddr' for setting a specific interface or let it undefined.");
      if (attribute.equals("use_outbound")) System.err.println("WARNING: parameter 'use_outbound' is no more supported; use 'outbound_proxy' for setting an outbound proxy or let it undefined.");
      if (attribute.equals("outbound_addr"))
      {  System.err.println("WARNING: parameter 'outbound_addr' has been deprecated; use 'outbound_proxy=<host_addr>[:<host_port>]' instead.");
         outbound_addr=par.getString();
         return;
      }
      if (attribute.equals("outbound_port"))
      {  System.err.println("WARNING: parameter 'outbound_port' has been deprecated; use 'outbound_proxy=<host_addr>[:<host_port>]' instead.");
         outbound_port=par.getInt();
         return;
      }
   }  


   /** Converts the entire object into lines (to be saved into the config file) */
   protected String toLines()
   {  // currently not implemented..
      return toString();
   }


   /** Gets a String with the list of transport protocols. */ 
   private String transportProtocolsToString()
   {  String list=transport_protocols[0];
      for (int i=1; i<transport_protocols.length; i++) list+="/"+transport_protocols[i];
      return list;
   }


   // ************************** Public methods *************************

   /** Gets via address. */ 
   public String getViaAddress()
   {  return via_addr;
   }    
   
   /** Sets via address. */ 
   /*public void setViaAddress(String addr)
   {  via_addr=addr;
   }*/   

   /** Gets host port. */ 
   public int getPort()
   {  return host_port;
   }       

   /** Whether binding the sip provider to all interfaces or only on the specified host address. */
   public boolean isAllInterfaces()
   {  return host_ipaddr==null;
   }       

   /** Gets host interface IpAddress. */ 
   public IpAddress getInterfaceAddress()
   {  return host_ipaddr;
   }    
   
   /** Gets array of transport protocols. */ 
   public String[] getTransportProtocols()
   {  return transport_protocols;
   }    
   
   /** Gets the default transport protocol. */ 
   public String getDefaultTransport()
   {  return default_transport;
   } 
   
   /** Gets the default transport protocol. */ 
   public void setDefaultTransport(String proto)
   {  default_transport=proto;
   }    

   /** Sets rport support. */ 
   public void setRport(boolean flag)
   {  rport=flag;
   }   

   /** Whether using rport. */ 
   public boolean isRportSet()
   {  return rport;
   }   

   /** Sets 'force-rport' mode. */ 
   public void setForceRport(boolean flag)
   {  force_rport=flag;
   }   

   /** Whether using 'force-rport' mode. */ 
   public boolean isForceRportSet()
   {  return force_rport;
   }   

   /** Whether has outbound proxy. */ 
   public boolean hasOutboundProxy()
   {  return outbound_proxy!=null;
   }    

   /** Gets the outbound proxy. */ 
   public SocketAddress getOutboundProxy()
   {  return outbound_proxy;
   }    

   /** Sets the outbound proxy. Use 'null' for not using any outbound proxy. */ 
   public void setOutboundProxy(SocketAddress soaddr)
   {  outbound_proxy=soaddr;
   }

   /** Removes the outbound proxy. */ 
   /*public void removeOutboundProxy()
   {  setOutboundProxy(null);
   }*/

   /** Gets the max number of (contemporary) open connections. */ 
   public int getNMaxConnections()
   {  return nmax_connections;
   }    

   /** Sets the max number of (contemporary) open connections. */ 
   public void setNMaxConnections(int n)
   {  nmax_connections=n;
   }    
      
            
   /** Gets event log. */ 
   public Log getLog()
   {  return event_log;
   }    
   

   /** Returns the list (Hashtable) of active listener_IDs. */ 
   public Hashtable getListeners()
   {  return listeners;
   }   


   /** Adds a new listener to the SipProvider for caputering any message in PROMISQUE mode.
     * It is the same as using method addSipProviderListener(SipProvider.PROMISQUE,listener).
     * <p/>
     * When capturing messages in promisque mode all messages are passed to the SipProviderListener
     * before passing them to the specific listener (if present).
     * <br/> Note that more that one SipProviderListener can be active in promisque mode
     * at the same time;in that case the same message is passed to all PROMISQUE
     * SipProviderListeners.
     * @param listener is the SipProviderListener.
     * @return It returns <i>true</i> if the SipProviderListener is added,
     * <i>false</i> if the listener_ID is already in use. */
   public boolean addSipProviderPromisqueListener(SipProviderListener listener)
   {  return addSipProviderListener(PROMISQUE,listener);
   }

   /** Adds a new listener to the SipProvider for caputering ANY message.
     * It is the same as using method addSipProviderListener(SipProvider.ANY,listener).
     * @param listener is the SipProviderListener.
     * @return It returns <i>true</i> if the SipProviderListener is added,
     * <i>false</i> if the listener_ID is already in use. */
   public boolean addSipProviderListener(SipProviderListener listener)
   {  return addSipProviderListener(ANY,listener);
   }

   /** Adds a new listener to the SipProvider.
     * @param id is the unique identifier for the messages which the listener
     * as to be associated to. It is used as key.
     * It can identify a method, a transaction, or a dialog.
     * Use SipProvider.ANY to capture all messages.
     * Use SipProvider.PROMISQUE if you want to capture all message in promisque mode
     * (letting other listeners to capture the same received messages).
     * @param listener is the SipProviderListener for this message id.
     * @return It returns <i>true</i> if the SipProviderListener is added,
     * <i>false</i> if the listener_ID is already in use. */
   public boolean addSipProviderListener(Identifier id, SipProviderListener listener)
   {  printLog("adding SipProviderListener: "+id,LogLevel.MEDIUM);
      boolean ret;
      Identifier key=id;
      if (listeners.containsKey(key))
      {  printWarning("trying to add a SipProviderListener with a id that is already in use.",LogLevel.HIGH);
         ret=false;
      }
      else
      {  listeners.put(key,listener);
         ret=true;
      }
      
      if (listeners!=null)
      {  String list="";
         for (Enumeration e=listeners.keys(); e.hasMoreElements();) list+=e.nextElement()+", ";
         printLog(listeners.size()+" listeners: "+list,LogLevel.LOW);
      }
      return ret;
   }


   /** Removes a SipProviderListener.
     * @param id is the unique identifier used to select the listened messages.
     * @return It returns <i>true</i> if the SipProviderListener is removed,
     * <i>false</i> if the  identifier is missed. */
   public boolean removeSipProviderListener(Identifier id)
   {  printLog("removing SipProviderListener: "+id,LogLevel.MEDIUM);
      boolean ret;
      Identifier key=id;
      if (!listeners.containsKey(key))
      {  printWarning("trying to remove a missed SipProviderListener.",LogLevel.HIGH);
         ret=false;
      }
      else
      {  listeners.remove(key);
         ret=true;
      }
      
      if (listeners!=null)
      {  String list="";
         for (Enumeration e=listeners.keys(); e.hasMoreElements();) list+=e.nextElement()+", ";
         printLog(listeners.size()+" listeners: "+list,LogLevel.LOW);
      }
      return ret;
   }

  
   /** Sets the SipProviderExceptionListener.
     * The SipProviderExceptionListener is the listener for all exceptions
     * thrown by the SipProviders.
     * @param e_listener is the SipProviderExceptionListener.
     * @return It returns <i>true</i> if the SipProviderListener has been correctly set,
     * <i>false</i> if the SipProviderListener was already set. */
   public boolean addSipProviderExceptionListener(SipProviderExceptionListener e_listener)

⌨️ 快捷键说明

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