Rework status table to be less dynamically generated.
[gpgme.git] / src / util.h
1 /* util.h
2    Copyright (C) 2000 Werner Koch (dd9jn)
3    Copyright (C) 2001, 2002, 2003, 2004, 2005 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 #ifndef UTIL_H
23 #define UTIL_H
24
25 #ifdef HAVE_W32_SYSTEM
26 # ifdef HAVE_W32CE_SYSTEM
27 #  include "w32-ce.h"
28 # else
29 #  include "windows.h"
30 # endif
31 #endif
32
33 /* For pid_t.  */
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37 /* We must see the symbol ttyname_r before a redefinition. */
38 #ifdef HAVE_UNISTD_H
39 # include <unistd.h>
40 #endif
41
42 #include "gpgme.h"
43
44 \f
45 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
46
47 \f
48 /*-- {posix,w32}-util.c --*/
49 const char *_gpgme_get_gpg_path (void);
50 const char *_gpgme_get_gpgsm_path (void);
51 const char *_gpgme_get_gpgconf_path (void);
52 const char *_gpgme_get_g13_path (void);
53 const char *_gpgme_get_uiserver_socket_path (void);
54
55 int _gpgme_get_conf_int (const char *key, int *value);
56 void _gpgme_allow_set_foreground_window (pid_t pid);
57
58 /*-- dirinfo.c --*/
59 const char *_gpgme_get_default_homedir (void);
60 const char *_gpgme_get_default_agent_socket (void);
61
62
63 \f
64 /*-- replacement functions in <funcname>.c --*/
65 #ifdef HAVE_CONFIG_H
66
67 #ifndef HAVE_STPCPY
68 static _GPGME_INLINE char *
69 _gpgme_stpcpy (char *a, const char *b)
70 {
71   while (*b)
72     *a++ = *b++;
73   *a = 0;
74   return a;
75 }
76 #define stpcpy(a,b) _gpgme_stpcpy ((a), (b))
77 #endif /*!HAVE_STPCPY*/
78
79 #if !HAVE_VASPRINTF
80 #include <stdarg.h>
81 int vasprintf (char **result, const char *format, va_list args);
82 int asprintf (char **result, const char *format, ...);
83 #endif
84
85 #if REPLACE_TTYNAME_R
86 int _gpgme_ttyname_r (int fd, char *buf, size_t buflen);
87 #undef  ttyname_r
88 #define ttyname_r(a,b,c) _gpgme_ttyname_r ((a), (b), (c))
89 #endif
90
91 #endif /*HAVE_CONFIG_H*/
92
93 \f
94 /*-- conversion.c --*/
95 /* Convert two hexadecimal digits from STR to the value they
96    represent.  Returns -1 if one of the characters is not a
97    hexadecimal digit.  */
98 int _gpgme_hextobyte (const char *str);
99
100 /* Decode the C formatted string SRC and store the result in the
101    buffer *DESTP which is LEN bytes long.  If LEN is zero, then a
102    large enough buffer is allocated with malloc and *DESTP is set to
103    the result.  Currently, LEN is only used to specify if allocation
104    is desired or not, the caller is expected to make sure that *DESTP
105    is large enough if LEN is not zero.  */
106 gpgme_error_t _gpgme_decode_c_string (const char *src, char **destp,
107                                       size_t len);
108
109 /* Decode the percent escaped string SRC and store the result in the
110    buffer *DESTP which is LEN bytes long.  If LEN is zero, then a
111    large enough buffer is allocated with malloc and *DESTP is set to
112    the result.  Currently, LEN is only used to specify if allocation
113    is desired or not, the caller is expected to make sure that *DESTP
114    is large enough if LEN is not zero.  If BINARY is 1, then '\0'
115    characters are allowed in the output.  */
116 gpgme_error_t _gpgme_decode_percent_string (const char *src, char **destp,
117                                             size_t len, int binary);
118
119 gpgme_error_t _gpgme_encode_percent_string (const char *src, char **destp,
120                                             size_t len);
121
122
123 /* Parse the string TIMESTAMP into a time_t.  The string may either be
124    seconds since Epoch or in the ISO 8601 format like
125    "20390815T143012".  Returns 0 for an empty string or seconds since
126    Epoch. Leading spaces are skipped. If ENDP is not NULL, it will
127    point to the next non-parsed character in TIMESTRING. */
128 time_t _gpgme_parse_timestamp (const char *timestamp, char **endp);
129
130
131 gpgme_error_t _gpgme_map_gnupg_error (char *err);
132
133 \f
134 /* Retrieve the environment variable NAME and return a copy of it in a
135    malloc()'ed buffer in *VALUE.  If the environment variable is not
136    set, return NULL in *VALUE.  */
137 gpgme_error_t _gpgme_getenv (const char *name, char **value);
138
139 \f
140 /*-- status-table.c --*/
141 /* Convert a status string to a status code.  */
142 void _gpgme_status_init (void);
143 gpgme_status_code_t _gpgme_parse_status (const char *name);
144
145 \f
146 #ifdef HAVE_W32_SYSTEM
147 int _gpgme_mkstemp (int *fd, char **name);
148 const char *_gpgme_get_w32spawn_path (void);
149 #endif /*HAVE_W32_SYSTEM*/
150 #ifdef HAVE_W32CE_SYSTEM
151 char *_gpgme_w32ce_get_debug_envvar (void);
152 #endif /*HAVE_W32CE_SYSTEM*/
153
154 /*--  Error codes not yet available in current gpg-error.h.   --*/
155 #ifndef GPG_ERR_UNFINISHED
156 #define GPG_ERR_UNFINISHED 199
157 #endif
158 #ifndef GPG_ERR_NOT_OPERATIONAL
159 #define GPG_ERR_NOT_OPERATIONAL 176
160 #endif
161 #ifndef GPG_ERR_MISSING_ISSUER_CERT
162 #define GPG_ERR_MISSING_ISSUER_CERT 185
163 #endif
164
165 \f
166 #ifdef ENABLE_ASSUAN
167 #include <assuan.h>
168 /* System hooks for assuan integration.  */
169 extern struct assuan_system_hooks _gpgme_assuan_system_hooks;
170 extern struct assuan_malloc_hooks _gpgme_assuan_malloc_hooks;
171 int _gpgme_assuan_log_cb (assuan_context_t ctx, void *hook,
172                           unsigned int cat, const char *msg);
173 #endif
174
175 #endif /* UTIL_H */