MinGW compiler is a bit more limited than most GCC or Clang available.
The types used on Windows for some API declarations differ from those
commonly used on Linux/BSD systems.
TODO: There are additional compile issues to resolve.
#ifndef SQUID_ASSERT_H
#define SQUID_ASSERT_H
-#if defined(NODEBUG)
+#if PURIFY
+#define assert(EX) ((void)0)
+#elif defined(NODEBUG)
#define assert(EX) ((void)0)
#elif STDC_HEADERS
#define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
struct base64_encode_ctx ctx;
base64_encode_init(&ctx);
static char encoded[8192];
- size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, fResult);
+ size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(fResult));
assert(dstLen < sizeof(encoded));
dstLen += base64_encode_final(&ctx, encoded+dstLen);
assert(dstLen < sizeof(encoded));
encoded[dstLen] = '\0';
- return reinterpret_cast<char *>(encoded);
+ return encoded;
}
return NULL;
}
struct base64_encode_ctx ctx;
base64_encode_init(&ctx);
static char encoded[8192];
- size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, pServerBuf);
+ size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(pServerBuf));
assert(dstLen < sizeof(encoded));
dstLen += base64_encode_final(&ctx, encoded+dstLen);
assert(dstLen < sizeof(encoded));
encoded[dstLen] = '\0';
- return reinterpret_cast<char *>(encoded);
+ return encoded;
}
return NULL;
}
struct base64_encode_ctx ctx;
base64_encode_init(&ctx);
static char encoded[8192];
- size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, pServerBuf);
+ size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(pServerBuf));
assert(dstLen < sizeof(encoded));
dstLen += base64_encode_final(&ctx, encoded+dstLen);
assert(dstLen < sizeof(encoded));
encoded[dstLen] = '\0';
- return reinterpret_cast<char *>(encoded);
+ return encoded;
}
return NULL;
}
/* Create threads and get them to sit in their wait loop */
squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));
- assert(NUMTHREADS);
+ assert(NUMTHREADS > 0);
for (i = 0; i < NUMTHREADS; ++i) {
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
}
int
-matchDomainName(const char *h, const char *d, uint8_t flags)
+matchDomainName(const char *h, const char *d, MatchDomainNameFlags flags)
{
int dl;
int hl;
* \retval 1 means the host is greater than the domain
* \retval -1 means the host is less than the domain
*/
-int matchDomainName(const char *host, const char *domain, uint8_t flags = mdnNone);
+int matchDomainName(const char *host, const char *domain, MatchDomainNameFlags flags = mdnNone);
int urlCheckRequest(const HttpRequest *);
char *urlHostname(const char *url);
void urlExtMethodConfigure(void);
{
struct base64_decode_ctx ctx;
base64_decode_init(&ctx);
- if (!base64_decode_update(&ctx, decodedLen, decoded, strlen(buf), reinterpret_cast<const uint8_t*>(buf)) ||
+ if (!base64_decode_update(&ctx, decodedLen, decoded, strlen(buf), buf) ||
!base64_decode_final(&ctx)) {
SEND("BH base64 decode failed");
fprintf(stderr, "ERROR: base64 decoding failed for: '%s'\n", buf);
{
struct base64_decode_ctx ctx;
base64_decode_init(&ctx);
- if (!base64_decode_update(&ctx, decodedLen, decoded, strlen(buf), reinterpret_cast<const uint8_t*>(buf)) ||
+ if (!base64_decode_update(&ctx, decodedLen, decoded, strlen(buf), buf) ||
!base64_decode_final(&ctx)) {
SEND_BH("message=\"base64 decode failed\"");
fprintf(stderr, "ERROR: base64 decoding failed for: '%s'\n", buf);
fd_ = CreateFile(TEXT(name_.c_str()), cfg.desiredAccess, cfg.shareMode, nullptr, cfg.creationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fd_ == InvalidHandle) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("CreateFile", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("CreateFile", WindowsErrorMessage(savedError)));
}
#else
mode_t oldCreationMask = 0;
#if _SQUID_WINDOWS_
if (!CloseHandle(fd_)) {
const auto savedError = GetLastError();
- debugs(54, DBG_IMPORTANT, sysCallFailure("CloseHandle", WindowsErrorMessage(savedError).c_str()));
+ debugs(54, DBG_IMPORTANT, sysCallFailure("CloseHandle", WindowsErrorMessage(savedError)));
}
#else
if (::close(fd_) != 0) {
#if _SQUID_WINDOWS_
if (!SetFilePointer(fd_, 0, nullptr, FILE_BEGIN)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("SetFilePointer", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("SetFilePointer", WindowsErrorMessage(savedError)));
}
if (!SetEndOfFile(fd_)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("SetEndOfFile", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("SetEndOfFile", WindowsErrorMessage(savedError)));
}
#else
if (::lseek(fd_, SEEK_SET, 0) < 0) {
DWORD result = 0;
if (!ReadFile(fd_, rawBuf, readLimit, &result, nullptr)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("ReadFile", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("ReadFile", WindowsErrorMessage(savedError)));
}
#else
const auto result = ::read(fd_, rawBuf, readLimit);
buf.rawAppendFinish(rawBuf, bytesRead);
if (buf.length() < minBytes) {
- const auto failure = buf.length() ? "premature eof" : "empty file";
- throw TexcHere(sysCallFailure("read", failure));
+ static const SBuf errPrematureEof("premature eof");
+ static const SBuf errEmptyFile("empty file");
+ throw TexcHere(sysCallFailure("read", buf.length() ? errPrematureEof : errEmptyFile));
}
if (buf.length() > maxBytes) {
- const auto failure = "unreasonably large file";
+ static const SBuf failure("unreasonably large file");
throw TexcHere(sysCallFailure("read", failure));
}
DWORD nBytesWritten = 0;
if (!WriteFile(fd_, data.rawContent(), data.length(), &nBytesWritten, nullptr)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("WriteFile", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("WriteFile", WindowsErrorMessage(savedError)));
}
const auto bytesWritten = static_cast<size_t>(nBytesWritten);
#else
}
const auto bytesWritten = static_cast<size_t>(result);
#endif
- if (bytesWritten != data.length())
- throw TexcHere(sysCallFailure("write", "partial write"));
+ if (bytesWritten != data.length()) {
+ static const SBuf failure("partial write");
+ throw TexcHere(sysCallFailure("write", failure));
+ }
}
void
#if _SQUID_WINDOWS_
if (!FlushFileBuffers(fd_)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("FlushFileBuffers", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("FlushFileBuffers", WindowsErrorMessage(savedError)));
}
#else
if (::fsync(fd_) != 0) {
#if _SQUID_WINDOWS_
if (!LockFileEx(fd_, cfg.lockFlags, 0, 0, 1, 0)) {
const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("LockFileEx", WindowsErrorMessage(savedError).c_str()));
+ throw TexcHere(sysCallFailure("LockFileEx", WindowsErrorMessage(savedError)));
}
#elif _SQUID_SOLARIS_
if (fcntlLock(fd_, cfg.lockType) != 0) {
/// \returns a description a system call-related failure
SBuf
-File::sysCallFailure(const char *callName, const char *error) const
+File::sysCallFailure(const char *callName, const SBuf &error) const
{
return ToSBuf("failed to ", callName, ' ', name_, ": ", error);
}
SBuf
File::sysCallError(const char *callName, const int savedErrno) const
{
- return sysCallFailure(callName, xstrerr(savedErrno));
+ return sysCallFailure(callName, SBuf(xstrerr(savedErrno)));
}
#if _SQUID_WINDOWS_
void close();
/// \returns a description a system call-related failure
- SBuf sysCallFailure(const char *callName, const char *error) const;
+ SBuf sysCallFailure(const char *callName, const SBuf &error) const;
/// \returns a description of an errno-based system call failure
SBuf sysCallError(const char *callName, const int savedErrno) const;
char *urlMakeAbsolute(const HttpRequest *, const char *)STUB_RETVAL(nullptr)
char *urlRInternal(const char *, unsigned short, const char *, const char *) STUB_RETVAL(nullptr)
char *urlInternal(const char *, const char *) STUB_RETVAL(nullptr)
-int matchDomainName(const char *, const char *, uint) STUB_RETVAL(0)
+int matchDomainName(const char *, const char *, enum MatchDomainNameFlags) STUB_RETVAL(0)
int urlCheckRequest(const HttpRequest *) STUB_RETVAL(0)
char *urlHostname(const char *) STUB_RETVAL(nullptr)
void urlExtMethodConfigure() STUB