Blame src/util.h

Packit Service 672cf4
/* util.h
Packit Service 672cf4
   Copyright (C) 2000 Werner Koch (dd9jn)
Packit Service 672cf4
   Copyright (C) 2001, 2002, 2003, 2004, 2005 g10 Code GmbH
Packit Service 672cf4
Packit Service 672cf4
   This file is part of GPGME.
Packit Service 672cf4
Packit Service 672cf4
   GPGME is free software; you can redistribute it and/or modify it
Packit Service 672cf4
   under the terms of the GNU Lesser General Public License as
Packit Service 672cf4
   published by the Free Software Foundation; either version 2.1 of
Packit Service 672cf4
   the License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
   GPGME is distributed in the hope that it will be useful, but
Packit Service 672cf4
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 672cf4
   Lesser General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
   You should have received a copy of the GNU Lesser General Public
Packit Service 672cf4
   License along with this program; if not, write to the Free Software
Packit Service 672cf4
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
Packit Service 672cf4
   02111-1307, USA.  */
Packit Service 672cf4
Packit Service 672cf4
#ifndef UTIL_H
Packit Service 672cf4
#define UTIL_H
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 6c01f9
# ifdef HAVE_W32CE_SYSTEM
Packit Service 6c01f9
#  include "w32-ce.h"
Packit Service 6c01f9
# else
Packit Service 6c01f9
#  include "winsock2.h"
Packit Service 6c01f9
#  include "windows.h"
Packit Service 6c01f9
# endif
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
/* For pid_t.  */
Packit Service 672cf4
#ifdef HAVE_SYS_TYPES_H
Packit Service 672cf4
# include <sys/types.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
/* We must see the symbol ttyname_r before a redefinition. */
Packit Service 672cf4
#ifdef HAVE_UNISTD_H
Packit Service 672cf4
# include <unistd.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "gpgme.h"
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
Packit Service 672cf4
Packit Service 672cf4
#if GPG_ERROR_VERSION_NUMBER < 0x011900 /* 1.25 */
Packit Service 672cf4
# define GPG_ERR_ENGINE_TOO_OLD 300
Packit Service 672cf4
# define GPG_ERR_TOO_OLD        308
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#ifndef GPGRT_ATTR_SENTINEL
Packit Service 672cf4
# define GPGRT_ATTR_SENTINEL(a)  /* */
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/*-- {posix,w32}-util.c --*/
Packit Service 672cf4
int _gpgme_get_conf_int (const char *key, int *value);
Packit Service 672cf4
void _gpgme_allow_set_foreground_window (pid_t pid);
Packit Service 672cf4
Packit Service 672cf4
/*-- dirinfo.c --*/
Packit Service 672cf4
void _gpgme_dirinfo_disable_gpgconf (void);
Packit Service 672cf4
Packit Service 672cf4
const char *_gpgme_get_default_homedir (void);
Packit Service 672cf4
const char *_gpgme_get_default_agent_socket (void);
Packit Service 672cf4
const char *_gpgme_get_default_gpg_name (void);
Packit Service 672cf4
const char *_gpgme_get_default_gpgsm_name (void);
Packit Service 672cf4
const char *_gpgme_get_default_g13_name (void);
Packit Service 672cf4
const char *_gpgme_get_default_gpgconf_name (void);
Packit Service 672cf4
const char *_gpgme_get_default_uisrv_socket (void);
Packit Service 672cf4
int _gpgme_in_gpg_one_mode (void);
Packit Service 672cf4
Packit Service 672cf4
const char *_gpgme_get_basename (const char *name);
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/*-- replacement functions in <funcname>.c --*/
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
Packit Service 672cf4
#ifndef HAVE_STPCPY
Packit Service 672cf4
static _GPGME_INLINE char *
Packit Service 672cf4
_gpgme_stpcpy (char *a, const char *b)
Packit Service 672cf4
{
Packit Service 672cf4
  while (*b)
Packit Service 672cf4
    *a++ = *b++;
Packit Service 672cf4
  *a = 0;
Packit Service 672cf4
  return a;
Packit Service 672cf4
}
Packit Service 672cf4
#define stpcpy(a,b) _gpgme_stpcpy ((a), (b))
Packit Service 672cf4
#endif /*!HAVE_STPCPY*/
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
/* Due to a bug in mingw32's snprintf related to the 'l' modifier and
Packit Service 672cf4
   for increased portability we use our snprintf on all systems. */
Packit Service 672cf4
#undef snprintf
Packit Service 672cf4
#define snprintf gpgrt_snprintf
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
#if REPLACE_TTYNAME_R
Packit Service 672cf4
int _gpgme_ttyname_r (int fd, char *buf, size_t buflen);
Packit Service 672cf4
#undef  ttyname_r
Packit Service 672cf4
#define ttyname_r(a,b,c) _gpgme_ttyname_r ((a), (b), (c))
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#endif /*HAVE_CONFIG_H*/
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/*-- conversion.c --*/
Packit Service 672cf4
Packit Service 672cf4
/* Concatenate the string S1 with all the following strings up to a
Packit Service 672cf4
   NULL.  Returns a malloced buffer with the new string or NULL on a
Packit Service 672cf4
   malloc error or if too many arguments are given.  */
Packit Service 672cf4
char *_gpgme_strconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
Packit Service 672cf4
Packit Service 672cf4
/* Convert two hexadecimal digits from STR to the value they
Packit Service 672cf4
   represent.  Returns -1 if one of the characters is not a
Packit Service 672cf4
   hexadecimal digit.  */
Packit Service 672cf4
int _gpgme_hextobyte (const char *str);
Packit Service 672cf4
Packit Service 672cf4
/* Decode the C formatted string SRC and store the result in the
Packit Service 672cf4
   buffer *DESTP which is LEN bytes long.  If LEN is zero, then a
Packit Service 672cf4
   large enough buffer is allocated with malloc and *DESTP is set to
Packit Service 672cf4
   the result.  Currently, LEN is only used to specify if allocation
Packit Service 672cf4
   is desired or not, the caller is expected to make sure that *DESTP
Packit Service 672cf4
   is large enough if LEN is not zero.  */
Packit Service 672cf4
gpgme_error_t _gpgme_decode_c_string (const char *src, char **destp,
Packit Service 672cf4
				      size_t len);
Packit Service 672cf4
Packit Service 672cf4
/* Decode the percent escaped string SRC and store the result in the
Packit Service 672cf4
   buffer *DESTP which is LEN bytes long.  If LEN is zero, then a
Packit Service 672cf4
   large enough buffer is allocated with malloc and *DESTP is set to
Packit Service 672cf4
   the result.  Currently, LEN is only used to specify if allocation
Packit Service 672cf4
   is desired or not, the caller is expected to make sure that *DESTP
Packit Service 672cf4
   is large enough if LEN is not zero.  If BINARY is 1, then '\0'
Packit Service 672cf4
   characters are allowed in the output.  */
Packit Service 672cf4
gpgme_error_t _gpgme_decode_percent_string (const char *src, char **destp,
Packit Service 672cf4
					    size_t len, int binary);
Packit Service 672cf4
Packit Service 672cf4
gpgme_error_t _gpgme_encode_percent_string (const char *src, char **destp,
Packit Service 672cf4
					    size_t len);
Packit Service 672cf4
Packit Service 672cf4
/* Split a string into space delimited fields and remove leading and
Packit Service 672cf4
 * trailing spaces from each field.  A pointer to the each field is
Packit Service 672cf4
 * stored in ARRAY.  Stop splitting at ARRAYSIZE fields.  The function
Packit Service 672cf4
 * modifies STRING.  The number of parsed fields is returned.  */
Packit Service 672cf4
int _gpgme_split_fields (char *string, char **array, int arraysize);
Packit Service 672cf4
Packit Service 672cf4
/* Convert the field STRING into an unsigned long value.  Check for
Packit Service 672cf4
 * trailing garbage.  */
Packit Service 672cf4
gpgme_error_t _gpgme_strtoul_field (const char *string, unsigned long *result);
Packit Service 672cf4
Packit Service 672cf4
/* Convert STRING into an offset value similar to atoi().  */
Packit Service 672cf4
gpgme_off_t _gpgme_string_to_off (const char *string);
Packit Service 672cf4
Packit Service 672cf4
/* Parse the string TIMESTAMP into a time_t.  The string may either be
Packit Service 672cf4
   seconds since Epoch or in the ISO 8601 format like
Packit Service 672cf4
   "20390815T143012".  Returns 0 for an empty string or seconds since
Packit Service 672cf4
   Epoch. Leading spaces are skipped. If ENDP is not NULL, it will
Packit Service 672cf4
   point to the next non-parsed character in TIMESTRING. */
Packit Service 672cf4
time_t _gpgme_parse_timestamp (const char *timestamp, char **endp);
Packit Service 672cf4
Packit Service 672cf4
/* Variant of _gpgme_parse_timestamp to return an unsigned long or 0
Packit Service 672cf4
 * on error or missing timestamp.  */
Packit Service 672cf4
unsigned long _gpgme_parse_timestamp_ul (const char *timestamp);
Packit Service 672cf4
Packit Service 6c01f9
gpgme_error_t _gpgme_map_gnupg_error (char *err);
Packit Service 672cf4
Packit Service 6c01f9
int _gpgme_map_pk_algo (int algo, gpgme_protocol_t protocol);
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/*-- b64dec.c --*/
Packit Service 672cf4
Packit Service 672cf4
struct b64state
Packit Service 672cf4
{
Packit Service 672cf4
  int idx;
Packit Service 672cf4
  int quad_count;
Packit Service 672cf4
  char *title;
Packit Service 672cf4
  unsigned char radbuf[4];
Packit Service 672cf4
  int stop_seen:1;
Packit Service 672cf4
  int invalid_encoding:1;
Packit Service 672cf4
  gpg_error_t lasterr;
Packit Service 672cf4
};
Packit Service 672cf4
Packit Service 672cf4
gpg_error_t _gpgme_b64dec_start (struct b64state *state, const char *title);
Packit Service 672cf4
gpg_error_t _gpgme_b64dec_proc (struct b64state *state,
Packit Service 672cf4
                                void *buffer, size_t length, size_t *r_nbytes);
Packit Service 672cf4
gpg_error_t _gpgme_b64dec_finish (struct b64state *state);
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/* Retrieve the environment variable NAME and return a copy of it in a
Packit Service 672cf4
   malloc()'ed buffer in *VALUE.  If the environment variable is not
Packit Service 672cf4
   set, return NULL in *VALUE.  */
Packit Service 672cf4
gpgme_error_t _gpgme_getenv (const char *name, char **value);
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
/*-- status-table.c --*/
Packit Service 672cf4
/* Convert a status string to a status code.  */
Packit Service 672cf4
void _gpgme_status_init (void);
Packit Service 672cf4
gpgme_status_code_t _gpgme_parse_status (const char *name);
Packit Service 672cf4
const char *_gpgme_status_to_string (gpgme_status_code_t code);
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
int _gpgme_mkstemp (int *fd, char **name);
Packit Service 672cf4
const char *_gpgme_get_w32spawn_path (void);
Packit Service 672cf4
#endif /*HAVE_W32_SYSTEM*/
Packit Service 6c01f9
#ifdef HAVE_W32CE_SYSTEM
Packit Service 6c01f9
char *_gpgme_w32ce_get_debug_envvar (void);
Packit Service 6c01f9
#endif /*HAVE_W32CE_SYSTEM*/
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
#include <assuan.h>
Packit Service 672cf4
/* System hooks for assuan integration.  */
Packit Service 672cf4
extern struct assuan_system_hooks _gpgme_assuan_system_hooks;
Packit Service 672cf4
extern struct assuan_malloc_hooks _gpgme_assuan_malloc_hooks;
Packit Service 672cf4
int _gpgme_assuan_log_cb (assuan_context_t ctx, void *hook,
Packit Service 672cf4
			  unsigned int cat, const char *msg);
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
Packit Service 672cf4
/* Parse the compliance field.  */
Packit Service 672cf4
#define PARSE_COMPLIANCE_FLAGS(flags, result)				\
Packit Service 672cf4
  do {									\
Packit Service 672cf4
    char *comp_p, *comp_endp;						\
Packit Service 672cf4
    unsigned long comp_ul;						\
Packit Service 672cf4
									\
Packit Service 672cf4
    for (comp_p = (flags);						\
Packit Service 672cf4
	 comp_p								\
Packit Service 672cf4
	   && (comp_ul = strtoul (comp_p, &comp_endp, 10))		\
Packit Service 672cf4
	   && comp_p != comp_endp;					\
Packit Service 672cf4
	 comp_p = comp_endp)						\
Packit Service 672cf4
      {									\
Packit Service 672cf4
	switch (comp_ul)						\
Packit Service 672cf4
	  {								\
Packit Service 672cf4
	  case 23: (result)->is_de_vs = 1; break;			\
Packit Service 672cf4
	  }								\
Packit Service 672cf4
      }									\
Packit Service 672cf4
  } while (0)
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
#endif /* UTIL_H */