Accessing StateData with User/Server/Resource
Posted: 27 July 2007 04:57 PM   [ Ignore ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

I am looking for an easy way to access a users StateData by using their JID/Server/Resource information.

Is their an easy way of accessing this data? Ive poked around in ejabberd_sm.erl but haven’t found an easy way of accessing it.

Can anyone point me in the right direction or give me pointers?

Profile
 
 
Posted: 28 July 2007 10:28 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

Hello dS_Jeffrey,

Basically, data contained in states are records. You can extract records in Erlang with a syntax of the type:

JID = StateData#state.jid

This is just an example and depend on the field you want to extrat in the record.

Note that JIDs are often records too. The module jlib.erl provide functions for JID record manipulations.

Did we answer your question ?

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
Posted: 28 July 2007 05:01 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

Actually no, i know how to access records. I should have been clearer.

I am creating a module that does not process_iq’s, which means that its initiated through some other means. Unfortunately with this being the case i only have access to the users Username, Server, JID, and SessionID.

I am trying to simulate a disconnect similar to the one found when a user signs in twice with the same Resource ID (the first user gets kicked and get replaced by the newer connection).

Now what i am trying to accomplish is to be able to access some of the StateData which is needed by some of the other function calls, such as presence_broadcast which requires the users active privacy_list.

Lastly i need access to the users ejabberd_receiver process so that i may disconnect the user. Unfortunately i am having issues trying to find how to access this data directly.

Thanks again.

Profile
 
 
Posted: 28 July 2007 05:06 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

Hello,

I am not totally sure that I understand what you want to achieve.
I think what you need is to register some hooks. Am I right ?

In this case the parameter you need are send to your module as a parameter by the hook.

Maybe you do not have all the hooks or all the parameter you need. In this case, let’s discuss what are missing to achieve what you are trying to do.

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
Posted: 28 July 2007 05:44 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

Simply I want to be able to kick someone by some external means. And the only thing provided will be the username and server.

Profile
 
 
Posted: 28 July 2007 05:55 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

What I would do is a match on the session table and I would then route packets to this user and then send an exit, kill signal to the process id managing the user connection.

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
Posted: 28 July 2007 07:09 PM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

Does it make sense to you ?

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
Posted: 28 July 2007 07:56 PM   [ Ignore ]   [ # 7 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

What would I route to the user? A stream:error? and then force a disconnect by killing the PID?

Would this gracefully disconnect the user by sending unavailable status to those with presence (while respecting mod_privacy)?

Profile
 
 
Posted: 30 July 2007 04:00 PM   [ Ignore ]   [ # 8 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

I have been able to determine the pid for the users session, and I was manually able to determine the ejabberd_receiver process (the connection process) using i() in the erlang console, and followed by using ejabberd_receiver:close(PID). This seems to work, but I am having trouble trying to find the user session’s parent PID using erlang.

Thanks again.

Profile
 
 
Posted: 30 July 2007 04:21 PM   [ Ignore ]   [ # 9 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

ejabberd_auth:remove_user(User, Server), seems to do the trick.

Thanks again.

Profile
 
 
Posted: 30 July 2007 04:29 PM   [ Ignore ]   [ # 10 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

Be carefull: ejabberd_auth:remove_user/2 will delete user, roster, etc from the database.

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
Posted: 30 July 2007 04:36 PM   [ Ignore ]   [ # 11 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

Thanks for the heads up, i looked into the function and found what i needed.

ejabberd_hooks:run(remove_user, LServer, [User, Server]).

EDIT: still might not be right.

Profile
 
 
Posted: 30 July 2007 08:13 PM   [ Ignore ]   [ # 12 ]
Newbie
Rank
Total Posts:  10
Joined  2007-07-24

I was able to resolve it by routing a “broadcast” packet and handling it in ejabberd_c2s.erl

Thanks You for your help Mickaël.

Profile
 
 
Posted: 31 July 2007 11:12 AM   [ Ignore ]   [ # 13 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  151
Joined  2006-11-12

I am glad this discussion solved your problem.
Depending on what your code is doing, you might consider sharing it with other people.

If you are interested we could open an area in ejabberd-modules Subversion repository.

 Signature 

Mickaël Rémond
ProcessOne

Profile
 
 
   
 
 
‹‹ check on timer      webdav support ››