[ejabberd] Warming BOSH bindings

Theo Cushion theo at jivatechnology.com
Wed Feb 3 20:11:00 MSK 2010


Hi

I've been trying to write my own BOSH binding warmer module. I've been  
drawing heavy inspiration from http://github.com/thepug/Mod-Http-Pre-Bind/ 
  and http://github.com/skeltoac/http_prebind/ .

Neither of these quite meet my needs:
	thepug's only deals with anonymous connections
	skeltoac requires a backdoor in the auth module

So I've been having a good poke around the ejabberd source code and  
identified several functions which will help me achieve creating an  
authenticated session without knowing the password and returning a SID  
and RID that can be used client side:

- mod_http_bind:handle_session_start
- mod_http_bind:start
- ejabberd_sm:open_session

Now I believe I have the BOSH session works fine - but my naive code  
doesn't seem to link it correctly to an authenticated session.

                     #jid{user = User, server = Server, resource =  
Resource} = jlib:string_to_jid(SJID),
                     Sid       = sha:sha(term_to_binary({now(),  
make_ref()})),
                     Rid       = list_to_integer(randoms:get_string()),
                     % Create PID to handle connection
                     {ok, Pid} =  
supervisor:start_child(ejabberd_http_bind_sup, [Sid, "", IP]),
                     % Create BOSH session # this is what  
handle_session_start does - but without sending a message back
                     mnesia:transaction(
                         fun() ->
                     	    mnesia:write(
                     	        #http_bind{id      = Sid,
                     	  	               pid     = Pid,
                     	  	               to      = {Server,"1.0"},
                     	  	               hold    = 1,
                     	  	               wait    = 3600,
                     	  	               version = 1.60}
                             )
                         end
                     ),
                     % Authenticate that session (skipping password  
mechanism)
                     Info        = [{ip,          IP},
                                    {conn,        http_bind},
                                    {auth_module, mod_http_bind_warm}],
                     ejabberd_sm:open_session({now(), self()}, User,  
Server, Resource, Info),

I'm certain I've made a gross assumption somewhere. Can someone shed  
any light on this? It seems all the other implementations try and do  
this by bouncing strings of XML around. Surely it must be possible by  
just tweaking the right functions?

Thanks

Theo


More information about the ejabberd mailing list