Blame src/progress.c

Packit Service 672cf4
/* progress.c -  status handler for progress status
Packit Service 0ef63b
 * Copyright (C) 2000 Werner Koch (dd9jn)
Packit Service 0ef63b
 * Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * This file is part of GPGME.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is free software; you can redistribute it and/or modify it
Packit Service 0ef63b
 * under the terms of the GNU Lesser General Public License as
Packit Service 0ef63b
 * published by the Free Software Foundation; either version 2.1 of
Packit Service 0ef63b
 * the License, or (at your option) any later version.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is distributed in the hope that it will be useful, but
Packit Service 0ef63b
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0ef63b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 0ef63b
 * Lesser General Public License for more details.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * You should have received a copy of the GNU Lesser General Public
Packit Service 0ef63b
 * License along with this program; if not, see <https://gnu.org/licenses/>.
Packit Service 0ef63b
 * SPDX-License-Identifier: LGPL-2.1-or-later
Packit Service 0ef63b
 */
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
#include <config.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
#include <stdlib.h>
Packit Service 672cf4
#include <string.h>
Packit Service 672cf4
#include <errno.h>
Packit Service 672cf4
Packit Service 672cf4
#include "util.h"
Packit Service 672cf4
#include "context.h"
Packit Service 672cf4
#include "debug.h"
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
/* The status handler for progress status lines which also monitors
Packit Service 672cf4
 * the PINENTRY_LAUNCHED status.  */
Packit Service 672cf4
gpgme_error_t
Packit Service 672cf4
_gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
Packit Service 672cf4
				char *args)
Packit Service 672cf4
{
Packit Service 672cf4
  gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
Packit Service 672cf4
  char *p;
Packit Service 672cf4
  char *args_cpy;
Packit Service 672cf4
  int type = 0;
Packit Service 672cf4
  int current = 0;
Packit Service 672cf4
  int total = 0;
Packit Service 672cf4
Packit Service 672cf4
  if (code == GPGME_STATUS_PINENTRY_LAUNCHED)
Packit Service 672cf4
    {
Packit Service 672cf4
      ctx->redraw_suggested = 1;
Packit Service 672cf4
      return 0;
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
  if (code != GPGME_STATUS_PROGRESS || !*args || !ctx->progress_cb)
Packit Service 672cf4
    return 0;
Packit Service 672cf4
Packit Service 672cf4
  args_cpy = strdup (args);
Packit Service 672cf4
  if (!args_cpy)
Packit Service 672cf4
    return gpg_error_from_syserror ();
Packit Service 672cf4
Packit Service 672cf4
  p = strchr (args_cpy, ' ');
Packit Service 672cf4
  if (p)
Packit Service 672cf4
    {
Packit Service 672cf4
      *p++ = 0;
Packit Service 672cf4
      if (*p)
Packit Service 672cf4
	{
Packit Service 672cf4
	  type = *(unsigned char *)p;
Packit Service 672cf4
	  p = strchr (p+1, ' ');
Packit Service 672cf4
	  if (p)
Packit Service 672cf4
	    {
Packit Service 672cf4
	      *p++ = 0;
Packit Service 672cf4
	      if (*p)
Packit Service 672cf4
		{
Packit Service 672cf4
		  current = atoi (p);
Packit Service 672cf4
		  p = strchr (p+1, ' ');
Packit Service 672cf4
		  if (p)
Packit Service 672cf4
		    {
Packit Service 672cf4
		      *p++ = 0;
Packit Service 672cf4
		      total = atoi (p);
Packit Service 672cf4
		    }
Packit Service 672cf4
		}
Packit Service 672cf4
	    }
Packit Service 672cf4
	}
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
  if (type != 'X')
Packit Service 672cf4
    ctx->progress_cb (ctx->progress_cb_value, args_cpy, type, current, total);
Packit Service 672cf4
Packit Service 672cf4
  free (args_cpy);
Packit Service 672cf4
  return 0;
Packit Service 672cf4
}