forked from jshiffer/go-xmpp
Merge pull request #16 from sushimako/master
Jid in bindBind was not unmarshalled due to missing xml-spec
This commit is contained in:
commit
df87efc875
27
xmpp.go
27
xmpp.go
@ -222,15 +222,25 @@ type Chat struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
type Presence struct {
|
||||
From string
|
||||
To string
|
||||
Type string
|
||||
Show string
|
||||
}
|
||||
|
||||
// Recv wait next token of chat.
|
||||
func (c *Client) Recv() (chat Chat, err error) {
|
||||
func (c *Client) Recv() (event interface{}, err error) {
|
||||
for {
|
||||
_, val, err := next(c.p)
|
||||
if err != nil {
|
||||
return Chat{}, err
|
||||
}
|
||||
if v, ok := val.(*clientMessage); ok {
|
||||
switch v := val.(type) {
|
||||
case *clientMessage:
|
||||
return Chat{v.From, v.Type, v.Body}, nil
|
||||
case *clientPresence:
|
||||
return Presence{v.From, v.To, v.Type, v.Show}, nil
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
@ -238,13 +248,12 @@ func (c *Client) Recv() (chat Chat, err error) {
|
||||
|
||||
// Send sends message text.
|
||||
func (c *Client) Send(chat Chat) {
|
||||
fmt.Fprintf(c.tls, "<message to='%s' type='chat' xml:lang='en'>"+
|
||||
fmt.Fprintf(c.tls, "<message to='%s' type='%s' xml:lang='en'>"+
|
||||
"<body>%s</body></message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Text))
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||
}
|
||||
|
||||
// RFC 3920 C.1 Streams name space
|
||||
|
||||
type streamFeatures struct {
|
||||
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
|
||||
StartTLS tlsStartTLS
|
||||
@ -308,7 +317,7 @@ type saslFailure struct {
|
||||
type bindBind struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
|
||||
Resource string
|
||||
Jid string
|
||||
Jid string `xml:"jid"`
|
||||
}
|
||||
|
||||
// RFC 3921 B.1 jabber:client
|
||||
@ -340,9 +349,9 @@ type clientPresence struct {
|
||||
Type string `xml:"type,attr"` // error, probe, subscribe, subscribed, unavailable, unsubscribe, unsubscribed
|
||||
Lang string `xml:"lang,attr"`
|
||||
|
||||
Show string `xml:"show,attr"`// away, chat, dnd, xa
|
||||
Status string `xml:"status,attr"`// sb []clientText
|
||||
Priority string `xml:"priority,attr"`
|
||||
Show string `xml:"show"` // away, chat, dnd, xa
|
||||
Status string `xml:"status,attr"` // sb []clientText
|
||||
Priority string `xml:"priority,attr"`
|
||||
Error *clientError
|
||||
}
|
||||
|
||||
|
31
xmpp_muc.go
Normal file
31
xmpp_muc.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2013 Flo Lauber <dev@qatfy.at>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// TODO(flo):
|
||||
// - support password protected MUC rooms
|
||||
// - cleanup signatures of join/leave functions
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
nsMUC = "http://jabber.org/protocol/muc"
|
||||
nsMUCUser = "http://jabber.org/protocol/muc#user"
|
||||
)
|
||||
|
||||
// xep-0045 7.2
|
||||
func (c *Client) JoinMUC(jid string) {
|
||||
fmt.Fprintf(c.tls, "<presence to='%s'>\n"+
|
||||
"<x xmlns='%s' />\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), nsMUC)
|
||||
}
|
||||
|
||||
// xep-0045 7.14
|
||||
func (c *Client) LeaveMUC(jid string) {
|
||||
fmt.Fprintf(c.tls, "<presence from='%s' to='%s' type='unavailable' />",
|
||||
c.jid, xmlEscape(jid))
|
||||
}
|
Loading…
Reference in New Issue
Block a user