Software / code / verse
Comparison
plugins/proxy65.lua @ 395:e86144a4eaa1
plugins: Cleanup [luacheck]
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 03 Sep 2015 22:41:27 +0200 |
| parent | 392:cdea6a28369e |
| child | 457:73d4eb93657b |
comparison
equal
deleted
inserted
replaced
| 394:c2e959b60c13 | 395:e86144a4eaa1 |
|---|---|
| 1 local events = require "util.events"; | 1 local verse = require "verse"; |
| 2 local uuid = require "util.uuid"; | 2 local uuid = require "util.uuid"; |
| 3 local sha1 = require "util.hashes".sha1; | 3 local sha1 = require "util.hashes".sha1; |
| 4 | 4 |
| 5 local proxy65_mt = {}; | 5 local proxy65_mt = {}; |
| 6 proxy65_mt.__index = proxy65_mt; | 6 proxy65_mt.__index = proxy65_mt; |
| 107 local type, condition, text = reply:get_error(); | 107 local type, condition, text = reply:get_error(); |
| 108 conn:event("connection-failed", { conn = conn, type = type, condition = condition, text = text }); | 108 conn:event("connection-failed", { conn = conn, type = type, condition = condition, text = text }); |
| 109 else | 109 else |
| 110 -- Target connected to streamhost, connect ourselves | 110 -- Target connected to streamhost, connect ourselves |
| 111 local streamhost_used = reply.tags[1]:get_child("streamhost-used"); | 111 local streamhost_used = reply.tags[1]:get_child("streamhost-used"); |
| 112 if not streamhost_used then | 112 -- if not streamhost_used then |
| 113 --FIXME: Emit error | 113 --FIXME: Emit error |
| 114 end | 114 -- end |
| 115 conn.streamhost_jid = streamhost_used.attr.jid; | 115 conn.streamhost_jid = streamhost_used.attr.jid; |
| 116 local host, port; | 116 local host, port; |
| 117 for _, proxy in ipairs(proxies or self.proxies) do | 117 for _, proxy in ipairs(proxies or self.proxies) do |
| 118 if proxy.jid == conn.streamhost_jid then | 118 if proxy.jid == conn.streamhost_jid then |
| 119 host, port = proxy.host, proxy.port; | 119 host, port = proxy.host, proxy.port; |
| 120 break; | 120 break; |
| 121 end | 121 end |
| 122 end | 122 end |
| 123 if not (host and port) then | 123 -- if not (host and port) then |
| 124 --FIXME: Emit error | 124 --FIXME: Emit error |
| 125 end | 125 -- end |
| 126 | 126 |
| 127 conn:connect(host, port); | 127 conn:connect(host, port); |
| 128 | 128 |
| 129 local function handle_proxy_connected() | 129 local function handle_proxy_connected() |
| 130 conn:unhook("connected", handle_proxy_connected); | 130 conn:unhook("connected", handle_proxy_connected); |
| 131 -- Both of us connected, tell proxy to activate connection | 131 -- Both of us connected, tell proxy to activate connection |
| 132 local request = verse.iq{to = conn.streamhost_jid, type="set"} | 132 local activate_request = verse.iq{to = conn.streamhost_jid, type="set"} |
| 133 :tag("query", { xmlns = xmlns_bytestreams, sid = conn.bytestream_sid }) | 133 :tag("query", { xmlns = xmlns_bytestreams, sid = conn.bytestream_sid }) |
| 134 :tag("activate"):text(target_jid); | 134 :tag("activate"):text(target_jid); |
| 135 self.stream:send_iq(request, function (reply) | 135 self.stream:send_iq(activate_request, function (activated) |
| 136 if reply.attr.type == "result" then | 136 if activated.attr.type == "result" then |
| 137 -- Connection activated, ready to use | 137 -- Connection activated, ready to use |
| 138 conn:event("connected", conn); | 138 conn:event("connected", conn); |
| 139 else | 139 -- else --FIXME: Emit error |
| 140 --FIXME: Emit error | |
| 141 end | 140 end |
| 142 end); | 141 end); |
| 143 return true; | 142 return true; |
| 144 end | 143 end |
| 145 conn:hook("connected", handle_proxy_connected, 100); | 144 conn:hook("connected", handle_proxy_connected, 100); |