示例#1
0
func (elm *Error) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "text":
				if err = elm.Text.Decode(d, &t); err != nil {
					return err
				}
			default:
				if t.Name.Space == NS {
					var s string
					if s, err = d.Text(); err != nil {
						return err
					}
					*elm.Condition.Extra = s
				}
			}
		}
	}
	return err
}
示例#2
0
func (elm *Mood) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "text":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Text = s
			default:
				if t.Name.Space == NS {
					*elm.Mood = MoodMood(t.Name.Local)
					if err = d.Skip(); err != nil {
						return err
					}
				}
			}
		}
	}
	return err
}
示例#3
0
func (elm *Invite) 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
}
}
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 == "reason":
var s string
if s, err = d.Text(); err != nil { return err }
*elm.Reason = s
}
}
}
return err
}
示例#4
0
func (elm *Vcard) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "VERSION":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.VERSION = s
			case t.Name.Space == NS && t.Name.Local == "FN":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.FN = s
			}
		}
	}
	return err
}
示例#5
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
}
示例#6
0
func (elm *Bind) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "resource":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Resource = s
			case t.Name.Space == NS && t.Name.Local == "jid":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				var j *jid.JID
				if j, err = jid.New(s); err != nil {
					return err
				}
				elm.Jid = j
			}
		}
	}
	return err
}
示例#7
0
func (elm *ORG) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "ORGNAME":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.ORGNAME = s
			case t.Name.Space == NS && t.Name.Local == "ORGUNIT":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				elm.ORGUNIT = append(elm.ORGUNIT, s)
			}
		}
	}
	return err
}
示例#8
0
func (elm *Action) 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.EndElement:
break Loop
case xml.StartElement:
switch {
case t.Name.Space == NS && t.Name.Local == "invite":
newel := &Invite{}
if err = newel.Decode(d, &t); err != nil { return err}
elm.Invite = append(elm.Invite, newel)
case t.Name.Space == NS && t.Name.Local == "password":
var s string
if s, err = d.Text(); err != nil { return err }
*elm.Password = s
case t.Name.Space == NS && t.Name.Local == "status":
newel := &Status{}
if err = newel.Decode(d, &t); err != nil { return err}
elm.Status = append(elm.Status, newel)
}
}
}
return err
}
示例#9
0
func (elm *BDAY) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	var s string
	if s, err = d.Text(); err != nil {
		return err
	}
	*elm = BDAY(s)
	return err
}
示例#10
0
func (elm *SOUND) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	var s string
	if s, err = d.Text(); err != nil {
		return err
	}
	*elm.Value = s
	return err
}
示例#11
0
func (elm *EMAIL) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "HOME":
				elm.HOME = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "WORK":
				elm.WORK = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "INTERNET":
				elm.INTERNET = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PREF":
				elm.PREF = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "X400":
				elm.X400 = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "USERID":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.USERID = s
			}
		}
	}
	return err
}
示例#12
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
}
示例#13
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
}
示例#14
0
文件: muc_data.go 项目: oxpa/bullxmpp
func (elm *Enter) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "history":
				for _, x := range tag.Attr {
					switch {
					case x.Name.Space == "" && x.Name.Local == "maxchars":
						var i int64
						i, err = strconv.ParseInt(x.Value, 10, 0)
						if err == nil {
							*elm.History.Maxchars = int(i)
						}
					case x.Name.Space == "" && x.Name.Local == "maxstanzas":
						var i int64
						i, err = strconv.ParseInt(x.Value, 10, 0)
						if err == nil {
							*elm.History.Maxstanzas = int(i)
						}
					case x.Name.Space == "" && x.Name.Local == "seconds":
						var i int64
						i, err = strconv.ParseInt(x.Value, 10, 0)
						if err == nil {
							*elm.History.Seconds = int(i)
						}
					case x.Name.Space == "" && x.Name.Local == "since":
						*elm.History.Since, err = time.Parse(time.RFC3339, x.Value)
						if err != nil {
							return err
						}
					}
				}
			case t.Name.Space == NS && t.Name.Local == "password":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Password = s
			}
		}
	}
	return err
}
示例#15
0
func (elm *X) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "type":
			value := XType(x.Value)
			elm.Type = &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 == "title":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Title = s
			case t.Name.Space == NS && t.Name.Local == "reported":
				var t xml.Token
			InLoop:
				for {
					if t, err = d.Token(); err != nil {
						return err
					}
					switch t := t.(type) {
					case xml.StartElement:
						if t.Name.Space == NS && t.Name.Local == "field" {
							newel := &Field{}
							if err = newel.Decode(d, &t); err != nil {
								return err
							}
							elm.Reported = append(elm.Reported, newel)
						}
					case xml.EndElement:
						break InLoop
					}
				}
			}
		}
	}
	return err
}
示例#16
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
}
示例#17
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
}
示例#18
0
func (elm *N) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "FAMILY":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.FAMILY = s
			case t.Name.Space == NS && t.Name.Local == "GIVEN":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.GIVEN = s
			case t.Name.Space == NS && t.Name.Local == "NIDDLE":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.NIDDLE = s
			case t.Name.Space == NS && t.Name.Local == "PREFIX":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.PREFIX = s
			case t.Name.Space == NS && t.Name.Local == "SUFFIX":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.SUFFIX = s
			}
		}
	}
	return err
}
示例#19
0
func (elm *Last) Decode(d *xmlencoder.Decoder, tag *xml.StartElement) error {
	var err error
	for _, x := range tag.Attr {
		switch {
		case x.Name.Space == "" && x.Name.Local == "seconds":
			var i uint64
			i, err = strconv.ParseUint(x.Value, 10, 0)
			if err == nil {
				*elm.Seconds = uint(i)
			}
		}
	}
	var s string
	if s, err = d.Text(); err != nil {
		return err
	}
	*elm.Extra = s
	return err
}
示例#20
0
func (elm *CATEGORIES) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "KEYWORD":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				elm.KEYWORD = append(elm.KEYWORD, s)
			}
		}
	}
	return err
}
示例#21
0
func (elm *PHOTO) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "TYPE":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.TYPE = s
			case t.Name.Space == NS && t.Name.Local == "BINVAL":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.BINVAL = s
			case t.Name.Space == NS && t.Name.Local == "EXTVAL":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.EXTVAL = s
			}
		}
	}
	return err
}
示例#22
0
func (elm *Version) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "name":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Name = s
			case t.Name.Space == NS && t.Name.Local == "version":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Version = s
			case t.Name.Space == NS && t.Name.Local == "os":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Os = s
			}
		}
	}
	return err
}
示例#23
0
func (elm *Time) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "utc":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Utc = s
			case t.Name.Space == NS && t.Name.Local == "tz":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Tz = s
			case t.Name.Space == NS && t.Name.Local == "display":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Display = s
			}
		}
	}
	return err
}
示例#24
0
func (elm *Query) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "registered":
				if err = d.Skip(); err != nil {
					return err
				}
			case t.Name.Space == NS && t.Name.Local == "instructions":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Instructions = s
			case t.Name.Space == NS && t.Name.Local == "username":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Username = s
			case t.Name.Space == NS && t.Name.Local == "nick":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Nick = s
			case t.Name.Space == NS && t.Name.Local == "password":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Password = s
			case t.Name.Space == NS && t.Name.Local == "name":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Name = s
			case t.Name.Space == NS && t.Name.Local == "first":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.First = s
			case t.Name.Space == NS && t.Name.Local == "last":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Last = s
			case t.Name.Space == NS && t.Name.Local == "email":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Email = s
			case t.Name.Space == NS && t.Name.Local == "address":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Address = s
			case t.Name.Space == NS && t.Name.Local == "city":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.City = s
			case t.Name.Space == NS && t.Name.Local == "state":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.State = s
			case t.Name.Space == NS && t.Name.Local == "zip":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Zip = s
			case t.Name.Space == NS && t.Name.Local == "phone":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Phone = s
			case t.Name.Space == NS && t.Name.Local == "url":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Url = s
			case t.Name.Space == NS && t.Name.Local == "date":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Date = s
			case t.Name.Space == NS && t.Name.Local == "misc":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Misc = s
			case t.Name.Space == NS && t.Name.Local == "text":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Text = s
			case t.Name.Space == NS && t.Name.Local == "key":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Fields.Key = s
			case t.Name.Space == NS && t.Name.Local == "remove":
				elm.Remove = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			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
			case t.Name.Space == "jabber:x:oob" && t.Name.Local == "x":
				newel := &xoob.X{}
				if err = newel.Decode(d, &t); err != nil {
					return err
				}
				elm.Xoob = newel
			}
		}
	}
	return err
}
示例#25
0
func (elm *Message) 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 := MessageType(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 == "thread":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.Thread = s
			case t.Name.Space == NS && t.Name.Local == "subject":
				if err = elm.Subject.Decode(d, &t); err != nil {
					return err
				}
			case t.Name.Space == NS && t.Name.Local == "body":
				if err = elm.Body.Decode(d, &t); err != nil {
					return err
				}
			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
}
示例#26
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
}
示例#27
0
func (elm *ADR) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "HOME":
				elm.HOME = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "WORK":
				elm.WORK = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "POSTAL":
				elm.POSTAL = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PARCEL":
				elm.PARCEL = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PREF":
				elm.PREF = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "POBOX":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.POBOX = s
			case t.Name.Space == NS && t.Name.Local == "EXTADD":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.EXTADD = s
			case t.Name.Space == NS && t.Name.Local == "STREET":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.STREET = s
			case t.Name.Space == NS && t.Name.Local == "LOCALITY":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.LOCALITY = s
			case t.Name.Space == NS && t.Name.Local == "REGION":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.REGION = s
			case t.Name.Space == NS && t.Name.Local == "PCODE":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.PCODE = s
			case t.Name.Space == NS && t.Name.Local == "CTRY":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.CTRY = s
			default:
				if t.Name.Space == NS {
					*elm.DOMINTL = DOMINTL(t.Name.Local)
					if err = d.Skip(); err != nil {
						return err
					}
				}
			}
		}
	}
	return err
}
示例#28
0
func (elm *TEL) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "HOME":
				elm.HOME = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "WORK":
				elm.WORK = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "VOICE":
				elm.VOICE = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "FAX":
				elm.FAX = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PAGER":
				elm.PAGER = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "MSG":
				elm.MSG = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "CELL":
				elm.CELL = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "VIDEO":
				elm.VIDEO = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "BBS":
				elm.BBS = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "MODEM":
				elm.MODEM = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "ISDN":
				elm.ISDN = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PCS":
				elm.PCS = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PREF":
				elm.PREF = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "NUMBER":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				*elm.NUMBER = s
			}
		}
	}
	return err
}
示例#29
0
func (elm *LABEL) 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.EndElement:
			break Loop
		case xml.StartElement:
			switch {
			case t.Name.Space == NS && t.Name.Local == "HOME":
				elm.HOME = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "WORK":
				elm.WORK = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "POSTAL":
				elm.POSTAL = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PARCEL":
				elm.PARCEL = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "PREF":
				elm.PREF = true
				if err = d.Skip(); err != nil {
					return err
				}
				continue
			case t.Name.Space == NS && t.Name.Local == "LINE":
				var s string
				if s, err = d.Text(); err != nil {
					return err
				}
				elm.LINE = append(elm.LINE, s)
			default:
				if t.Name.Space == NS {
					*elm.DOMINTL = DOMINTL(t.Name.Local)
					if err = d.Skip(); err != nil {
						return err
					}
				}
			}
		}
	}
	return err
}