diff options
Diffstat (limited to 'src')
38 files changed, 386 insertions, 267 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index fe850956..fbe92be0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -4,6 +4,87 @@ function is not used on Windows CE, and the callers were not adjusted). +2011-01-21 Marcus Brinkmann <[email protected]> + + * engine-gpgconf.c (_gpgme_conf_opt_change): Fix the case that is + not self-assignment. + +2010-12-08 Werner Koch <[email protected]> + + * gpgme-tool.c (strcpy_escaped_plus): New. + (DIM, xtoi_1, xtoi_2): New. + (cmd_keylist): Allow for multiple patterns. + +2010-11-23 Marcus Brinkmann <[email protected]> + + * w32-io.c (create_reader, create_writer): Use small stack size on + Windows CE. + +2010-11-23 Marcus Brinkmann <[email protected]> + + * gpgme.h.in (gpgme_conf_arg_new): Make VALUE arg const void *. + * gpgconf.c (_gpgme_conf_arg_new): Likewise. + (gpgme_conf_arg_new): Likewise. + * engine-gpgconf.c (_gpgme_conf_arg_new): Likewise. + (gpgconf_write): Remove debug hack. + +2010-11-19 Marcus Brinkmann <[email protected]> + + * engine-gpgconf.c (_gpgme_conf_opt_change): Support + self-assignment. Requested by Marc Mutz. + +2010-11-17 Marcus Brinkmann <[email protected]> + + * vasprintf.c (int_vasprintf) [HAVE_W32CE_SYSTEM]: Just use a + fixed size buffer, as va_copy is not easy to fake. + +2010-11-15 Marcus Brinkmann <[email protected]> + + * w32-ce.h (strcasecmp, strdup) [_MSC_VER]: Define. + * genkey.c, passphrase.c: Include util.h. + + * w32-util.c (_gpgme_w32ce_get_debug_envvar): Fix return value. + +2010-11-15 Werner Koch <[email protected]> + + * data-compat.c (gpgme_data_new_from_filepart) + (gpgme_data_new_from_file) [W32CE && _MSC_VER]: Return not + GPG_ERR_NOT_IMPLEMENTED. + + * w32-ce.h (HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, _IOLBF) + (abort) [_MSC_VER]: Provide these macros. + + * ath.h [W32CE && _MSC_VER]: Include winsock2.h. + + * ath.c (ath_read, ath_write) [W32CE && _MSC_VER]: Do not call + non-available functions. + +2010-11-04 Werner Koch <[email protected]> + + * w32-ce.h [_MSC_VER && W32CE]: Undef leave. + * export.c: Include util.h so that we get the above undef. + + * memrchr.c: Remove. Used to be a replacement function required + by the formerly included assuan code. + +2010-11-03 Werner Koch <[email protected]> + + * debug.c (_gpgme_debug) [W32CE]: Replace locatime by GetLocalTime. + + * signers.c (gpgme_signers_clear): Remove useless return. + Reported by Patrick Spendrin. + + * w32-util.c: s/__inline__/GPG_ERR_INLINE/ + + * setenv.c: Include string.h due to our strerror replacement. + + * w32-ce.h (access, bsearch): New macros. + * w32-ce.c (_gpgme_wince_access): New. + (RegQueryValueExA): Change DATA to a void*. + (_gpgme_wince_bsearch): New. Taken from glibc 2.6. + + Guard include of sys/stat.h and sys/types.h. + 2010-11-02 Werner Koch <[email protected]> * data-fd.c (read, write, lseek) [W32CE && ! __MINGW32CE__]: New. @@ -33,7 +33,9 @@ # include <sys/time.h> # endif #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #ifndef HAVE_W32_SYSTEM #include <sys/wait.h> #endif @@ -60,7 +62,6 @@ ath_self (void) } #else # ifdef __linux -#include <sys/types.h> #include <sys/syscall.h> uintptr_t ath_self (void) @@ -127,14 +128,22 @@ ath_mutex_unlock (ath_mutex_t *lock) ssize_t ath_read (int fd, void *buf, size_t nbytes) { +#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) + return -1; /* Not supported. */ +#else return read (fd, buf, nbytes); +#endif } ssize_t ath_write (int fd, const void *buf, size_t nbytes) { +#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) + return -1; /* Not supported. */ +#else return write (fd, buf, nbytes); +#endif } @@ -28,6 +28,9 @@ /* fixme: Check how we did it in libgcrypt. */ struct msghdr { int dummy; }; typedef int socklen_t; +# if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) +# include <winsock2.h> +# endif # include <windows.h> # include <io.h> @@ -40,7 +43,9 @@ # include <sys/time.h> # endif # endif -# include <sys/types.h> +# ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +# endif # include <sys/socket.h> #endif /*!HAVE_W32_SYSTEM*/ diff --git a/src/conversion.c b/src/conversion.c index 9d8f403e..e6282faa 100644 --- a/src/conversion.c +++ b/src/conversion.c @@ -25,8 +25,10 @@ #include <stdlib.h> #include <string.h> -/* Solaris 8 needs sys/types.h before time.h. */ -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H + /* Solaris 8 needs sys/types.h before time.h. */ +# include <sys/types.h> +#endif #include <time.h> #include <errno.h> diff --git a/src/data-compat.c b/src/data-compat.c index 0843ffd4..39c743ef 100644 --- a/src/data-compat.c +++ b/src/data-compat.c @@ -26,7 +26,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/stat.h> +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif #include <stdlib.h> #include "data.h" @@ -41,6 +43,9 @@ gpgme_error_t gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, FILE *stream, off_t offset, size_t length) { +#if defined (HAVE_W32CE_SYSTEM) && defined (_MSC_VER) + return gpgme_error (GPG_ERR_NOT_IMPLEMENTED); +#else gpgme_error_t err; char *buf = NULL; int res; @@ -109,6 +114,7 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, (*r_dh)->data.mem.length = length; return TRACE_SUC1 ("r_dh=%p", *r_dh); +#endif } @@ -117,6 +123,9 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy) { +#if defined (HAVE_W32CE_SYSTEM) && defined (_MSC_VER) + return gpgme_error (GPG_ERR_NOT_IMPLEMENTED); +#else gpgme_error_t err; struct stat statbuf; TRACE_BEG3 (DEBUG_DATA, "gpgme_data_new_from_filepart", r_dh, @@ -130,6 +139,7 @@ gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy) err = gpgme_data_new_from_filepart (r_dh, fname, NULL, 0, statbuf.st_size); return TRACE_ERR (err); +#endif } diff --git a/src/data-fd.c b/src/data-fd.c index 779202e2..388b45cc 100644 --- a/src/data-fd.c +++ b/src/data-fd.c @@ -25,7 +25,9 @@ #ifdef HAVE_UNISTD_H # include <unistd.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include "debug.h" #include "data.h" diff --git a/src/data-stream.c b/src/data-stream.c index 34a18d46..0e840655 100644 --- a/src/data-stream.c +++ b/src/data-stream.c @@ -23,7 +23,9 @@ #endif #include <stdio.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include "debug.h" #include "data.h" diff --git a/src/data-user.c b/src/data-user.c index 79e62ba9..65065e7a 100644 --- a/src/data-user.c +++ b/src/data-user.c @@ -22,7 +22,9 @@ #include <config.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <errno.h> #include "debug.h" @@ -25,7 +25,9 @@ #include <config.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <limits.h> #include "gpgme.h" diff --git a/src/debug.c b/src/debug.c index 754c8e11..34c5d18f 100644 --- a/src/debug.c +++ b/src/debug.c @@ -33,9 +33,13 @@ #include <errno.h> #include <time.h> #ifndef HAVE_DOSISH_SYSTEM +# ifdef HAVE_SYS_TYPES_H # include <sys/types.h> +# endif +# ifdef HAVE_SYS_STAT_H # include <sys/stat.h> -# include <fcntl.h> +# endif +# include <fcntl.h> #endif #include <assert.h> @@ -205,6 +209,15 @@ _gpgme_debug (int level, const char *format, ...) va_start (arg_ptr, format); LOCK (debug_lock); { +#ifdef HAVE_W32CE_SYSTEM + SYSTEMTIME t; + + GetLocalTime (&t); + fprintf (errfp, "GPGME %04d-%02d-%02d %02d:%02d:%02d <0x%04llx> ", + t.wYear, t.wMonth, t.wDay, + t.wHour, t.wMinute, t.wSecond, + (unsigned long long) ath_self ()); +#else struct tm *tp; time_t atime = time (NULL); @@ -213,6 +226,7 @@ _gpgme_debug (int level, const char *format, ...) 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, (unsigned long long) ath_self ()); +#endif } #ifdef FRAME_NR { diff --git a/src/engine-assuan.c b/src/engine-assuan.c index e521d6d6..dedb8a12 100644 --- a/src/engine-assuan.c +++ b/src/engine-assuan.c @@ -30,7 +30,9 @@ #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <assert.h> #ifdef HAVE_UNISTD_H # include <unistd.h> diff --git a/src/engine-g13.c b/src/engine-g13.c index f3119b5c..6ba49c42 100644 --- a/src/engine-g13.c +++ b/src/engine-g13.c @@ -25,7 +25,9 @@ #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <assert.h> #ifdef HAVE_UNISTD_H # include <unistd.h> diff --git a/src/engine-gpgconf.c b/src/engine-gpgconf.c index cf4df568..6807dce9 100644 --- a/src/engine-gpgconf.c +++ b/src/engine-gpgconf.c @@ -24,7 +24,9 @@ #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <assert.h> #ifdef HAVE_UNISTD_H # include <unistd.h> @@ -535,7 +537,7 @@ gpgconf_conf_load (void *engine, gpgme_conf_comp_t *comp_p) gpgme_error_t _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, - gpgme_conf_type_t type, void *value) + gpgme_conf_type_t type, const void *value) { gpgme_conf_arg_t arg; @@ -616,16 +618,19 @@ _gpgme_conf_arg_release (gpgme_conf_arg_t arg, gpgme_conf_type_t type) gpgme_error_t _gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, gpgme_conf_arg_t arg) { - if (opt->new_value) - release_arg (opt->new_value, opt->alt_type); - if (reset) { + if (opt->new_value) + release_arg (opt->new_value, opt->alt_type); opt->new_value = NULL; opt->change_value = 0; } else { + /* Support self-assignment, for example for adding an item to an + existing list. */ + if (opt->new_value && arg != opt->new_value) + release_arg (opt->new_value, opt->alt_type); opt->new_value = arg; opt->change_value = 1; } @@ -653,7 +658,6 @@ gpgconf_write (void *engine, char *arg1, char *arg2, gpgme_data_t conf) /* _gpgme_engine_new guarantees that this is not NULL. */ argv[0] = gpgconf->file_name; - argv[0] = "/nowhere/path-needs-to-be-fixed/gpgconf"; if (_gpgme_io_pipe (rp, 0) < 0) return gpg_error_from_syserror (); diff --git a/src/engine-gpgsm.c b/src/engine-gpgsm.c index 8a9cd893..4b7b5a2e 100644 --- a/src/engine-gpgsm.c +++ b/src/engine-gpgsm.c @@ -26,7 +26,9 @@ #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <assert.h> #ifdef HAVE_UNISTD_H # include <unistd.h> diff --git a/src/engine-uiserver.c b/src/engine-uiserver.c index fec7d7df..92f75363 100644 --- a/src/engine-uiserver.c +++ b/src/engine-uiserver.c @@ -29,7 +29,9 @@ #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <assert.h> #ifdef HAVE_UNISTD_H # include <unistd.h> diff --git a/src/export.c b/src/export.c index 59463eff..42f55977 100644 --- a/src/export.c +++ b/src/export.c @@ -25,6 +25,7 @@ #include <string.h> #include "gpgme.h" +#include "util.h" #include "debug.h" #include "context.h" #include "ops.h" diff --git a/src/genkey.c b/src/genkey.c index a85e6278..6de3bb8b 100644 --- a/src/genkey.c +++ b/src/genkey.c @@ -30,6 +30,7 @@ #include "debug.h" #include "context.h" #include "ops.h" +#include "util.h" typedef struct diff --git a/src/gpgconf.c b/src/gpgconf.c index 8fdf68ee..3c9d16b5 100644 --- a/src/gpgconf.c +++ b/src/gpgconf.c @@ -30,7 +30,7 @@ #ifdef ENABLE_GPGCONF /* engine-gpgconf.c. */ gpgme_error_t _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, - gpgme_conf_type_t type, void *value); + gpgme_conf_type_t type, const void *value); void _gpgme_conf_arg_release (gpgme_conf_arg_t arg, gpgme_conf_type_t type); gpgme_error_t _gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, gpgme_conf_arg_t arg); @@ -44,7 +44,7 @@ gpgme_error_t gpgme_op_conf_save (gpgme_ctx_t ctx, gpgme_conf_comp_t comp); /* Allocate a new gpgme_conf_arg_t. */ gpgme_error_t gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, - gpgme_conf_type_t type, void *value) + gpgme_conf_type_t type, const void *value) { #ifdef ENABLE_GPGCONF return _gpgme_conf_arg_new (arg_p, type, value); diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index 068681f6..e424c381 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -52,6 +52,10 @@ # define GT_GCC_A_PRINTF(f, a) #endif +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ + *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) @@ -506,6 +510,28 @@ log_error (int status, gpg_error_t errnum, const char *fmt, ...) } +/* Note that it is sufficient to allocate the target string D as long + as the source string S, i.e.: strlen(s)+1;. D == S is allowed. */ +static void +strcpy_escaped_plus (char *d, const char *s) +{ + while (*s) + { + if (*s == '%' && s[1] && s[2]) + { + s++; + *d++ = xtoi_2 (s); + s += 2; + } + else if (*s == '+') + *d++ = ' ', s++; + else + *d++ = *s++; + } + *d = 0; +} + + /* Check whether the option NAME appears in LINE. */ static int has_option (const char *line, const char *name) @@ -2671,14 +2697,22 @@ cmd_delete (assuan_context_t ctx, char *line) } +static const char hlp_keylist[] = + "KEYLIST [--secret-only] [<patterns>]\n" + "\n" + "List all certificates or only those specified by PATTERNS. Each\n" + "pattern shall be a percent-plus escaped certificate specification."; static gpg_error_t cmd_keylist (assuan_context_t ctx, char *line) { +#define MAX_CMD_KEYLIST_PATTERN 20 struct server *server = assuan_get_pointer (ctx); gpg_error_t err; int secret_only = 0; - const char *pattern[2]; + int idx; + const char *pattern[MAX_CMD_KEYLIST_PATTERN+1]; const char optstr[] = "--secret-only"; + char *p; if (!strncasecmp (line, optstr, strlen (optstr))) { @@ -2687,8 +2721,23 @@ cmd_keylist (assuan_context_t ctx, char *line) while (*line && !spacep (line)) line++; } - pattern[0] = line; - pattern[1] = NULL; + + idx = 0; + for (p=line; *p; line = p) + { + while (*p && *p != ' ') + p++; + if (*p) + *p++ = 0; + if (*line) + { + if (idx+1 == DIM (pattern)) + return gpg_error (GPG_ERR_TOO_MANY); + strcpy_escaped_plus (line, line); + pattern[idx++] = line; + } + } + pattern[idx] = NULL; err = gt_keylist_start (server->gt, pattern, secret_only); while (! err) @@ -2706,7 +2755,11 @@ cmd_keylist (assuan_context_t ctx, char *line) char buf[100]; /* FIXME: More data. */ snprintf (buf, sizeof (buf), "key:%s\n", key->subkeys->fpr); - assuan_send_data (ctx, buf, strlen (buf)); + /* Write data and flush so that we see one D line for each + key. This does not change the semantics but is easier to + read by organic eyes. */ + if (!assuan_send_data (ctx, buf, strlen (buf))) + assuan_send_data (ctx, NULL, 0); gpgme_key_unref (key); } } @@ -2895,8 +2948,8 @@ register_commands (assuan_context_t ctx) { "GENKEY", cmd_genkey }, { "DELETE", cmd_delete }, /* TODO: EDIT, CARD_EDIT (with INQUIRE) */ - { "KEYLIST", cmd_keylist }, - { "LISTKEYS", cmd_keylist }, + { "KEYLIST", cmd_keylist, hlp_keylist }, + { "LISTKEYS", cmd_keylist, hlp_keylist }, /* TODO: TRUSTLIST, TRUSTLIST_EXT */ { "GETAUDITLOG", cmd_getauditlog, hlp_getauditlog }, /* TODO: ASSUAN */ diff --git a/src/gpgme-w32spawn.c b/src/gpgme-w32spawn.c index 6f7c609a..ccf88a90 100644 --- a/src/gpgme-w32spawn.c +++ b/src/gpgme-w32spawn.c @@ -28,8 +28,12 @@ #include <fcntl.h> #include <ctype.h> #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif #include <stdint.h> #include <process.h> #include <windows.h> diff --git a/src/gpgme.h.in b/src/gpgme.h.in index f84cd465..a70ff2ad 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -1999,7 +1999,7 @@ typedef struct gpgme_conf_comp to the string. Else, it should point to an unsigned or signed integer respectively. */ gpgme_error_t gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, - gpgme_conf_type_t type, void *value); + gpgme_conf_type_t type, const void *value); /* This also releases all chained argument structures! */ void gpgme_conf_arg_release (gpgme_conf_arg_t arg, gpgme_conf_type_t type); diff --git a/src/keylist.c b/src/keylist.c index f76904b0..8f61a261 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -25,8 +25,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -/* Solaris 8 needs sys/types.h before time.h. */ -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H + /* Solaris 8 needs sys/types.h before time.h. */ +# include <sys/types.h> +#endif #include <time.h> #include <assert.h> #include <ctype.h> diff --git a/src/memrchr.c b/src/memrchr.c deleted file mode 100644 index 21662b1b..00000000 --- a/src/memrchr.c +++ /dev/null @@ -1,210 +0,0 @@ -/* memrchr -- find the last occurrence of a byte in a memory block - Copyright (C) 1991, 93, 96, 97, 99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Based on strlen implementation by Torbjorn Granlund ([email protected]), - with help from Dan Sahlin ([email protected]) and - commentary by Jim Blandy ([email protected]); - adaptation to memchr suggested by Dick Karpinski ([email protected]), - and implemented by Roland McGrath ([email protected]). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdlib.h> - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#undef __ptr_t -#if defined __cplusplus || (defined __STDC__ && __STDC__) -# define __ptr_t void * -#else /* Not C++ or ANSI C. */ -# define __ptr_t char * -#endif /* C++ or ANSI C. */ - -#if defined _LIBC -# include <string.h> -# include <memcopy.h> -#else -# define reg_char char -#endif - -#if defined HAVE_LIMITS_H || defined _LIBC -# include <limits.h> -#endif - -#define LONG_MAX_32_BITS 2147483647 - -#ifndef LONG_MAX -# define LONG_MAX LONG_MAX_32_BITS -#endif - -#include <sys/types.h> - -#undef __memrchr -#undef memrchr - -#ifndef weak_alias -# define __memrchr memrchr -#endif - -/* Search no more than N bytes of S for C. */ -__ptr_t -__memrchr (s, c_in, n) - const __ptr_t s; - int c_in; - size_t n; -{ - const unsigned char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, magic_bits, charmask; - unsigned reg_char c; - - c = (unsigned char) c_in; - - /* Handle the last few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s + n; - n > 0 && ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; - --n) - if (*--char_ptr == c) - return (__ptr_t) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (const unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - - if (sizeof (longword) != 4 && sizeof (longword) != 8) - abort (); - -#if LONG_MAX <= LONG_MAX_32_BITS - magic_bits = 0x7efefeff; -#else - magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff; -#endif - - /* Set up a longword, each of whose bytes is C. */ - charmask = c | (c << 8); - charmask |= charmask << 16; -#if LONG_MAX > LONG_MAX_32_BITS - charmask |= charmask << 32; -#endif - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - while (n >= sizeof (longword)) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. - - 3) But wait! Aren't we looking for C, not zero? - Good point. So what we do is XOR LONGWORD with a longword, - each of whose bytes is C. This turns each byte that is C - into a zero. */ - - longword = *--longword_ptr ^ charmask; - - /* Add MAGIC_BITS to LONGWORD. */ - if ((((longword + magic_bits) - - /* Set those bits that were unchanged by the addition. */ - ^ ~longword) - - /* Look at only the hole bits. If any of the hole bits - are unchanged, most likely one of the bytes was a - zero. */ - & ~magic_bits) != 0) - { - /* Which of the bytes was C? If none of them were, it was - a misfire; continue the search. */ - - const unsigned char *cp = (const unsigned char *) longword_ptr; - -#if LONG_MAX > 2147483647 - if (cp[7] == c) - return (__ptr_t) &cp[7]; - if (cp[6] == c) - return (__ptr_t) &cp[6]; - if (cp[5] == c) - return (__ptr_t) &cp[5]; - if (cp[4] == c) - return (__ptr_t) &cp[4]; -#endif - if (cp[3] == c) - return (__ptr_t) &cp[3]; - if (cp[2] == c) - return (__ptr_t) &cp[2]; - if (cp[1] == c) - return (__ptr_t) &cp[1]; - if (cp[0] == c) - return (__ptr_t) cp; - } - - n -= sizeof (longword); - } - - char_ptr = (const unsigned char *) longword_ptr; - - while (n-- > 0) - { - if (*--char_ptr == c) - return (__ptr_t) char_ptr; - } - - return 0; -} -#ifdef weak_alias -weak_alias (__memrchr, memrchr) -#endif diff --git a/src/passphrase.c b/src/passphrase.c index 71326845..c36b6ae4 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -31,6 +31,7 @@ #include "gpgme.h" #include "context.h" #include "ops.h" +#include "util.h" typedef struct diff --git a/src/posix-io.c b/src/posix-io.c index 762051e7..02782172 100644 --- a/src/posix-io.c +++ b/src/posix-io.c @@ -34,7 +34,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <sys/wait.h> #ifdef HAVE_SYS_UIO_H # include <sys/uio.h> diff --git a/src/posix-sema.c b/src/posix-sema.c index 7ab08dfd..b1808fd9 100644 --- a/src/posix-sema.c +++ b/src/posix-sema.c @@ -35,7 +35,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include "util.h" #include "sema.h" diff --git a/src/priv-io.h b/src/priv-io.h index 2c9d1e70..9c70d22f 100644 --- a/src/priv-io.h +++ b/src/priv-io.h @@ -32,7 +32,9 @@ #endif /* For pid_t. */ -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif /* A single file descriptor passed to spawn. For child fds, dup_to diff --git a/src/setenv.c b/src/setenv.c index 5a7e638b..d85bec9c 100644 --- a/src/setenv.c +++ b/src/setenv.c @@ -20,6 +20,7 @@ # include <config.h> #endif +#include <string.h> #include <gpg-error.h> #define __set_errno(ev) (gpg_err_set_errno (ev)) diff --git a/src/signers.c b/src/signers.c index 021a878d..ae74e815 100644 --- a/src/signers.c +++ b/src/signers.c @@ -57,7 +57,7 @@ void gpgme_signers_clear (gpgme_ctx_t ctx) { TRACE (DEBUG_CTX, "gpgme_signers_clear", ctx); - return _gpgme_signers_clear (ctx); + _gpgme_signers_clear (ctx); } @@ -31,7 +31,9 @@ #endif /* For pid_t. */ -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include "gpgme.h" diff --git a/src/vasprintf.c b/src/vasprintf.c index 77113a31..03d38ff2 100644 --- a/src/vasprintf.c +++ b/src/vasprintf.c @@ -51,6 +51,19 @@ int_vasprintf (result, format, args) const char *format; va_list *args; { +#ifdef HAVE_W32CE_SYSTEM + /* No va_copy and the replacement above doesn't work. */ +#define MAX_STRLEN 256 + *result = malloc (MAX_STRLEN); + if (*result != NULL) + { + int res = _vsnprintf (*result, MAX_STRLEN, format, *args); + (*result)[MAX_STRLEN - 1] = '\0'; + return res; + } + else + return 0; +#else const char *p = format; /* Add one to make sure that it is never zero, which might cause malloc to return NULL. */ @@ -133,6 +146,7 @@ int_vasprintf (result, format, args) return vsprintf (*result, format, *args); else return 0; +#endif } int diff --git a/src/w32-ce.c b/src/w32-ce.c index e6c512ce..88a8f316 100644 --- a/src/w32-ce.c +++ b/src/w32-ce.c @@ -1,5 +1,6 @@ /* w32-ce.h Copyright (C) 2010 g10 Code GmbH + Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc. This file is part of GPGME. @@ -14,9 +15,8 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + License along with this program; if not, see <http://www.gnu.org/licenses/>. + */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -290,7 +290,7 @@ RegQueryValueExA (HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, { wchar_t *name; LONG err; - BYTE *data; + void *data; DWORD data_len; DWORD type; @@ -335,8 +335,8 @@ RegQueryValueExA (HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, int data_c_len; /* This is valid since we allocated one more above. */ - data[data_len] = '\0'; - data[data_len + 1] = '\0'; + ((char*)data)[data_len] = '\0'; + ((char*)data)[data_len + 1] = '\0'; data_c = wchar_to_utf8 ((wchar_t*) data); if (!data_c) @@ -445,3 +445,63 @@ SHGetSpecialFolderPathA (HWND hwndOwner, LPSTR lpszPath, int nFolder, lpszPath[MAX_PATH - 1] = '\0'; return result; } + +/* Replacement for the access function. Note that we can't use fopen + here because wince might now allow to have a shared read for an + executable; it is better to to read the file attributes. + + Limitation: Only F_OK is supported. +*/ +int +_gpgme_wince_access (const char *fname, int mode) +{ + DWORD attr; + wchar_t *wfname; + + (void)mode; + + wfname = utf8_to_wchar (fname); + if (!wfname) + return -1; + + attr = GetFileAttributes (wfname); + free (wfname); + if (attr == (DWORD)(-1)) + { + gpg_err_set_errno (ENOENT); + return -1; + } + return 0; +} + + +/* Perform a binary search for KEY in BASE which has NMEMB elements + of SIZE bytes each. The comparisons are done by (*COMPAR)(). + Code taken from glibc-2.6. */ +void * +_gpgme_wince_bsearch (const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *)) +{ + size_t l, u, idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p); + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} + diff --git a/src/w32-ce.h b/src/w32-ce.h index f34eb1b3..36f1e9e5 100644 --- a/src/w32-ce.h +++ b/src/w32-ce.h @@ -26,13 +26,14 @@ #ifdef _MSC_VER typedef int pid_t; +#define strdup _strdup +#define strcasecmp _stricmp #endif #include <winsock2.h> #include <ws2tcpip.h> /* For getaddrinfo. */ #include <windows.h> - #define getenv _gpgme_wince_getenv char *getenv (const char *name); @@ -67,5 +68,24 @@ DWORD GetTempPathA(DWORD,LPSTR); #define SHGetSpecialFolderPathA _gpgme_wince_SHGetSpecialFolderPathA BOOL SHGetSpecialFolderPathA(HWND,LPSTR,int,BOOL); +int _gpgme_wince_access (const char *fname, int mode); +#define access(a,b) _gpgme_wince_access ((a), (b)) + +void *_gpgme_wince_bsearch (const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *)); +#define bsearch(a,b,c,d,e) _gpgme_wince_bsearch ((a),(b),(c),(d),(e)) + +#if defined(_MSC_VER) + /* Remove the redefined __leave keyword. It is defined by MSC for + W32 in excpt.h and not in sehmap.h as for the plain windows + version. */ +# undef leave +# define HKEY_PERFORMANCE_DATA ((HKEY)0x80000004) +# define HKEY_CURRENT_CONFIG ((HKEY)0x80000005) + /* Replace the Mingw32CE provided abort function. */ +# define abort() do { TerminateProcess (GetCurrentProcess(), 8); } while (0) +# define _IOLBF 0x40 +#endif #endif /* GPGME_W32_CE_H */ diff --git a/src/w32-glib-io.c b/src/w32-glib-io.c index 6b7cd150..5c72f036 100644 --- a/src/w32-glib-io.c +++ b/src/w32-glib-io.c @@ -34,7 +34,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <glib.h> #include <windows.h> #include <io.h> diff --git a/src/w32-io.c b/src/w32-io.c index d7abbf4c..168177e5 100644 --- a/src/w32-io.c +++ b/src/w32-io.c @@ -31,7 +31,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <io.h> #include "util.h" @@ -462,7 +464,13 @@ create_reader (int fd) ctx->have_data_ev = set_synchronize (ctx->have_data_ev); INIT_LOCK (ctx->mutex); +#ifdef HAVE_W32CE_SYSTEM + ctx->thread_hd = CreateThread (&sec_attr, 64 * 1024, reader, ctx, + STACK_SIZE_PARAM_IS_A_RESERVATION, &tid); +#else ctx->thread_hd = CreateThread (&sec_attr, 0, reader, ctx, 0, &tid); +#endif + if (!ctx->thread_hd) { TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ()); @@ -822,7 +830,13 @@ create_writer (int fd) ctx->is_empty = set_synchronize (ctx->is_empty); INIT_LOCK (ctx->mutex); +#ifdef HAVE_W32CE_SYSTEM + ctx->thread_hd = CreateThread (&sec_attr, 64 * 1024, writer, ctx, + STACK_SIZE_PARAM_IS_A_RESERVATION, &tid); +#else ctx->thread_hd = CreateThread (&sec_attr, 0, writer, ctx, 0, &tid ); +#endif + if (!ctx->thread_hd) { TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ()); diff --git a/src/w32-sema.c b/src/w32-sema.c index 33961041..504e6822 100644 --- a/src/w32-sema.c +++ b/src/w32-sema.c @@ -31,7 +31,9 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include <io.h> #include "util.h" diff --git a/src/w32-util.c b/src/w32-util.c index c29ff490..b33aa2c6 100644 --- a/src/w32-util.c +++ b/src/w32-util.c @@ -32,8 +32,12 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <sys/types.h> -#include <sys/stat.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif #ifdef HAVE_UNISTD_H # include <unistd.h> #endif @@ -72,14 +76,14 @@ DEFINE_STATIC_LOCK (get_path_lock); #define RTLD_LAZY 0 -static __inline__ void * +static GPG_ERR_INLINE void * dlopen (const char * name, int flag) { void * hd = LoadLibrary (name); return hd; } -static __inline__ void * +static GPG_ERR_INLINE void * dlsym (void * hd, const char * sym) { if (hd && sym) @@ -92,7 +96,7 @@ dlsym (void * hd, const char * sym) return NULL; } -static __inline__ int +static GPG_ERR_INLINE int dlclose (void * hd) { if (hd) @@ -104,7 +108,6 @@ dlclose (void * hd) } #endif /* HAVE_ALLOW_SET_FOREGROUND_WINDOW */ - void _gpgme_allow_set_foreground_window (pid_t pid) { @@ -631,6 +634,6 @@ _gpgme_w32ce_get_debug_envvar (void) free (tmp); tmp = NULL; } - return NULL; + return tmp; } #endif /*HAVE_W32CE_SYSTEM*/ @@ -26,7 +26,9 @@ #include <string.h> #include <assert.h> #include <errno.h> -#include <sys/types.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif #include "util.h" #include "context.h" |