]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Remove unnecessary C linkage and unused code (#1677)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Thu, 15 Feb 2024 13:24:21 +0000 (13:24 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 15 Feb 2024 17:28:17 +0000 (17:28 +0000)
Also upgrade lib/util.c to C++.

19 files changed:
compat/Makefile.am
compat/debug.h
compat/strnrchr.c [deleted file]
compat/strnrchr.h [deleted file]
include/getfullhostname.h [deleted file]
include/hash.h
include/splay.h
include/util.h
lib/Makefile.am
lib/getfullhostname.c [deleted file]
lib/util.cc [moved from lib/util.c with 61% similarity]
src/acl/external/kerberos_ldap_group/support.h
src/client_side.h
src/client_side_reply.cc
src/client_side_request.cc
src/dns/rfc1035.h
src/dns/rfc2671.h
src/dns/rfc3596.h
src/peer_proxy_negotiate_auth.h

index 510eb24848b1b0c754d70f52251f91dfdd59c4ab..e4200d111043ef16e9ec50c542a36de9dea56242 100644 (file)
@@ -69,8 +69,6 @@ libcompatsquid_la_SOURCES = \
        statvfs.h \
        stdio.h \
        stdvarargs.h \
-       strnrchr.c \
-       strnrchr.h \
        strnstr.cc \
        strtoll.h \
        tempnam.h \
index 241aba762859093aeaad183e04ab01e8cf35b1d2..feb3139db57090efd26ab52bc545f6792edc1db2 100644 (file)
@@ -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 (file)
index 186a7d9..0000000
+++ /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 (file)
index 7e89d6b..0000000
+++ /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 <stddef.h>
-#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 (file)
index f015821..0000000
+++ /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 */
-
index c1257127ad30614bead78c8ad41ed01207411b2d..cf6326be0d1394c77410c1f996044444e07236f3 100644 (file)
@@ -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
index 2e03079ec45321aa0ace13860a127ca1e97d4f72..a905a8514711dfd2e292947dc107ae2ebcaf832f 100644 (file)
@@ -92,7 +92,7 @@ private:
     size_t elements;
 };
 
-SQUIDCEXTERN int splayLastResult;
+extern int splayLastResult;
 
 template<class V>
 SplayNode<V>::SplayNode(const Value &someData): data(someData), left(nullptr), right(nullptr), visitThreadUp(nullptr) {}
index 32df6c32cc1545d24b6535623c0a6ccf078eb35a..e219f7ee4baa1671beb03d199c423e25c64630ef 100644 (file)
 #include <arpa/inet.h>
 #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 */
 
index de71e04379d8c35182eea8d36a1b3d4bd4e0ae6c..02fd5e8d75e1a539e0dc2f93e39485477bbc6219 100644 (file)
@@ -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 (file)
index 24331b7..0000000
+++ /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 <unistd.h>
-#endif
-#if HAVE_NETDB_H
-/* for gethostbyname() */
-#include <netdb.h>
-#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;
-}
-
similarity index 61%
rename from lib/util.c
rename to lib/util.cc
index 19dcb84370ee5bba3a1c64bb6b015826f114c31e..07470963ed249c0982c0b3124b50bcde8bfd979f 100644 (file)
@@ -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);
-}
-
index d2b66a186f87df61d4593bd2c2b4489b569dfb2d..3073b8cd8ab19222617b7906b4cf8cd89386e272 100644 (file)
@@ -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__
index 62ed67605b9093aff649754b6fc7e47d8a576b12..4a67203f75a56991082ac5c601fd14f435295660 100644 (file)
@@ -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;
 
index b3c80b6779a32d603200d859a3083d63fb602248..ef9e05a0f54c75d2b14a593b0d23dc0f11014783 100644 (file)
@@ -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
index 62a0cba182885fe56bebbb90378a968bba124ee0..b80b1b23057b6e5f60a76222ba37dd43c7272d83 100644 (file)
@@ -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()
index f86ac0fa07903fc935418a4487dafff5ed7123f9..98afbd5daedcfd5541691af91e5d3e74f4971d95 100644 (file)
@@ -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 */
 
index 1c6695f9127e6fb9df096b7faa380bf420ef87a0..25d3ce858c2077f96e6e090d05218ff21c271c6f 100644 (file)
@@ -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 */
 
index 20f114687ea98ec7deb5d7b6868ae4f4c319f1c3..6e10b11e6e7fc27cb13c90c01e5fc8e8bf13e58e 100644 (file)
 /* 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,
index a7a4b78c5f2cd97150009d25019a4e974855733c..f5c592cba2e8986149dfed9472e1378401d81b2e 100644 (file)
@@ -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 */