LCOV - code coverage report
Current view: top level - src - progress.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 31 96.8 %
Date: 2018-11-15 08:49:49 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* progress.c -  status handler for progress status
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             : 
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             : 
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    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 Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : #include <stdlib.h>
      26             : #include <string.h>
      27             : #include <errno.h>
      28             : 
      29             : #include "util.h"
      30             : #include "context.h"
      31             : #include "debug.h"
      32             : 
      33             : 
      34             : /* The status handler for progress status lines which also monitors
      35             :  * the PINENTRY_LAUNCHED status.  */
      36             : gpgme_error_t
      37        4980 : _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
      38             :                                 char *args)
      39             : {
      40        4980 :   gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
      41             :   char *p;
      42             :   char *args_cpy;
      43        4980 :   int type = 0;
      44        4980 :   int current = 0;
      45        4980 :   int total = 0;
      46             : 
      47        4980 :   if (code == GPGME_STATUS_PINENTRY_LAUNCHED)
      48             :     {
      49          20 :       ctx->redraw_suggested = 1;
      50          20 :       return 0;
      51             :     }
      52             : 
      53        4960 :   if (code != GPGME_STATUS_PROGRESS || !*args || !ctx->progress_cb)
      54        4822 :     return 0;
      55             : 
      56         138 :   args_cpy = strdup (args);
      57         138 :   if (!args_cpy)
      58           0 :     return gpg_error_from_syserror ();
      59             : 
      60         138 :   p = strchr (args_cpy, ' ');
      61         138 :   if (p)
      62             :     {
      63         138 :       *p++ = 0;
      64         138 :       if (*p)
      65             :         {
      66         138 :           type = *(unsigned char *)p;
      67         138 :           p = strchr (p+1, ' ');
      68         138 :           if (p)
      69             :             {
      70         138 :               *p++ = 0;
      71         138 :               if (*p)
      72             :                 {
      73         138 :                   current = atoi (p);
      74         138 :                   p = strchr (p+1, ' ');
      75         138 :                   if (p)
      76             :                     {
      77         138 :                       *p++ = 0;
      78         138 :                       total = atoi (p);
      79             :                     }
      80             :                 }
      81             :             }
      82             :         }
      83             :     }
      84             : 
      85         138 :   if (type != 'X')
      86         126 :     ctx->progress_cb (ctx->progress_cb_value, args_cpy, type, current, total);
      87             : 
      88         138 :   free (args_cpy);
      89         138 :   return 0;
      90             : }

Generated by: LCOV version 1.13