1 /* 2 * Conditions Of Use 3 * 4 * This software was developed by employees of the National Institute of 5 * Standards and Technology (NIST), an agency of the Federal Government. 6 * Pursuant to title 15 Untied States Code Section 105, works of NIST 7 * employees are not subject to copyright protection in the United States 8 * and are considered to be in the public domain. As a result, a formal 9 * license is not needed to use the software. 10 * 11 * This software is provided by NIST as a service and is expressly 12 * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15 * AND DATA ACCURACY. NIST does not warrant or make any representations 16 * regarding the use of the software or the results thereof, including but 17 * not limited to the correctness, accuracy, reliability or usefulness of 18 * the software. 19 * 20 * Permission to use this software is contingent upon your acceptance 21 * of the terms of this agreement 22 * 23 * . 24 * 25 */ 26 /******************************************************************************* 27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * 28 *******************************************************************************/ 29 package gov.nist.javax.sip.header; 30 31 import java.text.ParseException; 32 33 /** 34 * Protocol name and version. 35 * 36 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:33 $ 37 * 38 * @author M. Ranganathan <br/> 39 * 40 * 41 * 42 */ 43 public class Protocol extends SIPObject { 44 45 /** 46 * Comment for <code>serialVersionUID</code> 47 */ 48 private static final long serialVersionUID = 2216758055974073280L; 49 50 /** protocolName field 51 */ 52 protected String protocolName; 53 54 /** protocolVersion field 55 */ 56 protected String protocolVersion; 57 58 /** transport field 59 */ 60 protected String transport; 61 62 /** 63 * Return canonical form. 64 * @return String 65 */ encode()66 public String encode() { 67 return encode(new StringBuffer()).toString(); 68 } 69 encode(StringBuffer buffer)70 public StringBuffer encode(StringBuffer buffer) { 71 buffer.append(protocolName.toUpperCase()) 72 .append(SLASH) 73 .append(protocolVersion) 74 .append(SLASH) 75 .append(transport.toUpperCase()); 76 77 return buffer; 78 } 79 80 /** get the protocol name 81 * @return String 82 */ getProtocolName()83 public String getProtocolName() { 84 return protocolName; 85 } 86 87 /** get the protocol version 88 * @return String 89 */ getProtocolVersion()90 public String getProtocolVersion() { 91 return protocolVersion; 92 } 93 94 /** 95 * Get the protocol name + version 96 * JvB: This is what is returned in the ViaHeader interface for 'getProtocol()' 97 * 98 * @return String : protocolname + '/' + version 99 */ getProtocol()100 public String getProtocol() { 101 return protocolName + '/' + protocolVersion; 102 } 103 setProtocol( String name_and_version )104 public void setProtocol( String name_and_version ) throws ParseException { 105 int slash = name_and_version.indexOf('/'); 106 if (slash>0) { 107 this.protocolName = name_and_version.substring(0,slash); 108 this.protocolVersion = name_and_version.substring( slash+1 ); 109 } else throw new ParseException( "Missing '/' in protocol", 0 ); 110 } 111 112 /** get the transport 113 * @return String 114 */ getTransport()115 public String getTransport() { 116 return transport; 117 } 118 119 /** 120 * Set the protocolName member 121 * @param p String to set 122 */ setProtocolName(String p)123 public void setProtocolName(String p) { 124 protocolName = p; 125 } 126 127 /** 128 * Set the protocolVersion member 129 * @param p String to set 130 */ setProtocolVersion(String p)131 public void setProtocolVersion(String p) { 132 protocolVersion = p; 133 } 134 135 /** 136 * Set the transport member 137 * @param t String to set 138 */ setTransport(String t)139 public void setTransport(String t) { 140 transport = t; 141 } 142 143 /** 144 * Default constructor. 145 */ Protocol()146 public Protocol() { 147 protocolName = "SIP"; 148 protocolVersion = "2.0"; 149 transport = "UDP"; 150 } 151 } 152 /* 153 * $Log: Protocol.java,v $ 154 * Revision 1.8 2009/07/17 18:57:33 emcho 155 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. 156 * 157 * Revision 1.7 2007/02/12 15:19:23 belangery 158 * Changed the encode() and encodeBody() methods of SIP headers and basic classes to make them use the same StringBuffer instance during the encoding phase. 159 * 160 * Revision 1.6 2006/07/13 09:01:24 mranga 161 * Issue number: 162 * Obtained from: 163 * Submitted by: jeroen van bemmel 164 * Reviewed by: mranga 165 * Moved some changes from jain-sip-1.2 to java.net 166 * 167 * CVS: ---------------------------------------------------------------------- 168 * CVS: Issue number: 169 * CVS: If this change addresses one or more issues, 170 * CVS: then enter the issue number(s) here. 171 * CVS: Obtained from: 172 * CVS: If this change has been taken from another system, 173 * CVS: then name the system in this line, otherwise delete it. 174 * CVS: Submitted by: 175 * CVS: If this code has been contributed to the project by someone else; i.e., 176 * CVS: they sent us a patch or a set of diffs, then include their name/email 177 * CVS: address here. If this is your work then delete this line. 178 * CVS: Reviewed by: 179 * CVS: If we are doing pre-commit code reviews and someone else has 180 * CVS: reviewed your changes, include their name(s) here. 181 * CVS: If you have not had it reviewed then delete this line. 182 * 183 * Revision 1.4 2006/06/19 06:47:26 mranga 184 * javadoc fixups 185 * 186 * Revision 1.3 2006/06/16 15:26:28 mranga 187 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak 188 * 189 * Revision 1.2 2005/10/09 18:47:53 jeroen 190 * defined equals() in terms of API calls 191 * 192 * Revision 1.1.1.1 2005/10/04 17:12:35 mranga 193 * 194 * Import 195 * 196 * 197 * Revision 1.2 2004/01/22 13:26:29 sverker 198 * Issue number: 199 * Obtained from: 200 * Submitted by: sverker 201 * Reviewed by: mranga 202 * 203 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. 204 * 205 * CVS: ---------------------------------------------------------------------- 206 * CVS: Issue number: 207 * CVS: If this change addresses one or more issues, 208 * CVS: then enter the issue number(s) here. 209 * CVS: Obtained from: 210 * CVS: If this change has been taken from another system, 211 * CVS: then name the system in this line, otherwise delete it. 212 * CVS: Submitted by: 213 * CVS: If this code has been contributed to the project by someone else; i.e., 214 * CVS: they sent us a patch or a set of diffs, then include their name/email 215 * CVS: address here. If this is your work then delete this line. 216 * CVS: Reviewed by: 217 * CVS: If we are doing pre-commit code reviews and someone else has 218 * CVS: reviewed your changes, include their name(s) here. 219 * CVS: If you have not had it reviewed then delete this line. 220 * 221 */ 222