Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't export mod_opt_type/1 #15

Open
matt-tlc opened this issue Jun 12, 2015 · 5 comments
Open

doesn't export mod_opt_type/1 #15

matt-tlc opened this issue Jun 12, 2015 · 5 comments

Comments

@matt-tlc
Copy link

Hi,

I am trying to use the module and have come across an issue, would you
please be able to advice.

I followed your guide and ran the ./build.sh and I kept getting redefining
MACRO PRINT in logger.hrl
To get around it I moved the module and files into the ejabberd source and
built it from there and that built the beam file ok, although I am getting
Warning: variable 'Info' is unused"

I have put the beam file into the actual lib of the ejabberd and it starts
and can see in the logs it is trying to start but I am getting these
warnings which I think may be stopping it as its not logging anything
currently.

Here is the error in the ejabberd.log
[warning] <0.38.0>@gen_mod:validate_opts:256 module 'mod_log_chat_mysql5'
doesn't export mod_opt_type/1"

This comes after the above error:

[debug] <0.308.0> Supervisor ejabberd_sup started mod_log_chat_mysql5:start_link(<<"HOST">>, [{server,<<"localhost">>},{db,<<"DB_NAME">>},{user,<<"DB_USER">>},{password,<<"DB_PASS">>},{pool_size,...},...]) at pid <0.493.0>

I am running ejabberd 15.04.91.

Many Thanks
Matt

@mweibel
Copy link
Member

mweibel commented Jun 15, 2015

The mentioned log outputs seem to be only warnings, I'd say the module works regardless. Can you confirm?

Removing those warnings would need some adaptions to the latest ejabberd code.. will see what I can do about it

@matt-tlc
Copy link
Author

They are warnings but as the module is not working at all i wondered if they were affecting it working..

With regards to the Info var not used, to get around this error when building the beam file I had to underscore it.

Currently there is nothing in the database at all.

@matt-tlc
Copy link
Author

Not sure if im causing more damage than anything here, but I un-commented the following:

%%-define(ejabberd_debug, true).

I then removed the % from the INFO & DEBUG MSG, in hope these would highlight some issues.

This was the result I got in the ejabberd.log file:

[error] <0.493.0> CRASH REPORT Process <0.493.0> with 0 neighbours exited with reason: call to undefined function p1_logger:info_msg(mod_log_chat_mysql5, 64, "Starting ~p", [mod_log_chat_mysql5]) in gen_server:init_it/6 line 328

After reading through the logs I have just noticed this:

2015-06-15 09:45:52.522 [error] <0.493.0> gen_server 'mod_log_chat_mysql5_<DOMAIN>' terminated with reason: pool_not_found
2015-06-15 09:45:52.522 [error] <0.493.0> CRASH REPORT Process 'mod_log_chat_mysql5_<DOMAIN>' with 0 neighbours exited with reason: pool_not_found in gen_server:terminate/6 line 722
2015-06-15 09:45:52.522 [error] <0.38.0>@gen_mod:stop_module_keep_config:137 {pool_not_found,{gen_server,call,['mod_log_chat_mysql5_<DOMAIN>',stop]}}

@matt-tlc
Copy link
Author

Just to add I have started my VM afresh to try again.

I am now running the ./build.sh from inside the downloaded ejabberd-modules/mod_chat_log_mysql/ as per the installation in your README.
This is the error I get after running it.

../ejabberd-dev/trunk/include/logger.hrl:20: redefining macro 'PRINT'
../ejabberd-dev/trunk/include/logger.hrl:42: redefining macro 'DEBUG'
../ejabberd-dev/trunk/include/logger.hrl:45: redefining macro 'INFO_MSG'
../ejabberd-dev/trunk/include/logger.hrl:48: redefining macro 'WARNING_MSG'
../ejabberd-dev/trunk/include/logger.hrl:51: redefining macro 'ERROR_MSG'
../ejabberd-dev/trunk/include/logger.hrl:54: redefining macro 'CRITICAL_MSG'
src/mod_log_chat_mysql5.erl:129: Warning: variable 'Info' is unused

@matt-tlc
Copy link
Author

Managed to solve the issue;

I included Emysql and p1_logger into the deps of the ejabberd download, then ran the ./rebar get-deps, along with make.
I then downloaded the candy-chat/mod_log_chat_mysql5.erl and put this in the ejabberd/src file, I had to make some alterations as the xmelement has changed to xmlel and I have to put the following in

log_packet(From, To, Packet = {xmlel, <<"message">>, Attrs, _Els}) ->
    case xml:get_attr_s(<<"type">>, Attrs) of
        "error" -> %% we don't log errors
            %?INFO_MSG("dropping error: ~s", [xml:element_to_string(Packet)]),
            ok;
        _ ->
            case xml:get_subtag(Packet, <<"body">>) of
                false ->
                    ok;
                _ ->
                    % Check that we are sending to an online user, if not don't save
                    ResourceLen = length(ejabberd_sm:get_user_resources(To#jid.luser,To#jid.lserver)),
                        if
                            ResourceLen > 0 ->
                                    ?INFO_MSG("Saving Msg, From: ~s, To: ~s", [From#jid.luser, To#jid.luser]),
                        ?DEBUG("Writing Packet: ~s", [xml:get_tag_cdata(xml:get_subtag(Packet, <<"body">>))]),
                                            write_packet(From, To, Packet, xml:get_attr_s(<<"type">>, Attrs));
                            true ->
                                    ok
                        end
                end 
    end;
log_packet(_From, _To, _Packet) ->
    ok.
%% parse message and send to db connection gen_server
write_packet(From, To, Packet, Type) ->
    Body = xml:get_tag_cdata(xml:get_subtag(Packet, <<"body">>)),
    case Body of
        "" -> %% don't log empty messages
            ?INFO_MSG("not logging empty message from ~s",[jlib:jid_to_string(From)]),
            ok;
        _ ->
            FromJid = list_to_binary([From#jid.luser,"@",From#jid.lserver]),
            ToJid = list_to_binary([To#jid.luser,"@",To#jid.lserver]),
            Proc = gen_mod:get_module_proc(From#jid.server, ?PROCNAME),
            gen_server:cast(Proc, {insert_row, FromJid, ToJid, Body, Type})
    end.

I removed the escape function as I couldn't get this to work and I couldn't see that it was necessary as no matter what I tried in a message it saved and there was never any issues with escape characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants