Blame src/progress.c

Packit Service 672cf4
/* progress.c -  status handler for progress status
Packit Service 6c01f9
   Copyright (C) 2000 Werner Koch (dd9jn)
Packit Service 6c01f9
   Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
Packit Service 6c01f9
Packit Service 6c01f9
   This file is part of GPGME.
Packit Service 6c01f9
Packit Service 6c01f9
   GPGME is free software; you can redistribute it and/or modify it
Packit Service 6c01f9
   under the terms of the GNU Lesser General Public License as
Packit Service 6c01f9
   published by the Free Software Foundation; either version 2.1 of
Packit Service 6c01f9
   the License, or (at your option) any later version.
Packit Service 6c01f9
Packit Service 6c01f9
   GPGME is distributed in the hope that it will be useful, but
Packit Service 6c01f9
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 6c01f9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 6c01f9
   Lesser General Public License for more details.
Packit Service 6c01f9
Packit Service 6c01f9
   You should have received a copy of the GNU Lesser General Public
Packit Service 6c01f9
   License along with this program; if not, write to the Free Software
Packit Service 6c01f9
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
Packit Service 6c01f9
   02111-1307, USA.  */
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
}