LCOV - code coverage report
Current view: top level - src - queryswdb.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 36 0.0 %
Date: 2018-11-15 08:49:49 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* queryswdb.c - Access to the SWDB file
       2             :  * Copyright (C) 2016 g10 Code GmbH
       3             :  *
       4             :  * This file is part of GPGME.
       5             :  *
       6             :  * GPGME is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU Lesser General Public License as
       8             :  * published by the Free Software Foundation; either version 2.1 of
       9             :  * the License, or (at your option) any later version.
      10             :  *
      11             :  * GPGME is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with this program; if not, see <https://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #if HAVE_CONFIG_H
      21             : #include <config.h>
      22             : #endif
      23             : #include <stdlib.h>
      24             : #include <assert.h>
      25             : 
      26             : #include "gpgme.h"
      27             : #include "debug.h"
      28             : #include "context.h"
      29             : #include "ops.h"
      30             : 
      31             : 
      32             : typedef struct
      33             : {
      34             :   struct _gpgme_op_query_swdb_result result;
      35             : 
      36             : } *op_data_t;
      37             : 
      38             : 
      39             : 
      40             : static void
      41           0 : release_op_data (void *hook)
      42             : {
      43           0 :   op_data_t opd = (op_data_t) hook;
      44           0 :   gpgme_query_swdb_result_t result = &opd->result;
      45             : 
      46           0 :   assert (!result->next);
      47           0 :   free (result->name);
      48           0 :   free (result->iversion);
      49           0 :   free (result->version);
      50           0 : }
      51             : 
      52             : 
      53             : gpgme_query_swdb_result_t
      54           0 : gpgme_op_query_swdb_result (gpgme_ctx_t ctx)
      55             : {
      56             :   void *hook;
      57             :   op_data_t opd;
      58             :   gpgme_error_t err;
      59             : 
      60           0 :   TRACE_BEG (DEBUG_CTX, "gpgme_op_query_swdb_result", ctx);
      61             : 
      62           0 :   err = _gpgme_op_data_lookup (ctx, OPDATA_QUERY_SWDB, &hook, -1, NULL);
      63           0 :   opd = hook;
      64             : 
      65           0 :   if (err || !opd)
      66             :     {
      67           0 :       TRACE_SUC0 ("result=(null)");
      68           0 :       return NULL;
      69             :     }
      70             : 
      71           0 :   TRACE_SUC1 ("result=%p", &opd->result);
      72           0 :   return &opd->result;
      73             : }
      74             : 
      75             : 
      76             : 
      77             : /* Query the swdb for software package NAME and check against the
      78             :  * installed version given by IVERSION.  If IVERSION is NULL a check
      79             :  * is only done if GPGME can figure out the version by itself
      80             :  * (e.g. for "gpgme" or "gnupg").  RESERVED should be 0.
      81             :  *
      82             :  * Note that we only implemented the synchronous variant of this
      83             :  * function but the API is prepared for an asynchronous variant.
      84             :  */
      85             : gpgme_error_t
      86           0 : gpgme_op_query_swdb (gpgme_ctx_t ctx, const char *name, const char *iversion,
      87             :                      unsigned int reserved)
      88             : {
      89             :   gpgme_error_t err;
      90             :   void *hook;
      91             :   op_data_t opd;
      92             : 
      93           0 :   TRACE_BEG2 (DEBUG_CTX, "gpgme_op_query_swdb", ctx,
      94             :               "name=%s, iversion=%a", name, iversion);
      95             : 
      96           0 :   if (!ctx || reserved)
      97           0 :     return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
      98             : 
      99           0 :   if (ctx->protocol != GPGME_PROTOCOL_GPGCONF)
     100           0 :     return TRACE_ERR (gpg_error (GPG_ERR_UNSUPPORTED_PROTOCOL));
     101             : 
     102           0 :   if (!name)
     103           0 :     name = "gpgme";
     104             : 
     105           0 :   if (!iversion && !strcmp (name, "gpgme"))
     106           0 :     iversion = VERSION;
     107             : 
     108           0 :   err = _gpgme_op_reset (ctx, 1);
     109           0 :   if (err)
     110           0 :     return err;
     111             : 
     112           0 :   err = _gpgme_op_data_lookup (ctx, OPDATA_QUERY_SWDB, &hook,
     113             :                                sizeof (*opd), release_op_data);
     114           0 :   opd = hook;
     115           0 :   if (err)
     116           0 :     return TRACE_ERR (err);
     117             : 
     118           0 :   err = _gpgme_engine_op_query_swdb (ctx->engine, name, iversion,
     119             :                                      &opd->result);
     120           0 :   return TRACE_ERR (err);
     121             : }

Generated by: LCOV version 1.13