📄 sipuri.java
字号:
/* * This file was derived from libdissipate, an open source SIP library. The original file * was modified on 1/23/2001. Please see * http://www.div8.net/dissipate for more information. * * Copyright (c) 2000 Billy Biggs <bbiggs@div8.net> * * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public * License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * *//** * class SipUri * * Class to parse and reference a complete SIP URI * * This code has been generated using C2J++ * C2J++ is based on Chris Laffra's C2J (laffra@watson.ibm.com) * Read general disclaimer distributed with C2J++ before using this code * For information about C2J++, send mail to Ilya_Tilevich@ibi.com */package org.mitre.jsip;import java.util.Random;public class SipUri extends GeneralUri{ /** * SipUri */ public SipUri() { clear(); } /** * SipUri * @param parseinput */ public SipUri(String parseinput) { clear(); if ( parseinput != null ) parseUri( parseinput ); } /** * isValid * @return bool */ public boolean isValid() { return isvalid; } /** * getSipPort * @return int */ public int getSipPort() { return 5060; } /** * getUserParamString * @param u * @return String */ public static String getUserParamString(int u) { switch ( u ) { case Phone: return "phone"; case IP: return "ip"; case NoUserParam: return "BAD"; }; return null; } /** * getTransportParamString * @param t * @return String */ public static String getTransportParamString(int t) { switch ( t ) { case UDP: return "udp"; case TCP: return "tcp"; case NoTransportParam: return "BAD"; // Should return udp }; return null; } /** * getProtocolName * @return String */ public String getProtocolName() { return protocol; } /** * Set the protocol for this URI * * @param name The protocol name */ public void setProtocolName(String name) { protocol = name; } /** * uri * @return String */ public String uri() { String uritext; uritext = protocol + ":"; if( hasUserInfo() ) { uritext += username; if( hasPassword() ) { uritext += ":" + password; } uritext += "@"; } uritext += hostname; if( hasport || port != getSipPort() ) { uritext += ":" + String.valueOf( port ); } if( hasTransportParam() ) { uritext += ";transport=" + getTransportParamString( transparam ); } if( hasUserParam() ) { uritext += ";user=" + getUserParamString( userparam ); } if( hasMethodParam() ) { uritext += ";method=" + Sip.getMethodString( meth ); } if( hasTtlParam() ) { uritext += ";ttl=" + String.valueOf( (int) ttl ); } if( hasMaddrParam() ) { uritext += ";maddr=" + maddrhostname; } return uritext; } /** * nameAddr * @return String */ public String nameAddr() { StringBuffer nameaddr = new StringBuffer(); boolean hasFullName = false; if( ( fullname != null ) && ( fullname.length() > 0 ) ) { hasFullName = true; // if we see a double quote, assume string is quoted and we don't need to do it if (fullname.indexOf("\"") >= 0) { nameaddr.append( fullname ); } else { nameaddr.append( "\"" + fullname + "\" <" ); } } nameaddr.append( uri() ); if ( hasFullName ) nameaddr.append( ">" ); if( hasTag() ) { nameaddr.append( ";tag=" + getTag() ); } return nameaddr.toString(); } /** * reqUri * @return String */ public String reqUri() { String uritext; uritext = protocol + ":"; if( hasUserInfo() ) { uritext += username + "@"; if( hasPassword() ) { uritext += password; } } uritext += hostname; if( hasport || port != getSipPort() ) { uritext += ":" + String.valueOf( port ); } return uritext; } /** * user * @return String */ public String user() { String usertext = ""; if ( hasUserInfo() ) { usertext += username + "@"; if ( hasPassword() ) { usertext += password; } } usertext += hostname; return usertext; } /** * getFullname * @return String */ public String getFullname() { return fullname; } /** * getUsername * @return String */ public String getUsername() { return username; } /** * getPassword * @return String */ public String getPassword() { return password; } /** * getHostname * @return String */ public String getHostname() { return hostname; } /** * getTag * @return String */ public String getTag() { return tag; } /** * generateTag */ public void generateTag() { int uniqid; Random rand = new Random(); uniqid = rand.nextInt( 6000 ); tag = String.valueOf(uniqid); hastag = true; } /** * setTag * @param newtag */ public void setTag(String newtag) { tag = newtag; if( tag == null ) { hastag = false; } else { hastag = true; } } /** * setFullname * @param newfname */ public void setFullname(String newfname) { fullname = newfname; if ( fullname == null ) return; // take out any '\' *** LOOK AT **** if ((fullname.indexOf('\\')) >= 0) { StringBuffer sb = new StringBuffer(fullname); int index; while ((index = fullname.indexOf('\\')) >= 0) { sb.replace(index, index, ""); } fullname = sb.toString(); } } /** * setUsername * @param u */ public void setUsername(String u) { if ( u == null ) { hasuserinfo = false; } else { hasuserinfo = true; username = u; } } /** * setHostname * @param hname */ public void setHostname(String hname) { hostname = hname.toLowerCase().trim(); } /** * setPassword * @param p */ public void setPassword(String p) { if ( p == null ) { haspassword = false; } else { haspassword = true; password = p; } } /** * hasUserInfo * @return bool */ public boolean hasUserInfo() { return hasuserinfo; } /** * hasPassword * @return bool */ public boolean hasPassword() { return haspassword; } /** * setPortNumber * @param p */ public void setPortNumber(int p) { port = p; } /** * getPortNumber * @return int */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -