go fix. Clearly, I need to run this more often ;)

This commit is contained in:
Matt Goodall 2012-07-18 11:40:05 +01:00
parent 82015bcab4
commit 9ba9dcbe86
9 changed files with 54 additions and 55 deletions

View File

@ -18,7 +18,7 @@ func main() {
// Create stream and configure it as a client connection.
jid := must(xmpp.ParseJID(*jid)).(xmpp.JID)
stream := must(xmpp.NewStream(jid.Domain + ":5222", &xmpp.StreamConfig{LogStanzas: true})).(*xmpp.Stream)
stream := must(xmpp.NewStream(jid.Domain+":5222", &xmpp.StreamConfig{LogStanzas: true})).(*xmpp.Stream)
client := must(xmpp.NewClientXMPP(stream, jid, *password, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
log.Printf("Connection established for %s\n", client.JID)

View File

@ -142,12 +142,12 @@ func authenticate(stream *Stream, mechanisms []string, user, password string) er
type authHandler struct {
Mechanism string
Fn func(*Stream, string, string) error
Fn func(*Stream, string, string) error
}
var authHandlers = []authHandler{
authHandler{"PLAIN", authenticatePlain},
}
{"PLAIN", authenticatePlain},
}
func authenticatePlain(stream *Stream, user, password string) error {
auth := saslAuth{Mechanism: "PLAIN", Text: saslEncodePlain(user, password)}
@ -181,9 +181,9 @@ func authenticateResponse(stream *Stream) error {
}
type saslAuth struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl auth"`
Mechanism string `xml:"mechanism,attr"`
Text string `xml:",chardata"`
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl auth"`
Mechanism string `xml:"mechanism,attr"`
Text string `xml:",chardata"`
}
func bindResource(stream *Stream, jid JID) (JID, error) {
@ -211,9 +211,9 @@ func bindResource(stream *Stream, jid JID) (JID, error) {
}
type bindIq struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
Resource string `xml:"resource,omitempty"`
JID string `xml:"jid,omitempty"`
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
Resource string `xml:"resource,omitempty"`
JID string `xml:"jid,omitempty"`
}
func establishSession(stream *Stream, domain string) error {
@ -244,11 +244,11 @@ func stringSliceContains(l []string, m string) bool {
}
type features struct {
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
StartTLS *tlsStartTLS `xml:"starttls"`
Mechanisms *mechanisms `xml:"mechanisms"`
Bind *bind `xml:"bind"`
Session *session `xml:"session"`
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
StartTLS *tlsStartTLS `xml:"starttls"`
Mechanisms *mechanisms `xml:"mechanisms"`
Bind *bind `xml:"bind"`
Session *session `xml:"session"`
}
type session struct {
@ -256,25 +256,25 @@ type session struct {
}
type bind 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"`
Required *required `xml:"required"`
}
type mechanisms struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
Mechanisms []string `xml:"mechanism"`
}
type tlsStartTLS struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
Required *required `xml:"required"`
}
type required struct {}
type required struct{}
type saslFailure struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
Reason xml.Name `xml:",any"`
Reason xml.Name `xml:",any"`
}
// BUG(matt): authentication incorrectly reports, "No supported SASL mechanism

View File

@ -86,5 +86,5 @@ func handshake(stream *Stream, streamId, secret string) error {
type saslHandshake struct {
XMLName xml.Name `xml:"jabber:component:accept handshake"`
Value string `xml:",chardata"`
Value string `xml:",chardata"`
}

View File

@ -9,12 +9,12 @@ import (
// XMPP <iq/> stanza.
type Iq struct {
XMLName xml.Name `xml:"iq"`
Id string `xml:"id,attr"`
Type string `xml:"type,attr"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
Payload string `xml:",innerxml"`
Error *Error `xml:"error"`
Id string `xml:"id,attr"`
Type string `xml:"type,attr"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
Payload string `xml:",innerxml"`
Error *Error `xml:"error"`
}
// Encode the value to an XML string and set as the payload. See xml.Marshal
@ -57,29 +57,29 @@ func (iq *Iq) Response(type_ string) *Iq {
// XMPP <message/> stanza.
type Message struct {
XMLName xml.Name `xml:"message"`
Id string `xml:"id,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"`
Id string `xml:"id,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"`
}
// XMPP <presence/> stanza.
type Presence struct {
XMLName xml.Name `xml:"presence"`
Id string `xml:"id,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
Id string `xml:"id,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
To string `xml:"to,attr,omitempty"`
From string `xml:"from,attr,omitempty"`
}
// XMPP <error/>. May occur as a top-level stanza or embedded in another
// stanza, e.g. an <iq type="error"/>.
type Error struct {
XMLName xml.Name `xml:"error"`
Type string `xml:"type,attr"`
Payload string `xml:",innerxml"`
Type string `xml:"type,attr"`
Payload string `xml:",innerxml"`
}
func (e Error) Error() string {
@ -93,7 +93,7 @@ func (e Error) Error() string {
type errorText struct {
XMLName xml.Name
Text string `xml:",chardata"`
Text string `xml:",chardata"`
}
// Create a new Error instance using the args as the payload.

View File

@ -19,10 +19,10 @@ type StreamConfig struct {
}
type Stream struct {
conn net.Conn
dec *xml.Decoder
config *StreamConfig
stanzaBuf string
conn net.Conn
dec *xml.Decoder
config *StreamConfig
stanzaBuf string
incomingNamespace nsMap
}

View File

@ -15,4 +15,3 @@ func UUID4() string {
uuid[8] = (uuid[8] &^ 0x40) | 0x80
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
}

View File

@ -12,7 +12,7 @@ type XMPP struct {
// JID associated with the stream. Note: this may be negotiated with the
// server during setup and so must be used for all messages.
JID JID
JID JID
stream *Stream
// Channel of incoming messages. Values will be one of Iq, Message,
@ -26,17 +26,17 @@ type XMPP struct {
Out chan interface{}
// Incoming stanza filters.
filterLock sync.Mutex
filterLock sync.Mutex
nextFilterId FilterId
filters []filter
filters []filter
}
func newXMPP(jid JID, stream *Stream) *XMPP {
x := &XMPP{
JID: jid,
JID: jid,
stream: stream,
In: make(chan interface{}),
Out: make(chan interface{}),
In: make(chan interface{}),
Out: make(chan interface{}),
}
go x.sender()
go x.receiver()
@ -84,7 +84,7 @@ func (fid FilterId) Error() string {
type filter struct {
id FilterId
m Matcher
m Matcher
ch chan interface{}
}
@ -100,7 +100,7 @@ func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) {
// Allocate chan and id.
ch := make(chan interface{})
id := x.nextFilterId
x.nextFilterId ++
x.nextFilterId++
// Insert at head of filters list.
filters := make([]filter, len(x.filters)+1)

View File

@ -11,7 +11,7 @@ var (
skipverify = false
jid = ""
pass = ""
debug = false
debug = false
)
func init() {