Also upgrade lib/util.c to C++.
statvfs.h \
stdio.h \
stdvarargs.h \
- strnrchr.c \
- strnrchr.h \
strnstr.cc \
strtoll.h \
tempnam.h \
/* 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)
+++ /dev/null
-/*
- * 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;
-}
-
+++ /dev/null
-/*
- * 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 */
-
+++ /dev/null
-/*
- * 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 */
-
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
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) {}
#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 */
libmiscutil_la_SOURCES = \
$(SNPRINTFSOURCE) \
Splay.cc \
- getfullhostname.c \
heap.c \
radix.c \
- util.c
+ util.cc
TESTS += tests/testRFC1738
+++ /dev/null
-/*
- * 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;
-}
-
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)
{
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);
-}
-
char *principal;
};
-SQUIDCEXTERN int log_enabled;
+extern int log_enabled;
/* the macro overload style is really a gcc-ism */
#ifdef __GNUC__
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;
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 */
sendClientOldEntry();
}
-SQUIDCEXTERN CSR clientGetMoreData;
-SQUIDCEXTERN CSD clientReplyDetach;
+CSR clientGetMoreData;
+CSD clientReplyDetach;
/// \copydoc clientReplyContext::cacheHit()
void
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()
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
#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 */
/* 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 */
/* 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,
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,
#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 */