diff options
Diffstat (limited to 'connector/xmpp')
-rw-r--r-- | connector/xmpp/xmpp.go | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index 02d1a96..7e35135 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -3,12 +3,12 @@ package xmpp import ( "time" //"os" - "strings" - "fmt" "crypto/tls" + "fmt" + "strings" - log "github.com/sirupsen/logrus" gxmpp "github.com/mattn/go-xmpp" + log "github.com/sirupsen/logrus" . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) @@ -22,16 +22,16 @@ type XMPP struct { handler Handler connectorLoopNum int - connected bool - timeout int + connected bool + timeout int - server string - port int - ssl bool - jid string + server string + port int + ssl bool + jid string jid_localpart string - password string - nickname string + password string + nickname string conn *gxmpp.Client @@ -42,7 +42,7 @@ func (xm *XMPP) SetHandler(h Handler) { xm.handler = h } -func(xm *XMPP) Protocol() string { +func (xm *XMPP) Protocol() string { return "xmpp" } @@ -97,7 +97,7 @@ func (xm *XMPP) Configure(c Configuration) error { go xm.connectLoop(xm.connectorLoopNum) for i := 0; i < 42; i++ { - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) if xm.connected { return nil } @@ -116,12 +116,12 @@ func (xm *XMPP) connectLoop(num int) { InsecureSkipVerify: true, } options := gxmpp.Options{ - Host: xm.server, - User: xm.jid, - Password: xm.password, - NoTLS: true, - StartTLS: xm.ssl, - Session: true, + Host: xm.server, + User: xm.jid, + Password: xm.password, + NoTLS: true, + StartTLS: xm.ssl, + Session: true, TLSConfig: tc, } var err error @@ -237,8 +237,8 @@ func (xm *XMPP) handleXMPP() error { user := UserID(remote[1] + "@" + remote[0]) event := &Event{ - Type: EVENT_JOIN, - Room: RoomID(remote[0]), + Type: EVENT_JOIN, + Room: RoomID(remote[0]), Author: user, } if v.Type == "unavailable" { @@ -264,8 +264,8 @@ func (xm *XMPP) SetUserInfo(info *UserInfo) error { func (xm *XMPP) SetRoomInfo(roomId RoomID, info *RoomInfo) error { if info.Topic != "" { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "groupchat", - Remote: string(roomId), + Type: "groupchat", + Remote: string(roomId), Subject: info.Topic, }) if err != nil { @@ -324,16 +324,16 @@ func (xm *XMPP) Send(event *Event) error { fmt.Printf("xm *XMPP Send %#v\n", event) if len(event.Recipient) > 0 { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "chat", + Type: "chat", Remote: string(event.Recipient), - Text: event.Text, + Text: event.Text, }) return err } else if len(event.Room) > 0 { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "groupchat", + Type: "groupchat", Remote: string(event.Room), - Text: event.Text, + Text: event.Text, }) return err } else { @@ -346,4 +346,3 @@ func (xm *XMPP) Close() { xm.conn = nil xm.connectorLoopNum += 1 } - |