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