1 local sha1 = require "util.sha1".sha1; |
1 local sha1 = require "util.sha1".sha1; |
2 local st = require "util.stanza"; |
|
3 local timer = require "util.timer"; |
2 local timer = require "util.timer"; |
4 local uuid_generate = require "util.uuid".generate; |
3 local uuid_generate = require "util.uuid".generate; |
5 |
4 |
6 local xmlns_jingle = "urn:xmpp:jingle:1"; |
5 local xmlns_jingle = "urn:xmpp:jingle:1"; |
7 local xmlns_jingle_errors = "urn:xmpp:jingle:errors:1"; |
6 local xmlns_jingle_errors = "urn:xmpp:jingle:errors:1"; |
50 return true; |
49 return true; |
51 end |
50 end |
52 -- No existing Jingle object handled this action, our turn... |
51 -- No existing Jingle object handled this action, our turn... |
53 if action ~= "session-initiate" then |
52 if action ~= "session-initiate" then |
54 -- Trying to send a command to a session we don't know |
53 -- Trying to send a command to a session we don't know |
55 local reply = st.error_reply(stanza, "cancel", "item-not-found") |
54 local reply = verse.error_reply(stanza, "cancel", "item-not-found") |
56 :tag("unknown-session", { xmlns = xmlns_jingle_errors }):up(); |
55 :tag("unknown-session", { xmlns = xmlns_jingle_errors }):up(); |
57 stream:send(reply); |
56 stream:send(reply); |
58 return; |
57 return; |
59 end |
58 end |
60 |
59 |
95 end |
94 end |
96 end |
95 end |
97 end |
96 end |
98 if not content then |
97 if not content then |
99 -- FIXME: Fail, no content |
98 -- FIXME: Fail, no content |
100 stream:send(st.error_reply(stanza, "cancel", "feature-not-implemented", "The specified content is not supported")); |
99 stream:send(verse.error_reply(stanza, "cancel", "feature-not-implemented", "The specified content is not supported")); |
101 return; |
100 return; |
102 end |
101 end |
103 |
102 |
104 if not transport then |
103 if not transport then |
105 -- FIXME: Refuse session, no transport |
104 -- FIXME: Refuse session, no transport |
106 stream:send(st.error_reply(stanza, "cancel", "feature-not-implemented", "The specified transport is not supported")); |
105 stream:send(verse.error_reply(stanza, "cancel", "feature-not-implemented", "The specified transport is not supported")); |
107 return; |
106 return; |
108 end |
107 end |
109 |
108 |
110 stream:send(st.reply(stanza)); |
109 stream:send(verse.reply(stanza)); |
111 |
110 |
112 jingle.content_tag = content_tag; |
111 jingle.content_tag = content_tag; |
113 jingle.creator, jingle.name = content_tag.attr.creator, content_tag.attr.name; |
112 jingle.creator, jingle.name = content_tag.attr.creator, content_tag.attr.name; |
114 jingle.content, jingle.transport = content, transport; |
113 jingle.content, jingle.transport = content, transport; |
115 |
114 |
150 end |
149 end |
151 return true; |
150 return true; |
152 end |
151 end |
153 |
152 |
154 function jingle_mt:send_command(command, element, callback) |
153 function jingle_mt:send_command(command, element, callback) |
155 local stanza = st.iq({ to = self.peer, type = "set" }) |
154 local stanza = verse.iq({ to = self.peer, type = "set" }) |
156 :tag("jingle", { |
155 :tag("jingle", { |
157 xmlns = xmlns_jingle, |
156 xmlns = xmlns_jingle, |
158 sid = self.sid, |
157 sid = self.sid, |
159 action = command, |
158 action = command, |
160 initiator = self.role == "initiator" and self.stream.jid or nil, |
159 initiator = self.role == "initiator" and self.stream.jid or nil, |
166 self.stream:send_iq(stanza, callback); |
165 self.stream:send_iq(stanza, callback); |
167 end |
166 end |
168 end |
167 end |
169 |
168 |
170 function jingle_mt:accept(options) |
169 function jingle_mt:accept(options) |
171 local accept_stanza = st.iq({ to = self.peer, type = "set" }) |
170 local accept_stanza = verse.iq({ to = self.peer, type = "set" }) |
172 :tag("jingle", { |
171 :tag("jingle", { |
173 xmlns = xmlns_jingle, |
172 xmlns = xmlns_jingle, |
174 sid = self.sid, |
173 sid = self.sid, |
175 action = "session-accept", |
174 action = "session-accept", |
176 responder = stream.jid, |
175 responder = stream.jid, |
202 stream:hook("iq/"..xmlns_jingle, handle_incoming_jingle); |
201 stream:hook("iq/"..xmlns_jingle, handle_incoming_jingle); |
203 return true; |
202 return true; |
204 end |
203 end |
205 |
204 |
206 function jingle_mt:offer(name, content) |
205 function jingle_mt:offer(name, content) |
207 local session_initiate = st.iq({ to = self.peer, type = "set" }) |
206 local session_initiate = verse.iq({ to = self.peer, type = "set" }) |
208 :tag("jingle", { xmlns = xmlns_jingle, action = "session-initiate", |
207 :tag("jingle", { xmlns = xmlns_jingle, action = "session-initiate", |
209 initiator = self.stream.jid, sid = self.sid }); |
208 initiator = self.stream.jid, sid = self.sid }); |
210 |
209 |
211 -- Content tag |
210 -- Content tag |
212 session_initiate:tag("content", { creator = self.role, name = name }); |
211 session_initiate:tag("content", { creator = self.role, name = name }); |