From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:24:21 +0000 (+0000) Subject: Remove unnecessary C linkage and unused code (#1677) X-Git-Tag: SQUID_7_0_1~210 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ca919500647218fae924905a5c3f4184492417b0;p=thirdparty%2Fsquid.git Remove unnecessary C linkage and unused code (#1677) Also upgrade lib/util.c to C++. --- diff --git a/compat/Makefile.am b/compat/Makefile.am index 510eb24848..e4200d1110 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -69,8 +69,6 @@ libcompatsquid_la_SOURCES = \ statvfs.h \ stdio.h \ stdvarargs.h \ - strnrchr.c \ - strnrchr.h \ strnstr.cc \ strtoll.h \ tempnam.h \ diff --git a/compat/debug.h b/compat/debug.h index 241aba7628..feb3139db5 100644 --- a/compat/debug.h +++ b/compat/debug.h @@ -20,7 +20,7 @@ /* Debugging stuff */ -SQUIDCEXTERN int debug_enabled; +extern int debug_enabled; /* the macro overload style is really a gcc-ism */ #if defined(__GNUC__) || defined(__SUNPRO_CC) diff --git a/compat/strnrchr.c b/compat/strnrchr.c deleted file mode 100644 index 186a7d9540..0000000000 --- a/compat/strnrchr.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#include "squid.h" -#include "strnrchr.h" - -const char * -strnrchr(const char *s, size_t count, int c) -{ - const char *rv=NULL; - const char *l=s; - while (count > 0 && *l != 0) { - if (*l==c) - rv=l; - ++l; - --count; - } - return rv; -} - diff --git a/compat/strnrchr.h b/compat/strnrchr.h deleted file mode 100644 index 7e89d6b5f0..0000000000 --- a/compat/strnrchr.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#ifndef SQUID_COMPAT_STRNRCHR_H -#define SQUID_COMPAT_STRNRCHR_H - -#if HAVE_STDDEF_H -#include -#endif - -/** - * look for the last occurrence of a character in a c-string. - * - * Scanning starts at the beginning of the c-string, and ends - * after count bytes or at the end of the c-string, whichever happens first - */ -SQUIDCEXTERN const char *strnrchr(const char *s, size_t count, int c); - -#endif /* SQUID_COMPAT_STRNRCHR_H */ - diff --git a/include/getfullhostname.h b/include/getfullhostname.h deleted file mode 100644 index f015821ad0..0000000000 --- a/include/getfullhostname.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#ifndef SQUID_INCLUDE_GETFULLHOSTNAME_H -#define SQUID_INCLUDE_GETFULLHOSTNAME_H - -SQUIDCEXTERN const char *getfullhostname(void); - -#endif /* SQUID_INCLUDE_GETFULLHOSTNAME_H */ - diff --git a/include/hash.h b/include/hash.h index c1257127ad..cf6326be0d 100644 --- a/include/hash.h +++ b/include/hash.h @@ -31,20 +31,20 @@ public: int count; }; -SQUIDCEXTERN hash_table *hash_create(HASHCMP *, int, HASHHASH *); -SQUIDCEXTERN void hash_join(hash_table *, hash_link *); -SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *); -SQUIDCEXTERN int hashPrime(int n); -SQUIDCEXTERN hash_link *hash_lookup(hash_table *, const void *); -SQUIDCEXTERN void hash_first(hash_table *); -SQUIDCEXTERN hash_link *hash_next(hash_table *); -SQUIDCEXTERN void hash_last(hash_table *); -SQUIDCEXTERN hash_link *hash_get_bucket(hash_table *, unsigned int); -SQUIDCEXTERN void hashFreeMemory(hash_table *); -SQUIDCEXTERN void hashFreeItems(hash_table *, HASHFREE *); -SQUIDCEXTERN HASHHASH hash_string; -SQUIDCEXTERN HASHHASH hash4; -SQUIDCEXTERN const char *hashKeyStr(const hash_link *); +hash_table *hash_create(HASHCMP *, int, HASHHASH *); +void hash_join(hash_table *, hash_link *); +void hash_remove_link(hash_table *, hash_link *); +int hashPrime(int n); +hash_link *hash_lookup(hash_table *, const void *); +void hash_first(hash_table *); +hash_link *hash_next(hash_table *); +void hash_last(hash_table *); +hash_link *hash_get_bucket(hash_table *, unsigned int); +void hashFreeMemory(hash_table *); +void hashFreeItems(hash_table *, HASHFREE *); +HASHHASH hash_string; +HASHHASH hash4; +const char *hashKeyStr(const hash_link *); /* * Here are some good prime number choices. It's important not to diff --git a/include/splay.h b/include/splay.h index 2e03079ec4..a905a85147 100644 --- a/include/splay.h +++ b/include/splay.h @@ -92,7 +92,7 @@ private: size_t elements; }; -SQUIDCEXTERN int splayLastResult; +extern int splayLastResult; template SplayNode::SplayNode(const Value &someData): data(someData), left(nullptr), right(nullptr), visitThreadUp(nullptr) {} diff --git a/include/util.h b/include/util.h index 32df6c32cc..e219f7ee4b 100644 --- a/include/util.h +++ b/include/util.h @@ -13,32 +13,16 @@ #include #endif -SQUIDCEXTERN void Tolower(char *); - -SQUIDCEXTERN double xpercent(double part, double whole); -SQUIDCEXTERN int xpercentInt(double part, double whole); -SQUIDCEXTERN double xdiv(double nom, double denom); - -SQUIDCEXTERN const char *xitoa(int num); -SQUIDCEXTERN const char *xint64toa(int64_t num); - -typedef struct { - size_t count; - size_t bytes; - size_t gb; -} gb_t; - -/* gb_type operations */ -#define gb_flush_limit (0x3FFFFFFF) -#define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; } -#define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; } -#define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; } -extern double gb_to_double(const gb_t *); -SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value); -extern const char *gb_to_str(const gb_t *); -extern void gb_flush(gb_t *); /* internal, do not use this */ - -SQUIDCEXTERN unsigned int RoundTo(const unsigned int num, const unsigned int what); +void Tolower(char *); + +double xpercent(double part, double whole); +int xpercentInt(double part, double whole); +double xdiv(double nom, double denom); + +const char *xitoa(int num); +const char *xint64toa(int64_t num); + +const char *double_to_str(char *buf, int buf_size, double value); #endif /* SQUID_INCLUDE_UTIL_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index de71e04379..02fd5e8d75 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -56,10 +56,9 @@ libmisccontainers_la_SOURCES = \ libmiscutil_la_SOURCES = \ $(SNPRINTFSOURCE) \ Splay.cc \ - getfullhostname.c \ heap.c \ radix.c \ - util.c + util.cc TESTS += tests/testRFC1738 diff --git a/lib/getfullhostname.c b/lib/getfullhostname.c deleted file mode 100644 index 24331b7d09..0000000000 --- a/lib/getfullhostname.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#include "squid.h" -#include "getfullhostname.h" - -#if HAVE_UNISTD_H -/* for gethostname() function */ -#include -#endif -#if HAVE_NETDB_H -/* for gethostbyname() */ -#include -#endif - -/* for RFC 2181 constants */ -#include "rfc2181.h" - -/* for xstrncpy() - may need breaking out of there. */ -#include "util.h" - -/** - * \retval nullptr An error occurred. - * \retval * The fully qualified name (FQDN) of the current host. - * Pointer is only valid until the next call to the - * gethost*() functions. - */ -const char * -getfullhostname(void) -{ - const struct hostent *hp = NULL; - // TODO: make this dynamic so the duration limit is flexible - static char buf[RFC2181_MAXHOSTNAMELEN + 1]; - - if (gethostname(buf, RFC2181_MAXHOSTNAMELEN) < 0) - return NULL; - // TODO: convert this to a getaddrinfo() call - if ((hp = gethostbyname(buf)) != NULL) - xstrncpy(buf, hp->h_name, RFC2181_MAXHOSTNAMELEN); - return buf; -} - diff --git a/lib/util.c b/lib/util.cc similarity index 61% rename from lib/util.c rename to lib/util.cc index 19dcb84370..07470963ed 100644 --- a/lib/util.c +++ b/lib/util.cc @@ -73,19 +73,6 @@ xint64toa(int64_t num) return buf; } -void -gb_flush(gb_t * g) -{ - g->gb += (g->bytes >> 30); - g->bytes &= (1 << 30) - 1; -} - -double -gb_to_double(const gb_t * g) -{ - return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); -} - const char * double_to_str(char *buf, int buf_size, double value) { @@ -101,38 +88,3 @@ double_to_str(char *buf, int buf_size, double value) return buf; } -const char * -gb_to_str(const gb_t * g) -{ - /* - * it is often convenient to call gb_to_str several times for _one_ printf - */ -#define max_cc_calls 5 - typedef char GbBuf[32]; - static GbBuf bufs[max_cc_calls]; - static int call_id = 0; - double value = gb_to_double(g); - char *buf = bufs[call_id++]; - - if (call_id >= max_cc_calls) - call_id = 0; - - /* select format */ - if (value < 1e9) - snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); - else if (value < 1e12) - snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); - else - snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); - - return buf; -} - -/** - * rounds num to the next upper integer multiple of what - */ -unsigned int RoundTo(const unsigned int num, const unsigned int what) -{ - return what * ((num + what -1)/what); -} - diff --git a/src/acl/external/kerberos_ldap_group/support.h b/src/acl/external/kerberos_ldap_group/support.h index d2b66a186f..3073b8cd8a 100644 --- a/src/acl/external/kerberos_ldap_group/support.h +++ b/src/acl/external/kerberos_ldap_group/support.h @@ -93,7 +93,7 @@ struct main_args { char *principal; }; -SQUIDCEXTERN int log_enabled; +extern int log_enabled; /* the macro overload style is really a gcc-ism */ #ifdef __GNUC__ diff --git a/src/client_side.h b/src/client_side.h index 62ed67605b..4a67203f75 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -526,9 +526,9 @@ void clientPackRangeHdr(const HttpReplyPointer &, const HttpHdrRangeSpec *, Stri void clientPackTermBound(String boundary, MemBuf *); /* misplaced declaratrions of Stream callbacks provided/used by client side */ -SQUIDCEXTERN CSR clientGetMoreData; -SQUIDCEXTERN CSS clientReplyStatus; -SQUIDCEXTERN CSD clientReplyDetach; +CSR clientGetMoreData; +CSS clientReplyStatus; +CSD clientReplyDetach; CSCB clientSocketRecipient; CSD clientSocketDetach; diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index b3c80b6779..ef9e05a0f5 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -52,7 +52,7 @@ CBDATA_CLASS_INIT(clientReplyContext); /* Local functions */ -extern "C" CSS clientReplyStatus; +CSS clientReplyStatus; ErrorState *clientBuildError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const AccessLogEntry::Pointer &); /* privates */ @@ -500,8 +500,8 @@ clientReplyContext::handleIMSReply(const StoreIOBuffer result) sendClientOldEntry(); } -SQUIDCEXTERN CSR clientGetMoreData; -SQUIDCEXTERN CSD clientReplyDetach; +CSR clientGetMoreData; +CSD clientReplyDetach; /// \copydoc clientReplyContext::cacheHit() void diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 62a0cba182..b80b1b2305 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -99,9 +99,9 @@ static void clientInterpretRequestHeaders(ClientHttpRequest * http); static HLPCB clientRedirectDoneWrapper; static HLPCB clientStoreIdDoneWrapper; static void checkNoCacheDoneWrapper(Acl::Answer, void *); -SQUIDCEXTERN CSR clientGetMoreData; -SQUIDCEXTERN CSS clientReplyStatus; -SQUIDCEXTERN CSD clientReplyDetach; +CSR clientGetMoreData; +CSS clientReplyStatus; +CSD clientReplyDetach; static void checkFailureRatio(err_type, hier_code); ClientRequestContext::~ClientRequestContext() diff --git a/src/dns/rfc1035.h b/src/dns/rfc1035.h index f86ac0fa07..98afbd5dae 100644 --- a/src/dns/rfc1035.h +++ b/src/dns/rfc1035.h @@ -69,26 +69,26 @@ struct _rfc1035_message { rfc1035_rr *answer; }; -SQUIDCEXTERN ssize_t rfc1035BuildAQuery(const char *hostname, +ssize_t rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz); -SQUIDCEXTERN ssize_t rfc1035BuildPTRQuery(const struct in_addr, +ssize_t rfc1035BuildPTRQuery(const struct in_addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz); -SQUIDCEXTERN void rfc1035SetQueryID(char *, unsigned short qid); -SQUIDCEXTERN int rfc1035MessageUnpack(const char *buf, +void rfc1035SetQueryID(char *, unsigned short qid); +int rfc1035MessageUnpack(const char *buf, size_t sz, rfc1035_message ** answer); -SQUIDCEXTERN int rfc1035QueryCompare(const rfc1035_query *, const rfc1035_query *); -SQUIDCEXTERN void rfc1035RRDestroy(rfc1035_rr ** rr, int n); -SQUIDCEXTERN void rfc1035MessageDestroy(rfc1035_message ** message); -SQUIDCEXTERN const char * rfc1035ErrorMessage(int n); +int rfc1035QueryCompare(const rfc1035_query *, const rfc1035_query *); +void rfc1035RRDestroy(rfc1035_rr ** rr, int n); +void rfc1035MessageDestroy(rfc1035_message ** message); +const char * rfc1035ErrorMessage(int n); #define RFC1035_TYPE_A 1 #define RFC1035_TYPE_CNAME 5 @@ -96,19 +96,19 @@ SQUIDCEXTERN const char * rfc1035ErrorMessage(int n); #define RFC1035_CLASS_IN 1 /* Child Library RFC3596 Depends on some otherwise internal functions */ -SQUIDCEXTERN int rfc1035HeaderPack(char *buf, +int rfc1035HeaderPack(char *buf, size_t sz, rfc1035_message * hdr); -SQUIDCEXTERN int rfc1035HeaderUnpack(const char *buf, +int rfc1035HeaderUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_message * h); -SQUIDCEXTERN int rfc1035QuestionPack(char *buf, +int rfc1035QuestionPack(char *buf, size_t sz, const char *name, const unsigned short type, const unsigned short _class); -SQUIDCEXTERN int rfc1035RRPack(char *buf, size_t sz, const rfc1035_rr * RR); +int rfc1035RRPack(char *buf, size_t sz, const rfc1035_rr * RR); #endif /* SQUID_SRC_DNS_RFC1035_H */ diff --git a/src/dns/rfc2671.h b/src/dns/rfc2671.h index 1c6695f912..25d3ce858c 100644 --- a/src/dns/rfc2671.h +++ b/src/dns/rfc2671.h @@ -12,7 +12,7 @@ /* RFC2671 section 7 defines new RR type OPT as 41 */ #define RFC1035_TYPE_OPT 41 -SQUIDCEXTERN int rfc2671RROptPack(char *buf, size_t sz, ssize_t edns_sz); +int rfc2671RROptPack(char *buf, size_t sz, ssize_t edns_sz); #endif /* SQUID_SRC_DNS_RFC2671_H */ diff --git a/src/dns/rfc3596.h b/src/dns/rfc3596.h index 20f114687e..6e10b11e6e 100644 --- a/src/dns/rfc3596.h +++ b/src/dns/rfc3596.h @@ -12,28 +12,28 @@ /* RFC 3596 extends RFC 1035 */ #include "dns/rfc1035.h" -SQUIDCEXTERN ssize_t rfc3596BuildAQuery(const char *hostname, +ssize_t rfc3596BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz); -SQUIDCEXTERN ssize_t rfc3596BuildAAAAQuery(const char *hostname, +ssize_t rfc3596BuildAAAAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz); -SQUIDCEXTERN ssize_t rfc3596BuildPTRQuery4(const struct in_addr, +ssize_t rfc3596BuildPTRQuery4(const struct in_addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz); -SQUIDCEXTERN ssize_t rfc3596BuildPTRQuery6(const struct in6_addr, +ssize_t rfc3596BuildPTRQuery6(const struct in6_addr, char *buf, size_t sz, unsigned short qid, @@ -41,7 +41,7 @@ SQUIDCEXTERN ssize_t rfc3596BuildPTRQuery6(const struct in6_addr, ssize_t edns_sz); /* RFC3596 library implements RFC1035 generic host interface */ -SQUIDCEXTERN ssize_t rfc3596BuildHostQuery(const char *hostname, +ssize_t rfc3596BuildHostQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, diff --git a/src/peer_proxy_negotiate_auth.h b/src/peer_proxy_negotiate_auth.h index a7a4b78c5f..f5c592cba2 100644 --- a/src/peer_proxy_negotiate_auth.h +++ b/src/peer_proxy_negotiate_auth.h @@ -14,7 +14,7 @@ #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI /* upstream proxy authentication */ -SQUIDCEXTERN char *peer_proxy_negotiate_auth(char *principal_name, char *proxy, int flags); +char *peer_proxy_negotiate_auth(char *principal_name, char *proxy, int flags); #endif #endif /* SQUID_SRC_PEER_PROXY_NEGOTIATE_AUTH_H */