Beispiel #1
0
func (this *ToParser) Parse() (sh header.Header, ParseException error) {
	to := header.NewTo()
	this.HeaderName(TokenTypes_TO)

	if ParseException = this.AddressParametersParser.Parse(to); ParseException != nil {
		return nil, ParseException
	}

	this.GetLexer().Match('\n')
	addr := to.GetAddress().(*address.AddressImpl)
	if addr.GetAddressType() == address.ADDRESS_SPEC {
		// the parameters are header parameters.
		if to.GetAddress().GetURI().IsSipURI() {
			sipUri, _ := to.GetAddress().GetURI().(*address.SipURIImpl)
			parms := sipUri.GetUriParms()
			if parms != nil && parms.Len() > 0 {
				to.SetParameters(parms)
				sipUri.RemoveUriParms()
			}
		}
	}
	return to, nil
}
Beispiel #2
0
			/**
			   SIPHeader sipHeader =
				(SIPHeader)
			       ((ViaList) nextHeader).GetFirst().clone() ;
			   nextHeader = new ViaList();
			   ((ViaList)nextHeader).add(sipHeader);
			 **/
			//nextHeader = (ViaList) ((ViaList) nextHeader).clone();
		} else if cseq, ok := nextHeader.(*header.CSeq); ok { // CSeq method for a cancel request must be cancel.
			//CSeq cseq = (CSeq) nextHeader.clone();
			//try{
			cseq.SetMethod(CANCEL)
			//}
			//catch(ParseException e){}
			nextHeader = cseq
		}
		//try {
		newRequest.AttachHeader2(nextHeader, false)
		// } catch(SIPDuplicateHeaderException e){
		// 	e.printStackTrace();
		// }
	}
	return newRequest
}

// /** Creates a default ACK SIPRequest message for this original request.
// * Note that the defaultACK SIPRequest does not include the
// * content of the original SIPRequest. If responSetoHeader
// * is nil then the toHeader of this request is used to
// * construct the ACK.  Note that tag fields are just copied
// * from the original SIP Request.  Added by Jeff Keyser.
// *
// *@param responSetoHeader To header to use for this request.
// *
// *@return A SIPRequest with an ACK method.
// */
func (this *SIPRequest) CreateAckRequest(responseToHeader *header.To) *SIPRequest {
	// SIPRequest	newRequest;
	// Iterator	headerIterator;
	// SIPHeader	nextHeader;

	newRequest := NewSIPRequest()
	newRequest.SetRequestLine(this.requestLine)
	newRequest.SetMethod(ACK)
	for headerIterator := this.getHeaders().Front(); headerIterator != nil; headerIterator = headerIterator.Next() {
		nextHeader := headerIterator.Value.(header.Header)
		if _, ok := nextHeader.(*header.RouteList); ok {
			// Ack and cancel do not Get ROUTE headers.
			// Route header for ACK is assigned by the
			// Dialog if necessary.
			continue
		} else if _, ok := nextHeader.(*header.ProxyAuthorization); ok {
			// Remove proxy auth header.
			// Assigned by the Dialog if necessary.
			continue
		} else if cl, ok := nextHeader.(*header.ContentLength); ok {
			// Adding content is responsibility of user.
			//nextHeader = nextHeader.(*header.ContentLength)
			//try{
			cl.SetContentLength(0)
			nextHeader = cl
			//}
			//catch(InvalidArgumentException e){}
		} else if _, ok := nextHeader.(*header.ContentType); ok {
			// Content type header is removed since
			// content length is 0. Bug fix from
			// Antonis Kyardis.
			continue
		} else if cseq, ok := nextHeader.(*header.CSeq); ok {
			// The CSeq header field in the
			// ACK MUST contain the same value for the
			// sequence number as was present in the
			// original request, but the method parameter
			// MUST be equal to "ACK".
			//nextHeader = nextHeader.(*header.CSeq)
			//try{
			cseq.SetMethod(ACK)
			nextHeader = cseq
			//catch(ParseException e){}
			// = cseq;
		} else if _, ok := nextHeader.(*header.To); ok {
			if responseToHeader != nil {
				nextHeader = responseToHeader
			} else {
				//nextHeader = (SIPHeader) nextHeader.clone();
			}
		} else if vl, ok := nextHeader.(*header.ViaList); ok {
			// Bug reported by Gianluca Martinello
			//The ACK MUST contain a single Via header field,
			// and this MUST be equal to the top Via header
			// field of the original
			// request.

			nextHeader = vl.Front().Value.(header.Header)
		} else {
			//nextHeader = (SIPHeader) nextHeader.clone();
		}

		//try {
		newRequest.AttachHeader2(nextHeader, false)
		// } catch(SIPDuplicateHeaderException e){
		// 	e.printStackTrace();
		// }
	}
	return newRequest
}

// /** Create a new default SIPRequest from the original request. Warning:
// * the newly created SIPRequest, shares the headers of
// * this request but we generate any new headers that we need to modify
// * so  the original request is umodified. However, if you modify the
// * shared headers after this request is created, then the newly
// * created request will also be modified.
// * If you want to modify the original request
// * without affecting the returned Request
// * make sure you clone it before calling this method.
// *
// * Only required headers are copied.
// * <ul>
// * <li>
// * Contact headers are not included in the newly created request.
// * Setting the appropriate sequence number is the responsibility of
// * the caller. </li>
// * <li> RouteList is not copied for ACK and CANCEL </li>
// * <li> Note that we DO NOT copy the body of the
// * argument into the returned header. We do not copy the content
// * type header from the original request either. These have to be
// * added seperately and the content length has to be correctly Set
// * if necessary the content length is Set to 0 in the returned header.
// * </li>
// * <li>Contact List is not copied from the original request.</li>
// * <li>RecordRoute List is not included from original request. </li>
// * <li>Via header is not included from the original request. </li>
// * </ul>
// *
// *@param requestLine is the new request line.
// *
// *@param switchHeaders is a boolean flag that causes to and from
// * 	headers to switch (Set this to true if you are the
// *	server of the transaction and are generating a BYE
// *	request). If the headers are switched, we generate
// *	new From and To headers otherwise we just use the
// *	incoming headers.
// *
// *@return a new Default SIP Request which has the requestLine specified.
// *
// */
func (this *SIPRequest) CreateSIPRequest(requestLine *header.RequestLine, switchHeaders bool) *SIPRequest {
	newRequest := NewSIPRequest()
	newRequest.requestLine = this.requestLine
	for headerIterator := this.getHeaders().Front(); headerIterator != nil; headerIterator = headerIterator.Next() {
		nextHeader := headerIterator.Value.(header.Header)
		// For BYE and cancel Set the CSeq header to the
		// appropriate method.
		if newCseq, ok := nextHeader.(*header.CSeq); ok {
			// CSeq newCseq = (CSeq) nextHeader.clone();
			nextHeader = newCseq
			//try{
			newCseq.SetMethod(this.requestLine.GetMethod())
			//}
			//catch(ParseException e){}
		} else if vl, ok := nextHeader.(*header.ViaList); ok {
			via := vl.Front().Value.(*header.Via)
			via.RemoveParameter("branch")
			nextHeader = via
			// Cancel and ACK preserve the branch ID.
		} else if to, ok := nextHeader.(*header.To); ok {
			if switchHeaders {
				from := header.NewFrom()
				from.CloneTo(to)
				from.RemoveTag()
				nextHeader = from
			} else {
				//to2 := to.Clone().(*To)
				to.RemoveTag()
				nextHeader = to
			}
		} else if from, ok := nextHeader.(*header.From); ok {
			if switchHeaders {
				to := header.NewTo()
				to.CloneFrom(from)
				to.RemoveTag()
				nextHeader = to
			} else {
				//from2 := from.Clone().(*From)
				from.RemoveTag()
				nextHeader = from
			}
		} else if cl, ok := nextHeader.(*header.ContentLength); ok {
			//ContentLength cl  =
			//	(ContentLength) nextHeader.clone();
			//try{
			cl.SetContentLength(0)
			//}
			//catch(InvalidArgumentException e){}
			nextHeader = cl
		} else {
			_, ok1 := nextHeader.(*header.CallID)
			_, ok2 := nextHeader.(*header.MaxForwards)
			if !ok1 && !ok2 {
				// Route is kept by dialog.
				// RR is added by the caller.
				// Contact is added by the Caller
				// Any extension headers must be added
				// by the caller.
				continue
			}
		}
		//try {
		newRequest.AttachHeader2(nextHeader, false)
		//} catch(SIPDuplicateHeaderException e){
		//	e.printStackTrace();
		//}
	}
	return newRequest

}