Question: host_config / <domain> / modules /... how to get parameters ?

Hi Forum,
I'm a developer and I have just approached ejabberd and erlang as well. I'm stuck in a stupid thing for a couple of weeks so I have decided to ask you some help
Erlang is tough for me (imperative programming only, I'm sorry) but ejabberd is even more tough so please excuse me for this kind of newbie question.
I'm building an HTTP REST module for my internal multidomain server but I'd like to get some parameters from configuration file, these params are different from domain to domain so here's what I did in my ejabberd.yml file:

host_config:
  "mydomain":
    modules:
      mod_restapi:
        param1:
          - "value1"
          - "value2"

Here's what I'd like to do:
- Get "param1" list from configuration file (ejabberd.yml) at module startup and keep it "somewhere in memory" or retrieve it when needed without reading this from filesystem each time I need it
- My module implements gen_mod and gen_server behaviour and I'm using process/2 to handle HTTP requests, from there I'd like to use my "param1" list.
Is there a snippet of code or something I can read/understand/use to achieve this ?

I'd like to divide the problem in two parts: read my param1 from configuration file, use this param1 in various functions (ie: access/2) when needed.
From my pool Erlang knownledge I know there isn't "something in memory" or something shared so I'd like to at least read it from file and then I'll study how to share it in my functions.

I'm a seasoned programmer but please let me apologize again for my basic skills with erlang and ejabberd

Thanks in advance for your kind reply

Ben

Friend, You need to create a

Friend, You need to create a module and add that module in ejabberd config file. In that module you have to specify your command to get list of "param1" like others ejabberd command. e.g. get list of all registered users. "sudo ejabberdctl registered_users user localhost"

I suggest you to view "mod_admin_extra.erl" and go through this link for better understanding of modules http://learnyousomeerlang.com/introduction

Thanks vipulpachauri, I'm now

Thanks vipulpachauri,
I'm now using gen_mod:get_module_opt and similar functions from gen_mod to get all from them.

I also would like to know another thing:
what if I have a module with options declared globally (not related to a specific host) ?
here's an example:

modules:
  mymodule:
    property: "value"

This is not related to a single host but the module is declared globally.
How can I get "property" without specifying the host name ?

gen_mod:get_module_opt() needs to have an host to work

Thanks again,
Ben

Self replied. RTFM and source

Self replied.
RTFM and source code !

gen_mod:get_module_opt(global, mymodule, property, fun(A)->A end).

atom 'global' is my friend :)

Ben

I have a supervisor

I have a supervisor class
'-module(frequency_sup).

-behavior(gen_mod).
-behaviour(supervisor).

-export([start_link/0, init/1]).

-export([stop/0]).

-define(EJABBERD_DEBUG, true).

-export([
start/2,
stop/1,
process/2
]) .

-include("ejabberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl").

start(_Host, _Opts) -> ok.
stop(_Host) -> ok.

process(_Path, _Request) ->
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"}],
[{xmlelement, "head", [],
[{xmlelement, "title", [], []}]},
{xmlelement, "body", [],
[{xmlelement, "p", [], [{xmldata, start_link()}]}]}]},
"frequency has started".

start_link() ->

Pid=supervisor:start_link({local,?MODULE},?MODULE, []).

stop() -> exit(whereis(?MODULE), shutdown).

init(_) ->

ChildSpecList = [ child(myMainModule)],

{ok,{{rest_for_one, 2, 3600}, ChildSpecList}}.

child(Module) ->

{Module, {Module, start, []},

temporary, 2000, worker, [Module]}.

I am using process/2 function with parameters "path and "request" respectively,and I have configured my ejabberd.yml file in module section as modules: frequency_sup: {}` and

port: 5280
module: ejabberd_http
request_handlers:
"frequency": frequency_sup
"/websocket": ejabberd_http_ws
## "/pub/archive": mod_http_fileserver
web_admin: true
http_bind: true
## register: true
captcha: false
now when i call this function with this url localhost:5280/frequency_sup it generates the pid and I can monitor this in ejabberdctl live. but in my next step i need to login in another module which takes three parameters like login([EmailId],[Password],pid) and this is where I am having trouble with two things 1.that how to use the Pid that i generated via first url call of frequency_sup in the second function call of login and 2.as you can see I need to pass emailid and password to call login function,how to do that as each time a new user logs in he will pass different parameters and if i will write it into the ejabberd.yml file like login:
{EmailId: "bob"
Password: "123"}

then it will only work for custom cases. I have a feeling that it can be solved by the help of the _request parameter of the process module but i haven't found any good blogs explaining that can anybody help me with this. thank you in advance

I changed my login.erl file

I changed my login.erl file and compiled my login.erl to get login.beam file.Now when I start my ejabberd I am getting a crash dump as : options: [{key1,<<"bob">>},{key2,<<"123">>}] error: {badmatch,<<"bob">>} [{login,start,2,[{file,"login.erl"},{line,36}]}, and line 36 of login.erl is [EmailId]=proplists:get_value(key1, _Opts), I need my login values to go as login(["bob"],["123"],Pid) but instead I think it is going in as login(["<>"],["<<123>>"],Pid) Am I understanding it correctly or not and what should I do make it work in either case. Thank you in advance.

Syndicate content