LCOV - code coverage report
Current view: top level - glib/gio - gdummyproxyresolver.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 34 37 91.9 %
Date: 2024-04-23 05:16:05 Functions: 10 11 90.9 %
Branches: 9 12 75.0 %

           Branch data     Line data    Source code
       1                 :            : /* GIO - GLib Input, Output and Streaming Library
       2                 :            :  *
       3                 :            :  * Copyright (C) 2010 Collabora, Ltd.
       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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include "gdummyproxyresolver.h"
      26                 :            : 
      27                 :            : #include <glib.h>
      28                 :            : 
      29                 :            : #include "gasyncresult.h"
      30                 :            : #include "gcancellable.h"
      31                 :            : #include "gproxyresolver.h"
      32                 :            : #include "gtask.h"
      33                 :            : 
      34                 :            : #include "giomodule.h"
      35                 :            : #include "giomodule-priv.h"
      36                 :            : 
      37                 :            : struct _GDummyProxyResolver {
      38                 :            :   GObject parent_instance;
      39                 :            : };
      40                 :            : 
      41                 :            : static void g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface);
      42                 :            : 
      43                 :            : #define g_dummy_proxy_resolver_get_type _g_dummy_proxy_resolver_get_type
      44   [ +  +  +  -  :        234 : G_DEFINE_TYPE_WITH_CODE (GDummyProxyResolver, g_dummy_proxy_resolver, G_TYPE_OBJECT,
                   +  - ]
      45                 :            :                          G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER,
      46                 :            :                                                 g_dummy_proxy_resolver_iface_init)
      47                 :            :                          _g_io_modules_ensure_extension_points_registered ();
      48                 :            :                          g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
      49                 :            :                                                          g_define_type_id,
      50                 :            :                                                          "dummy",
      51                 :            :                                                          -100))
      52                 :            : 
      53                 :            : static void
      54                 :          0 : g_dummy_proxy_resolver_finalize (GObject *object)
      55                 :            : {
      56                 :            :   /* must chain up */
      57                 :          0 :   G_OBJECT_CLASS (g_dummy_proxy_resolver_parent_class)->finalize (object);
      58                 :          0 : }
      59                 :            : 
      60                 :            : static void
      61                 :          6 : g_dummy_proxy_resolver_init (GDummyProxyResolver *resolver)
      62                 :            : {
      63                 :          6 : }
      64                 :            : 
      65                 :            : static gboolean
      66                 :          6 : g_dummy_proxy_resolver_is_supported (GProxyResolver *resolver)
      67                 :            : {
      68                 :          6 :   return TRUE;
      69                 :            : }
      70                 :            : 
      71                 :            : static gchar **
      72                 :        427 : g_dummy_proxy_resolver_lookup (GProxyResolver  *resolver,
      73                 :            :                                const gchar     *uri,
      74                 :            :                                GCancellable    *cancellable,
      75                 :            :                                GError         **error)
      76                 :            : {
      77                 :            :   gchar **proxies;
      78                 :            : 
      79         [ +  + ]:        427 :   if (g_cancellable_set_error_if_cancelled (cancellable, error))
      80                 :          1 :     return NULL;
      81                 :            : 
      82                 :        426 :   proxies = g_new0 (gchar *, 2);
      83                 :        426 :   proxies[0] = g_strdup ("direct://");
      84                 :            : 
      85                 :        426 :   return proxies;
      86                 :            : }
      87                 :            : 
      88                 :            : static void
      89                 :        218 : g_dummy_proxy_resolver_lookup_async (GProxyResolver      *resolver,
      90                 :            :                                      const gchar         *uri,
      91                 :            :                                      GCancellable        *cancellable,
      92                 :            :                                      GAsyncReadyCallback  callback,
      93                 :            :                                      gpointer             user_data)
      94                 :            : {
      95                 :        218 :   GError *error = NULL;
      96                 :            :   GTask *task;
      97                 :            :   gchar **proxies;
      98                 :            : 
      99                 :        218 :   task = g_task_new (resolver, cancellable, callback, user_data);
     100         [ +  - ]:        218 :   g_task_set_source_tag (task, g_dummy_proxy_resolver_lookup_async);
     101                 :            : 
     102                 :        218 :   proxies = g_dummy_proxy_resolver_lookup (resolver, uri, cancellable, &error);
     103         [ +  + ]:        218 :   if (proxies)
     104                 :        217 :     g_task_return_pointer (task, proxies, (GDestroyNotify) g_strfreev);
     105                 :            :   else
     106                 :          1 :     g_task_return_error (task, error);
     107                 :        218 :   g_object_unref (task);
     108                 :        218 : }
     109                 :            : 
     110                 :            : static gchar **
     111                 :        218 : g_dummy_proxy_resolver_lookup_finish (GProxyResolver     *resolver,
     112                 :            :                                       GAsyncResult       *result,
     113                 :            :                                       GError            **error)
     114                 :            : {
     115                 :        218 :   g_return_val_if_fail (g_task_is_valid (result, resolver), NULL);
     116                 :            : 
     117                 :        218 :   return g_task_propagate_pointer (G_TASK (result), error);
     118                 :            : }
     119                 :            : 
     120                 :            : static void
     121                 :          6 : g_dummy_proxy_resolver_class_init (GDummyProxyResolverClass *resolver_class)
     122                 :            : {
     123                 :            :   GObjectClass *object_class;
     124                 :            :   
     125                 :          6 :   object_class = G_OBJECT_CLASS (resolver_class);
     126                 :          6 :   object_class->finalize = g_dummy_proxy_resolver_finalize;
     127                 :          6 : }
     128                 :            : 
     129                 :            : static void
     130                 :          6 : g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface)
     131                 :            : {
     132                 :          6 :   iface->is_supported = g_dummy_proxy_resolver_is_supported;
     133                 :          6 :   iface->lookup = g_dummy_proxy_resolver_lookup;
     134                 :          6 :   iface->lookup_async = g_dummy_proxy_resolver_lookup_async;
     135                 :          6 :   iface->lookup_finish = g_dummy_proxy_resolver_lookup_finish;
     136                 :          6 : }

Generated by: LCOV version 1.14