[BB10-internal] QNetworkAccessManager: return default configuration if without session

... instead of a zero configuration. That is documented already for
QNetworkAccessManager::setConfiguration().

Task-number: QTBUG-28973
(cherry picked from commit 1df2b9ee2376e132a6bf9596097351f0c79e6b73)

Change-Id: I074265525485b63adecad90f16fd4e2acf6d7b16
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] Revert "[BB10-internal] Remove QPerformanceTimer now that QElapsedTimer contains the necessary bits"

This reverts commit 88966515993773e4d7d6276bce6fccfcc13ab6f4.

This apparently caused regressions in Cascades.

Change-Id: I004a89ff387fa4af6e11d77ff271e437d2f8e170
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] SSL: Implement session sharing and use it from QNetworkAccessManager

This improves performance since a network round trip can be avoided.

Change-Id: I1aaff7e48ef9638cb137de0f43942c3a4dd2884a
Initial-patch-by: Markus Goetz <markus@woboq.com>
Reviewed-by: Richard J. Moore <rich@kde.org>

Author: Marcel Krems <m.krems@software-vision.eu>
Date:   Thu Feb 7 05:24:52 2013 +0100
SSL: Use correct signature for SSL_get1_session

This fixes a compilation error with GCC 4.7
which was introduced in b5652df775efbd1c52eecee5f08e40e600e5d70b
In function ‘SSL_SESSION* q_SSL_get1_session(const SSL*)’:
invalid conversion from ‘const SSL* {aka const ssl_st*}’ to ‘SSL* {aka ssl_st*}’ [-fpermissive]

Change-Id: I909f7fb4295b2019283a7af66a038d4711e5f7cb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Peter Hartmann <phartmann@rim.com>

(backport of b5652df775efbd1c52eecee5f08e40e600e5d70b and
9b5ec67c18cba4e7b0b8a4d5c8c52b64da7549a9 squashed together)

Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] Move support for socket binding from QUdpSocket to QAbstractSocketPrivate

(backport of 03f852cb47d508d98aa90f501e9b7f4214e8ad8b)
This is a backport of a Qt5 commit, moving the bind method to
QAbstractSocketPrivate to retain binary compatibility, yet still
being able to use it from the HTTP layer (i.e.
QHttpNetworkConnectionChannel).

Task-number: QTBUG-121
Change-Id: I733efe90ea70c5774971f11d6a2054c84b467988
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] QAbstractSocket: delay bind for TCP and SSL sockets

... because we delete the socket engine anyhow when connecting; so we
just store the local address, port and bind mode and bind after we
deleted the socket engine and before we connect to the server.

*caveat*:
DNS traffic is still flowing over the standard interface, because there
seems to be no way to tell getaddrinfo() which route to use.

This change also requires the following changes:
- the socket engine needs to allow connections when in BoundState
- in bind(), we need to always set the local address and port from
  the socket engine, so that in case the bind() failed we clear the
  address and port again.

Change-Id: I883199a7869effc3a66f0ded37a949ba7cd95b3d
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] QNetworkConfiguration: store list of host addresses

... which can be populated by the bearer plugin.

Change-Id: Ibfa92eb7e480ef8c75b90f1dc0751c938d7afda7
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] BB10 bearer plugin: populate list of host addresses

... so the sockets will know which address to bind to in case a non-
default interface should be used.

Change-Id: Ice0f946bf265fda50bd538a1f26d5fdd7a0dbd70
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] QNetworkAccessManager: store QNetworkConfiguration instead of identifier

In case a network session is not required, we need access to the
configuration object rather than to the QString. Also, only create a
session if the configuration manager needs one.

Change-Id: I05945525ce8247e343d0bebd7ec15e0e162ed826
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] HTTP internals: store QNetworkConfiguration to be set on the socket

The QNetworkConfiguration can be set via the QNetworkAccessManager
and needs to be set on the socket, e.g. when preferring cellular
traffic over Wifi.

Change-Id: Ia2d9ed8cdc29db77ca5d01b462aab65c72cca394
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] QHttpNetworkConnectionChannel: set bind addresses on the socket

... and use it in QAbstractSocket. By the time we connect the socket
we do not know yet whether we will need an IPv4 or IPv6 bind address,
so we set both as properties on the socket and decide after host name
lookup and right before connecting.

Change-Id: I2be6ab4ab84e7e799158d7f42443337ad37b4e72
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] QNetworkAccessManager: track online / accesible state without session

In particular, set online state right upon construction of the
QNetworkAccessManager instance.
Before, this would only work properly if a network session was created.
Now, networkAccessible() returns the correct status.

Change-Id: I7ff9ccfd18ad376a131fc5977843b55bf185fba0
Signed-off-by: Peter Hartmann <phartmann@rim.com>
[BB10-internal] Revert "[RIM-internal] QNetworkAccessManager: track online / accesible state without session"

This reverts commit 3a678bfb0d632d227541854a326f50722e2d0c74.

... because it causes crashes. It is probably not the commit that is
erroneous, but it seems there is some deeper lying problem.

Task-number: PR 316429
Change-Id: I355223563059b1a72ddb03b2254c0eccd554986a
Signed-off-by: Peter Hartmann <phartmann@blackberry.com>
[BB10-internal] Workaround for PR 318290

Hard to reproduce crashes on application exit are being worked
around by leaking the memory (safe, as this should only occur on
application exit when the memory will be cleaned up at a process
level shortly).

Change-Id: I6525a39edc772277b8d92820f520542fcdc4580a
Signed-off-by: Peter Hartmann <phartmann@blackberry.com>
[BB10-internal] SSL internals: fix memory corruption using QSslConfigurationPrivate

We are passing a QSslConfigurationPrivate that is allocated on the stack
(in QSslSocketBackendPrivate::initSslContext()) to
QSslConfiguration::QSslConfiguration(QSslConfigurationPrivate *dd).
When the SSL context is destroyed, this object is not there any more.
So now we create a deep copy of the configuration like we do in
QSslSocket::sslConfiguration().

Task-number: QTBUG-30648
(backport of commit 3a43aff9deb4af0479914a26d68fb98d313369b6)
Signed-off-by: Peter Hartmann <phartmann@blackberry.com>

Change-Id: I0a39b2bc485ce5a3528b72e6e47c3bd124963b3b
[BB10-internal] QSslConfiguration: add API to persist and resume SSL sessions

Session tickets can be cached on the client side for hours (e.g.
graph.facebook.com: ~ 24 hours, api.twitter.com: 4 hours), because the
server does not need to maintain state.
We need public API for it so an application can cache the session (e.g.
to disk) and resume a session already with the 1st handshake, saving
one network round trip.

Task-number: QTBUG-20668
(backport of commit ###)

Change-Id: I4c7f3a749edf0012b52deeb495706e550d24c42d
Signed-off-by: Peter Hartmann <phartmann@blackberry.com>