From 1890896fe698c55d15160a53aa6c5c22dc424031 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 2 Mar 2017 18:17:58 +0100 Subject: [PATCH] dirmngr: Rearrange files to fix de6d831. * dirmngr/http-common.c: New. * dirmngr/http-common.h: New. * dirmngr/Makefile.am (dirmngr_SOURCES): Add them. (t_http_SOURCES): Add them. (t_ldap_parse_uri_SOURCES): Add them. * dirmngr/misc.c (get_default_keyserver): Move to ... * dirmngr/http-common.c: here. * dirmngr/http.c: Include http-common.h instead of misc.h. * dirmngr/http-ntbtls.c: Ditto. Signed-off-by: Werner Koch --- dirmngr/Makefile.am | 7 +++--- dirmngr/dirmngr.c | 1 + dirmngr/http-common.c | 50 +++++++++++++++++++++++++++++++++++++++++++ dirmngr/http-common.h | 25 ++++++++++++++++++++++ dirmngr/http-ntbtls.c | 2 +- dirmngr/http.c | 2 +- dirmngr/misc.c | 23 -------------------- dirmngr/misc.h | 2 -- 8 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 dirmngr/http-common.c create mode 100644 dirmngr/http-common.h diff --git a/dirmngr/Makefile.am b/dirmngr/Makefile.am index 8d22cc47b..93880f8ce 100644 --- a/dirmngr/Makefile.am +++ b/dirmngr/Makefile.am @@ -61,8 +61,7 @@ dirmngr_SOURCES = dirmngr.c dirmngr.h server.c crlcache.c crlfetch.c \ cdb.h cdblib.c misc.c dirmngr-err.h \ ocsp.c ocsp.h validate.c validate.h \ dns-stuff.c dns-stuff.h \ - http.c http.h \ - http-ntbtls.c \ + http.c http.h http-common.c http-common.h http-ntbtls.c \ ks-action.c ks-action.h ks-engine.h \ ks-engine-hkp.c ks-engine-http.c ks-engine-finger.c ks-engine-kdns.c @@ -141,7 +140,7 @@ endif # http tests # We need to add the KSBA flags in case we are building against GNUTLS. # In that case NTBTLS flags are empty, but we need ksba anyway. -t_http_SOURCES = $(t_common_src) t-http.c http.c dns-stuff.c +t_http_SOURCES = $(t_common_src) t-http.c http.c dns-stuff.c http-common.c t_http_CFLAGS = -DWITHOUT_NPTH=1 $(USE_C99_CFLAGS) \ $(LIBGCRYPT_CFLAGS) $(NTBTLS_CFLAGS) $(LIBGNUTLS_CFLAGS) \ $(GPG_ERROR_CFLAGS) $(KSBA_CFLAGS) @@ -150,7 +149,7 @@ t_http_LDADD = $(t_common_ldadd) \ t_ldap_parse_uri_SOURCES = \ t-ldap-parse-uri.c ldap-parse-uri.c ldap-parse-uri.h \ - http.c dns-stuff.c \ + http.c http-common.c dns-stuff.c \ $(ldap_url) $(t_common_src) t_ldap_parse_uri_CFLAGS = -DWITHOUT_NPTH=1 $(USE_C99_CFLAGS) \ $(LIBGCRYPT_CFLAGS) $(GPG_ERROR_CFLAGS) diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index 75e852338..f05bdd127 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -72,6 +72,7 @@ #include "../common/init.h" #include "gc-opt-flags.h" #include "dns-stuff.h" +#include "http-common.h" #ifndef ENAMETOOLONG # define ENAMETOOLONG EINVAL diff --git a/dirmngr/http-common.c b/dirmngr/http-common.c new file mode 100644 index 000000000..6013669b3 --- /dev/null +++ b/dirmngr/http-common.c @@ -0,0 +1,50 @@ +/* http-common.c - Common support for TLS implementations. + * Copyright (C) 2017 Werner Koch + * + * This file is part of GnuPG. + * + * GnuPG 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 3 of the License, or + * (at your option) any later version. + * + * GnuPG 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, see . + */ + +#include + +#include +#include +#include + +#include "dirmngr.h" +#include "http-common.h" + + +/* Return a static string with the default keyserver. If NAME_ONLY is + * given only the name part is returned. */ +const char * +get_default_keyserver (int name_only) +{ + static const char *result; + + if (!name_only) + return DIRMNGR_DEFAULT_KEYSERVER; + + if (!result) + { + /* Strip the scheme from the constant. */ + result = strstr (DIRMNGR_DEFAULT_KEYSERVER, "://"); + log_assert (result && strlen (result) > 3); + result += 3; + /* Assert that there is no port given. */ + log_assert (strchr (result, ':')); + } + return result; +} diff --git a/dirmngr/http-common.h b/dirmngr/http-common.h new file mode 100644 index 000000000..5e6657b16 --- /dev/null +++ b/dirmngr/http-common.h @@ -0,0 +1,25 @@ +/* http-common.h - Defs for common support for TLS implementations. + * Copyright (C) 2017 Werner Koch + * + * This file is part of GnuPG. + * + * GnuPG 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 3 of the License, or + * (at your option) any later version. + * + * GnuPG 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, see . + */ + +#ifndef HTTP_COMMON_H +#define HTTP_COMMON_H + +const char *get_default_keyserver (int name_only); + +#endif /* HTTP_COMMON_H */ diff --git a/dirmngr/http-ntbtls.c b/dirmngr/http-ntbtls.c index d44b77930..250db556c 100644 --- a/dirmngr/http-ntbtls.c +++ b/dirmngr/http-ntbtls.c @@ -26,7 +26,7 @@ #include "dirmngr.h" #include "certcache.h" #include "validate.h" -#include "misc.h" +#include "http-common.h" #ifdef HTTP_USE_NTBTLS # include diff --git a/dirmngr/http.c b/dirmngr/http.c index fc8292455..0f11af750 100644 --- a/dirmngr/http.c +++ b/dirmngr/http.c @@ -100,7 +100,7 @@ #include "i18n.h" #include "dns-stuff.h" #include "http.h" -#include "misc.h" +#include "http-common.h" #ifdef USE_NPTH diff --git a/dirmngr/misc.c b/dirmngr/misc.c index d2f1c69a6..6d7c963db 100644 --- a/dirmngr/misc.c +++ b/dirmngr/misc.c @@ -30,29 +30,6 @@ #include "util.h" #include "misc.h" -/* Return a static string with the default keyserver. If NAME_ONLY is - * given only the name part is returned. */ -const char * -get_default_keyserver (int name_only) -{ - static const char *result; - - if (!name_only) - return DIRMNGR_DEFAULT_KEYSERVER; - - if (!result) - { - /* Strip the scheme from the constant. */ - result = strstr (DIRMNGR_DEFAULT_KEYSERVER, "://"); - log_assert (result && strlen (result) > 3); - result += 3; - /* Assert that there is no port given. */ - log_assert (strchr (result, ':')); - } - return result; -} - - /* Convert the hex encoded STRING back into binary and store the result into the provided buffer RESULT. The actual size of that diff --git a/dirmngr/misc.h b/dirmngr/misc.h index f25574f38..be4049e88 100644 --- a/dirmngr/misc.h +++ b/dirmngr/misc.h @@ -21,8 +21,6 @@ #ifndef MISC_H #define MISC_H -const char *get_default_keyserver (int name_only); - /* Convert hex encoded string back to binary. */ size_t unhexify (unsigned char *result, const char *string);