使用会话 PID 和会话 PID 提取 SID联合ID

发布于 2024-12-03 17:27:23 字数 386 浏览 1 评论 0原文

我正在尝试找到一种使用 PID 和 JID 提取 bosh 会话(ejabberd)的 SID 的方法,以便我可以在 ejabberd_sm:unset_presence 中使用它,我到处搜索但找不到方法去做它。

基本上,我已经使用 Ejabberd 和 Strope 构建了一个聊天系统,我想要实现的是,当用户按下一页上的离线按钮时,与该 JID 关联的所有会话都需要离线,我已经使用 提取了 PID ejabberd_sm:get_session_pid 但找不到提取 SID 的方法。我也尝试过SID!断开连接 但这会完全断开用户的连接,这是我不想要的。

如果有人做过此类工作,请帮助我,也欢迎实现此类工作的其他想法。

谢谢

I am trying to find a way for extracting SID of a bosh session (ejabberd) using PID and JID so that I can use it in ejabberd_sm:unset_presence, I have searched everywhere but can't find a way to do it.

Basically, I have built a chat system using Ejabberd and Strophe and what I am trying to achieve is when user press offline button on one page all the sessions associated with that JID needs to go offline, I have extraced the PID by using ejabberd_sm:get_session_pid but can't find a way to extrct SID. I have also tried SID ! Disconnect but that disconnects the user completely which I don't want.

If anybody has done this kind of work please help me, other ideas for implementing such thing are also welcome.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花肆意 2024-12-10 17:27:23

我对此进行了一些挖掘,这就是交易。您从 ejabberd_sm:get_session_pid 返回的值是该用户会话的 ejabberd_c2s 进程。但ejabberd_c2s完全不知道BOSH。您真正需要的是用户的 BOSH 会话 ID,它由模块 ejabberd_http_bind 维护。

据我所知,没有“好的”方法可以从 ejabberd_c2s 中获取此信息。我最终做了这样的事情:

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)),

现在,最终给您的只是 ejabberd_http_bind 进程的 PID。你可以再次重复整个肮脏的事情,但在这里我建议做一点欺骗:

MS = ets:fun2ms(fun(#http_bind{pid=BP, id=Id}) when BP == BindPid  -> Id  end),
mnesia:dirty_select(http_bind, MS).

正如你所看到的,这是非常丑陋的。更好的方法是修改ejabberd_c2s以接受新类型的sync_event,它将返回套接字信息,并同样修改ejabberd_http_bind接受类似的事件以返回 SID。当然,这两个都将被包装在公共函数中,这些函数在内部进行相关的 gen_fsm 调用。

话虽如此,我不确定 BOSH SID 到底能给您带来什么好处。特别是,我不确定在这种情况下“离线”和“断开连接”之间有什么区别。但无论如何,这就是您获取信息的方式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文