From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Tue, 23 Dec 2025 22:10:40 +0000 (+0000) Subject: Maintenance: Turn libmiscencoding to C++ (#2325) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac5209802131a8d0089cb06abaf026b2a2d3c973;p=thirdparty%2Fsquid.git Maintenance: Turn libmiscencoding to C++ (#2325) Squid C code does not need `libmiscencoding` anymore. These changes are limited to making renamed files compile cleanly using a C++ compiler. Library code still needs to be updated to follow best C++ practices. --- diff --git a/CREDITS b/CREDITS index 4ccb7162bf..bf3058ad12 100644 --- a/CREDITS +++ b/CREDITS @@ -501,7 +501,7 @@ lib/snmplib/snmp_vars.c: ============================================================================== include/base64.h: -lib/base64.c: +lib/base64.cc: /* Copyright (C) 2002 Niels Möller, Dan Egnor @@ -545,7 +545,7 @@ lib/heap.c: ============================================================================== include/md5.h, -lib/md5.c: +lib/md5.cc: * The algorithm is due to Ron Rivest. This code was * written by Colin Plumb in 1993, no copyright is claimed. @@ -582,7 +582,7 @@ SOFTWARE. ============================================================================== include/rfc2617.h, -lib/rfc2617.c: +lib/rfc2617.cc: * The source in this file is derived from the reference implementation * in RFC 2617. @@ -624,7 +624,7 @@ include/snmp_util.h: ============================================================================== -lib/base64.c::base64_encode(): +lib/base64.cc::base64_encode(): Adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c. Modified to work with strings instead of files. diff --git a/include/base64.h b/include/base64.h index 08d9f07cd1..8505b1f05a 100644 --- a/include/base64.h +++ b/include/base64.h @@ -47,10 +47,6 @@ not, see http://www.gnu.org/licenses/. */ -#ifdef __cplusplus -extern "C" { -#endif - /* Base64 encoding */ /* Maximum length of output for base64_encode_update. NOTE: Doesn't @@ -158,10 +154,6 @@ base64_decode_update(struct base64_decode_ctx *ctx, int base64_decode_final(struct base64_decode_ctx *ctx); -#ifdef __cplusplus -} -#endif - #endif /* HAVE_NETTLE_BASE64_H */ /// Calculate the buffer size required to hold the encoded form of diff --git a/include/rfc1738.h b/include/rfc1738.h index 1d6b5e6d55..c7d7edb328 100644 --- a/include/rfc1738.h +++ b/include/rfc1738.h @@ -9,10 +9,6 @@ #ifndef SQUID_INCLUDE_RFC1738_H #define SQUID_INCLUDE_RFC1738_H -#ifdef __cplusplus -extern "C" { -#endif - /* Encoder rfc1738_do_escape flag values. */ #define RFC1738_ESCAPE_CTRLS 1 #define RFC1738_ESCAPE_UNSAFE 2 @@ -64,8 +60,5 @@ extern char *rfc1738_do_escape(const char *url, int flags); */ extern void rfc1738_unescape(char *url); -#ifdef __cplusplus -} -#endif #endif /* SQUID_INCLUDE_RFC1738_H */ diff --git a/include/rfc2617.h b/include/rfc2617.h index 97884b2080..60a1910ae5 100644 --- a/include/rfc2617.h +++ b/include/rfc2617.h @@ -23,10 +23,6 @@ #ifndef SQUID_INCLUDE_RFC2617_H #define SQUID_INCLUDE_RFC2617_H -#ifdef __cplusplus -extern "C" { -#endif - #define HASHLEN 16 typedef char HASH[HASHLEN]; #define HASHHEXLEN 32 @@ -61,8 +57,5 @@ extern void CvtHex(const HASH Bin, HASHHEX Hex); extern void CvtBin(const HASHHEX Hex, HASH Bin); -#ifdef __cplusplus -} -#endif #endif /* SQUID_INCLUDE_RFC2617_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 2196226d9e..d2094afe61 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -38,10 +38,10 @@ EXTRA_libmiscutil_la_SOURCES = \ getopt.c libmiscencoding_la_SOURCES = \ - base64.c \ - md5.c \ - rfc1738.c \ - rfc2617.c + base64.cc \ + md5.cc \ + rfc1738.cc \ + rfc2617.cc libmisccontainers_la_SOURCES = \ hash.cc diff --git a/lib/base64.c b/lib/base64.cc similarity index 99% rename from lib/base64.c rename to lib/base64.cc index 3b411d6679..0826805a91 100644 --- a/lib/base64.c +++ b/lib/base64.cc @@ -208,7 +208,7 @@ encode_raw(const char *alphabet, assert(out == dst); } -static const char base64_encode_table[64] = +static const auto base64_encode_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; diff --git a/lib/md5-test.c b/lib/md5-test.cc similarity index 100% rename from lib/md5-test.c rename to lib/md5-test.cc diff --git a/lib/md5.c b/lib/md5.cc similarity index 99% rename from lib/md5.c rename to lib/md5.cc index 8a1a14551d..03572de283 100644 --- a/lib/md5.c +++ b/lib/md5.cc @@ -88,7 +88,7 @@ SquidMD5Init(struct SquidMD5Context *ctx) void SquidMD5Update(struct SquidMD5Context *ctx, const void *_buf, unsigned len) { - uint8_t const *buf = _buf; + auto buf = static_cast(_buf); uint32_t t; /* Update byte count */ @@ -180,7 +180,7 @@ SquidMD5Final(unsigned char digest[16], struct SquidMD5Context *ctx) void SquidMD5Transform(uint32_t buf[4], uint32_t const in[16]) { - register uint32_t a, b, c, d; + uint32_t a, b, c, d; a = buf[0]; b = buf[1]; diff --git a/lib/rfc1738.c b/lib/rfc1738.cc similarity index 100% rename from lib/rfc1738.c rename to lib/rfc1738.cc diff --git a/lib/rfc2617.c b/lib/rfc2617.cc similarity index 100% rename from lib/rfc2617.c rename to lib/rfc2617.cc diff --git a/lib/tests/testRFC1738.cc b/lib/tests/testRFC1738.cc index 061a45ad29..6eee796ff5 100644 --- a/lib/tests/testRFC1738.cc +++ b/lib/tests/testRFC1738.cc @@ -13,7 +13,7 @@ #include /* Being a C library code it is best bodily included and tested with C++ type-safe techniques. */ -#include "lib/rfc1738.c" +#include "lib/rfc1738.cc" /** * Test the URL coder RFC 1738 Engine