Skip to content

Commit

Permalink
Merge pull request #87 from Mendor/master
Browse files Browse the repository at this point in the history
Fix for #85
  • Loading branch information
0xAX committed Dec 14, 2013
2 parents 4447ca6 + 2fceeab commit aa18f52
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion priv/webadmin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="https://github.com/0xAX/Ybot">Source Code</a></li>
<li><a href="http://https://github.com/0xAX/ybot-contrib">Plugins catalog</a></li>
<li><a href="https://github.com/0xAX/ybot-contrib">Plugins catalog</a></li>
</ul>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions priv/webadmin/js/ybot.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ function YbotController ($scope, $location, $http) {
$http({'method' : 'POST', 'url' : '/admin', 'data' : data}).success(function (data) {});
}

$scope.start_xmpp = function(jabber_nick, jabber_password, jabber_room, jabber_server, jabber_resource, jabber_port,
$scope.start_xmpp = function(jabber_login, jabber_password, jabber_room, jabber_nick, jabber_server, jabber_resource, jabber_port,
jabber_ssl, jabber_reconnect_timeout){
var data = {'method' : 'start_xmpp', params : {'xmpp_login' : jabber_nick, 'xmpp_password': jabber_password,
'xmpp_room':jabber_room, 'xmpp_server': jabber_server,
var data = {'method' : 'start_xmpp', params : {'xmpp_login' : jabber_login, 'xmpp_password': jabber_password,
'xmpp_room':jabber_room, 'xmpp_nick':jabber_nick, 'xmpp_server': jabber_server,
'xmpp_resource':jabber_resource, 'xmpp_port':jabber_port,
'xmpp_ssl':jabber_ssl, 'xmpp_reconnect_timeout':jabber_reconnect_timeout}};
$http({'method' : 'POST', 'url' : '/admin', 'data' : data}).success(function (data) {});
Expand Down
6 changes: 4 additions & 2 deletions priv/webadmin/views/activate_transport.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ <h3>Start new transport</h3>

<tab heading="XMPP">
<div id="tr2">
<label>Bot nick:</label>
<input type="text" ng-model="jabber_nick"/>
<label>Bot login:</label>
<input type="text" ng-model="jabber_login"/>
<label>Bot password:</label>
<input type="text" ng-model="jabber_password"/>
<label>Jabber room:</label>
<input type="text" ng-model="jabber_room"/>
<label>Nick in room:</label>
<input type="text" ng-model="jabber_nick"/>
<label>Jabber server:</label>
<input type="text" ng-model="jabber_server"/>
<label>Jabber resource:</label>
Expand Down
3 changes: 2 additions & 1 deletion src/transport/xmpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ For using Ybot with `jabber`, you must to configure it in configuration file ybo
[
% list of transport
{transports, [
% Xmpp Multi-user chat Login Password Room Host Resource
% Xmpp Multi-user chat Login Password Room Nick Host Resource
{xmpp, <<"[email protected]">>,
<<"password">>,
<<"[email protected]">>,
<<"YbotNick">>,
<<"jabber.org">>,
<<"home">>,
[{port, 5222}, {use_ssl, false}, {reconnect_timeout, 5000}]
Expand Down
11 changes: 7 additions & 4 deletions src/transport/xmpp/xmpp_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-include("xmpp.hrl").
-include_lib("xmerl/include/xmerl.hrl").

-export([start_link/9]).
-export([start_link/10]).

%% gen_server callbacks
-export([init/1,
Expand All @@ -37,6 +37,8 @@
host,
% Jabber room
room,
% Nick in jabber room
nick,
% Client resource
resource,
% Xmpp server port
Expand All @@ -53,14 +55,14 @@
%%% API
%%%=============================================================================

start_link(CallbackModule, Login, Password, Server, Port, Room, Resource, SocketMode, ReconnectTimeout) ->
gen_server:start_link(?MODULE, [CallbackModule, Login, Password, Server, Port, Room, Resource, SocketMode, ReconnectTimeout], []).
start_link(CallbackModule, Login, Password, Server, Port, Room, Nick, Resource, SocketMode, ReconnectTimeout) ->
gen_server:start_link(?MODULE, [CallbackModule, Login, Password, Server, Port, Room, Nick, Resource, SocketMode, ReconnectTimeout], []).

%%%=============================================================================
%%% xmpp_client callbacks
%%%=============================================================================

init([CallbackModule, Login, Password, Server, Port, Room, Resource, SocketMode, ReconnectTimeout ]) ->
init([CallbackModule, Login, Password, Server, Port, Room, Nick, Resource, SocketMode, ReconnectTimeout ]) ->
% try to connect
gen_server:cast(self(), {connect, Server, Port}),
% init process internal state
Expand All @@ -69,6 +71,7 @@ init([CallbackModule, Login, Password, Server, Port, Room, Resource, SocketMode,
password = Password,
host = Server,
room = Room,
nick = Nick,
resource = Resource,
port = Port,
socket_mod = SocketMode,
Expand Down
9 changes: 5 additions & 4 deletions src/transport/xmpp/xmpp_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-behaviour(supervisor).

%% API
-export([start_link/0, start_xmpp_client/9]).
-export([start_link/0, start_xmpp_client/10]).

%% Supervisor callbacks
-export([init/1]).
Expand All @@ -26,12 +26,13 @@ start_link() ->
Password :: binary(),
Server :: binary(),
Port :: integer(),
Room :: binary(),
Room :: binary(),
Nick :: binary(),
Resource :: binary(),
UseSsl :: boolean(),
ReconnectTimeout :: integer())
-> {ok, Pid :: pid()} | {error, Reason :: term()}.
start_xmpp_client(CallbackModule, Login, Password, Server, Port, Room, Resource, UseSsl, ReconnectTimeout ) ->
start_xmpp_client(CallbackModule, Login, Password, Server, Port, Room, Nick, Resource, UseSsl, ReconnectTimeout ) ->
% Match socket mode
SocketMode = case UseSsl of
true ->
Expand All @@ -41,7 +42,7 @@ start_xmpp_client(CallbackModule, Login, Password, Server, Port, Room, Resource,
end,
% Xmpp child
Child = {xmpp_client,
{xmpp_client, start_link, [CallbackModule, Login, Password, Server, Port, Room, Resource, SocketMode, ReconnectTimeout]},
{xmpp_client, start_link, [CallbackModule, Login, Password, Server, Port, Room, Nick, Resource, SocketMode, ReconnectTimeout]},
temporary, 2000, worker, []
},

Expand Down
2 changes: 1 addition & 1 deletion src/transport/xmpp/xmpp_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ message(Room, Message) ->

%% @doc Join to muc
-spec muc(Room :: string()) -> string().
muc(Room) ->
muc(Room) ->
% xml structure data
XmlData = [{'presence', [{'to', Room}],
[{'x', [{'xmlns', 'http://jabber.org/protocol/muc'}],
Expand Down
4 changes: 2 additions & 2 deletions src/web/web_admin_req_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ handle_request(Body, Req, State) ->
cowboy_req:reply(200, [], <<"ok">>, Req);
<<"start_xmpp">> ->
{[{<<"xmpp_login">>, Login}, {<<"xmpp_password">>, Password},
{<<"xmpp_room">>, Room}, {<<"xmpp_server">>, Host}, {<<"xmpp_resource">>, Resource},
{<<"xmpp_room">>, Room}, {<<"xmpp_nick">>, Nick}, {<<"xmpp_server">>, Host}, {<<"xmpp_resource">>, Resource},
{<<"xmpp_port">>, Port}, {<<"xmpp_ssl">>, Ssl}, {<<"xmpp_reconnect_timeout">>, RecTimeout}]} = Params,
Options = [{port, ybot_utils:to_int(Port)}, {use_ssl, Ssl}, {reconnect_timeout, ybot_utils:to_int(RecTimeout)}],
ybot_manager:run_transport({xmpp, Login, Password, Room, Host, Resource, Options}),
ybot_manager:run_transport({xmpp, Login, Password, Room, Nick, Host, Resource, Options}),
cowboy_req:reply(200, [], <<"ok">>, Req);
<<"start_campfire">> ->
{[{<<"login">>, Login}, {<<"token">>, Token},
Expand Down
12 changes: 6 additions & 6 deletions src/ybot_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ load_transport({irc, Nick, Channel, Host, Options}) ->
end;

%% @doc start xmpp client
load_transport({xmpp, Login, Password, Room, Host, Resource, Options}) ->
load_transport({xmpp, Login, Password, Room, Nick, Host, Resource, Options}) ->
% Start parser process
{ok, ParserPid} = ybot_parser:start_link(),
% Validate transport options
Expand All @@ -248,15 +248,15 @@ load_transport({xmpp, Login, Password, Room, Host, Resource, Options}) ->
% Start xmpp handler
{ok, HandlerPid} = xmpp_handler:start_link(),
% Make room
XmppRoom = list_to_binary(binary_to_list(Room) ++ "/" ++ binary_to_list(Login)),
XmppRoom = list_to_binary(binary_to_list(Room) ++ "/" ++ binary_to_list(Nick)),
% Log
lager:info("Starting XMPP transport: ~s, ~s, ~s", [Host, Room, Resource]),
lager:info("Starting XMPP transport: ~s, ~s, ~s", [Host, Room, Nick]),
% Start new xmpp transport
{ok, ClientPid} = xmpp_sup:start_xmpp_client(HandlerPid, Login, Password, Host, Port, XmppRoom, Resource, UseSsl, ReconnectTimeout),
{ok, ClientPid} = xmpp_sup:start_xmpp_client(HandlerPid, Login, Password, Host, Port, XmppRoom, Nick, Resource, UseSsl, ReconnectTimeout),
% Send client pid to handler
ok = gen_server:cast(HandlerPid, {xmpp_client, ClientPid, ParserPid, Login}),
ok = gen_server:cast(HandlerPid, {xmpp_client, ClientPid, ParserPid, Nick}),
% return correct transport
{xmpp, ClientPid, HandlerPid, Login, Password, Host, Room, Resource};
{xmpp, ClientPid, HandlerPid, Login, Password, Host, Room, Nick, Resource};
% wrong options
_ ->
[]
Expand Down
4 changes: 3 additions & 1 deletion ybot.config
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
% <<"ybot_password">>,
% % xmpp room
% <<"[email protected]">>,
% % nick in this room
% <<"MyYbot">>,
% % xmpp server
% <<"jabber.org">>,
% % xmpp resource
Expand All @@ -46,7 +48,7 @@
% % Use ssl or not
% {use_ssl, false},
% % reconnect timeout
% {reconnect_timeout, 5000},
% {reconnect_timeout, 5000}
% ]
%},

Expand Down

0 comments on commit aa18f52

Please sign in to comment.