Using mod_pubsub via console

I Wrote a module where some pubsub command available in ejabberdctl. I uploaded some data with strophiejs and testing the get_items/2 pubsub function:

%...
#ejabberd_commands{name = discover_nodes, tags = [pubsub],
			desc = "Pubsub: discover_nodes",
			module = ?MODULE, function = discover_nodes,
			args = [{host, binary}, {node, string}],
			args_example = ["discover_nodes"],
			args_desc = ["discover_nodes"],
			result = {result, rescode},
			result_example = ok,
			result_desc = "discover_nodes"}
%...

discover_nodes(Host, Node) ->
	mod_pubsub:get_items(Host, Node).

%...

I found the new command in ejabberdctl but when im testing it, return a "item-not-found" error:

command call: ejabberdctl discover_nodes pubsub.myhost.hu Piskota

result:

Error: {stanza_error,cancel,404,<<>>,'item-not-found',
                     {text,<<"en">>,<<"Node not found">>},
                     []}

I'm sure i have uploaded datas, and found a function what can list them (here is the "Piskota"):

{pubsub_node,{<<"pubsub.myhost.hu">>,<<"Piskota">>},
             8,[],<<"flat">>,
             [{<<"admin">>,<<"myhost.hu">>,<<>>}],
             [{deliver_payloads,true},
              {notify_config,false},
              {notify_delete,false},
              {notify_retract,true},
              {purge_offline,false},
              {persist_items,true},
              {max_items,10},
              {subscribe,true},
              {access_model,open},
              {roster_groups_allowed,[]},
              {publish_model,publishers},
              {notification_type,headline},
              {max_payload_size,60000},
              {send_last_published_item,on_sub_and_presence},
              {deliver_notifications,true},
              {title,<<>>},
              {presence_based_delivery,false},
              {itemreply,none}]}

I tried a lots of parameter combination and variation, but always got this item-not-found.

I dont know it is help, but here is my pubsub config detail:

   mod_pubsub:
    access_createnode: all
    ignore_pep_from_offline: true
    last_item_cache: false
    plugins:
      - "flat"
      - "hometree"
      - "pep" # pep requires mod_caps

It can be a lots of help, if you can send me a native erlang call example for get_items/2 and create_node/5.

> a native erlang call

> a native erlang call example for get_items/2 and create_node/5.

You can know what arguments, and in what format they are expected, if you add some debug lines like this one, recompile, install, then trigger the code with a normal client, and see the log lines in the ejabberd log:

--- a/src/mod_pubsub.erl
+++ b/src/mod_pubsub.erl
@@ -2137,6 +2137,7 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIds, RSM) ->
     end.
 
 get_items(Host, Node) ->
+    ?INFO_MSG("get_items, Host: ~p, Node: ~p.", [Host, Node]),
     Action = fun (#pubsub_node{type = Type, id = Nidx}) ->
            node_call(Host, Type, get_items, [Nidx, service_jid(Host), undefined])
     end,

Yea i got this idea too, but

Yea i got this idea too, but after compile pubsub (either without changes) the ejabberd wont start and return with this error:

[critical] <0.38.0>@gen_mod:start_module:162 Problem starting the module mod_pubsub for host <<"myhost.hu">>
options: [{access_createnode,all},
           {ignore_pep_from_offline,true},
           {last_item_cache,false},
           {plugins,[<<"flat">>,<<"hometree">>,<<"pep">>]}]
error: undef
[{gen_mod,start_child,
          [mod_pubsub,<<"myhost.hu">>,
           [{access_createnode,all},
            {ignore_pep_from_offline,true},
            {last_item_cache,false},
            {plugins,[<<"flat">>,<<"hometree">>,<<"pep">>]}]],
          []},
{gen_mod,start_module,3,[{file,"src/gen_mod.erl"},{line,154}]},
{lists,foreach,2,[{file,"lists.erl"},{line,1337}]},
{ejabberd_app,start,2,[{file,"src/ejabberd_app.erl"},{line,77}]},
{application_master,start_it_old,4,
                     [{file,"application_master.erl"},{line,273}]}]
2017-03-29 07:05:33.466 [critical] <0.38.0>@gen_mod:maybe_halt_ejabberd:170 ejabberd initialization was aborted because a module start failed.

I found the same error in forums with other modules, but can't solve this problem. And this is not a priority problem for me.

Okay, so i just figured out

Okay, so i just figured out in get_items/2 case:
The args type in the ejabberd_commands declaration must be binary:

args = [{host, binary}, {node, binary}],

And a native call for get_items/2 looks like this:

mod_pubsub:get_items(<<"pubsub.mydomain">>, <<"NodeName">>)

If the node got string instead of binary, it wont run in error or warning, just simply will not found the node.

Syndicate content