Move ejabberd_zlib.erl interface to ejabberd project (EJAB-991)
Enable port level locking in stringprep driver.

By default Erlang uses driver level locking.
However, it seems there is no reason for stringprep driver not to
use port level locking, thus reducing lock contention.
Enable port level locking for OpenSSL TLS driver.

OTP crypto module is already using OpenSSL and sets some
global OpenSSL callbacks that are needed to make it thread-safe.
To avoid problems with own callbacks, start crypto before
loading OpenSSL driver and enable port level locking if the
needed callbacks are already set.
Eliminate lock contention on stringprep port

exmpp_stringprep module used to open only one port, so there
was still a lot of lock contention on port access.
Now it opens as many ports as there are scheduler threads
(as described in Erlang Efficiency Guide).
Use ERTS allocation functions in exmpp_compress_zlib

exmpp_compress_zlib now configures zlib to use ERTS
allocation functions (driver_alloc/driver_free)
which are guaranteed to be thread-safe.
Enable port level locking in zlib compression driver.

zlib is thread-safe (as long as memory allocation functions it
uses are thread safe) so enable port level locking in zlib
compression driver.
Fix memory leaks in OpenSSL TLS driver.

SSL context and connection structures were never freed.
Additionally, trusted_certs also was never freed.
Use extended marker and driver versioning without SMP support.

Extended marker indicates that driver supports additional flags
like versioning and port level locking. Currently it was only
used when SMP support was enabled. Versioning seems like a nice
feature and has nothing to do with SMP (and is present in R12B5)
so enable it regardless of SMP support.
Fix compatibility with R12B5

There is no min/2 function in R12B5.
Added presence handling to echo_client.erl (thanks to Kuleshov Alexander)
Disable SSL 2.0 and session cache in OpenSSL driver

SSL 2.0 has security flaws and is deprecated for many years.
Session cache currently does not work anyway (as new SSL
context is made for every connection) so disable it.
Additionaly, instruct OpenSSL to free network buffers on idle
connections (this is available only in OpenSSL 1.0.0).
Decrease CPU usage caused by exmpp_tls:send with large data.

Sending one large chunk of data with exmpp_tls:send eats lots of
CPU power and blocks whole Erlang emulator. This is caused by the
fact that encrypted output is read from memory BIO in 1k chunks.
Memory BIO, after reading data, shifts the remaining part.
If large chunks of data (few MB) is sent and then read in 1k
chunks, then a _lot_ of shifting is performed eating CPU.

The solution is to simply allocate binary of the needed size
(amount of data in memory BIO can be retrieved with
BIO_ctrl_pending) and then issue only one read that reads the
whole data.
Enable ephemeral Diffie-Hellman parameters in OpenSSL driver.

DH parameters (taken from OpenSSL tarball) are hardcoded in
the source. They are public and this is exactly the same approach
as taken by various other servers (Apache, nginx).
Initialize driver data with memset.

Driver data structure was initialized in start() one field at
a time. This is error prone (in fact, bio_read and bio_write
were not initialized there). Use memset to initialize the whole
structure.
Additionally, set connection and context structures to NULL in
error path of init_library().
Support for ECDHE in OpenSSL driver.

Adds support for ephemeral elliptic curve Diffie–Hellman in OpenSSL
driver. Works only with OpenSSL 1.0.0 (OpenSSL 0.9.8 is supposed
to support ECDHE, but it seems not to work).
Guard ephemeral DH with ifdefs.
Disable weak ciphers in OpenSSL driver.
Enable ECDHE only on OpenSSL 1.0.0e and later.

Earlier versions of OpenSSL have security problems with ECDHE.
See http://www.openssl.org/news/secadv_20110906.txt for details.
Update exmpp version number to 0.9.8
Add whitespace ping for client sessions

IF the option {whitespace_ping, Seconds} is
passed to connect_TCP or connect_SSL,
then send "\n" on the socket if inactive for that
time.