示例#1
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
}
示例#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 *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
}
示例#4
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
}
示例#5
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
}
示例#6
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
}
示例#7
0
文件: client.go 项目: oxpa/bullxmpp
func New(jid_s, password, lang string, secure bool, logging bool) (cli *Client, err error) {
	jid, err := jid.New(jid_s)
	if err != nil {
		return
	}
	return NewWithJID(jid, password, lang, secure, logging)
}
示例#8
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
}
示例#9
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
}