Ejemplo n.º 1
0
func (h *Handler) HandleElement(el element.Element, props stream.Properties) (
	[]element.Element, stream.Properties) {
	var elems []element.Element
	var challenge bool
	switch el.Tag {
	case "auth":
		mechName := el.SelectAttrValue("mechanism", "")
		mech, ok := h.mechs[mechName]
		if !ok {
			elems = append(elems, element.SASLFailure.InvalidMechanism)
			break
		}
		data := el.Text()
		log.Println("Authenticating")
		elems, props, challenge = mech.Authenticate(data, props)
		if challenge {
			h.current = mech
		}
	case "response":
		if h.current == nil {
			el := element.SASLFailure.NotAuthorized.
				AddChild(element.New("text").SetText("Out of order SASL element"))
			elems = append(elems, el)
		}
		data := el.Text()
		elems, props, challenge = h.current.Authenticate(data, props)
		if !challenge {
			h.current = nil
		}
	}
	return elems, props
}
Ejemplo n.º 2
0
func TransformPresence(el element.Element) (Presence, error) {
	if el.Tag != "presence" {
		return Presence{}, ErrNotPresence
	}
	presence := Presence{}
	presence.To = el.SelectAttrValue("to", "")
	presence.From = el.SelectAttrValue("from", "")
	presence.ID = el.SelectAttrValue("id", "")
	presence.Type = el.SelectAttrValue("type", "")
	presence.Lang = el.SelectAttrValue("xml:lang", "")
	presence.Data = el.Text()

	presence.Children = el.ChildElements()
	presence.Tag, presence.Space = el.Tag, el.Space

	return presence, nil
}
Ejemplo n.º 3
0
func TransformMessage(el element.Element) (Message, error) {
	if el.Tag != "message" {
		return Message{}, ErrNotMessage
	}
	message := Message{}
	message.To = el.SelectAttrValue("to", "")
	message.From = el.SelectAttrValue("from", "")
	message.ID = el.SelectAttrValue("id", "")
	message.Type = el.SelectAttrValue("type", "")
	message.Lang = el.SelectAttrValue("xml:lang", "")
	message.Data = el.Text()

	message.Children = el.ChildElements()
	message.Tag, message.Space = el.Tag, el.Space

	return message, nil
}
Ejemplo n.º 4
0
Archivo: iq.go Proyecto: skriptble/nine
func TransformIQ(el element.Element) IQ {
	if el.Tag != "iq" {
		return IQEmpty
	}
	iq := IQ{}
	iq.To = el.SelectAttrValue("to", "")
	iq.From = el.SelectAttrValue("from", "")
	iq.ID = el.SelectAttrValue("id", "")
	iq.Type = el.SelectAttrValue("type", "")
	iq.Lang = el.SelectAttrValue("xml:lang", "")
	iq.Data = el.Text()

	iq.Children = el.ChildElements()
	iq.Tag, iq.Space = el.Tag, el.Space

	return iq
}