aboutsummaryrefslogtreecommitdiff
path: root/src/mod_irc/iconv.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_irc/iconv.erl')
-rw-r--r--src/mod_irc/iconv.erl46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/mod_irc/iconv.erl b/src/mod_irc/iconv.erl
index b93bb2ea3..4d8180539 100644
--- a/src/mod_irc/iconv.erl
+++ b/src/mod_irc/iconv.erl
@@ -25,6 +25,7 @@
%%%----------------------------------------------------------------------
-module(iconv).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
@@ -32,63 +33,50 @@
-export([start/0, start_link/0, convert/3]).
%% Internal exports, call-back functions.
--export([init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- code_change/3,
- terminate/2]).
-
-
+-export([init/1, handle_call/3, handle_cast/2,
+ handle_info/2, code_change/3, terminate/2]).
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [],
+ []).
init([]) ->
- case erl_ddll:load_driver(ejabberd:get_so_path(), iconv_erl) of
- ok -> ok;
- {error, already_loaded} -> ok
+ case erl_ddll:load_driver(ejabberd:get_so_path(),
+ iconv_erl)
+ of
+ ok -> ok;
+ {error, already_loaded} -> ok
end,
Port = open_port({spawn, "iconv_erl"}, []),
ets:new(iconv_table, [set, public, named_table]),
ets:insert(iconv_table, {port, Port}),
{ok, Port}.
-
%%% --------------------------------------------------------
%%% The call-back functions.
%%% --------------------------------------------------------
-handle_call(_, _, State) ->
- {noreply, State}.
+handle_call(_, _, State) -> {noreply, State}.
-handle_cast(_, State) ->
- {noreply, State}.
+handle_cast(_, State) -> {noreply, State}.
handle_info({'EXIT', Port, Reason}, Port) ->
{stop, {port_died, Reason}, Port};
handle_info({'EXIT', _Pid, _Reason}, Port) ->
{noreply, Port};
-handle_info(_, State) ->
- {noreply, State}.
+handle_info(_, State) -> {noreply, State}.
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-terminate(_Reason, Port) ->
- Port ! {self, close},
- ok.
+code_change(_OldVsn, State, _Extra) -> {ok, State}.
+terminate(_Reason, Port) -> Port ! {self, close}, ok.
+-spec convert(binary(), binary(), binary()) -> binary().
convert(From, To, String) ->
[{port, Port} | _] = ets:lookup(iconv_table, port),
Bin = term_to_binary({From, To, String}),
BRes = port_control(Port, 1, Bin),
- binary_to_list(BRes).
-
-
-
+ (BRes).