?? sipvia.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 SipVia * * This class represents information for a single SIP Via header. * * 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;public class SipVia extends Object{ /** * SipVia */ public SipVia() { clear(); } /** * SipVia * @param parseinput */ public SipVia(String parseinput) { clear(); parseVia( parseinput ); } /** * getTransportString * @param t * @return String */ public String getTransportString(int t) { switch ( t ) { case UDP: return "UDP"; case TCP: return "TCP"; case BadTransport: return "BAD"; } return null; } /** * matchTransport * @param t * @return Transport */ public int matchTransport(String t) { if ( t.compareTo( getTransportString( UDP ) ) == 0 ) { return UDP; } if ( t.compareTo( getTransportString( TCP ) ) == 0 ) { return TCP; }; return BadTransport; } /** * getViaParamString * @param v * @return String */ public String getViaParamString(int v) { switch ( v ) { case Hidden: return "hidden"; case Ttl: return "ttl"; case Maddr: return "maddr"; case Received: return "received"; case Branch: return "branch"; case BadViaParam: return "BAD"; } return null; } /** * matchViaParam * @param v * @return ViaParam */ public int matchViaParam(String v) { if ( v.compareTo( getViaParamString( Hidden ) ) == 0 ) { return Hidden; } if ( v.compareTo( getViaParamString( Ttl ) ) == 0 ) { return Ttl; } if ( v.compareTo( getViaParamString( Maddr ) ) == 0 ) { return Maddr; } if ( v.compareTo( getViaParamString( Received ) ) == 0 ) { return Received; } if ( v.compareTo( getViaParamString( Branch ) ) == 0 ) { return Branch; } return BadViaParam; } /** * isValid * @return bool */ public boolean isValid() { return isvalid; } /** * setHostname * @param hname */ public void setHostname(String hname) { hostname = hname; } /** * getHostname * @return String */ public String getHostname() { return hostname; } /** * setTransport * @param t */ public void setTransport(int t) { trans = t; } /** * via * @return String */ public String via() { String viatext; viatext = protocolname + "/" + protocolver + "/" + getTransportString( trans ) + " " + hostname;; if( port != 5060 ) { viatext += ":"; viatext += String.valueOf( port ); } if( hasreceived ) { viatext += ";received="; viatext += received; } if( ishidden ) { viatext += ";hidden"; } if( hasttl ) { viatext += ";ttl="; viatext += ttl; } if( hasmaddr ) { viatext += ";maddr="; viatext += maddr; } if( hasbranch ) { viatext += ";branch="; viatext += branch; } return viatext; } /** * getProtocolName * @return String */ public String getProtocolName() { return protocolname; } /** * getProtocolVer * @return String */ public String getProtocolVer() { return protocolver; } /** * getTransport * @return Transport */ public int getTransport() { return trans; } /** * setPortNumber * @param p */ public void setPortNumber(int p) { port = p; } /** * getPortNumber * @return int */ public int getPortNumber() { return port; } /** * hasReceivedParam * @return bool */ public boolean hasReceivedParam() { return hasreceived; } /** * getReceivedParam * @return String & */ public String getReceivedParam() { return received; } /** * setReceivedParam * @param newreceived */ public void setReceivedParam(String newreceived) { if( newreceived == null ) { hasreceived = false; } else { hasreceived = true; received = newreceived.toLowerCase(); } } /** * isHidden * @return bool */ public boolean isHidden() { return ishidden; } /** * setHidden * @param hidden */ public void setHidden(boolean hidden) { ishidden = hidden; } /** * hasTtlParam * @return bool */ public boolean hasTtlParam() { return hasttl; } /** * getTtlParam * @return String & */ public String getTtlParam() { return ttl; } /** * setTtlParam * @param newttl */ public void setTtlParam(String newttl) { if( newttl == null ) { hasttl = false; } else { hasttl = true; ttl = newttl; } } /** * hasMaddrParam * @return bool */ public boolean hasMaddrParam() { return hasmaddr; } /** * getMaddrParam * @return String & */ public String getMaddrParam() { return maddr; } /** * setMaddrParam * @param newmaddr */ public void setMaddrParam(String newmaddr) { if( newmaddr == null ) { hasmaddr = false; } else { hasmaddr = true; maddr = newmaddr; } } /** * hasBranchParam * @return bool */ public boolean hasBranchParam() { return hasbranch; } /** * getBranchParam * @return String & */ public String getBranchParam() { return branch; } /** * setBranchParam * @param newbranch */ public void setBranchParam(String newbranch) { if( newbranch == null ) { hasbranch = false; } else { hasbranch = true; branch = newbranch; } } /** * clear */ private void clear() { setTransport( UDP ); port = 5060; hasreceived = false; ishidden = false; hasttl = false; hasmaddr = false; hasbranch = false; isvalid = true; protocolname = "SIP"; protocolver = "2.0"; } /** * parseVia * @param parseinput */ private void parseVia(String parseinput) { String inputline; String hostport; String curparm; String parmname; String parmvalue; String transport; int parm; isvalid = false; inputline = parseinput.trim(); protocolname = inputline.substring( 0, inputline.indexOf( "/" ) ).toUpperCase(); inputline = inputline.substring( inputline.indexOf( "/" ) + 1 ); protocolver = inputline.substring( 0, inputline.indexOf( "/" ) ); inputline = inputline.substring( inputline.indexOf( "/" ) + 1 ); // fixed for notel transport = inputline.substring( 0, inputline.indexOf( " " ) ).toUpperCase(); inputline = inputline.substring( inputline.indexOf( " " ) + 1 ); setTransport( matchTransport( transport ) ); if( getTransport() == BadTransport ) { return; } // we want the inputline to begin with ';' after this part... if ( inputline.indexOf( ";" ) >= 0 ) { hostport = inputline.substring( 0, inputline.indexOf( ";" ) ); inputline = inputline.substring( inputline.indexOf( ";" ) ); } else if ( inputline.indexOf( " " ) >= 0 ) { hostport = inputline.substring( 0, inputline.indexOf( " " ) ); inputline = inputline.substring( inputline.indexOf( " " ) ); } else { hostport = inputline; inputline = ""; } if ( hostport.indexOf( ":" ) >= 0 ) { setHostname( hostport.substring( 0, hostport.indexOf( ":" ) ) ); try { String sport = hostport.substring( hostport.indexOf( ":" ) + 1 ); setPortNumber( Integer.parseInt(sport) ); } catch (NumberFormatException nfe) { System.err.println("Error parsing port. Setting port value to default (5060)"); setPortNumber( 5060 ); } } else { setHostname( hostport ); setPortNumber( 5060 ); } while ( inputline.startsWith(";") ) { int nextSemi = inputline.indexOf( ";", 1 ); if ( nextSemi > 0 ) { curparm = inputline.substring( 1, nextSemi ); inputline = inputline.substring( nextSemi + 1 ); } else { curparm = inputline; inputline = ""; } if( curparm.indexOf( '=' ) >= 0 ) { parmname = curparm.substring( 0, curparm.indexOf( '=' ) ).trim().toLowerCase(); parmvalue = curparm.substring( curparm.indexOf( '=' ) + 1 ).trim(); } else { parmname = curparm; parmvalue = null; } parm = matchViaParam( parmname ); if( parm == Received ) { hasreceived = true; received = parmvalue; } else if( parm == Hidden ) { ishidden = true; } else if( parm == Ttl ) { hasttl = true; ttl = parmvalue; } else if( parm == Maddr ) { hasmaddr = true; maddr = parmvalue; } else if( parm == Branch ) { hasbranch = true; branch = parmvalue; } } isvalid = true; } // class variables static final int UDP = 0; static final int TCP = 1; static final int BadTransport = 2; static final int Hidden = 0; static final int Ttl = 1; static final int Maddr = 2; static final int Received = 3; static final int Branch = 4; static final int BadViaParam = 5; private boolean isvalid; private String hostname; private int trans; private String protocolname; private String protocolver; private boolean hasreceived; private String received; private boolean ishidden; private boolean hasttl; private String ttl; private boolean hasmaddr; private String maddr; private boolean hasbranch; private String branch; private int port;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -