diff options
author | René Schümann <white06tiger@gmail.com> | 2015-03-20 12:32:29 +0000 |
---|---|---|
committer | René Schümann <white06tiger@gmail.com> | 2015-03-20 12:32:29 +0000 |
commit | 539705d58fc39a28388ff18c695dd406f4ffd1d9 (patch) | |
tree | 51db7a37a66c09f41734ba5573d972aae9f30d71 /plugins/MirOTR/Libgpg-error | |
parent | 90171f125f36488dc08f5cfe0b0d4b78d995f08d (diff) |
MirOTR: Libgcrypt and Libgpg-error update
Libgcrypt 1.4.6 => 1.6.3
Libgpg-error 1.9 => 1.18
git-svn-id: http://svn.miranda-ng.org/main/trunk@12449 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/Libgpg-error')
57 files changed, 11456 insertions, 3110 deletions
diff --git a/plugins/MirOTR/Libgpg-error/README b/plugins/MirOTR/Libgpg-error/README deleted file mode 100644 index c415983598..0000000000 --- a/plugins/MirOTR/Libgpg-error/README +++ /dev/null @@ -1,47 +0,0 @@ -Notes on the source code -======================== - -The mechanism to generate the system error codes is delicate and -fragile, but it's the best I could come up with that supports -cross-compilation and dynamic self-configuration. Here is how it -works: - -1. Generate list of supported system error codes. - -mkerrcodes1.awk generates a list of supported system error codes from -errnos.in. Each entry in the list is protected with #ifdef/#endif, -and contains a GPG_ERR_* marker. The list is stored in "_mkerrcodes.h". - -2. The HOST cpp is run on _mkerrcodes.h. This evaluates the known -system error macros to something (may be a number, maybe a constant -expression as on the GNU/Hurd), suppressing the unknown ones. The -output is piped into step 3. - -3. The cpp output is filtered with grep for only those lines which -contain a GPG_ERR_* marker. The output is piped into step 4. - -4. The filtered output is processed by mkerrcodes.awk, which produces -a table of constant expressions plus GPG_ERR_* code string symbols in -a format suitable for the C program mkerrcodes.c. At this point we -are crossing our fingers that the constant expressions produced by the -system do not contain GPG_ERR_* markers. The output is stored in -mkerrcodes.h. - -5. The file mkerrcodes.h is included by mkerrcodes.c, which is -compiled to a binary executable on the BUILD system. At this point we -are crossing our fingers that the constant expressions produced by the -system do not depend on the build platform anymore. The output is -post-processed by mkerrcodes2.awk and stored in "code-from-errno.h", -which is subsequently used in the library. - --- Marcus - - Copyright 2006 g10 Code GmbH - - This file is free software; as a special exception the author gives - unlimited permission to copy and/or distribute it, with or without - modifications, as long as this notice is preserved. - - This file is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY, to the extent permitted by law; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/plugins/MirOTR/Libgpg-error/code-from-errno.c b/plugins/MirOTR/Libgpg-error/code-from-errno.c index 96fcf20860..6064270594 100644 --- a/plugins/MirOTR/Libgpg-error/code-from-errno.c +++ b/plugins/MirOTR/Libgpg-error/code-from-errno.c @@ -7,12 +7,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -22,7 +22,7 @@ #include <config.h> #endif -#include <errno.h> +#include <errno.h> #include <gpg-error.h> @@ -32,7 +32,7 @@ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report this). */ gpg_err_code_t -gpg_err_code_from_errno (int err) +_gpg_err_code_from_errno (int err) { int idx; @@ -52,7 +52,7 @@ gpg_err_code_from_errno (int err) returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */ gpg_err_code_t -gpg_err_code_from_syserror (void) +_gpg_err_code_from_syserror (void) { int err = errno; int idx; diff --git a/plugins/MirOTR/Libgpg-error/code-from-errno.h b/plugins/MirOTR/Libgpg-error/code-from-errno.h index 071d8ba17f..124eff2a80 100644 --- a/plugins/MirOTR/Libgpg-error/code-from-errno.h +++ b/plugins/MirOTR/Libgpg-error/code-from-errno.h @@ -1,107 +1,136 @@ /* Output of mkerrcodes2.awk. DO NOT EDIT. */ -/* errnos.h - List of system error values.
- Copyright (C) 2004 g10 Code GmbH
- This file is part of libgpg-error.
-
- libgpg-error 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.
-
- libgpg-error 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 libgpg-error; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
-
+/* errnos.h - List of system error values. + Copyright (C) 2004 g10 Code GmbH + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 libgpg-error; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + static const int err_code_from_index[] = { - GPG_ERR_EPERM
, - GPG_ERR_ENOENT
, - GPG_ERR_ESRCH
, - GPG_ERR_EINTR
, - GPG_ERR_EIO
, - GPG_ERR_ENXIO
, - GPG_ERR_E2BIG
, - GPG_ERR_ENOEXEC
, - GPG_ERR_EBADF
, - GPG_ERR_ECHILD
, - GPG_ERR_EAGAIN
, - GPG_ERR_ENOMEM
, - GPG_ERR_EACCES
, - GPG_ERR_EFAULT
, - GPG_ERR_EBUSY
, - GPG_ERR_EEXIST
, - GPG_ERR_EXDEV
, - GPG_ERR_ENODEV
, - GPG_ERR_ENOTDIR
, - GPG_ERR_EISDIR
, - GPG_ERR_EINVAL
, - GPG_ERR_ENFILE
, - GPG_ERR_EMFILE
, - GPG_ERR_ENOTTY
, - GPG_ERR_EFBIG
, - GPG_ERR_ENOSPC
, - GPG_ERR_ESPIPE
, - GPG_ERR_EROFS
, - GPG_ERR_EMLINK
, - GPG_ERR_EPIPE
, - GPG_ERR_EDOM
, - GPG_ERR_ERANGE
, - GPG_ERR_EDEADLK
, - GPG_ERR_EDEADLOCK
, - GPG_ERR_ENAMETOOLONG
, - GPG_ERR_ENOLCK
, - GPG_ERR_ENOSYS
, - GPG_ERR_ENOTEMPTY
, - GPG_ERR_EILSEQ
, - GPG_ERR_EINTR
, - GPG_ERR_EBADF
, - GPG_ERR_EACCES
, - GPG_ERR_EFAULT
, - GPG_ERR_EINVAL
, - GPG_ERR_EMFILE
, - GPG_ERR_EWOULDBLOCK
, - GPG_ERR_EINPROGRESS
, - GPG_ERR_EALREADY
, - GPG_ERR_ENOTSOCK
, - GPG_ERR_EDESTADDRREQ
, - GPG_ERR_EMSGSIZE
, - GPG_ERR_EPROTOTYPE
, - GPG_ERR_ENOPROTOOPT
, - GPG_ERR_EPROTONOSUPPORT
, - GPG_ERR_ESOCKTNOSUPPORT
, - GPG_ERR_EOPNOTSUPP
, - GPG_ERR_EPFNOSUPPORT
, - GPG_ERR_EAFNOSUPPORT
, - GPG_ERR_EADDRINUSE
, - GPG_ERR_EADDRNOTAVAIL
, - GPG_ERR_ENETDOWN
, - GPG_ERR_ENETUNREACH
, - GPG_ERR_ENETRESET
, - GPG_ERR_ECONNABORTED
, - GPG_ERR_ECONNRESET
, - GPG_ERR_ENOBUFS
, - GPG_ERR_EISCONN
, - GPG_ERR_ENOTCONN
, - GPG_ERR_ESHUTDOWN
, - GPG_ERR_ETOOMANYREFS
, - GPG_ERR_ETIMEDOUT
, - GPG_ERR_ECONNREFUSED
, - GPG_ERR_ELOOP
, - GPG_ERR_ENAMETOOLONG
, - GPG_ERR_EHOSTDOWN
, - GPG_ERR_EHOSTUNREACH
, - GPG_ERR_ENOTEMPTY
, - GPG_ERR_EPROCLIM
, - GPG_ERR_EUSERS
, - GPG_ERR_EDQUOT
, - GPG_ERR_ESTALE
, - GPG_ERR_EREMOTE
, + GPG_ERR_EPERM, + GPG_ERR_ENOENT, + GPG_ERR_ESRCH, + GPG_ERR_EINTR, + GPG_ERR_EIO, + GPG_ERR_ENXIO, + GPG_ERR_E2BIG, + GPG_ERR_ENOEXEC, + GPG_ERR_EBADF, + GPG_ERR_ECHILD, + GPG_ERR_EAGAIN, + GPG_ERR_ENOMEM, + GPG_ERR_EACCES, + GPG_ERR_EFAULT, + GPG_ERR_EBUSY, + GPG_ERR_EEXIST, + GPG_ERR_EXDEV, + GPG_ERR_ENODEV, + GPG_ERR_ENOTDIR, + GPG_ERR_EISDIR, + GPG_ERR_EINVAL, + GPG_ERR_ENFILE, + GPG_ERR_EMFILE, + GPG_ERR_ENOTTY, + GPG_ERR_EFBIG, + GPG_ERR_ENOSPC, + GPG_ERR_ESPIPE, + GPG_ERR_EROFS, + GPG_ERR_EMLINK, + GPG_ERR_EPIPE, + GPG_ERR_EDOM, + GPG_ERR_ERANGE, + GPG_ERR_EDEADLK, + GPG_ERR_EDEADLOCK, + GPG_ERR_ENAMETOOLONG, + GPG_ERR_ENOLCK, + GPG_ERR_ENOSYS, + GPG_ERR_ENOTEMPTY, + GPG_ERR_EILSEQ, + GPG_ERR_EADDRINUSE, + GPG_ERR_EADDRNOTAVAIL, + GPG_ERR_EAFNOSUPPORT, + GPG_ERR_EALREADY, + GPG_ERR_ECANCELED, + GPG_ERR_ECONNABORTED, + GPG_ERR_ECONNREFUSED, + GPG_ERR_ECONNRESET, + GPG_ERR_EDESTADDRREQ, + GPG_ERR_EHOSTUNREACH, + GPG_ERR_EINPROGRESS, + GPG_ERR_EISCONN, + GPG_ERR_ELOOP, + GPG_ERR_EMSGSIZE, + GPG_ERR_ENETDOWN, + GPG_ERR_ENETRESET, + GPG_ERR_ENETUNREACH, + GPG_ERR_ENOBUFS, + GPG_ERR_ENOPROTOOPT, + GPG_ERR_ENOTCONN, + GPG_ERR_ENOTSOCK, + GPG_ERR_ENOTSUP, + GPG_ERR_EOPNOTSUPP, + GPG_ERR_EOVERFLOW, + GPG_ERR_EPROTO, + GPG_ERR_EPROTONOSUPPORT, + GPG_ERR_EPROTOTYPE, + GPG_ERR_ETIMEDOUT, + GPG_ERR_EWOULDBLOCK, + GPG_ERR_EINTR, + GPG_ERR_EBADF, + GPG_ERR_EACCES, + GPG_ERR_EFAULT, + GPG_ERR_EINVAL, + GPG_ERR_EMFILE, + GPG_ERR_EWOULDBLOCK, + GPG_ERR_EINPROGRESS, + GPG_ERR_EALREADY, + GPG_ERR_ENOTSOCK, + GPG_ERR_EDESTADDRREQ, + GPG_ERR_EMSGSIZE, + GPG_ERR_EPROTOTYPE, + GPG_ERR_ENOPROTOOPT, + GPG_ERR_EPROTONOSUPPORT, + GPG_ERR_ESOCKTNOSUPPORT, + GPG_ERR_EOPNOTSUPP, + GPG_ERR_EPFNOSUPPORT, + GPG_ERR_EAFNOSUPPORT, + GPG_ERR_EADDRINUSE, + GPG_ERR_EADDRNOTAVAIL, + GPG_ERR_ENETDOWN, + GPG_ERR_ENETUNREACH, + GPG_ERR_ENETRESET, + GPG_ERR_ECONNABORTED, + GPG_ERR_ECONNRESET, + GPG_ERR_ENOBUFS, + GPG_ERR_EISCONN, + GPG_ERR_ENOTCONN, + GPG_ERR_ESHUTDOWN, + GPG_ERR_ETOOMANYREFS, + GPG_ERR_ETIMEDOUT, + GPG_ERR_ECONNREFUSED, + GPG_ERR_ELOOP, + GPG_ERR_ENAMETOOLONG, + GPG_ERR_EHOSTDOWN, + GPG_ERR_EHOSTUNREACH, + GPG_ERR_ENOTEMPTY, + GPG_ERR_EPROCLIM, + GPG_ERR_EUSERS, + GPG_ERR_EDQUOT, + GPG_ERR_ESTALE, + GPG_ERR_EREMOTE, }; #define errno_to_idx(code) (0 ? -1 \ @@ -111,10 +140,20 @@ static const int err_code_from_index[] = { : ((code >= 36) && (code <= 36)) ? (code - 4) \ : ((code >= 36) && (code <= 36)) ? (code - 3) \ : ((code >= 38) && (code <= 42)) ? (code - 4) \ - : ((code >= 10004) && (code <= 10004)) ? (code - 9965) \ - : ((code >= 10009) && (code <= 10009)) ? (code - 9969) \ - : ((code >= 10013) && (code <= 10014)) ? (code - 9972) \ - : ((code >= 10022) && (code <= 10022)) ? (code - 9979) \ - : ((code >= 10024) && (code <= 10024)) ? (code - 9980) \ - : ((code >= 10035) && (code <= 10071)) ? (code - 9990) \ + : ((code >= 100) && (code <= 103)) ? (code - 61) \ + : ((code >= 105) && (code <= 110)) ? (code - 62) \ + : ((code >= 112) && (code <= 119)) ? (code - 63) \ + : ((code >= 123) && (code <= 123)) ? (code - 66) \ + : ((code >= 126) && (code <= 126)) ? (code - 68) \ + : ((code >= 128) && (code <= 130)) ? (code - 69) \ + : ((code >= 132) && (code <= 132)) ? (code - 70) \ + : ((code >= 134) && (code <= 136)) ? (code - 71) \ + : ((code >= 138) && (code <= 138)) ? (code - 72) \ + : ((code >= 140) && (code <= 140)) ? (code - 73) \ + : ((code >= 10004) && (code <= 10004)) ? (code - 9936) \ + : ((code >= 10009) && (code <= 10009)) ? (code - 9940) \ + : ((code >= 10013) && (code <= 10014)) ? (code - 9943) \ + : ((code >= 10022) && (code <= 10022)) ? (code - 9950) \ + : ((code >= 10024) && (code <= 10024)) ? (code - 9951) \ + : ((code >= 10035) && (code <= 10071)) ? (code - 9961) \ : -1) diff --git a/plugins/MirOTR/Libgpg-error/code-to-errno.c b/plugins/MirOTR/Libgpg-error/code-to-errno.c index 5873aad633..6ba6d8788d 100644 --- a/plugins/MirOTR/Libgpg-error/code-to-errno.c +++ b/plugins/MirOTR/Libgpg-error/code-to-errno.c @@ -7,12 +7,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -29,7 +29,7 @@ /* Retrieve the system error for the error code CODE. This returns 0 if CODE is not a system error code. */ int -gpg_err_code_to_errno (gpg_err_code_t code) +_gpg_err_code_to_errno (gpg_err_code_t code) { if (!(code & GPG_ERR_SYSTEM_ERROR)) return 0; diff --git a/plugins/MirOTR/Libgpg-error/code-to-errno.h b/plugins/MirOTR/Libgpg-error/code-to-errno.h index 114489f929..8907fc0943 100644 --- a/plugins/MirOTR/Libgpg-error/code-to-errno.h +++ b/plugins/MirOTR/Libgpg-error/code-to-errno.h @@ -1,6 +1,6 @@ /* Output of mkerrnos.awk. DO NOT EDIT. */ -/* errnos.h - List of system error values. +/* errnos.in - List of system error values. Copyright (C) 2003, 2004 g10 Code GmbH This file is part of libgpg-error. @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA diff --git a/plugins/MirOTR/Libgpg-error/err-codes-sym.h b/plugins/MirOTR/Libgpg-error/err-codes-sym.h index 0ed5032eb0..c36da03b8c 100644 --- a/plugins/MirOTR/Libgpg-error/err-codes-sym.h +++ b/plugins/MirOTR/Libgpg-error/err-codes-sym.h @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -209,6 +209,21 @@ static const char msgstr[] = "GPG_ERR_MISSING_KEY" "\0" "GPG_ERR_TOO_MANY" "\0" "GPG_ERR_LIMIT_REACHED" "\0" + "GPG_ERR_NOT_INITIALIZED" "\0" + "GPG_ERR_MISSING_ISSUER_CERT" "\0" + "GPG_ERR_NO_KEYSERVER" "\0" + "GPG_ERR_INV_CURVE" "\0" + "GPG_ERR_UNKNOWN_CURVE" "\0" + "GPG_ERR_DUP_KEY" "\0" + "GPG_ERR_AMBIGUOUS" "\0" + "GPG_ERR_NO_CRYPT_CTX" "\0" + "GPG_ERR_WRONG_CRYPT_CTX" "\0" + "GPG_ERR_BAD_CRYPT_CTX" "\0" + "GPG_ERR_CRYPT_CTX_CONFLICT" "\0" + "GPG_ERR_BROKEN_PUBKEY" "\0" + "GPG_ERR_BROKEN_SECKEY" "\0" + "GPG_ERR_MAC_ALGO" "\0" + "GPG_ERR_FULLY_CANCELED" "\0" "GPG_ERR_UNFINISHED" "\0" "GPG_ERR_BUFFER_TOO_SHORT" "\0" "GPG_ERR_SEXP_INV_LEN_SPEC" "\0" @@ -224,6 +239,39 @@ static const char msgstr[] = "GPG_ERR_SEXP_BAD_HEX_CHAR" "\0" "GPG_ERR_SEXP_ODD_HEX_NUMBERS" "\0" "GPG_ERR_SEXP_BAD_OCT_CHAR" "\0" + "GPG_ERR_LEGACY_KEY" "\0" + "GPG_ERR_REQUEST_TOO_SHORT" "\0" + "GPG_ERR_REQUEST_TOO_LONG" "\0" + "GPG_ERR_OBJ_TERM_STATE" "\0" + "GPG_ERR_NO_CERT_CHAIN" "\0" + "GPG_ERR_CERT_TOO_LARGE" "\0" + "GPG_ERR_INV_RECORD" "\0" + "GPG_ERR_BAD_MAC" "\0" + "GPG_ERR_UNEXPECTED_MSG" "\0" + "GPG_ERR_COMPR_FAILED" "\0" + "GPG_ERR_WOULD_WRAP" "\0" + "GPG_ERR_FATAL_ALERT" "\0" + "GPG_ERR_NO_CIPHER" "\0" + "GPG_ERR_MISSING_CLIENT_CERT" "\0" + "GPG_ERR_CLOSE_NOTIFY" "\0" + "GPG_ERR_TICKET_EXPIRED" "\0" + "GPG_ERR_BAD_TICKET" "\0" + "GPG_ERR_UNKNOWN_IDENTITY" "\0" + "GPG_ERR_BAD_HS_CERT" "\0" + "GPG_ERR_BAD_HS_CERT_REQ" "\0" + "GPG_ERR_BAD_HS_CERT_VER" "\0" + "GPG_ERR_BAD_HS_CHANGE_CIPHER" "\0" + "GPG_ERR_BAD_HS_CLIENT_HELLO" "\0" + "GPG_ERR_BAD_HS_SERVER_HELLO" "\0" + "GPG_ERR_BAD_HS_SERVER_HELLO_DONE" "\0" + "GPG_ERR_BAD_HS_FINISHED" "\0" + "GPG_ERR_BAD_HS_SERVER_KEX" "\0" + "GPG_ERR_BAD_HS_CLIENT_KEX" "\0" + "GPG_ERR_BOGUS_STRING" "\0" + "GPG_ERR_FORBIDDEN" "\0" + "GPG_ERR_KEY_DISABLED" "\0" + "GPG_ERR_KEY_ON_CARD" "\0" + "GPG_ERR_INV_LOCK_OBJ" "\0" "GPG_ERR_ASS_GENERAL" "\0" "GPG_ERR_ASS_ACCEPT_FAILED" "\0" "GPG_ERR_ASS_CONNECT_FAILED" "\0" @@ -456,75 +504,123 @@ static const int msgidx[] = 3759, 3776, 3798, - 3817, - 3842, - 3868, - 3897, - 3926, - 3953, - 3980, - 4007, - 4032, - 4055, - 4081, - 4110, - 4136, - 4165, - 4191, - 4211, - 4237, - 4264, - 4289, - 4311, - 4339, - 4365, - 4393, - 4416, - 4442, - 4467, - 4492, - 4517, - 4540, - 4564, - 4590, - 4617, - 4641, - 4660, - 4681, - 4702, - 4724, - 4746, - 4774, - 4789, - 4804, - 4819, - 4834, - 4849, - 4864, - 4879, - 4894, - 4909, - 4925, - 4941, - 4957, - 4973, - 4989, - 5005, - 5021, - 5043, - 5065, - 5077 + 3822, + 3850, + 3871, + 3889, + 3911, + 3927, + 3945, + 3966, + 3990, + 4012, + 4039, + 4061, + 4083, + 4100, + 4123, + 4142, + 4167, + 4193, + 4222, + 4251, + 4278, + 4305, + 4332, + 4357, + 4380, + 4406, + 4435, + 4461, + 4490, + 4516, + 4535, + 4561, + 4586, + 4609, + 4631, + 4654, + 4673, + 4689, + 4712, + 4733, + 4752, + 4772, + 4790, + 4818, + 4839, + 4862, + 4881, + 4906, + 4926, + 4950, + 4974, + 5003, + 5031, + 5059, + 5092, + 5116, + 5142, + 5168, + 5189, + 5207, + 5228, + 5248, + 5269, + 5289, + 5315, + 5342, + 5367, + 5389, + 5417, + 5443, + 5471, + 5494, + 5520, + 5545, + 5570, + 5595, + 5618, + 5642, + 5668, + 5695, + 5719, + 5738, + 5759, + 5780, + 5802, + 5824, + 5852, + 5867, + 5882, + 5897, + 5912, + 5927, + 5942, + 5957, + 5972, + 5987, + 6003, + 6019, + 6035, + 6051, + 6067, + 6083, + 6099, + 6121, + 6143, + 6155 }; -static inline int +static GPG_ERR_INLINE int msgidxof (int code) { return (0 ? 0 - : ((code >= 0) && (code <= 183)) ? (code - 0) - : ((code >= 199) && (code <= 213)) ? (code - 15) - : ((code >= 257) && (code <= 271)) ? (code - 58) - : ((code >= 273) && (code <= 281)) ? (code - 59) - : ((code >= 1024) && (code <= 1039)) ? (code - 801) - : ((code >= 16381) && (code <= 16383)) ? (code - 16142) - : 16384 - 16142); + : ((code >= 0) && (code <= 213)) ? (code - 0) + : ((code >= 222) && (code <= 254)) ? (code - 8) + : ((code >= 257) && (code <= 271)) ? (code - 10) + : ((code >= 273) && (code <= 281)) ? (code - 11) + : ((code >= 1024) && (code <= 1039)) ? (code - 753) + : ((code >= 16381) && (code <= 16383)) ? (code - 16094) + : 16384 - 16094); } diff --git a/plugins/MirOTR/Libgpg-error/err-codes.h b/plugins/MirOTR/Libgpg-error/err-codes.h index 17ecc9c670..64ff57d215 100644 --- a/plugins/MirOTR/Libgpg-error/err-codes.h +++ b/plugins/MirOTR/Libgpg-error/err-codes.h @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -103,7 +103,7 @@ static const char msgstr[] = gettext_noop ("Incomplete line") "\0" gettext_noop ("Invalid response") "\0" gettext_noop ("No agent running") "\0" - gettext_noop ("agent error") "\0" + gettext_noop ("Agent error") "\0" gettext_noop ("Invalid data") "\0" gettext_noop ("Unspecific Assuan server fault") "\0" gettext_noop ("General Assuan error") "\0" @@ -209,6 +209,21 @@ static const char msgstr[] = gettext_noop ("Missing key") "\0" gettext_noop ("Too many objects") "\0" gettext_noop ("Limit reached") "\0" + gettext_noop ("Not initialized") "\0" + gettext_noop ("Missing issuer certificate") "\0" + gettext_noop ("No keyserver available") "\0" + gettext_noop ("Invalid elliptic curve") "\0" + gettext_noop ("Unknown elliptic curve") "\0" + gettext_noop ("Duplicated key") "\0" + gettext_noop ("Ambiguous result") "\0" + gettext_noop ("No crypto context") "\0" + gettext_noop ("Wrong crypto context") "\0" + gettext_noop ("Bad crypto context") "\0" + gettext_noop ("Conflict in the crypto context") "\0" + gettext_noop ("Broken public key") "\0" + gettext_noop ("Broken secret key") "\0" + gettext_noop ("Invalid MAC algorithm") "\0" + gettext_noop ("Operation fully cancelled") "\0" gettext_noop ("Operation not yet finished") "\0" gettext_noop ("Buffer too short") "\0" gettext_noop ("Invalid length specifier in S-expression") "\0" @@ -224,6 +239,39 @@ static const char msgstr[] = gettext_noop ("Bad hexadecimal character in S-expression") "\0" gettext_noop ("Odd hexadecimal numbers in S-expression") "\0" gettext_noop ("Bad octal character in S-expression") "\0" + gettext_noop ("Legacy key") "\0" + gettext_noop ("Request too short") "\0" + gettext_noop ("Request too long") "\0" + gettext_noop ("Object is in termination state") "\0" + gettext_noop ("No certificate chain") "\0" + gettext_noop ("Certificate is too large") "\0" + gettext_noop ("Invalid record") "\0" + gettext_noop ("The MAC does not verify") "\0" + gettext_noop ("Unexpected message") "\0" + gettext_noop ("Compression or decompression failed") "\0" + gettext_noop ("A counter would wrap") "\0" + gettext_noop ("Fatal alert message received") "\0" + gettext_noop ("No cipher algorithm") "\0" + gettext_noop ("Missing client certificate") "\0" + gettext_noop ("Close notification received") "\0" + gettext_noop ("Ticket expired") "\0" + gettext_noop ("Bad ticket") "\0" + gettext_noop ("Unknown identity") "\0" + gettext_noop ("Bad certificate message in handshake") "\0" + gettext_noop ("Bad certificate request message in handshake") "\0" + gettext_noop ("Bad certificate verify message in handshake") "\0" + gettext_noop ("Bad change cipher messsage in handshake") "\0" + gettext_noop ("Bad client hello message in handshake") "\0" + gettext_noop ("Bad server hello message in handshake") "\0" + gettext_noop ("Bad server hello done message in hanshake") "\0" + gettext_noop ("Bad finished message in handshake") "\0" + gettext_noop ("Bad server key exchange message in handshake") "\0" + gettext_noop ("Bad client key exchange message in handshake") "\0" + gettext_noop ("Bogus string") "\0" + gettext_noop ("Forbidden") "\0" + gettext_noop ("Key disabled") "\0" + gettext_noop ("Not possible with a card based key") "\0" + gettext_noop ("Invalid lock object") "\0" gettext_noop ("General IPC error") "\0" gettext_noop ("IPC accept call failed") "\0" gettext_noop ("IPC connect call failed") "\0" @@ -456,75 +504,123 @@ static const int msgidx[] = 3127, 3144, 3158, - 3185, - 3202, - 3243, - 3275, - 3313, - 3340, - 3370, - 3400, - 3428, - 3465, - 3489, - 3537, - 3579, - 3619, - 3655, - 3673, - 3696, - 3720, - 3741, - 3769, - 3799, - 3827, - 3847, - 3871, - 3898, - 3916, - 3934, - 3962, - 3977, - 3993, - 4021, - 4044, - 4064, - 4081, - 4109, - 4133, - 4158, - 4178, - 4198, - 4224, - 4250, - 4276, - 4302, - 4328, - 4354, - 4380, - 4406, - 4432, - 4459, - 4486, - 4513, - 4540, - 4567, - 4594, - 4621, - 4644, - 4665, - 4677 + 3174, + 3201, + 3224, + 3247, + 3270, + 3285, + 3302, + 3320, + 3341, + 3360, + 3391, + 3409, + 3427, + 3449, + 3475, + 3502, + 3519, + 3560, + 3592, + 3630, + 3657, + 3687, + 3717, + 3745, + 3782, + 3806, + 3854, + 3896, + 3936, + 3972, + 3983, + 4001, + 4018, + 4049, + 4070, + 4095, + 4110, + 4134, + 4153, + 4189, + 4210, + 4239, + 4259, + 4286, + 4314, + 4329, + 4340, + 4357, + 4394, + 4439, + 4483, + 4523, + 4561, + 4599, + 4641, + 4675, + 4720, + 4765, + 4778, + 4788, + 4801, + 4836, + 4856, + 4874, + 4897, + 4921, + 4942, + 4970, + 5000, + 5028, + 5048, + 5072, + 5099, + 5117, + 5135, + 5163, + 5178, + 5194, + 5222, + 5245, + 5265, + 5282, + 5310, + 5334, + 5359, + 5379, + 5399, + 5425, + 5451, + 5477, + 5503, + 5529, + 5555, + 5581, + 5607, + 5633, + 5660, + 5687, + 5714, + 5741, + 5768, + 5795, + 5822, + 5845, + 5866, + 5878 }; -static inline int +static GPG_ERR_INLINE int msgidxof (int code) { return (0 ? 0 - : ((code >= 0) && (code <= 183)) ? (code - 0) - : ((code >= 199) && (code <= 213)) ? (code - 15) - : ((code >= 257) && (code <= 271)) ? (code - 58) - : ((code >= 273) && (code <= 281)) ? (code - 59) - : ((code >= 1024) && (code <= 1039)) ? (code - 801) - : ((code >= 16381) && (code <= 16383)) ? (code - 16142) - : 16384 - 16142); + : ((code >= 0) && (code <= 213)) ? (code - 0) + : ((code >= 222) && (code <= 254)) ? (code - 8) + : ((code >= 257) && (code <= 271)) ? (code - 10) + : ((code >= 273) && (code <= 281)) ? (code - 11) + : ((code >= 1024) && (code <= 1039)) ? (code - 753) + : ((code >= 16381) && (code <= 16383)) ? (code - 16094) + : 16384 - 16094); } diff --git a/plugins/MirOTR/Libgpg-error/err-codes.h.in b/plugins/MirOTR/Libgpg-error/err-codes.h.in deleted file mode 100644 index 8b40861644..0000000000 --- a/plugins/MirOTR/Libgpg-error/err-codes.h.in +++ /dev/null @@ -1,298 +0,0 @@ -# err-codes.h.in - List of error codes and their description input file. -/* err-codes.h - List of error codes and their description. - Copyright (C) 2003, 2004 g10 Code GmbH - - This file is part of libgpg-error. - - libgpg-error 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. - - libgpg-error 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 libgpg-error; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -# Everything up to the first line that starts with a number in the -# first column is copied into the output verbatim. Then, empty lines -# are ignored. Other lines must have an error code number, followed -# by one or more <tab> characters, followed by the error code symbol, -# followed by one or more <tab> characters, followed by the error -# message. Trailing whitespace is removed. The error codes should be -# sorted. The last line should not have a number, but only a <tab>, -# followed by a dummy field, followed by a <tab>, followed by a -# description for error codes that are not in the list. - -0 GPG_ERR_NO_ERROR Success -1 GPG_ERR_GENERAL General error -2 GPG_ERR_UNKNOWN_PACKET Unknown packet -3 GPG_ERR_UNKNOWN_VERSION Unknown version in packet -4 GPG_ERR_PUBKEY_ALGO Invalid public key algorithm -5 GPG_ERR_DIGEST_ALGO Invalid digest algorithm -6 GPG_ERR_BAD_PUBKEY Bad public key -7 GPG_ERR_BAD_SECKEY Bad secret key -8 GPG_ERR_BAD_SIGNATURE Bad signature -9 GPG_ERR_NO_PUBKEY No public key -10 GPG_ERR_CHECKSUM Checksum error -11 GPG_ERR_BAD_PASSPHRASE Bad passphrase -12 GPG_ERR_CIPHER_ALGO Invalid cipher algorithm -13 GPG_ERR_KEYRING_OPEN Keyring open -14 GPG_ERR_INV_PACKET Invalid packet -15 GPG_ERR_INV_ARMOR Invalid armor -16 GPG_ERR_NO_USER_ID No user ID -17 GPG_ERR_NO_SECKEY No secret key -18 GPG_ERR_WRONG_SECKEY Wrong secret key used -19 GPG_ERR_BAD_KEY Bad session key -20 GPG_ERR_COMPR_ALGO Unknown compression algorithm -21 GPG_ERR_NO_PRIME Number is not prime -22 GPG_ERR_NO_ENCODING_METHOD Invalid encoding method -23 GPG_ERR_NO_ENCRYPTION_SCHEME Invalid encryption scheme -24 GPG_ERR_NO_SIGNATURE_SCHEME Invalid signature scheme -25 GPG_ERR_INV_ATTR Invalid attribute -26 GPG_ERR_NO_VALUE No value -27 GPG_ERR_NOT_FOUND Not found -28 GPG_ERR_VALUE_NOT_FOUND Value not found -29 GPG_ERR_SYNTAX Syntax error -30 GPG_ERR_BAD_MPI Bad MPI value -31 GPG_ERR_INV_PASSPHRASE Invalid passphrase -32 GPG_ERR_SIG_CLASS Invalid signature class -33 GPG_ERR_RESOURCE_LIMIT Resources exhausted -34 GPG_ERR_INV_KEYRING Invalid keyring -35 GPG_ERR_TRUSTDB Trust DB error -36 GPG_ERR_BAD_CERT Bad certificate -37 GPG_ERR_INV_USER_ID Invalid user ID -38 GPG_ERR_UNEXPECTED Unexpected error -39 GPG_ERR_TIME_CONFLICT Time conflict -40 GPG_ERR_KEYSERVER Keyserver error -41 GPG_ERR_WRONG_PUBKEY_ALGO Wrong public key algorithm -42 GPG_ERR_TRIBUTE_TO_D_A Tribute to D. A. -43 GPG_ERR_WEAK_KEY Weak encryption key -44 GPG_ERR_INV_KEYLEN Invalid key length -45 GPG_ERR_INV_ARG Invalid argument -46 GPG_ERR_BAD_URI Syntax error in URI -47 GPG_ERR_INV_URI Invalid URI -48 GPG_ERR_NETWORK Network error -49 GPG_ERR_UNKNOWN_HOST Unknown host -50 GPG_ERR_SELFTEST_FAILED Selftest failed -51 GPG_ERR_NOT_ENCRYPTED Data not encrypted -52 GPG_ERR_NOT_PROCESSED Data not processed -53 GPG_ERR_UNUSABLE_PUBKEY Unusable public key -54 GPG_ERR_UNUSABLE_SECKEY Unusable secret key -55 GPG_ERR_INV_VALUE Invalid value -56 GPG_ERR_BAD_CERT_CHAIN Bad certificate chain -57 GPG_ERR_MISSING_CERT Missing certificate -58 GPG_ERR_NO_DATA No data -59 GPG_ERR_BUG Bug -60 GPG_ERR_NOT_SUPPORTED Not supported -61 GPG_ERR_INV_OP Invalid operation code -62 GPG_ERR_TIMEOUT Timeout -63 GPG_ERR_INTERNAL Internal error -64 GPG_ERR_EOF_GCRYPT EOF (gcrypt) -65 GPG_ERR_INV_OBJ Invalid object -66 GPG_ERR_TOO_SHORT Provided object is too short -67 GPG_ERR_TOO_LARGE Provided object is too large -68 GPG_ERR_NO_OBJ Missing item in object -69 GPG_ERR_NOT_IMPLEMENTED Not implemented -70 GPG_ERR_CONFLICT Conflicting use -71 GPG_ERR_INV_CIPHER_MODE Invalid cipher mode -72 GPG_ERR_INV_FLAG Invalid flag -73 GPG_ERR_INV_HANDLE Invalid handle -74 GPG_ERR_TRUNCATED Result truncated -75 GPG_ERR_INCOMPLETE_LINE Incomplete line -76 GPG_ERR_INV_RESPONSE Invalid response -77 GPG_ERR_NO_AGENT No agent running -78 GPG_ERR_AGENT agent error -79 GPG_ERR_INV_DATA Invalid data -80 GPG_ERR_ASSUAN_SERVER_FAULT Unspecific Assuan server fault -81 GPG_ERR_ASSUAN General Assuan error -82 GPG_ERR_INV_SESSION_KEY Invalid session key -83 GPG_ERR_INV_SEXP Invalid S-expression -84 GPG_ERR_UNSUPPORTED_ALGORITHM Unsupported algorithm -85 GPG_ERR_NO_PIN_ENTRY No pinentry -86 GPG_ERR_PIN_ENTRY pinentry error -87 GPG_ERR_BAD_PIN Bad PIN -88 GPG_ERR_INV_NAME Invalid name -89 GPG_ERR_BAD_DATA Bad data -90 GPG_ERR_INV_PARAMETER Invalid parameter -91 GPG_ERR_WRONG_CARD Wrong card -92 GPG_ERR_NO_DIRMNGR No dirmngr -93 GPG_ERR_DIRMNGR dirmngr error -94 GPG_ERR_CERT_REVOKED Certificate revoked -95 GPG_ERR_NO_CRL_KNOWN No CRL known -96 GPG_ERR_CRL_TOO_OLD CRL too old -97 GPG_ERR_LINE_TOO_LONG Line too long -98 GPG_ERR_NOT_TRUSTED Not trusted -99 GPG_ERR_CANCELED Operation cancelled -100 GPG_ERR_BAD_CA_CERT Bad CA certificate -101 GPG_ERR_CERT_EXPIRED Certificate expired -102 GPG_ERR_CERT_TOO_YOUNG Certificate too young -103 GPG_ERR_UNSUPPORTED_CERT Unsupported certificate -104 GPG_ERR_UNKNOWN_SEXP Unknown S-expression -105 GPG_ERR_UNSUPPORTED_PROTECTION Unsupported protection -106 GPG_ERR_CORRUPTED_PROTECTION Corrupted protection -107 GPG_ERR_AMBIGUOUS_NAME Ambiguous name -108 GPG_ERR_CARD Card error -109 GPG_ERR_CARD_RESET Card reset required -110 GPG_ERR_CARD_REMOVED Card removed -111 GPG_ERR_INV_CARD Invalid card -112 GPG_ERR_CARD_NOT_PRESENT Card not present -113 GPG_ERR_NO_PKCS15_APP No PKCS15 application -114 GPG_ERR_NOT_CONFIRMED Not confirmed -115 GPG_ERR_CONFIGURATION Configuration error -116 GPG_ERR_NO_POLICY_MATCH No policy match -117 GPG_ERR_INV_INDEX Invalid index -118 GPG_ERR_INV_ID Invalid ID -119 GPG_ERR_NO_SCDAEMON No SmartCard daemon -120 GPG_ERR_SCDAEMON SmartCard daemon error -121 GPG_ERR_UNSUPPORTED_PROTOCOL Unsupported protocol -122 GPG_ERR_BAD_PIN_METHOD Bad PIN method -123 GPG_ERR_CARD_NOT_INITIALIZED Card not initialized -124 GPG_ERR_UNSUPPORTED_OPERATION Unsupported operation -125 GPG_ERR_WRONG_KEY_USAGE Wrong key usage -126 GPG_ERR_NOTHING_FOUND Nothing found -127 GPG_ERR_WRONG_BLOB_TYPE Wrong blob type -128 GPG_ERR_MISSING_VALUE Missing value -129 GPG_ERR_HARDWARE Hardware problem -130 GPG_ERR_PIN_BLOCKED PIN blocked -131 GPG_ERR_USE_CONDITIONS Conditions of use not satisfied -132 GPG_ERR_PIN_NOT_SYNCED PINs are not synced -133 GPG_ERR_INV_CRL Invalid CRL -134 GPG_ERR_BAD_BER BER error -135 GPG_ERR_INV_BER Invalid BER -136 GPG_ERR_ELEMENT_NOT_FOUND Element not found -137 GPG_ERR_IDENTIFIER_NOT_FOUND Identifier not found -138 GPG_ERR_INV_TAG Invalid tag -139 GPG_ERR_INV_LENGTH Invalid length -140 GPG_ERR_INV_KEYINFO Invalid key info -141 GPG_ERR_UNEXPECTED_TAG Unexpected tag -142 GPG_ERR_NOT_DER_ENCODED Not DER encoded -143 GPG_ERR_NO_CMS_OBJ No CMS object -144 GPG_ERR_INV_CMS_OBJ Invalid CMS object -145 GPG_ERR_UNKNOWN_CMS_OBJ Unknown CMS object -146 GPG_ERR_UNSUPPORTED_CMS_OBJ Unsupported CMS object -147 GPG_ERR_UNSUPPORTED_ENCODING Unsupported encoding -148 GPG_ERR_UNSUPPORTED_CMS_VERSION Unsupported CMS version -149 GPG_ERR_UNKNOWN_ALGORITHM Unknown algorithm -150 GPG_ERR_INV_ENGINE Invalid crypto engine -151 GPG_ERR_PUBKEY_NOT_TRUSTED Public key not trusted -152 GPG_ERR_DECRYPT_FAILED Decryption failed -153 GPG_ERR_KEY_EXPIRED Key expired -154 GPG_ERR_SIG_EXPIRED Signature expired -155 GPG_ERR_ENCODING_PROBLEM Encoding problem -156 GPG_ERR_INV_STATE Invalid state -157 GPG_ERR_DUP_VALUE Duplicated value -158 GPG_ERR_MISSING_ACTION Missing action -159 GPG_ERR_MODULE_NOT_FOUND ASN.1 module not found -160 GPG_ERR_INV_OID_STRING Invalid OID string -161 GPG_ERR_INV_TIME Invalid time -162 GPG_ERR_INV_CRL_OBJ Invalid CRL object -163 GPG_ERR_UNSUPPORTED_CRL_VERSION Unsupported CRL version -164 GPG_ERR_INV_CERT_OBJ Invalid certificate object -165 GPG_ERR_UNKNOWN_NAME Unknown name -166 GPG_ERR_LOCALE_PROBLEM A locale function failed -167 GPG_ERR_NOT_LOCKED Not locked -168 GPG_ERR_PROTOCOL_VIOLATION Protocol violation -169 GPG_ERR_INV_MAC Invalid MAC -170 GPG_ERR_INV_REQUEST Invalid request -171 GPG_ERR_UNKNOWN_EXTN Unknown extension -172 GPG_ERR_UNKNOWN_CRIT_EXTN Unknown critical extension -173 GPG_ERR_LOCKED Locked -174 GPG_ERR_UNKNOWN_OPTION Unknown option -175 GPG_ERR_UNKNOWN_COMMAND Unknown command -176 GPG_ERR_NOT_OPERATIONAL Not operational -177 GPG_ERR_NO_PASSPHRASE No passphrase given -178 GPG_ERR_NO_PIN No PIN given -179 GPG_ERR_NOT_ENABLED Not enabled -180 GPG_ERR_NO_ENGINE No crypto engine -181 GPG_ERR_MISSING_KEY Missing key -182 GPG_ERR_TOO_MANY Too many objects -183 GPG_ERR_LIMIT_REACHED Limit reached -# 184 to 198 are free to be used. - -199 GPG_ERR_UNFINISHED Operation not yet finished -200 GPG_ERR_BUFFER_TOO_SHORT Buffer too short - -# Error codes pertaining to S-expressions. - -201 GPG_ERR_SEXP_INV_LEN_SPEC Invalid length specifier in S-expression -202 GPG_ERR_SEXP_STRING_TOO_LONG String too long in S-expression -203 GPG_ERR_SEXP_UNMATCHED_PAREN Unmatched parentheses in S-expression -204 GPG_ERR_SEXP_NOT_CANONICAL S-expression not canonical -205 GPG_ERR_SEXP_BAD_CHARACTER Bad character in S-expression -206 GPG_ERR_SEXP_BAD_QUOTATION Bad quotation in S-expression -207 GPG_ERR_SEXP_ZERO_PREFIX Zero prefix in S-expression -208 GPG_ERR_SEXP_NESTED_DH Nested display hints in S-expression -209 GPG_ERR_SEXP_UNMATCHED_DH Unmatched display hints -210 GPG_ERR_SEXP_UNEXPECTED_PUNC Unexpected reserved punctuation in S-expression -211 GPG_ERR_SEXP_BAD_HEX_CHAR Bad hexadecimal character in S-expression -212 GPG_ERR_SEXP_ODD_HEX_NUMBERS Odd hexadecimal numbers in S-expression -213 GPG_ERR_SEXP_BAD_OCT_CHAR Bad octal character in S-expression - -# 214 to 254 are free to be used. 255 and 256 are RFU. - -# Error codes pertaining to the Assuan IPC interface -257 GPG_ERR_ASS_GENERAL General IPC error -258 GPG_ERR_ASS_ACCEPT_FAILED IPC accept call failed -259 GPG_ERR_ASS_CONNECT_FAILED IPC connect call failed -260 GPG_ERR_ASS_INV_RESPONSE Invalid IPC response -261 GPG_ERR_ASS_INV_VALUE Invalid value passed to IPC -262 GPG_ERR_ASS_INCOMPLETE_LINE Incomplete line passed to IPC -263 GPG_ERR_ASS_LINE_TOO_LONG Line passed to IPC too long -264 GPG_ERR_ASS_NESTED_COMMANDS Nested IPC commands -265 GPG_ERR_ASS_NO_DATA_CB No data callback in IPC -266 GPG_ERR_ASS_NO_INQUIRE_CB No inquire callback in IPC -267 GPG_ERR_ASS_NOT_A_SERVER Not an IPC server -268 GPG_ERR_ASS_NOT_A_CLIENT Not an IPC client -269 GPG_ERR_ASS_SERVER_START Problem starting IPC server -270 GPG_ERR_ASS_READ_ERROR IPC read error -271 GPG_ERR_ASS_WRITE_ERROR IPC write error -# reserved -273 GPG_ERR_ASS_TOO_MUCH_DATA Too much data for IPC layer -274 GPG_ERR_ASS_UNEXPECTED_CMD Unexpected IPC command -275 GPG_ERR_ASS_UNKNOWN_CMD Unknown IPC command -276 GPG_ERR_ASS_SYNTAX IPC syntax error -277 GPG_ERR_ASS_CANCELED IPC call has been cancelled -278 GPG_ERR_ASS_NO_INPUT No input source for IPC -279 GPG_ERR_ASS_NO_OUTPUT No output source for IPC -280 GPG_ERR_ASS_PARAMETER IPC parameter error -281 GPG_ERR_ASS_UNKNOWN_INQUIRE Unknown IPC inquire - -# 282 to 299 are reserved for future assuan codes. - -# 300 to 1023 are free to be used. - -# For free use by non-GnuPG components. -1024 GPG_ERR_USER_1 User defined error code 1 -1025 GPG_ERR_USER_2 User defined error code 2 -1026 GPG_ERR_USER_3 User defined error code 3 -1027 GPG_ERR_USER_4 User defined error code 4 -1028 GPG_ERR_USER_5 User defined error code 5 -1029 GPG_ERR_USER_6 User defined error code 6 -1030 GPG_ERR_USER_7 User defined error code 7 -1031 GPG_ERR_USER_8 User defined error code 8 -1032 GPG_ERR_USER_9 User defined error code 9 -1033 GPG_ERR_USER_10 User defined error code 10 -1034 GPG_ERR_USER_11 User defined error code 11 -1035 GPG_ERR_USER_12 User defined error code 12 -1036 GPG_ERR_USER_13 User defined error code 13 -1037 GPG_ERR_USER_14 User defined error code 14 -1038 GPG_ERR_USER_15 User defined error code 15 -1039 GPG_ERR_USER_16 User defined error code 16 - -# 1040 to 16380 are free to be used. - -16381 GPG_ERR_MISSING_ERRNO System error w/o errno -16382 GPG_ERR_UNKNOWN_ERRNO Unknown system error -16383 GPG_ERR_EOF End of file - -# 16384 - 32767 are reserved for future extensions. - -# GPG_SYSTEM_ERROR | (141 to 32767) are to be used for system errors. - - GPG_ERR_CODE_DIM Unknown error code diff --git a/plugins/MirOTR/Libgpg-error/err-sources-sym.h b/plugins/MirOTR/Libgpg-error/err-sources-sym.h index 62b8cb1618..98388e9da3 100644 --- a/plugins/MirOTR/Libgpg-error/err-sources-sym.h +++ b/plugins/MirOTR/Libgpg-error/err-sources-sym.h @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -40,6 +40,8 @@ static const char msgstr[] = "GPG_ERR_SOURCE_GPA" "\0" "GPG_ERR_SOURCE_KLEO" "\0" "GPG_ERR_SOURCE_G13" "\0" + "GPG_ERR_SOURCE_ASSUAN" "\0" + "GPG_ERR_SOURCE_TLS" "\0" "GPG_ERR_SOURCE_ANY" "\0" "GPG_ERR_SOURCE_USER_1" "\0" "GPG_ERR_SOURCE_USER_2" "\0" @@ -65,18 +67,21 @@ static const int msgidx[] = 277, 297, 316, - 335, + 338, 357, - 379, - 401, - 423 + 376, + 398, + 420, + 442, + 464 }; -static inline int +static GPG_ERR_INLINE int msgidxof (int code) { return (0 ? 0 - : ((code >= 0) && (code <= 14)) ? (code - 0) - : ((code >= 31) && (code <= 35)) ? (code - 16) - : 36 - 16); + : ((code >= 0) && (code <= 15)) ? (code - 0) + : ((code >= 17) && (code <= 17)) ? (code - 1) + : ((code >= 31) && (code <= 35)) ? (code - 14) + : 36 - 14); } diff --git a/plugins/MirOTR/Libgpg-error/err-sources.h b/plugins/MirOTR/Libgpg-error/err-sources.h index 0fcc551e2c..5160fd791f 100644 --- a/plugins/MirOTR/Libgpg-error/err-sources.h +++ b/plugins/MirOTR/Libgpg-error/err-sources.h @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -40,6 +40,8 @@ static const char msgstr[] = gettext_noop ("GPA") "\0" gettext_noop ("Kleopatra") "\0" gettext_noop ("G13") "\0" + gettext_noop ("Assuan") "\0" + gettext_noop ("TLS") "\0" gettext_noop ("Any source") "\0" gettext_noop ("User defined source 1") "\0" gettext_noop ("User defined source 2") "\0" @@ -65,18 +67,21 @@ static const int msgidx[] = 96, 106, 110, + 117, 121, - 143, - 165, - 187, - 209 + 132, + 154, + 176, + 198, + 220 }; -static inline int +static GPG_ERR_INLINE int msgidxof (int code) { return (0 ? 0 - : ((code >= 0) && (code <= 14)) ? (code - 0) - : ((code >= 31) && (code <= 35)) ? (code - 16) - : 36 - 16); + : ((code >= 0) && (code <= 15)) ? (code - 0) + : ((code >= 17) && (code <= 17)) ? (code - 1) + : ((code >= 31) && (code <= 35)) ? (code - 14) + : 36 - 14); } diff --git a/plugins/MirOTR/Libgpg-error/err-sources.h.in b/plugins/MirOTR/Libgpg-error/err-sources.h.in deleted file mode 100644 index d200fc6c31..0000000000 --- a/plugins/MirOTR/Libgpg-error/err-sources.h.in +++ /dev/null @@ -1,58 +0,0 @@ -# err-sources.h.in - List of error sources and their description input file. -/* err-sources.h - List of error sources and their description. - Copyright (C) 2003, 2004 g10 Code GmbH - - This file is part of libgpg-error. - - libgpg-error 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. - - libgpg-error 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 libgpg-error; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -# Everything up to the first line that starts with a number in the -# first column is copied into the output verbatim. Then, empty lines -# are ignored. Other lines must have an error source number, followed -# by one or more <tab> characters, followed by the error source -# symbol, followed by one or more <tab> characters, followed by the -# error source name. Trailing whitespace is removed. The error -# sources should be sorted. The last line should not have a number, -# but only a <tab>, followed by a description for error sources that -# are not in the list. - -0 GPG_ERR_SOURCE_UNKNOWN Unspecified source -1 GPG_ERR_SOURCE_GCRYPT gcrypt -2 GPG_ERR_SOURCE_GPG GnuPG -3 GPG_ERR_SOURCE_GPGSM GpgSM -4 GPG_ERR_SOURCE_GPGAGENT GPG Agent -5 GPG_ERR_SOURCE_PINENTRY Pinentry -6 GPG_ERR_SOURCE_SCD SCD -7 GPG_ERR_SOURCE_GPGME GPGME -8 GPG_ERR_SOURCE_KEYBOX Keybox -9 GPG_ERR_SOURCE_KSBA KSBA -10 GPG_ERR_SOURCE_DIRMNGR Dirmngr -11 GPG_ERR_SOURCE_GSTI GSTI -12 GPG_ERR_SOURCE_GPA GPA -13 GPG_ERR_SOURCE_KLEO Kleopatra -14 GPG_ERR_SOURCE_G13 G13 - -# 15 to 30 are free to be used. - -31 GPG_ERR_SOURCE_ANY Any source -32 GPG_ERR_SOURCE_USER_1 User defined source 1 -33 GPG_ERR_SOURCE_USER_2 User defined source 2 -34 GPG_ERR_SOURCE_USER_3 User defined source 3 -35 GPG_ERR_SOURCE_USER_4 User defined source 4 - -# 36 to 255 are free to be used. - - GPG_ERR_SOURCE_DIM Unknown source diff --git a/plugins/MirOTR/Libgpg-error/errnos-sym.h b/plugins/MirOTR/Libgpg-error/errnos-sym.h index 8bcb8ed946..42804ae216 100644 --- a/plugins/MirOTR/Libgpg-error/errnos-sym.h +++ b/plugins/MirOTR/Libgpg-error/errnos-sym.h @@ -1,6 +1,6 @@ /* Output of mkstrtable.awk. DO NOT EDIT. */ -/* errnos.h - List of system error values. +/* errnos.in - List of system error values. Copyright (C) 2003, 2004 g10 Code GmbH This file is part of libgpg-error. @@ -9,12 +9,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -314,7 +314,7 @@ static const int errnos_msgidx[] = }; -static inline int +static GPG_ERR_INLINE int errnos_msgidxof (int code) { return (0 ? 0 diff --git a/plugins/MirOTR/Libgpg-error/errnos.in b/plugins/MirOTR/Libgpg-error/errnos.in deleted file mode 100644 index 0688047681..0000000000 --- a/plugins/MirOTR/Libgpg-error/errnos.in +++ /dev/null @@ -1,172 +0,0 @@ -# errnos.h.in - List of system error values input file. -/* errnos.h - List of system error values. - Copyright (C) 2003, 2004 g10 Code GmbH - - This file is part of libgpg-error. - - libgpg-error 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. - - libgpg-error 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 libgpg-error; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -# Everything up to the first line that starts with a number in the -# first column is copied into the output verbatim. Then, empty lines -# are ignored. Other lines must have an error code number, followed -# by one or more <tab> characters, followed by the error name. -# -# IMPORTANT: For now, the numbering must be consecutive. Some of the -# scripts (notably mkerrnos.h) do not deal correctly with a numbering -# that is out of order or has gaps. - - -0 E2BIG -1 EACCES -2 EADDRINUSE -3 EADDRNOTAVAIL -4 EADV -5 EAFNOSUPPORT -6 EAGAIN -7 EALREADY -8 EAUTH -9 EBACKGROUND -10 EBADE -11 EBADF -12 EBADFD -13 EBADMSG -14 EBADR -15 EBADRPC -16 EBADRQC -17 EBADSLT -18 EBFONT -19 EBUSY -20 ECANCELED -21 ECHILD -22 ECHRNG -23 ECOMM -24 ECONNABORTED -25 ECONNREFUSED -26 ECONNRESET -27 ED -28 EDEADLK -29 EDEADLOCK -30 EDESTADDRREQ -31 EDIED -32 EDOM -33 EDOTDOT -34 EDQUOT -35 EEXIST -36 EFAULT -37 EFBIG -38 EFTYPE -39 EGRATUITOUS -40 EGREGIOUS -41 EHOSTDOWN -42 EHOSTUNREACH -43 EIDRM -44 EIEIO -45 EILSEQ -46 EINPROGRESS -47 EINTR -48 EINVAL -49 EIO -50 EISCONN -51 EISDIR -52 EISNAM -53 EL2HLT -54 EL2NSYNC -55 EL3HLT -56 EL3RST -57 ELIBACC -58 ELIBBAD -59 ELIBEXEC -60 ELIBMAX -61 ELIBSCN -62 ELNRNG -63 ELOOP -64 EMEDIUMTYPE -65 EMFILE -66 EMLINK -67 EMSGSIZE -68 EMULTIHOP -69 ENAMETOOLONG -70 ENAVAIL -71 ENEEDAUTH -72 ENETDOWN -73 ENETRESET -74 ENETUNREACH -75 ENFILE -76 ENOANO -77 ENOBUFS -78 ENOCSI -79 ENODATA -80 ENODEV -81 ENOENT -82 ENOEXEC -83 ENOLCK -84 ENOLINK -85 ENOMEDIUM -86 ENOMEM -87 ENOMSG -88 ENONET -89 ENOPKG -90 ENOPROTOOPT -91 ENOSPC -92 ENOSR -93 ENOSTR -94 ENOSYS -95 ENOTBLK -96 ENOTCONN -97 ENOTDIR -98 ENOTEMPTY -99 ENOTNAM -100 ENOTSOCK -101 ENOTSUP -102 ENOTTY -103 ENOTUNIQ -104 ENXIO -105 EOPNOTSUPP -106 EOVERFLOW -107 EPERM -108 EPFNOSUPPORT -109 EPIPE -110 EPROCLIM -111 EPROCUNAVAIL -112 EPROGMISMATCH -113 EPROGUNAVAIL -114 EPROTO -115 EPROTONOSUPPORT -116 EPROTOTYPE -117 ERANGE -118 EREMCHG -119 EREMOTE -120 EREMOTEIO -121 ERESTART -122 EROFS -123 ERPCMISMATCH -124 ESHUTDOWN -125 ESOCKTNOSUPPORT -126 ESPIPE -127 ESRCH -128 ESRMNT -129 ESTALE -130 ESTRPIPE -131 ETIME -132 ETIMEDOUT -133 ETOOMANYREFS -134 ETXTBSY -135 EUCLEAN -136 EUNATCH -137 EUSERS -138 EWOULDBLOCK -139 EXDEV -140 EXFULL
\ No newline at end of file diff --git a/plugins/MirOTR/Libgpg-error/estream-printf.c b/plugins/MirOTR/Libgpg-error/estream-printf.c new file mode 100644 index 0000000000..39a813feef --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/estream-printf.c @@ -0,0 +1,1875 @@ +/* estream-printf.c - Versatile mostly C-99 compliant printf formatting + * Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 g10 Code GmbH + * + * This file is part of Libestream. + * + * Libestream 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. + * + * Libestream 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 Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* Required autoconf tests: + + AC_TYPE_LONG_LONG_INT defines HAVE_LONG_LONG_INT + AC_TYPE_LONG_DOUBLE defines HAVE_LONG_DOUBLE + AC_TYPE_INTMAX_T defines HAVE_INTMAX_T + AC_TYPE_UINTMAX_T defines HAVE_UINTMAX_T + AC_CHECK_TYPES([ptrdiff_t]) defines HAVE_PTRDIFF_T + AC_CHECK_SIZEOF([unsigned long]) defines SIZEOF_UNSIGNED_LONG + AC_CHECK_SIZEOF([void *]) defines SIZEOF_VOID_P + HAVE_LANGINFO_THOUSANDS_SEP + + Note that the file estream.m4 provides the autoconf macro + ESTREAM_PRINTF_INIT which runs all required checks. + See estream-printf.h for ways to tune this code. + + Missing stuff: wchar and wint_t + thousands_sep in pr_float. + +*/ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#if defined(_WIN32) && !defined(HAVE_W32_SYSTEM) +# define HAVE_W32_SYSTEM 1 +# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM) +# define HAVE_W32CE_SYSTEM +# endif +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <stdarg.h> +#include <errno.h> +#include <stddef.h> +#include <assert.h> +#if defined(HAVE_INTMAX_T) || defined(HAVE_UINTMAX_T) +# ifdef HAVE_STDINT_H +# include <stdint.h> +# endif +#endif +#ifdef HAVE_LANGINFO_THOUSANDS_SEP +#include <langinfo.h> +#endif +#ifdef HAVE_W32CE_SYSTEM +#include <gpg-error.h> /* ERRNO replacement. */ +#endif +#ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE +# include _ESTREAM_PRINTF_EXTRA_INCLUDE +#endif +#include "estream-printf.h" + +/* #define DEBUG 1 */ + + +/* Allow redefinition of asprintf used realloc function. */ +#if defined(_ESTREAM_PRINTF_REALLOC) +#define my_printf_realloc(a,b) _ESTREAM_PRINTF_REALLOC((a),(b)) +#else +#define my_printf_realloc(a,b) fixed_realloc((a),(b)) +#endif + +/* A wrapper to set ERRNO. */ +#ifdef HAVE_W32CE_SYSTEM +# define _set_errno(a) gpg_err_set_errno ((a)) +#else +# define _set_errno(a) do { errno = (a); } while (0) +#endif + + +/* Calculate array dimension. */ +#ifndef DIM +#define DIM(array) (sizeof (array) / sizeof (*array)) +#endif + + +/* We allow for that many args without requiring malloced memory. */ +#define DEFAULT_MAX_ARGSPECS 5 + +/* We allow for that many values without requiring malloced memory. */ +#define DEFAULT_MAX_VALUES 8 + +/* We allocate this many new array argspec elements each time. */ +#define ARGSPECS_BUMP_VALUE 10 + +/* Special values for the field width and the precision. */ +#define NO_FIELD_VALUE (-1) +#define STAR_FIELD_VALUE (-2) + +/* Bit valuues used for the conversion flags. */ +#define FLAG_GROUPING 1 +#define FLAG_LEFT_JUST 2 +#define FLAG_PLUS_SIGN 4 +#define FLAG_SPACE_PLUS 8 +#define FLAG_ALT_CONV 16 +#define FLAG_ZERO_PAD 32 + +/* Constants used the length modifiers. */ +typedef enum + { + LENMOD_NONE = 0, + LENMOD_CHAR, /* "hh" */ + LENMOD_SHORT, /* "h" */ + LENMOD_LONG, /* "l" */ + LENMOD_LONGLONG, /* "ll" */ + LENMOD_INTMAX, /* "j" */ + LENMOD_SIZET, /* "z" */ + LENMOD_PTRDIFF, /* "t" */ + LENMOD_LONGDBL /* "L" */ + } lenmod_t; + +/* All the conversion specifiers. */ +typedef enum + { + CONSPEC_UNKNOWN = 0, + CONSPEC_DECIMAL, + CONSPEC_OCTAL, + CONSPEC_UNSIGNED, + CONSPEC_HEX, + CONSPEC_HEX_UP, + CONSPEC_FLOAT, + CONSPEC_FLOAT_UP, + CONSPEC_EXP, + CONSPEC_EXP_UP, + CONSPEC_F_OR_G, + CONSPEC_F_OR_G_UP, + CONSPEC_HEX_EXP, + CONSPEC_HEX_EXP_UP, + CONSPEC_CHAR, + CONSPEC_STRING, + CONSPEC_POINTER, + CONSPEC_STRERROR, + CONSPEC_BYTES_SO_FAR + } conspec_t; + + +/* Constants describing all the suppoorted types. Note that we list + all the types we know about even if certain types are not available + on this system. */ +typedef enum + { + VALTYPE_UNSUPPORTED = 0, /* Artificial type for error detection. */ + VALTYPE_CHAR, + VALTYPE_SCHAR, + VALTYPE_UCHAR, + VALTYPE_SHORT, + VALTYPE_USHORT, + VALTYPE_INT, + VALTYPE_UINT, + VALTYPE_LONG, + VALTYPE_ULONG, + VALTYPE_LONGLONG, + VALTYPE_ULONGLONG, + VALTYPE_DOUBLE, + VALTYPE_LONGDOUBLE, + VALTYPE_STRING, + VALTYPE_INTMAX, + VALTYPE_UINTMAX, + VALTYPE_SIZE, + VALTYPE_PTRDIFF, + VALTYPE_POINTER, + VALTYPE_CHAR_PTR, + VALTYPE_SCHAR_PTR, + VALTYPE_SHORT_PTR, + VALTYPE_INT_PTR, + VALTYPE_LONG_PTR, + VALTYPE_LONGLONG_PTR, + VALTYPE_INTMAX_PTR, + VALTYPE_SIZE_PTR, + VALTYPE_PTRDIFF_PTR + } valtype_t; + + +/* A union used to store the actual values. */ +typedef union +{ + char a_char; + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_long; + unsigned long int a_ulong; +#ifdef HAVE_LONG_LONG_INT + long long int a_longlong; + unsigned long long int a_ulonglong; +#endif + double a_double; +#ifdef HAVE_LONG_DOUBLE + long double a_longdouble; +#endif + const char *a_string; +#ifdef HAVE_INTMAX_T + intmax_t a_intmax; +#endif +#ifdef HAVE_UINTMAX_T + intmax_t a_uintmax; +#endif + size_t a_size; +#ifdef HAVE_PTRDIFF_T + ptrdiff_t a_ptrdiff; +#endif + void *a_void_ptr; + char *a_char_ptr; + signed char *a_schar_ptr; + short *a_short_ptr; + int *a_int_ptr; + long *a_long_ptr; +#ifdef HAVE_LONG_LONG_INT + long long int *a_longlong_ptr; +#endif +#ifdef HAVE_INTMAX_T + intmax_t *a_intmax_ptr; +#endif + size_t *a_size_ptr; +#ifdef HAVE_PTRDIFF_T + ptrdiff_t *a_ptrdiff_ptr; +#endif +} value_t; + +/* An object used to keep track of a format option and arguments. */ +struct argspec_s +{ + size_t length; /* The length of these args including the percent. */ + unsigned int flags; /* The conversion flags (bits defined by FLAG_foo). */ + int width; /* The field width. */ + int precision; /* The precision. */ + lenmod_t lenmod; /* The length modifier. */ + conspec_t conspec; /* The conversion specifier. */ + int arg_pos; /* The position of the argument. This one may + be -1 to indicate that no value is expected + (e.g. for "%m"). */ + int width_pos; /* The position of the argument for a field + width star's value. 0 for not used. */ + int precision_pos; /* The position of the argument for the a + precision star's value. 0 for not used. */ + valtype_t vt; /* The type of the corresponding argument. */ +}; +typedef struct argspec_s *argspec_t; + +/* An object to build up a table of values and their types. */ +struct valueitem_s +{ + valtype_t vt; /* The type of the value. */ + value_t value; /* The value. */ +}; +typedef struct valueitem_s *valueitem_t; + + +/* Not all systems have a C-90 compliant realloc. To cope with this + we use this simple wrapper. */ +#ifndef _ESTREAM_PRINTF_REALLOC +static void * +fixed_realloc (void *a, size_t n) +{ + if (!a) + return malloc (n); + + if (!n) + { + free (a); + return NULL; + } + + return realloc (a, n); +} +#endif /*!_ESTREAM_PRINTF_REALLOC*/ + + +#ifdef DEBUG +static void +dump_argspecs (argspec_t arg, size_t argcount) +{ + int idx; + + for (idx=0; argcount; argcount--, arg++, idx++) + fprintf (stderr, + "%2d: len=%u flags=%u width=%d prec=%d mod=%d " + "con=%d vt=%d pos=%d-%d-%d\n", + idx, + (unsigned int)arg->length, + arg->flags, + arg->width, + arg->precision, + arg->lenmod, + arg->conspec, + arg->vt, + arg->arg_pos, + arg->width_pos, + arg->precision_pos); +} +#endif /*DEBUG*/ + + +/* Set the vt field for ARG. */ +static void +compute_type (argspec_t arg) +{ + switch (arg->conspec) + { + case CONSPEC_UNKNOWN: + arg->vt = VALTYPE_UNSUPPORTED; + break; + + case CONSPEC_DECIMAL: + switch (arg->lenmod) + { + case LENMOD_CHAR: arg->vt = VALTYPE_SCHAR; break; + case LENMOD_SHORT: arg->vt = VALTYPE_SHORT; break; + case LENMOD_LONG: arg->vt = VALTYPE_LONG; break; + case LENMOD_LONGLONG: arg->vt = VALTYPE_LONGLONG; break; + case LENMOD_INTMAX: arg->vt = VALTYPE_INTMAX; break; + case LENMOD_SIZET: arg->vt = VALTYPE_SIZE; break; + case LENMOD_PTRDIFF: arg->vt = VALTYPE_PTRDIFF; break; + default: arg->vt = VALTYPE_INT; break; + } + break; + + case CONSPEC_OCTAL: + case CONSPEC_UNSIGNED: + case CONSPEC_HEX: + case CONSPEC_HEX_UP: + switch (arg->lenmod) + { + case LENMOD_CHAR: arg->vt = VALTYPE_UCHAR; break; + case LENMOD_SHORT: arg->vt = VALTYPE_USHORT; break; + case LENMOD_LONG: arg->vt = VALTYPE_ULONG; break; + case LENMOD_LONGLONG: arg->vt = VALTYPE_ULONGLONG; break; + case LENMOD_INTMAX: arg->vt = VALTYPE_UINTMAX; break; + case LENMOD_SIZET: arg->vt = VALTYPE_SIZE; break; + case LENMOD_PTRDIFF: arg->vt = VALTYPE_PTRDIFF; break; + default: arg->vt = VALTYPE_UINT; break; + } + break; + + case CONSPEC_FLOAT: + case CONSPEC_FLOAT_UP: + case CONSPEC_EXP: + case CONSPEC_EXP_UP: + case CONSPEC_F_OR_G: + case CONSPEC_F_OR_G_UP: + case CONSPEC_HEX_EXP: + case CONSPEC_HEX_EXP_UP: + switch (arg->lenmod) + { + case LENMOD_LONGDBL: arg->vt = VALTYPE_LONGDOUBLE; break; + case LENMOD_LONG: arg->vt = VALTYPE_DOUBLE; break; + default: arg->vt = VALTYPE_DOUBLE; break; + } + break; + + case CONSPEC_CHAR: + arg->vt = VALTYPE_INT; + break; + + case CONSPEC_STRING: + arg->vt = VALTYPE_STRING; + break; + + case CONSPEC_POINTER: + arg->vt = VALTYPE_POINTER; + break; + + case CONSPEC_STRERROR: + arg->vt = VALTYPE_STRING; + break; + + case CONSPEC_BYTES_SO_FAR: + switch (arg->lenmod) + { + case LENMOD_CHAR: arg->vt = VALTYPE_SCHAR_PTR; break; + case LENMOD_SHORT: arg->vt = VALTYPE_SHORT_PTR; break; + case LENMOD_LONG: arg->vt = VALTYPE_LONG_PTR; break; + case LENMOD_LONGLONG: arg->vt = VALTYPE_LONGLONG_PTR; break; + case LENMOD_INTMAX: arg->vt = VALTYPE_INTMAX_PTR; break; + case LENMOD_SIZET: arg->vt = VALTYPE_SIZE_PTR; break; + case LENMOD_PTRDIFF: arg->vt = VALTYPE_PTRDIFF_PTR; break; + default: arg->vt = VALTYPE_INT_PTR; break; + } + break; + + } +} + + + +/* Parse the FORMAT string and populate the specification array stored + at the address ARGSPECS_ADDR. The caller has provided enough space + to store up to MAX_ARGSPECS in that buffer. The function may + however ignore the provided buffer and malloc a larger one. On + success the address of that larger buffer will be stored at + ARGSPECS_ADDR. The actual number of specifications will be + returned at R_ARGSPECS_COUNT. */ +static int +parse_format (const char *format, + argspec_t *argspecs_addr, size_t max_argspecs, + size_t *r_argspecs_count) +{ + const char *s; + argspec_t argspecs = *argspecs_addr; + argspec_t arg; + size_t argcount = 0; + + if (!format) + goto leave_einval; + + for (; *format; format++) + { + unsigned int flags; + int width, precision; + lenmod_t lenmod; + conspec_t conspec; + int arg_pos, width_pos, precision_pos; + + if (*format != '%') + continue; + s = ++format; + if (!*s) + goto leave_einval; + if (*s == '%') + continue; /* Just a quoted percent. */ + + /* First check whether there is a positional argument. */ + arg_pos = 0; /* No positional argument given. */ + if (*s >= '1' && *s <= '9') + { + const char *save_s = s; + + arg_pos = (*s++ - '0'); + for (; *s >= '0' && *s <= '9'; s++) + arg_pos = 10*arg_pos + (*s - '0'); + if (arg_pos < 0) + goto leave_einval; /* Overflow during conversion. */ + if (*s == '$') + s++; + else + { + arg_pos = 0; + s = save_s; + } + } + + /* Parse the flags. */ + flags = 0; + for ( ; *s; s++) + { + switch (*s) + { + case '\'': flags |= FLAG_GROUPING; break; + case '-': flags |= FLAG_LEFT_JUST; break; + case '+': flags |= FLAG_PLUS_SIGN; break; + case ' ': flags |= FLAG_SPACE_PLUS; break; + case '#': flags |= FLAG_ALT_CONV; break; + case '0': flags |= FLAG_ZERO_PAD; break; + default: + goto flags_parsed; + } + } + flags_parsed: + + /* Parse the field width. */ + width_pos = 0; + if (*s == '*') + { + width = STAR_FIELD_VALUE; + s++; + /* If we have a positional argument, another one might also + be used to give the position of the star's value. */ + if (arg_pos && *s >= '1' && *s <= '9') + { + width_pos = (*s++ - '0'); + for (; *s >= '0' && *s <= '9'; s++) + width_pos = 10*width_pos + (*s - '0'); + if (width_pos < 1) + goto leave_einval; /* Overflow during conversion. */ + if (*s != '$') + goto leave_einval; /* Not followed by $. */ + s++; + } + } + else if ( *s >= '0' && *s <= '9') + { + width = (*s++ - '0'); + for (; *s >= '0' && *s <= '9'; s++) + { + if (!width && *s == '0') + goto leave_einval; /* Leading zeroes are not allowed. + Fixme: check what other + implementations do. */ + width = 10*width + (*s - '0'); + } + if (width < 0) + goto leave_einval; /* Overflow during conversion. */ + } + else + width = NO_FIELD_VALUE; + + /* Parse the precision. */ + precision_pos = 0; + precision = NO_FIELD_VALUE; + if (*s == '.') + { + int ignore_value = (s[1] == '-'); + + s++; + if (*s == '*') + { + precision = STAR_FIELD_VALUE; + s++; + /* If we have a positional argument, another one might also + be used to give the position of the star's value. */ + if (arg_pos && *s >= '1' && *s <= '9') + { + precision_pos = (*s++ - '0'); + for (; *s >= '0' && *s <= '9'; s++) + precision_pos = 10*precision_pos + (*s - '0'); + if (precision_pos < 1) + goto leave_einval; /* Overflow during conversion. */ + if (*s != '$') + goto leave_einval; /* Not followed by $. */ + s++; + } + } + else if ( *s >= '0' && *s <= '9') + { + precision = (*s++ - '0'); + for (; *s >= '0' && *s <= '9'; s++) + { + if (!precision && *s == '0') + goto leave_einval; /* Leading zeroes are not allowed. + Fixme: check what other + implementations do. */ + precision = 10*precision + (*s - '0'); + } + if (precision < 0) + goto leave_einval; /* Overflow during conversion. */ + } + else + precision = 0; + if (ignore_value) + precision = NO_FIELD_VALUE; + } + + /* Parse the length modifiers. */ + switch (*s) + { + case 'h': + if (s[1] == 'h') + { + lenmod = LENMOD_CHAR; + s++; + } + else + lenmod = LENMOD_SHORT; + s++; + break; + case 'l': + if (s[1] == 'l') + { + lenmod = LENMOD_LONGLONG; + s++; + } + else + lenmod = LENMOD_LONG; + s++; + break; + case 'j': lenmod = LENMOD_INTMAX; s++; break; + case 'z': lenmod = LENMOD_SIZET; s++; break; + case 't': lenmod = LENMOD_PTRDIFF; s++; break; + case 'L': lenmod = LENMOD_LONGDBL; s++; break; + default: lenmod = LENMOD_NONE; break; + } + + /* Parse the conversion specifier. */ + switch (*s) + { + case 'd': + case 'i': conspec = CONSPEC_DECIMAL; break; + case 'o': conspec = CONSPEC_OCTAL; break; + case 'u': conspec = CONSPEC_UNSIGNED; break; + case 'x': conspec = CONSPEC_HEX; break; + case 'X': conspec = CONSPEC_HEX_UP; break; + case 'f': conspec = CONSPEC_FLOAT; break; + case 'F': conspec = CONSPEC_FLOAT_UP; break; + case 'e': conspec = CONSPEC_EXP; break; + case 'E': conspec = CONSPEC_EXP_UP; break; + case 'g': conspec = CONSPEC_F_OR_G; break; + case 'G': conspec = CONSPEC_F_OR_G_UP; break; + case 'a': conspec = CONSPEC_HEX_EXP; break; + case 'A': conspec = CONSPEC_HEX_EXP_UP; break; + case 'c': conspec = CONSPEC_CHAR; break; + case 's': conspec = CONSPEC_STRING; break; + case 'p': conspec = CONSPEC_POINTER; break; + case 'n': conspec = CONSPEC_BYTES_SO_FAR; break; + case 'C': conspec = CONSPEC_CHAR; lenmod = LENMOD_LONG; break; + case 'S': conspec = CONSPEC_STRING; lenmod = LENMOD_LONG; break; + case 'm': conspec = CONSPEC_STRERROR; arg_pos = -1; break; + default: conspec = CONSPEC_UNKNOWN; + } + + /* Save the args. */ + if (argcount >= max_argspecs) + { + /* We either need to allocate a new array instead of the + caller provided one or realloc the array. Instead of + using realloc we allocate a new one and release the + original one then. */ + size_t n, newmax; + argspec_t newarg; + + newmax = max_argspecs + ARGSPECS_BUMP_VALUE; + if (newmax <= max_argspecs) + goto leave_einval; /* Too many arguments. */ + newarg = calloc (newmax, sizeof *newarg); + if (!newarg) + goto leave; + for (n=0; n < argcount; n++) + newarg[n] = argspecs[n]; + if (argspecs != *argspecs_addr) + free (argspecs); + argspecs = newarg; + max_argspecs = newmax; + } + + arg = argspecs + argcount; + arg->length = s - format + 2; + arg->flags = flags; + arg->width = width; + arg->precision = precision; + arg->lenmod = lenmod; + arg->conspec = conspec; + arg->arg_pos = arg_pos; + arg->width_pos = width_pos; + arg->precision_pos = precision_pos; + compute_type (arg); + argcount++; + format = s; + } + + *argspecs_addr = argspecs; + *r_argspecs_count = argcount; + return 0; /* Success. */ + + leave_einval: + _set_errno (EINVAL); + leave: + if (argspecs != *argspecs_addr) + free (argspecs); + *argspecs_addr = NULL; + return -1; +} + + +/* This function reads all the values as specified by VALUETABLE into + VALUETABLE. The values are expected in VAARGS. The function + returns -1 if a specified type is not supported. */ +static int +read_values (valueitem_t valuetable, size_t valuetable_len, va_list vaargs) +{ + int validx; + + for (validx=0; validx < valuetable_len; validx++) + { + value_t *value = &valuetable[validx].value; + valtype_t vt = valuetable[validx].vt; + + switch (vt) + { + case VALTYPE_CHAR: value->a_char = va_arg (vaargs, int); break; + case VALTYPE_CHAR_PTR: + value->a_char_ptr = va_arg (vaargs, char *); + break; + case VALTYPE_SCHAR: value->a_schar = va_arg (vaargs, int); break; + case VALTYPE_SCHAR_PTR: + value->a_schar_ptr = va_arg (vaargs, signed char *); + break; + case VALTYPE_UCHAR: value->a_uchar = va_arg (vaargs, int); break; + case VALTYPE_SHORT: value->a_short = va_arg (vaargs, int); break; + case VALTYPE_USHORT: value->a_ushort = va_arg (vaargs, int); break; + case VALTYPE_SHORT_PTR: + value->a_short_ptr = va_arg (vaargs, short *); + break; + case VALTYPE_INT: + value->a_int = va_arg (vaargs, int); + break; + case VALTYPE_INT_PTR: + value->a_int_ptr = va_arg (vaargs, int *); + break; + case VALTYPE_UINT: + value->a_uint = va_arg (vaargs, unsigned int); + break; + case VALTYPE_LONG: + value->a_long = va_arg (vaargs, long); + break; + case VALTYPE_ULONG: + value->a_ulong = va_arg (vaargs, unsigned long); + break; + case VALTYPE_LONG_PTR: + value->a_long_ptr = va_arg (vaargs, long *); + break; +#ifdef HAVE_LONG_LONG_INT + case VALTYPE_LONGLONG: + value->a_longlong = va_arg (vaargs, long long int); + break; + case VALTYPE_ULONGLONG: + value->a_ulonglong = va_arg (vaargs, unsigned long long int); + break; + case VALTYPE_LONGLONG_PTR: + value->a_longlong_ptr = va_arg (vaargs, long long *); + break; +#endif + case VALTYPE_DOUBLE: + value->a_double = va_arg (vaargs, double); + break; +#ifdef HAVE_LONG_DOUBLE + case VALTYPE_LONGDOUBLE: + value->a_longdouble = va_arg (vaargs, long double); + break; +#endif + case VALTYPE_STRING: + value->a_string = va_arg (vaargs, const char *); + break; + case VALTYPE_POINTER: + value->a_void_ptr = va_arg (vaargs, void *); + break; +#ifdef HAVE_INTMAX_T + case VALTYPE_INTMAX: + value->a_intmax = va_arg (vaargs, intmax_t); + break; + case VALTYPE_INTMAX_PTR: + value->a_intmax_ptr = va_arg (vaargs, intmax_t *); + break; +#endif +#ifdef HAVE_UINTMAX_T + case VALTYPE_UINTMAX: + value->a_uintmax = va_arg (vaargs, uintmax_t); + break; +#endif + case VALTYPE_SIZE: + value->a_size = va_arg (vaargs, size_t); + break; + case VALTYPE_SIZE_PTR: + value->a_size_ptr = va_arg (vaargs, size_t *); + break; +#ifdef HAVE_PTRDIFF_T + case VALTYPE_PTRDIFF: + value->a_ptrdiff = va_arg (vaargs, ptrdiff_t); + break; + case VALTYPE_PTRDIFF_PTR: + value->a_ptrdiff_ptr = va_arg (vaargs, ptrdiff_t *); + break; +#endif + default: /* Unsupported type. */ + return -1; + } + } + return 0; +} + + + +/* Output COUNT padding characters PADCHAR and update NBYTES by the + number of bytes actually written. */ +static int +pad_out (estream_printf_out_t outfnc, void *outfncarg, + int padchar, int count, size_t *nbytes) +{ + char buf[32]; + size_t n; + int rc; + + while (count > 0) + { + n = (count <= sizeof buf)? count : sizeof buf; + memset (buf, padchar, n); + rc = outfnc (outfncarg, buf, n); + if (rc) + return rc; + *nbytes += n; + count -= n; + } + + return 0; +} + + +/* "d,i,o,u,x,X" formatting. OUTFNC and OUTFNCARG describes the + output routine, ARG gives the argument description and VALUE the + actual value (its type is available through arg->vt). */ +static int +pr_integer (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + int rc; +#ifdef HAVE_LONG_LONG_INT + unsigned long long aulong; +#else + unsigned long aulong; +#endif + char numbuf[100]; + char *p, *pend; + size_t n; + char signchar = 0; + int n_prec; /* Number of extra precision digits required. */ + int n_extra; /* Extra number of prefix or sign characters. */ + + if (arg->conspec == CONSPEC_DECIMAL) + { +#ifdef HAVE_LONG_LONG_INT + long long along; +#else + long along; +#endif + + switch (arg->vt) + { + case VALTYPE_SHORT: along = value.a_short; break; + case VALTYPE_INT: along = value.a_int; break; + case VALTYPE_LONG: along = value.a_long; break; +#ifdef HAVE_LONG_LONG_INT + case VALTYPE_LONGLONG: along = value.a_longlong; break; + case VALTYPE_SIZE: along = value.a_size; break; +# ifdef HAVE_INTMAX_T + case VALTYPE_INTMAX: along = value.a_intmax; break; +# endif +# ifdef HAVE_PTRDIFF_T + case VALTYPE_PTRDIFF: along = value.a_ptrdiff; break; +# endif +#endif /*HAVE_LONG_LONG_INT*/ + default: + return -1; + } + if (along < 0) + { + aulong = -along; + signchar = '-'; + } + else + aulong = along; + } + else + { + switch (arg->vt) + { + case VALTYPE_USHORT: aulong = value.a_ushort; break; + case VALTYPE_UINT: aulong = value.a_uint; break; + case VALTYPE_ULONG: aulong = value.a_ulong; break; +#ifdef HAVE_LONG_LONG_INT + case VALTYPE_ULONGLONG: aulong = value.a_ulonglong; break; + case VALTYPE_SIZE: aulong = value.a_size; break; +# ifdef HAVE_UINTMAX_T + case VALTYPE_UINTMAX: aulong = value.a_uintmax; break; +# endif +# ifdef HAVE_PTRDIFF_T + case VALTYPE_PTRDIFF: aulong = value.a_ptrdiff; break; +# endif +#endif /*HAVE_LONG_LONG_INT*/ + default: + return -1; + } + } + + if (signchar == '-') + ; + else if ((arg->flags & FLAG_PLUS_SIGN)) + signchar = '+'; + else if ((arg->flags & FLAG_SPACE_PLUS)) + signchar = ' '; + + n_extra = !!signchar; + + /* We build the string up backwards. */ + p = pend = numbuf + DIM(numbuf); + if ((!aulong && !arg->precision)) + ; + else if (arg->conspec == CONSPEC_DECIMAL + || arg->conspec == CONSPEC_UNSIGNED) + { + int grouping = -1; + const char * grouping_string = +#ifdef HAVE_LANGINFO_THOUSANDS_SEP + nl_langinfo(THOUSANDS_SEP); +#else + "'"; +#endif + + do + { + if ((arg->flags & FLAG_GROUPING) + && (++grouping == 3) && *grouping_string) + { + *--p = *grouping_string; + grouping = 0; + } + *--p = '0' + (aulong % 10); + aulong /= 10; + } + while (aulong); + } + else if (arg->conspec == CONSPEC_OCTAL) + { + do + { + *--p = '0' + (aulong % 8); + aulong /= 8; + } + while (aulong); + if ((arg->flags & FLAG_ALT_CONV) && *p != '0') + *--p = '0'; + } + else /* HEX or HEXUP */ + { + const char *digits = ((arg->conspec == CONSPEC_HEX) + ? "0123456789abcdef" : "0123456789ABCDEF"); + do + { + *--p = digits[(aulong % 16)]; + aulong /= 16; + } + while (aulong); + if ((arg->flags & FLAG_ALT_CONV)) + n_extra += 2; + } + + n = pend - p; + + if ((arg->flags & FLAG_ZERO_PAD) + && arg->precision == NO_FIELD_VALUE && !(arg->flags & FLAG_LEFT_JUST) + && n && arg->width - n_extra > n ) + n_prec = arg->width - n_extra - n; + else if (arg->precision > 0 && arg->precision > n) + n_prec = arg->precision - n; + else + n_prec = 0; + + if (!(arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width - n_extra > n + && arg->width - n_extra - n >= n_prec ) + { + rc = pad_out (outfnc, outfncarg, ' ', + arg->width - n_extra - n - n_prec, nbytes); + if (rc) + return rc; + } + + if (signchar) + { + rc = outfnc (outfncarg, &signchar, 1); + if (rc) + return rc; + *nbytes += 1; + } + + if ((arg->flags & FLAG_ALT_CONV) + && (arg->conspec == CONSPEC_HEX || arg->conspec == CONSPEC_HEX_UP)) + { + rc = outfnc (outfncarg, arg->conspec == CONSPEC_HEX? "0x": "0X", 2); + if (rc) + return rc; + *nbytes += 2; + } + + if (n_prec) + { + rc = pad_out (outfnc, outfncarg, '0', n_prec, nbytes); + if (rc) + return rc; + } + + rc = outfnc (outfncarg, p, pend - p); + if (rc) + return rc; + *nbytes += pend - p; + + if ((arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width - n_extra - n_prec > n) + { + rc = pad_out (outfnc, outfncarg, ' ', + arg->width - n_extra - n_prec - n, nbytes); + if (rc) + return rc; + } + + return 0; +} + + +/* "e,E,f,F,g,G,a,A" formatting. OUTFNC and OUTFNCARG describes the + output routine, ARG gives the argument description and VALUE the + actual value (its type is available through arg->vt). For + portability reasons sprintf is used for the actual formatting. + This is useful because sprint is the only standard function to + convert a floating number into its ascii representation. To avoid + using malloc we just pass the precision to sprintf and do the final + formatting with our own code. */ +static int +pr_float (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + int rc; +#ifdef HAVE_LONG_DOUBLE + long double adblfloat = 0; /* Just to please gcc. */ + int use_dbl = 0; +#endif + double afloat; + char numbuf[350]; + char formatstr[20]; + char *p, *pend; + size_t n; + char signchar = 0; + int n_extra; /* Extra number of prefix or sign characters. */ + + switch (arg->vt) + { + case VALTYPE_DOUBLE: afloat = value.a_double; break; +#ifdef HAVE_LONG_DOUBLE + case VALTYPE_LONGDOUBLE: + afloat = 0; /* Just to please gcc. */ + adblfloat = value.a_longdouble; + use_dbl=1; break; +#endif + default: + return -1; + } + + /* We build the string using sprint. */ + p = formatstr + sizeof formatstr; + *--p = 0; + switch (arg->conspec) + { + case CONSPEC_FLOAT: *--p = 'f'; break; + case CONSPEC_FLOAT_UP: *--p = 'F'; break; + case CONSPEC_EXP: *--p = 'e'; break; + case CONSPEC_EXP_UP: *--p = 'E'; break; + case CONSPEC_F_OR_G: *--p = 'g'; break; + case CONSPEC_F_OR_G_UP: *--p = 'G'; break; + case CONSPEC_HEX_EXP: *--p = 'a'; break; + case CONSPEC_HEX_EXP_UP: *--p = 'A'; break; + default: + return -1; /* Actually a bug. */ + } +#ifdef HAVE_LONG_DOUBLE + if (use_dbl) + *--p = 'L'; +#endif + if (arg->precision != NO_FIELD_VALUE) + { + /* Limit it to a meaningful value so that even a stupid sprintf + won't overflow our buffer. */ + n = arg->precision <= 100? arg->precision : 100; + do + { + *--p = '0' + (n % 10); + n /= 10; + } + while (n); + *--p = '.'; + } + if ((arg->flags & FLAG_ALT_CONV)) + *--p = '#'; + *--p = '%'; +#ifdef HAVE_LONG_DOUBLE + if (use_dbl) + sprintf (numbuf, p, adblfloat); + else +#endif /*HAVE_LONG_DOUBLE*/ + sprintf (numbuf, p, afloat); + p = numbuf; + n = strlen (numbuf); + pend = p + n; + + if (*p =='-') + { + signchar = '-'; + p++; + n--; + } + else if ((arg->flags & FLAG_PLUS_SIGN)) + signchar = '+'; + else if ((arg->flags & FLAG_SPACE_PLUS)) + signchar = ' '; + + n_extra = !!signchar; + + if (!(arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width - n_extra > n) + { + rc = pad_out (outfnc, outfncarg, ' ', arg->width - n_extra - n, nbytes); + if (rc) + return rc; + } + + if (signchar) + { + rc = outfnc (outfncarg, &signchar, 1); + if (rc) + return rc; + *nbytes += 1; + } + + rc = outfnc (outfncarg, p, pend - p); + if (rc) + return rc; + *nbytes += pend - p; + + if ((arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width - n_extra > n) + { + rc = pad_out (outfnc, outfncarg, ' ', arg->width - n_extra - n, nbytes); + if (rc) + return rc; + } + + return 0; +} + + +/* "c" formatting. */ +static int +pr_char (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + int rc; + char buf[1]; + + if (arg->vt != VALTYPE_INT) + return -1; + buf[0] = (unsigned int)value.a_int; + rc = outfnc (outfncarg, buf, 1); + if(rc) + return rc; + *nbytes += 1; + + return 0; +} + + +/* "s" formatting. */ +static int +pr_string (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + int rc; + size_t n; + const char *string, *s; + + if (arg->vt != VALTYPE_STRING) + return -1; + string = value.a_string; + if (!string) + string = "(null)"; + if (arg->precision >= 0) + { + /* Test for nul after N so that we can pass a non-nul terminated + string. */ + for (n=0,s=string; n < arg->precision && *s; s++) + n++; + } + else + n = strlen (string); + + if (!(arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width > n ) + { + rc = pad_out (outfnc, outfncarg, ' ', arg->width - n, nbytes); + if (rc) + return rc; + } + + rc = outfnc (outfncarg, string, n); + if (rc) + return rc; + *nbytes += n; + + if ((arg->flags & FLAG_LEFT_JUST) + && arg->width >= 0 && arg->width > n) + { + rc = pad_out (outfnc, outfncarg, ' ', arg->width - n, nbytes); + if (rc) + return rc; + } + + return 0; +} + + +/* "p" formatting. */ +static int +pr_pointer (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + int rc; +#if defined(HAVE_LONG_LONG_INT) && (SIZEOF_UNSIGNED_LONG < SIZEOF_VOID_P) + unsigned long long aulong; +#else + unsigned long aulong; +#endif + char numbuf[100]; + char *p, *pend; + + if (arg->vt != VALTYPE_POINTER) + return -1; + /* We assume that a pointer can be converted to an unsigned long. + That is not correct for a 64 bit Windows, but then we assume that + long long is supported and usable for storing a pointer. */ +#if defined(HAVE_LONG_LONG_INT) && (SIZEOF_UNSIGNED_LONG < SIZEOF_VOID_P) + aulong = (unsigned long long)value.a_void_ptr; +#else + aulong = (unsigned long)value.a_void_ptr; +#endif + + p = pend = numbuf + DIM(numbuf); + do + { + *--p = "0123456789abcdefx"[(aulong % 16)]; + aulong /= 16; + } + while (aulong); + while ((pend-p) < 2*sizeof (aulong)) + *--p = '0'; + *--p = 'x'; + *--p = '0'; + + rc = outfnc (outfncarg, p, pend - p); + if (rc) + return rc; + *nbytes += pend - p; + + return 0; +} + +/* "n" pesudo format operation. */ +static int +pr_bytes_so_far (estream_printf_out_t outfnc, void *outfncarg, + argspec_t arg, value_t value, size_t *nbytes) +{ + (void)outfnc; + (void)outfncarg; + + switch (arg->vt) + { + case VALTYPE_SCHAR_PTR: + *value.a_schar_ptr = (signed char)(unsigned int)(*nbytes); + break; + case VALTYPE_SHORT_PTR: + *value.a_short_ptr = (short)(unsigned int)(*nbytes); + break; + case VALTYPE_LONG_PTR: + *value.a_long_ptr = (long)(*nbytes); + break; +#ifdef HAVE_LONG_LONG_INT + case VALTYPE_LONGLONG_PTR: + *value.a_longlong_ptr = (long long)(*nbytes); + break; +#endif +#ifdef HAVE_INTMAX_T + case VALTYPE_INTMAX_PTR: + *value.a_intmax_ptr = (intmax_t)(*nbytes); + break; +#endif + case VALTYPE_SIZE_PTR: + *value.a_size_ptr = (*nbytes); + break; +#ifdef HAVE_PTRDIFF_T + case VALTYPE_PTRDIFF_PTR: + *value.a_ptrdiff_ptr = (ptrdiff_t)(*nbytes); + break; +#endif + case VALTYPE_INT_PTR: + *value.a_int_ptr = (int)(*nbytes); + break; + default: + return -1; /* An unsupported type has been used. */ + } + + return 0; +} + + + +/* Run the actual formatting. OUTFNC and OUTFNCARG are the output + functions. FORMAT is format string ARGSPECS is the parsed format + string, ARGSPECS_LEN the number of items in ARGSPECS. VALUETABLE + holds the values and may be directly addressed using the position + arguments given by ARGSPECS. MYERRNO is used for the "%m" + conversion. NBYTES well be updated to reflect the number of bytes + send to the output function. */ +static int +do_format (estream_printf_out_t outfnc, void *outfncarg, + const char *format, argspec_t argspecs, size_t argspecs_len, + valueitem_t valuetable, int myerrno, size_t *nbytes) +{ + int rc = 0; + const char *s; + argspec_t arg = argspecs; + int argidx = 0; /* Only used for assertion. */ + size_t n; + value_t value; + + s = format; + while ( *s ) + { + if (*s != '%') + { + s++; + continue; + } + if (s != format) + { + rc = outfnc (outfncarg, format, (n=s-format)); + if (rc) + return rc; + *nbytes += n; + } + if (s[1] == '%') + { + /* Note that this code ignores one trailing percent escape - + this is however okay as the args parser must have + detected this already. */ + rc = outfnc (outfncarg, s, 1); + if (rc) + return rc; + *nbytes += 1; + s += 2; + format = s; + continue; + } + + /* Save the next start. */ + s += arg->length; + format = s; + + assert (argidx < argspecs_len); + argidx++; + + /* Apply indirect field width and precision values. */ + if (arg->width == STAR_FIELD_VALUE) + { + assert (valuetable[arg->width_pos-1].vt == VALTYPE_INT); + arg->width = valuetable[arg->width_pos-1].value.a_int; + if (arg->width < 0) + { + arg->width = -arg->width; + arg->flags |= FLAG_LEFT_JUST; + } + } + if (arg->precision == STAR_FIELD_VALUE) + { + assert (valuetable[arg->precision_pos-1].vt == VALTYPE_INT); + arg->precision = valuetable[arg->precision_pos-1].value.a_int; + if (arg->precision < 0) + arg->precision = NO_FIELD_VALUE; + } + + if (arg->arg_pos == -1 && arg->conspec == CONSPEC_STRERROR) + value.a_string = strerror (myerrno); + else + { + assert (arg->vt == valuetable[arg->arg_pos-1].vt); + value = valuetable[arg->arg_pos-1].value; + } + + switch (arg->conspec) + { + case CONSPEC_UNKNOWN: assert (!"bug"); break; + + case CONSPEC_DECIMAL: + case CONSPEC_UNSIGNED: + case CONSPEC_OCTAL: + case CONSPEC_HEX: + case CONSPEC_HEX_UP: + rc = pr_integer (outfnc, outfncarg, arg, value, nbytes); + break; + case CONSPEC_FLOAT: + case CONSPEC_FLOAT_UP: + case CONSPEC_EXP: + case CONSPEC_EXP_UP: + case CONSPEC_F_OR_G: + case CONSPEC_F_OR_G_UP: + case CONSPEC_HEX_EXP: + case CONSPEC_HEX_EXP_UP: + rc = pr_float (outfnc, outfncarg, arg, value, nbytes); + break; + case CONSPEC_CHAR: + rc = pr_char (outfnc, outfncarg, arg, value, nbytes); + break; + case CONSPEC_STRING: + case CONSPEC_STRERROR: + rc = pr_string (outfnc, outfncarg, arg, value, nbytes); + break; + case CONSPEC_POINTER: + rc = pr_pointer (outfnc, outfncarg, arg, value, nbytes); + break; + case CONSPEC_BYTES_SO_FAR: + rc = pr_bytes_so_far (outfnc, outfncarg, arg, value, nbytes); + break; + } + if (rc) + return rc; + arg++; + } + + /* Print out any trailing stuff. */ + n = s - format; + rc = n? outfnc (outfncarg, format, n) : 0; + if (!rc) + *nbytes += n; + + return rc; +} + + + + +/* The versatile printf formatting routine. It expects a callback + function OUTFNC and an opaque argument OUTFNCARG used for actual + output of the formatted stuff. FORMAT is the format specification + and VAARGS a variable argumemt list matching the arguments of + FORMAT. */ +int +_gpgrt_estream_format (estream_printf_out_t outfnc, + void *outfncarg, + const char *format, va_list vaargs) +{ + /* Buffer to hold the argspecs and a pointer to it.*/ + struct argspec_s argspecs_buffer[DEFAULT_MAX_ARGSPECS]; + argspec_t argspecs = argspecs_buffer; + size_t argspecs_len; /* Number of specifications in ARGSPECS. */ + + /* Buffer to hold the description for the values. */ + struct valueitem_s valuetable_buffer[DEFAULT_MAX_VALUES]; + valueitem_t valuetable = valuetable_buffer; + + int rc; /* Return code. */ + size_t argidx; /* Used to index the argspecs array. */ + size_t validx; /* Used to index the valuetable. */ + int max_pos;/* Highest argument position. */ + + size_t nbytes = 0; /* Keep track of the number of bytes passed to + the output function. */ + + int myerrno = errno; /* Save the errno for use with "%m". */ + + + /* Parse the arguments to come up with descriptive list. We can't + do this on the fly because we need to support positional + arguments. */ + rc = parse_format (format, &argspecs, DIM(argspecs_buffer), &argspecs_len); + if (rc) + goto leave; + + /* Check that all ARG_POS fields are set. */ + for (argidx=0,max_pos=0; argidx < argspecs_len; argidx++) + { + if (argspecs[argidx].arg_pos != -1 + && argspecs[argidx].arg_pos > max_pos) + max_pos = argspecs[argidx].arg_pos; + if (argspecs[argidx].width_pos > max_pos) + max_pos = argspecs[argidx].width_pos; + if (argspecs[argidx].precision_pos > max_pos) + max_pos = argspecs[argidx].precision_pos; + } + if (!max_pos) + { + /* Fill in all the positions. */ + for (argidx=0; argidx < argspecs_len; argidx++) + { + if (argspecs[argidx].width == STAR_FIELD_VALUE) + argspecs[argidx].width_pos = ++max_pos; + if (argspecs[argidx].precision == STAR_FIELD_VALUE) + argspecs[argidx].precision_pos = ++max_pos; + if (argspecs[argidx].arg_pos != -1 ) + argspecs[argidx].arg_pos = ++max_pos; + } + } + else + { + /* Check that they are all filled. More test are done later. */ + for (argidx=0; argidx < argspecs_len; argidx++) + { + if (!argspecs[argidx].arg_pos + || (argspecs[argidx].width == STAR_FIELD_VALUE + && !argspecs[argidx].width_pos) + || (argspecs[argidx].precision == STAR_FIELD_VALUE + && !argspecs[argidx].precision_pos)) + goto leave_einval; + } + } + /* Check that there is no overflow in max_pos and that it has a + reasonable length. There may never be more elements than the + number of characters in FORMAT. */ + if (max_pos < 0 || max_pos >= strlen (format)) + goto leave_einval; + +#ifdef DEBUG + dump_argspecs (argspecs, argspecs_len); +#endif + + /* Allocate a table to hold the values. If it is small enough we + use a stack allocated buffer. */ + if (max_pos > DIM(valuetable_buffer)) + { + valuetable = calloc (max_pos, sizeof *valuetable); + if (!valuetable) + goto leave_error; + } + else + { + for (validx=0; validx < DIM(valuetable_buffer); validx++) + valuetable[validx].vt = VALTYPE_UNSUPPORTED; + } + for (argidx=0; argidx < argspecs_len; argidx++) + { + if (argspecs[argidx].arg_pos != - 1) + { + validx = argspecs[argidx].arg_pos - 1; + if (valuetable[validx].vt) + goto leave_einval; /* Already defined. */ + valuetable[validx].vt = argspecs[argidx].vt; + } + if (argspecs[argidx].width == STAR_FIELD_VALUE) + { + validx = argspecs[argidx].width_pos - 1; + if (valuetable[validx].vt) + goto leave_einval; /* Already defined. */ + valuetable[validx].vt = VALTYPE_INT; + } + if (argspecs[argidx].precision == STAR_FIELD_VALUE) + { + validx = argspecs[argidx].precision_pos - 1; + if (valuetable[validx].vt) + goto leave_einval; /* Already defined. */ + valuetable[validx].vt = VALTYPE_INT; + } + } + + /* Read all the arguments. This will error out for unsupported + types and for not given positional arguments. */ + rc = read_values (valuetable, max_pos, vaargs); + if (rc) + goto leave_einval; + +/* for (validx=0; validx < max_pos; validx++) */ +/* fprintf (stderr, "%2d: vt=%d\n", validx, valuetable[validx].vt); */ + + /* Everything has been collected, go ahead with the formatting. */ + rc = do_format (outfnc, outfncarg, format, + argspecs, argspecs_len, valuetable, myerrno, &nbytes); + + goto leave; + + leave_einval: + _set_errno (EINVAL); + leave_error: + rc = -1; + leave: + if (valuetable != valuetable_buffer) + free (valuetable); + if (argspecs != argspecs_buffer) + free (argspecs); + return rc; +} + + + + +/* A simple output handler utilizing stdio. */ +static int +plain_stdio_out (void *outfncarg, const char *buf, size_t buflen) +{ + FILE *fp = (FILE*)outfncarg; + + if ( fwrite (buf, buflen, 1, fp) != 1 ) + return -1; + return 0; +} + + +/* A replacement for printf. */ +int +_gpgrt_estream_printf (const char *format, ...) +{ + int rc; + va_list arg_ptr; + + va_start (arg_ptr, format); + rc = _gpgrt_estream_format (plain_stdio_out, stderr, format, arg_ptr); + va_end (arg_ptr); + + return rc; +} + +/* A replacement for fprintf. */ +int +_gpgrt_estream_fprintf (FILE *fp, const char *format, ...) +{ + int rc; + va_list arg_ptr; + + va_start (arg_ptr, format); + rc = _gpgrt_estream_format (plain_stdio_out, fp, format, arg_ptr); + va_end (arg_ptr); + + return rc; +} + +/* A replacement for vfprintf. */ +int +_gpgrt_estream_vfprintf (FILE *fp, const char *format, va_list arg_ptr) +{ + return _gpgrt_estream_format (plain_stdio_out, fp, format, arg_ptr); +} + + + +/* Communication object used between estream_snprintf and + fixed_buffer_out. */ +struct fixed_buffer_parm_s +{ + size_t size; /* Size of the buffer. */ + size_t count; /* Number of bytes requested for output. */ + size_t used; /* Used size of the buffer. */ + char *buffer; /* Provided buffer. */ +}; + +/* A simple malloced buffer output handler. */ +static int +fixed_buffer_out (void *outfncarg, const char *buf, size_t buflen) +{ + struct fixed_buffer_parm_s *parm = outfncarg; + + parm->count += buflen; + + if (!parm->buffer) + ; + else if (parm->used + buflen < parm->size) + { + /* Handle the common case that everything fits into the buffer + separately. */ + memcpy (parm->buffer + parm->used, buf, buflen); + parm->used += buflen; + } + else + { + /* The slow version of above. */ + for ( ;buflen && parm->used < parm->size; buflen--) + parm->buffer[parm->used++] = *buf++; + } + + return 0; +} + + +/* A replacement for vsnprintf. */ +int +_gpgrt_estream_vsnprintf (char *buf, size_t bufsize, + const char *format, va_list arg_ptr) +{ + struct fixed_buffer_parm_s parm; + int rc; + + parm.size = bufsize; + parm.count = 0; + parm.used = 0; + parm.buffer = bufsize?buf:NULL; + rc = _gpgrt_estream_format (fixed_buffer_out, &parm, format, arg_ptr); + if (!rc) + rc = fixed_buffer_out (&parm, "", 1); /* Print terminating Nul. */ + if (rc == -1) + return -1; + if (bufsize && buf && parm.size && parm.count >= parm.size) + buf[parm.size-1] = 0; + + parm.count--; /* Do not count the trailing nul. */ + return (int)parm.count; /* Return number of bytes which would have + been written. */ +} + +/* A replacement for snprintf. */ +int +_gpgrt_estream_snprintf (char *buf, size_t bufsize, const char *format, ...) +{ + int rc; + va_list arg_ptr; + + va_start (arg_ptr, format); + rc = _gpgrt_estream_vsnprintf (buf, bufsize, format, arg_ptr); + va_end (arg_ptr); + + return rc; +} + + + +/* Communication object used between estream_asprintf and + dynamic_buffer_out. */ +struct dynamic_buffer_parm_s +{ + int error_flag; /* Internal helper. */ + size_t alloced; /* Allocated size of the buffer. */ + size_t used; /* Used size of the buffer. */ + char *buffer; /* Malloced buffer. */ +}; + +/* A simple malloced buffer output handler. */ +static int +dynamic_buffer_out (void *outfncarg, const char *buf, size_t buflen) +{ + struct dynamic_buffer_parm_s *parm = outfncarg; + + if (parm->error_flag) + { + /* Just in case some formatting routine did not checked for an + error. */ + _set_errno (parm->error_flag); + return -1; + } + + if (parm->used + buflen >= parm->alloced) + { + char *p; + + parm->alloced += buflen + 512; + p = my_printf_realloc (parm->buffer, parm->alloced); + if (!p) + { + parm->error_flag = errno ? errno : ENOMEM; + /* Wipe out what we already accumulated. This is useful in + case sensitive data is formated. */ + memset (parm->buffer, 0, parm->used); + return -1; + } + parm->buffer = p; + } + memcpy (parm->buffer + parm->used, buf, buflen); + parm->used += buflen; + + return 0; +} + + +/* A replacement for vasprintf. As with the BSD version of vasprintf + -1 will be returned on error and NULL stored at BUFP. On success + the number of bytes printed will be returned. */ +int +_gpgrt_estream_vasprintf (char **bufp, const char *format, va_list arg_ptr) +{ + struct dynamic_buffer_parm_s parm; + int rc; + + parm.error_flag = 0; + parm.alloced = 512; + parm.used = 0; + parm.buffer = my_printf_realloc (NULL, parm.alloced); + if (!parm.buffer) + { + *bufp = NULL; + return -1; + } + + rc = _gpgrt_estream_format (dynamic_buffer_out, &parm, format, arg_ptr); + if (!rc) + rc = dynamic_buffer_out (&parm, "", 1); /* Print terminating Nul. */ + /* Fixme: Should we shrink the resulting buffer? */ + if (rc != -1 && parm.error_flag) + { + rc = -1; + _set_errno (parm.error_flag); + } + if (rc == -1) + { + memset (parm.buffer, 0, parm.used); + if (parm.buffer) + my_printf_realloc (parm.buffer, 0); + *bufp = NULL; + return -1; + } + assert (parm.used); /* We have at least the terminating Nul. */ + *bufp = parm.buffer; + return parm.used - 1; /* Do not include that Nul. */ +} + +/* A replacement for asprintf. As with the BSD of asprintf version -1 + will be returned on error and NULL stored at BUFP. On success the + number of bytes printed will be returned. */ +int +_gpgrt_estream_asprintf (char **bufp, const char *format, ...) +{ + int rc; + va_list arg_ptr; + + va_start (arg_ptr, format); + rc = _gpgrt_estream_vasprintf (bufp, format, arg_ptr); + va_end (arg_ptr); + + return rc; +} + +/* A variant of asprintf. The function returns the allocated buffer + or NULL on error; ERRNO is set in the error case. The caller + should use es_free to release the buffer. This function actually + belongs into estream-printf but we put it here as a convenience + and because es_free is required anyway. */ +char * +_gpgrt_estream_bsprintf (const char *format, ...) +{ + int rc; + va_list ap; + char *buf; + + va_start (ap, format); + rc = _gpgrt_estream_vasprintf (&buf, format, ap); + va_end (ap); + if (rc < 0) + return NULL; + return buf; +} diff --git a/plugins/MirOTR/Libgpg-error/estream-printf.h b/plugins/MirOTR/Libgpg-error/estream-printf.h new file mode 100644 index 0000000000..e82d8fbcb4 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/estream-printf.h @@ -0,0 +1,151 @@ +/* estream-printf.h - Versatile mostly C-99 compliant printf formatting. + * Copyright (C) 2007, 2010, 2012 g10 Code GmbH + * + * This file is part of Libestream. + * + * Libestream 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. + * + * Libestream 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 Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ESTREAM_PRINTF_H +#define ESTREAM_PRINTF_H + +#include <stdarg.h> +#include <stdio.h> + +/* To use this file with libraries the following macro is useful: + + #define _ESTREAM_EXT_SYM_PREFIX _foo_ + + This prefixes all external symbols with "_foo_". + + For the implementation of the code (estream-printf.c) the following + macros may be used to tune the implementation for certain systems: + + #define _ESTREAM_PRINTF_REALLOC foo_realloc + + Make estream_asprintf and estream_vasprintf use foo_realloc + instead of the standard realloc to allocate memory returned to + the caller. Note that foo_realloc needs to be C-90 compliant: + foo_realloc (NULL,n) is the same as a call to malloc(n) and + foo_realloc (a, 0) is the same as a call to free (a). + + #define _ESTREAM_PRINTF_EXTRA_INCLUDE "foo.h" + + This includes the file "foo.h" which may provide prototypes for + the custom memory allocation functions. + */ + + +#ifdef _ESTREAM_EXT_SYM_PREFIX +#ifndef _ESTREAM_PREFIX +#define _ESTREAM_PREFIX1(x,y) x ## y +#define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y) +#define _ESTREAM_PREFIX(x) _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x) +#endif /*_ESTREAM_PREFIX*/ +#define estream_printf_out_t _ESTREAM_PREFIX(estream_printf_out_t) +#define estream_format _ESTREAM_PREFIX(estream_format) +#define estream_printf _ESTREAM_PREFIX(estream_printf) +#define estream_fprintf _ESTREAM_PREFIX(estream_fprintf) +#define estream_vfprintf _ESTREAM_PREFIX(estream_vfprintf) +#define estream_snprintf _ESTREAM_PREFIX(estream_snprintf) +#define estream_vsnprintf _ESTREAM_PREFIX(estream_vsnprintf) +#define estream_asprintf _ESTREAM_PREFIX(estream_asprintf) +#define estream_vasprintf _ESTREAM_PREFIX(estream_vasprintf) +#endif /*_ESTREAM_EXT_SYM_PREFIX*/ + +#ifndef _ESTREAM_GCC_A_PRINTF +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) +# define _ESTREAM_GCC_A_PRINTF( f, a ) \ + __attribute__ ((format (__gnu_printf__,f,a))) +# elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +# define _ESTREAM_GCC_A_PRINTF( f, a ) \ + __attribute__ ((format (printf,f,a))) +# else +# define _ESTREAM_GCC_A_PRINTF( f, a ) +# endif +#endif /*_ESTREAM_GCC_A_PRINTF*/ + + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + + +typedef int (*estream_printf_out_t) + (void *outfncarg, const char *buf, size_t buflen); + +int _gpgrt_estream_format (estream_printf_out_t outfnc, void *outfncarg, + const char *format, va_list vaargs) + _ESTREAM_GCC_A_PRINTF(3,0); +int _gpgrt_estream_printf (const char *format, ...) + _ESTREAM_GCC_A_PRINTF(1,2); +int _gpgrt_estream_fprintf (FILE *fp, const char *format, ... ) + _ESTREAM_GCC_A_PRINTF(2,3); +int _gpgrt_estream_vfprintf (FILE *fp, const char *format, va_list arg_ptr) + _ESTREAM_GCC_A_PRINTF(2,0); +int _gpgrt_estream_snprintf (char *buf, size_t bufsize, const char *format, ...) + _ESTREAM_GCC_A_PRINTF(3,4); +int _gpgrt_estream_vsnprintf (char *buf,size_t bufsize, + const char *format, va_list arg_ptr) + _ESTREAM_GCC_A_PRINTF(3,0); +int _gpgrt_estream_asprintf (char **bufp, const char *format, ...) + _ESTREAM_GCC_A_PRINTF(2,3); +int _gpgrt_estream_vasprintf (char **bufp, const char *format, va_list arg_ptr) + _ESTREAM_GCC_A_PRINTF(2,0); +char *_gpgrt_estream_bsprintf (const char *format, ...) + _ESTREAM_GCC_A_PRINTF(1,2); + + +#ifdef __cplusplus +} +#endif +#endif /*ESTREAM_PRINTF_H*/ diff --git a/plugins/MirOTR/Libgpg-error/estream.c b/plugins/MirOTR/Libgpg-error/estream.c new file mode 100644 index 0000000000..42609ee6eb --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/estream.c @@ -0,0 +1,4508 @@ +/* estream.c - Extended Stream I/O Library + * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011, + * 2014 g10 Code GmbH + * + * This file is part of Libestream. + * + * Libestream 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. + * + * Libestream 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 Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef USE_ESTREAM_SUPPORT_H +# include <estream-support.h> +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#if defined(_WIN32) && !defined(HAVE_W32_SYSTEM) +# define HAVE_W32_SYSTEM 1 +# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM) +# define HAVE_W32CE_SYSTEM +# endif +#endif + +#include <sys/types.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <stdarg.h> +#include <fcntl.h> +#include <errno.h> +#include <stddef.h> +#include <assert.h> +#ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include <winsock2.h> +# endif +# include <windows.h> +#endif + + +#include "gpgrt-int.h" +#include "estream-printf.h" + + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#ifdef HAVE_W32_SYSTEM +# define S_IRGRP S_IRUSR +# define S_IROTH S_IRUSR +# define S_IWGRP S_IWUSR +# define S_IWOTH S_IWUSR +# define S_IXGRP S_IXUSR +# define S_IXOTH S_IXUSR +#endif + + +#ifdef HAVE_W32CE_SYSTEM +# define _set_errno(a) gpg_err_set_errno ((a)) +/* Setmode is missing in cegcc but available since CE 5.0. */ +int _setmode (int handle, int mode); +# define setmode(a,b) _setmode ((a),(b)) +#else +# define _set_errno(a) do { errno = (a); } while (0) +#endif + +#ifdef HAVE_W32_SYSTEM +# define IS_INVALID_FD(a) ((void*)(a) == (void*)(-1)) /* ?? FIXME. */ +#else +# define IS_INVALID_FD(a) ((a) == -1) +#endif + + +/* Generally used types. */ + +typedef void *(*func_realloc_t) (void *mem, size_t size); +typedef void (*func_free_t) (void *mem); + + + + +/* Buffer management layer. */ + +#define BUFFER_BLOCK_SIZE BUFSIZ +#define BUFFER_UNREAD_SIZE 16 + + +/* A linked list to hold notification functions. */ +struct notify_list_s +{ + struct notify_list_s *next; + void (*fnc) (estream_t, void*); /* The notification function. */ + void *fnc_value; /* The value to be passed to FNC. */ +}; +typedef struct notify_list_s *notify_list_t; + + +/* A private cookie function to implement an internal IOCTL + service. */ +typedef int (*cookie_ioctl_function_t) (void *cookie, int cmd, + void *ptr, size_t *len); +/* IOCTL commands for the private cookie function. */ +#define COOKIE_IOCTL_SNATCH_BUFFER 1 + + +/* The internal stream object. */ +struct _gpgrt_stream_internal +{ + unsigned char buffer[BUFFER_BLOCK_SIZE]; + unsigned char unread_buffer[BUFFER_UNREAD_SIZE]; + + gpgrt_lock_t lock; /* Lock. */ + + void *cookie; /* Cookie. */ + void *opaque; /* Opaque data. */ + unsigned int modeflags; /* Flags for the backend. */ + char *printable_fname; /* Malloced filename for es_fname_get. */ + gpgrt_off_t offset; + gpgrt_cookie_read_function_t func_read; + gpgrt_cookie_write_function_t func_write; + gpgrt_cookie_seek_function_t func_seek; + gpgrt_cookie_close_function_t func_close; + cookie_ioctl_function_t func_ioctl; + int strategy; + es_syshd_t syshd; /* A copy of the sytem handle. */ + struct + { + unsigned int err: 1; + unsigned int eof: 1; + } indicators; + unsigned int deallocate_buffer: 1; + unsigned int is_stdstream:1; /* This is a standard stream. */ + unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */ + unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */ + unsigned int samethread: 1; /* The "samethread" mode keyword. */ + size_t print_ntotal; /* Bytes written from in print_writer. */ + notify_list_t onclose; /* On close notify function list. */ +}; +typedef struct _gpgrt_stream_internal *estream_internal_t; + +/* A linked list to hold active stream objects. */ +struct estream_list_s +{ + struct estream_list_s *next; + estream_t stream; /* Entry is not used if NULL. */ +}; +typedef struct estream_list_s *estream_list_t; +static estream_list_t estream_list; +/* A lock object for the estream list and the custom_std_fds array. */ +GPGRT_LOCK_DEFINE (estream_list_lock); + +/* File descriptors registered to be used as the standard file handles. */ +static int custom_std_fds[3]; +static unsigned char custom_std_fds_valid[3]; + +/* Functions called before and after blocking syscalls. */ +static void (*pre_syscall_func)(void); +static void (*post_syscall_func)(void); + +/* Error code replacements. */ +#ifndef EOPNOTSUPP +# define EOPNOTSUPP ENOSYS +#endif + + +/* Local prototypes. */ +static void fname_set_internal (estream_t stream, const char *fname, int quote); + + + + +/* Macros. */ + +/* Calculate array dimension. */ +#ifndef DIM +#define DIM(array) (sizeof (array) / sizeof (*array)) +#endif + +#define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) + + +/* Evaluate EXPRESSION, setting VARIABLE to the return code, if + VARIABLE is zero. */ +#define SET_UNLESS_NONZERO(variable, tmp_variable, expression) \ + do \ + { \ + tmp_variable = expression; \ + if ((! variable) && tmp_variable) \ + variable = tmp_variable; \ + } \ + while (0) + + + +static void * +mem_alloc (size_t n) +{ + return _gpgrt_malloc (n); +} + +static void * +mem_realloc (void *p, size_t n) +{ + return _gpgrt_realloc (p, n); +} + +static void +mem_free (void *p) +{ + if (p) + _gpgrt_free (p); +} + +#ifdef HAVE_W32_SYSTEM +static int +map_w32_to_errno (DWORD w32_err) +{ + switch (w32_err) + { + case 0: + return 0; + + case ERROR_FILE_NOT_FOUND: + return ENOENT; + + case ERROR_PATH_NOT_FOUND: + return ENOENT; + + case ERROR_ACCESS_DENIED: + return EPERM; + + case ERROR_INVALID_HANDLE: + case ERROR_INVALID_BLOCK: + return EINVAL; + + case ERROR_NOT_ENOUGH_MEMORY: + return ENOMEM; + + case ERROR_NO_DATA: + return EPIPE; + + default: + return EIO; + } +} +#endif /*HAVE_W32_SYSTEM*/ + +/* Replacement fucntions. */ + +#ifndef HAVE_MEMRCHR +static void * +memrchr (const void *buffer, int c, size_t n) +{ + const unsigned char *p = buffer; + + for (p += n; n ; n--) + if (*--p == c) + return (void *)p; + return NULL; +} +#endif /*HAVE_MEMRCHR*/ + + +/* + * Lock wrappers + */ +#if 0 +# define dbg_lock_0(f) fprintf (stderr, "estream: " f); +# define dbg_lock_1(f, a) fprintf (stderr, "estream: " f, (a)); +# define dbg_lock_2(f, a, b) fprintf (stderr, "estream: " f, (a), (b)); +#else +# define dbg_lock_0(f) +# define dbg_lock_1(f, a) +# define dbg_lock_2(f, a, b) +#endif + +static int +init_stream_lock (estream_t _GPGRT__RESTRICT stream) +{ + int rc; + + if (!stream->intern->samethread) + { + dbg_lock_1 ("enter init_stream_lock for %p\n", stream); + memset (&stream->intern->lock, 0 , sizeof stream->intern->lock); + rc = _gpgrt_lock_init (&stream->intern->lock); + dbg_lock_2 ("leave init_stream_lock for %p: rc=%d\n", stream, rc); + } + else + rc = 0; + return rc; +} + + +static void +destroy_stream_lock (estream_t _GPGRT__RESTRICT stream) +{ + if (!stream->intern->samethread) + { + dbg_lock_1 ("enter destroy_stream_lock for %p\n", stream); + _gpgrt_lock_destroy (&stream->intern->lock); + dbg_lock_1 ("leave destroy_stream_lock for %p\n", stream); + } +} + + +static void +lock_stream (estream_t _GPGRT__RESTRICT stream) +{ + if (!stream->intern->samethread) + { + dbg_lock_1 ("enter lock_stream for %p\n", stream); + _gpgrt_lock_lock (&stream->intern->lock); + dbg_lock_1 ("leave lock_stream for %p\n", stream); + } +} + + +static int +trylock_stream (estream_t _GPGRT__RESTRICT stream) +{ + int rc; + + if (!stream->intern->samethread) + { + dbg_lock_1 ("enter trylock_stream for %p\n", stream); + rc = _gpgrt_lock_trylock (&stream->intern->lock)? 0 : -1; + dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc); + } + else + rc = 0; + return rc; +} + + +static void +unlock_stream (estream_t _GPGRT__RESTRICT stream) +{ + if (!stream->intern->samethread) + { + dbg_lock_1 ("enter unlock_stream for %p\n", stream); + _gpgrt_lock_unlock (&stream->intern->lock); + dbg_lock_1 ("leave unlock_stream for %p\n", stream); + } +} + + +static void +lock_list (void) +{ + dbg_lock_0 ("enter lock_list\n"); + _gpgrt_lock_lock (&estream_list_lock); + dbg_lock_0 ("leave lock_list\n"); +} + + +static void +unlock_list (void) +{ + dbg_lock_0 ("enter unlock_list\n"); + _gpgrt_lock_unlock (&estream_list_lock); + dbg_lock_0 ("leave unlock_list\n"); +} + + +#undef dbg_lock_0 +#undef dbg_lock_1 +#undef dbg_lock_2 + + + +/* + * List manipulation. + */ + +/* Add STREAM to the list of registered stream objects. If + WITH_LOCKED_LIST is true it is assumed that the list of streams is + already locked. The implementation is straightforward: We first + look for an unused entry in the list and use that; if none is + available we put a new item at the head. We drawback of the + strategy never to shorten the list is that a one time allocation of + many streams will lead to scanning unused entries later. If that + turns out to be a problem, we may either free some items from the + list or append new entries at the end; or use a table. Returns 0 + on success; on error or non-zero is returned and ERRNO set. */ +static int +do_list_add (estream_t stream, int with_locked_list) +{ + estream_list_t item; + + if (!with_locked_list) + lock_list (); + + for (item = estream_list; item && item->stream; item = item->next) + ; + if (!item) + { + item = mem_alloc (sizeof *item); + if (item) + { + item->next = estream_list; + estream_list = item; + } + } + if (item) + item->stream = stream; + + if (!with_locked_list) + unlock_list (); + + return item? 0 : -1; +} + +/* Remove STREAM from the list of registered stream objects. */ +static void +do_list_remove (estream_t stream, int with_locked_list) +{ + estream_list_t item; + + if (!with_locked_list) + lock_list (); + + for (item = estream_list; item; item = item->next) + if (item->stream == stream) + { + item->stream = NULL; + break; + } + + if (!with_locked_list) + unlock_list (); +} + + + +static void +do_deinit (void) +{ + /* Flush all streams. */ + _gpgrt_fflush (NULL); + + /* We should release the estream_list. However there is one + problem: That list is also used to search for the standard + estream file descriptors. If we would remove the entire list, + any use of es_foo in another atexit function may re-create the + list and the streams with possible undesirable effects. Given + that we don't close the stream either, it should not matter that + we keep the list and let the OS clean it up at process end. */ + + /* Reset the syscall clamp. */ + pre_syscall_func = NULL; + post_syscall_func = NULL; +} + + +/* + * Initialization. + */ + +int +_gpgrt_es_init (void) +{ + static int initialized; + + if (!initialized) + { + initialized = 1; + atexit (do_deinit); + } + return 0; +} + +/* Register the syscall clamp. These two functions are called + immediately before and after a possible blocking system call. This + should be used before any I/O happens. The function is commonly + used with the nPth library: + + gpgrt_set_syscall_clamp (npth_unprotect, npth_protect); + + These functions may not modify ERRNO. +*/ +void +_gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void)) +{ + pre_syscall_func = pre; + post_syscall_func = post; +} + + + + +/* + * I/O methods. + */ + +/* Implementation of Memory I/O. */ + +/* Cookie for memory objects. */ +typedef struct estream_cookie_mem +{ + unsigned int modeflags; /* Open flags. */ + unsigned char *memory; /* Allocated data buffer. */ + size_t memory_size; /* Allocated size of MEMORY. */ + size_t memory_limit; /* Caller supplied maximum allowed + allocation size or 0 for no limit. */ + size_t offset; /* Current offset in MEMORY. */ + size_t data_len; /* Used length of data in MEMORY. */ + size_t block_size; /* Block size. */ + struct { + unsigned int grow: 1; /* MEMORY is allowed to grow. */ + } flags; + func_realloc_t func_realloc; + func_free_t func_free; +} *estream_cookie_mem_t; + + +/* Create function for memory objects. DATA is either NULL or a user + supplied buffer with the initial conetnt of the memory buffer. If + DATA is NULL, DATA_N and DATA_LEN need to be 0 as well. If DATA is + not NULL, DATA_N gives the allocated size of DATA and DATA_LEN the + used length in DATA. If this fucntion succeeds DATA is now owned + by this function. If GROW is false FUNC_REALLOC is not + required. */ +static int +func_mem_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie, + unsigned char *_GPGRT__RESTRICT data, size_t data_n, + size_t data_len, + size_t block_size, unsigned int grow, + func_realloc_t func_realloc, func_free_t func_free, + unsigned int modeflags, + size_t memory_limit) +{ + estream_cookie_mem_t mem_cookie; + int err; + + if (!data && (data_n || data_len)) + { + _set_errno (EINVAL); + return -1; + } + if (grow && func_free && !func_realloc) + { + _set_errno (EINVAL); + return -1; + } + + mem_cookie = mem_alloc (sizeof (*mem_cookie)); + if (!mem_cookie) + err = -1; + else + { + mem_cookie->modeflags = modeflags; + mem_cookie->memory = data; + mem_cookie->memory_size = data_n; + mem_cookie->memory_limit = memory_limit; + mem_cookie->offset = 0; + mem_cookie->data_len = data_len; + mem_cookie->block_size = block_size; + mem_cookie->flags.grow = !!grow; + mem_cookie->func_realloc + = grow? (func_realloc ? func_realloc : mem_realloc) : NULL; + mem_cookie->func_free = func_free ? func_free : mem_free; + *cookie = mem_cookie; + err = 0; + } + + return err; +} + + +/* Read function for memory objects. */ +static gpgrt_ssize_t +es_func_mem_read (void *cookie, void *buffer, size_t size) +{ + estream_cookie_mem_t mem_cookie = cookie; + gpgrt_ssize_t ret; + + if (!size) /* Just the pending data check. */ + return (mem_cookie->data_len - mem_cookie->offset)? 0 : -1; + + if (size > mem_cookie->data_len - mem_cookie->offset) + size = mem_cookie->data_len - mem_cookie->offset; + + if (size) + { + memcpy (buffer, mem_cookie->memory + mem_cookie->offset, size); + mem_cookie->offset += size; + } + + ret = size; + return ret; +} + + +/* Write function for memory objects. */ +static gpgrt_ssize_t +es_func_mem_write (void *cookie, const void *buffer, size_t size) +{ + estream_cookie_mem_t mem_cookie = cookie; + gpgrt_ssize_t ret; + size_t nleft; + + if (!size) + return 0; /* A flush is a NOP for memory objects. */ + + if (mem_cookie->modeflags & O_APPEND) + { + /* Append to data. */ + mem_cookie->offset = mem_cookie->data_len; + } + + assert (mem_cookie->memory_size >= mem_cookie->offset); + nleft = mem_cookie->memory_size - mem_cookie->offset; + + /* If we are not allowed to grow the buffer, limit the size to the + left space. */ + if (!mem_cookie->flags.grow && size > nleft) + size = nleft; + + /* Enlarge the memory buffer if needed. */ + if (size > nleft) + { + unsigned char *newbuf; + size_t newsize; + + if (!mem_cookie->memory_size) + newsize = size; /* Not yet allocated. */ + else + newsize = mem_cookie->memory_size + (size - nleft); + if (newsize < mem_cookie->offset) + { + _set_errno (EINVAL); + return -1; + } + + /* Round up to the next block length. BLOCK_SIZE should always + be set; we check anyway. */ + if (mem_cookie->block_size) + { + newsize += mem_cookie->block_size - 1; + if (newsize < mem_cookie->offset) + { + _set_errno (EINVAL); + return -1; + } + newsize /= mem_cookie->block_size; + newsize *= mem_cookie->block_size; + } + + /* Check for a total limit. */ + if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit) + { + _set_errno (ENOSPC); + return -1; + } + + assert (mem_cookie->func_realloc); + newbuf = mem_cookie->func_realloc (mem_cookie->memory, newsize); + if (!newbuf) + return -1; + + mem_cookie->memory = newbuf; + mem_cookie->memory_size = newsize; + + assert (mem_cookie->memory_size >= mem_cookie->offset); + nleft = mem_cookie->memory_size - mem_cookie->offset; + + assert (size <= nleft); + } + + memcpy (mem_cookie->memory + mem_cookie->offset, buffer, size); + if (mem_cookie->offset + size > mem_cookie->data_len) + mem_cookie->data_len = mem_cookie->offset + size; + mem_cookie->offset += size; + + ret = size; + return ret; +} + + +/* Seek function for memory objects. */ +static int +es_func_mem_seek (void *cookie, gpgrt_off_t *offset, int whence) +{ + estream_cookie_mem_t mem_cookie = cookie; + gpgrt_off_t pos_new; + + switch (whence) + { + case SEEK_SET: + pos_new = *offset; + break; + + case SEEK_CUR: + pos_new = mem_cookie->offset += *offset; + break; + + case SEEK_END: + pos_new = mem_cookie->data_len += *offset; + break; + + default: + _set_errno (EINVAL); + return -1; + } + + if (pos_new > mem_cookie->memory_size) + { + size_t newsize; + void *newbuf; + + if (!mem_cookie->flags.grow) + { + _set_errno (ENOSPC); + return -1; + } + + newsize = pos_new + mem_cookie->block_size - 1; + if (newsize < pos_new) + { + _set_errno (EINVAL); + return -1; + } + newsize /= mem_cookie->block_size; + newsize *= mem_cookie->block_size; + + if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit) + { + _set_errno (ENOSPC); + return -1; + } + + assert (mem_cookie->func_realloc); + newbuf = mem_cookie->func_realloc (mem_cookie->memory, newsize); + if (!newbuf) + return -1; + + mem_cookie->memory = newbuf; + mem_cookie->memory_size = newsize; + } + + if (pos_new > mem_cookie->data_len) + { + /* Fill spare space with zeroes. */ + memset (mem_cookie->memory + mem_cookie->data_len, + 0, pos_new - mem_cookie->data_len); + mem_cookie->data_len = pos_new; + } + + mem_cookie->offset = pos_new; + *offset = pos_new; + + return 0; +} + +/* An IOCTL function for memory objects. */ +static int +es_func_mem_ioctl (void *cookie, int cmd, void *ptr, size_t *len) +{ + estream_cookie_mem_t mem_cookie = cookie; + int ret; + + if (cmd == COOKIE_IOCTL_SNATCH_BUFFER) + { + /* Return the internal buffer of the stream to the caller and + invalidate it for the stream. */ + *(void**)ptr = mem_cookie->memory; + *len = mem_cookie->offset; + mem_cookie->memory = NULL; + mem_cookie->memory_size = 0; + mem_cookie->offset = 0; + ret = 0; + } + else + { + _set_errno (EINVAL); + ret = -1; + } + + return ret; +} + + +/* Destroy function for memory objects. */ +static int +es_func_mem_destroy (void *cookie) +{ + estream_cookie_mem_t mem_cookie = cookie; + + if (cookie) + { + mem_cookie->func_free (mem_cookie->memory); + mem_free (mem_cookie); + } + return 0; +} + + +static gpgrt_cookie_io_functions_t estream_functions_mem = + { + es_func_mem_read, + es_func_mem_write, + es_func_mem_seek, + es_func_mem_destroy + }; + + + +/* Implementation of file descriptor based I/O. */ + +/* Cookie for fd objects. */ +typedef struct estream_cookie_fd +{ + int fd; /* The file descriptor we are using for actual output. */ + int no_close; /* If set we won't close the file descriptor. */ +} *estream_cookie_fd_t; + +/* Create function for objects indentified by a libc file descriptor. */ +static int +func_fd_create (void **cookie, int fd, unsigned int modeflags, int no_close) +{ + estream_cookie_fd_t fd_cookie; + int err; + + fd_cookie = mem_alloc (sizeof (*fd_cookie)); + if (! fd_cookie) + err = -1; + else + { +#ifdef HAVE_DOSISH_SYSTEM + /* Make sure it is in binary mode if requested. */ + if ( (modeflags & O_BINARY) ) + setmode (fd, O_BINARY); +#else + (void)modeflags; +#endif + fd_cookie->fd = fd; + fd_cookie->no_close = no_close; + *cookie = fd_cookie; + err = 0; + } + + return err; +} + +/* Read function for fd objects. */ +static gpgrt_ssize_t +es_func_fd_read (void *cookie, void *buffer, size_t size) + +{ + estream_cookie_fd_t file_cookie = cookie; + gpgrt_ssize_t bytes_read; + + if (!size) + bytes_read = -1; /* We don't know whether anything is pending. */ + else if (IS_INVALID_FD (file_cookie->fd)) + { + _gpgrt_yield (); + bytes_read = 0; + } + else + { + if (pre_syscall_func) + pre_syscall_func (); + do + { + bytes_read = read (file_cookie->fd, buffer, size); + } + while (bytes_read == -1 && errno == EINTR); + if (post_syscall_func) + post_syscall_func (); + } + + return bytes_read; +} + +/* Write function for fd objects. */ +static gpgrt_ssize_t +es_func_fd_write (void *cookie, const void *buffer, size_t size) +{ + estream_cookie_fd_t file_cookie = cookie; + gpgrt_ssize_t bytes_written; + + if (IS_INVALID_FD (file_cookie->fd)) + { + _gpgrt_yield (); + bytes_written = size; /* Yeah: Success writing to the bit bucket. */ + } + else + { + if (pre_syscall_func) + pre_syscall_func (); + do + { + bytes_written = write (file_cookie->fd, buffer, size); + } + while (bytes_written == -1 && errno == EINTR); + if (post_syscall_func) + post_syscall_func (); + } + + return bytes_written; +} + +/* Seek function for fd objects. */ +static int +es_func_fd_seek (void *cookie, gpgrt_off_t *offset, int whence) +{ + estream_cookie_fd_t file_cookie = cookie; + gpgrt_off_t offset_new; + int err; + + if (IS_INVALID_FD (file_cookie->fd)) + { + _set_errno (ESPIPE); + err = -1; + } + else + { + if (pre_syscall_func) + pre_syscall_func (); + offset_new = lseek (file_cookie->fd, *offset, whence); + if (post_syscall_func) + post_syscall_func (); + if (offset_new == -1) + err = -1; + else + { + *offset = offset_new; + err = 0; + } + } + + return err; +} + +/* Destroy function for fd objects. */ +static int +es_func_fd_destroy (void *cookie) +{ + estream_cookie_fd_t fd_cookie = cookie; + int err; + + if (fd_cookie) + { + if (IS_INVALID_FD (fd_cookie->fd)) + err = 0; + else + err = fd_cookie->no_close? 0 : close (fd_cookie->fd); + mem_free (fd_cookie); + } + else + err = 0; + + return err; +} + + +static gpgrt_cookie_io_functions_t estream_functions_fd = + { + es_func_fd_read, + es_func_fd_write, + es_func_fd_seek, + es_func_fd_destroy + }; + + + + +#ifdef HAVE_W32_SYSTEM +/* Implementation of W32 handle based I/O. */ + +/* Cookie for fd objects. */ +typedef struct estream_cookie_w32 +{ + HANDLE hd; /* The handle we are using for actual output. */ + int no_close; /* If set we won't close the handle. */ +} *estream_cookie_w32_t; + + +/* Create function for w32 handle objects. */ +static int +es_func_w32_create (void **cookie, HANDLE hd, + unsigned int modeflags, int no_close) +{ + estream_cookie_w32_t w32_cookie; + int err; + + w32_cookie = mem_alloc (sizeof (*w32_cookie)); + if (!w32_cookie) + err = -1; + else + { + /* CR/LF translations are not supported when using the bare W32 + API. If that is really required we need to implemented that + in the upper layer. */ + (void)modeflags; + + w32_cookie->hd = hd; + w32_cookie->no_close = no_close; + *cookie = w32_cookie; + err = 0; + } + + return err; +} + +/* Read function for W32 handle objects. */ +static gpgrt_ssize_t +es_func_w32_read (void *cookie, void *buffer, size_t size) +{ + estream_cookie_w32_t w32_cookie = cookie; + gpgrt_ssize_t bytes_read; + + if (!size) + bytes_read = -1; /* We don't know whether anything is pending. */ + else if (w32_cookie->hd == INVALID_HANDLE_VALUE) + { + _gpgrt_yield (); + bytes_read = 0; + } + else + { + if (pre_syscall_func) + pre_syscall_func (); + do + { + DWORD nread, ec; + + if (!ReadFile (w32_cookie->hd, buffer, size, &nread, NULL)) + { + ec = GetLastError (); + if (ec == ERROR_BROKEN_PIPE) + bytes_read = 0; /* Like our pth_read we handle this as EOF. */ + else + { + _set_errno (map_w32_to_errno (ec)); + bytes_read = -1; + } + } + else + bytes_read = (int)nread; + } + while (bytes_read == -1 && errno == EINTR); + if (post_syscall_func) + post_syscall_func (); + } + + return bytes_read; +} + +/* Write function for W32 handle objects. */ +static gpgrt_ssize_t +es_func_w32_write (void *cookie, const void *buffer, size_t size) +{ + estream_cookie_w32_t w32_cookie = cookie; + gpgrt_ssize_t bytes_written; + + if (w32_cookie->hd == INVALID_HANDLE_VALUE) + { + _gpgrt_yield (); + bytes_written = size; /* Yeah: Success writing to the bit bucket. */ + } + else + { + if (pre_syscall_func) + pre_syscall_func (); + do + { + DWORD nwritten; + + if (!WriteFile (w32_cookie->hd, buffer, size, &nwritten, NULL)) + { + _set_errno (map_w32_to_errno (GetLastError ())); + bytes_written = -1; + } + else + bytes_written = (int)nwritten; + } + while (bytes_written == -1 && errno == EINTR); + if (post_syscall_func) + post_syscall_func (); + } + + return bytes_written; +} + +/* Seek function for W32 handle objects. */ +static int +es_func_w32_seek (void *cookie, gpgrt_off_t *offset, int whence) +{ + estream_cookie_w32_t w32_cookie = cookie; + DWORD method; + LARGE_INTEGER distance, newoff; + + if (w32_cookie->hd == INVALID_HANDLE_VALUE) + { + _set_errno (ESPIPE); + return -1; + } + + if (whence == SEEK_SET) + { + method = FILE_BEGIN; + distance.QuadPart = (unsigned long long)(*offset); + } + else if (whence == SEEK_CUR) + { + method = FILE_CURRENT; + distance.QuadPart = (long long)(*offset); + } + else if (whence == SEEK_END) + { + method = FILE_END; + distance.QuadPart = (long long)(*offset); + } + else + { + _set_errno (EINVAL); + return -1; + } +#ifdef HAVE_W32CE_SYSTEM +# warning need to use SetFilePointer +#else + if (pre_syscall_func) + pre_syscall_func (); + if (!SetFilePointerEx (w32_cookie->hd, distance, &newoff, method)) + { + _set_errno (map_w32_to_errno (GetLastError ())); + if (post_syscall_func) + post_syscall_func (); + return -1; + } + if (post_syscall_func) + post_syscall_func (); +#endif + /* Note that gpgrt_off_t is always 64 bit. */ + *offset = (gpgrt_off_t)newoff.QuadPart; + return 0; +} + +/* Destroy function for W32 handle objects. */ +static int +es_func_w32_destroy (void *cookie) +{ + estream_cookie_w32_t w32_cookie = cookie; + int err; + + if (w32_cookie) + { + if (w32_cookie->hd == INVALID_HANDLE_VALUE) + err = 0; + else if (w32_cookie->no_close) + err = 0; + else + { + if (!CloseHandle (w32_cookie->hd)) + { + _set_errno (map_w32_to_errno (GetLastError ())); + err = -1; + } + else + err = 0; + } + mem_free (w32_cookie); + } + else + err = 0; + + return err; +} + + +static gpgrt_cookie_io_functions_t estream_functions_w32 = + { + es_func_w32_read, + es_func_w32_write, + es_func_w32_seek, + es_func_w32_destroy + }; +#endif /*HAVE_W32_SYSTEM*/ + + + + +/* Implementation of FILE* I/O. */ + +/* Cookie for fp objects. */ +typedef struct estream_cookie_fp +{ + FILE *fp; /* The file pointer we are using for actual output. */ + int no_close; /* If set we won't close the file pointer. */ +} *estream_cookie_fp_t; + + +/* Create function for FILE objects. */ +static int +func_fp_create (void **cookie, FILE *fp, + unsigned int modeflags, int no_close) +{ + estream_cookie_fp_t fp_cookie; + int err; + + fp_cookie = mem_alloc (sizeof *fp_cookie); + if (!fp_cookie) + err = -1; + else + { +#ifdef HAVE_DOSISH_SYSTEM + /* Make sure it is in binary mode if requested. */ + if ( (modeflags & O_BINARY) ) + setmode (fileno (fp), O_BINARY); +#else + (void)modeflags; +#endif + fp_cookie->fp = fp; + fp_cookie->no_close = no_close; + *cookie = fp_cookie; + err = 0; + } + + return err; +} + +/* Read function for FILE* objects. */ +static gpgrt_ssize_t +es_func_fp_read (void *cookie, void *buffer, size_t size) + +{ + estream_cookie_fp_t file_cookie = cookie; + gpgrt_ssize_t bytes_read; + + if (!size) + return -1; /* We don't know whether anything is pending. */ + + if (file_cookie->fp) + { + if (pre_syscall_func) + pre_syscall_func (); + bytes_read = fread (buffer, 1, size, file_cookie->fp); + if (post_syscall_func) + post_syscall_func (); + } + else + bytes_read = 0; + if (!bytes_read && ferror (file_cookie->fp)) + return -1; + return bytes_read; +} + +/* Write function for FILE* objects. */ +static gpgrt_ssize_t +es_func_fp_write (void *cookie, const void *buffer, size_t size) +{ + estream_cookie_fp_t file_cookie = cookie; + size_t bytes_written; + + if (file_cookie->fp) + { + if (pre_syscall_func) + pre_syscall_func (); +#ifdef HAVE_W32_SYSTEM + /* Using an fwrite to stdout connected to the console fails with + the error "Not enough space" for an fwrite size of >= 52KB + (tested on Windows XP SP2). To solve this we always chunk + the writes up into smaller blocks. */ + bytes_written = 0; + while (bytes_written < size) + { + size_t cnt = size - bytes_written; + + if (cnt > 32*1024) + cnt = 32*1024; + if (fwrite ((const char*)buffer + bytes_written, + cnt, 1, file_cookie->fp) != 1) + break; /* Write error. */ + bytes_written += cnt; + } +#else + bytes_written = fwrite (buffer, 1, size, file_cookie->fp); +#endif + fflush (file_cookie->fp); + if (post_syscall_func) + post_syscall_func (); + } + else + bytes_written = size; /* Successfully written to the bit bucket. */ + if (bytes_written != size) + return -1; + return bytes_written; +} + +/* Seek function for FILE* objects. */ +static int +es_func_fp_seek (void *cookie, gpgrt_off_t *offset, int whence) +{ + estream_cookie_fp_t file_cookie = cookie; + long int offset_new; + + if (!file_cookie->fp) + { + _set_errno (ESPIPE); + return -1; + } + + if (pre_syscall_func) + pre_syscall_func (); + if ( fseek (file_cookie->fp, (long int)*offset, whence) ) + { + /* fprintf (stderr, "\nfseek failed: errno=%d (%s)\n", */ + /* errno,strerror (errno)); */ + if (post_syscall_func) + post_syscall_func (); + return -1; + } + + offset_new = ftell (file_cookie->fp); + if (post_syscall_func) + post_syscall_func (); + if (offset_new == -1) + { + /* fprintf (stderr, "\nftell failed: errno=%d (%s)\n", */ + /* errno,strerror (errno)); */ + return -1; + } + *offset = offset_new; + return 0; +} + +/* Destroy function for FILE* objects. */ +static int +es_func_fp_destroy (void *cookie) +{ + estream_cookie_fp_t fp_cookie = cookie; + int err; + + if (fp_cookie) + { + if (fp_cookie->fp) + { + if (pre_syscall_func) + pre_syscall_func (); + fflush (fp_cookie->fp); + if (post_syscall_func) + post_syscall_func (); + err = fp_cookie->no_close? 0 : fclose (fp_cookie->fp); + } + else + err = 0; + mem_free (fp_cookie); + } + else + err = 0; + + return err; +} + + +static gpgrt_cookie_io_functions_t estream_functions_fp = + { + es_func_fp_read, + es_func_fp_write, + es_func_fp_seek, + es_func_fp_destroy + }; + + + + +/* Implementation of file I/O. */ + +/* Create function for objects identified by a file name. */ +static int +func_file_create (void **cookie, int *filedes, + const char *path, unsigned int modeflags, unsigned int cmode) +{ + estream_cookie_fd_t file_cookie; + int err; + int fd; + + err = 0; + fd = -1; + + file_cookie = mem_alloc (sizeof (*file_cookie)); + if (! file_cookie) + { + err = -1; + goto out; + } + + fd = open (path, modeflags, cmode); + if (fd == -1) + { + err = -1; + goto out; + } +#ifdef HAVE_DOSISH_SYSTEM + /* Make sure it is in binary mode if requested. */ + if ( (modeflags & O_BINARY) ) + setmode (fd, O_BINARY); +#endif + + file_cookie->fd = fd; + file_cookie->no_close = 0; + *cookie = file_cookie; + *filedes = fd; + + out: + + if (err) + mem_free (file_cookie); + + return err; +} + + + +/* Parse the mode flags of fopen et al. In addition to the POSIX + defined mode flags keyword parameters are supported. These are + key/value pairs delimited by comma and optional white spaces. + Keywords and values may not contain a comma or white space; unknown + keywords are skipped. Supported keywords are: + + mode=<string> + + Creates a file and gives the new file read and write permissions + for the user and read permission for the group. The format of + the string is the same as shown by the -l option of the ls(1) + command. However the first letter must be a dash and it is + allowed to leave out trailing dashes. If this keyword parameter + is not given the default mode for creating files is "-rw-rw-r--" + (664). Note that the system still applies the current umask to + the mode when crating a file. Example: + + "wb,mode=-rw-r--" + + samethread + + Assumes that the object is only used by the creating thread and + disables any internal locking. This keyword is also found on + IBM systems. + + + Note: R_CMODE is optional because is only required by functions + which are able to creat a file. */ +static int +parse_mode (const char *modestr, + unsigned int *modeflags, int *samethread, + unsigned int *r_cmode) +{ + unsigned int omode, oflags, cmode; + int got_cmode = 0; + + *samethread = 0; + + switch (*modestr) + { + case 'r': + omode = O_RDONLY; + oflags = 0; + break; + case 'w': + omode = O_WRONLY; + oflags = O_TRUNC | O_CREAT; + break; + case 'a': + omode = O_WRONLY; + oflags = O_APPEND | O_CREAT; + break; + default: + _set_errno (EINVAL); + return -1; + } + for (modestr++; *modestr; modestr++) + { + switch (*modestr) + { + case '+': + omode = O_RDWR; + break; + case 'b': + oflags |= O_BINARY; + break; + case 'x': + oflags |= O_EXCL; + break; + case ',': + goto keyvalue; + default: /* Ignore unknown flags. */ + break; + } + } + + keyvalue: + /* Parse key/value pairs (similar to fopen on mainframes). */ + for (cmode=0; *modestr == ','; modestr += strcspn (modestr, ",")) + { + modestr++; + modestr += strspn (modestr, " \t"); + if (!strncmp (modestr, "mode=", 5)) + { + static struct { + char letter; + unsigned int value; + } table[] = { { '-', 0 }, + { 'r', S_IRUSR }, { 'w', S_IWUSR }, { 'x', S_IXUSR }, + { 'r', S_IRGRP }, { 'w', S_IWGRP }, { 'x', S_IXGRP }, + { 'r', S_IROTH }, { 'w', S_IWOTH }, { 'x', S_IXOTH }}; + int idx; + + got_cmode = 1; + modestr += 5; + /* For now we only support a string as used by ls(1) and no + octal numbers. The first character must be a dash. */ + for (idx=0; idx < 10 && *modestr; idx++, modestr++) + { + if (*modestr == table[idx].letter) + cmode |= table[idx].value; + else if (*modestr != '-') + break; + } + if (*modestr && !strchr (" \t,", *modestr)) + { + _set_errno (EINVAL); + return -1; + } + } + else if (!strncmp (modestr, "samethread", 10)) + { + modestr += 10; + if (*modestr && !strchr (" \t,", *modestr)) + { + _set_errno (EINVAL); + return -1; + } + *samethread = 1; + } + } + if (!got_cmode) + cmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + + *modeflags = (omode | oflags); + if (r_cmode) + *r_cmode = cmode; + return 0; +} + + + +/* + * Low level stream functionality. + */ + +static int +es_fill (estream_t stream) +{ + size_t bytes_read = 0; + int err; + + if (!stream->intern->func_read) + { + _set_errno (EOPNOTSUPP); + err = -1; + } + else if (!stream->buffer_size) + err = 0; + else + { + gpgrt_cookie_read_function_t func_read = stream->intern->func_read; + gpgrt_ssize_t ret; + + ret = (*func_read) (stream->intern->cookie, + stream->buffer, stream->buffer_size); + if (ret == -1) + { + bytes_read = 0; + err = -1; + } + else + { + bytes_read = ret; + err = 0; + } + } + + if (err) + stream->intern->indicators.err = 1; + else if (!bytes_read) + stream->intern->indicators.eof = 1; + + stream->intern->offset += stream->data_len; + stream->data_len = bytes_read; + stream->data_offset = 0; + + return err; +} + +static int +es_flush (estream_t stream) +{ + gpgrt_cookie_write_function_t func_write = stream->intern->func_write; + int err; + + assert (stream->flags.writing); + + if (stream->data_offset) + { + size_t bytes_written; + size_t data_flushed; + gpgrt_ssize_t ret; + + if (! func_write) + { + err = EOPNOTSUPP; + goto out; + } + + /* Note: to prevent an endless loop caused by user-provided + write-functions that pretend to have written more bytes than + they were asked to write, we have to check for + "(stream->data_offset - data_flushed) > 0" instead of + "stream->data_offset - data_flushed". */ + + data_flushed = 0; + err = 0; + + while ((((gpgrt_ssize_t) (stream->data_offset - data_flushed)) > 0) + && !err) + { + ret = (*func_write) (stream->intern->cookie, + stream->buffer + data_flushed, + stream->data_offset - data_flushed); + if (ret == -1) + { + bytes_written = 0; + err = -1; + } + else + bytes_written = ret; + + data_flushed += bytes_written; + if (err) + break; + } + + stream->data_flushed += data_flushed; + if (stream->data_offset == data_flushed) + { + stream->intern->offset += stream->data_offset; + stream->data_offset = 0; + stream->data_flushed = 0; + + /* Propagate flush event. */ + (*func_write) (stream->intern->cookie, NULL, 0); + } + } + else + err = 0; + + out: + + if (err) + stream->intern->indicators.err = 1; + + return err; +} + +/* Discard buffered data for STREAM. */ +static void +es_empty (estream_t stream) +{ + assert (!stream->flags.writing); + stream->data_len = 0; + stream->data_offset = 0; + stream->unread_data_len = 0; +} + +/* Initialize STREAM. */ +static void +init_stream_obj (estream_t stream, + void *cookie, es_syshd_t *syshd, + gpgrt_cookie_io_functions_t functions, + unsigned int modeflags, int samethread) +{ + stream->intern->cookie = cookie; + stream->intern->opaque = NULL; + stream->intern->offset = 0; + stream->intern->func_read = functions.func_read; + stream->intern->func_write = functions.func_write; + stream->intern->func_seek = functions.func_seek; + stream->intern->func_ioctl = NULL; + stream->intern->func_close = functions.func_close; + stream->intern->strategy = _IOFBF; + stream->intern->syshd = *syshd; + stream->intern->print_ntotal = 0; + stream->intern->indicators.err = 0; + stream->intern->indicators.eof = 0; + stream->intern->is_stdstream = 0; + stream->intern->stdstream_fd = 0; + stream->intern->deallocate_buffer = 0; + stream->intern->printable_fname = NULL; + stream->intern->printable_fname_inuse = 0; + stream->intern->samethread = !!samethread; + stream->intern->onclose = NULL; + + stream->data_len = 0; + stream->data_offset = 0; + stream->data_flushed = 0; + stream->unread_data_len = 0; + /* Depending on the modeflags we set whether we start in writing or + reading mode. This is required in case we are working on a + stream which is not seeekable (like stdout). Without this + pre-initialization we would do a seek at the first write call and + as this will fail no output will be delivered. */ + if ((modeflags & O_WRONLY) || (modeflags & O_RDWR) ) + stream->flags.writing = 1; + else + stream->flags.writing = 0; +} + +/* Deinitialize STREAM. */ +static int +es_deinitialize (estream_t stream) +{ + gpgrt_cookie_close_function_t func_close; + int err, tmp_err; + + func_close = stream->intern->func_close; + + err = 0; + if (stream->flags.writing) + SET_UNLESS_NONZERO (err, tmp_err, es_flush (stream)); + if (func_close) + SET_UNLESS_NONZERO (err, tmp_err, (*func_close) (stream->intern->cookie)); + + mem_free (stream->intern->printable_fname); + stream->intern->printable_fname = NULL; + stream->intern->printable_fname_inuse = 0; + while (stream->intern->onclose) + { + notify_list_t tmp = stream->intern->onclose->next; + mem_free (stream->intern->onclose); + stream->intern->onclose = tmp; + } + + return err; +} + +/* Create a new stream object, initialize it. */ +static int +es_create (estream_t *stream, void *cookie, es_syshd_t *syshd, + gpgrt_cookie_io_functions_t functions, unsigned int modeflags, + int samethread, int with_locked_list) +{ + estream_internal_t stream_internal_new; + estream_t stream_new; + int err; + + stream_new = NULL; + stream_internal_new = NULL; + + stream_new = mem_alloc (sizeof (*stream_new)); + if (! stream_new) + { + err = -1; + goto out; + } + + stream_internal_new = mem_alloc (sizeof (*stream_internal_new)); + if (! stream_internal_new) + { + err = -1; + goto out; + } + + stream_new->buffer = stream_internal_new->buffer; + stream_new->buffer_size = sizeof (stream_internal_new->buffer); + stream_new->unread_buffer = stream_internal_new->unread_buffer; + stream_new->unread_buffer_size = sizeof (stream_internal_new->unread_buffer); + stream_new->intern = stream_internal_new; + + init_stream_obj (stream_new, cookie, syshd, functions, modeflags, samethread); + init_stream_lock (stream_new); + + err = do_list_add (stream_new, with_locked_list); + if (err) + goto out; + + *stream = stream_new; + + out: + + if (err) + { + if (stream_new) + { + es_deinitialize (stream_new); + destroy_stream_lock (stream_new); + mem_free (stream_new->intern); + mem_free (stream_new); + } + } + + return err; +} + +/* Deinitialize a stream object and destroy it. */ +static int +do_close (estream_t stream, int with_locked_list) +{ + int err; + + if (stream) + { + do_list_remove (stream, with_locked_list); + while (stream->intern->onclose) + { + notify_list_t tmp = stream->intern->onclose->next; + + if (stream->intern->onclose->fnc) + stream->intern->onclose->fnc (stream, + stream->intern->onclose->fnc_value); + mem_free (stream->intern->onclose); + stream->intern->onclose = tmp; + } + err = es_deinitialize (stream); + destroy_stream_lock (stream); + mem_free (stream->intern); + mem_free (stream); + } + else + err = 0; + + return err; +} + + +/* This worker function is called with a locked stream. */ +static int +do_onclose (estream_t stream, int mode, + void (*fnc) (estream_t, void*), void *fnc_value) +{ + notify_list_t item; + + if (!mode) + { + for (item = stream->intern->onclose; item; item = item->next) + if (item->fnc && item->fnc == fnc && item->fnc_value == fnc_value) + item->fnc = NULL; /* Disable this notification. */ + } + else + { + item = mem_alloc (sizeof *item); + if (!item) + return -1; + item->fnc = fnc; + item->fnc_value = fnc_value; + item->next = stream->intern->onclose; + stream->intern->onclose = item; + } + return 0; +} + + +/* Try to read BYTES_TO_READ bytes FROM STREAM into BUFFER in + unbuffered-mode, storing the amount of bytes read in + *BYTES_READ. */ +static int +es_read_nbf (estream_t _GPGRT__RESTRICT stream, + unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_read, size_t *_GPGRT__RESTRICT bytes_read) +{ + gpgrt_cookie_read_function_t func_read = stream->intern->func_read; + size_t data_read; + gpgrt_ssize_t ret; + int err; + + data_read = 0; + err = 0; + + while (bytes_to_read - data_read) + { + ret = (*func_read) (stream->intern->cookie, + buffer + data_read, bytes_to_read - data_read); + if (ret == -1) + { + err = -1; + break; + } + else if (ret) + data_read += ret; + else + break; + } + + stream->intern->offset += data_read; + *bytes_read = data_read; + + return err; +} + +static int +check_pending_nbf (estream_t _GPGRT__RESTRICT stream) +{ + gpgrt_cookie_read_function_t func_read = stream->intern->func_read; + char buffer[1]; + + if (!(*func_read) (stream->intern->cookie, buffer, 0)) + return 1; /* Pending bytes. */ + return 0; /* No pending bytes or error. */ +} + + +/* Try to read BYTES_TO_READ bytes FROM STREAM into BUFFER in + fully-buffered-mode, storing the amount of bytes read in + *BYTES_READ. */ +static int +es_read_fbf (estream_t _GPGRT__RESTRICT stream, + unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_read, size_t *_GPGRT__RESTRICT bytes_read) +{ + size_t data_available; + size_t data_to_read; + size_t data_read; + int err; + + data_read = 0; + err = 0; + + while ((bytes_to_read - data_read) && (! err)) + { + if (stream->data_offset == stream->data_len) + { + /* Nothing more to read in current container, try to + fill container with new data. */ + err = es_fill (stream); + if (! err) + if (! stream->data_len) + /* Filling did not result in any data read. */ + break; + } + + if (! err) + { + /* Filling resulted in some new data. */ + + data_to_read = bytes_to_read - data_read; + data_available = stream->data_len - stream->data_offset; + if (data_to_read > data_available) + data_to_read = data_available; + + memcpy (buffer + data_read, + stream->buffer + stream->data_offset, data_to_read); + stream->data_offset += data_to_read; + data_read += data_to_read; + } + } + + *bytes_read = data_read; + + return err; +} + + +static int +check_pending_fbf (estream_t _GPGRT__RESTRICT stream) +{ + gpgrt_cookie_read_function_t func_read = stream->intern->func_read; + char buffer[1]; + + if (stream->data_offset == stream->data_len) + { + /* Nothing more to read in current container, check whetehr it + would be possible to fill the container with new data. */ + if (!(*func_read) (stream->intern->cookie, buffer, 0)) + return 1; /* Pending bytes. */ + } + else + return 1; + return 0; +} + + +/* Try to read BYTES_TO_READ bytes FROM STREAM into BUFFER in + line-buffered-mode, storing the amount of bytes read in + *BYTES_READ. */ +static int +es_read_lbf (estream_t _GPGRT__RESTRICT stream, + unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_read, size_t *_GPGRT__RESTRICT bytes_read) +{ + int err; + + err = es_read_fbf (stream, buffer, bytes_to_read, bytes_read); + + return err; +} + +/* Try to read BYTES_TO_READ bytes FROM STREAM into BUFFER, storing + the amount of bytes read in BYTES_READ. */ +static int +es_readn (estream_t _GPGRT__RESTRICT stream, + void *_GPGRT__RESTRICT buffer_arg, + size_t bytes_to_read, size_t *_GPGRT__RESTRICT bytes_read) +{ + unsigned char *buffer = (unsigned char *)buffer_arg; + size_t data_read_unread, data_read; + int err; + + data_read_unread = 0; + data_read = 0; + err = 0; + + if (stream->flags.writing) + { + /* Switching to reading mode -> flush output. */ + err = es_flush (stream); + if (err) + goto out; + stream->flags.writing = 0; + } + + /* Read unread data first. */ + while ((bytes_to_read - data_read_unread) && stream->unread_data_len) + { + buffer[data_read_unread] + = stream->unread_buffer[stream->unread_data_len - 1]; + stream->unread_data_len--; + data_read_unread++; + } + + switch (stream->intern->strategy) + { + case _IONBF: + err = es_read_nbf (stream, + buffer + data_read_unread, + bytes_to_read - data_read_unread, &data_read); + break; + case _IOLBF: + err = es_read_lbf (stream, + buffer + data_read_unread, + bytes_to_read - data_read_unread, &data_read); + break; + case _IOFBF: + err = es_read_fbf (stream, + buffer + data_read_unread, + bytes_to_read - data_read_unread, &data_read); + break; + } + + out: + + if (bytes_read) + *bytes_read = data_read_unread + data_read; + + return err; +} + + +/* Return true if at least one byte is pending for read. This is a + best effort check and it it possible that bytes are still pending + even if false is returned. If the stream is in writing mode it is + switched to read mode. */ +static int +check_pending (estream_t _GPGRT__RESTRICT stream) +{ + if (stream->flags.writing) + { + /* Switching to reading mode -> flush output. */ + if (es_flush (stream)) + return 0; /* Better return 0 on error. */ + stream->flags.writing = 0; + } + + /* Check unread data first. */ + if (stream->unread_data_len) + return 1; + + switch (stream->intern->strategy) + { + case _IONBF: + return check_pending_nbf (stream); + case _IOLBF: + case _IOFBF: + return check_pending_fbf (stream); + } + + return 0; +} + + +/* Try to unread DATA_N bytes from DATA into STREAM, storing the + amount of bytes successfully unread in *BYTES_UNREAD. */ +static void +es_unreadn (estream_t _GPGRT__RESTRICT stream, + const unsigned char *_GPGRT__RESTRICT data, size_t data_n, + size_t *_GPGRT__RESTRICT bytes_unread) +{ + size_t space_left; + + space_left = stream->unread_buffer_size - stream->unread_data_len; + + if (data_n > space_left) + data_n = space_left; + + if (! data_n) + goto out; + + memcpy (stream->unread_buffer + stream->unread_data_len, data, data_n); + stream->unread_data_len += data_n; + stream->intern->indicators.eof = 0; + + out: + + if (bytes_unread) + *bytes_unread = data_n; +} + +/* Seek in STREAM. */ +static int +es_seek (estream_t _GPGRT__RESTRICT stream, gpgrt_off_t offset, int whence, + gpgrt_off_t *_GPGRT__RESTRICT offset_new) +{ + gpgrt_cookie_seek_function_t func_seek = stream->intern->func_seek; + int err, ret; + gpgrt_off_t off; + + if (! func_seek) + { + _set_errno (EOPNOTSUPP); + err = -1; + goto out; + } + + if (stream->flags.writing) + { + /* Flush data first in order to prevent flushing it to the wrong + offset. */ + err = es_flush (stream); + if (err) + goto out; + stream->flags.writing = 0; + } + + off = offset; + if (whence == SEEK_CUR) + { + off = off - stream->data_len + stream->data_offset; + off -= stream->unread_data_len; + } + + ret = (*func_seek) (stream->intern->cookie, &off, whence); + if (ret == -1) + { + err = -1; + goto out; + } + + err = 0; + es_empty (stream); + + if (offset_new) + *offset_new = off; + + stream->intern->indicators.eof = 0; + stream->intern->offset = off; + + out: + + if (err) + stream->intern->indicators.err = 1; + + return err; +} + +/* Write BYTES_TO_WRITE bytes from BUFFER into STREAM in + unbuffered-mode, storing the amount of bytes written in + *BYTES_WRITTEN. */ +static int +es_write_nbf (estream_t _GPGRT__RESTRICT stream, + const unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_write, size_t *_GPGRT__RESTRICT bytes_written) +{ + gpgrt_cookie_write_function_t func_write = stream->intern->func_write; + size_t data_written; + gpgrt_ssize_t ret; + int err; + + if (bytes_to_write && (! func_write)) + { + err = EOPNOTSUPP; + goto out; + } + + data_written = 0; + err = 0; + + while (bytes_to_write - data_written) + { + ret = (*func_write) (stream->intern->cookie, + buffer + data_written, + bytes_to_write - data_written); + if (ret == -1) + { + err = -1; + break; + } + else + data_written += ret; + } + + stream->intern->offset += data_written; + *bytes_written = data_written; + + out: + + return err; +} + +/* Write BYTES_TO_WRITE bytes from BUFFER into STREAM in + fully-buffered-mode, storing the amount of bytes written in + *BYTES_WRITTEN. */ +static int +es_write_fbf (estream_t _GPGRT__RESTRICT stream, + const unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_write, size_t *_GPGRT__RESTRICT bytes_written) +{ + size_t space_available; + size_t data_to_write; + size_t data_written; + int err; + + data_written = 0; + err = 0; + + while ((bytes_to_write - data_written) && (! err)) + { + if (stream->data_offset == stream->buffer_size) + /* Container full, flush buffer. */ + err = es_flush (stream); + + if (! err) + { + /* Flushing resulted in empty container. */ + + data_to_write = bytes_to_write - data_written; + space_available = stream->buffer_size - stream->data_offset; + if (data_to_write > space_available) + data_to_write = space_available; + + memcpy (stream->buffer + stream->data_offset, + buffer + data_written, data_to_write); + stream->data_offset += data_to_write; + data_written += data_to_write; + } + } + + *bytes_written = data_written; + + return err; +} + + +/* Write BYTES_TO_WRITE bytes from BUFFER into STREAM in + line-buffered-mode, storing the amount of bytes written in + *BYTES_WRITTEN. */ +static int +es_write_lbf (estream_t _GPGRT__RESTRICT stream, + const unsigned char *_GPGRT__RESTRICT buffer, + size_t bytes_to_write, size_t *_GPGRT__RESTRICT bytes_written) +{ + size_t data_flushed = 0; + size_t data_buffered = 0; + unsigned char *nlp; + int err = 0; + + nlp = memrchr (buffer, '\n', bytes_to_write); + if (nlp) + { + /* Found a newline, directly write up to (including) this + character. */ + err = es_flush (stream); + if (!err) + err = es_write_nbf (stream, buffer, nlp - buffer + 1, &data_flushed); + } + + if (!err) + { + /* Write remaining data fully buffered. */ + err = es_write_fbf (stream, buffer + data_flushed, + bytes_to_write - data_flushed, &data_buffered); + } + + *bytes_written = data_flushed + data_buffered; + return err; +} + + +/* Write BYTES_TO_WRITE bytes from BUFFER into STREAM in, storing the + amount of bytes written in BYTES_WRITTEN. */ +static int +es_writen (estream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, + size_t bytes_to_write, size_t *_GPGRT__RESTRICT bytes_written) +{ + size_t data_written; + int err; + + data_written = 0; + err = 0; + + if (!stream->flags.writing) + { + /* Switching to writing mode -> discard input data and seek to + position at which reading has stopped. We can do this only + if a seek function has been registered. */ + if (stream->intern->func_seek) + { + err = es_seek (stream, 0, SEEK_CUR, NULL); + if (err) + { + if (errno == ESPIPE) + err = 0; + else + goto out; + } + } + } + + switch (stream->intern->strategy) + { + case _IONBF: + err = es_write_nbf (stream, buffer, bytes_to_write, &data_written); + break; + + case _IOLBF: + err = es_write_lbf (stream, buffer, bytes_to_write, &data_written); + break; + + case _IOFBF: + err = es_write_fbf (stream, buffer, bytes_to_write, &data_written); + break; + } + + out: + + if (bytes_written) + *bytes_written = data_written; + if (data_written) + if (!stream->flags.writing) + stream->flags.writing = 1; + + return err; +} + + +static int +es_peek (estream_t _GPGRT__RESTRICT stream, unsigned char **_GPGRT__RESTRICT data, + size_t *_GPGRT__RESTRICT data_len) +{ + int err; + + if (stream->flags.writing) + { + /* Switching to reading mode -> flush output. */ + err = es_flush (stream); + if (err) + goto out; + stream->flags.writing = 0; + } + + if (stream->data_offset == stream->data_len) + { + /* Refill container. */ + err = es_fill (stream); + if (err) + goto out; + } + + if (data) + *data = stream->buffer + stream->data_offset; + if (data_len) + *data_len = stream->data_len - stream->data_offset; + err = 0; + + out: + + return err; +} + + +/* Skip SIZE bytes of input data contained in buffer. */ +static int +es_skip (estream_t stream, size_t size) +{ + int err; + + if (stream->data_offset + size > stream->data_len) + { + _set_errno (EINVAL); + err = -1; + } + else + { + stream->data_offset += size; + err = 0; + } + + return err; +} + + +static int +doreadline (estream_t _GPGRT__RESTRICT stream, size_t max_length, + char *_GPGRT__RESTRICT *_GPGRT__RESTRICT line, + size_t *_GPGRT__RESTRICT line_length) +{ + size_t space_left; + size_t line_size; + estream_t line_stream; + char *line_new; + void *line_stream_cookie; + char *newline; + unsigned char *data; + size_t data_len; + int err; + es_syshd_t syshd; + + line_new = NULL; + line_stream = NULL; + line_stream_cookie = NULL; + + err = func_mem_create (&line_stream_cookie, NULL, 0, 0, + BUFFER_BLOCK_SIZE, 1, + mem_realloc, mem_free, + O_RDWR, + 0); + if (err) + goto out; + + memset (&syshd, 0, sizeof syshd); + err = es_create (&line_stream, line_stream_cookie, &syshd, + estream_functions_mem, O_RDWR, 1, 0); + if (err) + goto out; + + space_left = max_length; + line_size = 0; + while (1) + { + if (max_length && (space_left == 1)) + break; + + err = es_peek (stream, &data, &data_len); + if (err || (! data_len)) + break; + + if (data_len > (space_left - 1)) + data_len = space_left - 1; + + newline = memchr (data, '\n', data_len); + if (newline) + { + data_len = (newline - (char *) data) + 1; + err = _gpgrt_write (line_stream, data, data_len, NULL); + if (! err) + { + space_left -= data_len; + line_size += data_len; + es_skip (stream, data_len); + break; + } + } + else + { + err = _gpgrt_write (line_stream, data, data_len, NULL); + if (! err) + { + space_left -= data_len; + line_size += data_len; + es_skip (stream, data_len); + } + } + if (err) + break; + } + if (err) + goto out; + + /* Complete line has been written to line_stream. */ + + if ((max_length > 1) && (! line_size)) + { + stream->intern->indicators.eof = 1; + goto out; + } + + err = es_seek (line_stream, 0, SEEK_SET, NULL); + if (err) + goto out; + + if (! *line) + { + line_new = mem_alloc (line_size + 1); + if (! line_new) + { + err = -1; + goto out; + } + } + else + line_new = *line; + + err = _gpgrt_read (line_stream, line_new, line_size, NULL); + if (err) + goto out; + + line_new[line_size] = '\0'; + + if (! *line) + *line = line_new; + if (line_length) + *line_length = line_size; + + out: + + if (line_stream) + do_close (line_stream, 0); + else if (line_stream_cookie) + es_func_mem_destroy (line_stream_cookie); + + if (err) + { + if (! *line) + mem_free (line_new); + stream->intern->indicators.err = 1; + } + + return err; +} + + +/* Output fucntion used for estream_format. */ +static int +print_writer (void *outfncarg, const char *buf, size_t buflen) +{ + estream_t stream = outfncarg; + size_t nwritten; + int rc; + + nwritten = 0; + rc = es_writen (stream, buf, buflen, &nwritten); + stream->intern->print_ntotal += nwritten; + return rc; +} + + +/* The core of our printf function. This is called in locked state. */ +static int +es_print (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, va_list ap) +{ + int rc; + + stream->intern->print_ntotal = 0; + rc = _gpgrt_estream_format (print_writer, stream, format, ap); + if (rc) + return -1; + return (int)stream->intern->print_ntotal; +} + + +static void +es_set_indicators (estream_t stream, int ind_err, int ind_eof) +{ + if (ind_err != -1) + stream->intern->indicators.err = ind_err ? 1 : 0; + if (ind_eof != -1) + stream->intern->indicators.eof = ind_eof ? 1 : 0; +} + + +static int +es_get_indicator (estream_t stream, int ind_err, int ind_eof) +{ + int ret = 0; + + if (ind_err) + ret = stream->intern->indicators.err; + else if (ind_eof) + ret = stream->intern->indicators.eof; + + return ret; +} + + +static int +es_set_buffering (estream_t _GPGRT__RESTRICT stream, + char *_GPGRT__RESTRICT buffer, int mode, size_t size) +{ + int err; + + /* Flush or empty buffer depending on mode. */ + if (stream->flags.writing) + { + err = es_flush (stream); + if (err) + goto out; + } + else + es_empty (stream); + + es_set_indicators (stream, -1, 0); + + /* Free old buffer in case that was allocated by this function. */ + if (stream->intern->deallocate_buffer) + { + stream->intern->deallocate_buffer = 0; + mem_free (stream->buffer); + stream->buffer = NULL; + } + + if (mode == _IONBF) + stream->buffer_size = 0; + else + { + void *buffer_new; + + if (buffer) + buffer_new = buffer; + else + { + if (!size) + size = BUFSIZ; + buffer_new = mem_alloc (size); + if (! buffer_new) + { + err = -1; + goto out; + } + } + + stream->buffer = buffer_new; + stream->buffer_size = size; + if (! buffer) + stream->intern->deallocate_buffer = 1; + } + stream->intern->strategy = mode; + err = 0; + + out: + + return err; +} + + +static gpgrt_off_t +es_offset_calculate (estream_t stream) +{ + gpgrt_off_t offset; + + offset = stream->intern->offset + stream->data_offset; + if (offset < stream->unread_data_len) + /* Offset undefined. */ + offset = 0; + else + offset -= stream->unread_data_len; + + return offset; +} + + +static void +es_opaque_ctrl (estream_t _GPGRT__RESTRICT stream, void *_GPGRT__RESTRICT opaque_new, + void **_GPGRT__RESTRICT opaque_old) +{ + if (opaque_old) + *opaque_old = stream->intern->opaque; + if (opaque_new) + stream->intern->opaque = opaque_new; +} + + +/* API. */ + +estream_t +_gpgrt_fopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode) +{ + unsigned int modeflags, cmode; + int samethread, create_called; + estream_t stream; + void *cookie; + int err; + int fd; + es_syshd_t syshd; + + stream = NULL; + cookie = NULL; + create_called = 0; + + err = parse_mode (mode, &modeflags, &samethread, &cmode); + if (err) + goto out; + + err = func_file_create (&cookie, &fd, path, modeflags, cmode); + if (err) + goto out; + + syshd.type = ES_SYSHD_FD; + syshd.u.fd = fd; + + create_called = 1; + err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags, + samethread, 0); + if (err) + goto out; + + if (stream && path) + fname_set_internal (stream, path, 1); + + out: + + if (err && create_called) + (*estream_functions_fd.func_close) (cookie); + + return stream; +} + + + +/* Create a new estream object in memory. If DATA is not NULL this + buffer will be used as the memory buffer; thus after this functions + returns with the success the the memory at DATA belongs to the new + estream. The allocated length of DATA is given by DATA_LEN and its + used length by DATA_N. Usually this is malloced buffer; if a + static buffer is provided, the caller must pass false for GROW and + provide a dummy function for FUNC_FREE. FUNC_FREE and FUNC_REALLOC + allow the caller to provide custom functions for realloc and free + to be used by the new estream object. Note that the realloc + function is also used for initial allocation. If DATA is NULL a + buffer is internally allocated; either using internal function or + those provide by the caller. It is an error to provide a realloc + function but no free function. Providing only a free function is + allowed as long as GROW is false. */ +estream_t +_gpgrt_mopen (void *_GPGRT__RESTRICT data, size_t data_n, size_t data_len, + unsigned int grow, + func_realloc_t func_realloc, func_free_t func_free, + const char *_GPGRT__RESTRICT mode) +{ + int create_called = 0; + estream_t stream = NULL; + void *cookie = NULL; + unsigned int modeflags; + int samethread; + int err; + es_syshd_t syshd; + + err = parse_mode (mode, &modeflags, &samethread, NULL); + if (err) + goto out; + + err = func_mem_create (&cookie, data, data_n, data_len, + BUFFER_BLOCK_SIZE, grow, + func_realloc, func_free, modeflags, 0); + if (err) + goto out; + + memset (&syshd, 0, sizeof syshd); + create_called = 1; + err = es_create (&stream, cookie, &syshd, + estream_functions_mem, modeflags, samethread, 0); + + out: + + if (err && create_called) + (*estream_functions_mem.func_close) (cookie); + + return stream; +} + + + +estream_t +_gpgrt_fopenmem (size_t memlimit, const char *_GPGRT__RESTRICT mode) +{ + unsigned int modeflags; + int samethread; + estream_t stream = NULL; + void *cookie = NULL; + es_syshd_t syshd; + + /* Memory streams are always read/write. We use MODE only to get + the append flag. */ + if (parse_mode (mode, &modeflags, &samethread, NULL)) + return NULL; + modeflags |= O_RDWR; + + if (func_mem_create (&cookie, NULL, 0, 0, + BUFFER_BLOCK_SIZE, 1, + mem_realloc, mem_free, modeflags, + memlimit)) + return NULL; + + memset (&syshd, 0, sizeof syshd); + if (es_create (&stream, cookie, &syshd, estream_functions_mem, modeflags, + samethread, 0)) + (*estream_functions_mem.func_close) (cookie); + + if (stream) + stream->intern->func_ioctl = es_func_mem_ioctl; + + return stream; +} + + +/* This is the same as es_fopenmem but intializes the memory with a + copy of (DATA,DATALEN). The stream is initally set to the + beginning. If MEMLIMIT is not 0 but shorter than DATALEN it + DATALEN will be used as the value for MEMLIMIT. */ +estream_t +_gpgrt_fopenmem_init (size_t memlimit, const char *_GPGRT__RESTRICT mode, + const void *data, size_t datalen) +{ + estream_t stream; + + if (memlimit && memlimit < datalen) + memlimit = datalen; + + stream = _gpgrt_fopenmem (memlimit, mode); + if (stream && data && datalen) + { + if (es_writen (stream, data, datalen, NULL)) + { + int saveerrno = errno; + _gpgrt_fclose (stream); + stream = NULL; + _set_errno (saveerrno); + } + else + { + es_seek (stream, 0L, SEEK_SET, NULL); + es_set_indicators (stream, 0, 0); + } + } + return stream; +} + + + +estream_t +_gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie, + const char *_GPGRT__RESTRICT mode, + gpgrt_cookie_io_functions_t functions) +{ + unsigned int modeflags; + int samethread; + estream_t stream; + int err; + es_syshd_t syshd; + + stream = NULL; + modeflags = 0; + + err = parse_mode (mode, &modeflags, &samethread, NULL); + if (err) + goto out; + + memset (&syshd, 0, sizeof syshd); + err = es_create (&stream, cookie, &syshd, functions, modeflags, + samethread, 0); + if (err) + goto out; + + out: + return stream; +} + + + +static estream_t +do_fdopen (int filedes, const char *mode, int no_close, int with_locked_list) +{ + unsigned int modeflags; + int samethread, create_called; + estream_t stream; + void *cookie; + int err; + es_syshd_t syshd; + + stream = NULL; + cookie = NULL; + create_called = 0; + + err = parse_mode (mode, &modeflags, &samethread, NULL); + if (err) + goto out; + + err = func_fd_create (&cookie, filedes, modeflags, no_close); + if (err) + goto out; + + syshd.type = ES_SYSHD_FD; + syshd.u.fd = filedes; + create_called = 1; + err = es_create (&stream, cookie, &syshd, estream_functions_fd, + modeflags, samethread, with_locked_list); + + out: + if (err && create_called) + (*estream_functions_fd.func_close) (cookie); + + return stream; +} + +estream_t +_gpgrt_fdopen (int filedes, const char *mode) +{ + return do_fdopen (filedes, mode, 0, 0); +} + +/* A variant of es_fdopen which does not close FILEDES at the end. */ +estream_t +_gpgrt_fdopen_nc (int filedes, const char *mode) +{ + return do_fdopen (filedes, mode, 1, 0); +} + + + +static estream_t +do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list) +{ + unsigned int modeflags, cmode; + int samethread, create_called; + estream_t stream; + void *cookie; + int err; + es_syshd_t syshd; + + stream = NULL; + cookie = NULL; + create_called = 0; + + err = parse_mode (mode, &modeflags, &samethread, &cmode); + if (err) + goto out; + + if (fp) + fflush (fp); + err = func_fp_create (&cookie, fp, modeflags, no_close); + if (err) + goto out; + + syshd.type = ES_SYSHD_FD; + syshd.u.fd = fp? fileno (fp): -1; + create_called = 1; + err = es_create (&stream, cookie, &syshd, estream_functions_fp, + modeflags, samethread, with_locked_list); + + out: + + if (err && create_called) + (*estream_functions_fp.func_close) (cookie); + + return stream; +} + + +/* Create an estream from the stdio stream FP. This mechanism is + useful in case the stdio streams have special properties and may + not be mixed with fd based functions. This is for example the case + under Windows where the 3 standard streams are associated with the + console whereas a duped and fd-opened stream of one of this stream + won't be associated with the console. As this messes things up it + is easier to keep on using the standard I/O stream as a backend for + estream. */ +estream_t +_gpgrt_fpopen (FILE *fp, const char *mode) +{ + return do_fpopen (fp, mode, 0, 0); +} + + +/* Same as es_fpopen but does not close FP at the end. */ +estream_t +_gpgrt_fpopen_nc (FILE *fp, const char *mode) +{ + return do_fpopen (fp, mode, 1, 0); +} + + + +#ifdef HAVE_W32_SYSTEM +estream_t +do_w32open (HANDLE hd, const char *mode, + int no_close, int with_locked_list) +{ + unsigned int modeflags, cmode; + int samethread; + int create_called = 0; + estream_t stream = NULL; + void *cookie = NULL; + int err; + es_syshd_t syshd; + + err = parse_mode (mode, &modeflags, &samethread, &cmode); + if (err) + goto leave; + + err = es_func_w32_create (&cookie, hd, modeflags, no_close); + if (err) + goto leave; + + syshd.type = ES_SYSHD_HANDLE; + syshd.u.handle = hd; + create_called = 1; + err = es_create (&stream, cookie, &syshd, estream_functions_w32, + modeflags, samethread, with_locked_list); + + leave: + if (err && create_called) + (*estream_functions_w32.func_close) (cookie); + + return stream; +} +#endif /*HAVE_W32_SYSTEM*/ + +static estream_t +do_sysopen (es_syshd_t *syshd, const char *mode, int no_close) +{ + estream_t stream; + + switch (syshd->type) + { + case ES_SYSHD_FD: + case ES_SYSHD_SOCK: + stream = do_fdopen (syshd->u.fd, mode, no_close, 0); + break; + +#ifdef HAVE_W32_SYSTEM + case ES_SYSHD_HANDLE: + stream = do_w32open (syshd->u.handle, mode, no_close, 0); + break; +#endif + + /* FIXME: Support RVIDs under Wince? */ + + default: + _set_errno (EINVAL); + stream = NULL; + } + return stream; +} + +/* On POSIX systems this function is an alias for es_fdopen. Under + Windows it uses the bare W32 API and thus a HANDLE instead of a + file descriptor. */ +estream_t +_gpgrt_sysopen (es_syshd_t *syshd, const char *mode) +{ + return do_sysopen (syshd, mode, 0); +} + +/* Same as es_sysopen but the handle/fd will not be closed by + es_fclose. */ +estream_t +_gpgrt_sysopen_nc (es_syshd_t *syshd, const char *mode) +{ + return do_sysopen (syshd, mode, 1); +} + + + +/* Set custom standard descriptors to be used for stdin, stdout and + stderr. This function needs to be called before any of the + standard streams are accessed. This internal version uses a double + dash inside its name. */ +void +_gpgrt__set_std_fd (int no, int fd) +{ + /* fprintf (stderr, "es_set_std_fd(%d, %d)\n", no, fd); */ + lock_list (); + if (no >= 0 && no < 3 && !custom_std_fds_valid[no]) + { + custom_std_fds[no] = fd; + custom_std_fds_valid[no] = 1; + } + unlock_list (); +} + + +/* Return the stream used for stdin, stdout or stderr. + This internal version uses a double dash inside its name. */ +estream_t +_gpgrt__get_std_stream (int fd) +{ + estream_list_t list_obj; + estream_t stream = NULL; + + fd %= 3; /* We only allow 0, 1 or 2 but we don't want to return an error. */ + + lock_list (); + + for (list_obj = estream_list; list_obj; list_obj = list_obj->next) + if (list_obj->stream && list_obj->stream->intern->is_stdstream + && list_obj->stream->intern->stdstream_fd == fd) + { + stream = list_obj->stream; + break; + } + if (!stream) + { + /* Standard stream not yet created. We first try to create them + from registered file descriptors. */ + if (!fd && custom_std_fds_valid[0]) + stream = do_fdopen (custom_std_fds[0], "r", 1, 1); + else if (fd == 1 && custom_std_fds_valid[1]) + stream = do_fdopen (custom_std_fds[1], "a", 1, 1); + else if (custom_std_fds_valid[2]) + stream = do_fdopen (custom_std_fds[2], "a", 1, 1); + + if (!stream) + { + /* Second try is to use the standard C streams. */ + if (!fd) + stream = do_fpopen (stdin, "r", 1, 1); + else if (fd == 1) + stream = do_fpopen (stdout, "a", 1, 1); + else + stream = do_fpopen (stderr, "a", 1, 1); + } + + if (!stream) + { + /* Last try: Create a bit bucket. */ + stream = do_fpopen (NULL, fd? "a":"r", 0, 1); + if (!stream) + { + fprintf (stderr, "fatal: error creating a dummy estream" + " for %d: %s\n", fd, strerror (errno)); + abort(); + } + } + + stream->intern->is_stdstream = 1; + stream->intern->stdstream_fd = fd; + if (fd == 2) + es_set_buffering (stream, NULL, _IOLBF, 0); + fname_set_internal (stream, + fd == 0? "[stdin]" : + fd == 1? "[stdout]" : "[stderr]", 0); + } + + unlock_list (); + return stream; +} + +/* Note: A "samethread" keyword given in "mode" is ignored and the + value used by STREAM is used instead. */ +estream_t +_gpgrt_freopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode, + estream_t _GPGRT__RESTRICT stream) +{ + int err; + + if (path) + { + unsigned int modeflags, cmode; + int dummy, samethread, create_called; + void *cookie; + int fd; + es_syshd_t syshd; + + cookie = NULL; + create_called = 0; + + samethread = stream->intern->samethread; + + lock_stream (stream); + + es_deinitialize (stream); + + err = parse_mode (mode, &modeflags, &dummy, &cmode); + if (err) + goto leave; + (void)dummy; + + err = func_file_create (&cookie, &fd, path, modeflags, cmode); + if (err) + goto leave; + + syshd.type = ES_SYSHD_FD; + syshd.u.fd = fd; + create_called = 1; + init_stream_obj (stream, cookie, &syshd, estream_functions_fd, + modeflags, samethread); + + leave: + + if (err) + { + if (create_called) + es_func_fd_destroy (cookie); + + do_close (stream, 0); + stream = NULL; + } + else + { + if (path) + fname_set_internal (stream, path, 1); + unlock_stream (stream); + } + } + else + { + /* FIXME? We don't support re-opening at the moment. */ + _set_errno (EINVAL); + es_deinitialize (stream); + do_close (stream, 0); + stream = NULL; + } + + return stream; +} + + +int +_gpgrt_fclose (estream_t stream) +{ + int err; + + err = do_close (stream, 0); + + return err; +} + + +/* This is a special version of es_fclose which can be used with + es_fopenmem to return the memory buffer. This is feature is useful + to write to a memory buffer using estream. Note that the function + does not close the stream if the stream does not support snatching + the buffer. On error NULL is stored at R_BUFFER. Note that if no + write operation has happened, NULL may also be stored at BUFFER on + success. The caller needs to release the returned memory using + gpgrt_free. */ +int +_gpgrt_fclose_snatch (estream_t stream, void **r_buffer, size_t *r_buflen) +{ + int err; + + /* Note: There is no need to lock the stream in a close call. The + object will be destroyed after the close and thus any other + contender for the lock would work on a closed stream. */ + + if (r_buffer) + { + cookie_ioctl_function_t func_ioctl = stream->intern->func_ioctl; + size_t buflen; + + *r_buffer = NULL; + + if (!func_ioctl) + { + _set_errno (EOPNOTSUPP); + err = -1; + goto leave; + } + + if (stream->flags.writing) + { + err = es_flush (stream); + if (err) + goto leave; + stream->flags.writing = 0; + } + + err = func_ioctl (stream->intern->cookie, COOKIE_IOCTL_SNATCH_BUFFER, + r_buffer, &buflen); + if (err) + goto leave; + if (r_buflen) + *r_buflen = buflen; + } + + err = do_close (stream, 0); + + leave: + if (err && r_buffer) + { + mem_free (*r_buffer); + *r_buffer = NULL; + } + return err; +} + + +/* Register or unregister a close notification function for STREAM. + FNC is the function to call and FNC_VALUE the value passed as + second argument. To register the notification the value for MODE + must be 1. If mode is 0 the function tries to remove or disable an + already registered notification; for this to work the value of FNC + and FNC_VALUE must be the same as with the registration and + FNC_VALUE must be a unique value. No error will be returned if + MODE is 0. + + FIXME: I think the next comment is not anymore correct: + Unregister should only be used in the error case because it may not + be able to remove memory internally allocated for the onclose + handler. + + FIXME: Unregister is not thread safe. + + The notification will be called right before the stream is closed. + It may not call any estream function for STREAM, neither direct nor + indirectly. */ +int +_gpgrt_onclose (estream_t stream, int mode, + void (*fnc) (estream_t, void*), void *fnc_value) +{ + int err; + + lock_stream (stream); + err = do_onclose (stream, mode, fnc, fnc_value); + unlock_stream (stream); + + return err; +} + + +int +_gpgrt_fileno_unlocked (estream_t stream) +{ + es_syshd_t syshd; + + if (_gpgrt_syshd_unlocked (stream, &syshd)) + return -1; + switch (syshd.type) + { + case ES_SYSHD_FD: return syshd.u.fd; + case ES_SYSHD_SOCK: return syshd.u.sock; + default: + _set_errno (EINVAL); + return -1; + } +} + + +/* Return the handle of a stream which has been opened by es_sysopen. + The caller needs to pass a structure which will be filled with the + sys handle. Return 0 on success or true on error and sets errno. + This is the unlocked version. */ +int +_gpgrt_syshd_unlocked (estream_t stream, es_syshd_t *syshd) +{ + if (!stream || !syshd || stream->intern->syshd.type == ES_SYSHD_NONE) + { + if (syshd) + syshd->type = ES_SYSHD_NONE; + _set_errno (EINVAL); + return -1; + } + + *syshd = stream->intern->syshd; + return 0; +} + + +void +_gpgrt_flockfile (estream_t stream) +{ + lock_stream (stream); +} + + +int +_gpgrt_ftrylockfile (estream_t stream) +{ + return trylock_stream (stream); +} + + +void +_gpgrt_funlockfile (estream_t stream) +{ + unlock_stream (stream); +} + + +int +_gpgrt_fileno (estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_fileno_unlocked (stream); + unlock_stream (stream); + + return ret; +} + + +/* Return the handle of a stream which has been opened by es_sysopen. + The caller needs to pass a structure which will be filled with the + sys handle. Return 0 on success or true on error and sets errno. + This is the unlocked version. */ +int +_gpgrt_syshd (estream_t stream, es_syshd_t *syshd) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_syshd_unlocked (stream, syshd); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt__pending_unlocked (estream_t stream) +{ + return check_pending (stream); +} + + +/* Return true if there is at least one byte pending for read on + STREAM. This does only work if the backend supports checking for + pending bytes and is thus mostly useful with cookie based backends. + + Note that if this function is used with cookie based functions, the + read cookie may be called with 0 for the SIZE argument. If bytes + are pending the function is expected to return -1 in this case and + thus deviates from the standard behavior of read(2). */ +int +_gpgrt__pending (estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt__pending_unlocked (stream); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt_feof_unlocked (estream_t stream) +{ + return es_get_indicator (stream, 0, 1); +} + + +int +_gpgrt_feof (estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_feof_unlocked (stream); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt_ferror_unlocked (estream_t stream) +{ + return es_get_indicator (stream, 1, 0); +} + + +int +_gpgrt_ferror (estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_ferror_unlocked (stream); + unlock_stream (stream); + + return ret; +} + + +void +_gpgrt_clearerr_unlocked (estream_t stream) +{ + es_set_indicators (stream, 0, 0); +} + + +void +_gpgrt_clearerr (estream_t stream) +{ + lock_stream (stream); + _gpgrt_clearerr_unlocked (stream); + unlock_stream (stream); +} + + +static int +do_fflush (estream_t stream) +{ + int err; + + if (stream->flags.writing) + err = es_flush (stream); + else + { + es_empty (stream); + err = 0; + } + + return err; +} + + +int +_gpgrt_fflush (estream_t stream) +{ + int err; + + if (stream) + { + lock_stream (stream); + err = do_fflush (stream); + unlock_stream (stream); + } + else + { + estream_list_t item; + + err = 0; + lock_list (); + for (item = estream_list; item; item = item->next) + if (item->stream) + { + lock_stream (item->stream); + err |= do_fflush (item->stream); + unlock_stream (item->stream); + } + unlock_list (); + } + return err ? EOF : 0; +} + + +int +_gpgrt_fseek (estream_t stream, long int offset, int whence) +{ + int err; + + lock_stream (stream); + err = es_seek (stream, offset, whence, NULL); + unlock_stream (stream); + + return err; +} + + +int +_gpgrt_fseeko (estream_t stream, gpgrt_off_t offset, int whence) +{ + int err; + + lock_stream (stream); + err = es_seek (stream, offset, whence, NULL); + unlock_stream (stream); + + return err; +} + + +long int +_gpgrt_ftell (estream_t stream) +{ + long int ret; + + lock_stream (stream); + ret = es_offset_calculate (stream); + unlock_stream (stream); + + return ret; +} + + +gpgrt_off_t +_gpgrt_ftello (estream_t stream) +{ + gpgrt_off_t ret = -1; + + lock_stream (stream); + ret = es_offset_calculate (stream); + unlock_stream (stream); + + return ret; +} + + +void +_gpgrt_rewind (estream_t stream) +{ + lock_stream (stream); + es_seek (stream, 0L, SEEK_SET, NULL); + es_set_indicators (stream, 0, -1); + unlock_stream (stream); +} + + +int +_gpgrt__getc_underflow (estream_t stream) +{ + int err; + unsigned char c; + size_t bytes_read; + + err = es_readn (stream, &c, 1, &bytes_read); + + return (err || (! bytes_read)) ? EOF : c; +} + + +int +_gpgrt__putc_overflow (int c, estream_t stream) +{ + unsigned char d = c; + int err; + + err = es_writen (stream, &d, 1, NULL); + + return err ? EOF : c; +} + + +int +_gpgrt_fgetc (estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_getc_unlocked (stream); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt_fputc (int c, estream_t stream) +{ + int ret; + + lock_stream (stream); + ret = _gpgrt_putc_unlocked (c, stream); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt_ungetc (int c, estream_t stream) +{ + unsigned char data = (unsigned char) c; + size_t data_unread; + + lock_stream (stream); + es_unreadn (stream, &data, 1, &data_unread); + unlock_stream (stream); + + return data_unread ? c : EOF; +} + + +int +_gpgrt_read (estream_t _GPGRT__RESTRICT stream, + void *_GPGRT__RESTRICT buffer, size_t bytes_to_read, + size_t *_GPGRT__RESTRICT bytes_read) +{ + int err; + + if (bytes_to_read) + { + lock_stream (stream); + err = es_readn (stream, buffer, bytes_to_read, bytes_read); + unlock_stream (stream); + } + else + err = 0; + + return err; +} + + +int +_gpgrt_write (estream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write, + size_t *_GPGRT__RESTRICT bytes_written) +{ + int err; + + if (bytes_to_write) + { + lock_stream (stream); + err = es_writen (stream, buffer, bytes_to_write, bytes_written); + unlock_stream (stream); + } + else + err = 0; + + return err; +} + + +size_t +_gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems, + estream_t _GPGRT__RESTRICT stream) +{ + size_t ret, bytes; + + if (size * nitems) + { + lock_stream (stream); + es_readn (stream, ptr, size * nitems, &bytes); + unlock_stream (stream); + + ret = bytes / size; + } + else + ret = 0; + + return ret; +} + + +size_t +_gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems, + estream_t _GPGRT__RESTRICT stream) +{ + size_t ret, bytes; + + if (size * nitems) + { + lock_stream (stream); + es_writen (stream, ptr, size * nitems, &bytes); + unlock_stream (stream); + + ret = bytes / size; + } + else + ret = 0; + + return ret; +} + + +char * +_gpgrt_fgets (char *_GPGRT__RESTRICT buffer, int length, + estream_t _GPGRT__RESTRICT stream) +{ + unsigned char *s = (unsigned char*)buffer; + int c; + + if (!length) + return NULL; + + c = EOF; + lock_stream (stream); + while (length > 1 && (c = _gpgrt_getc_unlocked (stream)) != EOF && c != '\n') + { + *s++ = c; + length--; + } + unlock_stream (stream); + + if (c == EOF && s == (unsigned char*)buffer) + return NULL; /* Nothing read. */ + + if (c != EOF && length > 1) + *s++ = c; + + *s = 0; + return buffer; +} + + +int +_gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s, + estream_t _GPGRT__RESTRICT stream) +{ + size_t length; + int err; + + length = strlen (s); + err = es_writen (stream, s, length, NULL); + return err ? EOF : 0; +} + +int +_gpgrt_fputs (const char *_GPGRT__RESTRICT s, estream_t _GPGRT__RESTRICT stream) +{ + size_t length; + int err; + + length = strlen (s); + lock_stream (stream); + err = es_writen (stream, s, length, NULL); + unlock_stream (stream); + + return err ? EOF : 0; +} + + +gpgrt_ssize_t +_gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, + size_t *_GPGRT__RESTRICT n, estream_t _GPGRT__RESTRICT stream) +{ + char *line = NULL; + size_t line_n = 0; + int err; + + lock_stream (stream); + err = doreadline (stream, 0, &line, &line_n); + unlock_stream (stream); + if (err) + goto out; + + if (*n) + { + /* Caller wants us to use his buffer. */ + + if (*n < (line_n + 1)) + { + /* Provided buffer is too small -> resize. */ + + void *p; + + p = mem_realloc (*lineptr, line_n + 1); + if (! p) + err = -1; + else + { + if (*lineptr != p) + *lineptr = p; + } + } + + if (! err) + { + memcpy (*lineptr, line, line_n + 1); + if (*n != line_n) + *n = line_n; + } + mem_free (line); + } + else + { + /* Caller wants new buffers. */ + *lineptr = line; + *n = line_n; + } + + out: + + return err ? err : (gpgrt_ssize_t)line_n; +} + + + +/* Same as fgets() but if the provided buffer is too short a larger + one will be allocated. This is similar to getline. A line is + considered a byte stream ending in a LF. + + If MAX_LENGTH is not NULL, it shall point to a value with the + maximum allowed allocation. + + Returns the length of the line. EOF is indicated by a line of + length zero. A truncated line is indicated my setting the value at + MAX_LENGTH to 0. If the returned value is less then 0 not enough + memory was enable or another error occurred; ERRNO is then set + accordingly. + + If a line has been truncated, the file pointer is moved forward to + the end of the line so that the next read starts with the next + line. Note that MAX_LENGTH must be re-initialzied in this case. + + The caller initially needs to provide the address of a variable, + initialized to NULL, at ADDR_OF_BUFFER and don't change this value + anymore with the following invocations. LENGTH_OF_BUFFER should be + the address of a variable, initialized to 0, which is also + maintained by this function. Thus, both paramaters should be + considered the state of this function. + + Note: The returned buffer is allocated with enough extra space to + allow the caller to append a CR,LF,Nul. The buffer should be + released using gpgrt_free. + */ +gpgrt_ssize_t +_gpgrt_read_line (estream_t stream, + char **addr_of_buffer, size_t *length_of_buffer, + size_t *max_length) +{ + int c; + char *buffer = *addr_of_buffer; + size_t length = *length_of_buffer; + size_t nbytes = 0; + size_t maxlen = max_length? *max_length : 0; + char *p; + + if (!buffer) + { + /* No buffer given - allocate a new one. */ + length = 256; + buffer = mem_alloc (length); + *addr_of_buffer = buffer; + if (!buffer) + { + *length_of_buffer = 0; + if (max_length) + *max_length = 0; + return -1; + } + *length_of_buffer = length; + } + + if (length < 4) + { + /* This should never happen. If it does, the function has been + called with wrong arguments. */ + _set_errno (EINVAL); + return -1; + } + length -= 3; /* Reserve 3 bytes for CR,LF,EOL. */ + + lock_stream (stream); + p = buffer; + while ((c = _gpgrt_getc_unlocked (stream)) != EOF) + { + if (nbytes == length) + { + /* Enlarge the buffer. */ + if (maxlen && length > maxlen) + { + /* We are beyond our limit: Skip the rest of the line. */ + while (c != '\n' && (c=_gpgrt_getc_unlocked (stream)) != EOF) + ; + *p++ = '\n'; /* Always append a LF (we reserved some space). */ + nbytes++; + if (max_length) + *max_length = 0; /* Indicate truncation. */ + break; /* the while loop. */ + } + length += 3; /* Adjust for the reserved bytes. */ + length += length < 1024? 256 : 1024; + *addr_of_buffer = mem_realloc (buffer, length); + if (!*addr_of_buffer) + { + int save_errno = errno; + mem_free (buffer); + *length_of_buffer = 0; + if (max_length) + *max_length = 0; + unlock_stream (stream); + _set_errno (save_errno); + return -1; + } + buffer = *addr_of_buffer; + *length_of_buffer = length; + length -= 3; + p = buffer + nbytes; + } + *p++ = c; + nbytes++; + if (c == '\n') + break; + } + *p = 0; /* Make sure the line is a string. */ + unlock_stream (stream); + + return nbytes; +} + +/* Wrapper around free() to match the memory allocation system used by + estream. Should be used for all buffers returned to the caller by + libestream. If a custom allocation handler has been set with + gpgrt_set_alloc_func that register function may be used + instead. This function has been moved to init.c. */ +/* void */ +/* _gpgrt_free (void *a) */ +/* { */ +/* mem_free (a); */ +/* } */ + + +int +_gpgrt_vfprintf_unlocked (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, + va_list ap) +{ + return es_print (stream, format, ap); +} + + +int +_gpgrt_vfprintf (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, + va_list ap) +{ + int ret; + + lock_stream (stream); + ret = es_print (stream, format, ap); + unlock_stream (stream); + + return ret; +} + + +int +_gpgrt_fprintf_unlocked (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) +{ + int ret; + + va_list ap; + va_start (ap, format); + ret = es_print (stream, format, ap); + va_end (ap); + + return ret; +} + + +int +_gpgrt_fprintf (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) +{ + int ret; + + va_list ap; + va_start (ap, format); + lock_stream (stream); + ret = es_print (stream, format, ap); + unlock_stream (stream); + va_end (ap); + + return ret; +} + + +static int +tmpfd (void) +{ +#ifdef HAVE_W32_SYSTEM + int attempts, n; +#ifdef HAVE_W32CE_SYSTEM + wchar_t buffer[MAX_PATH+9+12+1]; +# define mystrlen(a) wcslen (a) + wchar_t *name, *p; +#else + char buffer[MAX_PATH+9+12+1]; +# define mystrlen(a) strlen (a) + char *name, *p; +#endif + HANDLE file; + int pid = GetCurrentProcessId (); + unsigned int value; + int i; + + n = GetTempPath (MAX_PATH+1, buffer); + if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH) + { + _set_errno (ENOENT); + return -1; + } + p = buffer + mystrlen (buffer); +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L"_estream"); +#else + strcpy (p, "_estream"); +#endif + p += 8; + /* We try to create the directory but don't care about an error as + it may already exist and the CreateFile would throw an error + anyway. */ + CreateDirectory (buffer, NULL); + *p++ = '\\'; + name = p; + for (attempts=0; attempts < 10; attempts++) + { + p = name; + value = (GetTickCount () ^ ((pid<<16) & 0xffff0000)); + for (i=0; i < 8; i++) + { + *p++ = tohex (((value >> 28) & 0x0f)); + value <<= 4; + } +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L".tmp"); +#else + strcpy (p, ".tmp"); +#endif + file = CreateFile (buffer, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, + NULL); + if (file != INVALID_HANDLE_VALUE) + { +#ifdef HAVE_W32CE_SYSTEM + int fd = (int)file; +#else + int fd = _open_osfhandle ((long)file, 0); + if (fd == -1) + { + CloseHandle (file); + return -1; + } +#endif + return fd; + } + Sleep (1); /* One ms as this is the granularity of GetTickCount. */ + } + _set_errno (ENOENT); + return -1; +#else /*!HAVE_W32_SYSTEM*/ + FILE *fp; + int fp_fd; + int fd; + + fp = NULL; + fd = -1; + + fp = tmpfile (); + if (! fp) + goto out; + + fp_fd = fileno (fp); + fd = dup (fp_fd); + + out: + + if (fp) + fclose (fp); + + return fd; +#endif /*!HAVE_W32_SYSTEM*/ +} + +estream_t +_gpgrt_tmpfile (void) +{ + unsigned int modeflags; + int create_called; + estream_t stream; + void *cookie; + int err; + int fd; + es_syshd_t syshd; + + create_called = 0; + stream = NULL; + modeflags = O_RDWR | O_TRUNC | O_CREAT; + cookie = NULL; + + fd = tmpfd (); + if (fd == -1) + { + err = -1; + goto out; + } + + err = func_fd_create (&cookie, fd, modeflags, 0); + if (err) + goto out; + + syshd.type = ES_SYSHD_FD; + syshd.u.fd = fd; + create_called = 1; + err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags, + 0, 0); + + out: + if (err) + { + if (create_called) + es_func_fd_destroy (cookie); + else if (fd != -1) + close (fd); + stream = NULL; + } + + return stream; +} + + +int +_gpgrt_setvbuf (estream_t _GPGRT__RESTRICT stream, + char *_GPGRT__RESTRICT buf, int type, size_t size) +{ + int err; + + if ((type == _IOFBF || type == _IOLBF || type == _IONBF) + && (!buf || size || type == _IONBF)) + { + lock_stream (stream); + err = es_set_buffering (stream, buf, type, size); + unlock_stream (stream); + } + else + { + _set_errno (EINVAL); + err = -1; + } + + return err; +} + + +/* Put a stream into binary mode. This is only needed for the + standard streams if they are to be used in a binary way. On Unix + systems it is never needed but MSDOS based systems require such a + call. It needs to be called before any I/O is done on STREAM. */ +void +_gpgrt_set_binary (estream_t stream) +{ + lock_stream (stream); + if (!(stream->intern->modeflags & O_BINARY)) + { + stream->intern->modeflags |= O_BINARY; +#ifdef HAVE_DOSISH_SYSTEM + if (stream->intern->func_read == es_func_fd_read) + { + estream_cookie_fd_t fd_cookie = stream->intern->cookie; + + if (!IS_INVALID_FD (fd_cookie->fd)) + setmode (fd_cookie->fd, O_BINARY); + } + else if (stream->intern->func_read == es_func_fp_read) + { + estream_cookie_fp_t fp_cookie = stream->intern->cookie; + + if (fp_cookie->fp) + setmode (fileno (fp_cookie->fp), O_BINARY); + } +#endif + } + unlock_stream (stream); +} + + +void +_gpgrt_opaque_set (estream_t stream, void *opaque) +{ + lock_stream (stream); + es_opaque_ctrl (stream, opaque, NULL); + unlock_stream (stream); +} + + +void * +_gpgrt_opaque_get (estream_t stream) +{ + void *opaque; + + lock_stream (stream); + es_opaque_ctrl (stream, NULL, &opaque); + unlock_stream (stream); + + return opaque; +} + + +static void +fname_set_internal (estream_t stream, const char *fname, int quote) +{ + if (stream->intern->printable_fname + && !stream->intern->printable_fname_inuse) + { + mem_free (stream->intern->printable_fname); + stream->intern->printable_fname = NULL; + } + if (stream->intern->printable_fname) + return; /* Can't change because it is in use. */ + + if (*fname != '[') + quote = 0; + else + quote = !!quote; + + stream->intern->printable_fname = mem_alloc (strlen (fname) + quote + 1); + if (fname) + { + if (quote) + stream->intern->printable_fname[0] = '\\'; + strcpy (stream->intern->printable_fname+quote, fname); + } +} + + +/* Set the filename attribute of STREAM. There is no error return. + as long as STREAM is valid. This function is called internally by + functions which open a filename. */ +void +_gpgrt_fname_set (estream_t stream, const char *fname) +{ + if (fname) + { + lock_stream (stream); + fname_set_internal (stream, fname, 1); + unlock_stream (stream); + } +} + + +/* Return the filename attribute of STREAM. In case no filename has + been set, "[?]" will be returned. The returned file name is valid + as long as STREAM is valid. */ +const char * +_gpgrt_fname_get (estream_t stream) +{ + const char *fname; + + lock_stream (stream); + fname = stream->intern->printable_fname; + if (fname) + stream->intern->printable_fname_inuse = 1; + unlock_stream (stream); + if (!fname) + fname = "[?]"; + return fname; +} + + +/* Print a BUFFER to STREAM while replacing all control characters and + the characters in DELIMITERS by standard C escape sequences. + Returns 0 on success or -1 on error. If BYTES_WRITTEN is not NULL + the number of bytes actually written are stored at this + address. */ +int +_gpgrt_write_sanitized (estream_t _GPGRT__RESTRICT stream, + const void * _GPGRT__RESTRICT buffer, size_t length, + const char * delimiters, + size_t * _GPGRT__RESTRICT bytes_written) +{ + const unsigned char *p = buffer; + size_t count = 0; + int ret; + + lock_stream (stream); + for (; length; length--, p++, count++) + { + if (*p < 0x20 + || *p == 0x7f + || (delimiters + && (strchr (delimiters, *p) || *p == '\\'))) + { + _gpgrt_putc_unlocked ('\\', stream); + count++; + if (*p == '\n') + { + _gpgrt_putc_unlocked ('n', stream); + count++; + } + else if (*p == '\r') + { + _gpgrt_putc_unlocked ('r', stream); + count++; + } + else if (*p == '\f') + { + _gpgrt_putc_unlocked ('f', stream); + count++; + } + else if (*p == '\v') + { + _gpgrt_putc_unlocked ('v', stream); + count++; + } + else if (*p == '\b') + { + _gpgrt_putc_unlocked ('b', stream); + count++; + } + else if (!*p) + { + _gpgrt_putc_unlocked('0', stream); + count++; + } + else + { + _gpgrt_fprintf_unlocked (stream, "x%02x", *p); + count += 3; + } + } + else + { + _gpgrt_putc_unlocked (*p, stream); + count++; + } + } + + if (bytes_written) + *bytes_written = count; + ret = _gpgrt_ferror_unlocked (stream)? -1 : 0; + unlock_stream (stream); + + return ret; +} + + +/* Write LENGTH bytes of BUFFER to STREAM as a hex encoded string. + RESERVED must be 0. Returns 0 on success or -1 on error. If + BYTES_WRITTEN is not NULL the number of bytes actually written are + stored at this address. */ +int +_gpgrt_write_hexstring (estream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t length, + int reserved, size_t *_GPGRT__RESTRICT bytes_written ) +{ + int ret; + const unsigned char *s; + size_t count = 0; + + (void)reserved; + +#define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) + + if (!length) + return 0; + + lock_stream (stream); + + for (s = buffer; length; s++, length--) + { + _gpgrt_putc_unlocked ( tohex ((*s>>4)&15), stream); + _gpgrt_putc_unlocked ( tohex (*s&15), stream); + count += 2; + } + + if (bytes_written) + *bytes_written = count; + ret = _gpgrt_ferror_unlocked (stream)? -1 : 0; + + unlock_stream (stream); + + return ret; + +#undef tohex +} diff --git a/plugins/MirOTR/Libgpg-error/extra-h.in b/plugins/MirOTR/Libgpg-error/extra-h.in deleted file mode 100644 index 197ee272f8..0000000000 --- a/plugins/MirOTR/Libgpg-error/extra-h.in +++ /dev/null @@ -1,41 +0,0 @@ -## w32-add.h - Snippet to be be included into gpg-error.h. -## Comments are indicated by a double hash mark. Due to a -## peculiarity of the script the first used line must not -## start with a hash mark. - -/* Decide whether to use the format_arg attribute. */ -#if _GPG_ERR_GCC_VERSION > 20800 -# define _GPG_ERR_ATTR_FORMAT_ARG(a) __attribute__ ((__format_arg__ (a))) -#else -# define _GPG_ERR_ATTR_FORMAT_ARG(a) -#endif - -/* A lean gettext implementation based on GNU style mo files which are - required to be encoded in UTF-8. There is a limit on 65534 entries - to save some RAM. Only Germanic plural rules are supported. */ -const char *_gpg_w32_bindtextdomain (const char *domainname, - const char *dirname); -const char *_gpg_w32_textdomain (const char *domainname); -const char *_gpg_w32_gettext (const char *msgid) - _GPG_ERR_ATTR_FORMAT_ARG (1); -const char *_gpg_w32_dgettext (const char *domainname, const char *msgid) - _GPG_ERR_ATTR_FORMAT_ARG (2); -const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1, - const char *msgid2, unsigned long int n) - _GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3); -const char *_gpg_w32_gettext_localename (void); -int _gpg_w32_gettext_use_utf8 (int value); - -#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS -# define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b)) -# define textdomain(a) _gpg_w32_textdomain ((a)) -# define gettext(a) _gpg_w32_gettext ((a)) -# define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) -# define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) -# define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) -# define gettext_localename() _gpg_w32_gettext_localename () -# define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) -#endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/ - - -EOF diff --git a/plugins/MirOTR/Libgpg-error/gen-posix-lock-obj.c b/plugins/MirOTR/Libgpg-error/gen-posix-lock-obj.c new file mode 100644 index 0000000000..d2bc645947 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/gen-posix-lock-obj.c @@ -0,0 +1,131 @@ +/* gen-posix-lock-obj.c - Build tool to construct the lock object. + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_W32_SYSTEM +# error This module may not be build for Windows. +#endif + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> +#include <pthread.h> + +#include "posix-lock-obj.h" + +#define PGM "gen-posix-lock-obj" + +/* Check that configure did its job. */ +#if SIZEOF_PTHREAD_MUTEX_T < 4 +# error sizeof pthread_mutex_t is not known. +#endif + +/* Special requirements for certain platforms. */ +#if defined(__hppa__) && defined(__linux__) +# define USE_16BYTE_ALIGNMENT 1 +#else +# define USE_16BYTE_ALIGNMENT 0 +#endif + + +#if USE_16BYTE_ALIGNMENT && !HAVE_GCC_ATTRIBUTE_ALIGNED +# error compiler is not able to enforce a 16 byte alignment +#endif + + +static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; + + +int +main (void) +{ + unsigned char *p; + int i; + struct { + pthread_mutex_t mtx; + long vers; + } dummyobj; + + if (sizeof mtx != SIZEOF_PTHREAD_MUTEX_T) + { + fprintf (stderr, PGM ": pthread_mutex_t mismatch\n"); + exit (1); + } + + if (sizeof (dummyobj) != sizeof (_gpgrt_lock_t)) + { + fprintf (stderr, PGM ": internal and external lock object mismatch\n"); + exit (1); + } + + /* To force a probably suitable alignment of the structure we use a + union and include a long and a pointer to a long. */ + printf ("## lock-obj-pub.%s.h\n" + "## File created by " PGM " - DO NOT EDIT\n" + "## To be included by mkheader into gpg-error.h\n" + "\n" + "typedef struct\n" + "{\n" + " long _vers;\n" + " union {\n" + " volatile char _priv[%d];\n" + "%s" + " long _x_align;\n" + " long *_xp_align;\n" + " } u;\n" + "} gpgrt_lock_t;\n" + "\n" + "#define GPGRT_LOCK_INITIALIZER {%d,{{", + HOST_TRIPLET_STRING, + SIZEOF_PTHREAD_MUTEX_T, +#if USE_16BYTE_ALIGNMENT + " int _x16_align __attribute__ ((aligned (16)));\n", +#else + "", +#endif + LOCK_ABI_VERSION); + p = (unsigned char *)&mtx; + for (i=0; i < sizeof mtx; i++) + { + if (i && !(i % 8)) + printf (" \\\n%*s", 36, ""); + printf ("%u", p[i]); + if (i < sizeof mtx - 1) + putchar (','); + } + fputs ("}}}\n" + "##\n" + "## Loc" "al Variables:\n" + "## mode: c\n" + "## buffer-read-only: t\n" + "## End:\n" + "##\n", stdout); + + if (ferror (stdout)) + { + fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno)); + return 1; + } + + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/gen-w32-lock-obj.c b/plugins/MirOTR/Libgpg-error/gen-w32-lock-obj.c new file mode 100644 index 0000000000..9e49d1e1df --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/gen-w32-lock-obj.c @@ -0,0 +1,55 @@ +/* gen-w32-lock-obj.c - Build tool to get the size of the lock object. + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef HAVE_W32_SYSTEM +# error This module may only be build for Windows. +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <windows.h> + +#include "w32-lock-obj.h" + + +int +main (void) +{ + _gpgrt_lock_t lk; + unsigned char *p; + int i; + + printf ("sizeof CRITICAL_SECTION = %u\n", (int)sizeof (CRITICAL_SECTION)); + printf ("sizeof _gpgrt_lock_t = %u\n", (int)sizeof lk); + + memset (&lk, 0, sizeof lk); + lk.vers = LOCK_ABI_VERSION; + lk.started = -1; + printf ("#define GPGRT_LOCK_INITIALIZER {"); + p = (unsigned char *)&lk; + for (i=0; i < sizeof lk - 1; i++) + printf ("%u,", p[i]); + printf ("%u}\n", p[sizeof(lk)-1]); + + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/gpg-error-config b/plugins/MirOTR/Libgpg-error/gpg-error-config index d4f88b22f5..407a15e800 100644 --- a/plugins/MirOTR/Libgpg-error/gpg-error-config +++ b/plugins/MirOTR/Libgpg-error/gpg-error-config @@ -17,12 +17,14 @@ libdir=${exec_prefix}/lib isubdirafter="" output="" +mt=no usage() { cat <<EOF Usage: gpg-error-config [OPTIONS] Options: + [--mt] (must be the first option) [--prefix] [--exec-prefix] [--version] @@ -47,6 +49,9 @@ while test $# -gt 0; do esac case $1 in + --mt) + mt=yes + ;; --prefix) output="$output $prefix" ;; @@ -54,7 +59,7 @@ while test $# -gt 0; do output="$output $exec_prefix" ;; --version) - echo "1.9" + echo "1.18" exit 0 ;; --cflags) @@ -67,13 +72,26 @@ while test $# -gt 0; do output="$output -idirafter ${includedir}/${i}" done output="$output " + if test $mt = yes ; then + output="$output " + fi ;; --libs) - if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/lib"; then - output="$output -L$libdir" - fi + case "$libdir" in + /usr/lib|/usr/lib64|/lib|/lib64) ;; + *) + output="$output -L$libdir" + ;; + esac output="$output -lgpg-error" + if test $mt = yes ; then + output="$output " + fi ;; + --host) + echo "x86_64-pc-mingw32" + exit 0 + ;; *) usage 1 1>&2 ;; diff --git a/plugins/MirOTR/Libgpg-error/gpg-error-config.in b/plugins/MirOTR/Libgpg-error/gpg-error-config.in deleted file mode 100644 index 4be034328a..0000000000 --- a/plugins/MirOTR/Libgpg-error/gpg-error-config.in +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh -# Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. -# -# This file is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -includedir=@includedir@ -libdir=@libdir@ -isubdirafter="@GPG_ERROR_CONFIG_ISUBDIRAFTER@" - -output="" - -usage() -{ - cat <<EOF -Usage: gpg-error-config [OPTIONS] -Options: - [--prefix] - [--exec-prefix] - [--version] - [--libs] - [--cflags] -EOF - exit $1 -} - -if test $# -eq 0; then - usage 1 1>&2 -fi - -while test $# -gt 0; do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - ;; - *) - optarg= - ;; - esac - - case $1 in - --prefix) - output="$output $prefix" - ;; - --exec-prefix) - output="$output $exec_prefix" - ;; - --version) - echo "@VERSION@" - exit 0 - ;; - --cflags) - if test "x$includedir" != "x/usr/include" -a "x$includedir" != "x/include"; then - output="$output -I$includedir" - fi - # Note: -idirafter is a gcc extension. It is only used on - # systems where gcc is the only compiler we support. - for i in $isubdirafter; do - output="$output -idirafter ${includedir}/${i}" - done - output="$output @GPG_ERROR_CONFIG_CFLAGS@" - ;; - --libs) - if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/lib"; then - output="$output -L$libdir" - fi - output="$output @GPG_ERROR_CONFIG_LIBS@" - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - -echo $output diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.c b/plugins/MirOTR/Libgpg-error/gpg-error.c index 9cddb3d463..034a61b6e0 100644 --- a/plugins/MirOTR/Libgpg-error/gpg-error.c +++ b/plugins/MirOTR/Libgpg-error/gpg-error.c @@ -7,12 +7,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -30,7 +30,7 @@ #include <stdio.h> #ifdef HAVE_LOCALE_H -# include <locale.h> +# include <locale.h> #endif #ifdef ENABLE_NLS #ifdef HAVE_W32_SYSTEM @@ -66,7 +66,16 @@ i18n_init (void) { #ifdef ENABLE_NLS char *locale_dir; - + +#ifdef HAVE_LC_MESSAGES + setlocale (LC_TIME, ""); + setlocale (LC_MESSAGES, ""); +#else +# ifndef HAVE_W32_SYSTEM + setlocale (LC_ALL, "" ); +# endif +#endif + /* Note that for this program we would only need the textdomain call because libgpg-error already initializes itself to its locale dir (via gpg_err_init or a constructor). However this is only done @@ -106,7 +115,7 @@ get_locale_dir (void) nbytes = WideCharToMultiByte (CP_UTF8, 0, moddir, -1, NULL, 0, NULL, NULL); if (nbytes < 0) return NULL; - + result = malloc (nbytes + strlen (SLDIR) + 1); if (result) { @@ -122,6 +131,12 @@ get_locale_dir (void) p = strrchr (result, '\\'); if (p) *p = 0; + /* If we are installed below "bin" strip that part and + use the top directory instead. */ + p = strrchr (result, '\\'); + if (p && !strcmp (p+1, "bin")) + *p = 0; + /* Append the static part. */ strcat (result, SLDIR); } } @@ -134,8 +149,8 @@ get_locale_dir (void) strcpy (result, "c:\\gnupg"); strcat (result, SLDIR); } - } -#undef SLDIR + } +#undef SLDIR return result; } @@ -299,7 +314,7 @@ get_err_from_str_one (char *str, gpg_error_t *err, { if (*have_code) return 0; - + *have_code = 1; *err |= code; return 1; @@ -318,7 +333,7 @@ get_err_from_str (char *str, gpg_error_t *err) int have_code = 0; int ret; char *saved_pos = NULL; - char saved_char; + char saved_char = 0; /* (avoid warning) */ *err = 0; ret = get_err_from_str_one (str, err, &have_source, &have_code); @@ -365,22 +380,18 @@ main (int argc, char *argv[]) const char *error_sym; gpg_error_t err; -#ifndef GPG_ERR_INITIALIZED - gpg_err_init (); -#endif - + gpgrt_init (); i18n_init (); - if (argc == 1) { - fprintf (stderr, _("Usage: %s GPG-ERROR [...]\n"), + fprintf (stderr, _("Usage: %s GPG-ERROR [...]\n"), strrchr (argv[0],'/')? (strrchr (argv[0], '/')+1): argv[0]); exit (1); } else if (argc == 2 && !strcmp (argv[1], "--version")) { - fputs ( ("gpg-error ("PACKAGE_NAME") "PACKAGE_VERSION"\n") , stdout); + fputs ("gpg-error (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stdout); exit (0); } else if (argc == 2 && !strcmp (argv[1], "--list")) @@ -423,7 +434,7 @@ main (int argc, char *argv[]) { source_sym = gpg_strsource_sym (err); error_sym = gpg_strerror_sym (err); - + printf ("%u = (%u, %u) = (%s, %s) = (%s, %s)\n", err, gpg_err_source (err), gpg_err_code (err), source_sym ? source_sym : "-", error_sym ? error_sym : "-", diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.def b/plugins/MirOTR/Libgpg-error/gpg-error.def index 0e8c946ee6..290bc27877 100644 --- a/plugins/MirOTR/Libgpg-error/gpg-error.def +++ b/plugins/MirOTR/Libgpg-error/gpg-error.def @@ -1,15 +1,11 @@ - - - - EXPORTS gpg_strerror @1 gpg_strerror_r @2 gpg_strsource @3 gpg_err_code_from_errno @4 gpg_err_code_to_errno @5 - gpg_err_init @6 + gpg_err_code_from_syserror @7 gpg_err_set_errno @8 @@ -25,4 +21,98 @@ EXPORTS _gpg_w32_gettext_localename @16 _gpg_w32_gettext_use_utf8 @17 - gpg_err_deinit @18 + + gpg_error_check_version @19 + + gpgrt_lock_init @20 + gpgrt_lock_lock @21 + gpgrt_lock_unlock @22 + gpgrt_lock_destroy @23 + gpgrt_yield @24 + gpgrt_lock_trylock @25 + + gpgrt_set_syscall_clamp @26 + + gpgrt_fopen @27 + gpgrt_mopen @28 + gpgrt_fopenmem @29 + gpgrt_fopenmem_init @30 + gpgrt_fdopen @31 + gpgrt_fdopen_nc @32 + gpgrt_sysopen @33 + gpgrt_sysopen_nc @34 + gpgrt_fpopen @35 + gpgrt_fpopen_nc @36 + gpgrt_freopen @37 + gpgrt_fopencookie @38 + gpgrt_fclose @39 + gpgrt_fclose_snatch @40 + gpgrt_onclose @41 + gpgrt_fileno @42 + gpgrt_fileno_unlocked @43 + gpgrt_syshd @44 + gpgrt_syshd_unlocked @45 + _gpgrt_set_std_fd @46 + _gpgrt_get_std_stream @47 + gpgrt_flockfile @48 + gpgrt_ftrylockfile @49 + gpgrt_funlockfile @50 + gpgrt_feof @51 + gpgrt_feof_unlocked @52 + gpgrt_ferror @53 + gpgrt_ferror_unlocked @54 + gpgrt_clearerr @55 + gpgrt_clearerr_unlocked @56 + gpgrt_fflush @57 + gpgrt_fseek @58 + gpgrt_fseeko @59 + gpgrt_ftell @60 + gpgrt_ftello @61 + gpgrt_rewind @62 + gpgrt_fgetc @63 + _gpgrt_getc_underflow @64 + gpgrt_fputc @65 + _gpgrt_putc_overflow @66 + gpgrt_ungetc @67 + gpgrt_read @68 + gpgrt_write @69 + gpgrt_write_sanitized @70 + gpgrt_write_hexstring @71 + gpgrt_fread @72 + gpgrt_fwrite @73 + gpgrt_fgets @74 + gpgrt_fputs @75 + gpgrt_fputs_unlocked @76 + gpgrt_getline @77 + gpgrt_read_line @78 + gpgrt_free @79 + gpgrt_fprintf @80 + gpgrt_fprintf_unlocked @81 + gpgrt_printf @82 + gpgrt_printf_unlocked @83 + gpgrt_vfprintf @84 + gpgrt_vfprintf_unlocked @85 + gpgrt_setvbuf @86 + gpgrt_setbuf @87 + gpgrt_set_binary @88 + gpgrt_tmpfile @89 + gpgrt_opaque_set @90 + gpgrt_opaque_get @91 + gpgrt_fname_set @92 + gpgrt_fname_get @93 + gpgrt_asprintf @94 + gpgrt_vasprintf @95 + gpgrt_bsprintf @96 + gpgrt_vbsprintf @97 + gpgrt_snprintf @98 + gpgrt_vsnprintf @99 + + gpgrt_check_version @100 + gpg_err_init @101 + gpg_err_deinit @102 + gpgrt_set_alloc_func @103 + + _gpgrt_pending @104 + _gpgrt_pending_unlocked @105 + +;; end of file with public symbols for Windows. diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.def.in b/plugins/MirOTR/Libgpg-error/gpg-error.def.in deleted file mode 100644 index cbabd57053..0000000000 --- a/plugins/MirOTR/Libgpg-error/gpg-error.def.in +++ /dev/null @@ -1,29 +0,0 @@ -/* gpg-error.def.in - Exported symbols - * Needs to be processed by CPP. - */ - -#include <config.h> - -EXPORTS - gpg_strerror @1 - gpg_strerror_r @2 - gpg_strsource @3 - gpg_err_code_from_errno @4 - gpg_err_code_to_errno @5 - gpg_err_init @6 - gpg_err_code_from_syserror @7 - gpg_err_set_errno @8 -#ifdef HAVE_W32CE_SYSTEM - _gpg_w32ce_get_errno @9 - _gpg_w32ce_strerror @10 -#endif -#ifdef HAVE_W32_SYSTEM - _gpg_w32_bindtextdomain @11 - _gpg_w32_textdomain @12 - _gpg_w32_gettext @13 - _gpg_w32_dgettext @14 - _gpg_w32_dngettext @15 - _gpg_w32_gettext_localename @16 - _gpg_w32_gettext_use_utf8 @17 -#endif - gpg_err_deinit @18 diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.exe b/plugins/MirOTR/Libgpg-error/gpg-error.exe Binary files differdeleted file mode 100644 index 63968b7840..0000000000 --- a/plugins/MirOTR/Libgpg-error/gpg-error.exe +++ /dev/null diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.h b/plugins/MirOTR/Libgpg-error/gpg-error.h index c9e0346b4e..c94d4f99dc 100644 --- a/plugins/MirOTR/Libgpg-error/gpg-error.h +++ b/plugins/MirOTR/Libgpg-error/gpg-error.h @@ -1,710 +1,1237 @@ -/* Output of mkheader.awk. DO NOT EDIT. -*- buffer-read-only: t -*- */ - -/* gpg-error.h - Public interface to libgpg-error. - Copyright (C) 2003, 2004, 2010 g10 Code GmbH - - This file is part of libgpg-error. - - libgpg-error 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. - - libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef GPG_ERROR_H -#define GPG_ERROR_H 1 - -#include <stddef.h> - -#ifdef __GNUC__ -#define GPG_ERR_INLINE __inline__ -#elif __STDC_VERSION__ >= 199901L -#define GPG_ERR_INLINE inline -#else -#ifndef GPG_ERR_INLINE -#define GPG_ERR_INLINE -#endif -#endif - - -#ifdef __cplusplus -extern "C" { -#if 0 /* just to make Emacs auto-indent happy */ -} -#endif -#endif /* __cplusplus */ - -/* The GnuPG project consists of many components. Error codes are - exchanged between all components. The common error codes and their - user-presentable descriptions are kept into a shared library to - allow adding new error codes and components without recompiling any - of the other components. The interface will not change in a - backward incompatible way. - - An error code together with an error source build up an error - value. As the error value is been passed from one component to - another, it preserver the information about the source and nature - of the error. - - A component of the GnuPG project can define the following macros to - tune the behaviour of the library: - - GPG_ERR_SOURCE_DEFAULT: Define to an error source of type - gpg_err_source_t to make that source the default for gpg_error(). - Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. - - GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the - internal gettext API to standard names. This has only an effect on - Windows platforms. */ - - -/* The error source type gpg_err_source_t. - - Where as the Poo out of a welle small - Taketh his firste springing and his sours. - --Chaucer. */ - -/* Only use free slots, never change or reorder the existing - entries. */ -typedef enum - { - GPG_ERR_SOURCE_UNKNOWN = 0, - GPG_ERR_SOURCE_GCRYPT = 1, - GPG_ERR_SOURCE_GPG = 2, - GPG_ERR_SOURCE_GPGSM = 3, - GPG_ERR_SOURCE_GPGAGENT = 4, - GPG_ERR_SOURCE_PINENTRY = 5, - GPG_ERR_SOURCE_SCD = 6, - GPG_ERR_SOURCE_GPGME = 7, - GPG_ERR_SOURCE_KEYBOX = 8, - GPG_ERR_SOURCE_KSBA = 9, - GPG_ERR_SOURCE_DIRMNGR = 10, - GPG_ERR_SOURCE_GSTI = 11, - GPG_ERR_SOURCE_GPA = 12, - GPG_ERR_SOURCE_KLEO = 13, - GPG_ERR_SOURCE_G13 = 14, - GPG_ERR_SOURCE_ANY = 31, - GPG_ERR_SOURCE_USER_1 = 32, - GPG_ERR_SOURCE_USER_2 = 33, - GPG_ERR_SOURCE_USER_3 = 34, - GPG_ERR_SOURCE_USER_4 = 35, - - /* This is one more than the largest allowed entry. */ - GPG_ERR_SOURCE_DIM = 128 - } gpg_err_source_t; - - -/* The error code type gpg_err_code_t. */ - -/* Only use free slots, never change or reorder the existing - entries. */ -typedef enum - { - GPG_ERR_NO_ERROR = 0, - GPG_ERR_GENERAL = 1, - GPG_ERR_UNKNOWN_PACKET = 2, - GPG_ERR_UNKNOWN_VERSION = 3, - GPG_ERR_PUBKEY_ALGO = 4, - GPG_ERR_DIGEST_ALGO = 5, - GPG_ERR_BAD_PUBKEY = 6, - GPG_ERR_BAD_SECKEY = 7, - GPG_ERR_BAD_SIGNATURE = 8, - GPG_ERR_NO_PUBKEY = 9, - GPG_ERR_CHECKSUM = 10, - GPG_ERR_BAD_PASSPHRASE = 11, - GPG_ERR_CIPHER_ALGO = 12, - GPG_ERR_KEYRING_OPEN = 13, - GPG_ERR_INV_PACKET = 14, - GPG_ERR_INV_ARMOR = 15, - GPG_ERR_NO_USER_ID = 16, - GPG_ERR_NO_SECKEY = 17, - GPG_ERR_WRONG_SECKEY = 18, - GPG_ERR_BAD_KEY = 19, - GPG_ERR_COMPR_ALGO = 20, - GPG_ERR_NO_PRIME = 21, - GPG_ERR_NO_ENCODING_METHOD = 22, - GPG_ERR_NO_ENCRYPTION_SCHEME = 23, - GPG_ERR_NO_SIGNATURE_SCHEME = 24, - GPG_ERR_INV_ATTR = 25, - GPG_ERR_NO_VALUE = 26, - GPG_ERR_NOT_FOUND = 27, - GPG_ERR_VALUE_NOT_FOUND = 28, - GPG_ERR_SYNTAX = 29, - GPG_ERR_BAD_MPI = 30, - GPG_ERR_INV_PASSPHRASE = 31, - GPG_ERR_SIG_CLASS = 32, - GPG_ERR_RESOURCE_LIMIT = 33, - GPG_ERR_INV_KEYRING = 34, - GPG_ERR_TRUSTDB = 35, - GPG_ERR_BAD_CERT = 36, - GPG_ERR_INV_USER_ID = 37, - GPG_ERR_UNEXPECTED = 38, - GPG_ERR_TIME_CONFLICT = 39, - GPG_ERR_KEYSERVER = 40, - GPG_ERR_WRONG_PUBKEY_ALGO = 41, - GPG_ERR_TRIBUTE_TO_D_A = 42, - GPG_ERR_WEAK_KEY = 43, - GPG_ERR_INV_KEYLEN = 44, - GPG_ERR_INV_ARG = 45, - GPG_ERR_BAD_URI = 46, - GPG_ERR_INV_URI = 47, - GPG_ERR_NETWORK = 48, - GPG_ERR_UNKNOWN_HOST = 49, - GPG_ERR_SELFTEST_FAILED = 50, - GPG_ERR_NOT_ENCRYPTED = 51, - GPG_ERR_NOT_PROCESSED = 52, - GPG_ERR_UNUSABLE_PUBKEY = 53, - GPG_ERR_UNUSABLE_SECKEY = 54, - GPG_ERR_INV_VALUE = 55, - GPG_ERR_BAD_CERT_CHAIN = 56, - GPG_ERR_MISSING_CERT = 57, - GPG_ERR_NO_DATA = 58, - GPG_ERR_BUG = 59, - GPG_ERR_NOT_SUPPORTED = 60, - GPG_ERR_INV_OP = 61, - GPG_ERR_TIMEOUT = 62, - GPG_ERR_INTERNAL = 63, - GPG_ERR_EOF_GCRYPT = 64, - GPG_ERR_INV_OBJ = 65, - GPG_ERR_TOO_SHORT = 66, - GPG_ERR_TOO_LARGE = 67, - GPG_ERR_NO_OBJ = 68, - GPG_ERR_NOT_IMPLEMENTED = 69, - GPG_ERR_CONFLICT = 70, - GPG_ERR_INV_CIPHER_MODE = 71, - GPG_ERR_INV_FLAG = 72, - GPG_ERR_INV_HANDLE = 73, - GPG_ERR_TRUNCATED = 74, - GPG_ERR_INCOMPLETE_LINE = 75, - GPG_ERR_INV_RESPONSE = 76, - GPG_ERR_NO_AGENT = 77, - GPG_ERR_AGENT = 78, - GPG_ERR_INV_DATA = 79, - GPG_ERR_ASSUAN_SERVER_FAULT = 80, - GPG_ERR_ASSUAN = 81, - GPG_ERR_INV_SESSION_KEY = 82, - GPG_ERR_INV_SEXP = 83, - GPG_ERR_UNSUPPORTED_ALGORITHM = 84, - GPG_ERR_NO_PIN_ENTRY = 85, - GPG_ERR_PIN_ENTRY = 86, - GPG_ERR_BAD_PIN = 87, - GPG_ERR_INV_NAME = 88, - GPG_ERR_BAD_DATA = 89, - GPG_ERR_INV_PARAMETER = 90, - GPG_ERR_WRONG_CARD = 91, - GPG_ERR_NO_DIRMNGR = 92, - GPG_ERR_DIRMNGR = 93, - GPG_ERR_CERT_REVOKED = 94, - GPG_ERR_NO_CRL_KNOWN = 95, - GPG_ERR_CRL_TOO_OLD = 96, - GPG_ERR_LINE_TOO_LONG = 97, - GPG_ERR_NOT_TRUSTED = 98, - GPG_ERR_CANCELED = 99, - GPG_ERR_BAD_CA_CERT = 100, - GPG_ERR_CERT_EXPIRED = 101, - GPG_ERR_CERT_TOO_YOUNG = 102, - GPG_ERR_UNSUPPORTED_CERT = 103, - GPG_ERR_UNKNOWN_SEXP = 104, - GPG_ERR_UNSUPPORTED_PROTECTION = 105, - GPG_ERR_CORRUPTED_PROTECTION = 106, - GPG_ERR_AMBIGUOUS_NAME = 107, - GPG_ERR_CARD = 108, - GPG_ERR_CARD_RESET = 109, - GPG_ERR_CARD_REMOVED = 110, - GPG_ERR_INV_CARD = 111, - GPG_ERR_CARD_NOT_PRESENT = 112, - GPG_ERR_NO_PKCS15_APP = 113, - GPG_ERR_NOT_CONFIRMED = 114, - GPG_ERR_CONFIGURATION = 115, - GPG_ERR_NO_POLICY_MATCH = 116, - GPG_ERR_INV_INDEX = 117, - GPG_ERR_INV_ID = 118, - GPG_ERR_NO_SCDAEMON = 119, - GPG_ERR_SCDAEMON = 120, - GPG_ERR_UNSUPPORTED_PROTOCOL = 121, - GPG_ERR_BAD_PIN_METHOD = 122, - GPG_ERR_CARD_NOT_INITIALIZED = 123, - GPG_ERR_UNSUPPORTED_OPERATION = 124, - GPG_ERR_WRONG_KEY_USAGE = 125, - GPG_ERR_NOTHING_FOUND = 126, - GPG_ERR_WRONG_BLOB_TYPE = 127, - GPG_ERR_MISSING_VALUE = 128, - GPG_ERR_HARDWARE = 129, - GPG_ERR_PIN_BLOCKED = 130, - GPG_ERR_USE_CONDITIONS = 131, - GPG_ERR_PIN_NOT_SYNCED = 132, - GPG_ERR_INV_CRL = 133, - GPG_ERR_BAD_BER = 134, - GPG_ERR_INV_BER = 135, - GPG_ERR_ELEMENT_NOT_FOUND = 136, - GPG_ERR_IDENTIFIER_NOT_FOUND = 137, - GPG_ERR_INV_TAG = 138, - GPG_ERR_INV_LENGTH = 139, - GPG_ERR_INV_KEYINFO = 140, - GPG_ERR_UNEXPECTED_TAG = 141, - GPG_ERR_NOT_DER_ENCODED = 142, - GPG_ERR_NO_CMS_OBJ = 143, - GPG_ERR_INV_CMS_OBJ = 144, - GPG_ERR_UNKNOWN_CMS_OBJ = 145, - GPG_ERR_UNSUPPORTED_CMS_OBJ = 146, - GPG_ERR_UNSUPPORTED_ENCODING = 147, - GPG_ERR_UNSUPPORTED_CMS_VERSION = 148, - GPG_ERR_UNKNOWN_ALGORITHM = 149, - GPG_ERR_INV_ENGINE = 150, - GPG_ERR_PUBKEY_NOT_TRUSTED = 151, - GPG_ERR_DECRYPT_FAILED = 152, - GPG_ERR_KEY_EXPIRED = 153, - GPG_ERR_SIG_EXPIRED = 154, - GPG_ERR_ENCODING_PROBLEM = 155, - GPG_ERR_INV_STATE = 156, - GPG_ERR_DUP_VALUE = 157, - GPG_ERR_MISSING_ACTION = 158, - GPG_ERR_MODULE_NOT_FOUND = 159, - GPG_ERR_INV_OID_STRING = 160, - GPG_ERR_INV_TIME = 161, - GPG_ERR_INV_CRL_OBJ = 162, - GPG_ERR_UNSUPPORTED_CRL_VERSION = 163, - GPG_ERR_INV_CERT_OBJ = 164, - GPG_ERR_UNKNOWN_NAME = 165, - GPG_ERR_LOCALE_PROBLEM = 166, - GPG_ERR_NOT_LOCKED = 167, - GPG_ERR_PROTOCOL_VIOLATION = 168, - GPG_ERR_INV_MAC = 169, - GPG_ERR_INV_REQUEST = 170, - GPG_ERR_UNKNOWN_EXTN = 171, - GPG_ERR_UNKNOWN_CRIT_EXTN = 172, - GPG_ERR_LOCKED = 173, - GPG_ERR_UNKNOWN_OPTION = 174, - GPG_ERR_UNKNOWN_COMMAND = 175, - GPG_ERR_NOT_OPERATIONAL = 176, - GPG_ERR_NO_PASSPHRASE = 177, - GPG_ERR_NO_PIN = 178, - GPG_ERR_NOT_ENABLED = 179, - GPG_ERR_NO_ENGINE = 180, - GPG_ERR_MISSING_KEY = 181, - GPG_ERR_TOO_MANY = 182, - GPG_ERR_LIMIT_REACHED = 183, - GPG_ERR_UNFINISHED = 199, - GPG_ERR_BUFFER_TOO_SHORT = 200, - GPG_ERR_SEXP_INV_LEN_SPEC = 201, - GPG_ERR_SEXP_STRING_TOO_LONG = 202, - GPG_ERR_SEXP_UNMATCHED_PAREN = 203, - GPG_ERR_SEXP_NOT_CANONICAL = 204, - GPG_ERR_SEXP_BAD_CHARACTER = 205, - GPG_ERR_SEXP_BAD_QUOTATION = 206, - GPG_ERR_SEXP_ZERO_PREFIX = 207, - GPG_ERR_SEXP_NESTED_DH = 208, - GPG_ERR_SEXP_UNMATCHED_DH = 209, - GPG_ERR_SEXP_UNEXPECTED_PUNC = 210, - GPG_ERR_SEXP_BAD_HEX_CHAR = 211, - GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212, - GPG_ERR_SEXP_BAD_OCT_CHAR = 213, - GPG_ERR_ASS_GENERAL = 257, - GPG_ERR_ASS_ACCEPT_FAILED = 258, - GPG_ERR_ASS_CONNECT_FAILED = 259, - GPG_ERR_ASS_INV_RESPONSE = 260, - GPG_ERR_ASS_INV_VALUE = 261, - GPG_ERR_ASS_INCOMPLETE_LINE = 262, - GPG_ERR_ASS_LINE_TOO_LONG = 263, - GPG_ERR_ASS_NESTED_COMMANDS = 264, - GPG_ERR_ASS_NO_DATA_CB = 265, - GPG_ERR_ASS_NO_INQUIRE_CB = 266, - GPG_ERR_ASS_NOT_A_SERVER = 267, - GPG_ERR_ASS_NOT_A_CLIENT = 268, - GPG_ERR_ASS_SERVER_START = 269, - GPG_ERR_ASS_READ_ERROR = 270, - GPG_ERR_ASS_WRITE_ERROR = 271, - GPG_ERR_ASS_TOO_MUCH_DATA = 273, - GPG_ERR_ASS_UNEXPECTED_CMD = 274, - GPG_ERR_ASS_UNKNOWN_CMD = 275, - GPG_ERR_ASS_SYNTAX = 276, - GPG_ERR_ASS_CANCELED = 277, - GPG_ERR_ASS_NO_INPUT = 278, - GPG_ERR_ASS_NO_OUTPUT = 279, - GPG_ERR_ASS_PARAMETER = 280, - GPG_ERR_ASS_UNKNOWN_INQUIRE = 281, - GPG_ERR_USER_1 = 1024, - GPG_ERR_USER_2 = 1025, - GPG_ERR_USER_3 = 1026, - GPG_ERR_USER_4 = 1027, - GPG_ERR_USER_5 = 1028, - GPG_ERR_USER_6 = 1029, - GPG_ERR_USER_7 = 1030, - GPG_ERR_USER_8 = 1031, - GPG_ERR_USER_9 = 1032, - GPG_ERR_USER_10 = 1033, - GPG_ERR_USER_11 = 1034, - GPG_ERR_USER_12 = 1035, - GPG_ERR_USER_13 = 1036, - GPG_ERR_USER_14 = 1037, - GPG_ERR_USER_15 = 1038, - GPG_ERR_USER_16 = 1039, - GPG_ERR_MISSING_ERRNO = 16381, - GPG_ERR_UNKNOWN_ERRNO = 16382, - GPG_ERR_EOF = 16383, - - /* The following error codes are used to map system errors. */ -#define GPG_ERR_SYSTEM_ERROR (1 << 15) - GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0, - GPG_ERR_EACCES = GPG_ERR_SYSTEM_ERROR | 1, - GPG_ERR_EADDRINUSE = GPG_ERR_SYSTEM_ERROR | 2, - GPG_ERR_EADDRNOTAVAIL = GPG_ERR_SYSTEM_ERROR | 3, - GPG_ERR_EADV = GPG_ERR_SYSTEM_ERROR | 4, - GPG_ERR_EAFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 5, - GPG_ERR_EAGAIN = GPG_ERR_SYSTEM_ERROR | 6, - GPG_ERR_EALREADY = GPG_ERR_SYSTEM_ERROR | 7, - GPG_ERR_EAUTH = GPG_ERR_SYSTEM_ERROR | 8, - GPG_ERR_EBACKGROUND = GPG_ERR_SYSTEM_ERROR | 9, - GPG_ERR_EBADE = GPG_ERR_SYSTEM_ERROR | 10, - GPG_ERR_EBADF = GPG_ERR_SYSTEM_ERROR | 11, - GPG_ERR_EBADFD = GPG_ERR_SYSTEM_ERROR | 12, - GPG_ERR_EBADMSG = GPG_ERR_SYSTEM_ERROR | 13, - GPG_ERR_EBADR = GPG_ERR_SYSTEM_ERROR | 14, - GPG_ERR_EBADRPC = GPG_ERR_SYSTEM_ERROR | 15, - GPG_ERR_EBADRQC = GPG_ERR_SYSTEM_ERROR | 16, - GPG_ERR_EBADSLT = GPG_ERR_SYSTEM_ERROR | 17, - GPG_ERR_EBFONT = GPG_ERR_SYSTEM_ERROR | 18, - GPG_ERR_EBUSY = GPG_ERR_SYSTEM_ERROR | 19, - GPG_ERR_ECANCELED = GPG_ERR_SYSTEM_ERROR | 20, - GPG_ERR_ECHILD = GPG_ERR_SYSTEM_ERROR | 21, - GPG_ERR_ECHRNG = GPG_ERR_SYSTEM_ERROR | 22, - GPG_ERR_ECOMM = GPG_ERR_SYSTEM_ERROR | 23, - GPG_ERR_ECONNABORTED = GPG_ERR_SYSTEM_ERROR | 24, - GPG_ERR_ECONNREFUSED = GPG_ERR_SYSTEM_ERROR | 25, - GPG_ERR_ECONNRESET = GPG_ERR_SYSTEM_ERROR | 26, - GPG_ERR_ED = GPG_ERR_SYSTEM_ERROR | 27, - GPG_ERR_EDEADLK = GPG_ERR_SYSTEM_ERROR | 28, - GPG_ERR_EDEADLOCK = GPG_ERR_SYSTEM_ERROR | 29, - GPG_ERR_EDESTADDRREQ = GPG_ERR_SYSTEM_ERROR | 30, - GPG_ERR_EDIED = GPG_ERR_SYSTEM_ERROR | 31, - GPG_ERR_EDOM = GPG_ERR_SYSTEM_ERROR | 32, - GPG_ERR_EDOTDOT = GPG_ERR_SYSTEM_ERROR | 33, - GPG_ERR_EDQUOT = GPG_ERR_SYSTEM_ERROR | 34, - GPG_ERR_EEXIST = GPG_ERR_SYSTEM_ERROR | 35, - GPG_ERR_EFAULT = GPG_ERR_SYSTEM_ERROR | 36, - GPG_ERR_EFBIG = GPG_ERR_SYSTEM_ERROR | 37, - GPG_ERR_EFTYPE = GPG_ERR_SYSTEM_ERROR | 38, - GPG_ERR_EGRATUITOUS = GPG_ERR_SYSTEM_ERROR | 39, - GPG_ERR_EGREGIOUS = GPG_ERR_SYSTEM_ERROR | 40, - GPG_ERR_EHOSTDOWN = GPG_ERR_SYSTEM_ERROR | 41, - GPG_ERR_EHOSTUNREACH = GPG_ERR_SYSTEM_ERROR | 42, - GPG_ERR_EIDRM = GPG_ERR_SYSTEM_ERROR | 43, - GPG_ERR_EIEIO = GPG_ERR_SYSTEM_ERROR | 44, - GPG_ERR_EILSEQ = GPG_ERR_SYSTEM_ERROR | 45, - GPG_ERR_EINPROGRESS = GPG_ERR_SYSTEM_ERROR | 46, - GPG_ERR_EINTR = GPG_ERR_SYSTEM_ERROR | 47, - GPG_ERR_EINVAL = GPG_ERR_SYSTEM_ERROR | 48, - GPG_ERR_EIO = GPG_ERR_SYSTEM_ERROR | 49, - GPG_ERR_EISCONN = GPG_ERR_SYSTEM_ERROR | 50, - GPG_ERR_EISDIR = GPG_ERR_SYSTEM_ERROR | 51, - GPG_ERR_EISNAM = GPG_ERR_SYSTEM_ERROR | 52, - GPG_ERR_EL2HLT = GPG_ERR_SYSTEM_ERROR | 53, - GPG_ERR_EL2NSYNC = GPG_ERR_SYSTEM_ERROR | 54, - GPG_ERR_EL3HLT = GPG_ERR_SYSTEM_ERROR | 55, - GPG_ERR_EL3RST = GPG_ERR_SYSTEM_ERROR | 56, - GPG_ERR_ELIBACC = GPG_ERR_SYSTEM_ERROR | 57, - GPG_ERR_ELIBBAD = GPG_ERR_SYSTEM_ERROR | 58, - GPG_ERR_ELIBEXEC = GPG_ERR_SYSTEM_ERROR | 59, - GPG_ERR_ELIBMAX = GPG_ERR_SYSTEM_ERROR | 60, - GPG_ERR_ELIBSCN = GPG_ERR_SYSTEM_ERROR | 61, - GPG_ERR_ELNRNG = GPG_ERR_SYSTEM_ERROR | 62, - GPG_ERR_ELOOP = GPG_ERR_SYSTEM_ERROR | 63, - GPG_ERR_EMEDIUMTYPE = GPG_ERR_SYSTEM_ERROR | 64, - GPG_ERR_EMFILE = GPG_ERR_SYSTEM_ERROR | 65, - GPG_ERR_EMLINK = GPG_ERR_SYSTEM_ERROR | 66, - GPG_ERR_EMSGSIZE = GPG_ERR_SYSTEM_ERROR | 67, - GPG_ERR_EMULTIHOP = GPG_ERR_SYSTEM_ERROR | 68, - GPG_ERR_ENAMETOOLONG = GPG_ERR_SYSTEM_ERROR | 69, - GPG_ERR_ENAVAIL = GPG_ERR_SYSTEM_ERROR | 70, - GPG_ERR_ENEEDAUTH = GPG_ERR_SYSTEM_ERROR | 71, - GPG_ERR_ENETDOWN = GPG_ERR_SYSTEM_ERROR | 72, - GPG_ERR_ENETRESET = GPG_ERR_SYSTEM_ERROR | 73, - GPG_ERR_ENETUNREACH = GPG_ERR_SYSTEM_ERROR | 74, - GPG_ERR_ENFILE = GPG_ERR_SYSTEM_ERROR | 75, - GPG_ERR_ENOANO = GPG_ERR_SYSTEM_ERROR | 76, - GPG_ERR_ENOBUFS = GPG_ERR_SYSTEM_ERROR | 77, - GPG_ERR_ENOCSI = GPG_ERR_SYSTEM_ERROR | 78, - GPG_ERR_ENODATA = GPG_ERR_SYSTEM_ERROR | 79, - GPG_ERR_ENODEV = GPG_ERR_SYSTEM_ERROR | 80, - GPG_ERR_ENOENT = GPG_ERR_SYSTEM_ERROR | 81, - GPG_ERR_ENOEXEC = GPG_ERR_SYSTEM_ERROR | 82, - GPG_ERR_ENOLCK = GPG_ERR_SYSTEM_ERROR | 83, - GPG_ERR_ENOLINK = GPG_ERR_SYSTEM_ERROR | 84, - GPG_ERR_ENOMEDIUM = GPG_ERR_SYSTEM_ERROR | 85, - GPG_ERR_ENOMEM = GPG_ERR_SYSTEM_ERROR | 86, - GPG_ERR_ENOMSG = GPG_ERR_SYSTEM_ERROR | 87, - GPG_ERR_ENONET = GPG_ERR_SYSTEM_ERROR | 88, - GPG_ERR_ENOPKG = GPG_ERR_SYSTEM_ERROR | 89, - GPG_ERR_ENOPROTOOPT = GPG_ERR_SYSTEM_ERROR | 90, - GPG_ERR_ENOSPC = GPG_ERR_SYSTEM_ERROR | 91, - GPG_ERR_ENOSR = GPG_ERR_SYSTEM_ERROR | 92, - GPG_ERR_ENOSTR = GPG_ERR_SYSTEM_ERROR | 93, - GPG_ERR_ENOSYS = GPG_ERR_SYSTEM_ERROR | 94, - GPG_ERR_ENOTBLK = GPG_ERR_SYSTEM_ERROR | 95, - GPG_ERR_ENOTCONN = GPG_ERR_SYSTEM_ERROR | 96, - GPG_ERR_ENOTDIR = GPG_ERR_SYSTEM_ERROR | 97, - GPG_ERR_ENOTEMPTY = GPG_ERR_SYSTEM_ERROR | 98, - GPG_ERR_ENOTNAM = GPG_ERR_SYSTEM_ERROR | 99, - GPG_ERR_ENOTSOCK = GPG_ERR_SYSTEM_ERROR | 100, - GPG_ERR_ENOTSUP = GPG_ERR_SYSTEM_ERROR | 101, - GPG_ERR_ENOTTY = GPG_ERR_SYSTEM_ERROR | 102, - GPG_ERR_ENOTUNIQ = GPG_ERR_SYSTEM_ERROR | 103, - GPG_ERR_ENXIO = GPG_ERR_SYSTEM_ERROR | 104, - GPG_ERR_EOPNOTSUPP = GPG_ERR_SYSTEM_ERROR | 105, - GPG_ERR_EOVERFLOW = GPG_ERR_SYSTEM_ERROR | 106, - GPG_ERR_EPERM = GPG_ERR_SYSTEM_ERROR | 107, - GPG_ERR_EPFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 108, - GPG_ERR_EPIPE = GPG_ERR_SYSTEM_ERROR | 109, - GPG_ERR_EPROCLIM = GPG_ERR_SYSTEM_ERROR | 110, - GPG_ERR_EPROCUNAVAIL = GPG_ERR_SYSTEM_ERROR | 111, - GPG_ERR_EPROGMISMATCH = GPG_ERR_SYSTEM_ERROR | 112, - GPG_ERR_EPROGUNAVAIL = GPG_ERR_SYSTEM_ERROR | 113, - GPG_ERR_EPROTO = GPG_ERR_SYSTEM_ERROR | 114, - GPG_ERR_EPROTONOSUPPORT = GPG_ERR_SYSTEM_ERROR | 115, - GPG_ERR_EPROTOTYPE = GPG_ERR_SYSTEM_ERROR | 116, - GPG_ERR_ERANGE = GPG_ERR_SYSTEM_ERROR | 117, - GPG_ERR_EREMCHG = GPG_ERR_SYSTEM_ERROR | 118, - GPG_ERR_EREMOTE = GPG_ERR_SYSTEM_ERROR | 119, - GPG_ERR_EREMOTEIO = GPG_ERR_SYSTEM_ERROR | 120, - GPG_ERR_ERESTART = GPG_ERR_SYSTEM_ERROR | 121, - GPG_ERR_EROFS = GPG_ERR_SYSTEM_ERROR | 122, - GPG_ERR_ERPCMISMATCH = GPG_ERR_SYSTEM_ERROR | 123, - GPG_ERR_ESHUTDOWN = GPG_ERR_SYSTEM_ERROR | 124, - GPG_ERR_ESOCKTNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 125, - GPG_ERR_ESPIPE = GPG_ERR_SYSTEM_ERROR | 126, - GPG_ERR_ESRCH = GPG_ERR_SYSTEM_ERROR | 127, - GPG_ERR_ESRMNT = GPG_ERR_SYSTEM_ERROR | 128, - GPG_ERR_ESTALE = GPG_ERR_SYSTEM_ERROR | 129, - GPG_ERR_ESTRPIPE = GPG_ERR_SYSTEM_ERROR | 130, - GPG_ERR_ETIME = GPG_ERR_SYSTEM_ERROR | 131, - GPG_ERR_ETIMEDOUT = GPG_ERR_SYSTEM_ERROR | 132, - GPG_ERR_ETOOMANYREFS = GPG_ERR_SYSTEM_ERROR | 133, - GPG_ERR_ETXTBSY = GPG_ERR_SYSTEM_ERROR | 134, - GPG_ERR_EUCLEAN = GPG_ERR_SYSTEM_ERROR | 135, - GPG_ERR_EUNATCH = GPG_ERR_SYSTEM_ERROR | 136, - GPG_ERR_EUSERS = GPG_ERR_SYSTEM_ERROR | 137, - GPG_ERR_EWOULDBLOCK = GPG_ERR_SYSTEM_ERROR | 138, - GPG_ERR_EXDEV = GPG_ERR_SYSTEM_ERROR | 139, - GPG_ERR_EXFULL = GPG_ERR_SYSTEM_ERROR | 140, - - /* This is one more than the largest allowed entry. */ - GPG_ERR_CODE_DIM = 65536 - } gpg_err_code_t; - - -/* The error value type gpg_error_t. */ - -/* We would really like to use bit-fields in a struct, but using - structs as return values can cause binary compatibility issues, in - particular if you want to do it effeciently (also see - -freg-struct-return option to GCC). */ -typedef unsigned int gpg_error_t; - -/* We use the lowest 16 bits of gpg_error_t for error codes. The 16th - bit indicates system errors. */ -#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1) - -/* Bits 17 to 24 are reserved. */ - -/* We use the upper 7 bits of gpg_error_t for error sources. */ -#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1) -#define GPG_ERR_SOURCE_SHIFT 24 - -/* The highest bit is reserved. It shouldn't be used to prevent - potential negative numbers when transmitting error values as - text. */ - - -/* GCC feature test. */ -#undef _GPG_ERR_HAVE_CONSTRUCTOR -#if __GNUC__ -#define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#if _GPG_ERR_GCC_VERSION > 30100 -#define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__)) -#define _GPG_ERR_HAVE_CONSTRUCTOR -#endif -#endif - -#ifndef _GPG_ERR_CONSTRUCTOR -#define _GPG_ERR_CONSTRUCTOR -#endif - - -/* Initialization function. */ - -/* Initialize the library. This function should be run early. */ -gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR; - -/* If this is defined, the library is already initialized by the - constructor and does not need to be initialized explicitely. */ -#undef GPG_ERR_INITIALIZED -#ifdef _GPG_ERR_HAVE_CONSTRUCTOR -#define GPG_ERR_INITIALIZED 1 -#endif - -/* See the source on how to use the deinit function; it is usually not - required. */ -void gpg_err_deinit (int mode); - - -/* Constructor and accessor functions. */ - -/* Construct an error value from an error code and source. Within a - subsystem, use gpg_error. */ -static GPG_ERR_INLINE gpg_error_t -gpg_err_make (gpg_err_source_t source, gpg_err_code_t code) -{ - return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR - : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT) - | (code & GPG_ERR_CODE_MASK)); -} - - -/* The user should define GPG_ERR_SOURCE_DEFAULT before including this - file to specify a default source for gpg_error. */ -#ifndef GPG_ERR_SOURCE_DEFAULT -#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN -#endif - -static GPG_ERR_INLINE gpg_error_t -gpg_error (gpg_err_code_t code) -{ - return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code); -} - - -/* Retrieve the error code from an error value. */ -static GPG_ERR_INLINE gpg_err_code_t -gpg_err_code (gpg_error_t err) -{ - return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK); -} - - -/* Retrieve the error source from an error value. */ -static GPG_ERR_INLINE gpg_err_source_t -gpg_err_source (gpg_error_t err) -{ - return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT) - & GPG_ERR_SOURCE_MASK); -} - - -/* String functions. */ - -/* Return a pointer to a string containing a description of the error - code in the error value ERR. This function is not thread-safe. */ -const char *gpg_strerror (gpg_error_t err); - -/* Return the error string for ERR in the user-supplied buffer BUF of - size BUFLEN. This function is, in contrast to gpg_strerror, - thread-safe if a thread-safe strerror_r() function is provided by - the system. If the function succeeds, 0 is returned and BUF - contains the string describing the error. If the buffer was not - large enough, ERANGE is returned and BUF contains as much of the - beginning of the error string as fits into the buffer. */ -int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen); - -/* Return a pointer to a string containing a description of the error - source in the error value ERR. */ -const char *gpg_strsource (gpg_error_t err); - - -/* Mapping of system errors (errno). */ - -/* Retrieve the error code for the system error ERR. This returns - GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report - this). */ -gpg_err_code_t gpg_err_code_from_errno (int err); - - -/* Retrieve the system error for the error code CODE. This returns 0 - if CODE is not a system error code. */ -int gpg_err_code_to_errno (gpg_err_code_t code); - - -/* Retrieve the error code directly from the ERRNO variable. This - returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped - (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */ -gpg_err_code_t gpg_err_code_from_syserror (void); - - -/* Set the ERRNO variable. This function is the preferred way to set - ERRNO due to peculiarities on WindowsCE. */ -void gpg_err_set_errno (int err); - -/* Decide whether to use the format_arg attribute. */ -#if _GPG_ERR_GCC_VERSION > 20800 -# define _GPG_ERR_ATTR_FORMAT_ARG(a) __attribute__ ((__format_arg__ (a))) -#else -# define _GPG_ERR_ATTR_FORMAT_ARG(a) -#endif - -/* A lean gettext implementation based on GNU style mo files which are - required to be encoded in UTF-8. There is a limit on 65534 entries - to save some RAM. Only Germanic plural rules are supported. */ -const char *_gpg_w32_bindtextdomain (const char *domainname, - const char *dirname); -const char *_gpg_w32_textdomain (const char *domainname); -const char *_gpg_w32_gettext (const char *msgid) - _GPG_ERR_ATTR_FORMAT_ARG (1); -const char *_gpg_w32_dgettext (const char *domainname, const char *msgid) - _GPG_ERR_ATTR_FORMAT_ARG (2); -const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1, - const char *msgid2, unsigned long int n) - _GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3); -const char *_gpg_w32_gettext_localename (void); -int _gpg_w32_gettext_use_utf8 (int value); - -#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS -# define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b)) -# define textdomain(a) _gpg_w32_textdomain ((a)) -# define gettext(a) _gpg_w32_gettext ((a)) -# define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) -# define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) -# define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) -# define gettext_localename() _gpg_w32_gettext_localename () -# define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) -#endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/ - - - -/* Self-documenting convenience functions. */ - -static GPG_ERR_INLINE gpg_error_t -gpg_err_make_from_errno (gpg_err_source_t source, int err) -{ - return gpg_err_make (source, gpg_err_code_from_errno (err)); -} - - -static GPG_ERR_INLINE gpg_error_t -gpg_error_from_errno (int err) -{ - return gpg_error (gpg_err_code_from_errno (err)); -} - -static GPG_ERR_INLINE gpg_error_t -gpg_error_from_syserror (void) -{ - return gpg_error (gpg_err_code_from_syserror ()); -} - -#ifdef __cplusplus -} -#endif - - -#endif /* GPG_ERROR_H */ +/* gpg-error.h - Public interface to libgpg-error. -*- c -*-
+ Copyright (C) 2003, 2004, 2010, 2013, 2014, 2015 g10 Code GmbH
+
+ This file is part of libgpg-error.
+
+ libgpg-error 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.
+
+ libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>.
+
+ Do not edit. Generated from gpg-error.h.in for x86_64-pc-mingw32.
+ */
+
+
+#ifndef GPG_ERROR_H
+#define GPG_ERROR_H 1
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifdef __GNUC__
+#define GPG_ERR_INLINE __inline__
+#elif _MSC_VER >= 1300
+#define GPG_ERR_INLINE __inline
+#elif __STDC_VERSION__ >= 199901L
+#define GPG_ERR_INLINE inline
+#else
+#ifndef GPG_ERR_INLINE
+#define GPG_ERR_INLINE
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* just to make Emacs auto-indent happy */
+}
+#endif
+#endif /* __cplusplus */
+
+/* The GnuPG project consists of many components. Error codes are
+ exchanged between all components. The common error codes and their
+ user-presentable descriptions are kept into a shared library to
+ allow adding new error codes and components without recompiling any
+ of the other components. The interface will not change in a
+ backward incompatible way.
+
+ An error code together with an error source build up an error
+ value. As the error value is been passed from one component to
+ another, it preserver the information about the source and nature
+ of the error.
+
+ A component of the GnuPG project can define the following macros to
+ tune the behaviour of the library:
+
+ GPG_ERR_SOURCE_DEFAULT: Define to an error source of type
+ gpg_err_source_t to make that source the default for gpg_error().
+ Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default.
+
+ GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the
+ internal gettext API to standard names. This has only an effect on
+ Windows platforms.
+
+ GPGRT_ENABLE_ES_MACROS: Define to provide "es_" macros for the
+ estream functions.
+
+ In addition to the error codes, Libgpg-error also provides a set of
+ functions used by most GnuPG components. */
+
+
+/* The error source type gpg_err_source_t.
+
+ Where as the Poo out of a welle small
+ Taketh his firste springing and his sours.
+ --Chaucer. */
+
+/* Only use free slots, never change or reorder the existing
+ entries. */
+typedef enum
+ {
+ GPG_ERR_SOURCE_UNKNOWN = 0,
+ GPG_ERR_SOURCE_GCRYPT = 1,
+ GPG_ERR_SOURCE_GPG = 2,
+ GPG_ERR_SOURCE_GPGSM = 3,
+ GPG_ERR_SOURCE_GPGAGENT = 4,
+ GPG_ERR_SOURCE_PINENTRY = 5,
+ GPG_ERR_SOURCE_SCD = 6,
+ GPG_ERR_SOURCE_GPGME = 7,
+ GPG_ERR_SOURCE_KEYBOX = 8,
+ GPG_ERR_SOURCE_KSBA = 9,
+ GPG_ERR_SOURCE_DIRMNGR = 10,
+ GPG_ERR_SOURCE_GSTI = 11,
+ GPG_ERR_SOURCE_GPA = 12,
+ GPG_ERR_SOURCE_KLEO = 13,
+ GPG_ERR_SOURCE_G13 = 14,
+ GPG_ERR_SOURCE_ASSUAN = 15,
+ GPG_ERR_SOURCE_TLS = 17,
+ GPG_ERR_SOURCE_ANY = 31,
+ GPG_ERR_SOURCE_USER_1 = 32,
+ GPG_ERR_SOURCE_USER_2 = 33,
+ GPG_ERR_SOURCE_USER_3 = 34,
+ GPG_ERR_SOURCE_USER_4 = 35,
+
+ /* This is one more than the largest allowed entry. */
+ GPG_ERR_SOURCE_DIM = 128
+ } gpg_err_source_t;
+
+
+/* The error code type gpg_err_code_t. */
+
+/* Only use free slots, never change or reorder the existing
+ entries. */
+typedef enum
+ {
+ GPG_ERR_NO_ERROR = 0,
+ GPG_ERR_GENERAL = 1,
+ GPG_ERR_UNKNOWN_PACKET = 2,
+ GPG_ERR_UNKNOWN_VERSION = 3,
+ GPG_ERR_PUBKEY_ALGO = 4,
+ GPG_ERR_DIGEST_ALGO = 5,
+ GPG_ERR_BAD_PUBKEY = 6,
+ GPG_ERR_BAD_SECKEY = 7,
+ GPG_ERR_BAD_SIGNATURE = 8,
+ GPG_ERR_NO_PUBKEY = 9,
+ GPG_ERR_CHECKSUM = 10,
+ GPG_ERR_BAD_PASSPHRASE = 11,
+ GPG_ERR_CIPHER_ALGO = 12,
+ GPG_ERR_KEYRING_OPEN = 13,
+ GPG_ERR_INV_PACKET = 14,
+ GPG_ERR_INV_ARMOR = 15,
+ GPG_ERR_NO_USER_ID = 16,
+ GPG_ERR_NO_SECKEY = 17,
+ GPG_ERR_WRONG_SECKEY = 18,
+ GPG_ERR_BAD_KEY = 19,
+ GPG_ERR_COMPR_ALGO = 20,
+ GPG_ERR_NO_PRIME = 21,
+ GPG_ERR_NO_ENCODING_METHOD = 22,
+ GPG_ERR_NO_ENCRYPTION_SCHEME = 23,
+ GPG_ERR_NO_SIGNATURE_SCHEME = 24,
+ GPG_ERR_INV_ATTR = 25,
+ GPG_ERR_NO_VALUE = 26,
+ GPG_ERR_NOT_FOUND = 27,
+ GPG_ERR_VALUE_NOT_FOUND = 28,
+ GPG_ERR_SYNTAX = 29,
+ GPG_ERR_BAD_MPI = 30,
+ GPG_ERR_INV_PASSPHRASE = 31,
+ GPG_ERR_SIG_CLASS = 32,
+ GPG_ERR_RESOURCE_LIMIT = 33,
+ GPG_ERR_INV_KEYRING = 34,
+ GPG_ERR_TRUSTDB = 35,
+ GPG_ERR_BAD_CERT = 36,
+ GPG_ERR_INV_USER_ID = 37,
+ GPG_ERR_UNEXPECTED = 38,
+ GPG_ERR_TIME_CONFLICT = 39,
+ GPG_ERR_KEYSERVER = 40,
+ GPG_ERR_WRONG_PUBKEY_ALGO = 41,
+ GPG_ERR_TRIBUTE_TO_D_A = 42,
+ GPG_ERR_WEAK_KEY = 43,
+ GPG_ERR_INV_KEYLEN = 44,
+ GPG_ERR_INV_ARG = 45,
+ GPG_ERR_BAD_URI = 46,
+ GPG_ERR_INV_URI = 47,
+ GPG_ERR_NETWORK = 48,
+ GPG_ERR_UNKNOWN_HOST = 49,
+ GPG_ERR_SELFTEST_FAILED = 50,
+ GPG_ERR_NOT_ENCRYPTED = 51,
+ GPG_ERR_NOT_PROCESSED = 52,
+ GPG_ERR_UNUSABLE_PUBKEY = 53,
+ GPG_ERR_UNUSABLE_SECKEY = 54,
+ GPG_ERR_INV_VALUE = 55,
+ GPG_ERR_BAD_CERT_CHAIN = 56,
+ GPG_ERR_MISSING_CERT = 57,
+ GPG_ERR_NO_DATA = 58,
+ GPG_ERR_BUG = 59,
+ GPG_ERR_NOT_SUPPORTED = 60,
+ GPG_ERR_INV_OP = 61,
+ GPG_ERR_TIMEOUT = 62,
+ GPG_ERR_INTERNAL = 63,
+ GPG_ERR_EOF_GCRYPT = 64,
+ GPG_ERR_INV_OBJ = 65,
+ GPG_ERR_TOO_SHORT = 66,
+ GPG_ERR_TOO_LARGE = 67,
+ GPG_ERR_NO_OBJ = 68,
+ GPG_ERR_NOT_IMPLEMENTED = 69,
+ GPG_ERR_CONFLICT = 70,
+ GPG_ERR_INV_CIPHER_MODE = 71,
+ GPG_ERR_INV_FLAG = 72,
+ GPG_ERR_INV_HANDLE = 73,
+ GPG_ERR_TRUNCATED = 74,
+ GPG_ERR_INCOMPLETE_LINE = 75,
+ GPG_ERR_INV_RESPONSE = 76,
+ GPG_ERR_NO_AGENT = 77,
+ GPG_ERR_AGENT = 78,
+ GPG_ERR_INV_DATA = 79,
+ GPG_ERR_ASSUAN_SERVER_FAULT = 80,
+ GPG_ERR_ASSUAN = 81,
+ GPG_ERR_INV_SESSION_KEY = 82,
+ GPG_ERR_INV_SEXP = 83,
+ GPG_ERR_UNSUPPORTED_ALGORITHM = 84,
+ GPG_ERR_NO_PIN_ENTRY = 85,
+ GPG_ERR_PIN_ENTRY = 86,
+ GPG_ERR_BAD_PIN = 87,
+ GPG_ERR_INV_NAME = 88,
+ GPG_ERR_BAD_DATA = 89,
+ GPG_ERR_INV_PARAMETER = 90,
+ GPG_ERR_WRONG_CARD = 91,
+ GPG_ERR_NO_DIRMNGR = 92,
+ GPG_ERR_DIRMNGR = 93,
+ GPG_ERR_CERT_REVOKED = 94,
+ GPG_ERR_NO_CRL_KNOWN = 95,
+ GPG_ERR_CRL_TOO_OLD = 96,
+ GPG_ERR_LINE_TOO_LONG = 97,
+ GPG_ERR_NOT_TRUSTED = 98,
+ GPG_ERR_CANCELED = 99,
+ GPG_ERR_BAD_CA_CERT = 100,
+ GPG_ERR_CERT_EXPIRED = 101,
+ GPG_ERR_CERT_TOO_YOUNG = 102,
+ GPG_ERR_UNSUPPORTED_CERT = 103,
+ GPG_ERR_UNKNOWN_SEXP = 104,
+ GPG_ERR_UNSUPPORTED_PROTECTION = 105,
+ GPG_ERR_CORRUPTED_PROTECTION = 106,
+ GPG_ERR_AMBIGUOUS_NAME = 107,
+ GPG_ERR_CARD = 108,
+ GPG_ERR_CARD_RESET = 109,
+ GPG_ERR_CARD_REMOVED = 110,
+ GPG_ERR_INV_CARD = 111,
+ GPG_ERR_CARD_NOT_PRESENT = 112,
+ GPG_ERR_NO_PKCS15_APP = 113,
+ GPG_ERR_NOT_CONFIRMED = 114,
+ GPG_ERR_CONFIGURATION = 115,
+ GPG_ERR_NO_POLICY_MATCH = 116,
+ GPG_ERR_INV_INDEX = 117,
+ GPG_ERR_INV_ID = 118,
+ GPG_ERR_NO_SCDAEMON = 119,
+ GPG_ERR_SCDAEMON = 120,
+ GPG_ERR_UNSUPPORTED_PROTOCOL = 121,
+ GPG_ERR_BAD_PIN_METHOD = 122,
+ GPG_ERR_CARD_NOT_INITIALIZED = 123,
+ GPG_ERR_UNSUPPORTED_OPERATION = 124,
+ GPG_ERR_WRONG_KEY_USAGE = 125,
+ GPG_ERR_NOTHING_FOUND = 126,
+ GPG_ERR_WRONG_BLOB_TYPE = 127,
+ GPG_ERR_MISSING_VALUE = 128,
+ GPG_ERR_HARDWARE = 129,
+ GPG_ERR_PIN_BLOCKED = 130,
+ GPG_ERR_USE_CONDITIONS = 131,
+ GPG_ERR_PIN_NOT_SYNCED = 132,
+ GPG_ERR_INV_CRL = 133,
+ GPG_ERR_BAD_BER = 134,
+ GPG_ERR_INV_BER = 135,
+ GPG_ERR_ELEMENT_NOT_FOUND = 136,
+ GPG_ERR_IDENTIFIER_NOT_FOUND = 137,
+ GPG_ERR_INV_TAG = 138,
+ GPG_ERR_INV_LENGTH = 139,
+ GPG_ERR_INV_KEYINFO = 140,
+ GPG_ERR_UNEXPECTED_TAG = 141,
+ GPG_ERR_NOT_DER_ENCODED = 142,
+ GPG_ERR_NO_CMS_OBJ = 143,
+ GPG_ERR_INV_CMS_OBJ = 144,
+ GPG_ERR_UNKNOWN_CMS_OBJ = 145,
+ GPG_ERR_UNSUPPORTED_CMS_OBJ = 146,
+ GPG_ERR_UNSUPPORTED_ENCODING = 147,
+ GPG_ERR_UNSUPPORTED_CMS_VERSION = 148,
+ GPG_ERR_UNKNOWN_ALGORITHM = 149,
+ GPG_ERR_INV_ENGINE = 150,
+ GPG_ERR_PUBKEY_NOT_TRUSTED = 151,
+ GPG_ERR_DECRYPT_FAILED = 152,
+ GPG_ERR_KEY_EXPIRED = 153,
+ GPG_ERR_SIG_EXPIRED = 154,
+ GPG_ERR_ENCODING_PROBLEM = 155,
+ GPG_ERR_INV_STATE = 156,
+ GPG_ERR_DUP_VALUE = 157,
+ GPG_ERR_MISSING_ACTION = 158,
+ GPG_ERR_MODULE_NOT_FOUND = 159,
+ GPG_ERR_INV_OID_STRING = 160,
+ GPG_ERR_INV_TIME = 161,
+ GPG_ERR_INV_CRL_OBJ = 162,
+ GPG_ERR_UNSUPPORTED_CRL_VERSION = 163,
+ GPG_ERR_INV_CERT_OBJ = 164,
+ GPG_ERR_UNKNOWN_NAME = 165,
+ GPG_ERR_LOCALE_PROBLEM = 166,
+ GPG_ERR_NOT_LOCKED = 167,
+ GPG_ERR_PROTOCOL_VIOLATION = 168,
+ GPG_ERR_INV_MAC = 169,
+ GPG_ERR_INV_REQUEST = 170,
+ GPG_ERR_UNKNOWN_EXTN = 171,
+ GPG_ERR_UNKNOWN_CRIT_EXTN = 172,
+ GPG_ERR_LOCKED = 173,
+ GPG_ERR_UNKNOWN_OPTION = 174,
+ GPG_ERR_UNKNOWN_COMMAND = 175,
+ GPG_ERR_NOT_OPERATIONAL = 176,
+ GPG_ERR_NO_PASSPHRASE = 177,
+ GPG_ERR_NO_PIN = 178,
+ GPG_ERR_NOT_ENABLED = 179,
+ GPG_ERR_NO_ENGINE = 180,
+ GPG_ERR_MISSING_KEY = 181,
+ GPG_ERR_TOO_MANY = 182,
+ GPG_ERR_LIMIT_REACHED = 183,
+ GPG_ERR_NOT_INITIALIZED = 184,
+ GPG_ERR_MISSING_ISSUER_CERT = 185,
+ GPG_ERR_NO_KEYSERVER = 186,
+ GPG_ERR_INV_CURVE = 187,
+ GPG_ERR_UNKNOWN_CURVE = 188,
+ GPG_ERR_DUP_KEY = 189,
+ GPG_ERR_AMBIGUOUS = 190,
+ GPG_ERR_NO_CRYPT_CTX = 191,
+ GPG_ERR_WRONG_CRYPT_CTX = 192,
+ GPG_ERR_BAD_CRYPT_CTX = 193,
+ GPG_ERR_CRYPT_CTX_CONFLICT = 194,
+ GPG_ERR_BROKEN_PUBKEY = 195,
+ GPG_ERR_BROKEN_SECKEY = 196,
+ GPG_ERR_MAC_ALGO = 197,
+ GPG_ERR_FULLY_CANCELED = 198,
+ GPG_ERR_UNFINISHED = 199,
+ GPG_ERR_BUFFER_TOO_SHORT = 200,
+ GPG_ERR_SEXP_INV_LEN_SPEC = 201,
+ GPG_ERR_SEXP_STRING_TOO_LONG = 202,
+ GPG_ERR_SEXP_UNMATCHED_PAREN = 203,
+ GPG_ERR_SEXP_NOT_CANONICAL = 204,
+ GPG_ERR_SEXP_BAD_CHARACTER = 205,
+ GPG_ERR_SEXP_BAD_QUOTATION = 206,
+ GPG_ERR_SEXP_ZERO_PREFIX = 207,
+ GPG_ERR_SEXP_NESTED_DH = 208,
+ GPG_ERR_SEXP_UNMATCHED_DH = 209,
+ GPG_ERR_SEXP_UNEXPECTED_PUNC = 210,
+ GPG_ERR_SEXP_BAD_HEX_CHAR = 211,
+ GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212,
+ GPG_ERR_SEXP_BAD_OCT_CHAR = 213,
+ GPG_ERR_LEGACY_KEY = 222,
+ GPG_ERR_REQUEST_TOO_SHORT = 223,
+ GPG_ERR_REQUEST_TOO_LONG = 224,
+ GPG_ERR_OBJ_TERM_STATE = 225,
+ GPG_ERR_NO_CERT_CHAIN = 226,
+ GPG_ERR_CERT_TOO_LARGE = 227,
+ GPG_ERR_INV_RECORD = 228,
+ GPG_ERR_BAD_MAC = 229,
+ GPG_ERR_UNEXPECTED_MSG = 230,
+ GPG_ERR_COMPR_FAILED = 231,
+ GPG_ERR_WOULD_WRAP = 232,
+ GPG_ERR_FATAL_ALERT = 233,
+ GPG_ERR_NO_CIPHER = 234,
+ GPG_ERR_MISSING_CLIENT_CERT = 235,
+ GPG_ERR_CLOSE_NOTIFY = 236,
+ GPG_ERR_TICKET_EXPIRED = 237,
+ GPG_ERR_BAD_TICKET = 238,
+ GPG_ERR_UNKNOWN_IDENTITY = 239,
+ GPG_ERR_BAD_HS_CERT = 240,
+ GPG_ERR_BAD_HS_CERT_REQ = 241,
+ GPG_ERR_BAD_HS_CERT_VER = 242,
+ GPG_ERR_BAD_HS_CHANGE_CIPHER = 243,
+ GPG_ERR_BAD_HS_CLIENT_HELLO = 244,
+ GPG_ERR_BAD_HS_SERVER_HELLO = 245,
+ GPG_ERR_BAD_HS_SERVER_HELLO_DONE = 246,
+ GPG_ERR_BAD_HS_FINISHED = 247,
+ GPG_ERR_BAD_HS_SERVER_KEX = 248,
+ GPG_ERR_BAD_HS_CLIENT_KEX = 249,
+ GPG_ERR_BOGUS_STRING = 250,
+ GPG_ERR_FORBIDDEN = 251,
+ GPG_ERR_KEY_DISABLED = 252,
+ GPG_ERR_KEY_ON_CARD = 253,
+ GPG_ERR_INV_LOCK_OBJ = 254,
+ GPG_ERR_ASS_GENERAL = 257,
+ GPG_ERR_ASS_ACCEPT_FAILED = 258,
+ GPG_ERR_ASS_CONNECT_FAILED = 259,
+ GPG_ERR_ASS_INV_RESPONSE = 260,
+ GPG_ERR_ASS_INV_VALUE = 261,
+ GPG_ERR_ASS_INCOMPLETE_LINE = 262,
+ GPG_ERR_ASS_LINE_TOO_LONG = 263,
+ GPG_ERR_ASS_NESTED_COMMANDS = 264,
+ GPG_ERR_ASS_NO_DATA_CB = 265,
+ GPG_ERR_ASS_NO_INQUIRE_CB = 266,
+ GPG_ERR_ASS_NOT_A_SERVER = 267,
+ GPG_ERR_ASS_NOT_A_CLIENT = 268,
+ GPG_ERR_ASS_SERVER_START = 269,
+ GPG_ERR_ASS_READ_ERROR = 270,
+ GPG_ERR_ASS_WRITE_ERROR = 271,
+ GPG_ERR_ASS_TOO_MUCH_DATA = 273,
+ GPG_ERR_ASS_UNEXPECTED_CMD = 274,
+ GPG_ERR_ASS_UNKNOWN_CMD = 275,
+ GPG_ERR_ASS_SYNTAX = 276,
+ GPG_ERR_ASS_CANCELED = 277,
+ GPG_ERR_ASS_NO_INPUT = 278,
+ GPG_ERR_ASS_NO_OUTPUT = 279,
+ GPG_ERR_ASS_PARAMETER = 280,
+ GPG_ERR_ASS_UNKNOWN_INQUIRE = 281,
+ GPG_ERR_USER_1 = 1024,
+ GPG_ERR_USER_2 = 1025,
+ GPG_ERR_USER_3 = 1026,
+ GPG_ERR_USER_4 = 1027,
+ GPG_ERR_USER_5 = 1028,
+ GPG_ERR_USER_6 = 1029,
+ GPG_ERR_USER_7 = 1030,
+ GPG_ERR_USER_8 = 1031,
+ GPG_ERR_USER_9 = 1032,
+ GPG_ERR_USER_10 = 1033,
+ GPG_ERR_USER_11 = 1034,
+ GPG_ERR_USER_12 = 1035,
+ GPG_ERR_USER_13 = 1036,
+ GPG_ERR_USER_14 = 1037,
+ GPG_ERR_USER_15 = 1038,
+ GPG_ERR_USER_16 = 1039,
+ GPG_ERR_MISSING_ERRNO = 16381,
+ GPG_ERR_UNKNOWN_ERRNO = 16382,
+ GPG_ERR_EOF = 16383,
+
+ /* The following error codes are used to map system errors. */
+#define GPG_ERR_SYSTEM_ERROR (1 << 15)
+ GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0,
+ GPG_ERR_EACCES = GPG_ERR_SYSTEM_ERROR | 1,
+ GPG_ERR_EADDRINUSE = GPG_ERR_SYSTEM_ERROR | 2,
+ GPG_ERR_EADDRNOTAVAIL = GPG_ERR_SYSTEM_ERROR | 3,
+ GPG_ERR_EADV = GPG_ERR_SYSTEM_ERROR | 4,
+ GPG_ERR_EAFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 5,
+ GPG_ERR_EAGAIN = GPG_ERR_SYSTEM_ERROR | 6,
+ GPG_ERR_EALREADY = GPG_ERR_SYSTEM_ERROR | 7,
+ GPG_ERR_EAUTH = GPG_ERR_SYSTEM_ERROR | 8,
+ GPG_ERR_EBACKGROUND = GPG_ERR_SYSTEM_ERROR | 9,
+ GPG_ERR_EBADE = GPG_ERR_SYSTEM_ERROR | 10,
+ GPG_ERR_EBADF = GPG_ERR_SYSTEM_ERROR | 11,
+ GPG_ERR_EBADFD = GPG_ERR_SYSTEM_ERROR | 12,
+ GPG_ERR_EBADMSG = GPG_ERR_SYSTEM_ERROR | 13,
+ GPG_ERR_EBADR = GPG_ERR_SYSTEM_ERROR | 14,
+ GPG_ERR_EBADRPC = GPG_ERR_SYSTEM_ERROR | 15,
+ GPG_ERR_EBADRQC = GPG_ERR_SYSTEM_ERROR | 16,
+ GPG_ERR_EBADSLT = GPG_ERR_SYSTEM_ERROR | 17,
+ GPG_ERR_EBFONT = GPG_ERR_SYSTEM_ERROR | 18,
+ GPG_ERR_EBUSY = GPG_ERR_SYSTEM_ERROR | 19,
+ GPG_ERR_ECANCELED = GPG_ERR_SYSTEM_ERROR | 20,
+ GPG_ERR_ECHILD = GPG_ERR_SYSTEM_ERROR | 21,
+ GPG_ERR_ECHRNG = GPG_ERR_SYSTEM_ERROR | 22,
+ GPG_ERR_ECOMM = GPG_ERR_SYSTEM_ERROR | 23,
+ GPG_ERR_ECONNABORTED = GPG_ERR_SYSTEM_ERROR | 24,
+ GPG_ERR_ECONNREFUSED = GPG_ERR_SYSTEM_ERROR | 25,
+ GPG_ERR_ECONNRESET = GPG_ERR_SYSTEM_ERROR | 26,
+ GPG_ERR_ED = GPG_ERR_SYSTEM_ERROR | 27,
+ GPG_ERR_EDEADLK = GPG_ERR_SYSTEM_ERROR | 28,
+ GPG_ERR_EDEADLOCK = GPG_ERR_SYSTEM_ERROR | 29,
+ GPG_ERR_EDESTADDRREQ = GPG_ERR_SYSTEM_ERROR | 30,
+ GPG_ERR_EDIED = GPG_ERR_SYSTEM_ERROR | 31,
+ GPG_ERR_EDOM = GPG_ERR_SYSTEM_ERROR | 32,
+ GPG_ERR_EDOTDOT = GPG_ERR_SYSTEM_ERROR | 33,
+ GPG_ERR_EDQUOT = GPG_ERR_SYSTEM_ERROR | 34,
+ GPG_ERR_EEXIST = GPG_ERR_SYSTEM_ERROR | 35,
+ GPG_ERR_EFAULT = GPG_ERR_SYSTEM_ERROR | 36,
+ GPG_ERR_EFBIG = GPG_ERR_SYSTEM_ERROR | 37,
+ GPG_ERR_EFTYPE = GPG_ERR_SYSTEM_ERROR | 38,
+ GPG_ERR_EGRATUITOUS = GPG_ERR_SYSTEM_ERROR | 39,
+ GPG_ERR_EGREGIOUS = GPG_ERR_SYSTEM_ERROR | 40,
+ GPG_ERR_EHOSTDOWN = GPG_ERR_SYSTEM_ERROR | 41,
+ GPG_ERR_EHOSTUNREACH = GPG_ERR_SYSTEM_ERROR | 42,
+ GPG_ERR_EIDRM = GPG_ERR_SYSTEM_ERROR | 43,
+ GPG_ERR_EIEIO = GPG_ERR_SYSTEM_ERROR | 44,
+ GPG_ERR_EILSEQ = GPG_ERR_SYSTEM_ERROR | 45,
+ GPG_ERR_EINPROGRESS = GPG_ERR_SYSTEM_ERROR | 46,
+ GPG_ERR_EINTR = GPG_ERR_SYSTEM_ERROR | 47,
+ GPG_ERR_EINVAL = GPG_ERR_SYSTEM_ERROR | 48,
+ GPG_ERR_EIO = GPG_ERR_SYSTEM_ERROR | 49,
+ GPG_ERR_EISCONN = GPG_ERR_SYSTEM_ERROR | 50,
+ GPG_ERR_EISDIR = GPG_ERR_SYSTEM_ERROR | 51,
+ GPG_ERR_EISNAM = GPG_ERR_SYSTEM_ERROR | 52,
+ GPG_ERR_EL2HLT = GPG_ERR_SYSTEM_ERROR | 53,
+ GPG_ERR_EL2NSYNC = GPG_ERR_SYSTEM_ERROR | 54,
+ GPG_ERR_EL3HLT = GPG_ERR_SYSTEM_ERROR | 55,
+ GPG_ERR_EL3RST = GPG_ERR_SYSTEM_ERROR | 56,
+ GPG_ERR_ELIBACC = GPG_ERR_SYSTEM_ERROR | 57,
+ GPG_ERR_ELIBBAD = GPG_ERR_SYSTEM_ERROR | 58,
+ GPG_ERR_ELIBEXEC = GPG_ERR_SYSTEM_ERROR | 59,
+ GPG_ERR_ELIBMAX = GPG_ERR_SYSTEM_ERROR | 60,
+ GPG_ERR_ELIBSCN = GPG_ERR_SYSTEM_ERROR | 61,
+ GPG_ERR_ELNRNG = GPG_ERR_SYSTEM_ERROR | 62,
+ GPG_ERR_ELOOP = GPG_ERR_SYSTEM_ERROR | 63,
+ GPG_ERR_EMEDIUMTYPE = GPG_ERR_SYSTEM_ERROR | 64,
+ GPG_ERR_EMFILE = GPG_ERR_SYSTEM_ERROR | 65,
+ GPG_ERR_EMLINK = GPG_ERR_SYSTEM_ERROR | 66,
+ GPG_ERR_EMSGSIZE = GPG_ERR_SYSTEM_ERROR | 67,
+ GPG_ERR_EMULTIHOP = GPG_ERR_SYSTEM_ERROR | 68,
+ GPG_ERR_ENAMETOOLONG = GPG_ERR_SYSTEM_ERROR | 69,
+ GPG_ERR_ENAVAIL = GPG_ERR_SYSTEM_ERROR | 70,
+ GPG_ERR_ENEEDAUTH = GPG_ERR_SYSTEM_ERROR | 71,
+ GPG_ERR_ENETDOWN = GPG_ERR_SYSTEM_ERROR | 72,
+ GPG_ERR_ENETRESET = GPG_ERR_SYSTEM_ERROR | 73,
+ GPG_ERR_ENETUNREACH = GPG_ERR_SYSTEM_ERROR | 74,
+ GPG_ERR_ENFILE = GPG_ERR_SYSTEM_ERROR | 75,
+ GPG_ERR_ENOANO = GPG_ERR_SYSTEM_ERROR | 76,
+ GPG_ERR_ENOBUFS = GPG_ERR_SYSTEM_ERROR | 77,
+ GPG_ERR_ENOCSI = GPG_ERR_SYSTEM_ERROR | 78,
+ GPG_ERR_ENODATA = GPG_ERR_SYSTEM_ERROR | 79,
+ GPG_ERR_ENODEV = GPG_ERR_SYSTEM_ERROR | 80,
+ GPG_ERR_ENOENT = GPG_ERR_SYSTEM_ERROR | 81,
+ GPG_ERR_ENOEXEC = GPG_ERR_SYSTEM_ERROR | 82,
+ GPG_ERR_ENOLCK = GPG_ERR_SYSTEM_ERROR | 83,
+ GPG_ERR_ENOLINK = GPG_ERR_SYSTEM_ERROR | 84,
+ GPG_ERR_ENOMEDIUM = GPG_ERR_SYSTEM_ERROR | 85,
+ GPG_ERR_ENOMEM = GPG_ERR_SYSTEM_ERROR | 86,
+ GPG_ERR_ENOMSG = GPG_ERR_SYSTEM_ERROR | 87,
+ GPG_ERR_ENONET = GPG_ERR_SYSTEM_ERROR | 88,
+ GPG_ERR_ENOPKG = GPG_ERR_SYSTEM_ERROR | 89,
+ GPG_ERR_ENOPROTOOPT = GPG_ERR_SYSTEM_ERROR | 90,
+ GPG_ERR_ENOSPC = GPG_ERR_SYSTEM_ERROR | 91,
+ GPG_ERR_ENOSR = GPG_ERR_SYSTEM_ERROR | 92,
+ GPG_ERR_ENOSTR = GPG_ERR_SYSTEM_ERROR | 93,
+ GPG_ERR_ENOSYS = GPG_ERR_SYSTEM_ERROR | 94,
+ GPG_ERR_ENOTBLK = GPG_ERR_SYSTEM_ERROR | 95,
+ GPG_ERR_ENOTCONN = GPG_ERR_SYSTEM_ERROR | 96,
+ GPG_ERR_ENOTDIR = GPG_ERR_SYSTEM_ERROR | 97,
+ GPG_ERR_ENOTEMPTY = GPG_ERR_SYSTEM_ERROR | 98,
+ GPG_ERR_ENOTNAM = GPG_ERR_SYSTEM_ERROR | 99,
+ GPG_ERR_ENOTSOCK = GPG_ERR_SYSTEM_ERROR | 100,
+ GPG_ERR_ENOTSUP = GPG_ERR_SYSTEM_ERROR | 101,
+ GPG_ERR_ENOTTY = GPG_ERR_SYSTEM_ERROR | 102,
+ GPG_ERR_ENOTUNIQ = GPG_ERR_SYSTEM_ERROR | 103,
+ GPG_ERR_ENXIO = GPG_ERR_SYSTEM_ERROR | 104,
+ GPG_ERR_EOPNOTSUPP = GPG_ERR_SYSTEM_ERROR | 105,
+ GPG_ERR_EOVERFLOW = GPG_ERR_SYSTEM_ERROR | 106,
+ GPG_ERR_EPERM = GPG_ERR_SYSTEM_ERROR | 107,
+ GPG_ERR_EPFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 108,
+ GPG_ERR_EPIPE = GPG_ERR_SYSTEM_ERROR | 109,
+ GPG_ERR_EPROCLIM = GPG_ERR_SYSTEM_ERROR | 110,
+ GPG_ERR_EPROCUNAVAIL = GPG_ERR_SYSTEM_ERROR | 111,
+ GPG_ERR_EPROGMISMATCH = GPG_ERR_SYSTEM_ERROR | 112,
+ GPG_ERR_EPROGUNAVAIL = GPG_ERR_SYSTEM_ERROR | 113,
+ GPG_ERR_EPROTO = GPG_ERR_SYSTEM_ERROR | 114,
+ GPG_ERR_EPROTONOSUPPORT = GPG_ERR_SYSTEM_ERROR | 115,
+ GPG_ERR_EPROTOTYPE = GPG_ERR_SYSTEM_ERROR | 116,
+ GPG_ERR_ERANGE = GPG_ERR_SYSTEM_ERROR | 117,
+ GPG_ERR_EREMCHG = GPG_ERR_SYSTEM_ERROR | 118,
+ GPG_ERR_EREMOTE = GPG_ERR_SYSTEM_ERROR | 119,
+ GPG_ERR_EREMOTEIO = GPG_ERR_SYSTEM_ERROR | 120,
+ GPG_ERR_ERESTART = GPG_ERR_SYSTEM_ERROR | 121,
+ GPG_ERR_EROFS = GPG_ERR_SYSTEM_ERROR | 122,
+ GPG_ERR_ERPCMISMATCH = GPG_ERR_SYSTEM_ERROR | 123,
+ GPG_ERR_ESHUTDOWN = GPG_ERR_SYSTEM_ERROR | 124,
+ GPG_ERR_ESOCKTNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 125,
+ GPG_ERR_ESPIPE = GPG_ERR_SYSTEM_ERROR | 126,
+ GPG_ERR_ESRCH = GPG_ERR_SYSTEM_ERROR | 127,
+ GPG_ERR_ESRMNT = GPG_ERR_SYSTEM_ERROR | 128,
+ GPG_ERR_ESTALE = GPG_ERR_SYSTEM_ERROR | 129,
+ GPG_ERR_ESTRPIPE = GPG_ERR_SYSTEM_ERROR | 130,
+ GPG_ERR_ETIME = GPG_ERR_SYSTEM_ERROR | 131,
+ GPG_ERR_ETIMEDOUT = GPG_ERR_SYSTEM_ERROR | 132,
+ GPG_ERR_ETOOMANYREFS = GPG_ERR_SYSTEM_ERROR | 133,
+ GPG_ERR_ETXTBSY = GPG_ERR_SYSTEM_ERROR | 134,
+ GPG_ERR_EUCLEAN = GPG_ERR_SYSTEM_ERROR | 135,
+ GPG_ERR_EUNATCH = GPG_ERR_SYSTEM_ERROR | 136,
+ GPG_ERR_EUSERS = GPG_ERR_SYSTEM_ERROR | 137,
+ GPG_ERR_EWOULDBLOCK = GPG_ERR_SYSTEM_ERROR | 138,
+ GPG_ERR_EXDEV = GPG_ERR_SYSTEM_ERROR | 139,
+ GPG_ERR_EXFULL = GPG_ERR_SYSTEM_ERROR | 140,
+
+ /* This is one more than the largest allowed entry. */
+ GPG_ERR_CODE_DIM = 65536
+ } gpg_err_code_t;
+
+
+/* The error value type gpg_error_t. */
+
+/* We would really like to use bit-fields in a struct, but using
+ structs as return values can cause binary compatibility issues, in
+ particular if you want to do it effeciently (also see
+ -freg-struct-return option to GCC). */
+typedef unsigned int gpg_error_t;
+
+/* We use the lowest 16 bits of gpg_error_t for error codes. The 16th
+ bit indicates system errors. */
+#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
+
+/* Bits 17 to 24 are reserved. */
+
+/* We use the upper 7 bits of gpg_error_t for error sources. */
+#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
+#define GPG_ERR_SOURCE_SHIFT 24
+
+/* The highest bit is reserved. It shouldn't be used to prevent
+ potential negative numbers when transmitting error values as
+ text. */
+
+
+/* GCC feature test. */
+#if __GNUC__
+# define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+#else
+# define _GPG_ERR_GCC_VERSION 0
+#endif
+
+#undef _GPG_ERR_HAVE_CONSTRUCTOR
+#if _GPG_ERR_GCC_VERSION > 30100
+# define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__))
+# define _GPG_ERR_HAVE_CONSTRUCTOR
+#else
+# define _GPG_ERR_CONSTRUCTOR
+#endif
+
+#if _GPG_ERR_GCC_VERSION >= 40400
+# define _GPGRT_GCC_A_PRINTF(f, a) __attribute__ ((format(__gnu_printf__,f,a)))
+#elif _GPG_ERR_GCC_VERSION >= 20500
+# define _GPGRT_GCC_A_PRINTF(f, a) __attribute__ ((format(printf,f,a)))
+#else
+# define _GPGRT_GCC_A_PRINTF(f, a)
+#endif
+
+#if _GPG_ERR_GCC_VERSION >= 29200
+# define _GPGRT__RESTRICT __restrict__
+#else
+# define _GPGRT__RESTRICT
+#endif
+
+
+
+/* Initialization function. */
+
+/* Initialize the library. This function should be run early. */
+gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR;
+
+/* If this is defined, the library is already initialized by the
+ constructor and does not need to be initialized explicitely. */
+#undef GPG_ERR_INITIALIZED
+#ifdef _GPG_ERR_HAVE_CONSTRUCTOR
+# define GPG_ERR_INITIALIZED 1
+# define gpgrt_init() do { gpg_err_init (); } while (0)
+#else
+# define gpgrt_init() do { ; } while (0)
+#endif
+
+/* See the source on how to use the deinit function; it is usually not
+ required. */
+void gpg_err_deinit (int mode);
+
+/* Register blocking system I/O clamping functions. */
+void gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void));
+
+/* Register a custom malloc/realloc/free function. */
+void gpgrt_set_alloc_func (void *(*f)(void *a, size_t n));
+
+
+
+/* Constructor and accessor functions. */
+
+/* Construct an error value from an error code and source. Within a
+ subsystem, use gpg_error. */
+static GPG_ERR_INLINE gpg_error_t
+gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
+{
+ return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
+ : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
+ | (code & GPG_ERR_CODE_MASK));
+}
+
+
+/* The user should define GPG_ERR_SOURCE_DEFAULT before including this
+ file to specify a default source for gpg_error. */
+#ifndef GPG_ERR_SOURCE_DEFAULT
+#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN
+#endif
+
+static GPG_ERR_INLINE gpg_error_t
+gpg_error (gpg_err_code_t code)
+{
+ return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
+}
+
+
+/* Retrieve the error code from an error value. */
+static GPG_ERR_INLINE gpg_err_code_t
+gpg_err_code (gpg_error_t err)
+{
+ return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK);
+}
+
+
+/* Retrieve the error source from an error value. */
+static GPG_ERR_INLINE gpg_err_source_t
+gpg_err_source (gpg_error_t err)
+{
+ return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT)
+ & GPG_ERR_SOURCE_MASK);
+}
+
+
+/* String functions. */
+
+/* Return a pointer to a string containing a description of the error
+ code in the error value ERR. This function is not thread-safe. */
+const char *gpg_strerror (gpg_error_t err);
+
+/* Return the error string for ERR in the user-supplied buffer BUF of
+ size BUFLEN. This function is, in contrast to gpg_strerror,
+ thread-safe if a thread-safe strerror_r() function is provided by
+ the system. If the function succeeds, 0 is returned and BUF
+ contains the string describing the error. If the buffer was not
+ large enough, ERANGE is returned and BUF contains as much of the
+ beginning of the error string as fits into the buffer. */
+int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
+
+/* Return a pointer to a string containing a description of the error
+ source in the error value ERR. */
+const char *gpg_strsource (gpg_error_t err);
+
+
+/* Mapping of system errors (errno). */
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gpg_err_code_t gpg_err_code_from_errno (int err);
+
+
+/* Retrieve the system error for the error code CODE. This returns 0
+ if CODE is not a system error code. */
+int gpg_err_code_to_errno (gpg_err_code_t code);
+
+
+/* Retrieve the error code directly from the ERRNO variable. This
+ returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
+ (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
+gpg_err_code_t gpg_err_code_from_syserror (void);
+
+
+/* Set the ERRNO variable. This function is the preferred way to set
+ ERRNO due to peculiarities on WindowsCE. */
+void gpg_err_set_errno (int err);
+
+/* Return or check the version. Both functions are identical. */
+const char *gpgrt_check_version (const char *req_version);
+const char *gpg_error_check_version (const char *req_version);
+
+/* The version string of this header. */
+#define GPG_ERROR_VERSION "1.18"
+
+/* The version number of this header. */
+#define GPG_ERROR_VERSION_NUMBER 0x011200
+
+/* System specific type definitions. */
+# include <stdint.h>
+typedef int64_t gpgrt_ssize_t;
+
+typedef int64_t gpgrt_off_t;
+
+
+
+/* Decide whether to use the format_arg attribute. */
+#if _GPG_ERR_GCC_VERSION > 20800
+# define _GPG_ERR_ATTR_FORMAT_ARG(a) __attribute__ ((__format_arg__ (a)))
+#else
+# define _GPG_ERR_ATTR_FORMAT_ARG(a)
+#endif
+
+/* A lean gettext implementation based on GNU style mo files which are
+ required to be encoded in UTF-8. There is a limit on 65534 entries
+ to save some RAM. Only Germanic plural rules are supported. */
+const char *_gpg_w32_bindtextdomain (const char *domainname,
+ const char *dirname);
+const char *_gpg_w32_textdomain (const char *domainname);
+const char *_gpg_w32_gettext (const char *msgid)
+ _GPG_ERR_ATTR_FORMAT_ARG (1);
+const char *_gpg_w32_dgettext (const char *domainname, const char *msgid)
+ _GPG_ERR_ATTR_FORMAT_ARG (2);
+const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1,
+ const char *msgid2, unsigned long int n)
+ _GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3);
+const char *_gpg_w32_gettext_localename (void);
+int _gpg_w32_gettext_use_utf8 (int value);
+
+#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS
+# define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b))
+# define textdomain(a) _gpg_w32_textdomain ((a))
+# define gettext(a) _gpg_w32_gettext ((a))
+# define dgettext(a,b) _gpg_w32_dgettext ((a), (b))
+# define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c))
+# define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d))
+# define gettext_localename() _gpg_w32_gettext_localename ()
+# define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a)
+#endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/
+
+
+
+
+/* Self-documenting convenience functions. */
+
+static GPG_ERR_INLINE gpg_error_t
+gpg_err_make_from_errno (gpg_err_source_t source, int err)
+{
+ return gpg_err_make (source, gpg_err_code_from_errno (err));
+}
+
+
+static GPG_ERR_INLINE gpg_error_t
+gpg_error_from_errno (int err)
+{
+ return gpg_error (gpg_err_code_from_errno (err));
+}
+
+static GPG_ERR_INLINE gpg_error_t
+gpg_error_from_syserror (void)
+{
+ return gpg_error (gpg_err_code_from_syserror ());
+}
+
+
+
+/* Lock functions. */
+
+
+#ifdef _WIN64
+
+#pragma pack(push, 8)
+typedef struct
+{
+ volatile char priv[56];
+} gpgrt_lock_t;
+#pragma pack(pop)
+
+#define GPGRT_LOCK_INITIALIZER {{1,0,0,0,0,0,0,0,255,255,255,255, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0}}
+
+#else
+
+#pragma pack(push, 8)
+typedef struct
+{
+ volatile char priv[36];
+} gpgrt_lock_t;
+#pragma pack(pop)
+
+#define GPGRT_LOCK_INITIALIZER {{1,0,0,0,0,0,0,0,255,255,255,255, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0}}
+#endif
+
+
+#define GPGRT_LOCK_DEFINE(name) \
+ static gpgrt_lock_t name = GPGRT_LOCK_INITIALIZER
+
+/* NB: If GPGRT_LOCK_DEFINE is not used, zero out the lock variable
+ before passing it to gpgrt_lock_init. */
+gpg_err_code_t gpgrt_lock_init (gpgrt_lock_t *lockhd);
+gpg_err_code_t gpgrt_lock_lock (gpgrt_lock_t *lockhd);
+gpg_err_code_t gpgrt_lock_trylock (gpgrt_lock_t *lockhd);
+gpg_err_code_t gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
+gpg_err_code_t gpgrt_lock_destroy (gpgrt_lock_t *lockhd);
+
+
+
+/* Thread functions. */
+
+gpg_err_code_t gpgrt_yield (void);
+
+
+
+
+/* Estream */
+
+/* The definition of this struct is entirely private. You must not
+ use it for anything. It is only here so some functions can be
+ implemented as macros. */
+struct _gpgrt_stream_internal;
+struct _gpgrt__stream
+{
+ /* The layout of this struct must never change. It may be grown,
+ but only if all functions which access the new members are
+ versioned. */
+
+ /* Various flags. */
+ struct {
+ unsigned int magic: 16;
+ unsigned int writing: 1;
+ unsigned int reserved: 15;
+ } flags;
+
+ /* A pointer to the stream buffer. */
+ unsigned char *buffer;
+
+ /* The size of the buffer in bytes. */
+ size_t buffer_size;
+
+ /* The length of the usable data in the buffer, only valid when in
+ read mode (see flags). */
+ size_t data_len;
+
+ /* The current position of the offset pointer, valid in read and
+ write mode. */
+ size_t data_offset;
+
+ size_t data_flushed;
+ unsigned char *unread_buffer;
+ size_t unread_buffer_size;
+
+ /* The number of unread bytes. */
+ size_t unread_data_len;
+
+ /* A pointer to our internal data for this stream. */
+ struct _gpgrt_stream_internal *intern;
+};
+
+/* The opaque type for an estream. */
+typedef struct _gpgrt__stream *gpgrt_stream_t;
+#ifdef GPGRT_ENABLE_ES_MACROS
+typedef struct _gpgrt__stream *estream_t;
+#endif
+
+typedef gpgrt_ssize_t (*gpgrt_cookie_read_function_t) (void *cookie,
+ void *buffer, size_t size);
+typedef gpgrt_ssize_t (*gpgrt_cookie_write_function_t) (void *cookie,
+ const void *buffer,
+ size_t size);
+typedef int (*gpgrt_cookie_seek_function_t) (void *cookie,
+ gpgrt_off_t *pos, int whence);
+typedef int (*gpgrt_cookie_close_function_t) (void *cookie);
+
+struct _gpgrt_cookie_io_functions
+{
+ gpgrt_cookie_read_function_t func_read;
+ gpgrt_cookie_write_function_t func_write;
+ gpgrt_cookie_seek_function_t func_seek;
+ gpgrt_cookie_close_function_t func_close;
+};
+typedef struct _gpgrt_cookie_io_functions gpgrt_cookie_io_functions_t;
+#ifdef GPGRT_ENABLE_ES_MACROS
+typedef struct _gpgrt_cookie_io_functions es_cookie_io_functions_t;
+#define es_cookie_read_function_t gpgrt_cookie_read_function_t
+#define es_cookie_write_function_t gpgrt_cookie_read_function_t
+#define es_cookie_seek_function_t gpgrt_cookie_read_function_t
+#define es_cookie_close_function_t gpgrt_cookie_read_function_t
+#endif
+
+enum gpgrt_syshd_types
+ {
+ GPGRT_SYSHD_NONE = 0, /* No system handle available. */
+ GPGRT_SYSHD_FD = 1, /* A file descriptor as returned by open(). */
+ GPGRT_SYSHD_SOCK = 2, /* A socket as returned by socket(). */
+ GPGRT_SYSHD_RVID = 3, /* A rendevous id (see libassuan's gpgcedev.c). */
+ GPGRT_SYSHD_HANDLE = 4 /* A HANDLE object (Windows). */
+ };
+
+struct _gpgrt_syshd
+{
+ enum gpgrt_syshd_types type;
+ union {
+ int fd;
+ int sock;
+ int rvid;
+ void *handle;
+ } u;
+};
+typedef struct _gpgrt_syshd gpgrt_syshd_t;
+#ifdef GPGRT_ENABLE_ES_MACROS
+typedef struct _gpgrt_syshd es_syshd_t;
+#define ES_SYSHD_NONE GPGRT_SYSHD_NONE
+#define ES_SYSHD_FD GPGRT_SYSHD_FD
+#define ES_SYSHD_SOCK GPGRT_SYSHD_SOCK
+#define ES_SYSHD_RVID GPGRT_SYSHD_RVID
+#define ES_SYSHD_HANDLE GPGRT_SYSHD_HANDLE
+#endif
+
+gpgrt_stream_t gpgrt_fopen (const char *_GPGRT__RESTRICT path,
+ const char *_GPGRT__RESTRICT mode);
+gpgrt_stream_t gpgrt_mopen (void *_GPGRT__RESTRICT data,
+ size_t data_n, size_t data_len,
+ unsigned int grow,
+ void *(*func_realloc) (void *mem, size_t size),
+ void (*func_free) (void *mem),
+ const char *_GPGRT__RESTRICT mode);
+gpgrt_stream_t gpgrt_fopenmem (size_t memlimit,
+ const char *_GPGRT__RESTRICT mode);
+gpgrt_stream_t gpgrt_fopenmem_init (size_t memlimit,
+ const char *_GPGRT__RESTRICT mode,
+ const void *data, size_t datalen);
+gpgrt_stream_t gpgrt_fdopen (int filedes, const char *mode);
+gpgrt_stream_t gpgrt_fdopen_nc (int filedes, const char *mode);
+gpgrt_stream_t gpgrt_sysopen (gpgrt_syshd_t *syshd, const char *mode);
+gpgrt_stream_t gpgrt_sysopen_nc (gpgrt_syshd_t *syshd, const char *mode);
+gpgrt_stream_t gpgrt_fpopen (FILE *fp, const char *mode);
+gpgrt_stream_t gpgrt_fpopen_nc (FILE *fp, const char *mode);
+gpgrt_stream_t gpgrt_freopen (const char *_GPGRT__RESTRICT path,
+ const char *_GPGRT__RESTRICT mode,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+gpgrt_stream_t gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
+ const char *_GPGRT__RESTRICT mode,
+ gpgrt_cookie_io_functions_t functions);
+int gpgrt_fclose (gpgrt_stream_t stream);
+int gpgrt_fclose_snatch (gpgrt_stream_t stream,
+ void **r_buffer, size_t *r_buflen);
+int gpgrt_onclose (gpgrt_stream_t stream, int mode,
+ void (*fnc) (gpgrt_stream_t, void*), void *fnc_value);
+int gpgrt_fileno (gpgrt_stream_t stream);
+int gpgrt_fileno_unlocked (gpgrt_stream_t stream);
+int gpgrt_syshd (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
+int gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
+
+void _gpgrt_set_std_fd (int no, int fd);
+gpgrt_stream_t _gpgrt_get_std_stream (int fd);
+
+#define gpgrt_stdin _gpgrt_get_std_stream (0)
+#define gpgrt_stdout _gpgrt_get_std_stream (1)
+#define gpgrt_stderr _gpgrt_get_std_stream (2)
+
+
+void gpgrt_flockfile (gpgrt_stream_t stream);
+int gpgrt_ftrylockfile (gpgrt_stream_t stream);
+void gpgrt_funlockfile (gpgrt_stream_t stream);
+
+int gpgrt_feof (gpgrt_stream_t stream);
+int gpgrt_feof_unlocked (gpgrt_stream_t stream);
+int gpgrt_ferror (gpgrt_stream_t stream);
+int gpgrt_ferror_unlocked (gpgrt_stream_t stream);
+void gpgrt_clearerr (gpgrt_stream_t stream);
+void gpgrt_clearerr_unlocked (gpgrt_stream_t stream);
+
+int _gpgrt_pending (gpgrt_stream_t stream); /* (private) */
+int _gpgrt_pending_unlocked (gpgrt_stream_t stream); /* (private) */
+
+#define gpgrt_pending(stream) _gpgrt_pending (stream)
+
+#define gpgrt_pending_unlocked(stream) \
+ (((!(stream)->flags.writing) \
+ && (((stream)->data_offset < (stream)->data_len) \
+ || ((stream)->unread_data_len))) \
+ ? 1 : _gpgrt_pending_unlocked ((stream)))
+
+int gpgrt_fflush (gpgrt_stream_t stream);
+int gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence);
+int gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence);
+long int gpgrt_ftell (gpgrt_stream_t stream);
+gpgrt_off_t gpgrt_ftello (gpgrt_stream_t stream);
+void gpgrt_rewind (gpgrt_stream_t stream);
+
+int gpgrt_fgetc (gpgrt_stream_t stream);
+int gpgrt_fputc (int c, gpgrt_stream_t stream);
+
+int _gpgrt_getc_underflow (gpgrt_stream_t stream); /* (private) */
+int _gpgrt_putc_overflow (int c, gpgrt_stream_t stream); /* (private) */
+
+#define gpgrt_getc_unlocked(stream) \
+ (((!(stream)->flags.writing) \
+ && ((stream)->data_offset < (stream)->data_len) \
+ && (! (stream)->unread_data_len)) \
+ ? ((int) (stream)->buffer[((stream)->data_offset)++]) \
+ : _gpgrt_getc_underflow ((stream)))
+
+#define gpgrt_putc_unlocked(c, stream) \
+ (((stream)->flags.writing \
+ && ((stream)->data_offset < (stream)->buffer_size) \
+ && (c != '\n')) \
+ ? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \
+ : _gpgrt_putc_overflow ((c), (stream)))
+
+#define gpgrt_getc(stream) gpgrt_fgetc (stream)
+#define gpgrt_putc(c, stream) gpgrt_fputc (c, stream)
+
+int gpgrt_ungetc (int c, gpgrt_stream_t stream);
+
+int gpgrt_read (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ void *_GPGRT__RESTRICT buffer, size_t bytes_to_read,
+ size_t *_GPGRT__RESTRICT bytes_read);
+int gpgrt_write (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write,
+ size_t *_GPGRT__RESTRICT bytes_written);
+int gpgrt_write_sanitized (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const void *_GPGRT__RESTRICT buffer, size_t length,
+ const char *delimiters,
+ size_t *_GPGRT__RESTRICT bytes_written);
+int gpgrt_write_hexstring (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const void *_GPGRT__RESTRICT buffer, size_t length,
+ int reserved,
+ size_t *_GPGRT__RESTRICT bytes_written);
+
+size_t gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+size_t gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, size_t size, size_t memb,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+
+char *gpgrt_fgets (char *_GPGRT__RESTRICT s, int n,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+int gpgrt_fputs (const char *_GPGRT__RESTRICT s,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+int gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s,
+ gpgrt_stream_t _GPGRT__RESTRICT stream);
+
+gpgrt_ssize_t gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr,
+ size_t *_GPGRT__RESTRICT n,
+ gpgrt_stream_t stream);
+gpgrt_ssize_t gpgrt_read_line (gpgrt_stream_t stream,
+ char **addr_of_buffer, size_t *length_of_buffer,
+ size_t *max_length);
+void gpgrt_free (void *a);
+
+int gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const char *_GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(2,3);
+int gpgrt_fprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const char *_GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(2,3);
+
+int gpgrt_printf (const char *_GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(1,2);
+int gpgrt_printf_unlocked (const char *_GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(1,2);
+
+int gpgrt_vfprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const char *_GPGRT__RESTRICT format, va_list ap)
+ _GPGRT_GCC_A_PRINTF(2,0);
+int gpgrt_vfprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ const char *_GPGRT__RESTRICT format, va_list ap)
+ _GPGRT_GCC_A_PRINTF(2,0);
+
+int gpgrt_setvbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ char *_GPGRT__RESTRICT buf, int mode, size_t size);
+void gpgrt_setbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ char *_GPGRT__RESTRICT buf);
+
+void gpgrt_set_binary (gpgrt_stream_t stream);
+
+gpgrt_stream_t gpgrt_tmpfile (void);
+
+void gpgrt_opaque_set (gpgrt_stream_t _GPGRT__RESTRICT stream,
+ void *_GPGRT__RESTRICT opaque);
+void *gpgrt_opaque_get (gpgrt_stream_t stream);
+
+void gpgrt_fname_set (gpgrt_stream_t stream, const char *fname);
+const char *gpgrt_fname_get (gpgrt_stream_t stream);
+
+int gpgrt_asprintf (char **r_buf, const char * _GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(2,3);
+int gpgrt_vasprintf (char **r_buf, const char * _GPGRT__RESTRICT format,
+ va_list ap)
+ _GPGRT_GCC_A_PRINTF(2,0);
+char *gpgrt_bsprintf (const char * _GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(1,2);
+char *gpgrt_vbsprintf (const char * _GPGRT__RESTRICT format, va_list ap)
+ _GPGRT_GCC_A_PRINTF(1,0);
+int gpgrt_snprintf (char *buf, size_t bufsize,
+ const char * _GPGRT__RESTRICT format, ...)
+ _GPGRT_GCC_A_PRINTF(3,4);
+int gpgrt_vsnprintf (char *buf,size_t bufsize,
+ const char * _GPGRT__RESTRICT format, va_list arg_ptr)
+ _GPGRT_GCC_A_PRINTF(3,0);
+
+
+#ifdef GPGRT_ENABLE_ES_MACROS
+# define es_fopen gpgrt_fopen
+# define es_mopen gpgrt_mopen
+# define es_fopenmem gpgrt_fopenmem
+# define es_fopenmem_init gpgrt_fopenmem_init
+# define es_fdopen gpgrt_fdopen
+# define es_fdopen_nc gpgrt_fdopen_nc
+# define es_sysopen gpgrt_sysopen
+# define es_sysopen_nc gpgrt_sysopen_nc
+# define es_fpopen gpgrt_fpopen
+# define es_fpopen_nc gpgrt_fpopen_nc
+# define es_freopen gpgrt_freopen
+# define es_fopencookie gpgrt_fopencookie
+# define es_fclose gpgrt_fclose
+# define es_fclose_snatch gpgrt_fclose_snatch
+# define es_onclose gpgrt_onclose
+# define es_fileno gpgrt_fileno
+# define es_fileno_unlocked gpgrt_fileno_unlocked
+# define es_syshd gpgrt_syshd
+# define es_syshd_unlocked gpgrt_syshd_unlocked
+# define es_stdin _gpgrt_get_std_stream (0)
+# define es_stdout _gpgrt_get_std_stream (1)
+# define es_stderr _gpgrt_get_std_stream (2)
+# define es_flockfile gpgrt_flockfile
+# define es_ftrylockfile gpgrt_ftrylockfile
+# define es_funlockfile gpgrt_funlockfile
+# define es_feof gpgrt_feof
+# define es_feof_unlocked gpgrt_feof_unlocked
+# define es_ferror gpgrt_ferror
+# define es_ferror_unlocked gpgrt_ferror_unlocked
+# define es_clearerr gpgrt_clearerr
+# define es_clearerr_unlocked gpgrt_clearerr_unlocked
+# define es_pending gpgrt_pending
+# define es_pending_unlocked gpgrt_pending_unlocked
+# define es_fflush gpgrt_fflush
+# define es_fseek gpgrt_fseek
+# define es_fseeko gpgrt_fseeko
+# define es_ftell gpgrt_ftell
+# define es_ftello gpgrt_ftello
+# define es_rewind gpgrt_rewind
+# define es_fgetc gpgrt_fgetc
+# define es_fputc gpgrt_fputc
+# define es_getc_unlocked gpgrt_getc_unlocked
+# define es_putc_unlocked gpgrt_putc_unlocked
+# define es_getc gpgrt_getc
+# define es_putc gpgrt_putc
+# define es_ungetc gpgrt_ungetc
+# define es_read gpgrt_read
+# define es_write gpgrt_write
+# define es_write_sanitized gpgrt_write_sanitized
+# define es_write_hexstring gpgrt_write_hexstring
+# define es_fread gpgrt_fread
+# define es_fwrite gpgrt_fwrite
+# define es_fgets gpgrt_fgets
+# define es_fputs gpgrt_fputs
+# define es_fputs_unlocked gpgrt_fputs_unlocked
+# define es_getline gpgrt_getline
+# define es_read_line gpgrt_read_line
+# define es_free gpgrt_free
+# define es_fprintf gpgrt_fprintf
+# define es_fprintf_unlocked gpgrt_fprintf_unlocked
+# define es_printf gpgrt_printf
+# define es_printf_unlocked gpgrt_printf_unlocked
+# define es_vfprintf gpgrt_vfprintf
+# define es_vfprintf_unlocked gpgrt_vfprintf_unlocked
+# define es_setvbuf gpgrt_setvbuf
+# define es_setbuf gpgrt_setbuf
+# define es_set_binary gpgrt_set_binary
+# define es_tmpfile gpgrt_tmpfile
+# define es_opaque_set gpgrt_opaque_set
+# define es_opaque_get gpgrt_opaque_get
+# define es_fname_set gpgrt_fname_set
+# define es_fname_get gpgrt_fname_get
+# define es_asprintf gpgrt_asprintf
+# define es_vasprintf gpgrt_vasprintf
+# define es_bsprintf gpgrt_bsprintf
+# define es_vbsprintf gpgrt_vbsprintf
+#endif /*GPGRT_ENABLE_ES_MACROS*/
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* GPG_ERROR_H */
+/*
+Local Variables:
+buffer-read-only: t
+End:
+*/
diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.h.in b/plugins/MirOTR/Libgpg-error/gpg-error.h.in deleted file mode 100644 index ae1be21818..0000000000 --- a/plugins/MirOTR/Libgpg-error/gpg-error.h.in +++ /dev/null @@ -1,274 +0,0 @@ -/* gpg-error.h - Public interface to libgpg-error. - Copyright (C) 2003, 2004, 2010 g10 Code GmbH - - This file is part of libgpg-error. - - libgpg-error 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. - - libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef GPG_ERROR_H -#define GPG_ERROR_H 1 - -#include <stddef.h> - -#ifdef __GNUC__ -#define GPG_ERR_INLINE __inline__ -#elif __STDC_VERSION__ >= 199901L -#define GPG_ERR_INLINE inline -#else -#ifndef GPG_ERR_INLINE -#define GPG_ERR_INLINE -#endif -#endif - - -#ifdef __cplusplus -extern "C" { -#if 0 /* just to make Emacs auto-indent happy */ -} -#endif -#endif /* __cplusplus */ - -/* The GnuPG project consists of many components. Error codes are - exchanged between all components. The common error codes and their - user-presentable descriptions are kept into a shared library to - allow adding new error codes and components without recompiling any - of the other components. The interface will not change in a - backward incompatible way. - - An error code together with an error source build up an error - value. As the error value is been passed from one component to - another, it preserver the information about the source and nature - of the error. - - A component of the GnuPG project can define the following macros to - tune the behaviour of the library: - - GPG_ERR_SOURCE_DEFAULT: Define to an error source of type - gpg_err_source_t to make that source the default for gpg_error(). - Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. - - GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the - internal gettext API to standard names. This has only an effect on - Windows platforms. */ - - -/* The error source type gpg_err_source_t. - - Where as the Poo out of a welle small - Taketh his firste springing and his sours. - --Chaucer. */ - -/* Only use free slots, never change or reorder the existing - entries. */ -typedef enum - { -@include err-sources.h.in - - /* This is one more than the largest allowed entry. */ - GPG_ERR_SOURCE_DIM = 128 - } gpg_err_source_t; - - -/* The error code type gpg_err_code_t. */ - -/* Only use free slots, never change or reorder the existing - entries. */ -typedef enum - { -@include err-codes.h.in - - /* The following error codes are used to map system errors. */ -#define GPG_ERR_SYSTEM_ERROR (1 << 15) -@include errnos.in - - /* This is one more than the largest allowed entry. */ - GPG_ERR_CODE_DIM = 65536 - } gpg_err_code_t; - - -/* The error value type gpg_error_t. */ - -/* We would really like to use bit-fields in a struct, but using - structs as return values can cause binary compatibility issues, in - particular if you want to do it effeciently (also see - -freg-struct-return option to GCC). */ -typedef unsigned int gpg_error_t; - -/* We use the lowest 16 bits of gpg_error_t for error codes. The 16th - bit indicates system errors. */ -#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1) - -/* Bits 17 to 24 are reserved. */ - -/* We use the upper 7 bits of gpg_error_t for error sources. */ -#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1) -#define GPG_ERR_SOURCE_SHIFT 24 - -/* The highest bit is reserved. It shouldn't be used to prevent - potential negative numbers when transmitting error values as - text. */ - - -/* GCC feature test. */ -#undef _GPG_ERR_HAVE_CONSTRUCTOR -#if __GNUC__ -#define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#if _GPG_ERR_GCC_VERSION > 30100 -#define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__)) -#define _GPG_ERR_HAVE_CONSTRUCTOR -#endif -#endif - -#ifndef _GPG_ERR_CONSTRUCTOR -#define _GPG_ERR_CONSTRUCTOR -#endif - - -/* Initialization function. */ - -/* Initialize the library. This function should be run early. */ -gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR; - -/* If this is defined, the library is already initialized by the - constructor and does not need to be initialized explicitely. */ -#undef GPG_ERR_INITIALIZED -#ifdef _GPG_ERR_HAVE_CONSTRUCTOR -#define GPG_ERR_INITIALIZED 1 -#endif - -/* See the source on how to use the deinit function; it is usually not - required. */ -void gpg_err_deinit (int mode); - - -/* Constructor and accessor functions. */ - -/* Construct an error value from an error code and source. Within a - subsystem, use gpg_error. */ -static GPG_ERR_INLINE gpg_error_t -gpg_err_make (gpg_err_source_t source, gpg_err_code_t code) -{ - return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR - : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT) - | (code & GPG_ERR_CODE_MASK)); -} - - -/* The user should define GPG_ERR_SOURCE_DEFAULT before including this - file to specify a default source for gpg_error. */ -#ifndef GPG_ERR_SOURCE_DEFAULT -#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN -#endif - -static GPG_ERR_INLINE gpg_error_t -gpg_error (gpg_err_code_t code) -{ - return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code); -} - - -/* Retrieve the error code from an error value. */ -static GPG_ERR_INLINE gpg_err_code_t -gpg_err_code (gpg_error_t err) -{ - return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK); -} - - -/* Retrieve the error source from an error value. */ -static GPG_ERR_INLINE gpg_err_source_t -gpg_err_source (gpg_error_t err) -{ - return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT) - & GPG_ERR_SOURCE_MASK); -} - - -/* String functions. */ - -/* Return a pointer to a string containing a description of the error - code in the error value ERR. This function is not thread-safe. */ -const char *gpg_strerror (gpg_error_t err); - -/* Return the error string for ERR in the user-supplied buffer BUF of - size BUFLEN. This function is, in contrast to gpg_strerror, - thread-safe if a thread-safe strerror_r() function is provided by - the system. If the function succeeds, 0 is returned and BUF - contains the string describing the error. If the buffer was not - large enough, ERANGE is returned and BUF contains as much of the - beginning of the error string as fits into the buffer. */ -int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen); - -/* Return a pointer to a string containing a description of the error - source in the error value ERR. */ -const char *gpg_strsource (gpg_error_t err); - - -/* Mapping of system errors (errno). */ - -/* Retrieve the error code for the system error ERR. This returns - GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report - this). */ -gpg_err_code_t gpg_err_code_from_errno (int err); - - -/* Retrieve the system error for the error code CODE. This returns 0 - if CODE is not a system error code. */ -int gpg_err_code_to_errno (gpg_err_code_t code); - - -/* Retrieve the error code directly from the ERRNO variable. This - returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped - (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */ -gpg_err_code_t gpg_err_code_from_syserror (void); - - -/* Set the ERRNO variable. This function is the preferred way to set - ERRNO due to peculiarities on WindowsCE. */ -void gpg_err_set_errno (int err); - -@include extra-h.in - -/* Self-documenting convenience functions. */ - -static GPG_ERR_INLINE gpg_error_t -gpg_err_make_from_errno (gpg_err_source_t source, int err) -{ - return gpg_err_make (source, gpg_err_code_from_errno (err)); -} - - -static GPG_ERR_INLINE gpg_error_t -gpg_error_from_errno (int err) -{ - return gpg_error (gpg_err_code_from_errno (err)); -} - -static GPG_ERR_INLINE gpg_error_t -gpg_error_from_syserror (void) -{ - return gpg_error (gpg_err_code_from_syserror ()); -} - -#ifdef __cplusplus -} -#endif - - -#endif /* GPG_ERROR_H */ diff --git a/plugins/MirOTR/Libgpg-error/gpg-error.m4 b/plugins/MirOTR/Libgpg-error/gpg-error.m4 deleted file mode 100644 index 9d96d1675c..0000000000 --- a/plugins/MirOTR/Libgpg-error/gpg-error.m4 +++ /dev/null @@ -1,65 +0,0 @@ -# gpg-error.m4 - autoconf macro to detect libgpg-error. -# Copyright (C) 2002, 2003, 2004 g10 Code GmbH -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. -# -# This file is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION, -dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) -dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS -dnl -AC_DEFUN([AM_PATH_GPG_ERROR], -[ AC_ARG_WITH(gpg-error-prefix, - AC_HELP_STRING([--with-gpg-error-prefix=PFX], - [prefix where GPG Error is installed (optional)]), - gpg_error_config_prefix="$withval", gpg_error_config_prefix="") - if test x$gpg_error_config_prefix != x ; then - if test x${GPG_ERROR_CONFIG+set} != xset ; then - GPG_ERROR_CONFIG=$gpg_error_config_prefix/bin/gpg-error-config - fi - fi - - AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no) - min_gpg_error_version=ifelse([$1], ,0.0,$1) - AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version) - ok=no - if test "$GPG_ERROR_CONFIG" != "no" ; then - req_major=`echo $min_gpg_error_version | \ - sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` - req_minor=`echo $min_gpg_error_version | \ - sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` - gpg_error_config_version=`$GPG_ERROR_CONFIG $gpg_error_config_args --version` - major=`echo $gpg_error_config_version | \ - sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` - minor=`echo $gpg_error_config_version | \ - sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` - if test "$major" -gt "$req_major"; then - ok=yes - else - if test "$major" -eq "$req_major"; then - if test "$minor" -ge "$req_minor"; then - ok=yes - fi - fi - fi - fi - if test $ok = yes; then - GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags` - GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs` - AC_MSG_RESULT([yes ($gpg_error_config_version)]) - ifelse([$2], , :, [$2]) - else - GPG_ERROR_CFLAGS="" - GPG_ERROR_LIBS="" - AC_MSG_RESULT(no) - ifelse([$3], , :, [$3]) - fi - AC_SUBST(GPG_ERROR_CFLAGS) - AC_SUBST(GPG_ERROR_LIBS) -]) - diff --git a/plugins/MirOTR/Libgpg-error/gpgrt-int.h b/plugins/MirOTR/Libgpg-error/gpgrt-int.h new file mode 100644 index 0000000000..bc2db8b83a --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/gpgrt-int.h @@ -0,0 +1,205 @@ +/* gpgrt-int.h - Internal definitions + * Copyright (C) 2014 g10 Code GmbH + * + * This file is part of libgpg-error. + * + * libgpg-error 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. + * + * libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _GPGRT_GPGRT_INT_H +#define _GPGRT_GPGRT_INT_H + +#include "gpg-error.h" +#include "visibility.h" + +/* Local error function prototypes. */ +const char *_gpg_strerror (gpg_error_t err); +int _gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen); +const char *_gpg_strsource (gpg_error_t err); +gpg_err_code_t _gpg_err_code_from_errno (int err); +int _gpg_err_code_to_errno (gpg_err_code_t code); +gpg_err_code_t _gpg_err_code_from_syserror (void); +void _gpg_err_set_errno (int err); + +gpg_error_t _gpg_err_init (void); +void _gpg_err_deinit (int mode); +void _gpgrt_set_alloc_func (void *(*f)(void *a, size_t n)); + +void *_gpgrt_realloc (void *a, size_t n); +void *_gpgrt_malloc (size_t n); +void _gpgrt_free (void *a); + +const char *_gpg_error_check_version (const char *req_version); + +gpg_err_code_t _gpgrt_lock_init (gpgrt_lock_t *lockhd); +gpg_err_code_t _gpgrt_lock_lock (gpgrt_lock_t *lockhd); +gpg_err_code_t _gpgrt_lock_trylock (gpgrt_lock_t *lockhd); +gpg_err_code_t _gpgrt_lock_unlock (gpgrt_lock_t *lockhd); +gpg_err_code_t _gpgrt_lock_destroy (gpgrt_lock_t *lockhd); +gpg_err_code_t _gpgrt_yield (void); + + +/* Local prototypes for estream. */ +int _gpgrt_es_init (void); +void _gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void)); + +gpgrt_stream_t _gpgrt_fopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode); +gpgrt_stream_t _gpgrt_mopen (void *_GPGRT__RESTRICT data, + size_t data_n, size_t data_len, + unsigned int grow, + void *(*func_realloc) (void *mem, size_t size), + void (*func_free) (void *mem), + const char *_GPGRT__RESTRICT mode); +gpgrt_stream_t _gpgrt_fopenmem (size_t memlimit, + const char *_GPGRT__RESTRICT mode); +gpgrt_stream_t _gpgrt_fopenmem_init (size_t memlimit, + const char *_GPGRT__RESTRICT mode, + const void *data, size_t datalen); +gpgrt_stream_t _gpgrt_fdopen (int filedes, const char *mode); +gpgrt_stream_t _gpgrt_fdopen_nc (int filedes, const char *mode); +gpgrt_stream_t _gpgrt_sysopen (gpgrt_syshd_t *syshd, const char *mode); +gpgrt_stream_t _gpgrt_sysopen_nc (gpgrt_syshd_t *syshd, const char *mode); +gpgrt_stream_t _gpgrt_fpopen (FILE *fp, const char *mode); +gpgrt_stream_t _gpgrt_fpopen_nc (FILE *fp, const char *mode); +gpgrt_stream_t _gpgrt_freopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode, + gpgrt_stream_t _GPGRT__RESTRICT stream); +gpgrt_stream_t _gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie, + const char *_GPGRT__RESTRICT mode, + gpgrt_cookie_io_functions_t functions); +int _gpgrt_fclose (gpgrt_stream_t stream); +int _gpgrt_fclose_snatch (gpgrt_stream_t stream, + void **r_buffer, size_t *r_buflen); +int _gpgrt_onclose (gpgrt_stream_t stream, int mode, + void (*fnc) (gpgrt_stream_t, void*), void *fnc_value); +int _gpgrt_fileno (gpgrt_stream_t stream); +int _gpgrt_fileno_unlocked (gpgrt_stream_t stream); +int _gpgrt_syshd (gpgrt_stream_t stream, gpgrt_syshd_t *syshd); +int _gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd); + +void _gpgrt__set_std_fd (int no, int fd); +gpgrt_stream_t _gpgrt__get_std_stream (int fd); + +void _gpgrt_flockfile (gpgrt_stream_t stream); +int _gpgrt_ftrylockfile (gpgrt_stream_t stream); +void _gpgrt_funlockfile (gpgrt_stream_t stream); + +int _gpgrt_feof (gpgrt_stream_t stream); +int _gpgrt_feof_unlocked (gpgrt_stream_t stream); +int _gpgrt_ferror (gpgrt_stream_t stream); +int _gpgrt_ferror_unlocked (gpgrt_stream_t stream); +void _gpgrt_clearerr (gpgrt_stream_t stream); +void _gpgrt_clearerr_unlocked (gpgrt_stream_t stream); +int _gpgrt__pending (gpgrt_stream_t stream); +int _gpgrt__pending_unlocked (gpgrt_stream_t stream); + +int _gpgrt_fflush (gpgrt_stream_t stream); +int _gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence); +int _gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence); +long int _gpgrt_ftell (gpgrt_stream_t stream); +gpgrt_off_t _gpgrt_ftello (gpgrt_stream_t stream); +void _gpgrt_rewind (gpgrt_stream_t stream); + +int _gpgrt_fgetc (gpgrt_stream_t stream); +int _gpgrt_fputc (int c, gpgrt_stream_t stream); + +int _gpgrt__getc_underflow (gpgrt_stream_t stream); +int _gpgrt__putc_overflow (int c, gpgrt_stream_t stream); + +/* Note: Keeps the next two macros in sync + with their counterparts in gpg-error.h. */ +#define _gpgrt_getc_unlocked(stream) \ + (((!(stream)->flags.writing) \ + && ((stream)->data_offset < (stream)->data_len) \ + && (! (stream)->unread_data_len)) \ + ? ((int) (stream)->buffer[((stream)->data_offset)++]) \ + : _gpgrt__getc_underflow ((stream))) + +#define _gpgrt_putc_unlocked(c, stream) \ + (((stream)->flags.writing \ + && ((stream)->data_offset < (stream)->buffer_size) \ + && (c != '\n')) \ + ? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \ + : _gpgrt__putc_overflow ((c), (stream))) + +int _gpgrt_ungetc (int c, gpgrt_stream_t stream); + +int _gpgrt_read (gpgrt_stream_t _GPGRT__RESTRICT stream, + void *_GPGRT__RESTRICT buffer, size_t bytes_to_read, + size_t *_GPGRT__RESTRICT bytes_read); +int _gpgrt_write (gpgrt_stream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write, + size_t *_GPGRT__RESTRICT bytes_written); +int _gpgrt_write_sanitized (gpgrt_stream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t length, + const char *delimiters, + size_t *_GPGRT__RESTRICT bytes_written); +int _gpgrt_write_hexstring (gpgrt_stream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t length, + int reserved, + size_t *_GPGRT__RESTRICT bytes_written); + +size_t _gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems, + gpgrt_stream_t _GPGRT__RESTRICT stream); +size_t _gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, + size_t size, size_t memb, + gpgrt_stream_t _GPGRT__RESTRICT stream); + +char *_gpgrt_fgets (char *_GPGRT__RESTRICT s, int n, + gpgrt_stream_t _GPGRT__RESTRICT stream); +int _gpgrt_fputs (const char *_GPGRT__RESTRICT s, + gpgrt_stream_t _GPGRT__RESTRICT stream); +int _gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s, + gpgrt_stream_t _GPGRT__RESTRICT stream); + +gpgrt_ssize_t _gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, + size_t *_GPGRT__RESTRICT n, + gpgrt_stream_t stream); +gpgrt_ssize_t _gpgrt_read_line (gpgrt_stream_t stream, + char **addr_of_buffer, size_t *length_of_buffer, + size_t *max_length); + +int _gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) + _GPGRT_GCC_A_PRINTF(2,3); +int _gpgrt_fprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) + _GPGRT_GCC_A_PRINTF(2,3); + +int _gpgrt_vfprintf (gpgrt_stream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, va_list ap) + _GPGRT_GCC_A_PRINTF(2,0); +int _gpgrt_vfprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, va_list ap) + _GPGRT_GCC_A_PRINTF(2,0); + +int _gpgrt_setvbuf (gpgrt_stream_t _GPGRT__RESTRICT stream, + char *_GPGRT__RESTRICT buf, int mode, size_t size); + +void _gpgrt_set_binary (gpgrt_stream_t stream); + +gpgrt_stream_t _gpgrt_tmpfile (void); + +void _gpgrt_opaque_set (gpgrt_stream_t _GPGRT__RESTRICT stream, + void *_GPGRT__RESTRICT opaque); +void *_gpgrt_opaque_get (gpgrt_stream_t stream); + +void _gpgrt_fname_set (gpgrt_stream_t stream, const char *fname); +const char *_gpgrt_fname_get (gpgrt_stream_t stream); + +#include "estream-printf.h" + + +#endif /*_GPGRT_GPGRT_INT_H*/ diff --git a/plugins/MirOTR/Libgpg-error/init.c b/plugins/MirOTR/Libgpg-error/init.c index d30435a2ce..6305fe31af 100644 --- a/plugins/MirOTR/Libgpg-error/init.c +++ b/plugins/MirOTR/Libgpg-error/init.c @@ -7,12 +7,12 @@ 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. - + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. */ @@ -26,13 +26,19 @@ #include <string.h> #include <errno.h> -#include <gpg-error.h> - +#include "gpgrt-int.h" #include "gettext.h" #include "init.h" #ifdef HAVE_W32CE_SYSTEM # include "mkw32errmap.map.c" /* Generated map_w32codes () */ +# ifndef TLS_OUT_OF_INDEXES +# define TLS_OUT_OF_INDEXES 0xFFFFFFFF +# endif +# ifndef __MINGW32CE__ +# /* Replace the Mingw32CE provided abort function. */ +# define abort() do { TerminateProcess (GetCurrentProcess(), 8); } while (0) +# endif #endif @@ -42,7 +48,7 @@ #include <windows.h> -static int tls_index = TLS_OUT_OF_INDEXES; /* Index for the TLS functions. */ +static int tls_index = TLS_OUT_OF_INDEXES; /* Index for the TLS functions. */ static char *get_locale_dir (void); static void drop_locale_dir (char *locale_dir); @@ -54,6 +60,11 @@ static void drop_locale_dir (char *locale_dir); #endif /*!HAVE_W32_SYSTEM*/ + +/* The realloc function as set by gpgrt_set_alloc_func. */ +static void *(*custom_realloc)(void *a, size_t n); + + static void real_init (void) @@ -69,11 +80,12 @@ real_init (void) drop_locale_dir (locale_dir); } #endif + _gpgrt_es_init (); } /* Initialize the library. This function should be run early. */ gpg_error_t -gpg_err_init (void) +_gpg_err_init (void) { #ifdef HAVE_W32_SYSTEM # ifdef DLL_EXPORT @@ -96,6 +108,7 @@ gpg_err_init (void) /* No way to continue - commit suicide. */ abort (); } + _gpg_w32__init_gettext_module (); real_init (); } # endif /*!DLL_EXPORT*/ @@ -115,11 +128,11 @@ gpg_err_init (void) this function may be called from the DllMain function of a DLL which statically links to libgpg-error. */ void -gpg_err_deinit (int mode) +_gpg_err_deinit (int mode) { #if defined (HAVE_W32_SYSTEM) && !defined(DLL_EXPORT) struct tls_space_s *tls; - + tls = TlsGetValue (tls_index); if (tls) { @@ -138,6 +151,58 @@ gpg_err_deinit (int mode) } + + +/* Register F as allocation function. This function is used for all + APIs which return an allocated buffer. F needs to have standard + realloc semantics. It should be called as early as possible and + not changed later. */ +void +_gpgrt_set_alloc_func (void *(*f)(void *a, size_t n)) +{ + custom_realloc = f; +} + + +/* The realloc to be used for data returned by the public API. */ +void * +_gpgrt_realloc (void *a, size_t n) +{ + if (custom_realloc) + return custom_realloc (a, n); + + if (!a) + return malloc (n); + + if (!n) + { + free (a); + return NULL; + } + + return realloc (a, n); +} + + +/* The malloc to be used for data returned by the public API. */ +void * +_gpgrt_malloc (size_t n) +{ + if (!n) + n++; + return _gpgrt_realloc (NULL, n); +} + + +/* The free to be used for data returned by the public API. */ +void +_gpgrt_free (void *a) +{ + _gpgrt_realloc (a, 0); +} + + + #ifdef HAVE_W32_SYSTEM @@ -218,7 +283,7 @@ get_locale_dir (void) nbytes = WideCharToMultiByte (CP_UTF8, 0, moddir, -1, NULL, 0, NULL, NULL); if (nbytes < 0) return NULL; - + result = malloc (nbytes + strlen (SLDIR) + 1); if (result) { @@ -234,6 +299,27 @@ get_locale_dir (void) p = strrchr (result, '\\'); if (p) *p = 0; + /* If we are installed below "bin" strip that part and + use the top directory instead. + + Background: Under Windows we don't install GnuPG + below bin/ but in the top directory with only share/, + lib/, and etc/ below it. One of the reasons is to + keep the the length of the filenames at bay so not to + increase the limited length of the PATH envvar. + Another and more important reason, however, is that + the very first GPG versions on W32 were installed + into a flat directory structure and for best + compatibility with these versions we didn't changed + that later. For WindowsCE we can right away install + it under bin, though. The hack with detection of the + bin directory part allows us to eventually migrate to + such a directory layout under plain Windows without + the need to change libgpg-error. */ + p = strrchr (result, '\\'); + if (p && !strcmp (p+1, "bin")) + *p = 0; + /* Append the static part. */ strcat (result, SLDIR); } } @@ -246,8 +332,8 @@ get_locale_dir (void) strcpy (result, "c:\\gnupg"); strcat (result, SLDIR); } - } -#undef SLDIR + } +#undef SLDIR return result; } @@ -280,7 +366,7 @@ get_tls (void) tls->gt_use_utf8 = 0; TlsSetValue (tls_index, tls); } - + return tls; } @@ -308,6 +394,10 @@ _gpg_w32ce_strerror (int err) if (err == -1) err = _gpg_w32ce_get_errno (); + + /* Note: On a German HTC Touch Pro2 device I also tried + LOCALE_USER_DEFAULT and LOCALE_SYSTEM_DEFAULT - both returned + English messages. */ if (FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmpbuf, STRBUFFER_SIZE -1, @@ -324,13 +414,13 @@ _gpg_w32ce_strerror (int err) if (n < 0) snprintf (tls->strerror_buffer, sizeof tls->strerror_buffer -1, "[w32err=%d]", err); - return tls->strerror_buffer; + return tls->strerror_buffer; } #endif /*HAVE_W32CE_SYSTEM*/ void -gpg_err_set_errno (int err) +_gpg_err_set_errno (int err) { #ifdef HAVE_W32CE_SYSTEM SetLastError (err); @@ -347,13 +437,18 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved) { struct tls_space_s *tls; (void)reserved; + (void)hinst; switch (reason) { case DLL_PROCESS_ATTACH: tls_index = TlsAlloc (); if (tls_index == TLS_OUT_OF_INDEXES) - return FALSE; + return FALSE; +#ifndef _GPG_ERR_HAVE_CONSTRUCTOR + /* If we have not constructors (e.g. MSC) we call it here. */ + _gpg_w32__init_gettext_module (); +#endif /* falltru. */ case DLL_THREAD_ATTACH: tls = LocalAlloc (LPTR, sizeof *tls); @@ -383,7 +478,7 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved) default: break; } - + return TRUE; } #endif /*DLL_EXPORT*/ @@ -391,7 +486,7 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved) #else /*!HAVE_W32_SYSTEM*/ void -gpg_err_set_errno (int err) +_gpg_err_set_errno (int err) { errno = err; } diff --git a/plugins/MirOTR/Libgpg-error/init.h b/plugins/MirOTR/Libgpg-error/init.h index 0fa27be4d2..0a31fd72c4 100644 --- a/plugins/MirOTR/Libgpg-error/init.h +++ b/plugins/MirOTR/Libgpg-error/init.h @@ -60,6 +60,11 @@ struct tls_space_s struct tls_space_s *get_tls (void); +/* Explicit constructor for w32-gettext.c */ +#ifndef DLL_EXPORT +void _gpg_w32__init_gettext_module (void); +#endif + #endif /*HAVE_W32_SYSTEM*/ #endif /*INIT_H*/ diff --git a/plugins/MirOTR/Libgpg-error/lock.h b/plugins/MirOTR/Libgpg-error/lock.h new file mode 100644 index 0000000000..b60f2c2401 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/lock.h @@ -0,0 +1,24 @@ +/* lock.h - Declarations for *-lock.c + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef LOCK_H +#define LOCK_H + + +#endif /*LOCK_H*/ diff --git a/plugins/MirOTR/Libgpg-error/mkerrcodes.awk b/plugins/MirOTR/Libgpg-error/mkerrcodes.awk deleted file mode 100644 index 46d436c6b0..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkerrcodes.awk +++ /dev/null @@ -1,99 +0,0 @@ -# mkerrcodes.awk -# Copyright (C) 2004, 2005 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkerrcodes.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkerrcodes.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkerrcodes.awk program. -# -# Certain portions of the mkerrcodes.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkerrcodes.awk. We call these the "data" portions. The rest of the -# mkerrcodes.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkerrcodes.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkerrcodes.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkerrcodes.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script outputs an intermediate file that contains the following output: -# static struct -# { -# int err; -# const char *err_sym; -# } err_table[] = -# { -# { 7, "GPG_ERR_E2BIG" }, -# [...] -# }; -# -# The input file is a list of possible system errors, followed by a GPG_ERR_* name: -# -# 7 GPG_ERR_E2BIG -# -# Comments (starting with # and ending at the end of the line) are removed, -# as is trailing whitespace. - -BEGIN { - FS="[ \t]+GPG_ERR_"; - print "/* Output of mkerrcodes.awk. DO NOT EDIT. */"; - print ""; - header = 1; -} - -/^#/ { next; } - -header { - if (! /^[ \t]*$/) - { - header = 0; - - print "static struct"; - print " {"; - print " int err;"; - print " const char *err_sym;"; - print " } err_table[] = "; - print "{"; - } - else - print; -} - -!header { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - print " { " $1 ", \"GPG_ERR_" $2 "\" },"; -} - -END { - print "};"; -} diff --git a/plugins/MirOTR/Libgpg-error/mkerrcodes.exe b/plugins/MirOTR/Libgpg-error/mkerrcodes.exe Binary files differdeleted file mode 100644 index e8ea336f01..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkerrcodes.exe +++ /dev/null diff --git a/plugins/MirOTR/Libgpg-error/mkerrcodes.h b/plugins/MirOTR/Libgpg-error/mkerrcodes.h index b9bc07bbc5..e7b8c62ac7 100644 --- a/plugins/MirOTR/Libgpg-error/mkerrcodes.h +++ b/plugins/MirOTR/Libgpg-error/mkerrcodes.h @@ -8,84 +8,113 @@ static struct { { 7, "GPG_ERR_E2BIG" }, { 13, "GPG_ERR_EACCES" }, - { 10013L, "GPG_ERR_EACCES" }, - { 10048L, "GPG_ERR_EADDRINUSE" }, - { 10049L, "GPG_ERR_EADDRNOTAVAIL" }, - { 10047L, "GPG_ERR_EAFNOSUPPORT" }, + { (10000 + 13), "GPG_ERR_EACCES" }, + { 100, "GPG_ERR_EADDRINUSE" }, + { (10000 + 48), "GPG_ERR_EADDRINUSE" }, + { 101, "GPG_ERR_EADDRNOTAVAIL" }, + { (10000 + 49), "GPG_ERR_EADDRNOTAVAIL" }, + { 102, "GPG_ERR_EAFNOSUPPORT" }, + { (10000 + 47), "GPG_ERR_EAFNOSUPPORT" }, { 11, "GPG_ERR_EAGAIN" }, - { 10037L, "GPG_ERR_EALREADY" }, + { 103, "GPG_ERR_EALREADY" }, + { (10000 + 37), "GPG_ERR_EALREADY" }, { 9, "GPG_ERR_EBADF" }, - { 10009L, "GPG_ERR_EBADF" }, + { (10000 + 9), "GPG_ERR_EBADF" }, { 16, "GPG_ERR_EBUSY" }, + { 105, "GPG_ERR_ECANCELED" }, { 10, "GPG_ERR_ECHILD" }, - { 10053L, "GPG_ERR_ECONNABORTED" }, - { 10061L, "GPG_ERR_ECONNREFUSED" }, - { 10054L, "GPG_ERR_ECONNRESET" }, + { 106, "GPG_ERR_ECONNABORTED" }, + { (10000 + 53), "GPG_ERR_ECONNABORTED" }, + { 107, "GPG_ERR_ECONNREFUSED" }, + { (10000 + 61), "GPG_ERR_ECONNREFUSED" }, + { 108, "GPG_ERR_ECONNRESET" }, + { (10000 + 54), "GPG_ERR_ECONNRESET" }, { 36, "GPG_ERR_EDEADLK" }, { 36, "GPG_ERR_EDEADLOCK" }, - { 10039L, "GPG_ERR_EDESTADDRREQ" }, + { 109, "GPG_ERR_EDESTADDRREQ" }, + { (10000 + 39), "GPG_ERR_EDESTADDRREQ" }, { 33, "GPG_ERR_EDOM" }, - { 10069L, "GPG_ERR_EDQUOT" }, + { (10000 + 69), "GPG_ERR_EDQUOT" }, { 17, "GPG_ERR_EEXIST" }, { 14, "GPG_ERR_EFAULT" }, - { 10014L, "GPG_ERR_EFAULT" }, + { (10000 + 14), "GPG_ERR_EFAULT" }, { 27, "GPG_ERR_EFBIG" }, - { 10064L, "GPG_ERR_EHOSTDOWN" }, - { 10065L, "GPG_ERR_EHOSTUNREACH" }, + { (10000 + 64), "GPG_ERR_EHOSTDOWN" }, + { 110, "GPG_ERR_EHOSTUNREACH" }, + { (10000 + 65), "GPG_ERR_EHOSTUNREACH" }, { 42, "GPG_ERR_EILSEQ" }, - { 10036L, "GPG_ERR_EINPROGRESS" }, + { 112, "GPG_ERR_EINPROGRESS" }, + { (10000 + 36), "GPG_ERR_EINPROGRESS" }, { 4, "GPG_ERR_EINTR" }, - { 10004L, "GPG_ERR_EINTR" }, + { (10000 + 4), "GPG_ERR_EINTR" }, { 22, "GPG_ERR_EINVAL" }, - { 10022L, "GPG_ERR_EINVAL" }, + { (10000 + 22), "GPG_ERR_EINVAL" }, { 5, "GPG_ERR_EIO" }, - { 10056L, "GPG_ERR_EISCONN" }, + { 113, "GPG_ERR_EISCONN" }, + { (10000 + 56), "GPG_ERR_EISCONN" }, { 21, "GPG_ERR_EISDIR" }, - { 10062L, "GPG_ERR_ELOOP" }, + { 114, "GPG_ERR_ELOOP" }, + { (10000 + 62), "GPG_ERR_ELOOP" }, { 24, "GPG_ERR_EMFILE" }, - { 10024L, "GPG_ERR_EMFILE" }, + { (10000 + 24), "GPG_ERR_EMFILE" }, { 31, "GPG_ERR_EMLINK" }, - { 10040L, "GPG_ERR_EMSGSIZE" }, + { 115, "GPG_ERR_EMSGSIZE" }, + { (10000 + 40), "GPG_ERR_EMSGSIZE" }, { 38, "GPG_ERR_ENAMETOOLONG" }, - { 10063L, "GPG_ERR_ENAMETOOLONG" }, - { 10050L, "GPG_ERR_ENETDOWN" }, - { 10052L, "GPG_ERR_ENETRESET" }, - { 10051L, "GPG_ERR_ENETUNREACH" }, + { (10000 + 63), "GPG_ERR_ENAMETOOLONG" }, + { 116, "GPG_ERR_ENETDOWN" }, + { (10000 + 50), "GPG_ERR_ENETDOWN" }, + { 117, "GPG_ERR_ENETRESET" }, + { (10000 + 52), "GPG_ERR_ENETRESET" }, + { 118, "GPG_ERR_ENETUNREACH" }, + { (10000 + 51), "GPG_ERR_ENETUNREACH" }, { 23, "GPG_ERR_ENFILE" }, - { 10055L, "GPG_ERR_ENOBUFS" }, + { 119, "GPG_ERR_ENOBUFS" }, + { (10000 + 55), "GPG_ERR_ENOBUFS" }, { 19, "GPG_ERR_ENODEV" }, { 2, "GPG_ERR_ENOENT" }, { 8, "GPG_ERR_ENOEXEC" }, { 39, "GPG_ERR_ENOLCK" }, { 12, "GPG_ERR_ENOMEM" }, - { 10042L, "GPG_ERR_ENOPROTOOPT" }, + { 123, "GPG_ERR_ENOPROTOOPT" }, + { (10000 + 42), "GPG_ERR_ENOPROTOOPT" }, { 28, "GPG_ERR_ENOSPC" }, { 40, "GPG_ERR_ENOSYS" }, - { 10057L, "GPG_ERR_ENOTCONN" }, + { 126, "GPG_ERR_ENOTCONN" }, + { (10000 + 57), "GPG_ERR_ENOTCONN" }, { 20, "GPG_ERR_ENOTDIR" }, { 41, "GPG_ERR_ENOTEMPTY" }, - { 10066L, "GPG_ERR_ENOTEMPTY" }, - { 10038L, "GPG_ERR_ENOTSOCK" }, + { (10000 + 66), "GPG_ERR_ENOTEMPTY" }, + { 128, "GPG_ERR_ENOTSOCK" }, + { (10000 + 38), "GPG_ERR_ENOTSOCK" }, + { 129, "GPG_ERR_ENOTSUP" }, { 25, "GPG_ERR_ENOTTY" }, { 6, "GPG_ERR_ENXIO" }, - { 10045L, "GPG_ERR_EOPNOTSUPP" }, + { 130, "GPG_ERR_EOPNOTSUPP" }, + { (10000 + 45), "GPG_ERR_EOPNOTSUPP" }, + { 132, "GPG_ERR_EOVERFLOW" }, { 1, "GPG_ERR_EPERM" }, - { 10046L, "GPG_ERR_EPFNOSUPPORT" }, + { (10000 + 46), "GPG_ERR_EPFNOSUPPORT" }, { 32, "GPG_ERR_EPIPE" }, - { 10067L, "GPG_ERR_EPROCLIM" }, - { 10043L, "GPG_ERR_EPROTONOSUPPORT" }, - { 10041L, "GPG_ERR_EPROTOTYPE" }, + { (10000 + 67), "GPG_ERR_EPROCLIM" }, + { 134, "GPG_ERR_EPROTO" }, + { 135, "GPG_ERR_EPROTONOSUPPORT" }, + { (10000 + 43), "GPG_ERR_EPROTONOSUPPORT" }, + { 136, "GPG_ERR_EPROTOTYPE" }, + { (10000 + 41), "GPG_ERR_EPROTOTYPE" }, { 34, "GPG_ERR_ERANGE" }, - { 10071L, "GPG_ERR_EREMOTE" }, + { (10000 + 71), "GPG_ERR_EREMOTE" }, { 30, "GPG_ERR_EROFS" }, - { 10058L, "GPG_ERR_ESHUTDOWN" }, - { 10044L, "GPG_ERR_ESOCKTNOSUPPORT" }, + { (10000 + 58), "GPG_ERR_ESHUTDOWN" }, + { (10000 + 44), "GPG_ERR_ESOCKTNOSUPPORT" }, { 29, "GPG_ERR_ESPIPE" }, { 3, "GPG_ERR_ESRCH" }, - { 10070L, "GPG_ERR_ESTALE" }, - { 10060L, "GPG_ERR_ETIMEDOUT" }, - { 10059L, "GPG_ERR_ETOOMANYREFS" }, - { 10068L, "GPG_ERR_EUSERS" }, - { 10035L, "GPG_ERR_EWOULDBLOCK" }, + { (10000 + 70), "GPG_ERR_ESTALE" }, + { 138, "GPG_ERR_ETIMEDOUT" }, + { (10000 + 60), "GPG_ERR_ETIMEDOUT" }, + { (10000 + 59), "GPG_ERR_ETOOMANYREFS" }, + { (10000 + 68), "GPG_ERR_EUSERS" }, + { 140, "GPG_ERR_EWOULDBLOCK" }, + { (10000 + 35), "GPG_ERR_EWOULDBLOCK" }, { 18, "GPG_ERR_EXDEV" }, }; diff --git a/plugins/MirOTR/Libgpg-error/mkerrcodes1.awk b/plugins/MirOTR/Libgpg-error/mkerrcodes1.awk deleted file mode 100644 index a771a73602..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkerrcodes1.awk +++ /dev/null @@ -1,96 +0,0 @@ -# mkerrcodes.awk -# Copyright (C) 2003, 2004 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkerrcodes.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkerrcodes.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkerrcodes.awk program. -# -# Certain portions of the mkerrcodes.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkerrcodes.awk. We call these the "data" portions. The rest of the -# mkerrcodes.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkerrcodes.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkerrcodes.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkerrcodes.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script outputs an intermediate file that contains the following block -# for each error value symbol in the input file (example for EINVAL): -# -# #ifdef EINVAL -# EINVAL GPG_ERR_EINVAL -# #endif -# -# The input file is a list of possible system errors in the column errnoidx -# (defaults to 2). -# -# Comments (starting with # and ending at the end of the line) are removed, -# as is trailing whitespace. - -BEGIN { - FS="[\t]+"; - header = 1; - if (errnoidx == 0) - errnoidx = 2; - - print "/* Output of mkerrcodes.awk. DO NOT EDIT. */"; - print ""; -} - -/^#/ { next; } - -header { - if ($1 ~ /^[0-9]/) - { - print "#include <errno.h>"; - print "#ifdef _WIN32"; - print "#include <winsock2.h>"; - print "#endif"; - print ""; - header = 0; - } - else - print; -} - -!header { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - print "#ifdef " $errnoidx; - print $errnoidx "\tGPG_ERR_" $errnoidx; - print "#endif"; - print "#ifdef WSA" $errnoidx; - print "WSA" $errnoidx "\tGPG_ERR_" $errnoidx; - print "#endif"; -} diff --git a/plugins/MirOTR/Libgpg-error/mkerrcodes2.awk b/plugins/MirOTR/Libgpg-error/mkerrcodes2.awk deleted file mode 100644 index ea5850341c..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkerrcodes2.awk +++ /dev/null @@ -1,134 +0,0 @@ -# mkstrtable.awk -# Copyright (C) 2003 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkerrcodes2.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkerrcodes2.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkerrcodes2.awk program. -# -# Certain portions of the mkerrcodes2.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkerrcodes2.awk. We call these the "data" portions. The rest of the -# mkerrcodes2.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkstrtable.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkerrcodes2.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkerrcodes2.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script outputs a source file that does define the following -# symbols: -# -# static const char msgstr[]; -# A string containing all messages in the list. -# -# static const int msgidx[]; -# A list of index numbers, one for each message, that points to the -# beginning of the string in msgstr. -# -# msgidxof (code); -# A macro that maps code numbers to idx numbers. If a DEFAULT MESSAGE -# is provided (see below), its index will be returned for unknown codes. -# Otherwise -1 is returned for codes that do not appear in the list. -# You can lookup the message with code CODE with: -# msgstr + msgidx[msgidxof (code)]. -# -# The input file has the following format: -# CODE1 MESSAGE1 (Code number, <tab>, message string) -# CODE2 MESSAGE2 (Code number, <tab>, message string) -# ... -# CODEn MESSAGEn (Code number, <tab>, message string) -# DEFAULT MESSAGE (<tab>, fall-back message string) -# -# Comments (starting with # and ending at the end of the line) are removed, -# as is trailing whitespace. The last line is optional; if no DEFAULT -# MESSAGE is given, msgidxof will return the number -1 for unknown -# index numbers. - -BEGIN { -# msg holds the number of messages. - msg = 0; - print "/* Output of mkerrcodes2.awk. DO NOT EDIT. */"; - print ""; - header = 1; -} - -/^#/ { next; } - -header { - if ($1 ~ /^[0123456789]+$/) - { - print "static const int err_code_from_index[] = {"; - header = 0; - } - else - print; -} - -!header { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - -# Print the string msgstr line by line. We delay output by one line to be able -# to treat the last line differently (see END). - print " " $2 ","; - -# Remember the error value and index of each error code. - code[msg] = $1; - pos[msg] = $2; - msg++; -} -END { - print "};"; - print ""; - print "#define errno_to_idx(code) (0 ? -1 \\"; - -# Gather the ranges. - skip = code[0]; - start = code[0]; - stop = code[0]; - for (i = 1; i < msg; i++) - { - if (code[i] == stop + 1) - stop++; - else - { - print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \ - skip ") \\"; - skip += code[i] - stop - 1; - start = code[i]; - stop = code[i]; - } - } - print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \ - skip ") \\"; - print " : -1)"; -} diff --git a/plugins/MirOTR/Libgpg-error/mkerrnos.awk b/plugins/MirOTR/Libgpg-error/mkerrnos.awk deleted file mode 100644 index f79df6613a..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkerrnos.awk +++ /dev/null @@ -1,104 +0,0 @@ -# mkerrnos.awk -# Copyright (C) 2003, 2004 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkerrnos.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkerrnos.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkerrnos.awk program. -# -# Certain portions of the mkerrnos.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkerrnos.awk. We call these the "data" portions. The rest of the -# mkerrnos.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkerrnos.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkerrnos.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkerrnos.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script outputs a source file that does define the following -# symbols: -# -# static const int err_code_to_errno[]; -# A mapping of gpg_err_code_t numbers to system errno. The index of an -# error code in the table can be obtained after removing the system error -# code indication bit. -# -# The input file is a list of possible system errors in the column errnoidx -# (defaults to 2). -# -# Comments (starting with # and ending at the end of the line) are removed, -# as is trailing whitespace. - -BEGIN { - FS="[\t]+"; - header = 1; - if (errnoidx == 0) - errnoidx = 2; - - print "/* Output of mkerrnos.awk. DO NOT EDIT. */"; - print ""; -} - -/^#/ { next; } - -header { - if ($1 ~ /^[0-9]/) - { - print "#include <errno.h>"; - print "#ifdef _WIN32"; - print "#include <winsock2.h>"; - print "#endif"; - print ""; - print "static const int err_code_to_errno [] = {"; - header = 0; - } - else - print; -} - -!header { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - print "#ifdef " $errnoidx; - print " " $errnoidx ","; - print "#else"; - print "#ifdef WSA" $errnoidx; - print " WSA" $errnoidx ","; - print "#else"; - print " 0,"; - print "#endif"; - print "#endif"; -} -END { - print "};"; -} diff --git a/plugins/MirOTR/Libgpg-error/mkheader.awk b/plugins/MirOTR/Libgpg-error/mkheader.awk deleted file mode 100644 index 0ff08f98eb..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkheader.awk +++ /dev/null @@ -1,218 +0,0 @@ -# mkheader.awk -# Copyright (C) 2003, 2004 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkheader.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkheader.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkheader.awk program. -# -# Certain portions of the mkheader.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkheader.awk. We call these the "data" portions. The rest of the -# mkheader.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkheader.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkheader.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkheader.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script processes gpg-error.h.in in an awful way. -# Its input is, one after another, the content of the err-sources.h.in file, -# the err-codes.h.in file, the errnos.in file, and then gpg-error.h.in. -# There is nothing fancy about this. -# -# An alternative would be to use getline to get the content of the first three files, -# but then we need to pre-process gpg-error.h.in with configure to get -# at the full path of the files in @srcdir@. - -BEGIN { - FS = "[\t]+"; -# sources_nr holds the number of error sources. - sources_nr = 0; -# codes_nr holds the number of error codes. - codes_nr = 0; -# errnos_nr holds the number of system errors. - errnos_nr = 0; -# extra_nr holds the number of extra lines to be included. - extra_nr = 0 - -# These variables walk us through our input. - sources_header = 1; - sources_body = 0; - between_sources_and_codes = 0; - codes_body = 0; - between_codes_and_errnos = 0; - errnos_body = 0; - extra_body = 0; - gpg_error_h = 0; - - print "/* Output of mkheader.awk. DO NOT EDIT. -*- buffer-read-only: t -*- */"; - print ""; - -} - - -sources_header { - if ($1 ~ /^[0123456789]+$/) - { - sources_header = 0; - sources_body = 1; - } -} - -sources_body { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - if ($1 == "") - { - sources_body = 0; - between_sources_and_codes = 1; - } - else - { -# Remember the error source number and symbol of each error source. - sources_idx[sources_nr] = $1; - sources_sym[sources_nr] = $2; - sources_nr++; - } -} - -between_sources_and_codes { - if ($1 ~ /^[0123456789]+$/) - { - between_sources_and_codes = 0; - codes_body = 1; - } -} - -codes_body { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - if ($1 == "") - { - codes_body = 0; - between_codes_and_errnos = 1; - } - else - { -# Remember the error code number and symbol of each error source. - codes_idx[codes_nr] = $1; - codes_sym[codes_nr] = $2; - codes_nr++; - } -} - -between_codes_and_errnos { - if ($1 ~ /^[0-9]/) - { - between_codes_and_errnos = 0; - errnos_body = 1; - } -} - -errnos_body { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - - if ($1 !~ /^[0-9]/) - { -# Note that this assumes that extra_body.in doesn't start with a digit. - errnos_body = 0; - extra_body = 1; - } - else - { - errnos_idx[errnos_nr] = "GPG_ERR_SYSTEM_ERROR | " $1; - errnos_sym[errnos_nr] = "GPG_ERR_" $2; - errnos_nr++; - } -} - -extra_body { - if (/^##/) - next - - if (/^EOF/) - { - extra_body = 0; - gpg_error_h = 1; - next; - } - else - { - extra_line[extra_nr] = $0; - extra_nr++; - } -} - -gpg_error_h { - if ($0 ~ /^@include err-sources/) - { - for (i = 0; i < sources_nr; i++) - { - print " " sources_sym[i] " = " sources_idx[i] ","; -# print "#define " sources_sym[i] " (" sources_idx[i] ")"; - } - } - else if ($0 ~ /^@include err-codes/) - { - for (i = 0; i < codes_nr; i++) - { - print " " codes_sym[i] " = " codes_idx[i] ","; -# print "#define " codes_sym[i] " (" codes_idx[i] ")"; - } - } - else if ($0 ~ /^@include errnos/) - { - for (i = 0; i < errnos_nr; i++) - { - print " " errnos_sym[i] " = " errnos_idx[i] ","; -# print "#define " errnos_sym[i] " (" errnos_idx[i] ")"; - } - } - else if ($0 ~ /^@include extra-h.in/) - { - for (i = 0; i < extra_nr; i++) - { - print extra_line[i]; - } - } - else - print; -} diff --git a/plugins/MirOTR/Libgpg-error/mkheader.c b/plugins/MirOTR/Libgpg-error/mkheader.c new file mode 100644 index 0000000000..9fe0695c7a --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/mkheader.c @@ -0,0 +1,597 @@ +/* mkheader.c - Create a header file for libgpg-error + * Copyright (C) 2010 Free Software Foundation, Inc. + * Copyright (C) 2014 g10 Code GmbH + * + * This file is free software; as a special exception the author gives + * unlimited permission to copy and/or distribute it, with or without + * modifications, as long as this notice is preserved. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> + +#define PGM "mkheader" + +#define LINESIZE 1024 + +static const char *host_os; +static const char *host_triplet; +static char *srcdir; +static const char *hdr_version; +static const char *hdr_version_number; + +/* Values take from the supplied config.h. */ +static int have_stdint_h; +static int have_w32_system; +static int have_w64_system; +static char *replacement_for_off_type; + +/* Various state flags. */ +static int stdint_h_included; + + +/* The usual free wrapper. */ +static void +xfree (void *a) +{ + if (a) + free (a); +} + + +static char * +xstrdup (const char *string) +{ + char *p; + + p = malloc (strlen (string)+1); + if (!p) + { + fputs (PGM ": out of core\n", stderr); + exit (1); + } + strcpy (p, string); + return p; +} + + +/* Parse the supplied config.h file and extract required info. + Returns 0 on success. */ +static int +parse_config_h (const char *fname) +{ + FILE *fp; + char line[LINESIZE]; + int lnr = 0; + char *p1; + + fp = fopen (fname, "r"); + if (!fp) + { + fprintf (stderr, "%s:%d: can't open file: %s", + fname, lnr, strerror (errno)); + return 1; + } + + while (fgets (line, LINESIZE, fp)) + { + size_t n = strlen (line); + + lnr++; + if (!n || line[n-1] != '\n') + { + fprintf (stderr, + "%s:%d: trailing linefeed missing, line too long or " + "embedded nul character\n", fname, lnr); + break; + } + line[--n] = 0; + + if (strncmp (line, "#define ", 8)) + continue; /* We are only interested in define lines. */ + p1 = strtok (line + 8, " \t"); + if (!*p1) + continue; /* oops */ + if (!strcmp (p1, "HAVE_STDINT_H")) + have_stdint_h = 1; + else if (!strcmp (p1, "HAVE_W32_SYSTEM")) + have_w32_system = 1; + else if (!strcmp (p1, "HAVE_W64_SYSTEM")) + have_w64_system = 1; + else if (!strcmp (p1, "REPLACEMENT_FOR_OFF_T")) + { + p1 = strtok (NULL, "\""); + if (!*p1) + continue; /* oops */ + xfree (replacement_for_off_type); + replacement_for_off_type = xstrdup (p1); + } + } + + if (ferror (fp)) + { + fprintf (stderr, "%s:%d: error reading file: %s\n", + fname, lnr, strerror (errno)); + return 1; + } + + fclose (fp); + return 0; +} + + +/* Write LINE to stdout. The function is allowed to modify LINE. */ +static void +write_str (char *line) +{ + if (fputs (line, stdout) == EOF) + { + fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno)); + exit (1); + } +} + +static void +write_line (char *line) +{ + if (puts (line) == EOF) + { + fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno)); + exit (1); + } +} + + +/* Write SOURCE or CODES line to stdout. The function is allowed to + modify LINE. Trailing white space is already removed. Passing + NULL resets the internal state. */ +static void +write_sources_or_codes (char *line) +{ + static int in_intro; + char *p1, *p2; + + if (!line) + { + in_intro = 1; + return; + } + + if (!*line) + return; + + if (in_intro) + { + if (!strchr ("0123456789", *line)) + return; + in_intro = 0; + } + + p1 = strtok (line, " \t"); + p2 = p1? strtok (NULL, " \t") : NULL; + + if (p1 && p2 && strchr ("0123456789", *p1) && *p2) + { + write_str (" "); + write_str (p2); + write_str (" = "); + write_str (p1); + write_str (",\n"); + } +} + + +/* Write system errnos to stdout. The function is allowed to + modify LINE. Trailing white space is already removed. Passing + NULL resets the internal state. */ +static void +write_errnos_in (char *line) +{ + static int state; + char *p1, *p2; + + if (!line) + { + state = 0; + return; + } + + if (!*line) + return; + + if (!state && strchr ("0123456789", *line)) + state = 1; + else if (state == 1 && !strchr ("0123456789", *line)) + state = 2; + + if (state != 1) + return; + + p1 = strtok (line, " \t"); + p2 = p1? strtok (NULL, " \t") : NULL; + + if (p1 && p2 && strchr ("0123456789", *p1) && *p2) + { + write_str (" GPG_ERR_"); + write_str (p2); + write_str (" = GPG_ERR_SYSTEM_ERROR | "); + write_str (p1); + write_str (",\n"); + } +} + + +/* Create the full file name for NAME and return a newly allocated + string with it. If name contains a '&' and REPL is not NULL + replace '&' with REPL. */ +static char * +mk_include_name (const char *name, const char *repl) +{ + FILE *fp; + char *incfname, *p; + const char *s; + + incfname = malloc (strlen (srcdir) + strlen (name) + + (repl?strlen (repl):0) + 1); + if (!incfname) + { + fputs (PGM ": out of core\n", stderr); + exit (1); + } + + if (*name == '.' && name[1] == '/') + *incfname = 0; + else + strcpy (incfname, srcdir); + p = incfname + strlen (incfname); + for (s=name; *s; s++) + { + if (*s == '&' && repl) + { + while (*repl) + *p++ = *repl++; + repl = NULL; /* Replace only once. */ + } + else + *p++ = *s; + } + *p = 0; + return incfname; +} + + +/* Include the file NAME from the source directory. The included file + is not further expanded. It may have comments indicated by a + double hash mark at the begin of a line. OUTF is called for each + read line and passed a buffer with the content of line sans line + line endings. If NAME is prefixed with "./" it is included from + the current directory and not from the source directory. */ +static void +include_file (const char *fname, int lnr, const char *name, void (*outf)(char*)) +{ + FILE *fp; + char *incfname; + int inclnr; + char line[LINESIZE]; + int repl_flag; + + repl_flag = !!strchr (name, '&'); + incfname = mk_include_name (name, repl_flag? host_triplet : NULL); + fp = fopen (incfname, "r"); + if (!fp && repl_flag) + { + /* Try again using the OS string. */ + free (incfname); + incfname = mk_include_name (name, host_os); + fp = fopen (incfname, "r"); + } + if (!fp) + { + fprintf (stderr, "%s:%d: error including `%s': %s\n", + fname, lnr, incfname, strerror (errno)); + exit (1); + } + + if (repl_flag) + fprintf (stderr,"%s:%d: note: including '%s'\n", + fname, lnr, incfname); + + inclnr = 0; + while (fgets (line, LINESIZE, fp)) + { + size_t n = strlen (line); + + inclnr++; + if (!n || line[n-1] != '\n') + { + fprintf (stderr, + "%s:%d: trailing linefeed missing, line too long or " + "embedded nul character\n", incfname, inclnr); + fprintf (stderr,"%s:%d: note: file '%s' included from here\n", + fname, lnr, incfname); + exit (1); + } + line[--n] = 0; + while (line[n] == ' ' || line[n] == '\t' || line[n] == '\r') + { + line[n] = 0; + if (!n) + break; + n--; + } + + if (line[0] == '#' && line[1] == '#') + { + if (!strncmp (line+2, "EOF##", 5)) + break; /* Forced EOF. */ + } + else + outf (line); + } + if (ferror (fp)) + { + fprintf (stderr, "%s:%d: error reading `%s': %s\n", + fname, lnr, incfname, strerror (errno)); + exit (1); + } + fclose (fp); + free (incfname); +} + + +/* Try to include the file NAME. Returns true if it does not + exist. */ +static int +try_include_file (const char *fname, int lnr, const char *name, + void (*outf)(char*)) +{ + int rc; + char *incfname; + int repl_flag; + + repl_flag = !!strchr (name, '&'); + incfname = mk_include_name (name, repl_flag? host_triplet : NULL); + rc = access (incfname, R_OK); + if (rc && repl_flag) + { + free (incfname); + incfname = mk_include_name (name, host_os); + rc = access (incfname, R_OK); + } + if (!rc) + include_file (fname, lnr, name, outf); + + free (incfname); + return rc; +} + + +static int +write_special (const char *fname, int lnr, const char *tag) +{ + if (!strcmp (tag, "version")) + { + putchar ('\"'); + fputs (hdr_version, stdout); + putchar ('\"'); + } + else if (!strcmp (tag, "version-number")) + { + fputs (hdr_version_number, stdout); + } + else if (!strcmp (tag, "define:gpgrt_off_t")) + { + if (!replacement_for_off_type) + { + fprintf (stderr, "%s:%d: replacement for off_t not defined\n", + fname, lnr); + exit (1); + } + else + { + if (!strcmp (replacement_for_off_type, "int64_t") + && !stdint_h_included && have_stdint_h) + { + fputs ("#include <stdint.h>\n\n", stdout); + stdint_h_included = 1; + } + printf ("typedef %s gpgrt_off_t;\n", replacement_for_off_type); + } + } + else if (!strcmp (tag, "define:gpgrt_ssize_t")) + { + if (have_w64_system) + { + if (!stdint_h_included && have_stdint_h) + { + fputs ("# include <stdint.h>\n", stdout); + stdint_h_included = 1; + } + fputs ("typedef int64_t gpgrt_ssize_t;\n", stdout); + } + else if (have_w32_system) + { + fputs ("typedef long gpgrt_ssize_t;\n", stdout); + } + else + { + fputs ("#include <sys/types.h>\n" + "typedef ssize_t gpgrt_ssize_t;\n", stdout); + } + } + else if (!strcmp (tag, "api_ssize_t")) + { + if (have_w32_system) + fputs ("gpgrt_ssize_t", stdout); + else + fputs ("ssize_t", stdout); + } + else if (!strcmp (tag, "include:err-sources")) + { + write_sources_or_codes (NULL); + include_file (fname, lnr, "err-sources.h.in", write_sources_or_codes); + } + else if (!strcmp (tag, "include:err-codes")) + { + write_sources_or_codes (NULL); + include_file (fname, lnr, "err-codes.h.in", write_sources_or_codes); + } + else if (!strcmp (tag, "include:errnos")) + { + include_file (fname, lnr, "errnos.in", write_errnos_in); + } + else if (!strcmp (tag, "include:os-add")) + { + if (!strcmp (host_os, "mingw32")) + { + include_file (fname, lnr, "w32-add.h", write_line); + } + else if (!strcmp (host_os, "mingw32ce")) + { + include_file (fname, lnr, "w32-add.h", write_line); + include_file (fname, lnr, "w32ce-add.h", write_line); + } + } + else if (!strcmp (tag, "include:lock-obj")) + { + if (try_include_file (fname, lnr, "./lock-obj-pub.native.h", write_line)) + include_file (fname, lnr, "syscfg/lock-obj-pub.&.h", write_line); + } + else + return 0; /* Unknown tag. */ + + return 1; /* Tag processed. */ +} + + +int +main (int argc, char **argv) +{ + FILE *fp; + char line[LINESIZE]; + int lnr = 0; + const char *fname, *s; + char *p1, *p2; + const char *config_h; + + if (argc) + { + argc--; argv++; + } + + if (argc != 6) + { + fputs ("usage: " PGM + " host_os host_triplet template.h config.h" + " version version_number\n", + stderr); + return 1; + } + host_os = argv[0]; + host_triplet = argv[1]; + fname = argv[2]; + config_h = argv[3]; + hdr_version = argv[4]; + hdr_version_number = argv[5]; + + srcdir = malloc (strlen (fname) + 2 + 1); + if (!srcdir) + { + fputs (PGM ": out of core\n", stderr); + return 1; + } + strcpy (srcdir, fname); + p1 = strrchr (srcdir, '/'); + if (p1) + p1[1] = 0; + else + strcpy (srcdir, "./"); + + if (parse_config_h (config_h)) + return 1; + + fp = fopen (fname, "r"); + if (!fp) + { + fprintf (stderr, "%s:%d: can't open file: %s", + fname, lnr, strerror (errno)); + return 1; + } + + while (fgets (line, LINESIZE, fp)) + { + size_t n = strlen (line); + + lnr++; + if (!n || line[n-1] != '\n') + { + fprintf (stderr, + "%s:%d: trailing linefeed missing, line too long or " + "embedded nul character\n", fname, lnr); + break; + } + line[--n] = 0; + + p1 = strchr (line, '@'); + p2 = p1? strchr (p1+1, '@') : NULL; + if (!p1 || !p2 || p2-p1 == 1) + { + puts (line); + continue; + } + *p1++ = 0; + *p2++ = 0; + fputs (line, stdout); + + if (!strcmp (p1, "configure_input")) + { + s = strrchr (fname, '/'); + printf ("Do not edit. Generated from %s for %s.", + s? s+1 : fname, host_triplet); + fputs (p2, stdout); + } + else if (!write_special (fname, lnr, p1)) + { + putchar ('@'); + fputs (p1, stdout); + putchar ('@'); + fputs (p2, stdout); + } + else if (p2 && *p2) + { + fputs (p2, stdout); + } + putchar ('\n'); + } + + if (ferror (fp)) + { + fprintf (stderr, "%s:%d: error reading file: %s\n", + fname, lnr, strerror (errno)); + return 1; + } + + fputs ("/*\n" + "Loc" "al Variables:\n" + "buffer-read-only: t\n" + "End:\n" + "*/\n", stdout); + + if (ferror (stdout)) + { + fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno)); + return 1; + } + + fclose (fp); + + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/mkstrtable.awk b/plugins/MirOTR/Libgpg-error/mkstrtable.awk deleted file mode 100644 index d97e150489..0000000000 --- a/plugins/MirOTR/Libgpg-error/mkstrtable.awk +++ /dev/null @@ -1,189 +0,0 @@ -# mkstrtable.awk -# Copyright (C) 2003, 2004, 2008 g10 Code GmbH -# -# This program 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. -# -# This program 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. -# -# As a special exception, g10 Code GmbH gives unlimited permission to -# copy, distribute and modify the C source files that are the output -# of mkstrtable.awk. You need not follow the terms of the GNU General -# Public License when using or distributing such scripts, even though -# portions of the text of mkstrtable.awk appear in them. The GNU -# General Public License (GPL) does govern all other use of the material -# that constitutes the mkstrtable.awk program. -# -# Certain portions of the mkstrtable.awk source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# mkstrtable.awk. We call these the "data" portions. The rest of the -# mkstrtable.awk source text consists of comments plus executable code -# that decides which of the data portions to output in any given case. -# We call these comments and executable code the "non-data" portions. -# mkstrtable.h never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of mkstrtable.awk -# released by g10 Code GmbH. When you make and distribute a modified version -# of mkstrtable.awk, you may extend this special exception to the GPL to -# apply to your modified version as well, *unless* your modified version -# has the potential to copy into its output some of the text that was the -# non-data portion of the version that you started with. (In other words, -# unless your change moves or copies text from the non-data portions to the -# data portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified version. - -# This script outputs a source file that does define the following -# symbols: -# -# static const char msgstr[]; -# A string containing all messages in the list. -# -# static const int msgidx[]; -# A list of index numbers, one for each message, that points to the -# beginning of the string in msgstr. -# -# msgidxof (code); -# A macro that maps code numbers to idx numbers. If a DEFAULT MESSAGE -# is provided (see below), its index will be returned for unknown codes. -# Otherwise -1 is returned for codes that do not appear in the list. -# You can lookup the message with code CODE with: -# msgstr + msgidx[msgidxof (code)]. -# -# The input file has the following format: -# CODE1 ... MESSAGE1 (code nr, <tab>, something, <tab>, msg) -# CODE2 ... MESSAGE2 (code nr, <tab>, something, <tab>, msg) -# ... -# CODEn ... MESSAGEn (code nr, <tab>, something, <tab>, msg) -# ... DEFAULT-MESSAGE (<tab>, something, <tab>, fall-back msg) -# -# Comments (starting with # and ending at the end of the line) are removed, -# as is trailing whitespace. The last line is optional; if no DEFAULT -# MESSAGE is given, msgidxof will return the number -1 for unknown -# index numbers. -# -# The field to be used is specified with the variable "textidx" on -# the command line. It defaults to 2. -# -# The variable nogettext can be set to 1 to suppress gettext markers. -# -# The variable prefix can be used to prepend a string to each message. -# -# The variable namespace can be used to prepend a string to each -# variable and macro name. - -BEGIN { - FS = "[\t]+"; -# cpos holds the current position in the message string. - cpos = 0; -# msg holds the number of messages. - msg = 0; - print "/* Output of mkstrtable.awk. DO NOT EDIT. */"; - print ""; - header = 1; - if (textidx == 0) - textidx = 2; -# nogettext can be set to 1 to suppress gettext noop markers. -} - -/^#/ { next; } - -header { - if ($1 ~ /^[0123456789]+$/) - { - print "/* The purpose of this complex string table is to produce"; - print " optimal code with a minimum of relocations. */"; - print ""; - print "static const char " namespace "msgstr[] = "; - header = 0; - } - else - print; -} - -!header { - sub (/\#.+/, ""); - sub (/[ ]+$/, ""); # Strip trailing space and tab characters. - - if (/^$/) - next; - -# Print the string msgstr line by line. We delay output by one line to be able -# to treat the last line differently (see END). - if (last_msgstr) - { - if (nogettext) - print " \"" last_msgstr "\" \"\\0\""; - else - print " gettext_noop (\"" last_msgstr "\") \"\\0\""; - } - last_msgstr = prefix $textidx; - -# Remember the error code and msgidx of each error message. - code[msg] = $1; - pos[msg] = cpos; - cpos += length (last_msgstr) + 1; - msg++; - - if ($1 == "") - { - has_default = 1; - exit; - } -} -END { - if (has_default) - coded_msgs = msg - 1; - else - coded_msgs = msg; - - if (nogettext) - print " \"" last_msgstr "\";"; - else - print " gettext_noop (\"" last_msgstr "\");"; - print ""; - print "static const int " namespace "msgidx[] ="; - print " {"; - for (i = 0; i < coded_msgs; i++) - print " " pos[i] ","; - print " " pos[coded_msgs]; - print " };"; - print ""; - print "static inline int"; - print namespace "msgidxof (int code)"; - print "{"; - print " return (0 ? 0"; - -# Gather the ranges. - skip = code[0]; - start = code[0]; - stop = code[0]; - for (i = 1; i < coded_msgs; i++) - { - if (code[i] == stop + 1) - stop++; - else - { - print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \ - skip ")"; - skip += code[i] - stop - 1; - start = code[i]; - stop = code[i]; - } - } - print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \ - skip ")"; - if (has_default) - print " : " stop + 1 " - " skip ");"; - else - print " : -1);"; - print "}"; -} diff --git a/plugins/MirOTR/Libgpg-error/posix-lock-obj.h b/plugins/MirOTR/Libgpg-error/posix-lock-obj.h new file mode 100644 index 0000000000..7714d3ccc2 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/posix-lock-obj.h @@ -0,0 +1,35 @@ +/* posic-lock-obj.h - Declaration of the POSIX lock object + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef POSIX_LOCK_OBJ_H +#define POSIX_LOCK_OBJ_H + +#define LOCK_ABI_VERSION 1 + +typedef struct +{ + long vers; + union { + pthread_mutex_t mtx; + long *dummy; + } u; +} _gpgrt_lock_t; + + +#endif /*POSIX_LOCK_OBJ_H*/ diff --git a/plugins/MirOTR/Libgpg-error/posix-lock.c b/plugins/MirOTR/Libgpg-error/posix-lock.c new file mode 100644 index 0000000000..7f20347250 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/posix-lock.c @@ -0,0 +1,249 @@ +/* posix-lock.c - GPGRT lock functions for POSIX systems + Copyright (C) 2005-2009 Free Software Foundation, Inc. + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + + Parts of the code, in particular use_pthreads_p, are based on code + from gettext, written by Bruno Haible <bruno@clisp.org>, 2005. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_W32_SYSTEM +# error This module may not be build for Windows. +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#if USE_POSIX_THREADS +# include <pthread.h> +#endif + +#include "gpg-error.h" +#include "lock.h" +#include "posix-lock-obj.h" + + +#if USE_POSIX_THREADS +# if USE_POSIX_THREADS_WEAK + /* On ELF systems it is easy to use pthreads using weak + references. Take care not to test the address of a weak + referenced function we actually use; some GCC versions have a + bug were &foo != NULL is always evaluated to true in PIC mode. */ +# pragma weak pthread_cancel +# pragma weak pthread_mutex_init +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_trylock +# pragma weak pthread_mutex_unlock +# pragma weak pthread_mutex_destroy +# if ! PTHREAD_IN_USE_DETECTION_HARD +# define use_pthread_p() (!!pthread_cancel) +# endif +# else /*!USE_POSIX_THREADS_WEAK*/ +# if ! PTHREAD_IN_USE_DETECTION_HARD +# define use_pthread_p() (1) +# endif +# endif /*!USE_POSIX_THREADS_WEAK*/ +# if PTHREAD_IN_USE_DETECTION_HARD +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +static int +use_pthread_p (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL)) + result = 0; /* Thread creation failed. */ + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} +#endif /*PTHREAD_IN_USE_DETECTION_HARD*/ +#endif /*USE_POSIX_THREADS*/ + + + +static _gpgrt_lock_t * +get_lock_object (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd; + + if (lock->vers != LOCK_ABI_VERSION) + abort (); + if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t)) + abort (); + + return lock; +} + + +gpg_err_code_t +_gpgrt_lock_init (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd; + int rc; + + /* If VERS is zero we assume that no static initialization has been + done, so we setup our ABI version right here. The caller might + have called us to test whether lock support is at all available. */ + if (!lock->vers) + { + if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t)) + abort (); + lock->vers = LOCK_ABI_VERSION; + } + else /* Run the usual check. */ + lock = get_lock_object (lockhd); + +#if USE_POSIX_THREADS + if (use_pthread_p()) + { + rc = pthread_mutex_init (&lock->u.mtx, NULL); + if (rc) + rc = gpg_err_code_from_errno (rc); + } + else + rc = 0; /* Threads are not used. */ +#else /* Unknown thread system. */ + rc = GPG_ERR_NOT_IMPLEMENTED; +#endif /* Unknown thread system. */ + + return rc; +} + + +gpg_err_code_t +_gpgrt_lock_lock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + int rc; + +#if USE_POSIX_THREADS + if (use_pthread_p()) + { + rc = pthread_mutex_lock (&lock->u.mtx); + if (rc) + rc = gpg_err_code_from_errno (rc); + } + else + rc = 0; /* Threads are not used. */ +#else /* Unknown thread system. */ + rc = GPG_ERR_NOT_IMPLEMENTED; +#endif /* Unknown thread system. */ + + return rc; +} + + +gpg_err_code_t +_gpgrt_lock_trylock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + int rc; + +#if USE_POSIX_THREADS + if (use_pthread_p()) + { + rc = pthread_mutex_trylock (&lock->u.mtx); + if (rc) + rc = gpg_err_code_from_errno (rc); + } + else + rc = 0; /* Threads are not used. */ +#else /* Unknown thread system. */ + rc = GPG_ERR_NOT_IMPLEMENTED; +#endif /* Unknown thread system. */ + + return rc; +} + + +gpg_err_code_t +_gpgrt_lock_unlock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + int rc; + +#if USE_POSIX_THREADS + if (use_pthread_p()) + { + rc = pthread_mutex_unlock (&lock->u.mtx); + if (rc) + rc = gpg_err_code_from_errno (rc); + } + else + rc = 0; /* Threads are not used. */ +#else /* Unknown thread system. */ + rc = GPG_ERR_NOT_IMPLEMENTED; +#endif /* Unknown thread system. */ + + return rc; +} + + +/* Note: Use this function only if no other thread holds or waits for + this lock. */ +gpg_err_code_t +_gpgrt_lock_destroy (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + int rc; + +#if USE_POSIX_THREADS + if (use_pthread_p()) + { + rc = pthread_mutex_destroy (&lock->u.mtx); + if (rc) + rc = gpg_err_code_from_errno (rc); + else + { + /* Re-init the mutex so that it can be re-used. */ + gpgrt_lock_t tmp = GPGRT_LOCK_INITIALIZER; + memcpy (lockhd, &tmp, sizeof tmp); + } + } + else + rc = 0; /* Threads are not used. */ +#else /* Unknown thread system. */ + rc = GPG_ERR_NOT_IMPLEMENTED; +#endif /* Unknown thread system. */ + + return rc; +} diff --git a/plugins/MirOTR/Libgpg-error/posix-thread.c b/plugins/MirOTR/Libgpg-error/posix-thread.c new file mode 100644 index 0000000000..bef0386295 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/posix-thread.c @@ -0,0 +1,63 @@ +/* posix-thread.c - GPGRT thread functions for POSIX systems + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_W32_SYSTEM +# error This module may not be build for Windows. +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> /* Get posix option macros. */ + +#if USE_POSIX_THREADS +# ifdef _POSIX_PRIORITY_SCHEDULING +# include <sched.h> +# endif +#elif USE_SOLARIS_THREADS +# include <thread.h> +#endif + +#include "gpg-error.h" + +#include "thread.h" + + +gpg_err_code_t +_gpgrt_yield (void) +{ +#if USE_POSIX_THREADS +# ifdef _POSIX_PRIORITY_SCHEDULING + sched_yield (); +# else + return GPG_ERR_NOT_SUPPORTED; +# endif +#elif USE_SOLARIS_THREADS + thr_yield (); +#else + return GPG_ERR_NOT_SUPPORTED; +#endif + + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/strerror.c b/plugins/MirOTR/Libgpg-error/strerror.c index dc56040262..b0efb3de4b 100644 --- a/plugins/MirOTR/Libgpg-error/strerror.c +++ b/plugins/MirOTR/Libgpg-error/strerror.c @@ -7,12 +7,12 @@ 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -35,7 +35,7 @@ /* Return a pointer to a string containing a description of the error code in the error value ERR. This function is not thread-safe. */ const char * -gpg_strerror (gpg_error_t err) +_gpg_strerror (gpg_error_t err) { gpg_err_code_t code = gpg_err_code (err); @@ -134,7 +134,7 @@ system_strerror_r (int no, char *buf, size_t buflen) large enough, ERANGE is returned and BUF contains as much of the beginning of the error string as fits into the buffer. */ int -gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen) +_gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen) { gpg_err_code_t code = gpg_err_code (err); const char *errstr; diff --git a/plugins/MirOTR/Libgpg-error/strsource.c b/plugins/MirOTR/Libgpg-error/strsource.c index 66d783c436..6604eb0a80 100644 --- a/plugins/MirOTR/Libgpg-error/strsource.c +++ b/plugins/MirOTR/Libgpg-error/strsource.c @@ -2,17 +2,17 @@ Copyright (C) 2003 g10 Code GmbH This file is part of libgpg-error. - + libgpg-error 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. - + libgpg-error 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 libgpg-error; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -30,7 +30,7 @@ /* Return a pointer to a string containing a description of the error source in the error value ERR. */ const char * -gpg_strsource (gpg_error_t err) +_gpg_strsource (gpg_error_t err) { gpg_err_source_t source = gpg_err_source (err); return dgettext (PACKAGE, msgstr + msgidx[msgidxof (source)]); diff --git a/plugins/MirOTR/Libgpg-error/thread.h b/plugins/MirOTR/Libgpg-error/thread.h new file mode 100644 index 0000000000..0b2cf0414f --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/thread.h @@ -0,0 +1,24 @@ +/* thread.h - Declarations for *-thread.c + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef THREAD_H +#define THREAD_H + + +#endif /*THREAD_H*/ diff --git a/plugins/MirOTR/Libgpg-error/version.c b/plugins/MirOTR/Libgpg-error/version.c new file mode 100644 index 0000000000..216fee4e5c --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/version.c @@ -0,0 +1,121 @@ +/* version.c - Version checking + * Copyright (C) 2001, 2002, 2012, 2013, 2014 g10 Code GmbH + * + * This file is part of libgpg-error. + * + * libgpg-error 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. + * + * libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <gpg-error.h> + + +#define digitp(a) ((a) >= '0' && (a) <= '9') + + +/* This is actually a dummy function to make sure that is module is + not empty. Some compilers barf on empty modules. */ +static const char * +cright_blurb (void) +{ + static const char blurb[] = + "\n\n" + "This is Libgpg-error " PACKAGE_VERSION " - An error code library\n" + "Copyright 2003, 2004, 2010, 2013, 2014, 2015 g10 Code GmbH\n" + "\n" + "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n" + "\n\n"; + return blurb; +} + + +static const char* +parse_version_number (const char *s, int *number) +{ + int val = 0; + + if (*s == '0' && digitp (s[1])) + return NULL; /* Leading zeros are not allowed. */ + for (; digitp (*s); s++) + { + val *= 10; + val += *s - '0'; + } + *number = val; + return val < 0 ? NULL : s; +} + + +static const char * +parse_version_string (const char *s, int *major, int *minor) +{ + s = parse_version_number (s, major); + if (!s || *s != '.') + return NULL; + s++; + s = parse_version_number (s, minor); + if (!s) + return NULL; + return s; /* Patchlevel. */ +} + + +static const char * +compare_versions (const char *my_version, const char *req_version) +{ + int my_major, my_minor; + int rq_major, rq_minor; + const char *my_plvl, *rq_plvl; + + if (!req_version) + return my_version; + if (!my_version) + return NULL; + + my_plvl = parse_version_string (my_version, &my_major, &my_minor); + if (!my_plvl) + return NULL; /* Very strange: our own version is bogus. */ + rq_plvl = parse_version_string(req_version, &rq_major, &rq_minor); + if (!rq_plvl) + return NULL; /* Requested version string is invalid. */ + + if (my_major > rq_major + || (my_major == rq_major && my_minor >= rq_minor)) + { + return my_version; + } + return NULL; +} + + +/* + * Check that the the version of the library is at minimum REQ_VERSION + * and return the actual version string; return NULL if the condition + * is not met. If NULL is passed to this function, no check is done + * and the version string is simply returned. + */ +const char * +_gpg_error_check_version (const char *req_version) +{ + if (req_version && req_version[0] == 1 && req_version[1] == 1) + return cright_blurb (); + return compare_versions (PACKAGE_VERSION, req_version); +} diff --git a/plugins/MirOTR/Libgpg-error/versioninfo.rc b/plugins/MirOTR/Libgpg-error/versioninfo.rc index 5a3b96bca1..214accd298 100644 --- a/plugins/MirOTR/Libgpg-error/versioninfo.rc +++ b/plugins/MirOTR/Libgpg-error/versioninfo.rc @@ -1,6 +1,6 @@ /* versioninfo.rc.in - for libgpg-error * Copyright (C) 2005 g10 Code GmbH - * + * * This file is free software; as a special exception the author gives * unlimited permission to copy and/or distribute it, with or without * modifications, as long as this notice is preserved. @@ -9,7 +9,7 @@ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ - + /* This file is processed by configure to create versioninfo.rc */ #line __LINE__ "versioninfo.rc.in" @@ -18,8 +18,8 @@ VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,9,0,2 - PRODUCTVERSION 1,9,0,2 + FILEVERSION 1,18,0,63382 + PRODUCTVERSION 1,18,0,63382 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x21L @@ -37,15 +37,15 @@ BEGIN VALUE "Comments", "Provided under the terms of the GNU Lesser General Public License.\0" VALUE "CompanyName", "g10 Code GmbH\0" VALUE "FileDescription", "libgpg-error - Common error codes\0" - VALUE "FileVersion", "1.9\0" + VALUE "FileVersion", "14.14.0.f796885\0" VALUE "InternalName", "libgpg-error\0" - VALUE "LegalCopyright", "Copyright © 2005 g10 Code GmbH\0" + VALUE "LegalCopyright", "Copyright © 2013 g10 Code GmbH\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "libgpg-error.dll\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "libgpg-error\0" - VALUE "ProductVersion", "1.9\0" - VALUE "SpecialBuild", "2010-08-12T17:56+0000\0" + VALUE "ProductVersion", "1.18\0" + VALUE "SpecialBuild", "2015-03-20T10:27+0000\0" END END END diff --git a/plugins/MirOTR/Libgpg-error/versioninfo.rc.in b/plugins/MirOTR/Libgpg-error/versioninfo.rc.in deleted file mode 100644 index 3384adc361..0000000000 --- a/plugins/MirOTR/Libgpg-error/versioninfo.rc.in +++ /dev/null @@ -1,52 +0,0 @@ -/* versioninfo.rc.in - for libgpg-error - * Copyright (C) 2005 g10 Code GmbH - * - * This file is free software; as a special exception the author gives - * unlimited permission to copy and/or distribute it, with or without - * modifications, as long as this notice is preserved. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ - -/* This file is processed by configure to create versioninfo.rc */ - -#line __LINE__ "versioninfo.rc.in" - -#include <afxres.h> - - -VS_VERSION_INFO VERSIONINFO - FILEVERSION @BUILD_FILEVERSION@ - PRODUCTVERSION @BUILD_FILEVERSION@ - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x21L -#else - FILEFLAGS 0x20L -#endif - FILEOS 0x40004L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "Provided under the terms of the GNU Lesser General Public License.\0" - VALUE "CompanyName", "g10 Code GmbH\0" - VALUE "FileDescription", "libgpg-error - Common error codes\0" - VALUE "FileVersion", "@VERSION@\0" - VALUE "InternalName", "libgpg-error\0" - VALUE "LegalCopyright", "Copyright © 2005 g10 Code GmbH\0" - VALUE "LegalTrademarks", "\0" - VALUE "OriginalFilename", "libgpg-error.dll\0" - VALUE "PrivateBuild", "\0" - VALUE "ProductName", "libgpg-error\0" - VALUE "ProductVersion", "@VERSION@\0" - VALUE "SpecialBuild", "@BUILD_TIMESTAMP@\0" - END - END -END - diff --git a/plugins/MirOTR/Libgpg-error/visibility.c b/plugins/MirOTR/Libgpg-error/visibility.c new file mode 100644 index 0000000000..9213ce92f5 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/visibility.c @@ -0,0 +1,689 @@ +/* visibility.c - Wrapper for all public functions. + * Copyright (C) 2014 g10 Code GmbH + * + * This file is part of libgpg-error. + * + * libgpg-error 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. + * + * libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <stdarg.h> + +#define _GPGRT_INCL_BY_VISIBILITY_C 1 +#include "gpgrt-int.h" + +const char * +gpg_strerror (gpg_error_t err) +{ + return _gpg_strerror (err); +} + +int +gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen) +{ + return _gpg_strerror_r (err, buf, buflen); +} + +const char * +gpg_strsource (gpg_error_t err) +{ + return _gpg_strsource (err); +} + +gpg_err_code_t +gpg_err_code_from_errno (int err) +{ + return _gpg_err_code_from_errno (err); +} + +int +gpg_err_code_to_errno (gpg_err_code_t code) +{ + return _gpg_err_code_to_errno (code); +} + +gpg_err_code_t +gpg_err_code_from_syserror (void) +{ + return _gpg_err_code_from_syserror (); +} + +void +gpg_err_set_errno (int err) +{ + _gpg_err_set_errno (err); +} + + +gpg_error_t +gpg_err_init (void) +{ + return _gpg_err_init (); +} + +void +gpg_err_deinit (int mode) +{ + _gpg_err_deinit (mode); +} + +const char * +gpg_error_check_version (const char *req_version) +{ + return _gpg_error_check_version (req_version); +} + +const char * +gpgrt_check_version (const char *req_version) +{ + return _gpg_error_check_version (req_version); +} + +void +gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void)) +{ + _gpgrt_set_syscall_clamp (pre, post); +} + +void +gpgrt_set_alloc_func (void *(*f)(void *a, size_t n)) +{ + _gpgrt_set_alloc_func (f); +} + + +gpg_err_code_t +gpgrt_lock_init (gpgrt_lock_t *lockhd) +{ + return _gpgrt_lock_init (lockhd); +} + +gpg_err_code_t +gpgrt_lock_lock (gpgrt_lock_t *lockhd) +{ + return _gpgrt_lock_lock (lockhd); +} + +gpg_err_code_t +gpgrt_lock_trylock (gpgrt_lock_t *lockhd) +{ + return _gpgrt_lock_trylock (lockhd); +} + +gpg_err_code_t +gpgrt_lock_unlock (gpgrt_lock_t *lockhd) +{ + return _gpgrt_lock_unlock (lockhd); +} + +gpg_err_code_t +gpgrt_lock_destroy (gpgrt_lock_t *lockhd) +{ + return _gpgrt_lock_destroy (lockhd); +} + +gpg_err_code_t +gpgrt_yield (void) +{ + return _gpgrt_yield (); +} + + + +estream_t +gpgrt_fopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode) +{ + return _gpgrt_fopen (path, mode); +} + +estream_t +gpgrt_mopen (void *_GPGRT__RESTRICT data, size_t data_n, size_t data_len, + unsigned int grow, + void *(*func_realloc) (void *mem, size_t size), + void (*func_free) (void *mem), + const char *_GPGRT__RESTRICT mode) +{ + return _gpgrt_mopen (data, data_n, data_len, grow, func_realloc, func_free, + mode); +} + +estream_t +gpgrt_fopenmem (size_t memlimit, const char *_GPGRT__RESTRICT mode) +{ + return _gpgrt_fopenmem (memlimit, mode); +} + +estream_t +gpgrt_fopenmem_init (size_t memlimit, const char *_GPGRT__RESTRICT mode, + const void *data, size_t datalen) +{ + return _gpgrt_fopenmem_init (memlimit, mode, data, datalen); +} + +estream_t +gpgrt_fdopen (int filedes, const char *mode) +{ + return _gpgrt_fdopen (filedes, mode); +} + +estream_t +gpgrt_fdopen_nc (int filedes, const char *mode) +{ + return _gpgrt_fdopen_nc (filedes, mode); +} + +estream_t +gpgrt_sysopen (es_syshd_t *syshd, const char *mode) +{ + return _gpgrt_sysopen (syshd, mode); +} + +estream_t +gpgrt_sysopen_nc (es_syshd_t *syshd, const char *mode) +{ + return _gpgrt_sysopen_nc (syshd, mode); +} + +estream_t +gpgrt_fpopen (FILE *fp, const char *mode) +{ + return _gpgrt_fpopen (fp, mode); +} + +estream_t +gpgrt_fpopen_nc (FILE *fp, const char *mode) +{ + return _gpgrt_fpopen_nc (fp, mode); +} + +estream_t +gpgrt_freopen (const char *_GPGRT__RESTRICT path, + const char *_GPGRT__RESTRICT mode, + estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_freopen (path, mode, stream); +} + +estream_t +gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie, + const char *_GPGRT__RESTRICT mode, + gpgrt_cookie_io_functions_t functions) +{ + return _gpgrt_fopencookie (cookie, mode, functions); +} + +int +gpgrt_fclose (estream_t stream) +{ + return _gpgrt_fclose (stream); +} + +int +gpgrt_fclose_snatch (estream_t stream, void **r_buffer, size_t *r_buflen) +{ + return _gpgrt_fclose_snatch (stream, r_buffer, r_buflen); +} + +int +gpgrt_onclose (estream_t stream, int mode, + void (*fnc) (estream_t, void*), void *fnc_value) +{ + return _gpgrt_onclose (stream, mode, fnc, fnc_value); +} + +int +gpgrt_fileno (estream_t stream) +{ + return _gpgrt_fileno (stream); +} + +int +gpgrt_fileno_unlocked (estream_t stream) +{ + return _gpgrt_fileno_unlocked (stream); +} + +int +gpgrt_syshd (estream_t stream, es_syshd_t *syshd) +{ + return _gpgrt_syshd (stream, syshd); +} + +int +gpgrt_syshd_unlocked (estream_t stream, es_syshd_t *syshd) +{ + return _gpgrt_syshd_unlocked (stream, syshd); +} + +void +_gpgrt_set_std_fd (int no, int fd) +{ + _gpgrt__set_std_fd (no, fd); /* (double dash in name) */ +} + +estream_t +_gpgrt_get_std_stream (int fd) +{ + return _gpgrt__get_std_stream (fd); /* (double dash in name) */ +} + +void +gpgrt_flockfile (estream_t stream) +{ + _gpgrt_flockfile (stream); +} + +int +gpgrt_ftrylockfile (estream_t stream) +{ + return _gpgrt_ftrylockfile (stream); +} + +void +gpgrt_funlockfile (estream_t stream) +{ + _gpgrt_funlockfile (stream); +} + +int +_gpgrt_pending (estream_t stream) +{ + return _gpgrt__pending (stream); +} + +int +_gpgrt_pending_unlocked (estream_t stream) +{ + return _gpgrt__pending_unlocked (stream); +} + +int +gpgrt_feof (estream_t stream) +{ + return _gpgrt_feof (stream); +} + +int +gpgrt_feof_unlocked (estream_t stream) +{ + return _gpgrt_feof_unlocked (stream); +} + +int +gpgrt_ferror (estream_t stream) +{ + return _gpgrt_ferror (stream); +} + +int +gpgrt_ferror_unlocked (estream_t stream) +{ + return _gpgrt_ferror_unlocked (stream); +} + +void +gpgrt_clearerr (estream_t stream) +{ + _gpgrt_clearerr (stream); +} + +void +gpgrt_clearerr_unlocked (estream_t stream) +{ + _gpgrt_clearerr_unlocked (stream); +} + +int +gpgrt_fflush (estream_t stream) +{ + return _gpgrt_fflush (stream); +} + +int +gpgrt_fseek (estream_t stream, long int offset, int whence) +{ + return _gpgrt_fseek (stream, offset, whence); +} + +int +gpgrt_fseeko (estream_t stream, gpgrt_off_t offset, int whence) +{ + return _gpgrt_fseeko (stream, offset, whence); +} + +long int +gpgrt_ftell (estream_t stream) +{ + return _gpgrt_ftell (stream); +} + +gpgrt_off_t +gpgrt_ftello (estream_t stream) +{ + return _gpgrt_ftello (stream); +} + +void +gpgrt_rewind (estream_t stream) +{ + _gpgrt_rewind (stream); +} + +int +gpgrt_fgetc (estream_t stream) +{ + return _gpgrt_fgetc (stream); +} + +int +_gpgrt_getc_underflow (estream_t stream) +{ + return _gpgrt__getc_underflow (stream); +} + +int +gpgrt_fputc (int c, estream_t stream) +{ + return _gpgrt_fputc (c, stream); +} + +int +_gpgrt_putc_overflow (int c, estream_t stream) +{ + return _gpgrt__putc_overflow (c, stream); +} + +int +gpgrt_ungetc (int c, estream_t stream) +{ + return _gpgrt_ungetc (c, stream); +} + +int +gpgrt_read (estream_t _GPGRT__RESTRICT stream, + void *_GPGRT__RESTRICT buffer, size_t bytes_to_read, + size_t *_GPGRT__RESTRICT bytes_read) +{ + return _gpgrt_read (stream, buffer, bytes_to_read, bytes_read); +} + +int +gpgrt_write (estream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write, + size_t *_GPGRT__RESTRICT bytes_written) +{ + return _gpgrt_write (stream, buffer, bytes_to_write, bytes_written); +} + +int +gpgrt_write_sanitized (estream_t _GPGRT__RESTRICT stream, + const void * _GPGRT__RESTRICT buffer, size_t length, + const char * delimiters, + size_t * _GPGRT__RESTRICT bytes_written) +{ + return _gpgrt_write_sanitized (stream, buffer, length, delimiters, + bytes_written); +} + +int +gpgrt_write_hexstring (estream_t _GPGRT__RESTRICT stream, + const void *_GPGRT__RESTRICT buffer, size_t length, + int reserved, size_t *_GPGRT__RESTRICT bytes_written ) +{ + return _gpgrt_write_hexstring (stream, buffer, length, reserved, + bytes_written); +} + +size_t +gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems, + estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_fread (ptr, size, nitems, stream); +} + +size_t +gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems, + estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_fwrite (ptr, size, nitems, stream); +} + +char * +gpgrt_fgets (char *_GPGRT__RESTRICT buffer, int length, + estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_fgets (buffer, length, stream); +} + +int +gpgrt_fputs (const char *_GPGRT__RESTRICT s, estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_fputs (s, stream); +} + +int +gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s, + estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_fputs_unlocked (s, stream); +} + +gpgrt_ssize_t +gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, + size_t *_GPGRT__RESTRICT n, estream_t _GPGRT__RESTRICT stream) +{ + return _gpgrt_getline (lineptr, n, stream); +} + +gpgrt_ssize_t +gpgrt_read_line (estream_t stream, + char **addr_of_buffer, size_t *length_of_buffer, + size_t *max_length) +{ + return _gpgrt_read_line (stream, addr_of_buffer, length_of_buffer, + max_length); +} + +void +gpgrt_free (void *a) +{ + if (a) + _gpgrt_free (a); +} + +int +gpgrt_vfprintf (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, + va_list ap) +{ + return _gpgrt_vfprintf (stream, format, ap); +} + +int +gpgrt_vfprintf_unlocked (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, + va_list ap) +{ + return _gpgrt_vfprintf_unlocked (stream, format, ap); +} + +int +gpgrt_printf (const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf (es_stdout, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_printf_unlocked (const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf_unlocked (es_stdout, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_fprintf (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf (stream, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_fprintf_unlocked (estream_t _GPGRT__RESTRICT stream, + const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf_unlocked (stream, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_setvbuf (estream_t _GPGRT__RESTRICT stream, + char *_GPGRT__RESTRICT buf, int type, size_t size) +{ + return _gpgrt_setvbuf (stream, buf, type, size); +} + +void +gpgrt_setbuf (estream_t _GPGRT__RESTRICT stream, char *_GPGRT__RESTRICT buf) +{ + _gpgrt_setvbuf (stream, buf, buf? _IOFBF : _IONBF, BUFSIZ); +} + +void +gpgrt_set_binary (estream_t stream) +{ + _gpgrt_set_binary (stream); +} + +estream_t +gpgrt_tmpfile (void) +{ + return _gpgrt_tmpfile (); +} + +void +gpgrt_opaque_set (estream_t stream, void *opaque) +{ + _gpgrt_opaque_set (stream, opaque); +} + +void * +gpgrt_opaque_get (estream_t stream) +{ + return _gpgrt_opaque_get (stream); +} + +void +gpgrt_fname_set (estream_t stream, const char *fname) +{ + _gpgrt_fname_set (stream, fname); +} + +const char * +gpgrt_fname_get (estream_t stream) +{ + return _gpgrt_fname_get (stream); +} + +int +gpgrt_asprintf (char **r_buf, const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_estream_vasprintf (r_buf, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_vasprintf (char **r_buf, const char *_GPGRT__RESTRICT format, va_list ap) +{ + return _gpgrt_estream_vasprintf (r_buf, format, ap); +} + +char * +gpgrt_bsprintf (const char *_GPGRT__RESTRICT format, ...) +{ + int rc; + va_list ap; + char *buf; + + va_start (ap, format); + rc = _gpgrt_estream_vasprintf (&buf, format, ap); + va_end (ap); + if (rc < 0) + return NULL; + return buf; +} + +char * +gpgrt_vbsprintf (const char *_GPGRT__RESTRICT format, va_list ap) +{ + int rc; + char *buf; + + rc = _gpgrt_estream_vasprintf (&buf, format, ap); + if (rc < 0) + return NULL; + return buf; +} + +int +gpgrt_snprintf (char *buf, size_t bufsize, const char *format, ...) +{ + int rc; + va_list arg_ptr; + + va_start (arg_ptr, format); + rc = _gpgrt_estream_vsnprintf (buf, bufsize, format, arg_ptr); + va_end (arg_ptr); + + return rc; +} + +int +gpgrt_vsnprintf (char *buf, size_t bufsize, + const char *format, va_list arg_ptr) +{ + return _gpgrt_estream_vsnprintf (buf, bufsize, format, arg_ptr); +} diff --git a/plugins/MirOTR/Libgpg-error/visibility.h b/plugins/MirOTR/Libgpg-error/visibility.h new file mode 100644 index 0000000000..6f7de8496e --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/visibility.h @@ -0,0 +1,253 @@ +/* visibility.h - Set visibility attribute + * Copyright (C) 2014 g10 Code GmbH + * + * This file is part of libgpg-error. + * + * libgpg-error 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. + * + * libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _GPGRT_VISIBILITY_H +#define _GPGRT_VISIBILITY_H + +/* Include the main header here so that public symbols are mapped to + the internal underscored ones. */ +#ifdef _GPGRT_INCL_BY_VISIBILITY_C +# include "gpgrt-int.h" +#endif + + +/* Our use of the ELF visibility feature works by passing + -fvisibiliy=hidden on the command line and by explicitly marking + all exported functions as visible. + + NOTE: When adding new functions, please make sure to add them to + gpg-error.vers and gpg-error.def.in as well. */ + +#ifdef _GPGRT_INCL_BY_VISIBILITY_C + +# ifdef GPGRT_USE_VISIBILITY +# define MARK_VISIBLE(name) \ + extern __typeof__ (name) name __attribute__ ((visibility("default"))); +# else +# define MARK_VISIBLE(name) /* */ +# endif + +MARK_VISIBLE (gpg_strerror) +MARK_VISIBLE (gpg_strerror_r) +MARK_VISIBLE (gpg_strsource) +MARK_VISIBLE (gpg_err_code_from_errno) +MARK_VISIBLE (gpg_err_code_to_errno) +MARK_VISIBLE (gpg_err_code_from_syserror) +MARK_VISIBLE (gpg_err_set_errno) + +MARK_VISIBLE (gpg_err_init) +MARK_VISIBLE (gpg_err_deinit) +MARK_VISIBLE (gpg_error_check_version) +MARK_VISIBLE (gpgrt_check_version) + +MARK_VISIBLE (gpgrt_lock_init) +MARK_VISIBLE (gpgrt_lock_lock) +MARK_VISIBLE (gpgrt_lock_unlock) +MARK_VISIBLE (gpgrt_lock_destroy) +MARK_VISIBLE (gpgrt_yield) +MARK_VISIBLE (gpgrt_lock_trylock) + +MARK_VISIBLE (gpgrt_fopen) +MARK_VISIBLE (gpgrt_mopen) +MARK_VISIBLE (gpgrt_fopenmem) +MARK_VISIBLE (gpgrt_fopenmem_init) +MARK_VISIBLE (gpgrt_fdopen) +MARK_VISIBLE (gpgrt_fdopen_nc) +MARK_VISIBLE (gpgrt_sysopen) +MARK_VISIBLE (gpgrt_sysopen_nc) +MARK_VISIBLE (gpgrt_fpopen) +MARK_VISIBLE (gpgrt_fpopen_nc) +MARK_VISIBLE (gpgrt_freopen) +MARK_VISIBLE (gpgrt_fopencookie) +MARK_VISIBLE (gpgrt_fclose) +MARK_VISIBLE (gpgrt_fclose_snatch) +MARK_VISIBLE (gpgrt_onclose) +MARK_VISIBLE (gpgrt_fileno) +MARK_VISIBLE (gpgrt_fileno_unlocked) +MARK_VISIBLE (gpgrt_syshd) +MARK_VISIBLE (gpgrt_syshd_unlocked) +MARK_VISIBLE (_gpgrt_set_std_fd) +MARK_VISIBLE (_gpgrt_get_std_stream) +MARK_VISIBLE (gpgrt_flockfile) +MARK_VISIBLE (gpgrt_ftrylockfile) +MARK_VISIBLE (gpgrt_funlockfile) +MARK_VISIBLE (_gpgrt_pending) +MARK_VISIBLE (_gpgrt_pending_unlocked) +MARK_VISIBLE (gpgrt_feof) +MARK_VISIBLE (gpgrt_feof_unlocked) +MARK_VISIBLE (gpgrt_ferror) +MARK_VISIBLE (gpgrt_ferror_unlocked) +MARK_VISIBLE (gpgrt_clearerr) +MARK_VISIBLE (gpgrt_clearerr_unlocked) +MARK_VISIBLE (gpgrt_fflush) +MARK_VISIBLE (gpgrt_fseek) +MARK_VISIBLE (gpgrt_fseeko) +MARK_VISIBLE (gpgrt_ftell) +MARK_VISIBLE (gpgrt_ftello) +MARK_VISIBLE (gpgrt_rewind) +MARK_VISIBLE (gpgrt_fgetc) +MARK_VISIBLE (_gpgrt_getc_underflow) +MARK_VISIBLE (gpgrt_fputc) +MARK_VISIBLE (_gpgrt_putc_overflow) +MARK_VISIBLE (gpgrt_ungetc) +MARK_VISIBLE (gpgrt_read) +MARK_VISIBLE (gpgrt_write) +MARK_VISIBLE (gpgrt_write_sanitized) +MARK_VISIBLE (gpgrt_write_hexstring) +MARK_VISIBLE (gpgrt_fread) +MARK_VISIBLE (gpgrt_fwrite) +MARK_VISIBLE (gpgrt_fgets) +MARK_VISIBLE (gpgrt_fputs) +MARK_VISIBLE (gpgrt_fputs_unlocked) +MARK_VISIBLE (gpgrt_getline) +MARK_VISIBLE (gpgrt_read_line) +MARK_VISIBLE (gpgrt_free) +MARK_VISIBLE (gpgrt_fprintf) +MARK_VISIBLE (gpgrt_fprintf_unlocked) +MARK_VISIBLE (gpgrt_printf) +MARK_VISIBLE (gpgrt_printf_unlocked) +MARK_VISIBLE (gpgrt_vfprintf) +MARK_VISIBLE (gpgrt_vfprintf_unlocked) +MARK_VISIBLE (gpgrt_setvbuf) +MARK_VISIBLE (gpgrt_setbuf) +MARK_VISIBLE (gpgrt_set_binary) +MARK_VISIBLE (gpgrt_tmpfile) +MARK_VISIBLE (gpgrt_opaque_set) +MARK_VISIBLE (gpgrt_opaque_get) +MARK_VISIBLE (gpgrt_fname_set) +MARK_VISIBLE (gpgrt_fname_get) +MARK_VISIBLE (gpgrt_asprintf) +MARK_VISIBLE (gpgrt_vasprintf) +MARK_VISIBLE (gpgrt_bsprintf) +MARK_VISIBLE (gpgrt_vbsprintf) +MARK_VISIBLE (gpgrt_snprintf) +MARK_VISIBLE (gpgrt_vsnprintf) +MARK_VISIBLE (gpgrt_set_syscall_clamp) +MARK_VISIBLE (gpgrt_set_alloc_func) + +#undef MARK_VISIBLE + +#else /*!_GPGRT_INCL_BY_VISIBILITY_C*/ + +/* To avoid accidental use of the public functions inside Libgpg-error, + we redefine them to catch such errors. */ + +#define gpg_strerror _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_strerror_r _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_strsource _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_err_code_from_errno _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_err_code_to_errno _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_err_code_from_syserror _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_err_set_errno _gpgrt_USE_UNDERSCORED_FUNCTION + +#define gpg_err_init _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_err_deinit _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpg_error_check_version _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_check_version _gpgrt_USE_OTHER_FUNCTION + +#define gpgrt_lock_init _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_lock_lock _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_lock_unlock _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_lock_destroy _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_yield _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_lock_trylock _gpgrt_USE_UNDERSCORED_FUNCTION + +#define gpgrt_fopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_mopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fopenmem _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fopenmem_init _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fdopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fdopen_nc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_sysopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_sysopen_nc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fpopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fpopen_nc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_freopen _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fopencookie _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fclose _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fclose_snatch _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_onclose _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fileno _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fileno_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_syshd _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_syshd_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_set_std_fd _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_get_std_stream _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_flockfile _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ftrylockfile _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_funlockfile _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_pending _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_pending_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_feof _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_feof_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ferror _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ferror_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_clearerr _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_clearerr_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fflush _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fseek _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fseeko _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ftell _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ftello _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_rewind _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fgetc _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_getc_underflow _gpgrt_USE_DBLUNDERSCO_FUNCTION +#define gpgrt_fputc _gpgrt_USE_UNDERSCORED_FUNCTION +#define _gpgrt_putc_overflow _gpgrt_USE_DBLUNDERSCO_FUNCTION +#define gpgrt_ungetc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_read _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_write _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_write_sanitized _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_write_hexstring _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fread _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fwrite _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fgets _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fputs _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fputs_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_getline _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_read_line _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_free _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fprintf_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_printf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_printf_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_vfprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_vfprintf_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_setvbuf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_setbuf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_set_binary _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_tmpfile _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_opaque_set _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_opaque_get _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fname_set _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_fname_get _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_asprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_vasprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_bsprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_vbsprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_snprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_vsnprintf _gpgrt_USE_UNDERSCORED_FUNCTION + +#define gpgrt_set_syscall_clamp _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_set_alloc_func _gpgrt_USE_UNDERSCORED_FUNCTION + + +#endif /*!_GPGRT_INCL_BY_VISIBILITY_C*/ + +#endif /*_GPGRT_VISIBILITY_H*/ diff --git a/plugins/MirOTR/Libgpg-error/w32-gettext.c b/plugins/MirOTR/Libgpg-error/w32-gettext.c index da07a25695..89f505d91d 100644 --- a/plugins/MirOTR/Libgpg-error/w32-gettext.c +++ b/plugins/MirOTR/Libgpg-error/w32-gettext.c @@ -1,19 +1,19 @@ /* w32-gettext.h - A simple gettext implementation for Windows targets. Copyright (C) 1995, 1996, 1997, 1999, 2005, 2007, -2 2008, 2010 Free Software Foundation, Inc. + 2008, 2010 Free Software Foundation, Inc. This file is part of libgpg-error. - + libgpg-error 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. - + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. */ @@ -30,8 +30,9 @@ #include <string.h> #include <errno.h> #include <ctype.h> +#ifdef HAVE_SYS_TYPES_H #include <sys/types.h> -#include <sys/stat.h> +#endif #include <stdint.h> #ifndef HAVE_W32CE_SYSTEM # include <locale.h> @@ -50,7 +51,39 @@ #endif /*!jnlib_malloc*/ #include "init.h" +#include "gpg-error.h" + +#ifdef HAVE_W32CE_SYSTEM +/* Forward declaration. */ +static wchar_t *utf8_to_wchar (const char *string, size_t length, size_t *retlen); + +static HANDLE +MyCreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwSharedMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile) +{ + wchar_t *filename; + HANDLE result; + int err; + size_t size; + + filename = utf8_to_wchar (lpFileName, -1, &size); + if (!filename) + return INVALID_HANDLE_VALUE; + result = CreateFileW (filename, dwDesiredAccess, dwSharedMode, + lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); + + err = GetLastError (); + free (filename); + SetLastError (err); + return result; +} +#undef CreateFileA +#define CreateFileA MyCreateFileA +#endif /* localname.c from gettext BEGIN. */ @@ -601,8 +634,8 @@ #ifndef SUBLANG_UZBEK_CYRILLIC #define SUBLANG_UZBEK_CYRILLIC 0x02 #endif - -/* Return an XPG style locale name + +/* Return an XPG style locale name language[_territory[.codeset]][@modifier]. Don't even bother determining the codeset; it's not useful in this context, because message catalogs are not specific to a single @@ -611,7 +644,9 @@ static const char * my_nl_locale_name (const char *categoryname) { +#ifndef HAVE_W32CE_SYSTEM const char *retval; +#endif LCID lcid; LANGID langid; int primary, sub; @@ -1026,7 +1061,7 @@ my_nl_locale_name (const char *categoryname) /* Support functions. */ -static __inline__ uint32_t +static GPG_ERR_INLINE uint32_t do_swap_u32 (uint32_t i) { return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); @@ -1041,12 +1076,12 @@ do_swap_u32 (uint32_t i) /* The so called `hashpjw' function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.] */ -static __inline__ unsigned long -hash_string( const char *str_param ) +static GPG_ERR_INLINE unsigned long +hash_string (const char *str_param) { unsigned long int hval, g; const char *str = str_param; - + hval = 0; while (*str != '\0') { @@ -1146,14 +1181,33 @@ static char *current_domainname; -/* Constructor for this module. Called from DllMain. */ -static void module_init (void) __attribute__ ((__constructor__)); +/* Constructor for this module. This can only be used if we are a + DLL. If used as a static lib we can't control the process set; for + example it might be used with a main module which is not build with + mingw and thus does not know how to call the constructors. */ +#ifdef DLL_EXPORT +static void module_init (void) _GPG_ERR_CONSTRUCTOR; +#endif static void module_init (void) { - InitializeCriticalSection (&domainlist_access_cs); + static int init_done; + + if (!init_done) + { + InitializeCriticalSection (&domainlist_access_cs); + init_done = 1; + } } +#if !defined(DLL_EXPORT) || !defined(_GPG_ERR_HAVE_CONSTRUCTOR) +void +_gpg_w32__init_gettext_module (void) +{ + module_init (); +} +#endif + /* Free the domain data. */ static void @@ -1171,35 +1225,33 @@ free_domain (struct loaded_domain *domain) jnlib_free (domain); } - + static struct loaded_domain * load_domain (const char *filename) { - FILE *fp; - size_t size; - struct stat st; + HANDLE fh; + DWORD size; struct mo_file_header *data = NULL; struct loaded_domain *domain = NULL; size_t to_read; char *read_ptr; - - fp = fopen (filename, "rb"); - if (!fp) - { - return NULL; - } - if (fstat (fileno (fp), &st) - || (size = (size_t) st.st_size) != st.st_size - || size < sizeof (struct mo_file_header)) + + fh = CreateFileA (filename, GENERIC_READ, FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + if (fh == INVALID_HANDLE_VALUE) + return NULL; + + size = GetFileSize (fh, NULL); + if (size == INVALID_FILE_SIZE) { - fclose (fp); + CloseHandle (fh); return NULL; } data = (2*size <= size)? NULL : jnlib_malloc (2*size); if (!data) { - fclose (fp); + CloseHandle (fh); return NULL; } @@ -1207,10 +1259,13 @@ load_domain (const char *filename) read_ptr = (char *) data; do { - long int nb = fread (read_ptr, 1, to_read, fp); - if (nb < to_read) + BOOL res; + DWORD nb; + + res = ReadFile (fh, read_ptr, to_read, &nb, NULL); + if (! res || nb < to_read) { - fclose (fp); + CloseHandle (fh); jnlib_free (data); return NULL; } @@ -1218,7 +1273,7 @@ load_domain (const char *filename) to_read -= nb; } while (to_read > 0); - fclose (fp); + CloseHandle (fh); /* Using the magic number we can test whether it really is a message catalog file. */ @@ -1238,7 +1293,7 @@ load_domain (const char *filename) domain->data = (char *) data; domain->data_native = (char *) data + size; domain->must_swap = data->magic != MAGIC; - + /* Fill in the information about the available tables. */ switch (SWAPIT (domain->must_swap, data->revision)) { @@ -1252,7 +1307,7 @@ load_domain (const char *filename) that many translations is very unlikely given that GnuPG with its very large number of strings has only about 1600 strings + variants. */ - nstrings = SWAPIT (domain->must_swap, data->nstrings); + nstrings = SWAPIT (domain->must_swap, data->nstrings); if (nstrings > 65534) goto bailout; domain->nstrings = nstrings; @@ -1298,7 +1353,7 @@ utf8_to_wchar (const char *string, size_t length, size_t *retlen) return NULL; nbytes = (size_t)(n+1) * sizeof(*result); - if (nbytes / sizeof(*result) != (n+1)) + if (nbytes / sizeof(*result) != (n+1)) { gpg_err_set_errno (ENOMEM); return NULL; @@ -1551,17 +1606,28 @@ get_string (struct loaded_domain *domain, uint32_t idx, + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); } - else if (!domain->mapped[idx]) + else if (!domain->mapped[idx]) { /* Not yet mapped. Map from utf-8 to native encoding now. */ const char *p_utf8; size_t plen_utf8, buflen; char *buf; - p_utf8 = (domain->data + p_utf8 = (domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); plen_utf8 = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); - + + /* We need to include the nul, so that the utf8->wchar->native + conversion chain works correctly and the nul is stored after + the conversion. */ + if (p_utf8[plen_utf8]) + { + trans = "ERROR in MO file"; /* Terminating zero is missing. */ + translen = 0; + goto leave; + } + plen_utf8++; + buf = utf8_to_native (p_utf8, plen_utf8, &buflen); if (!buf) { @@ -1573,7 +1639,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, /* Copy into the DATA_NATIVE area. */ char *p_tmp; - p_tmp = (domain->data_native + p_tmp = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); memcpy (p_tmp, buf, buflen); domain->mapped[idx] = buflen; @@ -1585,10 +1651,10 @@ get_string (struct loaded_domain *domain, uint32_t idx, /* There is not enough space for the translation (or for whatever reason an empty string is used): Store it in the overflow_space and mark that in the mapped array. - Because UTF-8 strings are in general shorter than the - Windows 2 byte encodings, we expect that this won't - happen too often (if at all) and thus we use a linked - list to manage this space. */ + Because UTF-8 strings are in general longer than the + Windows native encoding, we expect that this won't happen + too often and thus we use a linked list to manage this + space. */ os = jnlib_malloc (sizeof *os + buflen); if (os) { @@ -1607,9 +1673,11 @@ get_string (struct loaded_domain *domain, uint32_t idx, translen = 0; } } + if (translen) + translen--; /* TRANSLEN shall be the size without the nul. */ jnlib_free (buf); } - else if (domain->mapped[idx] == 1) + else if (domain->mapped[idx] == 1) { /* The translated string is in the overflow_space. */ for (os=domain->overflow_space; os; os = os->next) @@ -1626,13 +1694,14 @@ get_string (struct loaded_domain *domain, uint32_t idx, translen = 0; } } - else - { + else + { trans = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = domain->mapped[idx]; } + leave: if (use_plural && translen) return get_plural (trans, translen, nplural); else @@ -1641,7 +1710,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, static const char * -do_gettext (const char *domainname, +do_gettext (const char *domainname, const char *msgid, const char *msgid2, unsigned long nplural) { struct domainlist_s *dl; @@ -1649,14 +1718,14 @@ do_gettext (const char *domainname, int load_failed; uint32_t top, bottom, nstr; char *filename; - + if (!domainname) domainname = current_domainname? current_domainname : ""; /* FIXME: The whole locking stuff is a bit questionable because gettext does not claim to be thread-safe. We need to investigate this further. */ - + load_failed = 0; domain = NULL; filename = NULL; @@ -1708,7 +1777,7 @@ do_gettext (const char *domainname, domain = NULL; } } - + if (!domain) goto not_found; /* No MO file. */ @@ -1725,7 +1794,7 @@ do_gettext (const char *domainname, { nstr--; if (nstr < domain->nstrings - && SWAPIT(domain->must_swap, + && SWAPIT(domain->must_swap, domain->orig_tab[nstr].length) >= len && !strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1748,7 +1817,7 @@ do_gettext (const char *domainname, while (bottom < top) { int cmp_val; - + nstr = (bottom + top) / 2; cmp_val = strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1854,10 +1923,10 @@ _gpg_w32_gettext_use_utf8 (int value) int main (int argc, char **argv) { - const char atext1[] = + const char atext1[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u character long."; - const char atext2[] = + const char atext2[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u characters long."; @@ -1866,7 +1935,7 @@ main (int argc, char **argv) argc--; argv++; } - + _gpg_err_w32_bindtextdomain ("gnupg2", "c:/programme/gnu/gnupg/share/locale"); printf ("locale is `%s'\n", _gpg_err_w32_gettext_localename ()); diff --git a/plugins/MirOTR/Libgpg-error/w32-lock-obj.h b/plugins/MirOTR/Libgpg-error/w32-lock-obj.h new file mode 100644 index 0000000000..ef53546d90 --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/w32-lock-obj.h @@ -0,0 +1,38 @@ +/* w32-lock-obj.h - Declaration of the Windows lock object + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef W32_LOCK_OBJ_H +#define W32_LOCK_OBJ_H + +#define LOCK_ABI_VERSION 1 + +/* The real definition of our lock object. The public definition is + named gpgrt_lock_t and hides this internal structure. */ +#pragma pack(push, 8) +typedef struct +{ + long vers; + volatile long initdone; + volatile long started; + CRITICAL_SECTION csec; +} _gpgrt_lock_t; +#pragma pack(pop) + + +#endif /*W32_LOCK_OBJ_H*/ diff --git a/plugins/MirOTR/Libgpg-error/w32-lock.c b/plugins/MirOTR/Libgpg-error/w32-lock.c new file mode 100644 index 0000000000..8c086f976d --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/w32-lock.c @@ -0,0 +1,158 @@ +/* w32-lock.c - GPGRT lock functions for Windows + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef HAVE_W32_SYSTEM +# error This module may only be build for Windows. +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <gpg-error.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "lock.h" +#include "w32-lock-obj.h" + + +static _gpgrt_lock_t * +get_lock_object (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd; + + if (lock->vers != LOCK_ABI_VERSION) + abort (); + + return lock; +} + + +gpg_err_code_t +_gpgrt_lock_init (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd; + + /* If VERS is zero we assume that no static initialization has been + done, so we setup our ABI version right here. The caller might + have called us to test whether lock support is at all available. */ + if (!lock->vers) + { + if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t)) + abort (); + lock->vers = LOCK_ABI_VERSION; + } + else /* Run the usual check. */ + { + lock = get_lock_object (lockhd); + if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t)) + abort (); + } + + InitializeCriticalSection (&lock->csec); + lock->initdone = 1; + return 0; +} + + +gpg_err_code_t +_gpgrt_lock_lock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + + if (!lock->initdone) + { + if (!InterlockedIncrement (&lock->started)) + { + /* The new value of started is 0. Because the initial value + if the variable was -1 we known that this thread is the + first who needs this lock. Thus we initialize now. All + other threads won't get 0 back from InterlockedIncrement + and thus fall into the wait loop below. We ignore that + STARTED may in theory overflow if this thread starves for + too long. */ + gpgrt_lock_init (lockhd); + } + else + { + while (!lock->initdone) + Sleep (0); + } + } + + EnterCriticalSection (&lock->csec); + return 0; +} + + +gpg_err_code_t +_gpgrt_lock_trylock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + + if (!lock->initdone) + { + if (!InterlockedIncrement (&lock->started)) + { + gpgrt_lock_init (lockhd); + } + else + { + while (!lock->initdone) + Sleep (0); + } + } + + if (!TryEnterCriticalSection (&lock->csec)) + return GPG_ERR_EBUSY; + return 0; +} + + +gpg_err_code_t +_gpgrt_lock_unlock (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + + if (!lock->initdone) + return GPG_ERR_INV_LOCK_OBJ; + LeaveCriticalSection (&lock->csec); + return 0; +} + + +/* Note: Use this function only if no other thread holds or waits for + this lock. */ +gpg_err_code_t +_gpgrt_lock_destroy (gpgrt_lock_t *lockhd) +{ + _gpgrt_lock_t *lock = get_lock_object (lockhd); + + if (!lock->initdone) + return GPG_ERR_INV_LOCK_OBJ; + DeleteCriticalSection (&lock->csec); + lock->initdone = 0; + lock->started = -1; + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/w32-thread.c b/plugins/MirOTR/Libgpg-error/w32-thread.c new file mode 100644 index 0000000000..53d26b4d5d --- /dev/null +++ b/plugins/MirOTR/Libgpg-error/w32-thread.c @@ -0,0 +1,44 @@ +/* w32-thread.c - GPGRT thread functions for Windows + Copyright (C) 2014 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error 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. + + libgpg-error 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 this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef HAVE_W32_SYSTEM +# error This module may only be build for Windows. +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <gpg-error.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "thread.h" + + +gpg_err_code_t +_gpgrt_yield (void) +{ + Sleep (0); + return 0; +} diff --git a/plugins/MirOTR/Libgpg-error/w32ce-add.h b/plugins/MirOTR/Libgpg-error/w32ce-add.h index 83b75386f0..c6207bb2bb 100644 --- a/plugins/MirOTR/Libgpg-error/w32ce-add.h +++ b/plugins/MirOTR/Libgpg-error/w32ce-add.h @@ -3,5 +3,6 @@ /* Substitute for strerror - this one is thread safe. */ char *_gpg_w32ce_strerror (int err); -#define strerror(a) _gpg_w32ce_strerror (a) - +#ifdef GPG_ERR_ENABLE_ERRNO_MACROS +# define strerror(a) _gpg_w32ce_strerror (a) +#endif |