LCOV - code coverage report
Current view: top level - glib/gio - gdbusauthmechanism.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 72 106 67.9 %
Date: 2024-03-26 05:16:46 Functions: 20 27 74.1 %
Branches: 10 16 62.5 %

           Branch data     Line data    Source code
       1                 :            : /* GDBus - GLib D-Bus Library
       2                 :            :  *
       3                 :            :  * Copyright (C) 2008-2010 Red Hat, Inc.
       4                 :            :  *
       5                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       6                 :            :  *
       7                 :            :  * This library is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU Lesser General Public
       9                 :            :  * License as published by the Free Software Foundation; either
      10                 :            :  * version 2.1 of the License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This library is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :            :  * Lesser General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU Lesser General
      18                 :            :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19                 :            :  *
      20                 :            :  * Author: David Zeuthen <davidz@redhat.com>
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include "gdbusauthmechanism.h"
      26                 :            : #include "gcredentials.h"
      27                 :            : #include "gdbuserror.h"
      28                 :            : #include "gioenumtypes.h"
      29                 :            : #include "giostream.h"
      30                 :            : 
      31                 :            : #include "glibintl.h"
      32                 :            : 
      33                 :            : /* ---------------------------------------------------------------------------------------------------- */
      34                 :            : 
      35                 :            : struct _GDBusAuthMechanismPrivate
      36                 :            : {
      37                 :            :   GIOStream *stream;
      38                 :            :   GCredentials *credentials;
      39                 :            : };
      40                 :            : 
      41                 :            : enum
      42                 :            : {
      43                 :            :   PROP_0,
      44                 :            :   PROP_STREAM,
      45                 :            :   PROP_CREDENTIALS
      46                 :            : };
      47                 :            : 
      48   [ +  +  +  -  :      47874 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT)
                   +  + ]
      49                 :            : 
      50                 :            : /* ---------------------------------------------------------------------------------------------------- */
      51                 :            : 
      52                 :            : static void
      53                 :       1955 : _g_dbus_auth_mechanism_finalize (GObject *object)
      54                 :            : {
      55                 :       1955 :   GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
      56                 :            : 
      57         [ +  - ]:       1955 :   if (mechanism->priv->stream != NULL)
      58                 :       1955 :     g_object_unref (mechanism->priv->stream);
      59         [ +  + ]:       1955 :   if (mechanism->priv->credentials != NULL)
      60                 :       1339 :     g_object_unref (mechanism->priv->credentials);
      61                 :            : 
      62                 :       1955 :   G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object);
      63                 :       1955 : }
      64                 :            : 
      65                 :            : static void
      66                 :          0 : _g_dbus_auth_mechanism_get_property (GObject    *object,
      67                 :            :                                      guint       prop_id,
      68                 :            :                                      GValue     *value,
      69                 :            :                                      GParamSpec *pspec)
      70                 :            : {
      71                 :          0 :   GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
      72                 :            : 
      73      [ #  #  # ]:          0 :   switch (prop_id)
      74                 :            :     {
      75                 :          0 :     case PROP_STREAM:
      76                 :          0 :       g_value_set_object (value, mechanism->priv->stream);
      77                 :          0 :       break;
      78                 :            : 
      79                 :          0 :     case PROP_CREDENTIALS:
      80                 :          0 :       g_value_set_object (value, mechanism->priv->credentials);
      81                 :          0 :       break;
      82                 :            : 
      83                 :          0 :     default:
      84                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      85                 :          0 :       break;
      86                 :            :     }
      87                 :          0 : }
      88                 :            : 
      89                 :            : static void
      90                 :       3910 : _g_dbus_auth_mechanism_set_property (GObject      *object,
      91                 :            :                                      guint         prop_id,
      92                 :            :                                      const GValue *value,
      93                 :            :                                      GParamSpec   *pspec)
      94                 :            : {
      95                 :       3910 :   GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
      96                 :            : 
      97      [ +  +  - ]:       3910 :   switch (prop_id)
      98                 :            :     {
      99                 :       1955 :     case PROP_STREAM:
     100                 :       1955 :       mechanism->priv->stream = g_value_dup_object (value);
     101                 :       1955 :       break;
     102                 :            : 
     103                 :       1955 :     case PROP_CREDENTIALS:
     104                 :       1955 :       mechanism->priv->credentials = g_value_dup_object (value);
     105                 :       1955 :       break;
     106                 :            : 
     107                 :          0 :     default:
     108                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     109                 :          0 :       break;
     110                 :            :     }
     111                 :       3910 : }
     112                 :            : 
     113                 :            : static void
     114                 :         96 : _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass)
     115                 :            : {
     116                 :            :   GObjectClass *gobject_class;
     117                 :            : 
     118                 :         96 :   gobject_class = G_OBJECT_CLASS (klass);
     119                 :         96 :   gobject_class->get_property = _g_dbus_auth_mechanism_get_property;
     120                 :         96 :   gobject_class->set_property = _g_dbus_auth_mechanism_set_property;
     121                 :         96 :   gobject_class->finalize     = _g_dbus_auth_mechanism_finalize;
     122                 :            : 
     123                 :         96 :   g_object_class_install_property (gobject_class,
     124                 :            :                                    PROP_STREAM,
     125                 :            :                                    g_param_spec_object ("stream", NULL, NULL,
     126                 :            :                                                         G_TYPE_IO_STREAM,
     127                 :            :                                                         G_PARAM_READABLE |
     128                 :            :                                                         G_PARAM_WRITABLE |
     129                 :            :                                                         G_PARAM_CONSTRUCT_ONLY |
     130                 :            :                                                         G_PARAM_STATIC_NAME |
     131                 :            :                                                         G_PARAM_STATIC_BLURB |
     132                 :            :                                                         G_PARAM_STATIC_NICK));
     133                 :            : 
     134                 :            :   /**
     135                 :            :    * GDBusAuthMechanism:credentials:
     136                 :            :    *
     137                 :            :    * If authenticating as a server, this property contains the
     138                 :            :    * received credentials, if any.
     139                 :            :    *
     140                 :            :    * If authenticating as a client, the property contains the
     141                 :            :    * credentials that were sent, if any.
     142                 :            :    */
     143                 :         96 :   g_object_class_install_property (gobject_class,
     144                 :            :                                    PROP_CREDENTIALS,
     145                 :            :                                    g_param_spec_object ("credentials", NULL, NULL,
     146                 :            :                                                         G_TYPE_CREDENTIALS,
     147                 :            :                                                         G_PARAM_READABLE |
     148                 :            :                                                         G_PARAM_WRITABLE |
     149                 :            :                                                         G_PARAM_CONSTRUCT_ONLY |
     150                 :            :                                                         G_PARAM_STATIC_NAME |
     151                 :            :                                                         G_PARAM_STATIC_BLURB |
     152                 :            :                                                         G_PARAM_STATIC_NICK));
     153                 :         96 : }
     154                 :            : 
     155                 :            : static void
     156                 :       1955 : _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
     157                 :            : {
     158                 :       1955 :   mechanism->priv = _g_dbus_auth_mechanism_get_instance_private (mechanism);
     159                 :       1955 : }
     160                 :            : 
     161                 :            : /* ---------------------------------------------------------------------------------------------------- */
     162                 :            : 
     163                 :            : GIOStream *
     164                 :          0 : _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism)
     165                 :            : {
     166                 :          0 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     167                 :          0 :   return mechanism->priv->stream;
     168                 :            : }
     169                 :            : 
     170                 :            : GCredentials *
     171                 :       1463 : _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism)
     172                 :            : {
     173                 :       1463 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     174                 :       1463 :   return mechanism->priv->credentials;
     175                 :            : }
     176                 :            : 
     177                 :            : /* ---------------------------------------------------------------------------------------------------- */
     178                 :            : 
     179                 :            : const gchar *
     180                 :       9729 : _g_dbus_auth_mechanism_get_name (GType mechanism_type)
     181                 :            : {
     182                 :            :   const gchar *name;
     183                 :            :   GDBusAuthMechanismClass *klass;
     184                 :            : 
     185                 :       9729 :   g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL);
     186                 :            : 
     187                 :       9729 :   klass = g_type_class_ref (mechanism_type);
     188                 :       9729 :   g_assert (klass != NULL);
     189                 :       9729 :   name = klass->get_name ();
     190                 :            :   //g_type_class_unref (klass);
     191                 :            : 
     192                 :       9729 :   return name;
     193                 :            : }
     194                 :            : 
     195                 :            : gint
     196                 :       4928 : _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
     197                 :            : {
     198                 :            :   gint priority;
     199                 :            :   GDBusAuthMechanismClass *klass;
     200                 :            : 
     201                 :       4928 :   g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0);
     202                 :            : 
     203                 :       4928 :   klass = g_type_class_ref (mechanism_type);
     204                 :       4928 :   g_assert (klass != NULL);
     205                 :       4928 :   priority = klass->get_priority ();
     206                 :            :   //g_type_class_unref (klass);
     207                 :            : 
     208                 :       4928 :   return priority;
     209                 :            : }
     210                 :            : 
     211                 :            : /* ---------------------------------------------------------------------------------------------------- */
     212                 :            : 
     213                 :            : gboolean
     214                 :       1513 : _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism)
     215                 :            : {
     216                 :       1513 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE);
     217                 :       1513 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism);
     218                 :            : }
     219                 :            : 
     220                 :            : gchar *
     221                 :          0 : _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
     222                 :            :                                     const gchar        *data,
     223                 :            :                                     gsize               data_len,
     224                 :            :                                     gsize              *out_data_len)
     225                 :            : {
     226                 :          0 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     227                 :          0 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len);
     228                 :            : }
     229                 :            : 
     230                 :            : 
     231                 :            : gchar *
     232                 :          0 : _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
     233                 :            :                                     const gchar        *data,
     234                 :            :                                     gsize               data_len,
     235                 :            :                                     gsize              *out_data_len)
     236                 :            : {
     237                 :          0 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     238                 :          0 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len);
     239                 :            : }
     240                 :            : 
     241                 :            : /* ---------------------------------------------------------------------------------------------------- */
     242                 :            : 
     243                 :            : GDBusAuthMechanismState
     244                 :        586 : _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism)
     245                 :            : {
     246                 :        586 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
     247                 :        586 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism);
     248                 :            : }
     249                 :            : 
     250                 :            : void
     251                 :        442 : _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism,
     252                 :            :                                         const gchar        *initial_response,
     253                 :            :                                         gsize               initial_response_len)
     254                 :            : {
     255                 :        442 :   g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
     256                 :        442 :   G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len);
     257                 :            : }
     258                 :            : 
     259                 :            : void
     260                 :         72 : _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
     261                 :            :                                             const gchar        *data,
     262                 :            :                                             gsize               data_len)
     263                 :            : {
     264                 :         72 :   g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
     265                 :         72 :   G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len);
     266                 :            : }
     267                 :            : 
     268                 :            : gchar *
     269                 :         72 : _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
     270                 :            :                                          gsize              *out_data_len)
     271                 :            : {
     272                 :         72 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     273                 :         72 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len);
     274                 :            : }
     275                 :            : 
     276                 :            : gchar *
     277                 :          0 : _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism)
     278                 :            : {
     279                 :          0 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     280                 :          0 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism);
     281                 :            : }
     282                 :            : 
     283                 :            : void
     284                 :          0 : _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism)
     285                 :            : {
     286                 :          0 :   g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
     287                 :          0 :   G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism);
     288                 :            : }
     289                 :            : 
     290                 :            : /* ---------------------------------------------------------------------------------------------------- */
     291                 :            : 
     292                 :            : GDBusAuthMechanismState
     293                 :       2377 : _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism)
     294                 :            : {
     295                 :       2377 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
     296                 :       2377 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism);
     297                 :            : }
     298                 :            : 
     299                 :            : gchar *
     300                 :       1307 : _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism   *mechanism,
     301                 :            :                                         GDBusConnectionFlags  conn_flags,
     302                 :            :                                         gsize                *out_initial_response_len)
     303                 :            : {
     304                 :       1307 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     305                 :       1307 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism,
     306                 :            :                                                                        conn_flags,
     307                 :            :                                                                        out_initial_response_len);
     308                 :            : }
     309                 :            : 
     310                 :            : void
     311                 :       1070 : _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
     312                 :            :                                             const gchar        *data,
     313                 :            :                                             gsize               data_len)
     314                 :            : {
     315                 :       1070 :   g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
     316                 :       1070 :   G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len);
     317                 :            : }
     318                 :            : 
     319                 :            : gchar *
     320                 :       1070 : _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
     321                 :            :                                          gsize              *out_data_len)
     322                 :            : {
     323                 :       1070 :   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
     324                 :       1070 :   return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len);
     325                 :            : }
     326                 :            : 
     327                 :            : void
     328                 :          0 : _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism)
     329                 :            : {
     330                 :          0 :   g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
     331                 :          0 :   G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism);
     332                 :            : }
     333                 :            : 
     334                 :            : /* ---------------------------------------------------------------------------------------------------- */

Generated by: LCOV version 1.14