Example #1
0
func (this *RequestLineParser) Parse() (rl *header.RequestLine, ParseException error) {
	var m, v string
	var url address.URI

	retval := header.NewRequestLine()
	lexer := this.GetLexer()

	if m, ParseException = this.Method(); ParseException != nil {
		return nil, ParseException
	}

	lexer.SPorHT()
	retval.SetMethod(m)
	lexer.SelectLexer("sip_urlLexer")
	urlParser := NewURLParserFromLexer(this.GetLexer())
	if url, ParseException = urlParser.UriReference(); ParseException != nil {
		return nil, ParseException
	}
	lexer.SPorHT()
	retval.SetUri(url)
	lexer.SelectLexer("request_lineLexer")

	if v, ParseException = this.SipVersion(); ParseException != nil {
		return nil, ParseException
	}
	retval.SetSipVersion(v)
	lexer.SPorHT()
	lexer.Match('\n')

	return retval, nil
}
Example #2
0
	/*  BUGBUG
		* Need to revisit this check later...
	               * for now we just leave this to the
			* application to catch.
	*/

	if this.requestLine != nil && this.requestLine.GetMethod() != "" &&
		this.GetCSeq().GetMethod() != "" &&
		strings.ToLower(this.requestLine.GetMethod()) != strings.ToLower(this.GetCSeq().GetMethod()) {
		return errors.New("ParseException: CSEQ method mismatch with  Request-Line ")
	}

	return nil
}

// /**
// * Set the default values in the request URI if necessary.
// */
func (this *SIPRequest) SetDefaults() {
	// The request line may be unparseable (Set to nil by the
	// exception handler.
	if this.requestLine == nil {
		return
	}
	method := this.requestLine.GetMethod()
	// The requestLine may be malformed!
	if method == "" {
		return
	}
	u := this.requestLine.GetUri()
	if u == nil {
		return
	}
	if method == REGISTER || method == INVITE {
		if sipUri, ok := u.(address.SipURI); ok {
			//SipURIImpl sipUri = (SipURIImpl)  u;
			sipUri.SetUserParam(DEFAULT_USER)
			// try {
			sipUri.SetTransportParam(DEFAULT_TRANSPORT)
			// } catch (ParseException ex) {}
		}
	}
}

// /**
// * Patch up the request line as necessary.
// */
func (this *SIPRequest) SetRequestLineDefaults() {
	method := this.requestLine.GetMethod()
	if method == "" {
		cseq := this.GetCSeq().(*header.CSeq)
		if cseq != nil {
			method = cseq.GetMethod()
			this.requestLine.SetMethod(method)
		}
	}
}

// /**
// * A conveniance function to access the Request URI.
// *@return the requestURI if it exists.
// */
func (this *SIPRequest) GetRequestURI() address.URI {
	if this.requestLine == nil {
		return nil
	} else {
		return this.requestLine.GetUri()
	}
}

//        /** Sets the RequestURI of Request. The Request-URI is a SIP or
//         * SIPS URI or a general URI. It indicates the user or service to which
//         * this request  is being addressed. SIP elements MAY support
//         * Request-URIs with schemes  other than "sip" and "sips", for
//         * example the "tel" URI scheme. SIP  elements MAY translate
//         * non-SIP URIs using any mechanism at their disposal,  resulting
//         * in SIP URI, SIPS URI, or some other scheme.
//         *
//         * @param requestURI - the new Request URI of this request message
//         */
func (this *SIPRequest) SetRequestURI(uri address.URI) {
	if this.requestLine == nil {
		this.requestLine = header.NewRequestLine()
	}
	this.requestLine.SetUri(uri)
}

// /** Set the method.
// *@param method is the method to Set.
// *@throws IllegalArgumentException if the method is nil
// */
func (this *SIPRequest) SetMethod(method string) {
	//if method == nil
	//  throw new IllegalArgumentException("nil method");
	if this.requestLine == nil {
		this.requestLine = header.NewRequestLine()
	}
	this.requestLine.SetMethod(method)
	if this.cSeqHeader != nil {
		//try{
		this.cSeqHeader.SetMethod(method)
		//}catch(ParseException e){}
	}
}
Example #3
0
	/*  BUGBUG
		* Need to revisit this check later...
	               * for now we just leave this to the
			* application to catch.
	*/

	if this.requestLine != nil && this.requestLine.GetMethod() != "" &&
		this.GetCSeq().GetMethod() != "" &&
		strings.ToLower(this.requestLine.GetMethod()) != strings.ToLower(this.GetCSeq().GetMethod()) {
		return errors.New("ParseException: CSEQ method mismatch with  Request-Line ")
	}

	return nil
}

// /**
// * Set the default values in the request URI if necessary.
// */
func (this *SIPRequest) SetDefaults() {
	// The request line may be unparseable (Set to nil by the
	// exception handler.
	if this.requestLine == nil {
		return
	}
	method := this.requestLine.GetMethod()
	// The requestLine may be malformed!
	if method == "" {
		return
	}
	u := this.requestLine.GetUri()
	if u == nil {
		return
	}
	if method == REGISTER || method == INVITE {
		if sipUri, ok := u.(address.SipURI); ok {
			//SipURIImpl sipUri = (SipURIImpl)  u;
			sipUri.SetUserParam(DEFAULT_USER)
			// try {
			sipUri.SetTransportParam(DEFAULT_TRANSPORT)
			// } catch (ParseException ex) {}
		}
	}
}

// /**
// * Patch up the request line as necessary.
// */
func (this *SIPRequest) SetRequestLineDefaults() {
	method := this.requestLine.GetMethod()
	if method == "" {
		cseq := this.GetCSeq().(*header.CSeq)
		if cseq != nil {
			method = cseq.GetMethod()
			this.requestLine.SetMethod(method)
		}
	}
}

// /**
// * A conveniance function to access the Request URI.
// *@return the requestURI if it exists.
// */
func (this *SIPRequest) GetRequestURI() address.URI {
	if this.requestLine == nil {
		return nil
	} else {
		return this.requestLine.GetUri()
	}
}

//        /** Sets the RequestURI of Request. The Request-URI is a SIP or
//         * SIPS URI or a general URI. It indicates the user or service to which
//         * this request  is being addressed. SIP elements MAY support
//         * Request-URIs with schemes  other than "sip" and "sips", for
//         * example the "tel" URI scheme. SIP  elements MAY translate
//         * non-SIP URIs using any mechanism at their disposal,  resulting
//         * in SIP URI, SIPS URI, or some other scheme.
//         *
//         * @param requestURI - the new Request URI of this request message
//         */
func (this *SIPRequest) SetRequestURI(uri address.URI) {
	if this.requestLine == nil {
		this.requestLine = header.NewRequestLine()
	}
	this.requestLine.SetUri(uri)
}