diff --git a/ChangeLog b/ChangeLog index cf0a230c..4a46d077 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-01-29 Marcus Brinkmann + + * configure.ac: Remove all uses of GNUPG_CHECK_TYPEDEF, for byte, + ushort, ulong, u16 and u32. + * acinclude.m4 (GNUPG_CHECK_TYPEDEF): Remove macro. + 2002-12-24 Marcus Brinkmann * configure.ac: New conditional HAVE_LD_VERSION_SCRIPT. diff --git a/acinclude.m4 b/acinclude.m4 index 6a06343c..abdee4d3 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -26,24 +26,6 @@ AC_DEFUN(GNUPG_FIX_HDR_VERSION, ]) -dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME) -dnl Check whether a typedef exists and create a #define $2 if it exists -dnl -AC_DEFUN(GNUPG_CHECK_TYPEDEF, - [ AC_MSG_CHECKING(for $1 typedef) - AC_CACHE_VAL(gnupg_cv_typedef_$1, - [AC_TRY_COMPILE([#include - #include ], [ - #undef $1 - int a = sizeof($1); - ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )]) - AC_MSG_RESULT($gnupg_cv_typedef_$1) - if test "$gnupg_cv_typedef_$1" = yes; then - AC_DEFINE($2, , - [Define to 1 if $1 is defined in the header file.]) - fi - ]) - dnl ## dnl ## GNU Pth - The GNU Portable Threads dnl ## Copyright (c) 1999-2002 Ralf S. Engelschall diff --git a/configure.ac b/configure.ac index fec653dd..fa9c3eb2 100644 --- a/configure.ac +++ b/configure.ac @@ -145,16 +145,9 @@ dnl Checks for header files. dnl AC_CHECK_HEADERS(sys/select.h) - - dnl -dnl Checks for typedefs and structures. +dnl Type checks. dnl -GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF) -GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF) -GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF) -GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF) -GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF) AC_CHECK_SIZEOF(unsigned int) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index fc31bc40..fef98724 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,5 +1,18 @@ 2003-01-29 Marcus Brinkmann + * types.h: Remove byte and ulong types. + * util.h (_gpgme_hextobyte): Change prototype to unsigned char + instead byte. + * conversion.c (_gpgme_hextobyte): Change argument to unsigned + char instead byte. + (_gpgme_decode_c_string): Likewise, and beautify. Also support a + few more escaped characters. Be more strict about buffer size. + (_gpgme_data_append_percentstring_for_xml): Change type of SRC, + BUF and DST to unsigned char instead byte. + * progress.c (_gpgme_progress_status_handler): Use unsigned char + instead byte. + * debug.c (trim_spaces): Likewise. + * util.h (mk_error): Remove macro. * conversion.c, data.c, data-compat.c, decrypt.c, delete.c, edit.c, encrypt.c, encrypt-sign.c, engine.c, engine-gpgsm.c, diff --git a/gpgme/conversion.c b/gpgme/conversion.c index 143c8dbc..5b2cb67a 100644 --- a/gpgme/conversion.c +++ b/gpgme/conversion.c @@ -1,6 +1,6 @@ /* conversion.c - String conversion helper functions. Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002 g10 Code GmbH + Copyright (C) 2001, 2002, 2003 g10 Code GmbH This file is part of GPGME. @@ -31,9 +31,12 @@ #include "gpgme.h" #include "util.h" - + +/* Convert two hexadecimal digits from STR to the value they + represent. Returns -1 if one of the characters is not a + hexadecimal digit. */ int -_gpgme_hextobyte (const byte *str) +_gpgme_hextobyte (const unsigned char *str) { int val = 0; int i; @@ -68,12 +71,18 @@ _gpgme_decode_c_string (const char *src, char **destp, int len) { char *dest; + /* Set up the destination buffer. */ if (len) - dest = *destp; + { + if (len < strlen (src) + 1) + return GPGME_General_Error; + + dest = *destp; + } else { - /* We can malloc a buffer of the same length, because the converted - string will never be larger. */ + /* The converted string will never be larger than the original + string. */ dest = malloc (strlen (src) + 1); if (!dest) return GPGME_Out_Of_Core; @@ -81,71 +90,70 @@ _gpgme_decode_c_string (const char *src, char **destp, int len) *destp = dest; } + /* Convert the string. */ while (*src) { if (*src != '\\') - *(dest++) = *(src++); - else if (src[1] == '\\') { - src++; - *(dest++) = *(src++); - } - else if (src[1] == 'n') - { - src += 2; - *(dest++) = '\n'; - } - else if (src[1] == 'r') - { - src += 2; - *(dest++) = '\r'; - } - else if (src[1] == 'v') - { - src += 2; - *(dest++) = '\v'; - } - else if (src[1] == 'b') - { - src += 2; - *(dest++) = '\b'; - } - else if (src[1] == '0') - { - /* Hmmm: no way to express this */ - src += 2; - *(dest++) = '\\'; - *(dest++) = '\0'; - } - else if (src[1] == 'x' && isxdigit (src[2]) && isxdigit (src[3])) - { - int val = _gpgme_hextobyte (&src[2]); - if (val == -1) - { - /* Should not happen. */ - *(dest++) = *(src++); - *(dest++) = *(src++); - *(dest++) = *(src++); - *(dest++) = *(src++); - } - else - { - if (!val) - { - *(dest++) = '\\'; - *(dest++) = '\0'; - } - else - *(byte*)dest++ = val; - src += 4; - } - } - else - { - /* should not happen */ - src++; - *(dest++) = '\\'; *(dest++) = *(src++); + continue; + } + + switch (src[1]) + { +#define DECODE_ONE(match,result) \ + case match: \ + src += 2; \ + *(dest++) = result; \ + break; + + DECODE_ONE ('\'', '\''); + DECODE_ONE ('\"', '\"'); + DECODE_ONE ('\?', '\?'); + DECODE_ONE ('\\', '\\'); + DECODE_ONE ('a', '\a'); + DECODE_ONE ('b', '\b'); + DECODE_ONE ('f', '\f'); + DECODE_ONE ('n', '\n'); + DECODE_ONE ('r', '\r'); + DECODE_ONE ('t', '\t'); + DECODE_ONE ('v', '\v'); + + case 'x': + { + int val = _gpgme_hextobyte (&src[2]); + + if (val == -1) + { + /* Should not happen. */ + *(dest++) = *(src++); + *(dest++) = *(src++); + if (*src) + *(dest++) = *(src++); + if (*src) + *(dest++) = *(src++); + } + else + { + if (!val) + { + /* A binary zero is not representable in a C + string. */ + *(dest++) = '\\'; + *(dest++) = '0'; + } + else + *((unsigned char *) dest++) = val; + src += 4; + } + } + + default: + { + /* Should not happen. */ + *(dest++) = *(src++); + *(dest++) = *(src++); + } } } *(dest++) = 0; @@ -244,8 +252,8 @@ _gpgme_data_append_string_for_xml (GpgmeData dh, const char *str) GpgmeError _gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *str) { - const byte *src; - byte *buf, *dst; + const unsigned char *src; + unsigned char *buf, *dst; int val; GpgmeError err; diff --git a/gpgme/debug.c b/gpgme/debug.c index 8cb7030b..8fe32e60 100644 --- a/gpgme/debug.c +++ b/gpgme/debug.c @@ -1,24 +1,26 @@ /* debug.c - helpful output in desperate situations - * Copyright (C) 2001, 2002 g10 Code GmbH - * - * This file is part of GPGME. - * - * GPGME is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * GPGME 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 General Public License for more details. - * - * You should have received a copy of the GNU 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 - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003 g10 Code GmbH + + This file is part of GPGME. + GPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GPGME 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H #include +#endif #include #include #include @@ -56,11 +58,11 @@ trim_spaces (char *str) string = str; /* Find first non space character. */ - for (p = string; *p && isspace (*(byte *) p); p++) + for (p = string; *p && isspace (*(unsigned char *) p); p++) ; /* Move characters. */ for (mark = NULL; (*string = *p); string++, p++) - if (isspace (*(byte *) p)) + if (isspace (*(unsigned char *) p)) { if (!mark) mark = string; diff --git a/gpgme/progress.c b/gpgme/progress.c index f5daca5d..a939fcd4 100644 --- a/gpgme/progress.c +++ b/gpgme/progress.c @@ -1,6 +1,6 @@ /* progress.c - status handler for progress status Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002 g10 Code GmbH + Copyright (C) 2001, 2002, 2003 g10 Code GmbH This file is part of GPGME. @@ -50,7 +50,7 @@ _gpgme_progress_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) *p++ = 0; if (*p) { - type = *(byte *)p; + type = *(unsigned char *)p; p = strchr (p+1, ' '); if (p) { diff --git a/gpgme/types.h b/gpgme/types.h index 90feecf0..30ed7246 100644 --- a/gpgme/types.h +++ b/gpgme/types.h @@ -1,6 +1,6 @@ -/* types.h - Some type definitions +/* types.h - Type definitions. Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002 g10 Code GmbH + Copyright (C) 2001, 2002, 2003 g10 Code GmbH This file is part of GPGME. @@ -21,19 +21,9 @@ #ifndef TYPES_H #define TYPES_H -#include "gpgme.h" /* external objects and prototypes */ +#include "gpgme.h" -#ifndef HAVE_BYTE_TYPEDEF -typedef unsigned char byte; -#endif -#ifndef HAVE_ULONG_TYPEDEF -typedef unsigned long ulong; -#endif - - -/* - * Declaration of internal objects - */ +/* Declaration of internal objects. */ typedef GpgmeError (*GpgmeStatusHandler) (GpgmeCtx, GpgmeStatusCode code, char *args); @@ -94,5 +84,4 @@ typedef struct keylist_result_s *KeylistResult; struct edit_result_s; typedef struct edit_result_s *EditResult; - #endif /* TYPES_H */ diff --git a/gpgme/util.h b/gpgme/util.h index 8bc62536..c862235e 100644 --- a/gpgme/util.h +++ b/gpgme/util.h @@ -82,6 +82,11 @@ FILE *fopencookie (void *cookie, const char *opentype, /*-- conversion.c --*/ +/* Convert two hexadecimal digits from STR to the value they + represent. Returns -1 if one of the characters is not a + hexadecimal digit. */ +int _gpgme_hextobyte (const unsigned char *str); + /* Decode the C formatted string SRC and store the result in the buffer *DESTP which is LEN bytes long. If LEN is zero, then a large enough buffer is allocated with malloc and *DESTP is set to @@ -89,6 +94,6 @@ FILE *fopencookie (void *cookie, const char *opentype, is desired or not, the caller is expected to make sure that *DESTP is large enough if LEN is not zero. */ GpgmeError _gpgme_decode_c_string (const char *src, char **destp, int len); -int _gpgme_hextobyte (const byte *str); + #endif /* UTIL_H */