/* Copyright (C) 2013 The giomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glibmm/interface.h>
#include <giomm/enums.h>
#include <giomm/iostream.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/interface_p.h)
_PINCLUDE(gio/gio.h)

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GTlsClientConnectionInterface GTlsClientConnectionInterface;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

namespace Glib
{
class GLIBMM_API ByteArray;
}

namespace Gio
{

class GIOMM_API SocketConnectable;
class GIOMM_API TlsClientConnectionImpl;

// See https://bugzilla.gnome.org/show_bug.cgi?id=776537
// especially the last paragraph of comment 6.

/** TLS client-side connection.
 * %TlsClientConnection is the client-side subclass of TlsConnection,
 * representing a client-side TLS connection.
 * @newin{2,36}
 */
class GIOMM_API TlsClientConnection : public Glib::Interface
{
  _CLASS_INTERFACE(TlsClientConnection, GTlsClientConnection, G_TLS_CLIENT_CONNECTION, GTlsClientConnectionInterface, , , GIOMM_API)

public:
  // It's not possible to use _WRAP_CTOR/_WRAP_CREATE to wrap the new
  // function because this is an interface.
#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsClientConnectionImpl>',`std::dynamic_pointer_cast<TlsClientConnectionImpl>(Glib::wrap(G_TLS_CONNECTION($3)))')
  _WRAP_METHOD(static Glib::RefPtr<TlsClientConnectionImpl> create(const Glib::RefPtr<IOStream>& base_io_stream,
    const Glib::RefPtr<const SocketConnectable>& server_identity{?}), g_tls_client_connection_new, errthrow)

  _WRAP_METHOD(void set_server_identity(const Glib::RefPtr<SocketConnectable>& identity), g_tls_client_connection_set_server_identity)

  _WRAP_METHOD(Glib::RefPtr<SocketConnectable> get_server_identity(), g_tls_client_connection_get_server_identity, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const SocketConnectable> get_server_identity() const, g_tls_client_connection_get_server_identity, constversion)

  _WRAP_METHOD(void set_validation_flags(TlsCertificateFlags flags), g_tls_client_connection_set_validation_flags,
    deprecated "Do not attempt to ignore validation errors.")
  _WRAP_METHOD(TlsCertificateFlags get_validation_flags() const, g_tls_client_connection_get_validation_flags,
    deprecated "Do not attempt to ignore validation errors.")

  _IGNORE(g_tls_client_connection_set_use_ssl3, g_tls_client_connection_get_use_ssl3) dnl// deprecated

#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Glib::ByteArray> >',`Glib::ListHandler< Glib::RefPtr<Glib::ByteArray> >::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
  _WRAP_METHOD(std::vector< Glib::RefPtr<Glib::ByteArray> > get_accepted_cas(), g_tls_client_connection_get_accepted_cas)

#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Glib::ByteArray> >',`Glib::ListHandler< Glib::RefPtr<const Glib::ByteArray> >::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
  _WRAP_METHOD(std::vector< Glib::RefPtr<const Glib::ByteArray> > get_accepted_cas() const, g_tls_client_connection_get_accepted_cas)

  _WRAP_METHOD(void copy_session_state(const Glib::RefPtr<TlsClientConnection>& source), g_tls_client_connection_copy_session_state)

  // property_accepted_cas() won't work unless a Glib::Value<std::vector<Glib::RefPtr<Glib::ByteArray>>>
  // specialization is added. Workaround: Use get_accepted_cas().
  //_WRAP_PROPERTY("accepted-cas", std::vector<Glib::RefPtr<Glib::ByteArray>>)
  _WRAP_PROPERTY("server-identity", Glib::RefPtr<SocketConnectable>)
  _WRAP_PROPERTY("validation-flags", TlsCertificateFlags,
    deprecated "Do not attempt to ignore validation errors.")
  _IGNORE_PROPERTY(use-ssl3) dnl// deprecated
};

} // namespace Gio
