Пример #1
0
func (elm *Delete) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = 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 {
			case t.Name.Space == NS && t.Name.Local == "redirect":
				for _, x := range tag.Attr {
					switch {
					case x.Name.Space == "" && x.Name.Local == "url":
						elm.Redirect.Url = xmlencoder.Copystring(x.Value)
					}
				}
			}
		}
	}
	return err
}
Пример #2
0
func (elm *Start) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		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 == "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 == "id":
			elm.Id = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "version":
			elm.Version = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "http://www.w3.org/XML/1998/namespace" && x.Name.Local == "lang":
			elm.Lang = &x.Value
		}
	}
	return err
}
Пример #3
0
func (elm *Collection) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = 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 t.Name.Space == NS {
					for _, x := range tag.Attr {
						switch {
						case x.Name.Space == "" && x.Name.Local == "node":
							elm.Type.Node = xmlencoder.Copystring(x.Value)
						}
					}
				}
			}
		}
	}
	return err
}
Пример #4
0
func (elm *Subscription) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "expiry":
			*elm.Expiry, err = time.Parse(time.RFC3339, x.Value)
			if err != nil {
				return err
			}
		case x.Name.Space == "" && x.Name.Local == "jid":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.Jid = j
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "subid":
			elm.Subid = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "subscription":
			value := SubscriptionSubscription(x.Value)
			elm.Subscription = &value
		}
	}
	return err
}
Пример #5
0
func (elm *Field) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "label":
			elm.Label = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "type":
			value := FieldType(x.Value)
			elm.Type = &value
		case x.Name.Space == "" && x.Name.Local == "var":
			elm.Var = 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 {
			case t.Name.Space == NS && t.Name.Local == "desc":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Desc = s
			case t.Name.Space == NS && t.Name.Local == "required":
				elm.Required = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "value":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Value = s
			case t.Name.Space == NS && t.Name.Local == "option":
				newel := &Option{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Option = append(elm.Option, newel)
			}
		}
	}
	return err
}
Пример #6
0
func (elm *Identity) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "category":
			elm.Category = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "type":
			elm.Type = xmlencoder.Copystring(x.Value)
		}
	}
	return err
}
Пример #7
0
func (elm *Stat) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "name":
			elm.Name = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "units":
			elm.Units = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "value":
			elm.Value = xmlencoder.Copystring(x.Value)
		}
	}
	return err
}
Пример #8
0
func (elm *Option) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "label":
			elm.Label = 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 {
			case t.Name.Space == NS && t.Name.Local == "value":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Value = s
			}
		}
	}
	return err
}
Пример #9
0
func (elm *Configuration) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = 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 {
			case t.Name.Space == "jabber:x:data" && t.Name.Local == "x":
				newel := &xdata.X{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Xdata = newel
			}
		}
	}
	return err
}
Пример #10
0
func (elm *Caps) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "ext":
			elm.Ext = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "hash":
			elm.Hash = 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 == "ver":
			elm.Ver = xmlencoder.Copystring(x.Value)
		}
	}
	return err
}
Пример #11
0
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 == "action":
			value := ItemAction(x.Value)
			elm.Action = &value
		case x.Name.Space == "" && x.Name.Local == "order":
			var i uint64
			i, err = strconv.ParseUint(x.Value, 10, 0)
			if err == nil {
				*elm.Order = uint(i)
			}
		case x.Name.Space == "" && x.Name.Local == "type":
			value := ItemType(x.Value)
			elm.Type = &value
		case x.Name.Space == "" && x.Name.Local == "value":
			elm.Value = 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 {
			case t.Name.Space == NS && t.Name.Local == "iq":
				elm.Iq = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "message":
				elm.Message = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "presence-in":
				elm.PresenceIn = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "presence-out":
				elm.PresenceOut = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			}
		}
	}
	return err
}
Пример #12
0
func (elm *List) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "name":
			elm.Name = 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 {
			case t.Name.Space == NS && t.Name.Local == "item":
				newel := &Item{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Items = append(elm.Items, newel)
			}
		}
	}
	return err
}
Пример #13
0
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
}
Пример #14
0
func (elm *Retract) 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)
		}
	}
	return err
}
Пример #15
0
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 == "affiliation":
			value := ItemAffiliation(x.Value)
			elm.Affiliation = &value
		case x.Name.Space == "" && x.Name.Local == "jid":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.Jid = j
		case x.Name.Space == "" && x.Name.Local == "nick":
			elm.Nick = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "role":
			value := ItemRole(x.Value)
			elm.Role = &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 == "actor":
				for _, x := range tag.Attr {
					switch {
					case x.Name.Space == "" && x.Name.Local == "jid":
						var j *jid.JID
						if j, err = jid.New(x.Value); err != nil {
							return err
						}
						elm.Actor.Jid = j
					}
				}
			case t.Name.Space == NS && t.Name.Local == "reason":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Reason = s
			}
		}
	}
	return err
}
Пример #16
0
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
}
Пример #17
0
func (elm *Default) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "name":
			elm.Name = xmlencoder.Copystring(x.Value)
		}
	}
	var s string
	if s, err = d.Text(); err != nil {
		return err
	}
	*elm.Extra = s
	return err
}
Пример #18
0
func (elm *Auth) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "mechanism":
			elm.Mechanism = xmlencoder.Copystring(x.Value)
		}
	}
	var bdata []byte
	if bdata, err = d.Bytes(); err != nil {
		return err
	}
	elm.Data = bdata
	return err
}
Пример #19
0
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 == "approved":
			var b bool
			b, err = strconv.ParseBool(x.Value)
			if err == nil {
				elm.Approved = b
			}
		case x.Name.Space == "" && x.Name.Local == "ask":
			value := ItemAsk(x.Value)
			elm.Ask = &value
		case x.Name.Space == "" && x.Name.Local == "jid":
			var j *jid.JID
			if j, err = jid.New(x.Value); err != nil {
				return err
			}
			elm.Jid = j
		case x.Name.Space == "" && x.Name.Local == "name":
			elm.Name = xmlencoder.Copystring(x.Value)
		case x.Name.Space == "" && x.Name.Local == "subscription":
			value := ItemSubscription(x.Value)
			elm.Subscription = &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 == "group":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				elm.Group = append(elm.Group, s)
			}
		}
	}
	return err
}
Пример #20
0
func (elm *Info) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "node":
			elm.Node = 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 {
			case t.Name.Space == NS && t.Name.Local == "identity":
				newel := &Identity{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Identities = append(elm.Identities, newel)
			case t.Name.Space == NS && t.Name.Local == "feature":
				newel := &Feature{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Features = append(elm.Features, newel)
			}
		}
	}
	return err
}
Пример #21
0
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
}