1600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/* 2600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Conditions Of Use 3600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 4600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* This software was developed by employees of the National Institute of 5600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Standards and Technology (NIST), an agency of the Federal Government. 6600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Pursuant to title 15 Untied States Code Section 105, works of NIST 7600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* employees are not subject to copyright protection in the United States 8600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* and are considered to be in the public domain. As a result, a formal 9600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* license is not needed to use the software. 10600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 11600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* This software is provided by NIST as a service and is expressly 12600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* AND DATA ACCURACY. NIST does not warrant or make any representations 16600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* regarding the use of the software or the results thereof, including but 17600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* not limited to the correctness, accuracy, reliability or usefulness of 18600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* the software. 19600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 20600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Permission to use this software is contingent upon your acceptance 21600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* of the terms of this agreement 22600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 23600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* . 24600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 25600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang*/ 26600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/******************************************************************************* 27600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Product of NIST/ITL Advanced Networking Technologies Division (ANTD) * 28600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *******************************************************************************/ 29600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangpackage gov.nist.javax.sip.message; 30600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 31600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.core.InternalErrorHandler; 32600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.Utils; 33600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.address.SipUri; 34600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.CSeq; 35600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.CallID; 36600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.ContactList; 37600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.ContentLength; 38600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.ContentType; 39600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.From; 40600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.MaxForwards; 41600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.ReasonList; 42600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.RecordRouteList; 43600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.RequireList; 44600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.SIPHeader; 45600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.StatusLine; 46600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.To; 47600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.Via; 48600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.ViaList; 49600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport gov.nist.javax.sip.header.extensions.SessionExpires; 50600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 51600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport java.io.UnsupportedEncodingException; 52600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport java.text.ParseException; 53600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport java.util.Iterator; 54600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport java.util.LinkedList; 55600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 56600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport javax.sip.header.ReasonHeader; 57600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport javax.sip.header.ServerHeader; 58600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport javax.sip.message.Request; 59600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 60600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 61600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/** 62600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * SIP Response structure. 63600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 64600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @version 1.2 $Revision: 1.29 $ $Date: 2009/10/25 03:07:52 $ 65600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @since 1.1 66600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 67600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @author M. Ranganathan <br/> 68600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 69600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 70600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 71600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangpublic final class SIPResponse 72600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang extends SIPMessage 73600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang implements javax.sip.message.Response, ResponseExt { 74600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang protected StatusLine statusLine; 75600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 76600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public static String getReasonPhrase(int rc) { 77600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String retval = null; 78600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang switch (rc) { 79600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 80600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case TRYING : 81600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Trying"; 82600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 83600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 84600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case RINGING : 85600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Ringing"; 86600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 87600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 88600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case CALL_IS_BEING_FORWARDED : 89600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Call is being forwarded"; 90600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 91600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 92600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case QUEUED : 93600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Queued"; 94600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 95600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 96600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case SESSION_PROGRESS : 97600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Session progress"; 98600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 99600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 100600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case OK : 101600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "OK"; 102600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 103600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 104600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case ACCEPTED : 105600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Accepted"; 106600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 107600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 108600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case MULTIPLE_CHOICES : 109600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Multiple choices"; 110600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 111600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 112600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case MOVED_PERMANENTLY : 113600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Moved permanently"; 114600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 115600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 116600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case MOVED_TEMPORARILY : 117600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Moved Temporarily"; 118600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 119600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 120600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case USE_PROXY : 121600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Use proxy"; 122600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 123600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 124600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case ALTERNATIVE_SERVICE : 125600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Alternative service"; 126600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 127600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 128600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BAD_REQUEST : 129600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Bad request"; 130600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 131600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 132600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case UNAUTHORIZED : 133600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Unauthorized"; 134600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 135600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 136600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case PAYMENT_REQUIRED : 137600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Payment required"; 138600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 139600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 140600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case FORBIDDEN : 141600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Forbidden"; 142600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 143600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 144600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case NOT_FOUND : 145600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Not found"; 146600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 147600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 148600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case METHOD_NOT_ALLOWED : 149600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Method not allowed"; 150600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 151600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 152600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case NOT_ACCEPTABLE : 153600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Not acceptable"; 154600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 155600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 156600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case PROXY_AUTHENTICATION_REQUIRED : 157600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Proxy Authentication required"; 158600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 159600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 160600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case REQUEST_TIMEOUT : 161600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Request timeout"; 162600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 163600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 164600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case GONE : 165600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Gone"; 166600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 167600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 168600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case TEMPORARILY_UNAVAILABLE : 169600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Temporarily Unavailable"; 170600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 171600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 172600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case REQUEST_ENTITY_TOO_LARGE : 173600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Request entity too large"; 174600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 175600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 176600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case REQUEST_URI_TOO_LONG : 177600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Request-URI too large"; 178600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 179600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 180600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case UNSUPPORTED_MEDIA_TYPE : 181600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Unsupported media type"; 182600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 183600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 184600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case UNSUPPORTED_URI_SCHEME : 185600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Unsupported URI Scheme"; 186600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 187600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 188600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BAD_EXTENSION : 189600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Bad extension"; 190600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 191600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 192600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case EXTENSION_REQUIRED : 193600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Etension Required"; 194600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 195600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 196600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case INTERVAL_TOO_BRIEF : 197600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Interval too brief"; 198600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 199600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 200600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case CALL_OR_TRANSACTION_DOES_NOT_EXIST : 201600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Call leg/Transaction does not exist"; 202600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 203600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 204600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case LOOP_DETECTED : 205600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Loop detected"; 206600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 207600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 208600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case TOO_MANY_HOPS : 209600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Too many hops"; 210600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 211600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 212600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case ADDRESS_INCOMPLETE : 213600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Address incomplete"; 214600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 215600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 216600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case AMBIGUOUS : 217600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Ambiguous"; 218600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 219600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 220600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BUSY_HERE : 221600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Busy here"; 222600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 223600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 224600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case REQUEST_TERMINATED : 225600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Request Terminated"; 226600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 227600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 228600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //Issue 168, Typo fix reported by fre on the retval 229600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case NOT_ACCEPTABLE_HERE : 230600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Not Acceptable here"; 231600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 232600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 233600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BAD_EVENT : 234600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Bad Event"; 235600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 236600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 237600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case REQUEST_PENDING : 238600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Request Pending"; 239600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 240600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 241600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case SERVER_INTERNAL_ERROR : 242600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Server Internal Error"; 243600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 244600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 245600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case UNDECIPHERABLE : 246600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Undecipherable"; 247600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 248600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 249600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case NOT_IMPLEMENTED : 250600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Not implemented"; 251600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 252600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 253600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BAD_GATEWAY : 254600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Bad gateway"; 255600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 256600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 257600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case SERVICE_UNAVAILABLE : 258600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Service unavailable"; 259600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 260600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 261600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case SERVER_TIMEOUT : 262600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Gateway timeout"; 263600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 264600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 265600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case VERSION_NOT_SUPPORTED : 266600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "SIP version not supported"; 267600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 268600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 269600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case MESSAGE_TOO_LARGE : 270600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Message Too Large"; 271600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 272600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 273600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case BUSY_EVERYWHERE : 274600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Busy everywhere"; 275600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 276600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 277600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case DECLINE : 278600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Decline"; 279600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 280600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 281600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case DOES_NOT_EXIST_ANYWHERE : 282600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Does not exist anywhere"; 283600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 284600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 285600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case SESSION_NOT_ACCEPTABLE : 286600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Session Not acceptable"; 287600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 288600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 289600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang case CONDITIONAL_REQUEST_FAILED: 290600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Conditional request failed"; 291600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang break; 292600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 293600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang default : 294600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = "Unknown Status"; 295600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 296600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 297600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval; 298600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 299600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 300600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 301600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** set the status code. 302600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param statusCode is the status code to set. 303600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@throws IlegalArgumentException if invalid status code. 304600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 305600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setStatusCode(int statusCode) throws ParseException { 306600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 307600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang // RFC3261 defines statuscode as 3DIGIT, 606 is the highest officially 308600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang // defined code but extensions may add others (in theory up to 999, 309600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang // but in practice up to 699 since the 6xx range is defined as 'final error') 310600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusCode < 100 || statusCode > 699) 311600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException("bad status code", 0); 312600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.statusLine == null) 313600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.statusLine = new StatusLine(); 314600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.statusLine.setStatusCode(statusCode); 315600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 316600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 317600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 318600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Get the status line of the response. 319600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return StatusLine 320600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 321600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public StatusLine getStatusLine() { 322600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return statusLine; 323600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 324600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 325600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Get the staus code (conveniance function). 326600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return the status code of the status line. 327600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 328600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public int getStatusCode() { 329600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return statusLine.getStatusCode(); 330600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 331600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 332600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Set the reason phrase. 333600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param reasonPhrase the reason phrase. 334600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@throws IllegalArgumentException if null string 335600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 336600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setReasonPhrase(String reasonPhrase) { 337600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (reasonPhrase == null) 338600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new IllegalArgumentException("Bad reason phrase"); 339600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.statusLine == null) 340600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.statusLine = new StatusLine(); 341600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.statusLine.setReasonPhrase(reasonPhrase); 342600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 343600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 344600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Get the reason phrase. 345600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return the reason phrase. 346600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 347600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getReasonPhrase() { 348600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine == null || statusLine.getReasonPhrase() == null) 349600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return ""; 350600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 351600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return statusLine.getReasonPhrase(); 352600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 353600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 354600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Return true if the response is a final response. 355600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param rc is the return code. 356600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return true if the parameter is between the range 200 and 700. 357600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 358600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public static boolean isFinalResponse(int rc) { 359600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return rc >= 200 && rc < 700; 360600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 361600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 362600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Is this a final response? 363600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return true if this is a final response. 364600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 365600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean isFinalResponse() { 366600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return isFinalResponse(statusLine.getStatusCode()); 367600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 368600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 369600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 370600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Set the status line field. 371600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param sl Status line to set. 372600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 373600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setStatusLine(StatusLine sl) { 374600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang statusLine = sl; 375600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 376600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 377600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Constructor. 378600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 379600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public SIPResponse() { 380600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang super(); 381600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 382600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 383600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Print formatting function. 384600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *Indent and parenthesize for pretty printing. 385600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Note -- use the encode method for formatting the message. 386600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Hack here to XMLize. 387600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 388600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return a string for pretty printing. 389600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 390600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String debugDump() { 391600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String superstring = super.debugDump(); 392600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang stringRepresentation = ""; 393600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang sprint(SIPResponse.class.getCanonicalName()); 394600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang sprint("{"); 395600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine != null) { 396600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang sprint(statusLine.debugDump()); 397600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 398600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang sprint(superstring); 399600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang sprint("}"); 400600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return stringRepresentation; 401600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 402600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 403600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 404600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Check the response structure. Must have from, to CSEQ and VIA 405600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * headers. 406600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 407600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void checkHeaders() throws ParseException { 408600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getCSeq() == null) { 409600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException(CSeq.NAME+ " Is missing ", 0); 410600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 411600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getTo() == null) { 412600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException(To.NAME+ " Is missing ", 0); 413600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 414600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getFrom() == null) { 415600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException(From.NAME+ " Is missing ", 0); 416600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 417600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getViaHeaders() == null) { 418600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException(Via.NAME+ " Is missing ", 0); 419600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 420600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getCallId() == null) { 421600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException(CallID.NAME + " Is missing ", 0); 422600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 423600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 424600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 425600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (getStatusCode() > 699) { 426600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang throw new ParseException("Unknown error code!" + getStatusCode(), 0); 427600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 428600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 429600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 430600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 431600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 432600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Encode the SIP Request as a string. 433600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return The string encoded canonical form of the message. 434600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 435600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 436600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String encode() { 437600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String retval; 438600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine != null) 439600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = statusLine.encode() + super.encode(); 440600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 441600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = super.encode(); 442600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval ; 443600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 444600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 445600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Encode the message except for the body. 446600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 447600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return The string except for the body. 448600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 449600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 450600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String encodeMessage() { 451600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String retval; 452600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine != null) 453600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = statusLine.encode() + super.encodeSIPHeaders(); 454600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 455600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval = super.encodeSIPHeaders(); 456600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval ; 457600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 458600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 459600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 460600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 461600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Get this message as a list of encoded strings. 462600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return LinkedList containing encoded strings for each header in 463600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * the message. 464600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 465600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 466600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public LinkedList getMessageAsEncodedStrings() { 467600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang LinkedList retval = super.getMessageAsEncodedStrings(); 468600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 469600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine != null) 470600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.addFirst(statusLine.encode()); 471600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval; 472600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 473600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 474600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 475600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 476600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Make a clone (deep copy) of this object. 477600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return a deep copy of this object. 478600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 479600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 480600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public Object clone() { 481600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang SIPResponse retval = (SIPResponse) super.clone(); 482600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.statusLine != null) 483600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.statusLine = (StatusLine) this.statusLine.clone(); 484600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval; 485600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 486600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 487600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 488600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 489600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Compare for equality. 490600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param other other object to compare with. 491600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 492600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean equals(Object other) { 493600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (!this.getClass().equals(other.getClass())) 494600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return false; 495600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang SIPResponse that = (SIPResponse) other; 496600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return statusLine.equals(that.statusLine) && super.equals(other); 497600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 498600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 499600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 500600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Match with a template. 501600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@param matchObj template object to match ourselves with (null 502600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * in any position in the template object matches wildcard) 503600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 504600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean match(Object matchObj) { 505600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (matchObj == null) 506600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return true; 507600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else if (!matchObj.getClass().equals(this.getClass())) { 508600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return false; 509600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else if (matchObj == this) 510600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return true; 511600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang SIPResponse that = (SIPResponse) matchObj; 512600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 513600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang StatusLine rline = that.statusLine; 514600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.statusLine == null && rline != null) 515600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return false; 516600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else if (this.statusLine == rline) 517600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return super.match(matchObj); 518600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else { 519600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 520600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return statusLine.match(that.statusLine) && super.match(matchObj); 521600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 522600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 523600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 524600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 525600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Encode this into a byte array. 526600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * This is used when the body has been set as a binary array 527600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * and you want to encode the body as a byte array for transmission. 528600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 529600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return a byte array containing the SIPRequest encoded as a byte 530600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * array. 531600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 532600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 533600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public byte[] encodeAsBytes( String transport ) { 534600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang byte[] slbytes = null; 535600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine != null) { 536600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang try { 537600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang slbytes = statusLine.encode().getBytes("UTF-8"); 538600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } catch (UnsupportedEncodingException ex) { 539600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang InternalErrorHandler.handleException(ex); 540600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 541600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 542600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang byte[] superbytes = super.encodeAsBytes( transport ); 543600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang byte[] retval = new byte[slbytes.length + superbytes.length]; 544600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang System.arraycopy(slbytes, 0, retval, 0, slbytes.length); 545600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang System.arraycopy(superbytes, 0, retval, slbytes.length, 546600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang superbytes.length); 547600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval; 548600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 549600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 550600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 551600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 552600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Get a dialog identifier. 553600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Generates a string that can be used as a dialog identifier. 554600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 555600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param isServer is set to true if this is the UAS 556600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * and set to false if this is the UAC 557600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 558600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getDialogId(boolean isServer) { 559600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang CallID cid = (CallID) this.getCallId(); 560600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang From from = (From) this.getFrom(); 561600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang To to = (To) this.getTo(); 562600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang StringBuffer retval = new StringBuffer(cid.getCallId()); 563600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (!isServer) { 564600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(from.getUserAtHostPort()); 565600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (from.getTag() != null) { 566600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 567600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(from.getTag()); 568600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 569600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(to.getUserAtHostPort()); 570600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (to.getTag() != null) { 571600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 572600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(to.getTag()); 573600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 574600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else { 575600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(to.getUserAtHostPort()); 576600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (to.getTag() != null) { 577600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 578600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(to.getTag()); 579600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 580600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(from.getUserAtHostPort()); 581600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (from.getTag() != null) { 582600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 583600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(from.getTag()); 584600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 585600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 586600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval.toString().toLowerCase(); 587600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 588600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 589600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getDialogId(boolean isServer, String toTag) { 590600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang CallID cid = (CallID) this.getCallId(); 591600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang From from = (From) this.getFrom(); 592600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang StringBuffer retval = new StringBuffer(cid.getCallId()); 593600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (!isServer) { 594600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(from.getUserAtHostPort()); 595600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (from.getTag() != null) { 596600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 597600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(from.getTag()); 598600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 599600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(to.getUserAtHostPort()); 600600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (toTag != null) { 601600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 602600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(toTag); 603600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 604600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else { 605600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(to.getUserAtHostPort()); 606600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (toTag != null) { 607600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 608600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(toTag); 609600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 610600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //retval.append(COLON).append(from.getUserAtHostPort()); 611600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (from.getTag() != null) { 612600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(COLON); 613600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.append(from.getTag()); 614600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 615600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 616600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval.toString().toLowerCase(); 617600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 618600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 619600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 620600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Sets the Via branch for CANCEL or ACK requests 621600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 622600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param via 623600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param method 624600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @throws ParseException 625600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 626600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang private final void setBranch( Via via, String method ) { 627600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String branch; 628600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (method.equals( Request.ACK ) ) { 629600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine.getStatusCode() >= 300 ) { 630600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang branch = getTopmostVia().getBranch(); // non-2xx ACK uses same branch 631600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else { 632600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang branch = Utils.getInstance().generateBranchId(); // 2xx ACK gets new branch 633600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 634600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else if (method.equals( Request.CANCEL )) { 635600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang branch = getTopmostVia().getBranch(); // CANCEL uses same branch 636600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else return; 637600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 638600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang try { 639600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang via.setBranch( branch ); 640600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } catch (ParseException e) { 641600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang e.printStackTrace(); 642600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 643600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 644600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 645600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 646600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 647600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Get the encoded first line. 648600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 649600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return the status line encoded. 650600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 651600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 652600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getFirstLine() { 653600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.statusLine == null) 654600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return null; 655600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 656600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return this.statusLine.encode(); 657600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 658600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 659600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setSIPVersion(String sipVersion) { 660600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.statusLine.setSipVersion(sipVersion); 661600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 662600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 663600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getSIPVersion() { 664600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return this.statusLine.getSipVersion(); 665600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 666600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 667600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String toString() { 668600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (statusLine == null) return ""; 669600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else return statusLine.encode() + super.encode(); 670600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 671600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 672600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 673600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Generate a request from a response. 674600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 675600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param requestURI -- the request URI to assign to the request. 676600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param via -- the Via header to assign to the request 677600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param cseq -- the CSeq header to assign to the request 678600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param from -- the From header to assign to the request 679600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param to -- the To header to assign to the request 680600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return -- the newly generated sip request. 681600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 682600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public SIPRequest createRequest(SipUri requestURI, Via via, CSeq cseq, From from, To to) { 683600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang SIPRequest newRequest = new SIPRequest(); 684600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang String method = cseq.getMethod(); 685600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 686600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.setMethod(method); 687600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.setRequestURI(requestURI); 688600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang this.setBranch( via, method ); 689600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.setHeader(via); 690600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.setHeader(cseq); 691600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang Iterator headerIterator = getHeaders(); 692600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang while (headerIterator.hasNext()) { 693600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang SIPHeader nextHeader = (SIPHeader) headerIterator.next(); 694600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang // Some headers do not belong in a Request .... 695600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (SIPMessage.isResponseHeader(nextHeader) 696600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ViaList 697600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof CSeq 698600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ContentType 699600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ContentLength 700600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof RecordRouteList 701600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof RequireList 702600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ContactList // JvB: added 703600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ContentLength 704600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ServerHeader 705600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ReasonHeader 706600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof SessionExpires 707600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang || nextHeader instanceof ReasonList) { 708600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang continue; 709600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 710600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (nextHeader instanceof To) 711600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang nextHeader = (SIPHeader) to; 712600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else if (nextHeader instanceof From) 713600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang nextHeader = (SIPHeader) from; 714600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang try { 715600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.attachHeader(nextHeader, false); 716600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } catch (SIPDuplicateHeaderException e) { 717600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang //Should not happen! 718600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang e.printStackTrace(); 719600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 720600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 721600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 722600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang try { 723600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang // JvB: all requests need a Max-Forwards 724600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.attachHeader( new MaxForwards(70), false); 725600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } catch (Exception d) { 726600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 727600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 728600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 729600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (MessageFactoryImpl.getDefaultUserAgentHeader() != null ) { 730600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader()); 731600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 732600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return newRequest; 733600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 734600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 735600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 736