This commit is contained in:
Yasuhiro Matsumoto 2018-05-05 20:33:05 +09:00
parent 4fdbee9ac5
commit e543ad3fcd
No known key found for this signature in database
GPG Key ID: 622DE34DC490584B
2 changed files with 43 additions and 43 deletions

View File

@ -661,7 +661,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
thdtext = `<thread>` + xmlEscape(chat.Thread) + `</thread>` thdtext = `<thread>` + xmlEscape(chat.Thread) + `</thread>`
} }
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + thdtext + "</message>" stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + thdtext + "</message>"
return fmt.Fprintf(c.conn, stanza, return fmt.Fprintf(c.conn, stanza,
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text)) xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
@ -759,7 +759,7 @@ type saslFailure struct {
type bindBind struct { type bindBind struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
Resource string Resource string
Jid string `xml:"jid"` Jid string `xml:"jid"`
} }
// RFC 3921 B.1 jabber:client // RFC 3921 B.1 jabber:client

View File

@ -8,19 +8,19 @@
package xmpp package xmpp
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
"errors"
) )
const ( const (
nsMUC = "http://jabber.org/protocol/muc" nsMUC = "http://jabber.org/protocol/muc"
nsMUCUser = "http://jabber.org/protocol/muc#user" nsMUCUser = "http://jabber.org/protocol/muc#user"
NoHistory = 0 NoHistory = 0
CharHistory = 1 CharHistory = 1
StanzaHistory = 2 StanzaHistory = 2
SecondsHistory = 3 SecondsHistory = 3
SinceHistory = 4 SinceHistory = 4
) )
// Send sends room topic wrapped inside an XMPP message stanza body. // Send sends room topic wrapped inside an XMPP message stanza body.
@ -47,35 +47,35 @@ func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_da
} }
switch history_type { switch history_type {
case NoHistory: case NoHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s' />\n" + "<x xmlns='%s' />\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC) xmlEscape(jid), xmlEscape(nick), nsMUC)
case CharHistory: case CharHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case SinceHistory: case SinceHistory:
if history_date != nil { if history_date != nil {
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<history since='%s'/></x>\n" + "<history since='%s'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339)) xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
} }
} }
return 0, errors.New("Unknown history option") return 0, errors.New("Unknown history option")
@ -88,41 +88,41 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
} }
switch history_type { switch history_type {
case NoHistory: case NoHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<password>%s</password>" + "<password>%s</password>"+
"</x>\n" + "</x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password)) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
case CharHistory: case CharHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case SinceHistory: case SinceHistory:
if history_date != nil { if history_date != nil {
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" + return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n" + "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history since='%s'/></x>\n" + "<history since='%s'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339)) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
} }
} }
return 0, errors.New("Unknown history option") return 0, errors.New("Unknown history option")