I did some digging on this and here's the deal. The value you get back from ejabberd_sm:get_session_pid
is the ejabberd_c2s
process for that user's session. But ejabberd_c2s
is entirely unaware of BOSH. What you really need is the user's BOSH session ID which is maintained by the module ejabberd_http_bind
.
As best I can tell there's no "nice" way to get this information out of ejabberd_c2s
. I ended up doing something like this:
St = sys:get_status(Pid),
State = lists:nth(3, lists:nth(5, element(4, St))),
SocketState = element(2, State),
BindPid = element(2, element(3, SocketState)),
Now, all that gives you at the end of the day is a PID for the ejabberd_http_bind
process. You can repeat the whole sordid business again, but here I suggest cheating a little:
MS = ets:fun2ms(fun(#http_bind{pid=BP, id=Id}) when BP == BindPid -> Id end),
mnesia:dirty_select(http_bind, MS).
As you can see, this is horrendously ugly. The nicer way to do it would be to modify ejabberd_c2s
to accept a new type of sync_event
that would return the socket information, and likewise modify ejabberd_http_bind
to accept a similar sort of event to return the SID. And of course, both of these would be wrapped in public functions that internally make the relevant gen_fsm
calls.
All that said, I'm not sure what good the BOSH SID is really going to do you. And in particular, I'm not sure what the difference between "go offline" and "disconnect" is in this scenario. But anyway, that's how you get the information.