Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

erlang - I am unable to use `ejabberd_auth` in my **helloworld** project

I am unable to use ejabberd_auth in my helloworld project.

-behaviour(ejabberd_auth). 
... 
....  
try_register(<<"username">>, <<"example.com">>, <<"secret_password">>).  

With that I get the error warning:

helloworld.erl:15: Warning: behaviour ejabberd_auth undefined    


-import(ejabberd_auth, [try_register/3]).  
... 
....  
try_register(<<"username">>, <<"example.com">>, <<"secret_password">>).  

With this I get:

exception error: undefined function ejabberd_auth:try_register/3  

Why am I unable to access ejabberd_auth?

I am using IntelliJ Idea, with the Erlang plugin installed.

Thank you all in advance.

UPDATE:
I'm on Ubuntu 16.04 LTS

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I can get you past that error. Here's how...

When I compile a module in the erlang shell, the compiler creates a .beam file in the same directory, which allows me to call functions defined in the module. In your case, if you cd into the directory:

 .../ejabberd/ebin 

you will see all the ejabberd .beam files, including ejabberd_auth.beam. If you start an erlang shell in that directory, then issue your function call (don't compile anything), you won't get that error anymore.

But, then I get the error:

exception error: undefined function jid:nodeprep/1
     in function  ejabberd_auth:validate_credentials/3 (src/ejabberd_auth.erl, line 796)
     in call from ejabberd_auth:try_register/3 (src/ejabberd_auth.erl, line`

There is no jid.beam file in that directory. But:

~/Downloads/ejabberd$ find . -name jid.beam
./deps/xmpp/ebin/jid.beam

You are going to have to figure out how to compile your module so that all the ejabberd modules are available to your program. See: ejabberd how to compile new module.

I am unable to use ejabberd_auth in my helloworld project.

Are you following a tutorial somewhere?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...