示例#1
0
文件: parser.go 项目: hinike/gossip
// Parse a string representation of a CSeq header, returning a slice of at most one CSeq.
func parseCSeq(headerName string, headerText string) (
	headers []base.SipHeader, err error) {
	var cseq base.CSeq

	parts := splitByWhitespace(headerText)
	if len(parts) != 2 {
		err = fmt.Errorf("CSeq field should have precisely one whitespace section: '%s'",
			headerText)
		return
	}

	var seqno uint64
	seqno, err = strconv.ParseUint(parts[0], 10, 32)
	if err != nil {
		return
	}

	if seqno > MAX_CSEQ {
		err = fmt.Errorf("invalid CSeq %d: exceeds maximum permitted value "+
			"2**31 - 1", seqno)
		return
	}

	cseq.SeqNo = uint32(seqno)
	cseq.MethodName = base.Method(strings.TrimSpace(parts[1]))

	if strings.Contains(string(cseq.MethodName), ";") {
		err = fmt.Errorf("unexpected ';' in CSeq body: %s", headerText)
		return
	}

	headers = []base.SipHeader{&cseq}

	return
}
示例#2
0
文件: parser.go 项目: hinike/gossip
// Parse the first line of a SIP request, e.g:
//   INVITE [email protected] SIP/2.0
//   REGISTER [email protected] SIP/1.0
func parseRequestLine(requestLine string) (
	method base.Method, recipient base.Uri, sipVersion string, err error) {
	parts := strings.Split(requestLine, " ")
	if len(parts) != 3 {
		err = fmt.Errorf("request line should have 2 spaces: '%s'", requestLine)
		return
	}

	method = base.Method(strings.ToUpper(parts[0]))
	recipient, err = ParseUri(parts[1])
	sipVersion = parts[2]

	switch recipient.(type) {
	case *base.WildcardUri:
		err = fmt.Errorf("wildcard URI '*' not permitted in request line: '%s'", requestLine)
	}

	return
}