diff --git a/client.go b/client.go index 301e922..6c32611 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 1d6869e..34941d8 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -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 diff --git a/src/xmpp/component.go b/src/xmpp/component.go index 257b269..84cd628 100644 --- a/src/xmpp/component.go +++ b/src/xmpp/component.go @@ -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"` } diff --git a/src/xmpp/doc.go b/src/xmpp/doc.go index 27d38f1..3794dbd 100644 --- a/src/xmpp/doc.go +++ b/src/xmpp/doc.go @@ -31,7 +31,7 @@ The channel is sent all XMPP stanzas as well as terminating error (io.EOF for clean shutdown or any other error for something unexpected). The channel is also closed after an error. - + XMPP defines four types of stanza: , , and represented by Error, Iq, Message (shown below) and Presence structs respectively. diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index f791cca..584793d 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -9,12 +9,12 @@ import ( // XMPP 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 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 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 . May occur as a top-level stanza or embedded in another // stanza, e.g. an . 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. diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 4c3acc1..b856341 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -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 } diff --git a/src/xmpp/uuid.go b/src/xmpp/uuid.go index aafa40c..14d866f 100644 --- a/src/xmpp/uuid.go +++ b/src/xmpp/uuid.go @@ -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:]) } - diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 6dc75b7..20c5817 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -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) diff --git a/tail.go b/tail.go index d77aaf7..48f98e0 100644 --- a/tail.go +++ b/tail.go @@ -11,7 +11,7 @@ var ( skipverify = false jid = "" pass = "" - debug = false + debug = false ) func init() {