40 end |
40 end |
41 if not method then |
41 if not method then |
42 log("debug", "Request %s suffered error %s", tostring(request.id), body); |
42 log("debug", "Request %s suffered error %s", tostring(request.id), body); |
43 return; |
43 return; |
44 end |
44 end |
45 log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body)); |
45 --log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body)); |
46 request.notopen = true; |
46 request.notopen = true; |
47 request.log = log; |
47 request.log = log; |
48 local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "|"); |
48 local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "|"); |
49 |
49 |
50 parser:parse(body); |
50 parser:parse(body); |
77 request.reply_before = os_time() + session.bosh_wait; |
77 request.reply_before = os_time() + session.bosh_wait; |
78 request.on_destroy = on_destroy_request; |
78 request.on_destroy = on_destroy_request; |
79 waiting_requests[request] = true; |
79 waiting_requests[request] = true; |
80 end |
80 end |
81 |
81 |
82 log("debug", "Had nothing to say, so leaving request unanswered for now"); |
82 log("debug", "Have nothing to say, so leaving request unanswered for now"); |
83 return true; |
83 return true; |
84 end |
84 end |
85 end |
85 end |
86 |
86 |
87 |
87 |
99 sessions[session.sid] = nil; |
99 sessions[session.sid] = nil; |
100 sm_destroy_session(session); |
100 sm_destroy_session(session); |
101 end |
101 end |
102 |
102 |
103 function stream_callbacks.streamopened(request, attr) |
103 function stream_callbacks.streamopened(request, attr) |
104 print("Attr:") |
|
105 for k,v in pairs(attr) do print("", k, v); end |
|
106 log("debug", "BOSH body open (sid: %s)", attr.sid); |
104 log("debug", "BOSH body open (sid: %s)", attr.sid); |
107 local sid = attr.sid |
105 local sid = attr.sid |
108 if not sid then |
106 if not sid then |
109 -- New session request |
107 -- New session request |
110 request.notopen = nil; -- Signals that we accept this opening tag |
108 request.notopen = nil; -- Signals that we accept this opening tag |
137 end |
135 end |
138 if oldest_request then |
136 if oldest_request then |
139 log("debug", "We have an open request, so using that to send with"); |
137 log("debug", "We have an open request, so using that to send with"); |
140 response.body = t_concat{"<body xmlns='http://jabber.org/protocol/httpbind' sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", tostring(s), "</body>" }; |
138 response.body = t_concat{"<body xmlns='http://jabber.org/protocol/httpbind' sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", tostring(s), "</body>" }; |
141 oldest_request:send(response); |
139 oldest_request:send(response); |
142 log("debug", "Sent"); |
140 --log("debug", "Sent"); |
143 if oldest_request.stayopen then |
141 if oldest_request.stayopen then |
144 if #r>1 then |
142 if #r>1 then |
145 -- Move front request to back |
143 -- Move front request to back |
146 t_insert(r, oldest_request); |
144 t_insert(r, oldest_request); |
147 t_remove(r, 1); |
145 t_remove(r, 1); |