diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-07-30 16:42:14 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-07-30 16:42:14 +0200 |
commit | 2b089793b961549c44d8de562af43cf48a60d95b (patch) | |
tree | e14c34bfb2699a154addb1c108c0a2bb4d7d56c2 /gio | |
parent | b8299eae569f9681f1e2ee6f36864ce68e4eba12 (diff) | |
download | glibmm-2b089793b961549c44d8de562af43cf48a60d95b.tar.gz |
Gio: Add Tls[Client,Server]ConnectionImpl
Restructure Tls[Client,Server]Connection. They are interfaces. Now they
derive only from Glib::Interface, like all interfaces shall do.
Tls[Client,Server]ConnectionImpl don't correspond to C classes. They can
wrap any C object that derives from GTlsConnection and implements
GTls[Client,Server]Connection. Such C classes in GLib are not public.
They can't be wrapped in the usual way.
Diffstat (limited to 'gio')
-rw-r--r-- | gio/giomm.h | 2 | ||||
-rw-r--r-- | gio/giomm/filelist.am | 19 | ||||
-rw-r--r-- | gio/giomm/meson.build | 2 | ||||
-rw-r--r-- | gio/giomm/tlsclientconnectionimpl.cc | 45 | ||||
-rw-r--r-- | gio/giomm/tlsclientconnectionimpl.h | 69 | ||||
-rw-r--r-- | gio/giomm/tlsserverconnectionimpl.cc | 45 | ||||
-rw-r--r-- | gio/giomm/tlsserverconnectionimpl.h | 69 | ||||
-rw-r--r-- | gio/src/tlsclientconnection.ccg | 11 | ||||
-rw-r--r-- | gio/src/tlsclientconnection.hg | 25 | ||||
-rw-r--r-- | gio/src/tlsconnection.hg | 6 | ||||
-rw-r--r-- | gio/src/tlsfiledatabase.hg | 10 | ||||
-rw-r--r-- | gio/src/tlsserverconnection.ccg | 11 | ||||
-rw-r--r-- | gio/src/tlsserverconnection.hg | 21 |
13 files changed, 290 insertions, 45 deletions
diff --git a/gio/giomm.h b/gio/giomm.h index 30ba71d7..007cb27e 100644 --- a/gio/giomm.h +++ b/gio/giomm.h @@ -150,11 +150,13 @@ #include <giomm/threadedsocketservice.h> #include <giomm/tlscertificate.h> #include <giomm/tlsclientconnection.h> +#include <giomm/tlsclientconnectionimpl.h> #include <giomm/tlsconnection.h> #include <giomm/tlsdatabase.h> #include <giomm/tlsinteraction.h> #include <giomm/tlspassword.h> #include <giomm/tlsserverconnection.h> +#include <giomm/tlsserverconnectionimpl.h> #ifndef G_OS_WIN32 #include <giomm/unixconnection.h> #include <giomm/unixcredentialsmessage.h> diff --git a/gio/giomm/filelist.am b/gio/giomm/filelist.am index fe49892f..3414b39c 100644 --- a/gio/giomm/filelist.am +++ b/gio/giomm/filelist.am @@ -3,8 +3,23 @@ giomm_files_built_cc = $(giomm_files_used_hg:.hg=.cc) wrap_init.cc giomm_files_built_h = $(giomm_files_used_hg:.hg=.h) -giomm_files_extra_cc = contenttype.cc init.cc slot_async.cc socketsource.cc -giomm_files_extra_h = contenttype.h init.h slot_async.h socketsource.h wrap_init.h +giomm_files_extra_cc = \ + contenttype.cc \ + init.cc \ + slot_async.cc \ + socketsource.cc \ + tlsclientconnectionimpl.cc \ + tlsserverconnectionimpl.cc + +giomm_files_extra_h = \ + contenttype.h \ + init.h \ + slot_async.h \ + socketsource.h \ + tlsclientconnectionimpl.h \ + tlsserverconnectionimpl.h \ + wrap_init.h + giomm_files_extra_ph = giomm_files_all_h = $(giomm_files_hg:.hg=.h) $(giomm_files_extra_h) diff --git a/gio/giomm/meson.build b/gio/giomm/meson.build index 0e9c3115..4ab1aa8c 100644 --- a/gio/giomm/meson.build +++ b/gio/giomm/meson.build @@ -192,6 +192,8 @@ giomm_extra_h_cc_basenames = [ 'init', 'slot_async', 'socketsource', + 'tlsclientconnectionimpl', + 'tlsserverconnectionimpl', ] giomm_extra_h_files = [ diff --git a/gio/giomm/tlsclientconnectionimpl.cc b/gio/giomm/tlsclientconnectionimpl.cc new file mode 100644 index 00000000..9207924a --- /dev/null +++ b/gio/giomm/tlsclientconnectionimpl.cc @@ -0,0 +1,45 @@ +/* Copyright (C) 2020 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 <giomm/tlsclientconnectionimpl.h> + +namespace Gio +{ +TlsClientConnectionImpl::TlsClientConnectionImpl(GTlsConnection* castitem) +: Glib::ObjectBase(nullptr), TlsConnection(castitem) +{} +} /* namespace Gio */ + +namespace Glib +{ + +Glib::RefPtr<Gio::TlsClientConnectionImpl> wrap_tls_client_connection_impl( + GTlsConnection* object, bool take_copy) +{ + using IfaceImpl = Gio::TlsClientConnectionImpl; + + ObjectBase* pCppObject = ObjectBase::_get_current_wrapper((GObject*)object); + + if (!pCppObject) + pCppObject = new IfaceImpl(object); + + if (take_copy) + pCppObject->reference(); + + return Glib::make_refptr_for_instance<IfaceImpl>(dynamic_cast<IfaceImpl*>(pCppObject)); +} + +} /* namespace Glib */ diff --git a/gio/giomm/tlsclientconnectionimpl.h b/gio/giomm/tlsclientconnectionimpl.h new file mode 100644 index 00000000..f77e82d1 --- /dev/null +++ b/gio/giomm/tlsclientconnectionimpl.h @@ -0,0 +1,69 @@ +#ifndef _GIOMM_TLSCLIENTCONNECTIONIMPL_H +#define _GIOMM_TLSCLIENTCONNECTIONIMPL_H + +/* Copyright (C) 2020 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 <giommconfig.h> +#include <giomm/tlsclientconnection.h> +#include <giomm/tlsconnection.h> + +namespace Gio +{ + +/** %Gio::TlsClientConnectionImpl implements the Gio::TlsClientConnection interface. + * + * The GTlsClientConnection interface can be implemented by C classes that + * derive from GTlsConnection. No public GLib class implements GTlsClientConnection. + * Some GLib functions, such as g_tls_client_connection_new(), return an object + * of a class which is derived from GTlsConnection and implements GTlsClientConnection. + * Since that C class is not public, it's not wrapped in a C++ class. + * A C object of such a class can be wrapped in a %Gio::TlsClientConnectionImpl object. + * %Gio::TlsClientConnectionImpl does not directly correspond to any GLib class. + * + * This class is intended only for wrapping C objects returned from GLib functions. + * + * @newin{2,66} + */ +class GIOMM_API TlsClientConnectionImpl : public TlsClientConnection, public TlsConnection +{ +public: + explicit TlsClientConnectionImpl(GTlsConnection* castitem); +}; + +} // namespace Gio + +namespace Glib +{ + /** A %Glib::wrap() method for this object. + * + * It's not called %wrap() because it wraps a C object which is derived from + * GTlsConnection and implements the GTlsClientConnection interface. + * + * @param object The C instance. + * @param take_copy False if the result should take ownership of the C instance. + * True if it should take a new ref. + * @result A C++ instance that wraps this C instance. + * + * @relates Gio::TlsClientConnectionImpl + */ + GIOMM_API + Glib::RefPtr<Gio::TlsClientConnectionImpl> wrap_tls_client_connection_impl( + GTlsConnection* object, bool take_copy = false); + +} // namespace Glib + +#endif /* _GIOMM_TLSCLIENTCONNECTIONIMPL_H */ diff --git a/gio/giomm/tlsserverconnectionimpl.cc b/gio/giomm/tlsserverconnectionimpl.cc new file mode 100644 index 00000000..4a4779e0 --- /dev/null +++ b/gio/giomm/tlsserverconnectionimpl.cc @@ -0,0 +1,45 @@ +/* Copyright (C) 2020 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 <giomm/tlsserverconnectionimpl.h> + +namespace Gio +{ +TlsServerConnectionImpl::TlsServerConnectionImpl(GTlsConnection* castitem) +: Glib::ObjectBase(nullptr), TlsConnection(castitem) +{} +} /* namespace Gio */ + +namespace Glib +{ + +Glib::RefPtr<Gio::TlsServerConnectionImpl> wrap_tls_server_connection_impl( + GTlsConnection* object, bool take_copy) +{ + using IfaceImpl = Gio::TlsServerConnectionImpl; + + ObjectBase* pCppObject = ObjectBase::_get_current_wrapper((GObject*)object); + + if (!pCppObject) + pCppObject = new IfaceImpl(object); + + if (take_copy) + pCppObject->reference(); + + return Glib::make_refptr_for_instance<IfaceImpl>(dynamic_cast<IfaceImpl*>(pCppObject)); +} + +} /* namespace Glib */ diff --git a/gio/giomm/tlsserverconnectionimpl.h b/gio/giomm/tlsserverconnectionimpl.h new file mode 100644 index 00000000..ff25eb40 --- /dev/null +++ b/gio/giomm/tlsserverconnectionimpl.h @@ -0,0 +1,69 @@ +#ifndef _GIOMM_TLSSERVERCONNECTIONIMPL_H +#define _GIOMM_TLSSERVERCONNECTIONIMPL_H + +/* Copyright (C) 2020 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 <giommconfig.h> +#include <giomm/tlsserverconnection.h> +#include <giomm/tlsconnection.h> + +namespace Gio +{ + +/** %Gio::TlsServerConnectionImpl implements the Gio::TlsServerConnection interface. + * + * The GTlsServerConnection interface can be implemented by C classes that + * derive from GTlsConnection. No public GLib class implements GTlsServerConnection. + * Some GLib functions, such as g_tls_server_connection_new(), return an object + * of a class which is derived from GTlsConnection and implements GTlsServerConnection. + * Since that C class is not public, it's not wrapped in a C++ class. + * A C object of such a class can be wrapped in a %Gio::TlsServerConnectionImpl object. + * %Gio::TlsServerConnectionImpl does not directly correspond to any GLib class. + * + * This class is intended only for wrapping C objects returned from GLib functions. + * + * @newin{2,66} + */ +class GIOMM_API TlsServerConnectionImpl : public TlsServerConnection, public TlsConnection +{ +public: + explicit TlsServerConnectionImpl(GTlsConnection* castitem); +}; + +} // namespace Gio + +namespace Glib +{ + /** A %Glib::wrap() method for this object. + * + * It's not called %wrap() because it wraps a C object which is derived from + * GTlsConnection and implements the GTlsServerConnection interface. + * + * @param object The C instance. + * @param take_copy False if the result should take ownership of the C instance. + * True if it should take a new ref. + * @result A C++ instance that wraps this C instance. + * + * @relates Gio::TlsServerConnectionImpl + */ + GIOMM_API + Glib::RefPtr<Gio::TlsServerConnectionImpl> wrap_tls_server_connection_impl( + GTlsConnection* object, bool take_copy = false); + +} // namespace Glib + +#endif /* _GIOMM_TLSSERVERCONNECTIONIMPL_H */ diff --git a/gio/src/tlsclientconnection.ccg b/gio/src/tlsclientconnection.ccg index c2785a42..0fb8fbb0 100644 --- a/gio/src/tlsclientconnection.ccg +++ b/gio/src/tlsclientconnection.ccg @@ -16,13 +16,4 @@ #include <gio/gio.h> #include <giomm/socketconnectable.h> - -namespace Gio -{ - -TlsClientConnection::TlsClientConnection(GTlsClientConnection* castitem) -: TlsConnection(G_TLS_CONNECTION(castitem)) -{ -} - -} // namespace Gio +#include <giomm/tlsclientconnectionimpl.h> diff --git a/gio/src/tlsclientconnection.hg b/gio/src/tlsclientconnection.hg index ca01922e..94465477 100644 --- a/gio/src/tlsclientconnection.hg +++ b/gio/src/tlsclientconnection.hg @@ -15,8 +15,8 @@ */ #include <glibmm/interface.h> -#include <giomm/tlsconnection.h> #include <giomm/enums.h> +#include <giomm/iostream.h> _DEFS(giomm,gio) _PINCLUDE(glibmm/private/interface_p.h) @@ -26,32 +26,35 @@ _PINCLUDE(gio/gio.h) 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; -// It's unusual that a subclass of Glib::Object is a base class of an interface. -// For a discussion, see https://bugzilla.gnome.org/show_bug.cgi?id=776537 +// See https://bugzilla.gnome.org/show_bug.cgi?id=776537 // especially the last paragraph of comment 6. -/** TlsClientConnection - TLS client-side connection. - * TlsClientConnection is the client-side subclass of TlsConnection, +/** 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, - public TlsConnection +class GIOMM_API TlsClientConnection : public Glib::Interface { _CLASS_INTERFACE(TlsClientConnection, GTlsClientConnection, G_TLS_CLIENT_CONNECTION, GTlsClientConnectionInterface, , , GIOMM_API) - _CUSTOM_CTOR_CAST 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<TlsClientConnection>',`Glib::wrap(G_TLS_CLIENT_CONNECTION($3))') - _WRAP_METHOD(static Glib::RefPtr<TlsClientConnection> create(const Glib::RefPtr<IOStream>& base_io_stream, const Glib::RefPtr<const SocketConnectable>& server_identity{?}), g_tls_client_connection_new, errthrow) +#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsClientConnectionImpl>',`Glib::wrap_tls_client_connection_impl(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) diff --git a/gio/src/tlsconnection.hg b/gio/src/tlsconnection.hg index c70cc803..12132a80 100644 --- a/gio/src/tlsconnection.hg +++ b/gio/src/tlsconnection.hg @@ -30,9 +30,9 @@ class GIOMM_API Cancellable; class GIOMM_API TlsDatabase; class GIOMM_API TlsInteraction; -/** TlsConnection - TLS connection type. - * TlsConnection is the base TLS connection class type, which wraps an IOStream - * and provides TLS encryption on top of it. Its subclasses, +/** TLS connection type. + * %TlsConnection is the base TLS connection class type, which wraps an IOStream + * and provides TLS encryption on top of it. Its subclasses that implement * TlsClientConnection and TlsServerConnection, implement client-side and * server-side TLS, respectively. * @newin{2,36} diff --git a/gio/src/tlsfiledatabase.hg b/gio/src/tlsfiledatabase.hg index 232126f9..a2382bed 100644 --- a/gio/src/tlsfiledatabase.hg +++ b/gio/src/tlsfiledatabase.hg @@ -28,6 +28,16 @@ typedef struct _GTlsFileDatabaseInterface GTlsFileDatabaseInterface; namespace Gio { +// commit e28f5093dced2e8cafef5795c02657b7265b78ca +// Author: José Alburquerque <jaalburqu@svn.gnome.org> +// Date: Tue Mar 26 10:48:59 2013 -0400 +// TlsFileDatabase: Remove the class until its usage is more clear. + +// TODO: If this class is ever added to the build system, consider restructuring +// like TlsClientConnectionImpl and TlsServerConnectionImpl. +// class GIOMM_API TlsFileDatabase : public Glib::Interface +// class GIOMM_API TlsFileDatabaseImpl : public TlsFileDatabase, public TlsDatabase + // It's unusual that a subclass of Glib::Object is a base class of an interface. // For a discussion, see https://bugzilla.gnome.org/show_bug.cgi?id=776537 // especially the last paragraph of comment 6. diff --git a/gio/src/tlsserverconnection.ccg b/gio/src/tlsserverconnection.ccg index 01cfc858..16da8120 100644 --- a/gio/src/tlsserverconnection.ccg +++ b/gio/src/tlsserverconnection.ccg @@ -15,13 +15,4 @@ */ #include <gio/gio.h> - -namespace Gio -{ - -TlsServerConnection::TlsServerConnection(GTlsServerConnection* castitem) -: TlsConnection(G_TLS_CONNECTION(castitem)) -{ -} - -} // namespace Gio +#include <giomm/tlsserverconnectionimpl.h> diff --git a/gio/src/tlsserverconnection.hg b/gio/src/tlsserverconnection.hg index d4676119..94a729a5 100644 --- a/gio/src/tlsserverconnection.hg +++ b/gio/src/tlsserverconnection.hg @@ -15,8 +15,9 @@ */ #include <glibmm/interface.h> -#include <giomm/tlsconnection.h> #include <giomm/enums.h> +#include <giomm/iostream.h> +#include <giomm/tlscertificate.h> _DEFS(giomm,gio) _PINCLUDE(glibmm/private/interface_p.h) @@ -28,25 +29,27 @@ typedef struct _GTlsServerConnectionInterface GTlsServerConnectionInterface; namespace Gio { -// It's unusual that a subclass of Glib::Object is a base class of an interface. -// For a discussion, see https://bugzilla.gnome.org/show_bug.cgi?id=776537 + +class GIOMM_API TlsServerConnectionImpl; + +// See https://bugzilla.gnome.org/show_bug.cgi?id=776537 // especially the last paragraph of comment 6. -/** TlsServerConnection - TLS server-side connection. - * TlsServerConnection is the server-side subclass of TlsConnection, +/** TLS server-side connection. + * %TlsServerConnection is the server-side subclass of TlsConnection, * representing a server-side TLS connection. * @newin{2,36} */ -class GIOMM_API TlsServerConnection : public Glib::Interface, public TlsConnection +class GIOMM_API TlsServerConnection : public Glib::Interface { _CLASS_INTERFACE(TlsServerConnection, GTlsServerConnection, G_TLS_SERVER_CONNECTION, GTlsServerConnectionInterface, , , GIOMM_API) - _CUSTOM_CTOR_CAST 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<TlsServerConnection>',`Glib::wrap(G_TLS_SERVER_CONNECTION($3))') - _WRAP_METHOD(static Glib::RefPtr<IOStream> create(const Glib::RefPtr<IOStream>& base_io_stream, const Glib::RefPtr<TlsCertificate>& certificate), g_tls_server_connection_new, errthrow) +#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsServerConnectionImpl>',`Glib::wrap_tls_server_connection_impl(G_TLS_CONNECTION($3))') + _WRAP_METHOD(static Glib::RefPtr<TlsServerConnectionImpl> create(const Glib::RefPtr<IOStream>& base_io_stream, + const Glib::RefPtr<TlsCertificate>& certificate), g_tls_server_connection_new, errthrow) _WRAP_PROPERTY("authentication-mode", TlsAuthenticationMode) }; |