aboutsummaryrefslogtreecommitdiff
path: root/src/mod_irc/iconv.erl
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2003-02-16 20:07:21 +0000
committerAlexey Shchepin <alexey@process-one.net>2003-02-16 20:07:21 +0000
commita28f7232431e9e92ccbd824f933a54556ee4d198 (patch)
tree36180b95a416b5bbee9496719a975dba88c6576e /src/mod_irc/iconv.erl
parent* src/ejabberd_service.erl: Answer "Bad Request" on unknown tags (diff)
* src/mod_irc/: New IRC transport (not completed yet)
SVN Revision: 74
Diffstat (limited to 'src/mod_irc/iconv.erl')
-rw-r--r--src/mod_irc/iconv.erl75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/mod_irc/iconv.erl b/src/mod_irc/iconv.erl
new file mode 100644
index 000000000..ea42f0e41
--- /dev/null
+++ b/src/mod_irc/iconv.erl
@@ -0,0 +1,75 @@
+%%%----------------------------------------------------------------------
+%%% File : iconv.erl
+%%% Author : Alexey Shchepin <alexey@sevcom.net>
+%%% Purpose : Interface to libiconv
+%%% Created : 16 Feb 2003 by Alexey Shchepin <alexey@sevcom.net>
+%%% Id : $Id$
+%%%----------------------------------------------------------------------
+
+-module(iconv).
+-author('alexey@sevcom.net').
+-vsn('$Revision$ ').
+
+-behaviour(gen_server).
+
+-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]).
+
+
+
+start() ->
+ gen_server:start({local, ?MODULE}, ?MODULE, [], []).
+
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+init([]) ->
+ ok = erl_ddll:load_driver(".", iconv_erl),
+ 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_cast(_, State) ->
+ {noreply, State}.
+
+handle_info({'EXIT', Pid, Reason}, Port) ->
+ {noreply, Port};
+
+handle_info({'EXIT', Port, Reason}, Port) ->
+ {stop, {port_died, Reason}, Port};
+handle_info(_, State) ->
+ {noreply, State}.
+
+code_change(OldVsn, State, Extra) ->
+ {ok, State}.
+
+terminate(_Reason, Port) ->
+ Port ! {self, close},
+ ok.
+
+
+
+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).
+
+
+