how to get users "os" in module mod_muc_room

Hi;

What I am trying to do is :

1. in mod_muc_room.erl there is -->

normal_state({route, From, ToNick, {xmlelement, "iq", Attrs, _Els} = Packet}, StateData) ->
    Lang = xml:get_attr_s("xml:lang", Attrs),
    StanzaId = xml:get_attr_s("id", Attrs),

and I'm trying to definition OS

so I do it like this -->

normal_state({route, From, ToNick, {xmlelement, "iq", Attrs, _Els} = Packet}, StateData) ->
    Lang = xml:get_attr_s("xml:lang", Attrs),
    StanzaId = xml:get_attr_s("id", Attrs),
    OS = xml:get_subtag_cdata(Packet, "os"),

but it isn't work, how can I do it ? tnx.

What does not work ? What are

What does not work ? What are you trying to achieve ?

mremond wrote: What does not

mremond wrote:

What does not work ? What are you trying to achieve ?

I'm trying to define OS in mod_muc_room to get user's OS before joining room and print it.

More specifically: Is your

More specifically: Is your code crashing ? Is your OS tag not found ? What is your original XMPP packet looking like exactly ?

mremond wrote: More

mremond wrote:

More specifically: Is your code crashing ? Is your OS tag not found ? What is your original XMPP packet looking like exactly ?

Hi;

yes, OS tag not found. because nothing shown on terminal when I join.
I think this : OS = xml:get_subtag_cdata(Packet, "os"), not the correct way to definition the OS

It would be easier to help if

It would be easier to help if you could show the XMPP packet you are trying to parse. Can you please do that ?

mremond wrote: It would be

mremond wrote:

It would be easier to help if you could show the XMPP packet you are trying to parse. Can you please do that ?

Hi;

The idea is like any bot (iSida, gluxi, sulci ... etc) if u type to him this : version mremond

it'll send u your version information like -->

name : Psi+
ver : 1.1
os : windows 8.1

Example --> I need this os : windows 8.1 to print it when mremond joining the room, I need to definition the OS

I don't know what do u mean the XMPP packet in this case can u explain me with some example please!

thank u

An XMPP Packet is the basis

An XMPP Packet is the basis of XMPP protocol. You should read more on xmpp.org.

Hi; Sorry for late. Xmpp

Hi;

Sorry for late.

Xmpp packet like this :

<query xmlns='http://jabber.org/protocol/disco#info'
         node='http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w='>
    <identity xml:lang='en' category='client' name='Psi 0.11' type='pc'/>
    <identity xml:lang='el' category='client' name='Ψ 0.11' type='pc'/>
    <feature var='http://jabber.org/protocol/caps'/>
    <feature var='http://jabber.org/protocol/disco#info'/>
    <feature var='http://jabber.org/protocol/disco#items'/>
    <feature var='http://jabber.org/protocol/muc'/>
    <x xmlns='jabber:x:data' type='result'>
      <field var='FORM_TYPE' type='hidden'>
        <value>urn:xmpp:dataforms:softwareinfo</value>
      </field>
      <field var='ip_version'>
        <value>ipv4</value>
        <value>ipv6</value>
      </field>
      <field var='os'>
        <value>Windows 8.1</value>
      </field>
      <field var='os_version'>
        <value>10.5.1</value>
      </field>
      <field var='software'>
        <value>Psi</value>
      </field>
      <field var='software_version'>
        <value>0.11</value>
      </field>
    </x>
</query>

What I'm looking for is get os like : Windows 8.1

<field var='os'>
   <value>Windows 8.1</value><

I'm using ejabberd 15.09. The

I'm using ejabberd 15.09. The code is similar for older versions, you can reuse it.

This patch:

--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -618,6 +618,11 @@ normal_state({route, From, ToNick,
             StateData) ->
     Lang = xml:get_attr_s(<<"xml:lang">>, Attrs),
     StanzaId = xml:get_attr_s(<<"id">>, Attrs),
+    Os = case catch get_os(Packet) of
+       {ok, Result} -> Result;
+       _ -> not_iq_version
+    end,
+    ?INFO_MSG("Os: ~p", [Os]),
     case {(StateData#state.config)#config.allow_query_users,
          is_user_online_iq(StanzaId, From, StateData)}
        of
@@ -4539,3 +4544,7 @@ has_body_or_subject(Packet) ->
        (_) -> true
     end, Packet#xmlel.children).
 
+get_os(Packet) ->
+    Q = xml:get_subtag(Packet, <<"query">>),
+    O = xml:get_subtag(Q, <<"os">>),
+    {ok, xml:get_tag_cdata(O)}.

And I get something like this in the log:

12:15:58.841 [info] ({socket_state,gen_tcp,#Port<0.8631>,<0.507.0>}) Accepted legacy authentication for user1@localhost/tka1 by ejabberd_auth_internal from 127.0.0.1
12:16:06.458 [info] Os: not_iq_version
12:16:06.461 [info] Os: not_iq_version
12:16:06.466 [info] Os: not_iq_version
12:16:06.466 [info] Os: not_iq_version
12:16:06.471 [info] Os: <<"Debian GNU/Linux 8.1 (jessie) 8.1 jessie 4.1.0-2-amd64">>
12:16:06.472 [info] Os: not_iq_version
12:16:06.475 [info] Os: not_iq_version
12:16:06.477 [info] Os: not_iq_version

Hi; Thank u I edited

Hi;

Thank u

I edited mod_muc_room like what u say

and add get_os function

%% get OS
get_os(Packet) ->
Q = xml:get_subtag(Packet, "query"),
O = xml:get_subtag(Q, "os"),
{ok, xml:get_tag_cdata(O)}.

trying :

    Os = case catch get_os(Packet) of
       {ok, Result} -> Result;
       _ -> not_iq_version
    end,
    ?INFO_MSG("OS is : ~p", [OS]),

also trying :

    Os = case catch get_os(Packet) of
       {ok, Result} -> Result;
       _ -> not_iq_version
    end,
    ?WARNING_MSG("OS is : ~p", [OS]),

so I run Ejabberd : ejabberdctl live. and when I'm joining to room no thing show to me in terminal.

I'm using Ejabberd 2.1.x

How can I do it? thnx.

How can I do it? thnx.

Syndicate content