コード例 #1
0
ファイル: stream_data.go プロジェクト: oxpa/bullxmpp
func (elm *Features) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	var t xml.Token
Loop:
	for {
		if t, err = d.Token(); err != nil {
			return err
		}
		switch t := t.(type) {
		case xml.StartElement:
			if newel, ok := xmlencoder.GetExtension(t.Name); ok {
				if err = newel.(xmlencoder.Extension).Decode(d, &t); err != nil {
					return err
				}
				*elm = append(*elm, newel)
			} else {
				if err = d.Skip(); err != nil {
					return err
				}
			}
		case xml.EndElement:
			break Loop
		}
	}
	return err
}
コード例 #2
0
ファイル: client_data.go プロジェクト: oxpa/bullxmpp
func (elm *Iq) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "from":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.From = j
		case x.Name.Space == "" && x.Name.Local == "to":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.To = j
		case x.Name.Space == "" && x.Name.Local == "id":
			elm.Id = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "type":
			value := IqType(x.Value)
			elm.Type = &value
		case x.Name.Space == "http://www.w3.org/XML/1998/namespace" && x.Name.Local == "lang":
			elm.Lang = &x.Value
		}
	}
	var t xml.Token
Loop:
	for {
		if t, err = d.Token(); err != nil {
			return err
		}
		switch t := t.(type) {
		case xml.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			default:
				if newel, ok := xmlencoder.GetExtension(t.Name); ok {
					if err = newel.(xmlencoder.Extension).Decode(d, &t); err != nil {
						return err
					}
					elm.Payload = newel
				} else {
					if err = d.Skip(); err != nil {
						return err
					}
				}
			case t.Name.Space == "urn:ietf:params:xml:ns:xmpp-stanzas" && t.Name.Local == "error":
				newel := &stanza.Error{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Error = newel
			}
		}
	}
	return err
}
コード例 #3
0
ファイル: event_data.go プロジェクト: oxpa/bullxmpp
func (elm *Item) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "id":
			elm.Id = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "publisher":
			elm.Publisher = xmlencoder.Copystring(x.Value)
		}
	}
	var t xml.Token
Loop:
	for {
		if t, err = d.Token(); err != nil {
			return err
		}
		switch t := t.(type) {
		case xml.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			default:
				if newel, ok := xmlencoder.GetExtension(t.Name); ok {
					if err = newel.(xmlencoder.Extension).Decode(d, &t); err != nil {
						return err
					}
					elm.Event = newel
				} else {
					if err = d.Skip(); err != nil {
						return err
					}
				}
			}
		}
	}
	return err
}
コード例 #4
0
ファイル: client_data.go プロジェクト: oxpa/bullxmpp
func (elm *Presence) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "from":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.From = j
		case x.Name.Space == "" && x.Name.Local == "to":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.To = j
		case x.Name.Space == "" && x.Name.Local == "id":
			elm.Id = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "type":
			value := PresenceType(x.Value)
			elm.Type = &value
		case x.Name.Space == "http://www.w3.org/XML/1998/namespace" && x.Name.Local == "lang":
			elm.Lang = &x.Value
		}
	}
	var t xml.Token
Loop:
	for {
		if t, err = d.Token(); err != nil {
			return err
		}
		switch t := t.(type) {
		case xml.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "show":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Show = PresenceShow(s)
			case t.Name.Space == NS && t.Name.Local == "status":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Status = s
			case t.Name.Space == NS && t.Name.Local == "priority":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				var i int64
				if i, err = strconv.ParseInt(s, 10, 0); err == nil {
					*elm.Priority = int(i)
				}
			default:
				if newel, ok := xmlencoder.GetExtension(t.Name); ok {
					if err = newel.(xmlencoder.Extension).Decode(d, &t); err != nil {
						return err
					}
					elm.X = append(elm.X, newel)
				} else {
					if err = d.Skip(); err != nil {
						return err
					}
				}
			case t.Name.Space == "urn:ietf:params:xml:ns:xmpp-stanzas" && t.Name.Local == "error":
				newel := &stanza.Error{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Error = newel
			}
		}
	}
	return err
}