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 javax.sip.address.URI; 32 33 import gov.nist.javax.sip.address.*; 34 35 /** 36 * RequestLine of SIP Request. 37 * 38 * @version 1.2 $Revision: 1.8 $ $Date: 2009/09/15 02:55:27 $ 39 * @author M. Ranganathan 40 */ 41 public class RequestLine extends SIPObject implements SipRequestLine { 42 43 /** 44 * Comment for <code>serialVersionUID</code> 45 */ 46 private static final long serialVersionUID = -3286426172326043129L; 47 48 /** uri field. Note that this can be a SIP URI or a generic URI 49 * like tel URI. 50 */ 51 protected GenericURI uri; 52 53 /** method field. 54 */ 55 protected String method; 56 57 /** sipVersion field 58 */ 59 protected String sipVersion; 60 61 /** Default constructor 62 */ 63 public RequestLine() { 64 sipVersion = "SIP/2.0"; 65 } 66 67 68 /** Encode the request line as a String. 69 * 70 * @return requestLine encoded as a string. 71 */ 72 public String encode() { 73 return encode(new StringBuffer()).toString(); 74 } 75 76 public StringBuffer encode(StringBuffer buffer) { 77 if (method != null) { 78 buffer.append(method); 79 buffer.append(SP); 80 } 81 if (uri != null) { 82 uri.encode(buffer); 83 buffer.append(SP); 84 } 85 buffer.append(sipVersion); 86 buffer.append(NEWLINE); 87 return buffer; 88 } 89 90 /* (non-Javadoc) 91 * @see gov.nist.javax.sip.header.SipRequestLine#getUri() 92 */ 93 public GenericURI getUri() { 94 return uri; 95 } 96 97 /** Constructor given the request URI and the method. 98 */ 99 public RequestLine(GenericURI requestURI, String method) { 100 this.uri = requestURI; 101 this.method = method; 102 this.sipVersion = "SIP/2.0"; 103 } 104 105 /* (non-Javadoc) 106 * @see gov.nist.javax.sip.header.SipRequestLine#getMethod() 107 */ 108 public String getMethod() { 109 return method; 110 } 111 112 /* (non-Javadoc) 113 * @see gov.nist.javax.sip.header.SipRequestLine#getSipVersion() 114 */ 115 public String getSipVersion() { 116 return sipVersion; 117 } 118 119 /* (non-Javadoc) 120 * @see gov.nist.javax.sip.header.SipRequestLine#setUri(gov.nist.javax.sip.address.GenericURI) 121 */ 122 public void setUri(URI uri) { 123 this.uri = (GenericURI)uri; 124 } 125 126 /* (non-Javadoc) 127 * @see gov.nist.javax.sip.header.SipRequestLine#setMethod(java.lang.String) 128 */ 129 public void setMethod(String method) { 130 this.method = method; 131 } 132 133 /* (non-Javadoc) 134 * @see gov.nist.javax.sip.header.SipRequestLine#setSipVersion(java.lang.String) 135 */ 136 public void setSipVersion(String version) { 137 this.sipVersion = version; 138 } 139 140 /* (non-Javadoc) 141 * @see gov.nist.javax.sip.header.SipRequestLine#getVersionMajor() 142 */ 143 public String getVersionMajor() { 144 if (sipVersion == null) 145 return null; 146 String major = null; 147 boolean slash = false; 148 for (int i = 0; i < sipVersion.length(); i++) { 149 if (sipVersion.charAt(i) == '.') 150 break; 151 if (slash) { 152 if (major == null) 153 major = "" + sipVersion.charAt(i); 154 else 155 major += sipVersion.charAt(i); 156 } 157 if (sipVersion.charAt(i) == '/') 158 slash = true; 159 } 160 return major; 161 } 162 163 /* (non-Javadoc) 164 * @see gov.nist.javax.sip.header.SipRequestLine#getVersionMinor() 165 */ 166 public String getVersionMinor() { 167 if (sipVersion == null) 168 return null; 169 String minor = null; 170 boolean dot = false; 171 for (int i = 0; i < sipVersion.length(); i++) { 172 if (dot) { 173 if (minor == null) 174 minor = "" + sipVersion.charAt(i); 175 else 176 minor += sipVersion.charAt(i); 177 } 178 if (sipVersion.charAt(i) == '.') 179 dot = true; 180 } 181 return minor; 182 } 183 184 /** 185 * Compare for equality. 186 * 187 *@param other object to compare with. We assume that all fields 188 * are set. 189 */ 190 public boolean equals(Object other) { 191 boolean retval; 192 if (!other.getClass().equals(this.getClass())) { 193 return false; 194 } 195 RequestLine that = (RequestLine) other; 196 try { 197 retval = 198 this.method.equals(that.method) 199 && this.uri.equals(that.uri) 200 && this.sipVersion.equals(that.sipVersion); 201 } catch (NullPointerException ex) { 202 retval = false; 203 } 204 return retval; 205 } 206 207 public Object clone() { 208 RequestLine retval = (RequestLine) super.clone(); 209 if (this.uri != null) 210 retval.uri = (GenericURI) this.uri.clone(); 211 return retval; 212 } 213 } 214 /* 215 * $Log: RequestLine.java,v $ 216 * Revision 1.8 2009/09/15 02:55:27 mranga 217 * Issue number: 222 218 * Add HeaderFactoryExt.createStatusLine(String) and HeaderFactoryExt.createRequestLine(String) 219 * Allows users to easily parse SipFrag bodies (for example NOTIFY bodies 220 * during call transfer). 221 * 222 * Revision 1.7 2009/07/17 18:57:36 emcho 223 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. 224 * 225 * Revision 1.6 2007/02/12 15:19:23 belangery 226 * Changed the encode() and encodeBody() methods of SIP headers and basic classes to make them use the same StringBuffer instance during the encoding phase. 227 * 228 * Revision 1.5 2006/07/13 09:01:26 mranga 229 * Issue number: 230 * Obtained from: 231 * Submitted by: jeroen van bemmel 232 * Reviewed by: mranga 233 * Moved some changes from jain-sip-1.2 to java.net 234 * 235 * CVS: ---------------------------------------------------------------------- 236 * CVS: Issue number: 237 * CVS: If this change addresses one or more issues, 238 * CVS: then enter the issue number(s) here. 239 * CVS: Obtained from: 240 * CVS: If this change has been taken from another system, 241 * CVS: then name the system in this line, otherwise delete it. 242 * CVS: Submitted by: 243 * CVS: If this code has been contributed to the project by someone else; i.e., 244 * CVS: they sent us a patch or a set of diffs, then include their name/email 245 * CVS: address here. If this is your work then delete this line. 246 * CVS: Reviewed by: 247 * CVS: If we are doing pre-commit code reviews and someone else has 248 * CVS: reviewed your changes, include their name(s) here. 249 * CVS: If you have not had it reviewed then delete this line. 250 * 251 * Revision 1.3 2006/06/19 06:47:26 mranga 252 * javadoc fixups 253 * 254 * Revision 1.2 2006/06/16 15:26:28 mranga 255 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak 256 * 257 * Revision 1.1.1.1 2005/10/04 17:12:35 mranga 258 * 259 * Import 260 * 261 * 262 * Revision 1.3 2005/04/16 20:38:50 dmuresan 263 * Canonical clone() implementations for the GenericObject and GenericObjectList hierarchies 264 * 265 * Revision 1.2 2004/01/22 13:26:29 sverker 266 * Issue number: 267 * Obtained from: 268 * Submitted by: sverker 269 * Reviewed by: mranga 270 * 271 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. 272 * 273 * CVS: ---------------------------------------------------------------------- 274 * CVS: Issue number: 275 * CVS: If this change addresses one or more issues, 276 * CVS: then enter the issue number(s) here. 277 * CVS: Obtained from: 278 * CVS: If this change has been taken from another system, 279 * CVS: then name the system in this line, otherwise delete it. 280 * CVS: Submitted by: 281 * CVS: If this code has been contributed to the project by someone else; i.e., 282 * CVS: they sent us a patch or a set of diffs, then include their name/email 283 * CVS: address here. If this is your work then delete this line. 284 * CVS: Reviewed by: 285 * CVS: If we are doing pre-commit code reviews and someone else has 286 * CVS: reviewed your changes, include their name(s) here. 287 * CVS: If you have not had it reviewed then delete this line. 288 * 289 */ 290