From 4103f30812ed99c984a2fdb16aabca139c9255d7 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Sun, 22 Aug 2004 21:54:14 +0000 Subject: [PATCH] * src/mod_offline.erl: Added entire table locking on large message queue * src/ejabberd_sm.erl: Added offline_subscription_hook * src/mod_offline.erl: Use offline_subscription_hook * src/configure.erl: Updated (thanks to Sergei Golovan) * src/Makefile.win32: Likewise * src/tls/Makefile.win32: Likewise * src/win32/: Likewise * src/mod_announce.erl: Added announce to all users (thanks to Sergei Golovan) * doc/guide.tex: Updated (thanks to Sergei Golovan) SVN Revision: 259 --- ChangeLog | 17 ++++++ doc/guide.html | 23 +++++++- doc/guide.tex | 20 +++++++ src/Makefile.win32 | 19 +++---- src/configure.erl | 2 + src/ejabberd_sm.erl | 5 +- src/mod_announce.erl | 22 ++++++++ src/mod_offline.erl | 10 ++++ src/win32/CheckReqs.ini | 15 ++++- src/win32/CheckReqs1.ini | 28 +++++++++ src/win32/CheckReqs1H.ini | 29 ++++++++++ src/win32/CheckUserH.ini | 2 +- src/win32/ejabberd.cfg | 26 ++++++++- src/win32/ejabberd.nsi | 116 ++++++++++++++++++++++++++++++++++++-- 14 files changed, 309 insertions(+), 25 deletions(-) create mode 100644 src/win32/CheckReqs1.ini create mode 100644 src/win32/CheckReqs1H.ini diff --git a/ChangeLog b/ChangeLog index 12688b70f..8adc98569 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-08-23 Alexey Shchepin + + * src/mod_offline.erl: Added entire table locking on large message + queue + + * src/ejabberd_sm.erl: Added offline_subscription_hook + * src/mod_offline.erl: Use offline_subscription_hook + + * src/configure.erl: Updated (thanks to Sergei Golovan) + * src/Makefile.win32: Likewise + * src/tls/Makefile.win32: Likewise + * src/win32/: Likewise + + * src/mod_announce.erl: Added announce to all users (thanks to + Sergei Golovan) + * doc/guide.tex: Updated (thanks to Sergei Golovan) + 2004-08-14 Alexey Shchepin * src/msgs/nl.msg: Updated (thanks to Sander Devrieze) diff --git a/doc/guide.html b/doc/guide.html index 1d0927ac8..9090e5b9b 100644 --- a/doc/guide.html +++ b/doc/guide.html @@ -824,8 +824,27 @@ Example:

A.2  mod_announce

-This module adds support for broadcast announce messages and MOTD.
-
+This module adds support for broadcast announce messages and MOTD. +When the module is loaded, it handles messages sent to the following JID's +(suppose that main server has address example.org): +
+example.org/announce/all
Message is sent to all registered users. +If the user is online and connected to several resources, only resource with +the highest priority will receive the message. If the registered user is +not connected, the message will be stored offline (if oflline storage is +available). +
example.org/announce/online
Message is sent to all connected users. +If the user is online and connected to several resources, all resources +will receive the message. +
example.org/announce/motd
Message is set as MOTD (Message of the Day) +and will be sent to users as they login. In addition the message is sent to +all connected users (similar to announce/online resource). +
example.org/announce/motd/update
Message is set as MOTD (Message of the Day) +and will be sent to users as they login. The message is not sent to +all connected users. +
example.org/announce/motd/delete
Any message sent to this JID +removes existing MOTD. +
Options:
access
Specifies who is allowed to send announce messages diff --git a/doc/guide.tex b/doc/guide.tex index 5e12c70db..573fdfd6d 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -817,6 +817,26 @@ Example: \label{sec:modannounce} This module adds support for broadcast announce messages and MOTD. +When the module is loaded, it handles messages sent to the following JID's +(suppose that main server has address \jid{example.org}): +\begin{description} +\titem{example.org/announce/all} Message is sent to all registered users. +If the user is online and connected to several resources, only resource with +the highest priority will receive the message. If the registered user is +not connected, the message will be stored offline (if oflline storage is +available). +\titem{example.org/announce/online} Message is sent to all connected users. +If the user is online and connected to several resources, all resources +will receive the message. +\titem{example.org/announce/motd} Message is set as MOTD (Message of the Day) +and will be sent to users as they login. In addition the message is sent to +all connected users (similar to \term{announce/online} resource). +\titem{example.org/announce/motd/update} Message is set as MOTD (Message of the Day) +and will be sent to users as they login. The message is \emph{not sent} to +all connected users. +\titem{example.org/announce/motd/delete} Any message sent to this JID +removes existing MOTD. +\end{description} Options: \begin{description} diff --git a/src/Makefile.win32 b/src/Makefile.win32 index 57fd239be..692641c5a 100644 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -45,8 +45,6 @@ release : build release_clean copy $(SYSTEMROOT)\system32\libeay32.dll $(EREL) copy $(SYSTEMROOT)\system32\ssleay32.dll $(EREL) copy win32\ejabberd.ico $(WIN32_DIR) - mkdir $(WIN32_DIR)\5.3 - copy win32\5.3\*.beam $(WIN32_DIR)\5.3 mkdir $(SRC_DIR) copy *.app $(SRC_DIR) copy *.erl $(SRC_DIR) @@ -66,11 +64,10 @@ release : build release_clean copy stringprep\*.erl $(SRC_DIR)\stringprep copy stringprep\*.c $(SRC_DIR)\stringprep copy stringprep\*.tcl $(SRC_DIR)\stringprep + mkdir $(SRC_DIR)\tls + copy tls\*.erl $(SRC_DIR)\tls mkdir $(SRC_DIR)\web copy web\*.erl $(SRC_DIR)\web - mkdir $(SRC_DIR)\win32 - mkdir $(SRC_DIR)\win32\5.3 - copy win32\5.3\*.erl $(SRC_DIR)\win32\5.3 mkdir $(DOC_DIR) copy ..\doc\*.html $(DOC_DIR) copy ..\doc\*.png $(DOC_DIR) @@ -92,11 +89,11 @@ all-recursive : nmake -nologo -f Makefile.win32 cd ..\stringprep nmake -nologo -f Makefile.win32 + cd ..\tls + nmake -nologo -f Makefile.win32 cd ..\web nmake -nologo -f Makefile.win32 - cd ..\win32\5.3 - nmake -nologo -f Makefile.win32 - cd ..\.. + cd .. compile-beam : erl -s make all report -noinput -s erlang halt @@ -121,11 +118,11 @@ clean-recursive : nmake -nologo -f Makefile.win32 clean cd ..\stringprep nmake -nologo -f Makefile.win32 clean + cd ..\tls + nmake -nologo -f Makefile.win32 clean cd ..\web nmake -nologo -f Makefile.win32 clean - cd ..\win32\5.3 - nmake -nologo -f Makefile.win32 clean - cd ..\.. + cd .. distclean : release_clean clean -@erase $(NSIS_HEADER) diff --git a/src/configure.erl b/src/configure.erl index e7736a76e..069f19165 100644 --- a/src/configure.erl +++ b/src/configure.erl @@ -40,6 +40,7 @@ start() -> RootDirS = "ERLANG_DIR = " ++ code:root_dir() ++ "\n", Version = "EJABBERD_VERSION = " ++ ?VERSION ++ "\n", ExpatDir = "EXPAT_DIR = c:\\progra~1\\expat-1.95.7\n", + OpenSSLDir = "OPENSSL_DIR = c:\\progra~1\\OpenSSL\n", SSLDir = "SSLDIR = " ++ code:lib_dir("ssl") ++ "\n", StdLibDir = "STDLIBDIR = " ++ code:lib_dir("stdlib") ++ "\n", @@ -50,6 +51,7 @@ start() -> Version ++ SSLDir ++ StdLibDir ++ + OpenSSLDir ++ ExpatDir ++ ExpatLib ++ ExpatFlag ++ diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index d4a972518..90bec9b67 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -200,8 +200,9 @@ do_route(From, To, Packet) -> Subsc -> case ejabberd_auth:is_user_exists(LUser) of true -> - catch mod_offline:store_packet( - From, To, Packet); + ejabberd_hooks:run( + offline_subscription_hook, + [From, To, Packet]); _ -> Err = jlib:make_error_reply( Packet, ?ERR_SERVICE_UNAVAILABLE), diff --git a/src/mod_announce.erl b/src/mod_announce.erl index 29ac65e87..b8164aab0 100644 --- a/src/mod_announce.erl +++ b/src/mod_announce.erl @@ -41,6 +41,9 @@ init() -> loop() -> receive + {announce_all, From, To, Packet} -> + announce_all(From, To, Packet), + loop(); {announce_online, From, To, Packet} -> announce_online(From, To, Packet), loop(); @@ -70,6 +73,9 @@ announce(From, To, Packet) -> #jid{luser = "", lresource = Res} -> {xmlelement, Name, _Attrs, _Els} = Packet, case {Res, Name} of + {"announce/all", "message"} -> + ?PROCNAME ! {announce_all, From, To, Packet}, + stop; {"announce/online", "message"} -> ?PROCNAME ! {announce_online, From, To, Packet}, stop; @@ -89,6 +95,22 @@ announce(From, To, Packet) -> ok end. +announce_all(From, To, Packet) -> + Access = gen_mod:get_module_opt(?MODULE, access, none), + case acl:match_rule(Access, From) of + deny -> + Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED), + ejabberd_router:route(To, From, Err); + allow -> + Server = ?MYNAME, + Local = jlib:make_jid("", Server, ""), + lists:foreach( + fun(U) -> + Dest = jlib:make_jid(U, Server, ""), + ejabberd_router:route(Local, Dest, Packet) + end, ejabberd_auth:dirty_get_registered_users()) + end. + announce_online(From, To, Packet) -> Access = gen_mod:get_module_opt(?MODULE, access, none), case acl:match_rule(Access, From) of diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 22e9b85ee..e96b8f371 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -25,6 +25,7 @@ -record(offline_msg, {user, timestamp, from, to, packet}). -define(PROCNAME, ejabberd_offline). +-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000). start(_) -> mnesia:create_table(offline_msg, @@ -33,6 +34,8 @@ start(_) -> {attributes, record_info(fields, offline_msg)}]), ejabberd_hooks:add(offline_message_hook, ?MODULE, store_packet, 50), + ejabberd_hooks:add(offline_subscription_hook, + ?MODULE, store_packet, 50), ejabberd_hooks:add(resend_offline_messages_hook, ?MODULE, pop_offline_messages, 50), register(?PROCNAME, spawn(?MODULE, init, [])). @@ -44,7 +47,14 @@ loop() -> receive #offline_msg{} = Msg -> Msgs = receive_all([Msg]), + Len = length(Msgs), F = fun() -> + if + Len >= ?OFFLINE_TABLE_LOCK_THRESHOLD -> + mnesia:write_lock_table(offline_msg); + true -> + ok + end, lists:foreach(fun(M) -> mnesia:write(M) end, Msgs) diff --git a/src/win32/CheckReqs.ini b/src/win32/CheckReqs.ini index 0b573c826..74b193de7 100644 --- a/src/win32/CheckReqs.ini +++ b/src/win32/CheckReqs.ini @@ -1,11 +1,20 @@ [Settings] -NumFields=1 +NumFields=2 [Field 1] Type=label Left=0 Right=-1 Top=10 -Bottom=-10 -Text="Erlang OTP R9C (version 5.3) is required to install Ejabberd.\r\n\r\nIt is not found on your computer.\r\n\r\nPlease install Erlang OTP R9C before installing Ejabberd.\r\n\r\nIt can be downloaded from http://www.erlang.org/download/otp_win32_R9C-0.exe." +Bottom=70 +Text="Erlang OTP R9C-1 (version 5.3.6.2) or newer is required to install Ejabberd.\r\n\r\nIt is not found on your computer.\r\n\r\nPlease install Erlang OTP R9C-1 or newer before installing Ejabberd.\r\n\r\nIt can be downloaded from" + +[Field 2] +Type=link +Left=0 +Right=-1 +Top=74 +Bottom=88 +State=http://www.erlang.org/download.html +Text=http://www.erlang.org/download.html diff --git a/src/win32/CheckReqs1.ini b/src/win32/CheckReqs1.ini new file mode 100644 index 000000000..d475ede35 --- /dev/null +++ b/src/win32/CheckReqs1.ini @@ -0,0 +1,28 @@ +[Settings] +NumFields=3 + +[Field 1] +Type=label +Left=0 +Right=-1 +Top=10 +Bottom=70 +Text="OpenSLL 0.9.7c or newer is not found on your computer.\r\n\r\nEjabberd includes required SSL libraries but if you don't have SSL certificate then without installed OpenSSL you will not be able to create your own SSL certificate and use SSL-enabled connections.\r\n\r\nOpenSLL can be downloaded from" + +[Field 2] +Type=link +Left=0 +Right=-1 +Top=74 +Bottom=88 +State=http://www.slproweb.com/products/Win32OpenSSL.html +Text=http://www.slproweb.com/products/Win32OpenSSL.html + +[Field 3] +Type=label +Left=0 +Right=-1 +Top=93 +Bottom=-10 +Text="If you want to continue installation anyway, click Next." + diff --git a/src/win32/CheckReqs1H.ini b/src/win32/CheckReqs1H.ini new file mode 100644 index 000000000..15c4ecf7f --- /dev/null +++ b/src/win32/CheckReqs1H.ini @@ -0,0 +1,29 @@ +[Settings] +NumFields=3 + +[Field 1] +Type=label +Left=0 +Right=-1 +Top=10 +Bottom=70 +Text="OpenSLL 0.9.7c or newer is not found on your computer.\r\n\r\nEjabberd includes required SSL libraries but if you don't have SSL certificate then without installed OpenSSL you will not be able to create your own SSL certificate and use SSL-enabled connections.\r\n\r\nOpenSLL can be downloaded from" + +[Field 2] +Type=link +Left=0 +Right=-1 +Top=74 +Bottom=88 +State=http://www.slproweb.com/products/Win32OpenSSL.html +Text=http://www.slproweb.com/products/Win32OpenSSL.html + +[Field 3] +Type=checkbox +Left=0 +Right=-1 +Top=93 +Bottom=105 +Text="Proceed with install" +State=0 +Flags=NOTIFY diff --git a/src/win32/CheckUserH.ini b/src/win32/CheckUserH.ini index 63b2589b5..8cd9ffc42 100644 --- a/src/win32/CheckUserH.ini +++ b/src/win32/CheckUserH.ini @@ -14,7 +14,7 @@ Type=checkbox Left=0 Right=-1 Top=50 -Bottom=-10 +Bottom=62 Text="Proceed with install" State=0 Flags=NOTIFY diff --git a/src/win32/ejabberd.cfg b/src/win32/ejabberd.cfg index b4fdeb0d8..237761e5f 100644 --- a/src/win32/ejabberd.cfg +++ b/src/win32/ejabberd.cfg @@ -85,14 +85,35 @@ % Host name: {host, "localhost"}. +% Default language: +{language, "en"}. % Listened ports: {listen, - [{5222, ejabberd_c2s, [{access, c2s}, {shaper, c2s_shaper}]}, -% {5223, ejabberd_c2s, [{access, c2s}, ssl, {certfile, "./ssl.pem"}]}, + [ + {5222, ejabberd_c2s, [{access, c2s}, + {shaper, c2s_shaper}]}, + +% To create selfsigned certificate run the following command form the +% command prompt: +% +% openssl req -new -x509 -days 365 -nodes -out ejabberd.pem -keyout ejabberd.pem +% +% and answer the questions. +% {5222, ejabberd_c2s, [{access, c2s}, +% starttls, {certfile, "./ejabberd.pem"} +% {shaper, c2s_shaper}]}, + +% When using SSL/TLS ssl option is not recommended (it requires patching +% erlang ssl application). Use tls option instead (as shown below). +% {5223, ejabberd_c2s, [{access, c2s}, +% tls, {certfile, "./ejabberd.pem"}]}, + {5269, ejabberd_s2s_in, [{shaper, s2s_shaper}]}, + % {5555, ejabberd_service, [{access, all}, % {host, "icq.localhost", [{password, "secret"}]}]}, + {5280, ejabberd_http, [http_poll, web_admin]} ]}. @@ -111,6 +132,7 @@ {mod_stats, []}, {mod_vcard, []}, {mod_offline, []}, + {mod_announce, [{access, announce}]}, {mod_private, []}, {mod_irc, []}, {mod_muc, []}, diff --git a/src/win32/ejabberd.nsi b/src/win32/ejabberd.nsi index e0b23c978..8c7d3fe59 100644 --- a/src/win32/ejabberd.nsi +++ b/src/win32/ejabberd.nsi @@ -30,8 +30,10 @@ !ifdef HACKED_INSTALLOPTIONS ReserveFile "CheckUserH.ini" + ReserveFile "CheckReqs1H.ini" !else ReserveFile "CheckUser.ini" + ReserveFile "CheckReqs1.ini" !endif ReserveFile "CheckReqs.ini" !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS @@ -45,6 +47,9 @@ Var ERLANG_PATH Var ERLANG_VERSION Var REQUIRED_ERLANG_VERSION + Var OPENSSL_PATH + Var OPENSSL_VERSION + Var REQUIRED_OPENSSL_VERSION Var ERLSRV ;---------------------------------------------------------- @@ -52,7 +57,8 @@ Function .onInit - StrCpy $REQUIRED_ERLANG_VERSION "5.3" + StrCpy $REQUIRED_ERLANG_VERSION "5.3.6.2" + StrCpy $REQUIRED_OPENSSL_VERSION "0.9.7c" ;Default installation folder StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT}" @@ -70,8 +76,10 @@ Function .onInit ;Extract InstallOptions INI files !ifdef HACKED_INSTALLOPTIONS !insertmacro MUI_INSTALLOPTIONS_EXTRACT "CheckUserH.ini" + !insertmacro MUI_INSTALLOPTIONS_EXTRACT "CheckReqs1H.ini" !else !insertmacro MUI_INSTALLOPTIONS_EXTRACT "CheckUser.ini" + !insertmacro MUI_INSTALLOPTIONS_EXTRACT "CheckReqs1.ini" !endif !insertmacro MUI_INSTALLOPTIONS_EXTRACT "CheckReqs.ini" @@ -106,6 +114,7 @@ FunctionEnd Page custom CheckUser LeaveCheckUser !insertmacro MUI_PAGE_LICENSE "..\..\COPYING" Page custom CheckReqs LeaveCheckReqs + Page custom CheckReqs1 LeaveCheckReqs1 ;!insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY @@ -142,6 +151,7 @@ SectionIn 1 RO File /r "${TESTDIR}\win32" File "${TESTDIR}\libeay32.dll" File "${TESTDIR}\ssleay32.dll" + File /oname=ejabberd.cfg.example "${TESTDIR}\ejabberd.cfg" SetOverwrite off File "${TESTDIR}\ejabberd.cfg" SetOverwrite on @@ -155,10 +165,11 @@ SectionIn 1 RO StrCpy $0 "$SMPROGRAMS\$STARTMENU_FOLDER" CreateDirectory "$0" CreateShortCut "$0\Start Ejabberd.lnk" "$ERLANG_PATH\bin\werl.exe" \ - '-sname ejabberd -pa ebin -pa win32/$ERLANG_VERSION \ + '-sname ejabberd -pa ebin \ -env EJABBERD_SO_PATH priv/lib -env EJABBERD_MSGS_PATH msgs \ -env EJABBERD_LOG_PATH log/ejabberd.log \ - -s ejabberd -ejabberd config \"ejabberd.cfg\" -mnesia dir \"spool\"' \ + -s ejabberd -ejabberd config \"ejabberd.cfg\" -mnesia dir \"spool\" \ + -sasl sasl_error_logger {file,\"log/sasl.log\"}' \ $INSTDIR\win32\ejabberd.ico CreateShortCut "$0\Edit Config.lnk" "%SystemRoot%\system32\notepad.exe" \ "$INSTDIR\ejabberd.cfg" @@ -190,7 +201,7 @@ SectionIn 1 RO installsrv: nsExec::ExecToLog '"$ERLSRV" add ejabberd -stopaction "init:stop()." \ -onfail reboot -workdir "$INSTDIR" \ - -args "-s ejabberd -pa ebin -pa win32/$ERLANG_VERSION \ + -args "-s ejabberd -pa ebin \ -ejabberd config \\\"ejabberd.cfg\\\" \ -env EJABBERD_SO_PATH priv/lib -env EJABBERD_MSGS_PATH msgs \ -env EJABBERD_LOG_PATH log/ejabberd.log \ @@ -394,6 +405,56 @@ Function LeaveCheckReqs FunctionEnd +Function CheckReqs1 + + Push "HKLM" + Call FindOpenSSL + Pop $OPENSSL_PATH + Pop $OPENSSL_VERSION + StrCmp $OPENSSL_PATH "" 0 abort + Push "HKCU" + Call FindOpenSSL + Pop $OPENSSL_PATH + Pop $OPENSSL_VERSION + StrCmp $OPENSSL_PATH "" 0 abort + + !insertmacro MUI_HEADER_TEXT $(TEXT_CR_TITLE) $(TEXT_CR_SUBTITLE) + + !ifdef HACKED_INSTALLOPTIONS + !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "CheckReqs1H.ini" + !insertmacro MUI_INSTALLOPTIONS_READ $0 "CheckReqs1H.ini" "Field 3" "State" + GetDlgItem $1 $HWNDPARENT 1 + EnableWindow $1 $0 + !else + !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "CheckReqs1.ini" + !endif + + !insertmacro MUI_INSTALLOPTIONS_SHOW + + abort: + Abort + +FunctionEnd + +Function LeaveCheckReqs1 + + !ifdef HACKED_INSTALLOPTIONS + !insertmacro MUI_INSTALLOPTIONS_READ $0 "CheckReqs1H.ini" "Settings" "State" + StrCmp $0 0 validate ;Next button? + StrCmp $0 3 checkbox ;checkbox? + Abort ;Return to the page + + checkbox: + !insertmacro MUI_INSTALLOPTIONS_READ $0 "CheckReqs1H.ini" "Field 3" "State" + GetDlgItem $1 $HWNDPARENT 1 + EnableWindow $1 $0 + Abort + + validate: + !endif + +FunctionEnd + Function FindErlang Exch $R0 @@ -447,6 +508,53 @@ Function FindErlang FunctionEnd +Function FindOpenSSL + + Exch $R0 + Push $R1 + Push $R2 + Push $R3 + Push $R4 + Push $R5 + + StrCpy $R1 0 + StrCpy $R2 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenSSL_is1" + + StrCmp $R0 HKLM h1 + ReadRegStr $R3 HKCU "$R2" "DisplayName" + ReadRegStr $R4 HKCU "$R2" "Inno Setup: App Path" + Goto l1 + h1: + ReadRegStr $R3 HKLM "$R2" "DisplayName" + ReadRegStr $R4 HKLM "$R2" "Inno Setup: App Path" + l1: + + IfFileExists "$R4\bin\openssl.exe" 0 notfound + Goto get + ; TODO check version + ;Push $REQUIRED_OPENSSL_VERSION + ;Push $R3 + ;Call CompareVersions + ;Pop $R5 + ;StrCmp $R5 1 get + + notfound: + StrCpy $R4 "" + + get: + StrCpy $R0 $R4 + StrCpy $R1 $R3 + + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Exch $R1 + Exch + Exch $R0 + +FunctionEnd + ;---------------------------------------------------------------------- ; CompareVersions ; input: