Commit 5852a01d authored by Tails developers's avatar Tails developers
Browse files

Add support for using a Connect Server.

parent ba7ee08b
......@@ -52,7 +52,9 @@ class OtrBot(jabberbot.JabberBot):
PING_FREQUENCY = 60
def __init__(self, username, password, otr_key_path):
def __init__(self, username, password, otr_key_path, connect_server = None):
self.__connect_server = connect_server
self.__password = password
super(OtrBot, self).__init__(username, password)
self.__account = self.jid.getNode()
self.__protocol = "xmpp"
......@@ -64,6 +66,34 @@ class OtrBot(jabberbot.JabberBot):
}
self.__otr_callback_store = OtrCallbackStore()
# Unfortunately Jabberbot's connect() is not very friendly to
# overriding in subclasses so we have to re-implement it
# completely (copy-paste mostly) in order to add support for using
# an XMPP "Connect Server".
def connect(self):
if not self.conn:
conn = xmpp.Client(self.jid.getDomain(), debug=[])
if self.__connect_server:
try:
conn_server, conn_port = self.__connect_server.split(":", 1)
except ValueError:
conn_server = self.__connect_server
conn_port = 5222
conres = conn.connect((conn_server, int(conn_port)))
else:
conres = conn.connect()
if not conres:
return None
authres = conn.auth(self.jid.getNode(), self.__password, self.res)
if not authres:
return None
self.conn = conn
self.conn.sendInitPresence()
self.roster = self.conn.Roster.getRoster()
for (handler, callback) in self.handlers:
self.conn.RegisterHandler(handler, callback)
return self.conn
def __otr_callbacks(self, more_data = None):
opdata = self.__opdata.copy()
if more_data:
......@@ -155,10 +185,17 @@ if __name__ == '__main__':
help = "the user account's password")
parser.add_argument("otr_key_path",
help = "the path to the account's OTR key file")
parser.add_argument("-c", "--connect-server", metavar = 'ADDRESS',
help = "use a Connect Server, given as host[:port] " +
"(port defaults to 5222)")
parser.add_argument("-j", "--auto-join", nargs = '+', metavar = 'ROOMS',
help = "auto-join multi-user chatrooms on start")
args = parser.parse_args()
otr_bot = OtrBot(args.account, args.password, args.otr_key_path)
otr_bot_opt_args = dict()
if args.connect_server:
otr_bot_opt_args["connect_server"] = args.connect_server
otr_bot = OtrBot(args.account, args.password, args.otr_key_path,
**otr_bot_opt_args)
if args.auto_join:
for room in args.auto_join:
otr_bot.join_room(room)
......
......@@ -48,14 +48,14 @@ end
Given /^my XMPP friend goes online( and joins the multi-user chat)?$/ do |join_chat|
next if @skip_steps_while_restoring_background
rooms = nil
account = xmpp_account("Friend_account", ["otr_key"])
bot_opts = account.select { |k, v| ["connect_server"].include?(k) }
if join_chat
rooms = [@chat_room_jid]
bot_opts["auto_join"] = [@chat_room_jid]
end
account = xmpp_account("Friend_account", ["otr_key"])
@friend_name = account["username"]
@chatbot = ChatBot.new(account["username"] + "@" + account["domain"],
account["password"], account["otr_key"], rooms)
account["password"], account["otr_key"], bot_opts)
@chatbot.start
add_after_scenario_hook(@chatbot.method(:stop))
@vm.focus_window('Buddy List')
......
......@@ -2,11 +2,11 @@ require 'tempfile'
class ChatBot
def initialize(account, password, otr_key, rooms = nil)
def initialize(account, password, otr_key, opts = Hash.new)
@account = account
@password = password
@otr_key = otr_key
@rooms = rooms
@opts = opts
@pid = nil
@otr_key_file = nil
end
......@@ -22,7 +22,8 @@ class ChatBot
@password,
@otr_key_file.path
]
cmd += ["--auto-join"] + @rooms if @rooms
cmd += ["--connect-server", @opts["connect_server"]] if @opts["connect_server"]
cmd += ["--auto-join"] + @opts["auto_join"] if @opts["auto_join"]
job = IO.popen(cmd)
@pid = job.pid
......
......@@ -147,7 +147,7 @@ be subscribed to each other but to no other XMPP account. Also, for the
`Friend_account`, it's important that the `otr_key`'s `name` field is
the same as `username`, and that the `protocol` field is `xmpp`.
If a "Connect Server" is needed for the `Tails_account`, it can be set
If a "Connect Server" is needed for any of the accounts, it can be set
in the *optional* `connect_server` field.
In case the `Tails_account`'s conference server doesn't allow creating
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment