コード例 #1
0
ファイル: ChallengeParser.go プロジェクト: hinike/gosips
/** Get the parameter of the challenge string
 * @return NameValue containing the parameter
 */
func (this *ChallengeParser) ParseParameter(h header.AuthorizationHeader) (ParseException error) {
	var nv *core.NameValue
	if nv, ParseException = this.NameValue('='); ParseException != nil {
		return ParseException
	}
	ParseException = h.SetParameter(nv.GetName(), nv.GetValue().(string))
	return ParseException
}
コード例 #2
0
/** parse the AuthenticationInfo String header
 * @return Header (AuthenticationInfoList object)
 * @throws SIPParseException if the message does not respect the spec.
 */
func (this *AuthenticationInfoParser) Parse() (sh header.Header, ParseException error) {
	var ch byte
	var nv *core.NameValue
	lexer := this.GetLexer()
	this.HeaderName(TokenTypes_AUTHENTICATION_INFO)

	authenticationInfo := header.NewAuthenticationInfo()
	authenticationInfo.SetHeaderName(core.SIPHeaderNames_AUTHENTICATION_INFO)

	lexer.SPorHT()

	if nv, ParseException = this.NameValue('='); ParseException != nil {
		return nil, ParseException
	}
	authenticationInfo.SetParameter(nv.GetName(), nv.GetValue().(string))

	lexer.SPorHT()
	for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
		lexer.Match(',')
		lexer.SPorHT()

		if nv, ParseException = this.NameValue('='); ParseException != nil {
			return nil, ParseException
		}
		authenticationInfo.SetParameter(nv.GetName(), nv.GetValue().(string))

		lexer.SPorHT()
	}
	lexer.SPorHT()
	lexer.Match('\n')

	return authenticationInfo, nil
}
コード例 #3
0
ファイル: ParametersParser.go プロジェクト: hinike/gosips
func (this *ParametersParser) Parse(parametersHeader header.ParametersHeader) (ParseException error) {
	var ch byte
	var nv *core.NameValue

	lexer := this.GetLexer()

	lexer.SPorHT()
	if ch, ParseException = lexer.LookAheadK(0); ParseException != nil {
		return ParseException
	}

	for ch == ';' {
		lexer.ConsumeK(1)
		// eat white space
		lexer.SPorHT()

		if nv, ParseException = this.NameValue('='); ParseException != nil {
			return ParseException
		}

		if nv.IsValueQuoted() {
			parametersHeader.SetParameter(nv.GetName(), "\""+nv.GetValue().(string)+"\"")
		} else {
			parametersHeader.SetParameter(nv.GetName(), nv.GetValue().(string))
		}

		// eat white space
		lexer.SPorHT()

		if ch, ParseException = lexer.LookAheadK(0); ParseException != nil {
			return ParseException
		}
	}
	return nil
}
コード例 #4
0
ファイル: ViaParser.go プロジェクト: hinike/gosips
/**  a parser for the essential part of the via header.
 */
func (this *ViaParser) ParseVia(v *header.Via) (ParseException error) {
	lexer := this.GetLexer()

	var protocolName, protocolVersion *core.Token
	// The protocol
	lexer.Match(TokenTypes_ID)

	if protocolName = lexer.GetNextToken(); protocolName.GetTokenValue() != "SIP" {
		return this.CreateParseException("Protcoal Not Supported error")
	}

	lexer.SPorHT()
	// consume the "/"
	lexer.Match('/')
	lexer.SPorHT()
	lexer.Match(TokenTypes_ID)
	lexer.SPorHT()
	if protocolVersion = lexer.GetNextToken(); protocolVersion.GetTokenValue() != "2.0" {
		return this.CreateParseException("Version Not Supported error")
	}

	lexer.SPorHT()

	// We consume the "/"
	lexer.Match('/')
	lexer.SPorHT()
	lexer.Match(TokenTypes_ID)
	lexer.SPorHT()

	transport := lexer.GetNextToken()
	lexer.SPorHT()

	protocol := header.NewProtocol()
	protocol.SetProtocolName(protocolName.GetTokenValue())
	protocol.SetProtocolVersion(protocolVersion.GetTokenValue())
	protocol.SetTransport(transport.GetTokenValue())
	v.SetSentProtocol(protocol)

	// sent-By
	hnp := core.NewHostNameParserFromLexer(this.GetLexer())

	var hostPort *core.HostPort
	if hostPort, ParseException = hnp.GetHostPort(); ParseException != nil {
		return ParseException
	}
	v.SetSentBy(hostPort)

	// Ignore blanks
	lexer.SPorHT()

	var la byte
	for la, _ = lexer.LookAheadK(0); la == ';'; la, _ = lexer.LookAheadK(0) {
		lexer.Match(';')
		lexer.SPorHT()

		var nameValue *core.NameValue
		if nameValue, ParseException = this.NameValue(); ParseException != nil {
			return ParseException
		}

		name := nameValue.GetName()
		nameValue.SetName(strings.ToLower(name))
		v.SetParameterFromNameValue(nameValue)
		lexer.SPorHT()
	}

	if la, _ = lexer.LookAheadK(0); la == '(' {
		lexer.SelectLexer("charLexer")
		lexer.ConsumeK(1)

		var comment bytes.Buffer
		for {
			ch, _ := lexer.LookAheadK(0)
			if ch == ')' {
				lexer.ConsumeK(1)
				break
			} else if ch == '\\' {
				// Escaped character
				tok := lexer.GetNextToken()
				comment.WriteString(tok.GetTokenValue())
				lexer.ConsumeK(1)
				tok = lexer.GetNextToken()
				comment.WriteString(tok.GetTokenValue())
				lexer.ConsumeK(1)
			} else if ch == '\n' {
				break
			} else {
				comment.WriteByte(ch)
				lexer.ConsumeK(1)
			}
		}
		v.SetComment(comment.String())
	}

	return nil

}