diff --git a/CMakeLists.txt b/CMakeLists.txt index f7628cb14..a9dc180a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,7 +219,7 @@ endif(MSVC) set(OPENSSL_COMPILE_FLAGS -DWINSCP -DMK1MF_BUILD -DWIN32_LEAN_AND_MEAN -DVC_EXTRALEAN -DSECURITY_WIN32 - # -DOPENSSL_NO_LOCKING + # -DOPENSSL_NO_LOCKING -DDSO_WIN32 -DL_ENDIAN -D_stricmp=stricmp -D_strnicmp=strnicmp -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS @@ -227,9 +227,8 @@ set(OPENSSL_COMPILE_FLAGS -DOPENSSL_NO_WHIRLPOOL -DOPENSSL_NO_SEED -DOPENSSL_NO_ENGINE -DOPENSSL_NO_DYNAMIC_ENGINE - -DOPENSSL_NO_QUIC - -DOPENSSL_NO_BROTLI - -DOPENSSL_NO_COMP + -DOPENSSL_NO_QUIC -DOPENSSL_NO_BROTLI -DOPENSSL_NO_COMP -DOPENSSL_NO_COMP_ALG + -DOPENSSL_NO_TFO -DOPENSSL_NO_ASYNC -DOPENSSL_NO_ERR -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_DEPRECATED_3_0 @@ -1016,7 +1015,8 @@ set(libeay32_c_files libs/openssl-3/crypto/async/async.c libs/openssl-3/crypto/async/async_err.c libs/openssl-3/crypto/async/async_wait.c - libs/openssl-3/crypto/async/arch/async_win.c + # libs/openssl-3/crypto/async/arch/async_win.c + libs/openssl-3/crypto/async/arch/async_null.c libs/openssl-3/crypto/kdf/hkdf.c libs/openssl-3/crypto/kdf/tls1_prf.c libs/openssl-3/crypto/kdf/kdf_err.c diff --git a/libs/expat/expat_config.h b/libs/expat/expat_config.h index 882f90755..fa632c4cf 100644 --- a/libs/expat/expat_config.h +++ b/libs/expat/expat_config.h @@ -17,6 +17,9 @@ // WINSCP /* #undef HAVE_ARC4RANDOM_BUF */ +/* define if the compiler supports basic C++11 syntax */ +#define HAVE_CXX11 1 + /* Define to 1 if you have the header file. */ #define HAVE_DLFCN_H 1 @@ -75,13 +78,13 @@ #define PACKAGE "expat" /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "expat-bugs@libexpat.org" +#define PACKAGE_BUGREPORT "https://github.com/libexpat/libexpat/issues" /* Define to the full name of this package. */ #define PACKAGE_NAME "expat" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "expat 2.5.0" +#define PACKAGE_STRING "expat 2.6.1" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "expat" @@ -90,7 +93,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "2.5.0" +#define PACKAGE_VERSION "2.6.1" /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for @@ -98,7 +101,7 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "2.5.0" +#define VERSION "2.6.1" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ @@ -117,7 +120,7 @@ /* #undef XML_ATTR_INFO */ /* Define to specify how much context to retain around the current parse - point. */ + point, 0 to disable. */ #define XML_CONTEXT_BYTES 1024 /* Define to include code reading entropy from `/dev/urandom'. */ diff --git a/libs/expat/lib/expat.h b/libs/expat/lib/expat.h index 95464b0dd..6dfc45448 100644 --- a/libs/expat/lib/expat.h +++ b/libs/expat/lib/expat.h @@ -18,6 +18,7 @@ Copyright (c) 2022 Thijs Schreijer Copyright (c) 2023 Hanno Böck Copyright (c) 2023 Sony Corporation / Snild Dolkow + Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -1042,7 +1043,7 @@ typedef struct { XMLPARSEAPI(const XML_Feature *) XML_GetFeatureList(void); -#if XML_GE == 1 +#if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1) /* Added in Expat 2.4.0 for XML_DTD defined and * added in Expat 2.6.0 for XML_GE == 1. */ XMLPARSEAPI(XML_Bool) @@ -1065,7 +1066,7 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled); */ #define XML_MAJOR_VERSION 2 #define XML_MINOR_VERSION 6 -#define XML_MICRO_VERSION 0 +#define XML_MICRO_VERSION 1 #ifdef __cplusplus } diff --git a/libs/expat/lib/internal.h b/libs/expat/lib/internal.h index cce71e4c5..167ec3680 100644 --- a/libs/expat/lib/internal.h +++ b/libs/expat/lib/internal.h @@ -28,10 +28,11 @@ Copyright (c) 2002-2003 Fred L. Drake, Jr. Copyright (c) 2002-2006 Karl Waclawek Copyright (c) 2003 Greg Stein - Copyright (c) 2016-2023 Sebastian Pipping + Copyright (c) 2016-2024 Sebastian Pipping Copyright (c) 2018 Yury Gribov Copyright (c) 2019 David Loffredo - Copyright (c) 2023 Sony Corporation / Snild Dolkow + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow + Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -155,14 +156,20 @@ extern "C" { void _INTERNAL_trim_to_complete_utf8_characters(const char *from, const char **fromLimRef); -#if XML_GE == 1 +#if defined(XML_GE) && XML_GE == 1 unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); const char *unsignedCharToPrintable(unsigned char c); #endif -extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c -extern unsigned int g_parseAttempts; // used for testing only +extern +#if ! defined(XML_TESTING) + const +#endif + XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c +#if defined(XML_TESTING) +extern unsigned int g_bytesScanned; // used for testing only +#endif #ifdef __cplusplus } diff --git a/libs/expat/lib/winconfig.h b/libs/expat/lib/winconfig.h index 05805514e..617633130 100644 --- a/libs/expat/lib/winconfig.h +++ b/libs/expat/lib/winconfig.h @@ -44,5 +44,9 @@ #include #include +#include +#ifndef isnan +#define isnan _isnan +#endif #endif /* ndef WINCONFIG_H */ diff --git a/libs/expat/lib/xmlparse.c b/libs/expat/lib/xmlparse.c index aaf0fa9c8..153b77218 100644 --- a/libs/expat/lib/xmlparse.c +++ b/libs/expat/lib/xmlparse.c @@ -1,4 +1,4 @@ -/* 628e24d4966bedbd4800f6ed128d06d29703765b4bce12d3b7f099f90f842fc9 (2.6.0+) +/* dd2a9703e301882afe16d198a82689ab225277057f5eab9d079d8606eab736b4 (2.6.1+) __ __ _ ___\ \/ /_ __ __ _| |_ / _ \\ /| '_ \ / _` | __| @@ -38,7 +38,7 @@ Copyright (c) 2022 Jann Horn Copyright (c) 2022 Sean McBride Copyright (c) 2023 Owain Davies - Copyright (c) 2023 Sony Corporation / Snild Dolkow + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -210,7 +210,7 @@ typedef char ICHAR; #endif /* Round up n to be a multiple of sz, where sz is a power of 2. */ -#define ROUND_UP(n, sz) (((n) + ((sz)-1)) & ~((sz)-1)) +#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) /* Do safe (NULL-aware) pointer arithmetic */ #define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) @@ -248,7 +248,7 @@ static void copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key); it odd, since odd numbers are always relative prime to a power of 2. */ #define SECOND_HASH(hash, mask, power) \ - ((((hash) & ~(mask)) >> ((power)-1)) & ((mask) >> 2)) + ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) #define PROBE_STEP(hash, mask, power) \ ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) @@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName, ? 0 \ : ((*((pool)->ptr)++ = c), 1)) -XML_Bool g_reparseDeferralEnabledDefault = XML_TRUE; // write ONLY in runtests.c -unsigned int g_parseAttempts = 0; // used for testing only +#if ! defined(XML_TESTING) +const +#endif + XML_Bool g_reparseDeferralEnabledDefault + = XML_TRUE; // write ONLY in runtests.c +#if defined(XML_TESTING) +unsigned int g_bytesScanned = 0; // used for testing only +#endif struct XML_ParserStruct { /* The first member must be m_userData so that the XML_GetUserData @@ -762,6 +768,12 @@ XML_ParserCreate(const XML_Char *encodingName) { XML_Parser XMLCALL XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) { XML_Char tmp[2] = {nsSep, 0}; +#if defined(__BORLANDC__) + // WINSCP + XML_Char tmp[2]; + tmp[0] = nsSep; + tmp[1] = 0; +#endif // defined(__BORLANDC__) return XML_ParserCreate_MM(encodingName, NULL, tmp); } @@ -868,6 +880,10 @@ writeRandomBytes_arc4random(void *target, size_t count) { #ifdef _WIN32 +// WINSCP - See writeRandomBytes_rand_s +typedef BOOLEAN (APIENTRY *RTLGENRANDOM_FUNC)(PVOID, ULONG); +HMODULE _Expat_LoadLibrary(LPCTSTR filename); /* see loadlibrary.c */ + /* Provide declaration of rand_s() for MinGW-32 (not 64, which has it), as it didn't declare it in its header prior to version 5.3.0 of its runtime package (mingwrt, containing stdlib.h). The upstream fix @@ -883,22 +899,22 @@ __declspec(dllimport) int rand_s(unsigned int *); */ static int writeRandomBytes_rand_s(void *target, size_t count) { - size_t bytesWrittenTotal = 0; - - while (bytesWrittenTotal < count) { - unsigned int random32 = 0; - size_t i = 0; - - if (rand_s(&random32)) - return 0; /* failure */ - - for (; (i < sizeof(random32)) && (bytesWrittenTotal < count); - i++, bytesWrittenTotal++) { - const uint8_t random8 = (uint8_t)(random32 >> (i * 8)); - ((uint8_t *)target)[bytesWrittenTotal] = random8; + // WINSCP, we do not have rand_s in C++ Builder + int success = 0; /* full count bytes written? */ + const HMODULE advapi32 = _Expat_LoadLibrary(TEXT("ADVAPI32.DLL")); + + if (advapi32) { + const RTLGENRANDOM_FUNC RtlGenRandom + = (RTLGENRANDOM_FUNC)GetProcAddress(advapi32, "SystemFunction036"); + if (RtlGenRandom) { + if (RtlGenRandom((PVOID)target, (ULONG)count) == TRUE) { + success = 1; + } } + FreeLibrary(advapi32); } - return 1; /* success */ + + return success; } #endif /* _WIN32 */ @@ -1008,6 +1024,7 @@ callProcessor(XML_Parser parser, const char *start, const char *end, available_buffer += EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd); // m_lastBufferRequestSize is never assigned a value < 0, so the cast is ok + { // WINSCP const bool enough = (have_now >= 2 * had_before) || ((size_t)parser->m_lastBufferRequestSize > available_buffer); @@ -1016,8 +1033,12 @@ callProcessor(XML_Parser parser, const char *start, const char *end, *endPtr = start; // callers may expect this to be set return XML_ERROR_NONE; } + } // WINSCP } - g_parseAttempts += 1; +#if defined(XML_TESTING) + g_bytesScanned += (unsigned)have_now; +#endif + { // WINSCP const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr); if (ret == XML_ERROR_NONE) { // if we consumed nothing, remember what we had on this parse attempt. @@ -1028,6 +1049,7 @@ callProcessor(XML_Parser parser, const char *start, const char *end, } } return ret; + } // WINSCP } static XML_Bool /* only valid for root parser */ @@ -1441,7 +1463,10 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, would be otherwise. */ if (parser->m_ns) { - XML_Char tmp[2] = {parser->m_namespaceSeparator, 0}; + // WINSCP + XML_Char tmp[2]; + tmp[0] = parser->m_namespaceSeparator; + tmp[1] = 0; parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); } else { parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); @@ -2013,6 +2038,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { return result; } #endif /* XML_CONTEXT_BYTES == 0 */ + { // WINSCP void *buff = XML_GetBuffer(parser, len); if (buff == NULL) return XML_STATUS_ERROR; @@ -2021,6 +2047,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { memcpy(buff, s, len); } return XML_ParseBuffer(parser, len, isFinal); + } // WINSCP } enum XML_Status XMLCALL @@ -3536,6 +3563,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, return XML_ERROR_NO_MEMORY; } + { // WINSCP unsigned int nsAttsSize = 1u << parser->m_nsAttsPower; unsigned char oldNsAttsPower = parser->m_nsAttsPower; /* size of hash table must be at least 2 * (# of prefixed attributes) */ @@ -3692,6 +3720,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, } else /* not prefixed */ ((XML_Char *)s)[-1] = 0; /* clear flag */ } + } // WINSCP } /* clear flags for the remaining attributes */ for (; i < attIndex; i += 2) @@ -3997,12 +4026,14 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, } #endif + { // WINSCP XML_Char *temp = (XML_Char *)REALLOC( parser, b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE)); if (temp == NULL) return XML_ERROR_NO_MEMORY; b->uri = temp; b->uriAlloc = len + EXPAND_SPARE; + } // WINSCP } parser->m_freeBindingList = b->nextTagBinding; } else { @@ -4703,6 +4734,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, UNUSED_P(account); #endif + { // WINSCP /* save one level of indirection */ DTD *const dtd = parser->m_dtd; @@ -5389,6 +5421,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, return XML_ERROR_NO_MEMORY; } + { // WINSCP char *const new_connector = (char *)REALLOC( parser, parser->m_groupConnector, parser->m_groupSize *= 2); if (new_connector == NULL) { @@ -5396,6 +5429,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, return XML_ERROR_NO_MEMORY; } parser->m_groupConnector = new_connector; + } // WINSCP } if (dtd->scaffIndex) { @@ -5409,11 +5443,13 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, } #endif + { // WINSCP int *const new_scaff_index = (int *)REALLOC( parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int)); if (new_scaff_index == NULL) return XML_ERROR_NO_MEMORY; dtd->scaffIndex = new_scaff_index; + } // WINSCP } } else { parser->m_groupConnector @@ -5731,6 +5767,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, tok = XmlPrologTok(enc, s, end, &next); } } + } // WINSCP /* not reached */ } @@ -6530,6 +6567,7 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, return 0; } + { // WINSCP int count = type->allocDefaultAtts * 2; /* Detect and prevent integer overflow. @@ -6548,6 +6586,7 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, return 0; type->allocDefaultAtts = count; type->defaultAtts = temp; + } // WINSCP } } att = type->defaultAtts + type->nDefaultAtts; @@ -6754,6 +6793,7 @@ setContext(XML_Parser parser, const XML_Char *context) { return XML_FALSE; } + { // WINSCP DTD *const dtd = parser->m_dtd; /* save one level of indirection */ const XML_Char *s = context; @@ -6810,6 +6850,7 @@ setContext(XML_Parser parser, const XML_Char *context) { } } return XML_TRUE; + } // WINSCP } static void FASTCALL @@ -7202,6 +7243,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { return NULL; } + { // WINSCP size_t newSize = (size_t)1 << newPower; unsigned long newMask = (unsigned long)newSize - 1; @@ -7210,6 +7252,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { return NULL; } + { // WINSCP size_t tsize = newSize * sizeof(NAMED *); NAMED **newV = table->mem->malloc_fcn(tsize); if (! newV) @@ -7238,6 +7281,8 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { step = PROBE_STEP(h, newMask, newPower); i < step ? (i += newSize - step) : (i -= step); } + } // WINSCP + } // WINSCP } } table->v[i] = table->mem->malloc_fcn(createSize); @@ -7631,6 +7676,7 @@ build_model(XML_Parser parser) { return NULL; } + { // WINSCP const size_t allocsize = (dtd->scaffCount * sizeof(XML_Content) + (dtd->contentStringLen * sizeof(XML_Char))); @@ -7687,6 +7733,7 @@ build_model(XML_Parser parser) { * * - The algorithm repeats until all target array indices have been processed. */ + { // WINSCP XML_Content *dest = ret; /* tree node writing location, moves upwards */ XML_Content *const destLimit = &ret[dtd->scaffCount]; XML_Content *jobDest = ret; /* next free writing location in target array */ @@ -7729,6 +7776,8 @@ build_model(XML_Parser parser) { } return ret; + } // WINSCP + } // WINSCP } static ELEMENT_TYPE * @@ -7800,6 +7849,7 @@ accountingReportStats(XML_Parser originParser, const char *epilog) { return; } + { // WINSCP const float amplificationFactor = accountingGetCurrentAmplification(rootParser); fprintf(stderr, @@ -7808,6 +7858,7 @@ accountingReportStats(XML_Parser originParser, const char *epilog) { (void *)rootParser, rootParser->m_accounting.countBytesDirect, rootParser->m_accounting.countBytesIndirect, (double)amplificationFactor, epilog); + } // WINSCP } static void @@ -7827,6 +7878,7 @@ accountingReportDiff(XML_Parser rootParser, bytesMore, (account == XML_ACCOUNT_DIRECT) ? "DIR" : "EXP", levelsAwayFromRootParser, source_line, 10, ""); + { // WINSCP const char ellipis[] = "[..]"; const size_t ellipsisLength = sizeof(ellipis) /* because compile-time */ - 1; const unsigned int contextLength = 10; @@ -7850,6 +7902,7 @@ accountingReportDiff(XML_Parser rootParser, } } fprintf(stderr, "\"\n"); + } // WINSCP } static XML_Bool @@ -7870,11 +7923,13 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before, if (account == XML_ACCOUNT_NONE) return XML_TRUE; /* because these bytes have been accounted for, already */ + { // WINSCP unsigned int levelsAwayFromRootParser; const XML_Parser rootParser = getRootParserOf(originParser, &levelsAwayFromRootParser); assert(! rootParser->m_parentParser); + { // WINSCP const int isDirect = (account == XML_ACCOUNT_DIRECT) && (originParser == rootParser); const ptrdiff_t bytesMore = after - before; @@ -7888,6 +7943,7 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before, return XML_FALSE; *additionTarget += bytesMore; + { // WINSCP const XmlBigCount countBytesOutput = rootParser->m_accounting.countBytesDirect + rootParser->m_accounting.countBytesIndirect; @@ -7905,6 +7961,9 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before, } return tolerated; + } // WINSCP + } // WINSCP + } // WINSCP } unsigned long long @@ -7928,6 +7987,7 @@ entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity, if (rootParser->m_entity_stats.debugLevel == 0u) return; + { // WINSCP # if defined(XML_UNICODE) const char *const entityName = "[..]"; # else @@ -7943,6 +8003,7 @@ entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity, (rootParser->m_entity_stats.currentDepth - 1) * 2, "", entity->is_param ? "%" : "&", entityName, action, entity->textLen, sourceLine); + } // WINSCP } static void @@ -8503,7 +8564,7 @@ unsignedCharToPrintable(unsigned char c) { assert(0); /* never gets here */ return "dead code"; } - assert(0); /* never gets here */ + // WINSCP assert(0); /* never gets here */ } #endif /* XML_GE == 1 */ @@ -8514,10 +8575,13 @@ getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) { if (valueOrNull == NULL) { return defaultDebugLevel; } + { // WINSCP const char *const value = valueOrNull; errno = 0; + { // WINSCP char *afterValue = NULL; + unsigned long debugLevel = strtoul(value, &afterValue, 10); if ((errno != 0) || (afterValue == value) || (afterValue[0] != '\0')) { errno = 0; @@ -8525,4 +8589,6 @@ getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) { } return debugLevel; + } // WINSCP + } // WINSCP } diff --git a/libs/expat/lib/xmltok_impl.c b/libs/expat/lib/xmltok_impl.c index 239a2d06c..4df9b782a 100644 --- a/libs/expat/lib/xmltok_impl.c +++ b/libs/expat/lib/xmltok_impl.c @@ -1779,8 +1779,12 @@ PREFIX(updatePosition)(const ENCODING *enc, const char *ptr, const char *end, POSITION *pos) { while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { +// The "if (end - ptr < n)" branch is a patch from chromium\third_party\expat\files\lib # define LEAD_CASE(n) \ case BT_LEAD##n: \ + if (end - ptr < n) { \ + return; \ + } \ ptr += n; /* NOTE: The encoding has already been validated. */ \ pos->columnNumber++; \ break; diff --git a/libs/tinylog/src/Buffer.cpp b/libs/tinylog/src/Buffer.cpp index f3a3cc379..6d984bbfb 100644 --- a/libs/tinylog/src/Buffer.cpp +++ b/libs/tinylog/src/Buffer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -19,78 +20,21 @@ Buffer::~Buffer() } /* - * Append time and log to buffer. + * Append data to the buffer. * This function should be locked. * return value: - * 0 : success - * -1 : fail, buffer full + * number of bytes copied to the buffer */ -int32_t Buffer::TryAppend(struct tm * pt_time, int64_t u_sec, const char * file_name, int32_t line, - const char * func_name, const char* str_log_level, const char * log_data, int64_t to_write) +size_t Buffer::TryAppend(const void * pt_log, size_t ToWrite) { - /* - * date: 11 byte - * time: 13 byte - * line number: at most 5 byte - * log level: 9 byte - */ - const size_t prefix_len = 24 + (file_name ? strlen(file_name) : 0) + 5 + - (func_name ? strlen(func_name) : 0) + 9; - const size_t append_len = prefix_len + to_write; // strlen(log_data); - - if (append_len + size_ >= capacity_) - { - return -1; - } - - int n_append = 0; - if (file_name && *file_name && line > 0 && func_name && *func_name && !(strlen(str_log_level) == 0)) + const size_t available_space = capacity_ - size_; + size_t to_write = std::min(available_space, ToWrite); + if (to_write > 0) { - n_append = sprintf_s(data_ + size_, capacity_ - size_, - "%d-%02d-%02d %02d:%02d:%02d.%.03d %10s:%3d %16s %10s %s\n", - pt_time->tm_year + 1900, pt_time->tm_mon + 1, pt_time->tm_mday, - pt_time->tm_hour, pt_time->tm_min, pt_time->tm_sec, static_cast(u_sec / 1000), - file_name ? file_name : "", line, func_name ? func_name : "", str_log_level, - log_data); + memmove(data_ + size_, pt_log, to_write); + size_ += to_write; } - else - { - n_append = sprintf_s(data_ + size_, capacity_ - size_, - "%d-%02d-%02d %02d:%02d:%02d.%.03d %s\n", - pt_time->tm_year + 1900, pt_time->tm_mon + 1, pt_time->tm_mday, - pt_time->tm_hour, pt_time->tm_min, pt_time->tm_sec, static_cast(u_sec / 1000), - log_data); - } - if (n_append > 0) - { - size_ += n_append; - } - - return 0; -} - -int32_t Buffer::TryAppend(const void * pt_log, int32_t ToWrite) -{ - /* - * date: 11 byte - * time: 13 byte - * line number: at most 5 byte - * log level: 9 byte - */ - const size_t append_len = ToWrite; // 24 + strlen(pt_file) + 5 + strlen(pt_func) + 9 + strlen(pt_log); - - if (append_len + size_ > capacity_) - { - return -1; - } - memmove(data_ + size_, pt_log, ToWrite); - const int32_t n_append = ToWrite; - if (n_append > 0) - { - size_ += n_append; - } - - return 0; + return to_write; } void Buffer::Clear() @@ -98,47 +42,39 @@ void Buffer::Clear() size_ = 0; } -uint64_t Buffer::Size() const +size_t Buffer::Size() const { return size_; } -uint64_t Buffer::Capacity() const +size_t Buffer::Capacity() const { return capacity_; } -int32_t Buffer::Flush(FILE* file) +bool Buffer::Flush(FILE* file) { // DebugCheck(file); assert(file); if (!size_) return 0; size_t n_write = 0; - while ((n_write = fwrite(data_, 1, size_ - n_write, file)) != 0) + size_t to_write = size_; + const char * buf = data_; + + while (to_write > 0) { - if ((static_cast(n_write) < 0) && (errno != EINTR)) + n_write = fwrite(buf, 1, to_write, file); + if (n_write == 0) { - // error break; } - else if (n_write == size_) - { - // All write - break; - } - else if (n_write > 0) - { - // Half write - } + to_write -= n_write; + buf += n_write; } - // error - if (static_cast(n_write) < 0) - return -1; - fflush(file); - return 0; + return to_write == 0; } } // namespace tinylog diff --git a/libs/tinylog/src/LogStream.cpp b/libs/tinylog/src/LogStream.cpp index d7626e1e8..1f60b5179 100644 --- a/libs/tinylog/src/LogStream.cpp +++ b/libs/tinylog/src/LogStream.cpp @@ -35,9 +35,9 @@ LogStream::~LogStream() // DEBUG_PRINTF("end"); } -int64_t LogStream::Write(const char * data, int64_t ToWrite) +size_t LogStream::Write(const char * data, size_t ToWrite) { - return InternalWrite(data, ToWrite); + return FormattedWrite(data, ToWrite); } /* @@ -95,34 +95,73 @@ void LogStream::SetFile(FILE * file) file_ = file; } -int64_t LogStream::InternalWrite(const char * log_data, int64_t to_write) +size_t LogStream::FormattedWrite(const char * log_data, size_t to_write) { - const int64_t Result = to_write; + // max length calculation. assume max line number is 999999 + // "2000-01-01 00:00:00.000 :999999 \n\0" + // 24 + (file or 10) + 1 + 6 + 1 + (func or 16) + 1 + (level or 10) + 1 + to_write + 2 + // 36 + (file or 10) + (func or 16) + (level or 10) + to_write + + size_t Result = 0; + UpdateBaseTime(); - // queue_->Push(log); - char * data_to_write = (char * )log_data; + + const size_t prefix_len = 36 + (file_name_ ? strlen(file_name_) : 10) + + (func_name_ ? strlen(func_name_) : 16) + (str_log_level_ ? strlen(str_log_level_) : 10); + const size_t append_len = prefix_len + to_write; + + char * buf = nb::chcalloc(append_len); + if (buf != nullptr) + { + int n_append = 0; + if (file_name_ && *file_name_ && line_ > 0 && func_name_ && *func_name_ && str_log_level_ && *str_log_level_) + { + const int32_t line_number = line_ > 999999 ? 999999 : line_; + + n_append = sprintf_s(buf, append_len, + "%d-%02d-%02d %02d:%02d:%02d.%.03d %10s:%3d %16s %10s %.*s\n", + tm_base_.tm_year + 1900, tm_base_.tm_mon + 1, tm_base_.tm_mday, + tm_base_.tm_hour, tm_base_.tm_min, tm_base_.tm_sec, static_cast(tv_base_.tv_usec / 1000), + file_name_ ? file_name_ : "", line_number, func_name_ ? func_name_ : "", str_log_level_, + static_cast(to_write), log_data); + } + else + { + n_append = sprintf_s(buf, append_len, + "%d-%02d-%02d %02d:%02d:%02d.%.03d %.*s\n", + tm_base_.tm_year + 1900, tm_base_.tm_mon + 1, tm_base_.tm_mday, + tm_base_.tm_hour, tm_base_.tm_min, tm_base_.tm_sec, static_cast(tv_base_.tv_usec / 1000), + static_cast(to_write), log_data); + } + + if (n_append > 0) + { + Result = InternalWrite(buf, n_append); + } + nb_free(buf); + } + return Result; +} + +size_t LogStream::InternalWrite(const char * log_data, size_t to_write) +{ + const size_t Result = to_write; + size_t n_append; pthread_mutex_lock(&mutex_); // DEBUG_PRINTF("ToWrite: %d", (int)to_write); - while (true) + while (to_write) { auto & buff = drain_buffer_ ? back_buff_ : front_buff_; // append to the current buffer - int64_t need_capacity = static_cast(buff->Capacity() - buff->Size()); - if (to_write > need_capacity) - { - // trunc log_data - tmp_buff_ = std::make_unique(need_capacity); - tmp_buff_->TryAppend(log_data, need_capacity); - data_to_write = tmp_buff_->Data(); - to_write = need_capacity; - } - if (buff->TryAppend(&tm_base_, static_cast(tv_base_.tv_usec), file_name_, line_, func_name_, str_log_level_, data_to_write, to_write) < 0) + n_append = buff->TryAppend(log_data, to_write); + if (n_append == 0) { if (drain_buffer_) { // we are appending to the back_buff_ and there is no more space there // wait until buffer is drained (very rare situation) + pthread_cond_signal(&cond_); pthread_mutex_unlock(&mutex_); while (drain_buffer_) { @@ -140,7 +179,8 @@ int64_t LogStream::InternalWrite(const char * log_data, int64_t to_write) } else { - break; + log_data += n_append; + to_write -= n_append; } } @@ -155,14 +195,14 @@ int64_t LogStream::InternalWrite(const char * log_data, int64_t to_write) LogStream & LogStream::operator<<(const char * log_data) { - InternalWrite(log_data, strlen(log_data)); + FormattedWrite(log_data, strlen(log_data)); return *this; } LogStream & LogStream::operator<<(const std::string & ref_log) { - InternalWrite(ref_log.c_str(), ref_log.size()); + FormattedWrite(ref_log.c_str(), ref_log.size()); /* UpdateBaseTime(); diff --git a/libs/tinylog/src/TinyLog.cpp b/libs/tinylog/src/TinyLog.cpp index c0a97c5d5..e87e681fd 100644 --- a/libs/tinylog/src/TinyLog.cpp +++ b/libs/tinylog/src/TinyLog.cpp @@ -20,7 +20,7 @@ class TinyLogImpl Utils::LogLevel GetLogLevel() const; LogStream & GetLogStream(const char * file_name, int32_t line, const char * func_name, Utils::LogLevel log_level); - int64_t Write(const char * data, int64_t ToWrite); + size_t Write(const char * data, size_t ToWrite); void Close(); private: @@ -98,7 +98,7 @@ LogStream & TinyLogImpl::GetLogStream(const char * file_name, int32_t line, cons return *logstream_; } -int64_t TinyLogImpl::Write(const char * data, int64_t ToWrite) +size_t TinyLogImpl::Write(const char * data, size_t ToWrite) { return logstream_->Write(data, ToWrite); } @@ -191,7 +191,7 @@ LogStream & TinyLog::GetLogStream(const char * file_name, int32_t line_num, cons return impl_->GetLogStream(file_name, line_num, func_name, log_level); } -int64_t TinyLog::Write(const char * data, int64_t ToWrite) +size_t TinyLog::Write(const char * data, size_t ToWrite) { return impl_->Write(data, ToWrite); } diff --git a/libs/tinylog/tinylog/Buffer.h b/libs/tinylog/tinylog/Buffer.h index 90a0308ce..6662701dd 100644 --- a/libs/tinylog/tinylog/Buffer.h +++ b/libs/tinylog/tinylog/Buffer.h @@ -15,15 +15,13 @@ class Buffer explicit Buffer(size_t capacity); ~Buffer(); - int32_t TryAppend(struct tm* pt_time, int64_t u_sec, const char* file_name, int32_t line, - const char* func_name, const char* str_log_level, const char* log_data, int64_t to_write); - int32_t TryAppend(const void* pt_log, int32_t ToWrite); + size_t TryAppend(const void* pt_log, size_t ToWrite); void Clear(); - uint64_t Size() const; - uint64_t Capacity() const; + size_t Size() const; + size_t Capacity() const; char * Data() const { return data_; } - int32_t Flush(FILE* file); + bool Flush(FILE* file); private: Buffer(const Buffer&) = delete; diff --git a/libs/tinylog/tinylog/LogStream.h b/libs/tinylog/tinylog/LogStream.h index b0da9c6fe..f52d4e633 100644 --- a/libs/tinylog/tinylog/LogStream.h +++ b/libs/tinylog/tinylog/LogStream.h @@ -19,7 +19,7 @@ class LogStream explicit LogStream(FILE * file, pthread_mutex_t & mutex, pthread_cond_t & cond, bool & already_swap); ~LogStream(); - int64_t Write(const char * data, int64_t ToWrite); + size_t Write(const char * data, size_t ToWrite); void SwapBuffer(); void WriteBuffer(); @@ -39,11 +39,11 @@ class LogStream LogStream(const LogStream &) = delete; LogStream & operator =(const LogStream &) = delete; - int64_t InternalWrite(const char * log_data, int64_t ToWrite); + size_t InternalWrite(const char * log_data, size_t ToWrite); + size_t FormattedWrite(const char * log_data, size_t ToWrite); std::unique_ptr front_buff_; std::unique_ptr back_buff_; - std::unique_ptr tmp_buff_; // std::unique_ptr queue_; FILE * file_{nullptr}; // TODO: use gsl::not_null const char * file_name_{nullptr}; // TODO: use gsl::not_null diff --git a/libs/tinylog/tinylog/TinyLog.h b/libs/tinylog/tinylog/TinyLog.h index a24e1df6d..435e04d43 100644 --- a/libs/tinylog/tinylog/TinyLog.h +++ b/libs/tinylog/tinylog/TinyLog.h @@ -40,7 +40,7 @@ class TinyLog tinylog::Utils::LogLevel GetLogLevel() const; LogStream & GetLogStream(const char * file_name, int32_t line_num, const char * func_name, tinylog::Utils::LogLevel log_level); - int64_t Write(const char * data, int64_t ToWrite); + size_t Write(const char * data, size_t ToWrite); void Close(); // TODO: group / groupEnd diff --git a/src/NetBox/FarDialog.cpp b/src/NetBox/FarDialog.cpp index 13f4c0846..669ec75dc 100644 --- a/src/NetBox/FarDialog.cpp +++ b/src/NetBox/FarDialog.cpp @@ -2490,11 +2490,6 @@ TFarListBox::TFarListBox(TFarDialog * ADialog) noexcept : GetDialogItem()->ListItems = FList->GetListItems(); } -TFarListBox::~TFarListBox() noexcept -{ -// SAFE_DESTROY(FList); -} - intptr_t TFarListBox::ItemProc(intptr_t Msg, void * Param) { intptr_t Result = 0; @@ -2565,11 +2560,6 @@ TFarComboBox::TFarComboBox(TFarDialog * ADialog) noexcept : SetAutoSelect(false); } -TFarComboBox::~TFarComboBox() noexcept -{ -// SAFE_DESTROY(FList); -} - void TFarComboBox::ResizeToFitContent() { SetWidth(FList->GetMaxLength()); diff --git a/src/NetBox/FarDialog.h b/src/NetBox/FarDialog.h index c85f93925..a3ccb71af 100644 --- a/src/NetBox/FarDialog.h +++ b/src/NetBox/FarDialog.h @@ -534,7 +534,7 @@ class TFarListBox; class TFarComboBox; class TFarLister; -class TFarList : public TStringList +class TFarList final : public TStringList { friend class TFarListBox; friend class TFarLister; @@ -595,15 +595,16 @@ enum TFarListBoxAutoSelect asNever }; -class TFarListBox : public TFarDialogItem +class TFarListBox final : public TFarDialogItem { NB_DISABLE_COPY(TFarListBox) public: static bool classof(const TObject * Obj) { return Obj->is(OBJECT_CLASS_TFarListBox); } virtual bool is(TObjectClassId Kind) const override { return (Kind == OBJECT_CLASS_TFarListBox) || TFarDialogItem::is(Kind); } public: + TFarListBox() = delete; explicit TFarListBox(TFarDialog * ADialog) noexcept; - virtual ~TFarListBox() noexcept override; + virtual ~TFarListBox() noexcept override = default; void SetItems(const TStrings * Value, bool OwnItems = true); @@ -635,12 +636,13 @@ class TFarListBox : public TFarDialogItem bool FDenyClose{false}; }; -class TFarComboBox : public TFarDialogItem +class TFarComboBox final : public TFarDialogItem { NB_DISABLE_COPY(TFarComboBox) public: + TFarComboBox() = delete; explicit TFarComboBox(TFarDialog * ADialog) noexcept; - virtual ~TFarComboBox() noexcept override; + virtual ~TFarComboBox() noexcept override = default; void ResizeToFitContent(); @@ -670,7 +672,7 @@ class TFarComboBox : public TFarDialogItem bool FItemChanged{false}; }; -class TFarLister : public TFarDialogItem +class TFarLister final : public TFarDialogItem { NB_DISABLE_COPY(TFarLister) public: diff --git a/src/NetBox/FarPlugin.cpp b/src/NetBox/FarPlugin.cpp index 404709a8c..9c287d518 100644 --- a/src/NetBox/FarPlugin.cpp +++ b/src/NetBox/FarPlugin.cpp @@ -20,8 +20,8 @@ constexpr const wchar_t * FAR_TITLE_SUFFIX = L" - Far"; class TPluginIdleThread final : public TSimpleThread { - TPluginIdleThread() = delete; public: + TPluginIdleThread() = delete; explicit TPluginIdleThread(gsl::not_null Plugin, DWORD Millisecs) noexcept : TSimpleThread(OBJECT_CLASS_TPluginIdleThread), FPlugin(Plugin), @@ -122,14 +122,11 @@ TCustomFarPlugin::~TCustomFarPlugin() noexcept ClearPluginInfo(FPluginInfo); DebugAssert(FOpenedPlugins->GetCount() == 0); - // SAFE_DESTROY(FOpenedPlugins); for (int32_t Index = 0; Index < FSavedTitles->GetCount(); ++Index) { TObject * Object = FSavedTitles->Get(Index); SAFE_DESTROY(Object); } - // SAFE_DESTROY(FSavedTitles); - // TODO: CloseFileSystem(FarFileSystem); // DEBUG_PRINTF("end"); } @@ -151,14 +148,13 @@ void TCustomFarPlugin::SetStartupInfo(const struct PluginStartupInfo * Info) nb::ClearStruct(FStartupInfo); memmove(&FStartupInfo, Info, Info->StructSize >= nb::ToSizeT(sizeof(FStartupInfo)) ? - sizeof(FStartupInfo) : nb::ToSizeT(Info->StructSize)); + sizeof(FStartupInfo) : nb::ToSizeT(Info->StructSize)); // the minimum we really need DebugAssert(FStartupInfo.GetMsg != nullptr); DebugAssert(FStartupInfo.Message != nullptr); nb::ClearStruct(FFarStandardFunctions); - const size_t FSFOffset = (static_cast(nb::ToPtr(&Info->FSF)) - - static_cast(nb::ToPtr(Info))); + const size_t FSFOffset = nb::ToUIntPtr(&Info->FSF) - nb::ToUIntPtr(Info); if (nb::ToSizeT(Info->StructSize) > FSFOffset) { memmove(&FFarStandardFunctions, Info->FSF, @@ -827,11 +823,11 @@ int32_t TCustomFarPlugin::MaxLength(TStrings * Strings) const class TFarMessageDialog final : public TFarDialog { - TFarMessageDialog() = delete; public: + TFarMessageDialog() = delete; explicit TFarMessageDialog(gsl::not_null Plugin, gsl::not_null Params); - void Init(uint32_t AFlags, const UnicodeString & Title, const UnicodeString & Message, + void InitFarMessageDialog(uint32_t AFlags, const UnicodeString & Title, const UnicodeString & Message, TStrings * Buttons); virtual ~TFarMessageDialog() override; @@ -864,7 +860,7 @@ TFarMessageDialog::TFarMessageDialog(gsl::not_null Plugin, DebugAssert(FParams != nullptr); } -void TFarMessageDialog::Init(uint32_t AFlags, +void TFarMessageDialog::InitFarMessageDialog(uint32_t AFlags, const UnicodeString & Title, const UnicodeString & Message, TStrings * Buttons) { TFarDialog::InitDialog(); @@ -901,7 +897,7 @@ void TFarMessageDialog::Init(uint32_t AFlags, for (int32_t Index = 0; Index < MessageLines->GetCount(); ++Index) { - TFarText * Text = new TFarText(this); + TFarText * Text = MakeOwnedObject(this); Text->SetCaption(MessageLines->GetString(Index)); } @@ -910,13 +906,13 @@ void TFarMessageDialog::Init(uint32_t AFlags, if (FParams->MoreMessages != nullptr) { - new TFarSeparator(this); + MakeOwnedObject(this); - MoreMessagesLister = new TFarLister(this); + MoreMessagesLister = MakeOwnedObject(this); MoreMessagesLister->GetItems()->Assign(MoreMessageLines.get()); MoreMessagesLister->SetLeft(GetBorderBox()->GetLeft() + 1); - MoreMessagesSeparator = new TFarSeparator(this); + MoreMessagesSeparator = MakeOwnedObject(this); } const int32_t ButtonOffset = FParams->CheckBoxLabel.IsEmpty() ? -1 : -2; @@ -926,7 +922,7 @@ void TFarMessageDialog::Init(uint32_t AFlags, for (int32_t Index = 0; Index < Buttons->GetCount(); ++Index) { const TFarButton * PrevButton = Button; - Button = new TFarButton(this); + Button = MakeOwnedObject(this); Button->SetDefault(FParams->DefaultButton == Index); Button->SetBrackets(brNone); Button->SetOnClick(nb::bind(&TFarMessageDialog::ButtonClick, this)); @@ -974,7 +970,7 @@ void TFarMessageDialog::Init(uint32_t AFlags, if (!FParams->CheckBoxLabel.IsEmpty()) { SetNextItemPosition(ipNewLine); - FCheckBox = new TFarCheckBox(this); + FCheckBox = MakeOwnedObject(this); FCheckBox->SetCaption(FParams->CheckBoxLabel); if (MaxLen < FCheckBox->GetRight() - GetBorderBox()->GetLeft()) @@ -1133,7 +1129,7 @@ int32_t TCustomFarPlugin::DialogMessage(uint32_t Flags, gsl::not_null Params) { std::unique_ptr Dialog(std::make_unique(this, Params)); - Dialog->Init(Flags, Title, Message, Buttons); + Dialog->InitFarMessageDialog(Flags, Title, Message, Buttons); const int32_t Result = Dialog->Execute(Params->CheckBox); return Result; } @@ -1920,17 +1916,14 @@ void TCustomFarPlugin::Initialize() void TCustomFarPlugin::Finalize() { -// TGlobalsIntf * Intf = GetGlobals(); -// delete Intf; -// ::SetGlobals(nullptr); +#if 0 + // TODO: move to DestroyFarPlugin + TGlobalsIntf * Intf = GetGlobals(); + delete Intf; + ::SetGlobals(nullptr); +#endif //if 0 } -#ifdef NETBOX_DEBUG -void TCustomFarPlugin::RunTests() -{ -} -#endif - uint32_t TCustomFarFileSystem::FInstances = 0; TCustomFarFileSystem::TCustomFarFileSystem(TObjectClassId Kind, gsl::not_null APlugin) noexcept : @@ -2404,7 +2397,7 @@ void TFarPanelModes::SetFlag(PANELMODE_FLAGS & Flags, bool Value, PANELMODE_FLAG } } -void TFarPanelModes::ClearPanelMode(PanelMode &Mode) +void TFarPanelModes::ClearPanelMode(PanelMode & Mode) { if (Mode.ColumnTypes) { @@ -2520,7 +2513,7 @@ void TFarKeyBarTitles::SetKeyBarTitle(TFarShiftStatus ShiftStatus, Labels[FunctionKey - 1].LongText = nullptr; } -void TFarKeyBarTitles::ClearKeyBarTitles(KeyBarTitles &Titles) +void TFarKeyBarTitles::ClearKeyBarTitles(KeyBarTitles & Titles) { for (size_t Index = 0; Index < Titles.CountLabels; ++Index) { @@ -2928,7 +2921,7 @@ void TFarMenuItems::SetObject(int32_t Index, TObject * AObject) } } -int32_t TFarMenuItems::Add(const UnicodeString & Text, bool Visible) +int32_t TFarMenuItems::AddString(const UnicodeString & Text, bool Visible) { const int32_t Result = TStringList::Add(Text); if (!Visible) @@ -2940,7 +2933,7 @@ int32_t TFarMenuItems::Add(const UnicodeString & Text, bool Visible) void TFarMenuItems::AddSeparator(bool Visible) { - Add(""); + AddString(""); SetFlag(GetCount() - 1, MIF_SEPARATOR, true); if (!Visible) { @@ -2983,7 +2976,7 @@ bool TFarMenuItems::GetFlag(int32_t Index, uint32_t Flag) const return (nb::ToUIntPtr(Objects[Index]) & Flag) != 0; } -TFarEditorInfo::TFarEditorInfo(EditorInfo * Info) noexcept : +TFarEditorInfo::TFarEditorInfo(gsl::not_null Info) noexcept : FEditorInfo(Info) { } diff --git a/src/NetBox/FarPlugin.h b/src/NetBox/FarPlugin.h index 0c8b9057e..aa23ab746 100644 --- a/src/NetBox/FarPlugin.h +++ b/src/NetBox/FarPlugin.h @@ -10,6 +10,8 @@ #include #include "guid.h" +#undef GetStartupInfo + constexpr const DWORD RMASK = (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED | SHIFT_PRESSED); constexpr const DWORD ALTMASK = (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED); constexpr const DWORD CTRLMASK = (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED); @@ -203,7 +205,6 @@ class TCustomFarPlugin : public TObject HINSTANCE GetPluginHandle() const { return FPluginHandle; } uint32_t GetFarThreadId() const { return FFarThreadId; } const FarStandardFunctions & GetFarStandardFunctions() const { return FFarStandardFunctions; } - #undef GetStartupInfo const struct PluginStartupInfo * GetStartupInfo() const { return &FStartupInfo; } protected: @@ -246,10 +247,6 @@ class TCustomFarPlugin : public TObject const TCriticalSection & GetCriticalSection() const { return FCriticalSection; } -#ifdef NETBOX_DEBUG -public: - void RunTests(); -#endif private: void UpdateProgress(int32_t State, int32_t Progress) const; int64_t GetSystemSetting(HANDLE & Settings, const wchar_t * Name) const; @@ -307,8 +304,6 @@ class TCustomFarFileSystem : public TObject virtual UnicodeString GetCurrentDirectory() const = 0; protected: - gsl::not_null FPlugin; - bool FClosed{false}; virtual void GetOpenPanelInfoEx(OPENPANELINFO_FLAGS & Flags, UnicodeString & HostFile, UnicodeString & CurDir, UnicodeString & Format, @@ -349,18 +344,22 @@ class TCustomFarFileSystem : public TObject bool GetOpenPanelInfoValid() const { return FOpenPanelInfoValid; } protected: - TCriticalSection FCriticalSection; void InvalidateOpenPanelInfo(); TCustomFarFileSystem * GetOwnerFileSystem() { return FOwnerFileSystem; } void SetOwnerFileSystem(TCustomFarFileSystem * Value) { FOwnerFileSystem = Value; } + bool GetClosed() const { return FClosed; } + TCustomFarPlugin * GetPlugin() const { return FPlugin; } private: + TCriticalSection FCriticalSection; UnicodeString FNameStr; UnicodeString FDestPathStr; OpenPanelInfo FOpenPanelInfo{}; bool FOpenPanelInfoValid{false}; TCustomFarFileSystem * FOwnerFileSystem{nullptr}; TFarPanelInfo * FPanelInfo[2]{}; + gsl::not_null FPlugin; + bool FClosed{false}; static uint32_t FInstances; void ClearOpenPanelInfo(OpenPanelInfo & Info); @@ -389,7 +388,7 @@ class TFarPanelModes final : public TObject void FillOpenPanelInfo(struct OpenPanelInfo * Info); void SetFlag(PANELMODE_FLAGS & Flags, bool Value, PANELMODE_FLAGS Flag); - static void ClearPanelMode(PanelMode &Mode); + static void ClearPanelMode(PanelMode & Mode); static int32_t CommaCount(const UnicodeString & ColumnTypes); }; @@ -411,7 +410,7 @@ class TFarKeyBarTitles final : public TObject bool FReferenced{false}; void FillOpenPanelInfo(struct OpenPanelInfo * Info); - static void ClearKeyBarTitles(KeyBarTitles &Titles); + static void ClearKeyBarTitles(KeyBarTitles & Titles); }; class TCustomFarPanelItem : public TObject @@ -536,7 +535,7 @@ class TFarMenuItems final : public TStringList explicit TFarMenuItems() noexcept; virtual ~TFarMenuItems() override = default; void AddSeparator(bool Visible = true); - int32_t Add(const UnicodeString & Text, bool Visible = true); + int32_t AddString(const UnicodeString & Text, bool Visible = true); virtual void Clear() override; virtual void Delete(int32_t Index) override; @@ -564,7 +563,7 @@ class TFarEditorInfo final : public TObject NB_DISABLE_COPY(TFarEditorInfo) public: TFarEditorInfo() = delete; - explicit TFarEditorInfo(EditorInfo * Info) noexcept; + explicit TFarEditorInfo(gsl::not_null Info) noexcept; virtual ~TFarEditorInfo() noexcept override; int32_t GetEditorID() const; diff --git a/src/NetBox/WinSCPDialogs.cpp b/src/NetBox/WinSCPDialogs.cpp index 67041abac..5243d1743 100644 --- a/src/NetBox/WinSCPDialogs.cpp +++ b/src/NetBox/WinSCPDialogs.cpp @@ -1435,7 +1435,7 @@ bool TWinSCPFileSystem::PasswordDialog(TSessionData * SessionData, TStrings * Prompts, TStrings * Results, bool StoredCredentialsTried) { - std::unique_ptr Dialog(std::make_unique(FPlugin, SessionData->GetName(), + std::unique_ptr Dialog(std::make_unique(GetPlugin(), SessionData->GetName(), Kind, Name, Instructions, Prompts, StoredCredentialsTried)); const bool Result = Dialog->Execute(Results); return Result; @@ -1444,7 +1444,7 @@ bool TWinSCPFileSystem::PasswordDialog(TSessionData * SessionData, bool TWinSCPFileSystem::BannerDialog(const UnicodeString & SessionName, const UnicodeString & Banner, bool & NeverShowAgain, int32_t Options) { - std::unique_ptr DialogPtr(std::make_unique(FPlugin)); + std::unique_ptr DialogPtr(std::make_unique(GetPlugin())); TWinSCPDialog * Dialog = DialogPtr.get(); Dialog->SetSize(TPoint(70, 21)); @@ -3102,7 +3102,7 @@ void TSessionDialog::UpdateControls() (FSProtocol != fsSCPonly) || CacheDirectoriesCheck->GetChecked()); PreserveDirectoryChangesCheck->SetEnabled( CacheDirectoryChangesCheck->GetIsEnabled() && CacheDirectoryChangesCheck->GetChecked()); - ResolveSymlinksCheck->SetEnabled(!InternalWebDAVProtocol); + ResolveSymlinksCheck->SetEnabled(!InternalWebDAVProtocol && !lS3Protocol); // Environment tab DSTModeUnixCheck->SetEnabled(!lFtpProtocol); @@ -3999,7 +3999,7 @@ int32_t TSessionDialog::FtpsToIndex(TFtps AFtps) const inline int32_t TSessionDialog::GetLastSupportedFtpProxyMethod() const { - return pmNone; // pmSystem; + return pmHTTP; } bool TSessionDialog::GetSupportedFtpProxyMethod(int32_t Method) const @@ -4405,7 +4405,7 @@ int32_t TSessionDialog::AddTab(int32_t TabID, const UnicodeString & TabCaption) bool TWinSCPFileSystem::SessionDialog(TSessionData * SessionData, TSessionActionEnum & Action) { - std::unique_ptr Dialog(std::make_unique(FPlugin, Action)); + std::unique_ptr Dialog(std::make_unique(GetPlugin(), Action)); const bool Result = Dialog->Execute(SessionData, Action); return Result; } @@ -5181,7 +5181,7 @@ bool TWinSCPFileSystem::PropertiesDialog(TStrings * AFileList, const TRemoteTokenList * GroupList, const TRemoteTokenList * UserList, TRemoteProperties * Properties, int32_t AllowedChanges) { - std::unique_ptr Dialog(std::make_unique(FPlugin, AFileList, + std::unique_ptr Dialog(std::make_unique(GetPlugin(), AFileList, ADirectory, GroupList, UserList, AllowedChanges)); const bool Result = Dialog->Execute(Properties); return Result; @@ -5927,7 +5927,7 @@ bool TWinSCPFileSystem::CopyDialog(bool ToRemote, UnicodeString & TargetDirectory, TGUICopyParamType * Params) { - std::unique_ptr Dialog(std::make_unique(FPlugin, ToRemote, + std::unique_ptr Dialog(std::make_unique(GetPlugin(), ToRemote, Move, AFileList, Options, CopyParamAttrs)); const bool Result = Dialog->Execute(TargetDirectory, Params); return Result; @@ -6067,7 +6067,7 @@ bool TLinkDialog::Execute(UnicodeString & AFileName, UnicodeString & PointTo, bool TWinSCPFileSystem::LinkDialog(UnicodeString & AFileName, UnicodeString & PointTo, bool & Symbolic, bool Edit, bool AllowSymbolic) { - std::unique_ptr Dialog(std::make_unique(FPlugin, Edit, AllowSymbolic)); + std::unique_ptr Dialog(std::make_unique(GetPlugin(), Edit, AllowSymbolic)); const bool Result = Dialog->Execute(AFileName, PointTo, Symbolic); return Result; } @@ -6609,7 +6609,7 @@ void TWinSCPFileSystem::FileSystemInfoDialog( const TSessionInfo & SessionInfo, const TFileSystemInfo & FileSystemInfo, const UnicodeString & SpaceAvailablePath, TGetSpaceAvailableEvent && OnGetSpaceAvailable) { - std::unique_ptr Dialog(std::make_unique(FPlugin, std::move(OnGetSpaceAvailable))); + std::unique_ptr Dialog(std::make_unique(GetPlugin(), std::move(OnGetSpaceAvailable))); Dialog->Execute(SessionInfo, FileSystemInfo, SpaceAvailablePath); } @@ -6628,7 +6628,7 @@ bool TWinSCPFileSystem::OpenDirectoryDialog( std::unique_ptr Bookmarks(std::make_unique()); int32_t BookmarksOffset{0}; - const int32_t MaxLength = FPlugin->MaxMenuItemLength(); + const int32_t MaxLength = GetPlugin()->MaxMenuItemLength(); constexpr int32_t MaxHistory = 40; int32_t FirstHistory = 0; @@ -6727,7 +6727,7 @@ bool TWinSCPFileSystem::OpenDirectoryDialog( { 0, 0 } }; - ItemFocused = nb::ToInt32(FPlugin->Menu(FMENU_REVERSEAUTOHIGHLIGHT | FMENU_SHOWAMPERSAND | FMENU_WRAPMODE, + ItemFocused = nb::ToInt32(GetPlugin()->Menu(FMENU_REVERSEAUTOHIGHLIGHT | FMENU_SHOWAMPERSAND | FMENU_WRAPMODE, Caption, GetMsg(NB_OPEN_DIRECTORY_HELP), BookmarkItems.get(), BreakKeys, BreakCode)); if (BreakCode >= 0) { @@ -6753,7 +6753,7 @@ bool TWinSCPFileSystem::OpenDirectoryDialog( } else if (BreakCode == 3 || BreakCode == 4) { - FPlugin->FarCopyToClipboard(BookmarkPaths->GetString(ItemFocused)); + GetPlugin()->FarCopyToClipboard(BookmarkPaths->GetString(ItemFocused)); Repeat = true; } } @@ -6936,7 +6936,7 @@ bool TApplyCommandDialog::Execute(UnicodeString & Command, int32_t & Params) bool TWinSCPFileSystem::ApplyCommandDialog(UnicodeString & Command, int32_t & Params) const { - std::unique_ptr Dialog(std::make_unique(FPlugin)); + std::unique_ptr Dialog(std::make_unique(GetPlugin())); const bool Result = Dialog->Execute(Command, Params); return Result; } @@ -7363,7 +7363,7 @@ bool TWinSCPFileSystem::FullSynchronizeDialog(TTerminal::TSynchronizeMode & Mode const TUsableCopyParamAttrs & CopyParamAttrs) const { std::unique_ptr Dialog(std::make_unique( - FPlugin, Options, CopyParamAttrs)); + GetPlugin(), Options, CopyParamAttrs)); const bool Result = Dialog->Execute(Mode, Params, LocalDirectory, RemoteDirectory, CopyParams, SaveSettings, SaveMode); return Result; @@ -7964,7 +7964,7 @@ bool TWinSCPFileSystem::SynchronizeChecklistDialog( const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory) { std::unique_ptr Dialog(std::make_unique( - FPlugin, Mode, Params, LocalDirectory, RemoteDirectory)); + GetPlugin(), Mode, Params, LocalDirectory, RemoteDirectory)); const bool Result = Dialog->Execute(Checklist); return Result; } @@ -8420,7 +8420,7 @@ bool TWinSCPFileSystem::SynchronizeDialog(TSynchronizeParamType & Params, const TCopyParamType * CopyParams, TSynchronizeStartStopEvent && OnStartStop, bool & SaveSettings, uint32_t Options, uint32_t CopyParamAttrs, TGetSynchronizeOptionsEvent && OnGetOptions) { - std::unique_ptr Dialog(std::make_unique(FPlugin, std::move(OnStartStop), + std::unique_ptr Dialog(std::make_unique(GetPlugin(), std::move(OnStartStop), Options, CopyParamAttrs, std::move(OnGetOptions))); const bool Result = Dialog->Execute(Params, CopyParams, SaveSettings); return Result; @@ -8434,7 +8434,7 @@ bool TWinSCPFileSystem::RemoteTransferDialog(TStrings * AFileList, GetMsg(Move ? NB_REMOTE_MOVE_FILES : NB_REMOTE_COPY_FILES), AFileList, true); UnicodeString Value = TUnixPath::Join(Target, FileMask); - const bool Result = FPlugin->InputBox( + const bool Result = GetPlugin()->InputBox( GetMsg(Move ? NB_REMOTE_MOVE_TITLE : NB_REMOTE_COPY_TITLE), Prompt, Value, 0, MOVE_TO_HISTORY) && !Value.IsEmpty(); if (Result) @@ -8448,7 +8448,7 @@ bool TWinSCPFileSystem::RemoteTransferDialog(TStrings * AFileList, bool TWinSCPFileSystem::RenameFileDialog(TRemoteFile * AFile, UnicodeString & NewName) { - return FPlugin->InputBox(GetMsg(NB_RENAME_FILE_TITLE), + return GetPlugin()->InputBox(GetMsg(NB_RENAME_FILE_TITLE), FORMAT(GetMsg(NB_RENAME_FILE), AFile->GetFileName()), NewName, 0) && !NewName.IsEmpty(); } @@ -8984,7 +8984,7 @@ bool TQueueDialog::Execute(TTerminalQueueStatus * Status) bool TWinSCPFileSystem::QueueDialog( TTerminalQueueStatus * Status, bool ClosingPlugin) { - std::unique_ptr Dialog(std::make_unique(FPlugin, this, ClosingPlugin)); + std::unique_ptr Dialog(std::make_unique(GetPlugin(), this, ClosingPlugin)); const bool Result = Dialog->Execute(Status); return Result; } @@ -8992,7 +8992,7 @@ bool TWinSCPFileSystem::QueueDialog( bool TWinSCPFileSystem::CreateDirectoryDialog(UnicodeString & Directory, TRemoteProperties * Properties, bool & SaveSettings) { - std::unique_ptr Dialog(std::make_unique(FPlugin)); + std::unique_ptr Dialog(std::make_unique(GetPlugin())); Dialog->SetCaption(GetMsg(NB_CREATE_FOLDER_TITLE)); Dialog->SetSize(TPoint(66, 15)); diff --git a/src/NetBox/WinSCPFileSystem.cpp b/src/NetBox/WinSCPFileSystem.cpp index ba6b77156..ec7187247 100644 --- a/src/NetBox/WinSCPFileSystem.cpp +++ b/src/NetBox/WinSCPFileSystem.cpp @@ -295,7 +295,7 @@ TWinSCPFileSystem::TWinSCPFileSystem(gsl::not_null APlugin) { } -void TWinSCPFileSystem::Init(const TSecureShell * /*SecureShell*/) +void TWinSCPFileSystem::InitWinSCPFileSystem(const TSecureShell * /*SecureShell*/) { TCustomFarFileSystem::Init(); } @@ -321,7 +321,7 @@ void TWinSCPFileSystem::HandleException(Exception * E, OPERATION_MODES OpMode) { if (GetTerminal()) GetTerminal()->ShowExtendedException(E); - if (!FClosed) + if (!GetClosed()) { ClosePanel(); } @@ -335,7 +335,7 @@ void TWinSCPFileSystem::HandleException(Exception * E, OPERATION_MODES OpMode) void TWinSCPFileSystem::KeepaliveThreadCallback() { - const TGuard Guard(FCriticalSection); + const TGuard Guard(GetCriticalSection()); if (Connected()) { @@ -357,14 +357,14 @@ bool TWinSCPFileSystem::Connected() const const TWinSCPPlugin * TWinSCPFileSystem::GetWinSCPPlugin() const { - const TWinSCPPlugin * WinSCPPlugin = rtti::dyn_cast_or_null(FPlugin.get()); + const TWinSCPPlugin * WinSCPPlugin = rtti::dyn_cast_or_null(GetPlugin()); Ensures(WinSCPPlugin); return WinSCPPlugin; } TWinSCPPlugin * TWinSCPFileSystem::GetWinSCPPlugin() { - TWinSCPPlugin * WinSCPPlugin = rtti::dyn_cast_or_null(FPlugin.get()); + TWinSCPPlugin * WinSCPPlugin = rtti::dyn_cast_or_null(GetPlugin()); Ensures(WinSCPPlugin); return WinSCPPlugin; } @@ -411,7 +411,7 @@ void TWinSCPFileSystem::GetOpenPanelInfoEx(OPENPANELINFO_FLAGS & Flags, const UnicodeString SessionName = GetSessionData()->GetLocalName(); AFormat = FORMAT("netbox:%s", SessionName); const UnicodeString HostName = GetSessionData()->GetHostNameExpanded(); - const UnicodeString Url = GetSessionData()->GenerateSessionUrl(sufComplete); + // const UnicodeString Url = GetSessionData()->GenerateSessionUrl(sufComplete); if (GetFarConfiguration()->GetSessionNameInTitle()) { PanelTitle = FORMAT(" %s:%s ", SessionName, CurDir); @@ -471,44 +471,10 @@ bool TWinSCPFileSystem::GetFindDataEx(TObjectList * PanelItems, OPERATION_MODES FTerminal->ReloadDirectory(); } - TCustomFileSystem * FileSystem = GetTerminal()->GetFileSystem(); - bool ResolveSymlinks = GetSessionData()->GetResolveSymlinks(); for (int32_t Index = 0; Index < GetTerminal()->GetFiles()->GetCount(); ++Index) { TRemoteFile * File = GetTerminal()->GetFiles()->GetFile(Index); DebugAssert(File); - if (ResolveSymlinks && File->GetIsSymLink()) - { - if (FarPlugin->CheckForEsc()) - { - ResolveSymlinks = false; - continue; - }; - // Check what kind of symlink this is - const UnicodeString LinkFileName = File->GetLinkTo(); - if (!LinkFileName.IsEmpty()) - { - TRemoteFile * LinkFile = nullptr; - try - { - FileSystem->ReadFile(LinkFileName, LinkFile); - } - catch(const Exception & /*E*/) - { - LinkFile = nullptr; - } - if ((LinkFile != nullptr) && LinkFile->GetIsDirectory()) - { - File->SetType(FILETYPE_DIRECTORY); - File->SetIsSymLink(true); - if (const auto LinkedFile = File->GetLinkedFile()) - { - const_cast(LinkedFile)->SetType(FILETYPE_DIRECTORY); - } - } - SAFE_DESTROY(LinkFile); - } - } PanelItems->Add(new TRemoteFilePanelItem(File)); } } @@ -1724,7 +1690,7 @@ void TWinSCPFileSystem::Synchronize() { FSynchronizeController = nullptr; // plugin might have been closed during some synchronization already - if (!FClosed) + if (!GetClosed()) { if (UpdatePanel()) { diff --git a/src/NetBox/WinSCPFileSystem.h b/src/NetBox/WinSCPFileSystem.h index b01b377f7..00b3e917e 100644 --- a/src/NetBox/WinSCPFileSystem.h +++ b/src/NetBox/WinSCPFileSystem.h @@ -92,7 +92,7 @@ class TWinSCPFileSystem final : public TCustomFarFileSystem public: explicit TWinSCPFileSystem(gsl::not_null APlugin) noexcept; virtual ~TWinSCPFileSystem() noexcept override; - void Init(const TSecureShell * SecureShell); + void InitWinSCPFileSystem(const TSecureShell * SecureShell); virtual void Close() override; diff --git a/src/NetBox/WinSCPPlugin.cpp b/src/NetBox/WinSCPPlugin.cpp index 370715c38..e0e14257d 100644 --- a/src/NetBox/WinSCPPlugin.cpp +++ b/src/NetBox/WinSCPPlugin.cpp @@ -136,17 +136,17 @@ bool TWinSCPPlugin::ConfigureEx(const GUID * /* Item */) bool Change = false; std::unique_ptr MenuItems(std::make_unique()); - const int32_t MInterface = MenuItems->Add(GetMsg(NB_CONFIG_INTERFACE)); - const int32_t MConfirmations = MenuItems->Add(GetMsg(NB_CONFIG_CONFIRMATIONS)); - const int32_t MPanel = MenuItems->Add(GetMsg(NB_CONFIG_PANEL)); - const int32_t MTransfer = MenuItems->Add(GetMsg(NB_CONFIG_TRANSFER)); - const int32_t MBackground = MenuItems->Add(GetMsg(NB_CONFIG_BACKGROUND)); - const int32_t MEndurance = MenuItems->Add(GetMsg(NB_CONFIG_ENDURANCE)); - const int32_t MTransferEditor = MenuItems->Add(GetMsg(NB_CONFIG_TRANSFER_EDITOR)); - const int32_t MLogging = MenuItems->Add(GetMsg(NB_CONFIG_LOGGING)); - const int32_t MIntegration = MenuItems->Add(GetMsg(NB_CONFIG_INTEGRATION)); + const int32_t MInterface = MenuItems->AddString(GetMsg(NB_CONFIG_INTERFACE)); + const int32_t MConfirmations = MenuItems->AddString(GetMsg(NB_CONFIG_CONFIRMATIONS)); + const int32_t MPanel = MenuItems->AddString(GetMsg(NB_CONFIG_PANEL)); + const int32_t MTransfer = MenuItems->AddString(GetMsg(NB_CONFIG_TRANSFER)); + const int32_t MBackground = MenuItems->AddString(GetMsg(NB_CONFIG_BACKGROUND)); + const int32_t MEndurance = MenuItems->AddString(GetMsg(NB_CONFIG_ENDURANCE)); + const int32_t MTransferEditor = MenuItems->AddString(GetMsg(NB_CONFIG_TRANSFER_EDITOR)); + const int32_t MLogging = MenuItems->AddString(GetMsg(NB_CONFIG_LOGGING)); + const int32_t MIntegration = MenuItems->AddString(GetMsg(NB_CONFIG_INTEGRATION)); MenuItems->AddSeparator(); - const int32_t MAbout = MenuItems->Add(GetMsg(NB_CONFIG_ABOUT)); + const int32_t MAbout = MenuItems->AddString(GetMsg(NB_CONFIG_ABOUT)); intptr_t Result; @@ -283,7 +283,7 @@ TCustomFarFileSystem * TWinSCPPlugin::OpenPluginEx(OPENFROM OpenFrom, intptr_t I else { FileSystem = std::make_unique(this); - FileSystem->Init(nullptr); + FileSystem->InitWinSCPFileSystem(nullptr); if (OpenFrom == OPEN_LEFTDISKMENU || OpenFrom == OPEN_RIGHTDISKMENU || OpenFrom == OPEN_PLUGINSMENU || @@ -434,28 +434,28 @@ void TWinSCPPlugin::CommandsMenu(bool FromFileSystem) const bool FSVisible = FSConnected && FromFileSystem; const bool AnyFSVisible = (FSConnected || AnotherFSConnected) && FromFileSystem; - const int32_t MAttributes = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_ATTRIBUTES), FSVisible); - const int32_t MLink = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_LINK), FSVisible); - const int32_t MApplyCommand = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_APPLY_COMMAND), FSVisible); - const int32_t MFullSynchronize = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_FULL_SYNCHRONIZE), AnyFSVisible); - const int32_t MSynchronize = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_SYNCHRONIZE), AnyFSVisible); - const int32_t MQueue = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_QUEUE), FSVisible); - const int32_t MInformation = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_INFORMATION), FSVisible); - const int32_t MLog = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_LOG), FSVisible); - const int32_t MClearCaches = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_CLEAR_CACHES), FSVisible); - const int32_t MPutty = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_PUTTY), FSVisible); - const int32_t MEditHistory = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_EDIT_HISTORY), FSConnected); + const int32_t MAttributes = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_ATTRIBUTES), FSVisible); + const int32_t MLink = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_LINK), FSVisible); + const int32_t MApplyCommand = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_APPLY_COMMAND), FSVisible); + const int32_t MFullSynchronize = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_FULL_SYNCHRONIZE), AnyFSVisible); + const int32_t MSynchronize = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_SYNCHRONIZE), AnyFSVisible); + const int32_t MQueue = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_QUEUE), FSVisible); + const int32_t MInformation = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_INFORMATION), FSVisible); + const int32_t MLog = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_LOG), FSVisible); + const int32_t MClearCaches = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_CLEAR_CACHES), FSVisible); + const int32_t MPutty = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_PUTTY), FSVisible); + const int32_t MEditHistory = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_EDIT_HISTORY), FSConnected); MenuItems->AddSeparator(FSConnected || FSVisible); - const int32_t MAddBookmark = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_ADD_BOOKMARK), FSVisible); - const int32_t MOpenDirectory = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_OPEN_DIRECTORY), FSVisible); - const int32_t MHomeDirectory = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_HOME_DIRECTORY), FSVisible); - const int32_t MSynchronizeBrowsing = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_SYNCHRONIZE_BROWSING), FSVisible); + const int32_t MAddBookmark = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_ADD_BOOKMARK), FSVisible); + const int32_t MOpenDirectory = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_OPEN_DIRECTORY), FSVisible); + const int32_t MHomeDirectory = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_HOME_DIRECTORY), FSVisible); + const int32_t MSynchronizeBrowsing = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_SYNCHRONIZE_BROWSING), FSVisible); MenuItems->AddSeparator(FSVisible); - const int32_t MPageant = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_PAGEANT), FromFileSystem); - const int32_t MPuttygen = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_PUTTYGEN), FromFileSystem); + const int32_t MPageant = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_PAGEANT), FromFileSystem); + const int32_t MPuttygen = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_PUTTYGEN), FromFileSystem); MenuItems->AddSeparator(FromFileSystem); - const int32_t MConfigure = MenuItems->Add(GetMsg(NB_MENU_COMMANDS_CONFIGURE)); - const int32_t MAbout = MenuItems->Add(GetMsg(NB_CONFIG_ABOUT)); + const int32_t MConfigure = MenuItems->AddString(GetMsg(NB_MENU_COMMANDS_CONFIGURE)); + const int32_t MAbout = MenuItems->AddString(GetMsg(NB_CONFIG_ABOUT)); MenuItems->SetDisabled(MLog, !FSVisible || (WinSCPFileSystem && !WinSCPFileSystem->IsLogging())); MenuItems->SetDisabled(MClearCaches, !FSVisible || (WinSCPFileSystem && WinSCPFileSystem->AreCachesEmpty())); diff --git a/src/base/Classes.cpp b/src/base/Classes.cpp index 9d98d7e51..ebd63c0d6 100644 --- a/src/base/Classes.cpp +++ b/src/base/Classes.cpp @@ -1162,8 +1162,8 @@ int64_t THandleStream::Seek(const int64_t Offset, TSeekOrigin SeekOrigin) const void THandleStream::SetSize(int64_t NewSize) { - const auto res = Seek(NewSize, TSeekOrigin::soBeginning); - DebugAssert(res == NewSize); + const auto Res = Seek(NewSize, TSeekOrigin::soBeginning); + DebugAssert(Res == NewSize); // LARGE_INTEGER li; // li.QuadPart = size; // if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1) @@ -1330,8 +1330,8 @@ void TMemoryStream::SetSize(int64_t NewSize) FSize = NewSize; if (OldPosition > NewSize) { - const auto res = Seek(0, TSeekOrigin::soEnd); - DebugAssert(res == NewSize); + const auto Res = Seek(0, TSeekOrigin::soEnd); + DebugAssert(Res == NewSize); } } @@ -1706,8 +1706,8 @@ intptr_t TRegistry::ReadIntPtr(const UnicodeString & Name) const { int32_t Result = 0; TRegDataType RegData = rdUnknown; - const auto res = GetData(Name, &Result, sizeof(Result), RegData); - DebugAssert(res == sizeof(Result)); + const auto Res = GetData(Name, &Result, sizeof(Result), RegData); + DebugAssert(Res == sizeof(Result)); if (RegData != rdIntPtr) { ReadError(Name); @@ -1719,8 +1719,8 @@ int32_t TRegistry::ReadInteger(const UnicodeString & Name) const { DWORD Result{0}; TRegDataType RegData = rdUnknown; - const int32_t res = GetData(Name, &Result, sizeof(Result), RegData); - DebugAssert(res == sizeof(Result)); + const int32_t Res = GetData(Name, &Result, sizeof(Result), RegData); + DebugAssert(Res == sizeof(Result)); if (RegData != rdInteger) { ReadError(Name); @@ -1731,8 +1731,8 @@ int32_t TRegistry::ReadInteger(const UnicodeString & Name) const int64_t TRegistry::ReadInt64(const UnicodeString & Name) const { int64_t Result = 0; - const auto res = ReadBinaryData(Name, &Result, sizeof(Result)); - DebugAssert(res == sizeof(Result)); + const auto Res = ReadBinaryData(Name, &Result, sizeof(Result)); + DebugAssert(Res == sizeof(Result)); return Result; } @@ -1778,8 +1778,8 @@ int32_t TRegistry::ReadBinaryData(const UnicodeString & Name, TRegDataType RegData = Info.RegData; if (((RegData == rdBinary) || (RegData == rdUnknown)) && (Result <= BufSize)) { - const int32_t res = GetData(Name, Buffer, Result, RegData); - DebugAssert(res == Result); + const int32_t Res = GetData(Name, Buffer, Result, RegData); + DebugAssert(Res == Result); } else { diff --git a/src/base/System.IOUtils.cpp b/src/base/System.IOUtils.cpp index 44a0900d7..0850548c2 100644 --- a/src/base/System.IOUtils.cpp +++ b/src/base/System.IOUtils.cpp @@ -3,7 +3,7 @@ TFileStream * TFile::OpenRead(const UnicodeString & FileName) { - TFileStream * Result = TFileStream::Create(FileName, fmOpenRead || fmShareDenyWrite); + TFileStream * Result = TFileStream::Create(FileName, fmOpenRead | fmShareDenyWrite); return Result; } diff --git a/src/base/Sysutils.hpp b/src/base/Sysutils.hpp index 759d947c3..9689dbfb9 100644 --- a/src/base/Sysutils.hpp +++ b/src/base/Sysutils.hpp @@ -639,7 +639,7 @@ class NB_CORE_EXPORT EDirectoryNotFoundException final : public Exception explicit EDirectoryNotFoundException(TObjectClassId Kind, const UnicodeString & What) noexcept : Exception(Kind, What) {} }; -inline bool CheckHandle(HANDLE AFileHandle) +inline bool CheckHandle(const HANDLE AFileHandle) { return (AFileHandle != nullptr) && (AFileHandle != INVALID_HANDLE_VALUE); } diff --git a/src/core/Bookmarks.cpp b/src/core/Bookmarks.cpp index 60c2a680f..9fb0fa29b 100644 --- a/src/core/Bookmarks.cpp +++ b/src/core/Bookmarks.cpp @@ -254,7 +254,7 @@ TBookmarkList * TBookmarks::GetBookmarks(const UnicodeString & AIndex) return nullptr; } -void TBookmarks::SetBookmarks(const UnicodeString & AIndex, TBookmarkList * Value) +void TBookmarks::SetBookmarks(const UnicodeString & AIndex, const TBookmarkList * Value) { int32_t Index = FBookmarkLists->IndexOf(AIndex); if (Index >= 0) @@ -367,7 +367,7 @@ void TBookmarkList::InsertBefore(TBookmark * BeforeBookmark, TBookmark * Bookmar Insert(Index, Bookmark); } -void TBookmarkList::MoveTo(TBookmark * ToBookmark, +void TBookmarkList::MoveTo(const TBookmark * ToBookmark, const TBookmark * Bookmark, bool Before) { DebugAssert(ToBookmark != nullptr); @@ -416,7 +416,7 @@ void TBookmarkList::Delete(TBookmark *& Bookmark) SAFE_DESTROY(Bookmark); } -int32_t TBookmarkList::IndexOf(TBookmark * Bookmark) const +int32_t TBookmarkList::IndexOf(const TBookmark * Bookmark) const { return FBookmarks->IndexOf(Bookmark->GetKey()); } diff --git a/src/core/Bookmarks.h b/src/core/Bookmarks.h index c0cf255d7..fd5ee68df 100644 --- a/src/core/Bookmarks.h +++ b/src/core/Bookmarks.h @@ -31,7 +31,7 @@ class NB_CORE_EXPORT TBookmarks final : public TObject public: TBookmarkList * GetBookmarks(const UnicodeString & AIndex); - void SetBookmarks(const UnicodeString & AIndex, TBookmarkList * Value); + void SetBookmarks(const UnicodeString & AIndex, const TBookmarkList * Value); TBookmarkList * GetSharedBookmarks(); void SetSharedBookmarks(TBookmarkList * Value); @@ -57,7 +57,7 @@ class NB_CORE_EXPORT TBookmarkList final : public TPersistent void Add(TBookmark * Bookmark); void Insert(int32_t Index, TBookmark * Bookmark); void InsertBefore(TBookmark * BeforeBookmark, TBookmark * Bookmark); - void MoveTo(TBookmark * ToBookmark, const TBookmark * Bookmark, bool Before); + void MoveTo(const TBookmark * ToBookmark, const TBookmark * Bookmark, bool Before); void Delete(TBookmark *& Bookmark); TBookmark * FindByName(const UnicodeString & Node, const UnicodeString & Name) const; TBookmark * FindByShortCut(const TShortCut & ShortCut); @@ -72,7 +72,7 @@ class NB_CORE_EXPORT TBookmarkList final : public TPersistent // __property bool NodeOpened[UnicodeString Index] = { read = GetNodeOpened, write = SetNodeOpened }; protected: - int32_t IndexOf(TBookmark * Bookmark) const; + int32_t IndexOf(const TBookmark * Bookmark) const; void KeyChanged(int32_t Index); __property bool Modified = { read = FModified, write = FModified }; diff --git a/src/core/Configuration.cpp b/src/core/Configuration.cpp index d67e5eafe..adb2844ee 100644 --- a/src/core/Configuration.cpp +++ b/src/core/Configuration.cpp @@ -812,7 +812,7 @@ void TConfiguration::LoadDirectoryChangesCache(const UnicodeString & SessionKey, } void TConfiguration::SaveDirectoryChangesCache(const UnicodeString & SessionKey, - TRemoteDirectoryChangesCache * DirectoryChangesCache) + const TRemoteDirectoryChangesCache * DirectoryChangesCache) { std::unique_ptr Storage(CreateConfigStorage()); try__finally @@ -1420,7 +1420,7 @@ UnicodeString TConfiguration::GetFileVersion(const UnicodeString & AFileName) co return Result; } -UnicodeString TConfiguration::GetFileVersion(TVSFixedFileInfo * Info) const +UnicodeString TConfiguration::GetFileVersion(const TVSFixedFileInfo * Info) const { const TGuard Guard(FCriticalSection); UnicodeString Result; @@ -2045,7 +2045,7 @@ TStrings * TConfiguration::LoadDirectoryStatisticsCache( } void TConfiguration::SaveDirectoryStatisticsCache( - const UnicodeString & SessionKey, const UnicodeString & Path, const TCopyParamType & CopyParam, TStrings * DataList) + const UnicodeString & SessionKey, const UnicodeString & Path, const TCopyParamType & CopyParam, const TStrings * DataList) { std::unique_ptr Storage(OpenDirectoryStatisticsCache(true)); if (Storage != nullptr) diff --git a/src/core/Configuration.h b/src/core/Configuration.h index c75b57d6d..a8af3b133 100644 --- a/src/core/Configuration.h +++ b/src/core/Configuration.h @@ -162,7 +162,7 @@ class NB_CORE_EXPORT TConfiguration : public TObject UnicodeString GetFileProductVersion() const; UnicodeString GetProductName() const; UnicodeString GetCompanyName() const; - UnicodeString GetFileVersion(TVSFixedFileInfo * Info) const; + UnicodeString GetFileVersion(const TVSFixedFileInfo * Info) const; UnicodeString GetStoredSessionsSubKey() const; UnicodeString DoGetPuttySessionsKey() const; UnicodeString GetPuttySessionsSubKey() const; @@ -322,11 +322,11 @@ class NB_CORE_EXPORT TConfiguration : public TObject void LoadDirectoryChangesCache(const UnicodeString & SessionKey, TRemoteDirectoryChangesCache * DirectoryChangesCache); void SaveDirectoryChangesCache(const UnicodeString & SessionKey, - TRemoteDirectoryChangesCache * DirectoryChangesCache); + const TRemoteDirectoryChangesCache * DirectoryChangesCache); TStrings * LoadDirectoryStatisticsCache( const UnicodeString & SessionKey, const UnicodeString & Path, const TCopyParamType & CopyParam); void SaveDirectoryStatisticsCache( - const UnicodeString & SessionKey, const UnicodeString & Path, const TCopyParamType & CopyParam, TStrings * DataList); + const UnicodeString & SessionKey, const UnicodeString & Path, const TCopyParamType & CopyParam, const TStrings * DataList); bool ShowBanner(const UnicodeString & ASessionKey, const UnicodeString & ABanner, uint32_t & AParams); void NeverShowBanner(const UnicodeString & ASessionKey, const UnicodeString & ABanner); void SetBannerParams(const UnicodeString & ASessionKey, uint32_t AParams); diff --git a/src/core/CoreMain.cpp b/src/core/CoreMain.cpp index 100dd7355..2fcd89d91 100644 --- a/src/core/CoreMain.cpp +++ b/src/core/CoreMain.cpp @@ -131,7 +131,7 @@ bool IsAuthenticationPrompt(TPromptKind Kind) (Kind == pkPassword) || (Kind == pkNewPassword); } -bool IsPasswordOrPassphrasePrompt(TPromptKind Kind, TStrings * Prompts) +bool IsPasswordOrPassphrasePrompt(TPromptKind Kind, const TStrings * Prompts) { return (Prompts->GetCount() == 1) && FLAGCLEAR(nb::ToIntPtr(Prompts->Objects[0]), pupEcho) && @@ -139,7 +139,7 @@ bool IsPasswordOrPassphrasePrompt(TPromptKind Kind, TStrings * Prompts) (Kind == pkTIS) || (Kind == pkCryptoCard)); } -bool IsPasswordPrompt(TPromptKind Kind, TStrings * Prompts) +bool IsPasswordPrompt(TPromptKind Kind, const TStrings * Prompts) { return IsPasswordOrPassphrasePrompt(Kind, Prompts) && diff --git a/src/core/Cryptography.cpp b/src/core/Cryptography.cpp index 14cd9a0da..85a41730b 100644 --- a/src/core/Cryptography.cpp +++ b/src/core/Cryptography.cpp @@ -619,7 +619,7 @@ void CryptographyInitialize() { UnscrambleTable[SScrambleTable[Index]] = static_cast(Index); } - srand(nb::ToUInt32(time(nullptr)) ^ nb::ToUInt32(_getpid())); + // srand(nb::ToUInt32(time(nullptr)) ^ nb::ToUInt32(_getpid())); RAND_poll(); } diff --git a/src/core/FileMasks.cpp b/src/core/FileMasks.cpp index 9d42e5a49..491736769 100644 --- a/src/core/FileMasks.cpp +++ b/src/core/FileMasks.cpp @@ -763,7 +763,7 @@ void TFileMasks::TrimEx(UnicodeString & Str, int32_t & Start, int32_t & End) End -= Buf.Length() - Str.Length(); } -bool TFileMasks::MatchesMaskMask(TMask::TKind MaskKind, Masks::TMask * MaskMask, const UnicodeString & Str) +bool TFileMasks::MatchesMaskMask(TMask::TKind MaskKind, const Masks::TMask * MaskMask, const UnicodeString & Str) { bool Result; if (MaskKind == TMask::TKind::Any) @@ -862,7 +862,7 @@ void TFileMasks::SetRoots(const UnicodeString & LocalRoot, const UnicodeString & } } -void TFileMasks::SetRoots(TStrings * LocalFileList, const UnicodeString & RemoteRoot) +void TFileMasks::SetRoots(const TStrings * LocalFileList, const UnicodeString & RemoteRoot) { if (FAnyRelative) // optimization { @@ -872,7 +872,7 @@ void TFileMasks::SetRoots(TStrings * LocalFileList, const UnicodeString & Remote } } -void TFileMasks::SetRoots(const UnicodeString & LocalRoot, TStrings * RemoteFileList) +void TFileMasks::SetRoots(const UnicodeString & LocalRoot, const TStrings * RemoteFileList) { if (FAnyRelative) // optimization { @@ -1227,7 +1227,7 @@ TCustomCommandData::TCustomCommandData(const TCustomCommandData & Data) noexcept Init(Data.FSessionData.get()); } -TCustomCommandData::TCustomCommandData(TTerminal * Terminal) noexcept +TCustomCommandData::TCustomCommandData(const TTerminal * Terminal) noexcept { // Should use FillSessionDataForCode as in TCustomScpExplorerForm::SessionDataForCode Init(Terminal->SessionData, Terminal->UserName, Terminal->Password, @@ -1245,7 +1245,7 @@ TCustomCommandData::TCustomCommandData( Init(SessionData, UserName, Password, UnicodeString()); } -void TCustomCommandData::Init(TSessionData * ASessionData) +void TCustomCommandData::Init(const TSessionData * ASessionData) { FSessionData = std::make_unique(L""); if (ASessionData != nullptr) diff --git a/src/core/FileMasks.h b/src/core/FileMasks.h index c57a448c5..a9dcb97e6 100644 --- a/src/core/FileMasks.h +++ b/src/core/FileMasks.h @@ -58,8 +58,8 @@ friend class TTerminal; const TParams * Params, bool RecurseInclude, bool & ImplicitMatch) const; void SetRoots(const UnicodeString & LocalRoot, const UnicodeString & RemoteRoot); - void SetRoots(TStrings * LocalFileList, const UnicodeString & RemoteRoot); - void SetRoots(const UnicodeString & LocalRoot, TStrings * RemoteFileList); + void SetRoots(const TStrings * LocalFileList, const UnicodeString & RemoteRoot); + void SetRoots(const UnicodeString & LocalRoot, const TStrings * RemoteFileList); __property UnicodeString Masks = { read = FStr, write = SetMasks }; RWPropertySimple Masks{&FStr, nb::bind(&TFileMasks::SetMasks, this)}; @@ -130,7 +130,7 @@ friend class TTerminal; static bool MatchesMasks( const UnicodeString & AFileName, bool Local, bool Directory, const UnicodeString & APath, const TParams * Params, const TMasks & Masks, bool Recurse); - static bool MatchesMaskMask(TMask::TKind MaskKind, Masks::TMask * MaskMask, const UnicodeString & Str); + static bool MatchesMaskMask(TMask::TKind MaskKind, const Masks::TMask * MaskMask, const UnicodeString & Str); static Masks::TMask * DoCreateMaskMask(const UnicodeString & Str); void ThrowError(int32_t Start, int32_t End) const; bool DoMatches( @@ -210,7 +210,7 @@ struct NB_CORE_EXPORT TCustomCommandData final : public TObject public: TCustomCommandData() noexcept; TCustomCommandData(const TCustomCommandData & Data) noexcept; - explicit TCustomCommandData(TTerminal * Terminal) noexcept; + explicit TCustomCommandData(const TTerminal * Terminal) noexcept; explicit TCustomCommandData(TSessionData * SessionData); explicit TCustomCommandData( TSessionData * SessionData, const UnicodeString & AUserName, @@ -224,7 +224,7 @@ struct NB_CORE_EXPORT TCustomCommandData final : public TObject private: std::unique_ptr FSessionData; - void Init(TSessionData * ASessionData); + void Init(const TSessionData * ASessionData); void Init( TSessionData * ASessionData, const UnicodeString & AUserName, const UnicodeString & APassword, const UnicodeString & AHostKey); diff --git a/src/core/FileOperationProgress.cpp b/src/core/FileOperationProgress.cpp index 543ff01cd..1320a7652 100644 --- a/src/core/FileOperationProgress.cpp +++ b/src/core/FileOperationProgress.cpp @@ -1019,7 +1019,7 @@ void TFileOperationProgressType::Store(TPersistence & Persistence) Persistence = FPersistence; } -void TFileOperationProgressType::Restore(TPersistence & Persistence) +void TFileOperationProgressType::Restore(const TPersistence & Persistence) { TGuard Guard(FSection); FPersistence = Persistence; diff --git a/src/core/FileOperationProgress.h b/src/core/FileOperationProgress.h index 482337762..0824d2af4 100644 --- a/src/core/FileOperationProgress.h +++ b/src/core/FileOperationProgress.h @@ -272,7 +272,7 @@ class NB_CORE_EXPORT TFileOperationProgressType final : public TObject void SetSkipToAll(); UnicodeString GetLogStr(bool ADone) const; void Store(TPersistence & Persistence); - void Restore(TPersistence & Persistence); + void Restore(const TPersistence & Persistence); bool IsIndeterminate() const; bool IsTransfer() const; diff --git a/src/core/FtpFileSystem.cpp b/src/core/FtpFileSystem.cpp index e23dae721..21550d47b 100644 --- a/src/core/FtpFileSystem.cpp +++ b/src/core/FtpFileSystem.cpp @@ -2185,12 +2185,19 @@ void TFTPFileSystem::DoReadDirectory(TRemoteFileList * AFileList) { CheckTimeDifference(); - if ((FTimeDifference != 0) || !FUploadedTimes.empty())// optimization + auto CheckForEsc = FTerminal->GetOnCheckForEsc(); + for (int32_t Index = 0; Index < AFileList->GetCount(); ++Index) { - for (int32_t Index = 0; Index < AFileList->GetCount(); ++Index) + if (CheckForEsc != nullptr && CheckForEsc()) { - ApplyTimeDifference(AFileList->GetFile(Index)); + break; + } + auto File = AFileList->GetFile(Index); + if ((FTimeDifference != 0) || !FUploadedTimes.empty())// optimization + { + ApplyTimeDifference(File); } + File->Complete(); } } @@ -2624,12 +2631,11 @@ void TFTPFileSystem::ReadFile(const UnicodeString & AFileName, void TFTPFileSystem::ReadSymlink(TRemoteFile * SymlinkFile, TRemoteFile *& AFile) { - if (FForceReadSymlink && DebugAlwaysTrue(!SymlinkFile->LinkTo.IsEmpty()) && DebugAlwaysTrue(SymlinkFile->GetHaveFullFileName())) + if (DebugAlwaysTrue(!SymlinkFile->LinkTo.IsEmpty())) { // When we get here from TFTPFileSystem::ReadFile, it's likely the second time ReadSymlink has been called for the link. // The first time getting to the later branch, so IsDirectory is true and hence FullFileName ends with a slash. - const UnicodeString SymlinkDir = base::UnixExtractFileDir(base::UnixExcludeTrailingBackslash(SymlinkFile->FullFileName())); - const UnicodeString LinkTo = base::AbsolutePath(SymlinkDir, SymlinkFile->LinkTo); + const UnicodeString LinkTo = SymlinkFile->GetFullLinkName(); ReadFile(LinkTo, AFile); } else @@ -4436,7 +4442,7 @@ bool TFTPFileSystem::HandleAsyncRequestVerifyCertificate( { if (FTerminal->ConfirmCertificate(FSessionInfo, Data.VerificationResult, FtpsCertificateStorageKey, true)) { - // FZ's VerifyCertDlg.cpp returns 2 for "cached", what we do nto distinguish here, + // FZ's VerifyCertDlg.cpp returns 2 for "cached", what we do not distinguish here, // however FZAPI takes all non-zero values equally. RequestResult = 1; FSessionInfo.CertificateVerifiedManually = true; @@ -4625,7 +4631,7 @@ bool TFTPFileSystem::HandleListData(const wchar_t * Path, File->SetLinkTo(Entry->LinkTarget); - File->Complete(); + // File->Complete(); } catch (Exception &E) { diff --git a/src/core/Interface.h b/src/core/Interface.h index b6f5101e9..de49ae114 100644 --- a/src/core/Interface.h +++ b/src/core/Interface.h @@ -167,7 +167,7 @@ enum TPromptKind enum TPromptUserParam { pupEcho = 0x01, pupRemember = 0x02 }; NB_CORE_EXPORT bool IsAuthenticationPrompt(TPromptKind Kind); -NB_CORE_EXPORT bool IsPasswordOrPassphrasePrompt(TPromptKind Kind, TStrings * Prompts); +NB_CORE_EXPORT bool IsPasswordOrPassphrasePrompt(TPromptKind Kind, const TStrings * Prompts); NB_CORE_EXPORT bool IsPasswordPrompt(TPromptKind Kind, TStrings * Prompts); void AnswerNameAndCaption(uint32_t Answer, UnicodeString & Name, UnicodeString & Caption); class TTerminal; diff --git a/src/core/RemoteFiles.cpp b/src/core/RemoteFiles.cpp index 590792d2c..04262b25c 100644 --- a/src/core/RemoteFiles.cpp +++ b/src/core/RemoteFiles.cpp @@ -1035,14 +1035,7 @@ void TRemoteFile::SetIsHidden(bool Value) Boolean TRemoteFile::GetIsDirectory() const { - if (IsSymLink && (FLinkedFile != nullptr)) - { - return FLinkedFile->IsDirectory; - } - else - { - return (::UpCase(GetType()) == FILETYPE_DIRECTORY); - } + return (::UpCase(GetType()) == FILETYPE_DIRECTORY); } Boolean TRemoteFile::GetIsParentDirectory() const @@ -1160,6 +1153,15 @@ UnicodeString TRemoteFile::GetRightsStr() const return FRights->GetUnknown() ? GetHumanRights() : FRights->GetText(); } +UnicodeString TRemoteFile::GetFullLinkName() const +{ + if (base::UnixIsAbsolutePath(FLinkTo) || FLinkedByFile == nullptr) + { + return FLinkTo; + } + return base::UnixCombinePaths(base::UnixExtractFilePath(FLinkedByFile->GetFullLinkName()), FLinkTo); +} + void TRemoteFile::SetListingStr(const UnicodeString & Value) { // Value stored in 'Value' can be used for error message @@ -1590,6 +1592,8 @@ void TRemoteFile::FindLinkedFile() { TRemoteFile * File{nullptr}; GetTerminalNotConst()->ReadSymlink(this, File); + SetType(File == nullptr ? FILETYPE_SYMLINK : File->GetType()); + SetIsSymLink(true); FLinkedFile.reset(File); } __finally diff --git a/src/core/RemoteFiles.h b/src/core/RemoteFiles.h index a0a67309e..e243b09a8 100644 --- a/src/core/RemoteFiles.h +++ b/src/core/RemoteFiles.h @@ -132,6 +132,7 @@ class NB_CORE_EXPORT TRemoteFile : public TPersistent void SetListingStr(const UnicodeString & Value); UnicodeString GetListingStr() const; UnicodeString GetRightsStr() const; + UnicodeString GetFullLinkName() const; wchar_t GetType() const; void SetType(wchar_t AType); void SetTerminal(const TTerminal * Value); @@ -303,7 +304,7 @@ class NB_CORE_EXPORT TRemoteFileList : public TObjectList virtual void SetDirectory(const UnicodeString & Value); UnicodeString GetFullDirectory() const; Boolean GetIsRoot() const; - TRemoteFile * GetParentDirectory(); + // TRemoteFile * GetParentDirectory() const; UnicodeString GetParentPath() const; int64_t GetTotalSize() const; diff --git a/src/core/ScpFileSystem.cpp b/src/core/ScpFileSystem.cpp index 0d51a910d..7506dabf9 100644 --- a/src/core/ScpFileSystem.cpp +++ b/src/core/ScpFileSystem.cpp @@ -559,6 +559,7 @@ void TSCPFileSystem::SendCommand(const UnicodeString & Cmd, bool NoEnsureLocatio FOutput->Clear(); // We suppose, that 'Cmd' already contains command that ensures, // that 'LastLine' will be printed + FTerminal->LogEvent(FORMAT("Raw command: %s", Cmd)); FSecureShell->SendLine(Cmd); FProcessingCommand = true; } @@ -1104,8 +1105,13 @@ void TSCPFileSystem::ReadDirectory(TRemoteFileList * FileList) OutputCopy->Delete(0); } + auto CheckForEsc = FTerminal->GetOnCheckForEsc(); for (int32_t Index = 0; Index < OutputCopy->GetCount(); ++Index) { + if (CheckForEsc != nullptr && CheckForEsc()) + { + break; + } UnicodeString OutputLine = OutputCopy->GetString(Index); if (!OutputLine.IsEmpty()) { @@ -1231,8 +1237,9 @@ void TSCPFileSystem::CustomReadFile(const UnicodeString & AFileName, // the auto-detection of --full-time support is not implemented for fsListFile, // so we use it only if we already know that it is supported (asOn). const UnicodeString Options = (FLsFullTime == asOn) ? FullTimeOption : ""; + const UnicodeString FileName = ALinkedByFile ? ALinkedByFile->GetFullLinkName() : AFileName; ExecCommand(fsListFile, Params, - FTerminal->GetSessionData()->GetListingCommand(), Options, DelimitStr(AFileName) + FTerminal->GetSessionData()->GetListingCommand(), Options, DelimitStr(FileName) ); if (FOutput->GetCount()) { diff --git a/src/core/SessionInfo.cpp b/src/core/SessionInfo.cpp index 136e837ab..2930a865c 100644 --- a/src/core/SessionInfo.cpp +++ b/src/core/SessionInfo.cpp @@ -794,7 +794,7 @@ TFileSystemInfo::TFileSystemInfo() noexcept } -static FILE * LocalOpenLogFile(const UnicodeString & LogFileName, const TDateTime & Started, TSessionData * SessionData, bool Append, UnicodeString & ANewFileName) +static FILE * OpenLogFile(const UnicodeString & LogFileName, const TDateTime & Started, TSessionData * SessionData, bool Append, UnicodeString & ANewFileName) { // FILE * Result; const UnicodeString NewFileName = StripPathQuotes(GetExpandedLogFileName(LogFileName, Started, SessionData)); @@ -1071,7 +1071,7 @@ void TSessionLog::OpenLogFile() DebugAssert(FLogger == nullptr); DebugAssert(FConfiguration != nullptr); FCurrentLogFileName = FConfiguration->GetLogFileName(); - FILE * file = LocalOpenLogFile(FCurrentLogFileName, FStarted, FSessionData, FConfiguration->GetLogFileAppend(), FCurrentFileName); + FILE * file = ::OpenLogFile(FCurrentLogFileName, FStarted, FSessionData, FConfiguration->GetLogFileAppend(), FCurrentFileName); FLogger = std::make_unique(); FLogger->file(file); TSearchRec SearchRec; @@ -1792,7 +1792,7 @@ void TActionLog::OpenLogFile() DebugAssert(FConfiguration != nullptr); DebugAssert(FLogger == nullptr); FCurrentLogFileName = FConfiguration->GetActionsLogFileName(); - FILE * file = LocalOpenLogFile(FCurrentLogFileName, FStarted, FSessionData, false, FCurrentFileName); + FILE * file = ::OpenLogFile(FCurrentLogFileName, FStarted, FSessionData, false, FCurrentFileName); FLogger = std::make_unique(); FLogger->file(file); } @@ -1897,7 +1897,7 @@ void TApplicationLog::Enable(const UnicodeString & Path) { UnicodeString Dummy; FPath = Path; - FFile = LocalOpenLogFile(FPath, Now(), nullptr, false, Dummy); + FFile = OpenLogFile(FPath, Now(), nullptr, false, Dummy); FLogging = true; } diff --git a/src/core/SessionInfo.h b/src/core/SessionInfo.h index e8d3f0f7b..c1702181e 100644 --- a/src/core/SessionInfo.h +++ b/src/core/SessionInfo.h @@ -416,7 +416,7 @@ friend class TSessionActionRecord; void SetEnabled(bool Value); }; -class TApplicationLog +class TApplicationLog final { CUSTOM_MEM_ALLOCATION_IMPL public: diff --git a/src/filezilla/AsyncProxySocketLayer.cpp b/src/filezilla/AsyncProxySocketLayer.cpp index 30a27d024..d03fcccd1 100644 --- a/src/filezilla/AsyncProxySocketLayer.cpp +++ b/src/filezilla/AsyncProxySocketLayer.cpp @@ -186,7 +186,7 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode) } else if (m_ProxyData.nProxyType==PROXYTYPE_SOCKS5) { - if (m_nProxyOpState==1) //Get respone to initialization message + if (m_nProxyOpState==1) //Get response to initialization message { if (!m_pRecvBuffer) m_pRecvBuffer=nb::chcalloc(2); @@ -264,8 +264,8 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode) //No auth needed //Send connection request const char *lpszAsciiHost = m_pProxyPeerHost?m_pProxyPeerHost:""; - char *command=nb::chcalloc(10+nb::safe_strlen(lpszAsciiHost)+1); - memset(command,0,10+nb::safe_strlen(lpszAsciiHost)+1); + char *command=nb::chcalloc(11+nb::safe_strlen(lpszAsciiHost)+1); + memset(command,0,11+nb::safe_strlen(lpszAsciiHost)+1); command[0]=5; command[1]=(m_nProxyOpID==PROXYOP_CONNECT)?1:2; command[2]=0; @@ -279,7 +279,7 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode) else { command[len]=(char)nb::safe_strlen(lpszAsciiHost); - strncpy_s(&command[len+1], 10+nb::safe_strlen(lpszAsciiHost)+1, lpszAsciiHost, nb::safe_strlen(lpszAsciiHost)); + strncpy_s(&command[len+1], 11+nb::safe_strlen(lpszAsciiHost)+1, lpszAsciiHost, nb::safe_strlen(lpszAsciiHost)); len += (int)nb::safe_strlen(lpszAsciiHost) + 1; } nbstr_memcpy(&command[len], &m_nProxyPeerPort, 2); @@ -327,8 +327,8 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode) return; } const char * lpszAsciiHost = m_pProxyPeerHost?m_pProxyPeerHost:""; - char *command = nb::chcalloc(10+nb::safe_strlen(lpszAsciiHost)+1); - memset(command,0,10+nb::safe_strlen(lpszAsciiHost)+1); + char *command = nb::chcalloc(11+nb::safe_strlen(lpszAsciiHost)+1); + memset(command,0,11+nb::safe_strlen(lpszAsciiHost)+1); command[0]=5; command[1]=(m_nProxyOpID==PROXYOP_CONNECT)?1:2; command[2]=0; @@ -342,7 +342,7 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode) else { command[len]=(char)nb::safe_strlen(lpszAsciiHost); - strncpy_s(&command[len+1], 10+nb::safe_strlen(lpszAsciiHost)+1, lpszAsciiHost, nb::safe_strlen(lpszAsciiHost)); + strncpy_s(&command[len+1], 11+nb::safe_strlen(lpszAsciiHost)+1, lpszAsciiHost, nb::safe_strlen(lpszAsciiHost)); len+=(int)nb::safe_strlen(lpszAsciiHost)+1; } nbstr_memcpy(&command[len],&m_nProxyPeerPort,2);