diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2013-04-08 11:12:54 +0200 |
---|---|---|
committer | Christophe Romain <christophe.romain@process-one.net> | 2013-06-13 11:11:02 +0200 |
commit | 4d8f7706240a1603468968f47fc7b150b788d62f (patch) | |
tree | 92d55d789cc7ac979b3c9e161ffb7f908eba043a /src/mod_irc | |
parent | Fix Guide: ejabberd_service expects a shaper_rule, not a shaper (diff) |
Switch to rebar build tool
Use dynamic Rebar configuration
Make iconv dependency optional
Disable transient_supervisors compile option
Add hipe compilation support
Only compile ibrowse and lhttpc when needed
Make it possible to generate an OTP application release
Add --enable-debug compile option
Add --enable-all compiler option
Add --enable-tools configure option
Add --with-erlang configure option.
Add --enable-erlang-version-check configure option.
Add lager support
Improve the test suite
Diffstat (limited to '')
-rw-r--r-- | src/mod_irc.erl (renamed from src/mod_irc/mod_irc.erl) | 3 | ||||
-rw-r--r-- | src/mod_irc/Makefile.in | 60 | ||||
-rw-r--r-- | src/mod_irc/Makefile.win32 | 42 | ||||
-rw-r--r-- | src/mod_irc/iconv.erl | 82 | ||||
-rw-r--r-- | src/mod_irc/iconv_erl.c | 177 | ||||
-rw-r--r-- | src/mod_irc_connection.erl (renamed from src/mod_irc/mod_irc_connection.erl) | 1 |
6 files changed, 3 insertions, 362 deletions
diff --git a/src/mod_irc/mod_irc.erl b/src/mod_irc.erl index 53069671..9d9246fa 100644 --- a/src/mod_irc/mod_irc.erl +++ b/src/mod_irc.erl @@ -41,6 +41,7 @@ handle_info/2, terminate/2, code_change/3]). -include("ejabberd.hrl"). +-include("logger.hrl"). -include("jlib.hrl"). @@ -111,7 +112,7 @@ stop(Host) -> %% Description: Initiates the server %%-------------------------------------------------------------------- init([Host, Opts]) -> - iconv:start(), + ejabberd:start_app(p1_iconv), MyHost = gen_mod:get_opt_host(Host, Opts, <<"irc.@HOST@">>), case gen_mod:db_type(Opts) of diff --git a/src/mod_irc/Makefile.in b/src/mod_irc/Makefile.in deleted file mode 100644 index 9dcf9f18..00000000 --- a/src/mod_irc/Makefile.in +++ /dev/null @@ -1,60 +0,0 @@ -# $Id$ - -CC = @CC@ -CFLAGS = @CFLAGS@ -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ @LIBICONV@ - -ERLANG_CFLAGS = @ERLANG_CFLAGS@ -ERLANG_LIBS = @ERLANG_LIBS@ - -# Assume Linux-style dynamic library flags -DYNAMIC_LIB_CFLAGS = -fpic -shared -ifeq ($(shell uname),Darwin) - DYNAMIC_LIB_CFLAGS = -fPIC -bundle -flat_namespace -undefined suppress -endif -ifeq ($(shell uname),SunOs) - DYNAMIC_LIB_CFLAGS = -KPIC -G -z text -endif - - -EFLAGS += -I .. -EFLAGS += -pz .. - -# make debug=true to compile Erlang module with debug informations. -ifdef debug - EFLAGS+=+debug_info -endif - -ERLSHLIBS = ../iconv_erl.so -OUTDIR = .. -SOURCES = $(wildcard *.erl) -BEAMS = $(addprefix $(OUTDIR)/,$(SOURCES:.erl=.beam)) - -all: $(BEAMS) $(ERLSHLIBS) - -$(OUTDIR)/%.beam: %.erl - @ERLC@ -W $(EFLAGS) -o $(OUTDIR) $< - -#all: $(ERLSHLIBS) -# erl -s make all report "{outdir, \"..\"}" -noinput -s erlang halt - -$(ERLSHLIBS): ../%.so: %.c - $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) \ - $(subst ../,,$(subst .so,.c,$@)) \ - $(LIBS) \ - $(ERLANG_CFLAGS) \ - $(ERLANG_LIBS) \ - -o $@ \ - $(DYNAMIC_LIB_CFLAGS) - -clean: - rm -f $(BEAMS) $(ERLSHLIBS) - -distclean: clean - rm -f Makefile - -TAGS: - etags *.erl - diff --git a/src/mod_irc/Makefile.win32 b/src/mod_irc/Makefile.win32 deleted file mode 100644 index fb067110..00000000 --- a/src/mod_irc/Makefile.win32 +++ /dev/null @@ -1,42 +0,0 @@ - -include ..\Makefile.inc - -EFLAGS = -I .. -pz .. - -OUTDIR = .. -BEAMS = ..\iconv.beam ..\mod_irc.beam ..\mod_irc_connection.beam - -SOURCE = iconv_erl.c -OBJECT = iconv_erl.o -DLL = $(OUTDIR)\iconv_erl.dll - -ALL : $(DLL) $(BEAMS) - -CLEAN : - -@erase $(DLL) - -@erase $(OUTDIR)\iconv_erl.exp - -@erase $(OUTDIR)\iconv_erl.lib - -@erase $(OBJECT) - -@erase $(BEAMS) - -$(OUTDIR)\iconv.beam : iconv.erl - erlc -W $(EFLAGS) -o $(OUTDIR) iconv.erl - -$(OUTDIR)\mod_irc.beam : mod_irc.erl - erlc -W $(EFLAGS) -o $(OUTDIR) mod_irc.erl - -$(OUTDIR)\mod_irc_connection.beam : mod_irc_connection.erl - erlc -W $(EFLAGS) -o $(OUTDIR) mod_irc_connection.erl - -CC=cl.exe -CC_FLAGS=-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -MD -Ox -I"$(ERLANG_DIR)\usr\include" -I"$(EI_DIR)\include" -I"$(ICONV_DIR)\include" - -LD=link.exe -LD_FLAGS=-release -nologo -incremental:no -dll "$(EI_DIR)\lib\ei_md.lib" "$(EI_DIR)\lib\erl_interface_md.lib" "$(ICONV_LIB)" MSVCRT.LIB kernel32.lib advapi32.lib gdi32.lib user32.lib comctl32.lib comdlg32.lib shell32.lib - -$(DLL) : $(OBJECT) - $(LD) $(LD_FLAGS) -out:$@ $< - -$(OBJECT) : $(SOURCE) - $(CC) $(CC_FLAGS) -c -Fo$@ $< - diff --git a/src/mod_irc/iconv.erl b/src/mod_irc/iconv.erl deleted file mode 100644 index 4d818053..00000000 --- a/src/mod_irc/iconv.erl +++ /dev/null @@ -1,82 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : iconv.erl -%%% Author : Alexey Shchepin <alexey@process-one.net> -%%% Purpose : Interface to libiconv -%%% Created : 16 Feb 2003 by Alexey Shchepin <alexey@process-one.net> -%%% -%%% -%%% ejabberd, Copyright (C) 2002-2013 ProcessOne -%%% -%%% This program is free software; you can redistribute it and/or -%%% modify it under the terms of the GNU General Public License as -%%% published by the Free Software Foundation; either version 2 of the -%%% License, or (at your option) any later version. -%%% -%%% This program is distributed in the hope that it will be useful, -%%% but WITHOUT ANY WARRANTY; without even the implied warranty of -%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -%%% General Public License for more details. -%%% -%%% You should have received a copy of the GNU General Public License -%%% along with this program; if not, write to the Free Software -%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -%%% 02111-1307 USA -%%% -%%%---------------------------------------------------------------------- - --module(iconv). - --author('alexey@process-one.net'). - --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([]) -> - 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_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}. - -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), - (BRes). diff --git a/src/mod_irc/iconv_erl.c b/src/mod_irc/iconv_erl.c deleted file mode 100644 index 20d9389a..00000000 --- a/src/mod_irc/iconv_erl.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * ejabberd, Copyright (C) 2002-2013 ProcessOne - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - * - */ - -#include <stdio.h> -#include <string.h> -#include <erl_driver.h> -#include <ei.h> -#include <iconv.h> - -/* - * R15B changed several driver callbacks to use ErlDrvSizeT and - * ErlDrvSSizeT typedefs instead of int. - * This provides missing typedefs on older OTP versions. - */ -#if ERL_DRV_EXTENDED_MAJOR_VERSION < 2 -typedef int ErlDrvSizeT; -typedef int ErlDrvSSizeT; -#endif - -typedef struct { - ErlDrvPort port; - iconv_t cd; -} iconv_data; - - -static ErlDrvData iconv_erl_start(ErlDrvPort port, char *buff) -{ - iconv_data* d = (iconv_data*)driver_alloc(sizeof(iconv_data)); - d->port = port; - d->cd = NULL; - - set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY); - - return (ErlDrvData)d; -} - -static void iconv_erl_stop(ErlDrvData handle) -{ - driver_free((char*)handle); -} - -static ErlDrvSSizeT iconv_erl_control(ErlDrvData drv_data, - unsigned int command, - char *buf, ErlDrvSizeT len, - char **rbuf, ErlDrvSizeT rlen) -{ - int i; - int size; - int index = 0; - int avail; - size_t inleft, outleft; - ErlDrvBinary *b; - char *from, *to, *string, *stmp, *rstring, *rtmp; - iconv_t cd; - int invalid_utf8_as_latin1 = 0; - - ei_decode_version(buf, &index, &i); - ei_decode_tuple_header(buf, &index, &i); - ei_get_type(buf, &index, &i, &size); - from = driver_alloc(size + 1); - ei_decode_string(buf, &index, from); - - ei_get_type(buf, &index, &i, &size); - to = driver_alloc(size + 1); - ei_decode_string(buf, &index, to); - - ei_get_type(buf, &index, &i, &size); - stmp = string = driver_alloc(size + 1); - ei_decode_string(buf, &index, string); - - /* Special mode: parse as UTF-8 if possible; otherwise assume it's - Latin-1. Makes no difference when encoding. */ - if (strcmp(from, "utf-8+latin-1") == 0) { - from[5] = '\0'; - invalid_utf8_as_latin1 = 1; - } - if (strcmp(to, "utf-8+latin-1") == 0) { - to[5] = '\0'; - } - cd = iconv_open(to, from); - - if (cd == (iconv_t) -1) { - cd = iconv_open("ascii", "ascii"); - if (cd == (iconv_t) -1) { - *rbuf = (char*)(b = driver_alloc_binary(size)); - memcpy(b->orig_bytes, string, size); - - driver_free(from); - driver_free(to); - driver_free(string); - - return size; - } - } - - outleft = avail = 4*size; - inleft = size; - rtmp = rstring = driver_alloc(avail); - while (inleft > 0) { - if (iconv(cd, &stmp, &inleft, &rtmp, &outleft) == (size_t) -1) { - if (invalid_utf8_as_latin1 && (*stmp & 0x80) && outleft >= 2) { - /* Encode one byte of (assumed) Latin-1 into two bytes of UTF-8 */ - *rtmp++ = 0xc0 | ((*stmp & 0xc0) >> 6); - *rtmp++ = 0x80 | (*stmp & 0x3f); - outleft -= 2; - } - stmp++; - inleft--; - } - } - - size = rtmp - rstring; - - *rbuf = (char*)(b = driver_alloc_binary(size)); - memcpy(b->orig_bytes, rstring, size); - - driver_free(from); - driver_free(to); - driver_free(string); - driver_free(rstring); - iconv_close(cd); - - return size; -} - - - -ErlDrvEntry iconv_driver_entry = { - NULL, /* F_PTR init, N/A */ - iconv_erl_start, /* L_PTR start, called when port is opened */ - iconv_erl_stop, /* F_PTR stop, called when port is closed */ - NULL, /* F_PTR output, called when erlang has sent */ - NULL, /* F_PTR ready_input, called when input descriptor ready */ - NULL, /* F_PTR ready_output, called when output descriptor ready */ - "iconv_erl", /* char *driver_name, the argument to open_port */ - NULL, /* F_PTR finish, called when unloaded */ - NULL, /* handle */ - iconv_erl_control, /* F_PTR control, port_command callback */ - NULL, /* F_PTR timeout, reserved */ - NULL, /* F_PTR outputv, reserved */ - /* Added in Erlang/OTP R15B: */ - NULL, /* ready_async */ - NULL, /* flush */ - NULL, /* call */ - NULL, /* event */ - ERL_DRV_EXTENDED_MARKER, /* extended_marker */ - ERL_DRV_EXTENDED_MAJOR_VERSION, /* major_version */ - ERL_DRV_EXTENDED_MINOR_VERSION, /* minor_version */ - 0, /* driver_flags */ - NULL, /* handle2 */ - NULL, /* process_exit */ - NULL /* stop_select */ -}; - -DRIVER_INIT(iconv_erl) /* must match name in driver_entry */ -{ - return &iconv_driver_entry; -} - - diff --git a/src/mod_irc/mod_irc_connection.erl b/src/mod_irc_connection.erl index ba0cb434..c37ca7cb 100644 --- a/src/mod_irc/mod_irc_connection.erl +++ b/src/mod_irc_connection.erl @@ -41,6 +41,7 @@ code_change/4]). -include("ejabberd.hrl"). +-include("logger.hrl"). -include("jlib.hrl"). |