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