diff options
Diffstat (limited to 'connector')
-rw-r--r-- | connector/config.go | 21 | ||||
-rw-r--r-- | connector/irc/config.go | 32 | ||||
-rw-r--r-- | connector/irc/irc.go | 24 | ||||
-rw-r--r-- | connector/mattermost/config.go | 52 | ||||
-rw-r--r-- | connector/mattermost/mattermost.go | 6 | ||||
-rw-r--r-- | connector/xmpp/config.go | 38 | ||||
-rw-r--r-- | connector/xmpp/xmpp.go | 13 |
7 files changed, 174 insertions, 12 deletions
diff --git a/connector/config.go b/connector/config.go index e0fcf17..97e4556 100644 --- a/connector/config.go +++ b/connector/config.go @@ -43,3 +43,24 @@ func (c Configuration) GetBool(k string, deflt ...bool) (bool, error) { } return false, fmt.Errorf("Missing configuration key: %s", k) } + +// ---- + +type ConfigSchema []*ConfigEntry + +type ConfigEntry struct { + Name string + Description string + Default string + FixedValue string + Required bool + IsPassword bool + IsNumeric bool + IsBoolean bool +} + +var Protocols = map[string]ConfigSchema{} + +func Register(name string, schema ConfigSchema) { + Protocols[name] = schema +} diff --git a/connector/irc/config.go b/connector/irc/config.go new file mode 100644 index 0000000..26d9a63 --- /dev/null +++ b/connector/irc/config.go @@ -0,0 +1,32 @@ +package irc + +import ( + . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" +) + +func init() { + Register("irc", ConfigSchema{ + &ConfigEntry{ + Name: "nick", + Description: "Nickname", + Required: true, + }, + &ConfigEntry{ + Name: "server", + Description: "Server", + Required: true, + }, + &ConfigEntry{ + Name: "port", + Description: "Port", + IsNumeric: true, + Default: "6667", + }, + &ConfigEntry{ + Name: "ssl", + Description: "Use SSL", + IsBoolean: true, + Default: "false", + }, + }) +} diff --git a/connector/irc/irc.go b/connector/irc/irc.go index 2ed3923..d69884e 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -127,6 +127,10 @@ func (irc *IRC) SetUserInfo(info *UserInfo) error { } func (irc *IRC) SetRoomInfo(roomId RoomID, info *RoomInfo) error { + if irc.conn == nil { + return fmt.Errorf("Not connected") + } + ch, err := irc.checkRoomId(roomId) if err != nil { return err @@ -145,6 +149,10 @@ func (irc *IRC) SetRoomInfo(roomId RoomID, info *RoomInfo) error { } func (irc *IRC) Join(roomId RoomID) error { + if irc.conn == nil { + return fmt.Errorf("Not connected") + } + ch, err := irc.checkRoomId(roomId) if err != nil { return err @@ -155,6 +163,10 @@ func (irc *IRC) Join(roomId RoomID) error { } func (irc *IRC) Invite(userId UserID, roomId RoomID) error { + if irc.conn == nil { + return fmt.Errorf("Not connected") + } + who, err := irc.checkUserId(userId) if err != nil { return err @@ -174,6 +186,10 @@ func (irc *IRC) Invite(userId UserID, roomId RoomID) error { } func (irc *IRC) Leave(roomId RoomID) { + if irc.conn == nil { + return + } + ch, err := irc.checkRoomId(roomId) if err != nil { return @@ -183,6 +199,10 @@ func (irc *IRC) Leave(roomId RoomID) { } func (irc *IRC) Send(event *Event) error { + if irc.conn == nil { + return fmt.Errorf("Not connected") + } + // Workaround girc bug if event.Text[0] == ':' { event.Text = " " + event.Text @@ -231,7 +251,9 @@ func (irc *IRC) Send(event *Event) error { func (irc *IRC) Close() { conn := irc.conn irc.conn = nil - conn.Close() + if conn != nil { + conn.Close() + } } func (irc *IRC) connectLoop(c *girc.Client) { diff --git a/connector/mattermost/config.go b/connector/mattermost/config.go new file mode 100644 index 0000000..b7c4ba8 --- /dev/null +++ b/connector/mattermost/config.go @@ -0,0 +1,52 @@ +package mattermost + +import ( + . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" +) + +func init() { + Register("mattermost", ConfigSchema{ + &ConfigEntry{ + Name: "server", + Description: "Server", + Required: true, + }, + &ConfigEntry{ + Name: "username", + Description: "Username", + Required: true, + }, + &ConfigEntry{ + Name: "password", + Description: "Password", + IsPassword: true, + }, + &ConfigEntry{ + Name: "token", + Description: "Authentification token (replaces password if set)", + }, + &ConfigEntry{ + Name: "teams", + Description: "Comma-separated list of teams to follow", + Required: true, + }, + &ConfigEntry{ + Name: "no_tls", + Description: "Disable SSL/TLS", + IsBoolean: true, + Default: "false", + }, + &ConfigEntry{ + Name: "initial_backlog", + Description: "Maximum number of messages to load when joining a channel", + IsNumeric: true, + Default: "1000", + }, + &ConfigEntry{ + Name: "initial_members", + Description: "Maximum number of members to load when joining a channel", + IsNumeric: true, + Default: "100", + }, + }) +} diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index 0b863fb..e3a6429 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -69,7 +69,7 @@ func (mm *Mattermost) Configure(c Configuration) error { return err } - mm.initial_members, err = c.GetInt("initial_members", 1000) + mm.initial_members, err = c.GetInt("initial_members", 100) if err != nil { return err } @@ -312,7 +312,9 @@ func (mm *Mattermost) Send(event *Event) error { } func (mm *Mattermost) Close() { - mm.conn.WsQuit = true + if mm.conn != nil { + mm.conn.WsQuit = true + } if mm.handlerStopChan != nil { mm.handlerStopChan <- true mm.handlerStopChan = nil diff --git a/connector/xmpp/config.go b/connector/xmpp/config.go new file mode 100644 index 0000000..6fd5f9b --- /dev/null +++ b/connector/xmpp/config.go @@ -0,0 +1,38 @@ +package xmpp + +import ( + . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" +) + +func init() { + Register("xmpp", ConfigSchema{ + &ConfigEntry{ + Name: "jid", + Description: "JID", + Required: true, + }, + &ConfigEntry{ + Name: "password", + Description: "Password", + Required: true, + IsPassword: true, + }, + &ConfigEntry{ + Name: "nickname", + Description: "Nickname in MUCs", + Required: true, + }, + &ConfigEntry{ + Name: "port", + Description: "Port", + IsNumeric: true, + Default: "6667", + }, + &ConfigEntry{ + Name: "ssl", + Description: "Use SSL", + IsBoolean: true, + Default: "true", + }, + }) +} diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index 698016f..f1a75b2 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -55,11 +55,6 @@ func (xm *XMPP) Configure(c Configuration) error { // Parse and validate configuration var err error - xm.server, err = c.GetString("server") - if err != nil { - return err - } - xm.port, err = c.GetInt("port", 5222) if err != nil { return err @@ -78,9 +73,7 @@ func (xm *XMPP) Configure(c Configuration) error { if len(jid_parts) != 2 { return fmt.Errorf("Invalid JID: %s", xm.jid) } - if jid_parts[1] != xm.server { - return fmt.Errorf("JID %s not on server %s", xm.jid, xm.server) - } + xm.server = jid_parts[1] xm.jid_localpart = jid_parts[0] xm.nickname, _ = c.GetString("nickname", xm.jid_localpart) @@ -353,7 +346,9 @@ func (xm *XMPP) Send(event *Event) error { } func (xm *XMPP) Close() { - xm.conn.Close() + if xm.conn != nil { + xm.conn.Close() + } xm.conn = nil xm.connectorLoopNum += 1 } |