zlib: Update to version 1.3.1.2 and use context in decompression

This commit is contained in:
yuanyuanxiang
2026-01-15 14:34:10 +01:00
parent 32f298bdfb
commit 38517e20f9
14 changed files with 341 additions and 208 deletions

View File

@@ -22,6 +22,11 @@ CAudioManager::CAudioManager(IOCPClient* ClientObject, int n, void* user):CManag
if (Initialize()==FALSE) { if (Initialize()==FALSE) {
szPacket = NULL; szPacket = NULL;
m_hWorkThread = NULL; m_hWorkThread = NULL;
char buf[128];
sprintf_s(buf, "打开语音设备失败[IP: %s]", m_ClientObject->GetPublicIP().c_str());
Mprintf("%s\n", buf);
ClientMsg msg("语音管理", buf);
m_ClientObject->Send2Server((char*)&msg, sizeof(msg));
return; return;
} }

View File

@@ -62,7 +62,7 @@ template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
DWORD private_desktop(CONNECT_ADDRESS* conn, const State &exit, const std::string& hash, const std::string& hmac) DWORD private_desktop(CONNECT_ADDRESS* conn, const State &exit, const std::string& hash, const std::string& hmac)
{ {
void ShowBlackWindow(IOCPBase * ClientObject, CONNECT_ADDRESS * conn, const std::string & hash, const std::string & hmac); void ShowBlackWindow(IOCPBase * ClientObject, CONNECT_ADDRESS * conn, const std::string & hash, const std::string & hmac);
IOCPClient* ClientObject = new IOCPClient(exit, true, MaskTypeNone, conn->iHeaderEnc); IOCPClient* ClientObject = new IOCPClient(exit, true, MaskTypeNone, conn);
if (ClientObject->ConnectServer(conn->ServerIP(), conn->ServerPort())) { if (ClientObject->ConnectServer(conn->ServerIP(), conn->ServerPort())) {
CScreenManager m(ClientObject, 32, (void*)1); CScreenManager m(ClientObject, 32, (void*)1);
if (IsWindows8orHigher()) { if (IsWindows8orHigher()) {

View File

@@ -93,9 +93,10 @@ VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess, O
} }
IOCPClient::IOCPClient(const State&bExit, bool exit_while_disconnect, int mask, int encoder, IOCPClient::IOCPClient(const State&bExit, bool exit_while_disconnect, int mask, CONNECT_ADDRESS* conn,
const std::string& pubIP) : g_bExit(bExit) const std::string& pubIP) : g_bExit(bExit)
{ {
int encoder = conn ? conn->GetHeaderEncType() : 0;
m_sLocPublicIP = pubIP; m_sLocPublicIP = pubIP;
m_ServerAddr = {}; m_ServerAddr = {};
m_nHostPort = 0; m_nHostPort = 0;

View File

@@ -151,7 +151,7 @@ typedef BOOL(*TrailCheck)(void);
class IOCPClient : public IOCPBase class IOCPClient : public IOCPBase
{ {
public: public:
IOCPClient(const State& bExit, bool exit_while_disconnect = false, int mask=0, int encoder=0, IOCPClient(const State& bExit, bool exit_while_disconnect = false, int mask=0, CONNECT_ADDRESS *conn=0,
const std::string&pubIP=""); const std::string&pubIP="");
virtual ~IOCPClient(); virtual ~IOCPClient();
@@ -223,6 +223,12 @@ public:
return g_bExit; return g_bExit;
} }
void SetMultiThreadCompress(int threadNum=0); void SetMultiThreadCompress(int threadNum=0);
std::string GetClientID() const {
return m_conn ? std::to_string(m_conn->clientID) : "";
}
std::string GetPublicIP() const {
return m_sLocPublicIP;
}
protected: protected:
virtual int ReceiveData(char* buffer, int bufSize, int flags) virtual int ReceiveData(char* buffer, int bufSize, int flags)
{ {
@@ -266,4 +272,5 @@ protected:
PkgMask* m_masker; PkgMask* m_masker;
BOOL m_EncoderType; BOOL m_EncoderType;
std::string m_sLocPublicIP; std::string m_sLocPublicIP;
CONNECT_ADDRESS *m_conn = NULL;
}; };

View File

@@ -30,11 +30,11 @@ IOCPClient* NewNetClient(CONNECT_ADDRESS* conn, State& bExit, const std::string&
int type = conn->protoType == PROTO_RANDOM ? time(nullptr) % PROTO_RANDOM : conn->protoType; int type = conn->protoType == PROTO_RANDOM ? time(nullptr) % PROTO_RANDOM : conn->protoType;
if (!conn->IsVerified() || type == PROTO_TCP) if (!conn->IsVerified() || type == PROTO_TCP)
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeNone, conn->GetHeaderEncType(), publicIP); return new IOCPClient(bExit, exit_while_disconnect, MaskTypeNone, conn, publicIP);
if (type == PROTO_UDP) if (type == PROTO_UDP)
return new IOCPUDPClient(bExit, exit_while_disconnect); return new IOCPUDPClient(bExit, exit_while_disconnect);
if (type == PROTO_HTTP || type == PROTO_HTTPS) if (type == PROTO_HTTP || type == PROTO_HTTPS)
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP, conn->GetHeaderEncType(), publicIP); return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP, conn, publicIP);
if (type == PROTO_KCP) { if (type == PROTO_KCP) {
return new IOCPKCPClient(bExit, exit_while_disconnect); return new IOCPKCPClient(bExit, exit_while_disconnect);
} }
@@ -46,7 +46,7 @@ ThreadInfo* CreateKB(CONNECT_ADDRESS* conn, State& bExit, const std::string &pub
{ {
static ThreadInfo tKeyboard; static ThreadInfo tKeyboard;
tKeyboard.run = FOREVER_RUN; tKeyboard.run = FOREVER_RUN;
tKeyboard.p = new IOCPClient(bExit, false, MaskTypeNone, conn->GetHeaderEncType(), publicIP); tKeyboard.p = new IOCPClient(bExit, false, MaskTypeNone, conn, publicIP);
tKeyboard.conn = conn; tKeyboard.conn = conn;
tKeyboard.h = (HANDLE)__CreateThread(NULL, NULL, LoopKeyboardManager, &tKeyboard, 0, NULL); tKeyboard.h = (HANDLE)__CreateThread(NULL, NULL, LoopKeyboardManager, &tKeyboard, 0, NULL);
return &tKeyboard; return &tKeyboard;
@@ -769,7 +769,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
} }
case COMMAND_PROXY: { case COMMAND_PROXY: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopProxyManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopProxyManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
@@ -831,33 +831,33 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
if (m_hKeyboard) { if (m_hKeyboard) {
CloseHandle(__CreateThread(NULL, 0, SendKeyboardRecord, m_hKeyboard->user, 0, NULL)); CloseHandle(__CreateThread(NULL, 0, SendKeyboardRecord, m_hKeyboard->user, 0, NULL));
} else { } else {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopKeyboardManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopKeyboardManager, &m_hThread[m_ulThreadCount], 0, NULL);;
} }
break; break;
} }
case COMMAND_TALK: { case COMMAND_TALK: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount].user = m_hInstance; m_hThread[m_ulThreadCount].user = m_hInstance;
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopTalkManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopTalkManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_SHELL: { case COMMAND_SHELL: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopShellManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopShellManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_SYSTEM: { //远程进程管理 case COMMAND_SYSTEM: { //远程进程管理
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopProcessManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL, 0, LoopProcessManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_WSLIST: { //远程窗口管理 case COMMAND_WSLIST: { //远程窗口管理
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopWindowManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopWindowManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
@@ -892,14 +892,14 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
memcpy(user->buffer, szBuffer + 1, ulLength - 1); memcpy(user->buffer, szBuffer + 1, ulLength - 1);
if (ulLength > 2 && !m_conn->IsVerified()) user->buffer[2] = 0; if (ulLength > 2 && !m_conn->IsVerified()) user->buffer[2] = 0;
} }
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount].user = user; m_hThread[m_ulThreadCount].user = user;
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopScreenManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopScreenManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_LIST_DRIVE : { case COMMAND_LIST_DRIVE : {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopFileManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopFileManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
@@ -907,25 +907,25 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
case COMMAND_WEBCAM: { case COMMAND_WEBCAM: {
static bool hasCamera = WebCamIsExist(); static bool hasCamera = WebCamIsExist();
if (!hasCamera) break; if (!hasCamera) break;
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopVideoManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopVideoManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_AUDIO: { case COMMAND_AUDIO: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopAudioManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopAudioManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_REGEDIT: { case COMMAND_REGEDIT: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopRegisterManager, &m_hThread[m_ulThreadCount], 0, NULL);; m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopRegisterManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break; break;
} }
case COMMAND_SERVICES: { case COMMAND_SERVICES: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType(), publicIP); m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopServicesManager, &m_hThread[m_ulThreadCount], 0, NULL); m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopServicesManager, &m_hThread[m_ulThreadCount], 0, NULL);
break; break;
} }

View File

@@ -469,7 +469,7 @@ void RunFileReceiver(CScreenManager *mgr, const std::string &folder, const std::
{ {
auto start = time(0); auto start = time(0);
Mprintf("Enter thread RunFileReceiver: %d\n", GetCurrentThreadId()); Mprintf("Enter thread RunFileReceiver: %d\n", GetCurrentThreadId());
IOCPClient* pClient = new IOCPClient(mgr->g_bExit, true, MaskTypeNone, mgr->m_conn->GetHeaderEncType()); IOCPClient* pClient = new IOCPClient(mgr->g_bExit, true, MaskTypeNone, mgr->m_conn);
if (pClient->ConnectServer(mgr->m_ClientObject->ServerIP().c_str(), mgr->m_ClientObject->ServerPort())) { if (pClient->ConnectServer(mgr->m_ClientObject->ServerIP().c_str(), mgr->m_ClientObject->ServerPort())) {
pClient->setManagerCallBack(mgr, CManager::DataProcess, CManager::ReconnectProcess); pClient->setManagerCallBack(mgr, CManager::DataProcess, CManager::ReconnectProcess);
// 发送目录并准备接收文件 // 发送目录并准备接收文件
@@ -657,7 +657,7 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
files = GetClipboardFiles(result); files = GetClipboardFiles(result);
} }
if (!files.empty() && !dir.empty()) { if (!files.empty() && !dir.empty()) {
IOCPClient* pClient = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType()); IOCPClient* pClient = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn);
if (pClient->ConnectServer(m_ClientObject->ServerIP().c_str(), m_ClientObject->ServerPort())) { if (pClient->ConnectServer(m_ClientObject->ServerIP().c_str(), m_ClientObject->ServerPort())) {
std::thread(FileBatchTransferWorker, files, dir, pClient, ::SendData, ::FinishSend, std::thread(FileBatchTransferWorker, files, dir, pClient, ::SendData, ::FinishSend,
m_hash, m_hmac).detach(); m_hash, m_hmac).detach();

View File

@@ -23,8 +23,14 @@ CServicesManager::~CServicesManager()
VOID CServicesManager::SendServicesList() VOID CServicesManager::SendServicesList()
{ {
LPBYTE szBuffer = GetServicesList(); LPBYTE szBuffer = GetServicesList();
if (szBuffer == NULL) if (szBuffer == NULL) {
char buf[128];
sprintf_s(buf, "获取服务列表失败[IP: %s]", m_ClientObject->GetPublicIP().c_str());
Mprintf("%s\n", buf);
ClientMsg msg("服务管理", buf);
m_ClientObject->Send2Server((char*)&msg, sizeof(msg));
return; return;
}
HttpMask mask(DEFAULT_HOST, m_ClientObject->GetClientIPHeader()); HttpMask mask(DEFAULT_HOST, m_ClientObject->GetClientIPHeader());
m_ClientObject->Send2Server((char*)szBuffer, LocalSize(szBuffer), &mask); m_ClientObject->Send2Server((char*)szBuffer, LocalSize(szBuffer), &mask);
LocalFree(szBuffer); LocalFree(szBuffer);

View File

@@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * Copyright (C) 1995-2025 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -7,8 +7,11 @@
#ifndef ZCONF_H #ifndef ZCONF_H
#define ZCONF_H #define ZCONF_H
/* #undef Z_PREFIX */ /* #undef Z_PREFIX */
/* #undef Z_HAVE_UNISTD_H */ #define HAVE_STDARG_H 1
/* #undef HAVE_UNISTD_H */
ZCONF_H
/* /*
* If you *really* need a unique prefix for all types and library functions, * If you *really* need a unique prefix for all types and library functions,
@@ -61,6 +64,7 @@
# define deflateSetDictionary z_deflateSetDictionary # define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader # define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune # define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright # define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table # define get_crc_table z_get_crc_table
# ifndef Z_SOLO # ifndef Z_SOLO
@@ -236,27 +240,29 @@
# endif # endif
#endif #endif
#if defined(ZLIB_CONST) && !defined(z_const) #ifndef z_const
# define z_const const # ifdef ZLIB_CONST
#else # define z_const const
# define z_const # else
# define z_const
# endif
#endif #endif
#ifdef Z_SOLO #ifdef Z_SOLO
# ifdef _WIN64 # ifdef _WIN64
typedef unsigned long long z_size_t; typedef unsigned long long z_size_t;
# else # else
typedef unsigned long z_size_t; typedef unsigned long z_size_t;
# endif # endif
#else #else
# define z_longlong long long # define z_longlong long long
# if defined(NO_SIZE_T) # if defined(NO_SIZE_T)
typedef unsigned NO_SIZE_T z_size_t; typedef unsigned NO_SIZE_T z_size_t;
# elif defined(STDC) # elif defined(STDC)
# include <stddef.h> # include <stddef.h>
typedef size_t z_size_t; typedef size_t z_size_t;
# else # else
typedef unsigned long z_size_t; typedef unsigned long z_size_t;
# endif # endif
# undef z_longlong # undef z_longlong
#endif #endif
@@ -292,7 +298,7 @@ typedef unsigned long z_size_t;
for small objects. for small objects.
*/ */
/* Type declarations */ /* Type declarations */
#ifndef OF /* function prototypes */ #ifndef OF /* function prototypes */
# ifdef STDC # ifdef STDC
@@ -310,7 +316,7 @@ typedef unsigned long z_size_t;
*/ */
#ifdef SYS16BIT #ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM) # if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */ /* MSC small or medium model */
# define SMALL_MEDIUM # define SMALL_MEDIUM
# ifdef _MSC_VER # ifdef _MSC_VER
# define FAR _far # define FAR _far
@@ -319,7 +325,7 @@ typedef unsigned long z_size_t;
# endif # endif
# endif # endif
# if (defined(__SMALL__) || defined(__MEDIUM__)) # if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */ /* Turbo C small or medium model */
# define SMALL_MEDIUM # define SMALL_MEDIUM
# ifdef __BORLANDC__ # ifdef __BORLANDC__
# define FAR _far # define FAR _far
@@ -330,9 +336,9 @@ typedef unsigned long z_size_t;
#endif #endif
#if defined(WINDOWS) || defined(WIN32) #if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL. /* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase. * This is not mandatory, but it offers a little performance increase.
*/ */
# ifdef ZLIB_DLL # ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL # ifdef ZLIB_INTERNAL
@@ -342,10 +348,10 @@ typedef unsigned long z_size_t;
# endif # endif
# endif # endif
# endif /* ZLIB_DLL */ # endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention, /* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI. * define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/ */
# ifdef ZLIB_WINAPI # ifdef ZLIB_WINAPI
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
@@ -354,8 +360,8 @@ typedef unsigned long z_size_t;
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# endif # endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI # define ZEXPORT WINAPI
# ifdef WIN32 # ifdef WIN32
# define ZEXPORTVA WINAPIV # define ZEXPORTVA WINAPIV
@@ -398,10 +404,10 @@ typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */ typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM #ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR # define Bytef Byte FAR
#else #else
typedef Byte FAR Bytef; typedef Byte FAR Bytef;
#endif #endif
typedef char FAR charf; typedef char FAR charf;
typedef int FAR intf; typedef int FAR intf;
@@ -409,13 +415,13 @@ typedef uInt FAR uIntf;
typedef uLong FAR uLongf; typedef uLong FAR uLongf;
#ifdef STDC #ifdef STDC
typedef void const *voidpc; typedef void const *voidpc;
typedef void FAR *voidpf; typedef void FAR *voidpf;
typedef void *voidp; typedef void *voidp;
#else #else
typedef Byte const *voidpc; typedef Byte const *voidpc;
typedef Byte FAR *voidpf; typedef Byte FAR *voidpf;
typedef Byte *voidp; typedef Byte *voidp;
#endif #endif
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
@@ -430,16 +436,16 @@ typedef Byte *voidp;
#endif #endif
#ifdef Z_U4 #ifdef Z_U4
typedef Z_U4 z_crc_t; typedef Z_U4 z_crc_t;
#else #else
typedef unsigned long z_crc_t; typedef unsigned long z_crc_t;
#endif #endif
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ #if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H # define Z_HAVE_UNISTD_H
#endif #endif
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ #if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */
# define Z_HAVE_STDARG_H # define Z_HAVE_STDARG_H
#endif #endif
@@ -472,12 +478,8 @@ typedef unsigned long z_crc_t;
#endif #endif
#ifndef Z_HAVE_UNISTD_H #ifndef Z_HAVE_UNISTD_H
# ifdef __WATCOMC__ # if defined(__WATCOMC__) || defined(__GO32__) || \
# define Z_HAVE_UNISTD_H (defined(_LARGEFILE64_SOURCE) && !defined(_WIN32))
# endif
#endif
#ifndef Z_HAVE_UNISTD_H
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
# define Z_HAVE_UNISTD_H # define Z_HAVE_UNISTD_H
# endif # endif
#endif #endif
@@ -512,34 +514,36 @@ typedef unsigned long z_crc_t;
#endif #endif
#ifndef z_off_t #ifndef z_off_t
# define z_off_t long # define z_off_t long long
#endif #endif
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#elif defined(__MINGW32__)
# define z_off64_t long long
#elif defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64
#elif defined(__GO32__)
# define z_off64_t offset_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t z_off_t
# define z_off64_t __int64
# else
# define z_off64_t z_off_t
# endif
#endif #endif
/* MVS linker does not support external names larger than 8 bytes */ /* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__) #if defined(__MVS__)
#pragma map(deflateInit_,"DEIN") #pragma map(deflateInit_,"DEIN")
#pragma map(deflateInit2_,"DEIN2") #pragma map(deflateInit2_,"DEIN2")
#pragma map(deflateEnd,"DEEND") #pragma map(deflateEnd,"DEEND")
#pragma map(deflateBound,"DEBND") #pragma map(deflateBound,"DEBND")
#pragma map(inflateInit_,"ININ") #pragma map(inflateInit_,"ININ")
#pragma map(inflateInit2_,"ININ2") #pragma map(inflateInit2_,"ININ2")
#pragma map(inflateEnd,"INEND") #pragma map(inflateEnd,"INEND")
#pragma map(inflateSync,"INSY") #pragma map(inflateSync,"INSY")
#pragma map(inflateSetDictionary,"INSEDI") #pragma map(inflateSetDictionary,"INSEDI")
#pragma map(compressBound,"CMBND") #pragma map(compressBound,"CMBND")
#pragma map(inflate_table,"INTABL") #pragma map(inflate_table,"INTABL")
#pragma map(inflate_fast,"INFA") #pragma map(inflate_fast,"INFA")
#pragma map(inflate_copyright,"INCOPY") #pragma map(inflate_copyright,"INCOPY")
#endif #endif
#endif /* ZCONF_H */ #endif /* ZCONF_H */

View File

@@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.3.1, January 22nd, 2024 version 1.3.1.2, December 8th, 2025
Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler Copyright (C) 1995-2025 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@@ -24,25 +24,29 @@
The data format used by the zlib library is described by RFCs (Request for The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 Comments) 1950 to 1952 at https://datatracker.ietf.org/doc/html/rfc1950
(zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
*/ */
#ifndef ZLIB_H #ifndef ZLIB_H
#define ZLIB_H #define ZLIB_H
#include "zconf.h" #ifdef ZLIB_BUILD
# include <zconf.h>
#else
# include "zconf.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.3.1" #define ZLIB_VERSION "1.3.1.2-audit"
#define ZLIB_VERNUM 0x1310 #define ZLIB_VERNUM 0x1312
#define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 3 #define ZLIB_VER_MINOR 3
#define ZLIB_VER_REVISION 1 #define ZLIB_VER_REVISION 1
#define ZLIB_VER_SUBREVISION 0 #define ZLIB_VER_SUBREVISION 2
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and
@@ -163,7 +167,7 @@ typedef gz_header FAR *gz_headerp;
if the decompressor wants to decompress everything in a single step). if the decompressor wants to decompress everything in a single step).
*/ */
/* constants */ /* constants */
#define Z_NO_FLUSH 0 #define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 #define Z_PARTIAL_FLUSH 1
@@ -215,7 +219,7 @@ typedef gz_header FAR *gz_headerp;
/* for compatibility with versions < 1.0.2 */ /* for compatibility with versions < 1.0.2 */
/* basic functions */ /* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion(void); ZEXTERN const char * ZEXPORT zlibVersion(void);
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
@@ -441,7 +445,7 @@ ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
The Z_BLOCK option assists in appending to or combining deflate streams. The Z_BLOCK option assists in appending to or combining deflate streams.
To assist in this, on return inflate() always sets strm->data_type to the To assist in this, on return inflate() always sets strm->data_type to the
number of unused bits in the last byte taken from strm->next_in, plus 64 if number of unused bits in the input taken from strm->next_in, plus 64 if
inflate() is currently decoding the last block in the deflate stream, plus inflate() is currently decoding the last block in the deflate stream, plus
128 if inflate() returned immediately after decoding an end-of-block code or 128 if inflate() returned immediately after decoding an end-of-block code or
decoding the complete header up to just before the first byte of the deflate decoding the complete header up to just before the first byte of the deflate
@@ -529,7 +533,7 @@ ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
*/ */
/* Advanced functions */ /* Advanced functions */
/* /*
The following functions are needed only in some special applications. The following functions are needed only in some special applications.
@@ -587,18 +591,21 @@ ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
The strategy parameter is used to tune the compression algorithm. Use the The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no filter (or predictor), Z_RLE to limit match distances to one (run-length
string match), or Z_RLE to limit match distances to one (run-length encoding), or Z_HUFFMAN_ONLY to force Huffman encoding only (no string
encoding). Filtered data consists mostly of small values with a somewhat matching). Filtered data consists mostly of small values with a somewhat
random distribution. In this case, the compression algorithm is tuned to random distribution, as produced by the PNG filters. In this case, the
compress them better. The effect of Z_FILTERED is to force more Huffman compression algorithm is tuned to compress them better. The effect of
coding and less string matching; it is somewhat intermediate between Z_FILTERED is to force more Huffman coding and less string matching than the
Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as default; it is intermediate between Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY.
fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The Z_RLE is almost as fast as Z_HUFFMAN_ONLY, but should give better
strategy parameter only affects the compression ratio but not the compression for PNG image data than Huffman only. The degree of string
correctness of the compressed output even if it is not set appropriately. matching from most to none is: Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, then
Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler Z_HUFFMAN_ONLY. The strategy parameter affects the compression ratio but
decoder for special applications. never the correctness of the compressed output, even if it is not set
optimally for the given data. Z_FIXED uses the default string matching, but
prevents the use of dynamic Huffman codes, allowing for a simpler decoder
for special applications.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
@@ -609,8 +616,8 @@ ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
*/ */
ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength); uInt dictLength);
/* /*
Initializes the compression dictionary from the given byte sequence Initializes the compression dictionary from the given byte sequence
without producing any compressed output. When using the zlib format, this without producing any compressed output. When using the zlib format, this
@@ -653,8 +660,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
*/ */
ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength); uInt *dictLength);
/* /*
Returns the sliding dictionary being maintained by deflate. dictLength is Returns the sliding dictionary being maintained by deflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
@@ -788,6 +795,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateUsed(z_streamp strm,
int *bits);
/*
deflateUsed() returns in *bits the most recent number of deflate bits used
in the last byte when flushing to a byte boundary. The result is in 1..8, or
0 if there has not yet been a flush. This helps determine the location of
the last bit of a deflate stream.
deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
int bits, int bits,
int value); int value);
@@ -886,8 +905,8 @@ ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
*/ */
ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength); uInt dictLength);
/* /*
Initializes the decompression dictionary from the given uncompressed byte Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate, sequence. This function must be called immediately after a call of inflate,
@@ -909,8 +928,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
*/ */
ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength); uInt *dictLength);
/* /*
Returns the sliding dictionary being maintained by inflate. dictLength is Returns the sliding dictionary being maintained by inflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
@@ -987,13 +1006,15 @@ ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
int bits, int bits,
int value); int value);
/* /*
This function inserts bits in the inflate input stream. The intent is This function inserts bits in the inflate input stream. The intent is to
that this function is used to start inflating at a bit position in the use inflatePrime() to start inflating at a bit position in the middle of a
middle of a byte. The provided bits will be used before any bytes are used byte. The provided bits will be used before any bytes are used from
from next_in. This function should only be used with raw inflate, and next_in. This function should be used with raw inflate, before the first
should be used before the first inflate() call after inflateInit2() or inflate() call, after inflateInit2() or inflateReset(). It can also be used
inflateReset(). bits must be less than or equal to 16, and that many of the after an inflate() return indicates the end of a deflate block or header
least significant bits of value will be inserted in the input. when using Z_BLOCK. bits must be less than or equal to 16, and that many of
the least significant bits of value will be inserted in the input. The
other bits in value can be non-zero, and will be ignored.
If bits is negative, then the input stream bit buffer is emptied. Then If bits is negative, then the input stream bit buffer is emptied. Then
inflatePrime() can be called again to put bits in the buffer. This is used inflatePrime() can be called again to put bits in the buffer. This is used
@@ -1001,7 +1022,15 @@ ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
to feeding inflate codes. to feeding inflate codes.
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent, or if bits is out of range. If inflate was
in the middle of processing a header, trailer, or stored block lengths, then
it is possible for there to be only eight bits available in the bit buffer.
In that case, bits > 8 is considered out of range. However, when used as
outlined above, there will always be 16 bits available in the buffer for
insertion. As noted in its documentation above, inflate records the number
of bits in the bit buffer on return in data_type. 32 minus that is the
number of bits available for insertion. inflatePrime does not update
data_type with the new number of bits in buffer.
*/ */
ZEXTERN long ZEXPORT inflateMark(z_streamp strm); ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
@@ -1047,20 +1076,22 @@ ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
The text, time, xflags, and os fields are filled in with the gzip header The text, time, xflags, and os fields are filled in with the gzip header
contents. hcrc is set to true if there is a header CRC. (The header CRC contents. hcrc is set to true if there is a header CRC. (The header CRC
was valid if done is set to one.) If extra is not Z_NULL, then extra_max was valid if done is set to one.) The extra, name, and comment pointers
contains the maximum number of bytes to write to extra. Once done is true, much each be either Z_NULL or point to space to store that information from
extra_len contains the actual extra field length, and extra contains the the header. If extra is not Z_NULL, then extra_max contains the maximum
extra field, or that field truncated if extra_max is less than extra_len. number of bytes that can be written to extra. Once done is true, extra_len
If name is not Z_NULL, then up to name_max characters are written there, contains the actual extra field length, and extra contains the extra field,
terminated with a zero unless the length is greater than name_max. If or that field truncated if extra_max is less than extra_len. If name is not
comment is not Z_NULL, then up to comm_max characters are written there, Z_NULL, then up to name_max characters, including the terminating zero, are
terminated with a zero unless the length is greater than comm_max. When any written there. If comment is not Z_NULL, then up to comm_max characters,
of extra, name, or comment are not Z_NULL and the respective field is not including the terminating zero, are written there. The application can tell
present in the header, then that field is set to Z_NULL to signal its that the name or comment did not fit in the provided space by the absence of
absence. This allows the use of deflateSetHeader() with the returned a terminating zero. If any of extra, name, or comment are not present in
structure to duplicate the header. However if those fields are set to the header, then that field's pointer is set to Z_NULL. This allows the use
allocated memory, then the application will need to save those pointers of deflateSetHeader() with the returned structure to duplicate the header.
elsewhere so that they can be eventually freed. Note that if those fields initially pointed to allocated memory, then the
application will need to save them elsewhere so that they can be eventually
freed.
If inflateGetHeader is not used, then the header information is simply If inflateGetHeader is not used, then the header information is simply
discarded. The header is always checked for validity, including the header discarded. The header is always checked for validity, including the header
@@ -1219,7 +1250,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
#ifndef Z_SOLO #ifndef Z_SOLO
/* utility functions */ /* utility functions */
/* /*
The following utility functions are implemented on top of the basic The following utility functions are implemented on top of the basic
@@ -1293,7 +1324,7 @@ ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen,
source bytes consumed. source bytes consumed.
*/ */
/* gzip file access functions */ /* gzip file access functions */
/* /*
This library supports reading and writing files in gzip (.gz) format with This library supports reading and writing files in gzip (.gz) format with
@@ -1314,13 +1345,17 @@ ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
as in "wb9F". (See the description of deflateInit2 for more information as in "wb9F". (See the description of deflateInit2 for more information
about the strategy parameter.) 'T' will request transparent writing or about the strategy parameter.) 'T' will request transparent writing or
appending with no compression and not using the gzip format. appending with no compression and not using the gzip format. 'T' cannot be
used to force transparent reading. Transparent reading is automatically
performed if there is no gzip header at the start. Transparent reading can
be disabled with the 'G' option, which will instead return an error if there
is no gzip header. 'N' will open the file in non-blocking mode.
"a" can be used instead of "w" to request that the gzip stream that will 'a' can be used instead of 'w' to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since be written be appended to the file. '+' will result in an error, since
reading and writing to the same gzip file is not supported. The addition of reading and writing to the same gzip file is not supported. The addition of
"x" when writing will create the file exclusively, which fails if the file 'x' when writing will create the file exclusively, which fails if the file
already exists. On systems that support it, the addition of "e" when already exists. On systems that support it, the addition of 'e' when
reading or writing will set the flag to close the file on an execve() call. reading or writing will set the flag to close the file on an execve() call.
These functions, as well as gzip, will read and decode a sequence of gzip These functions, as well as gzip, will read and decode a sequence of gzip
@@ -1339,14 +1374,22 @@ ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
insufficient memory to allocate the gzFile state, or if an invalid mode was insufficient memory to allocate the gzFile state, or if an invalid mode was
specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
errno can be checked to determine if the reason gzopen failed was that the errno can be checked to determine if the reason gzopen failed was that the
file could not be opened. file could not be opened. Note that if 'N' is in mode for non-blocking, the
open() itself can fail in order to not block. In that case gzopen() will
return NULL and errno will be EAGAIN or ENONBLOCK. The call to gzopen() can
then be re-tried. If the application would like to block on opening the
file, then it can use open() without O_NONBLOCK, and then gzdopen() with the
resulting file descriptor and 'N' in the mode, which will set it to non-
blocking.
*/ */
ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
/* /*
Associate a gzFile with the file descriptor fd. File descriptors are Associate a gzFile with the file descriptor fd. File descriptors are
obtained from calls like open, dup, creat, pipe or fileno (if the file has obtained from calls like open, dup, creat, pipe or fileno (if the file has
been previously opened with fopen). The mode parameter is as in gzopen. been previously opened with fopen). The mode parameter is as in gzopen. An
'e' in mode will set fd's flag to close the file on an execve() call. An 'N'
in mode will set fd's non-blocking flag.
The next call of gzclose on the returned gzFile will also close the file The next call of gzclose on the returned gzFile will also close the file
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
@@ -1416,10 +1459,16 @@ ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
stream. Alternatively, gzerror can be used before gzclose to detect this stream. Alternatively, gzerror can be used before gzclose to detect this
case. case.
gzread can be used to read a gzip file on a non-blocking device. If the
input stalls and there is no uncompressed data to return, then gzread() will
return -1, and errno will be EAGAIN or EWOULDBLOCK. gzread() can then be
called again.
gzread returns the number of uncompressed bytes actually read, less than gzread returns the number of uncompressed bytes actually read, less than
len for end of file, or -1 for error. If len is too large to fit in an int, len for end of file, or -1 for error. If len is too large to fit in an int,
then nothing is read, -1 is returned, and the error state is set to then nothing is read, -1 is returned, and the error state is set to
Z_STREAM_ERROR. Z_STREAM_ERROR. If some data was read before an error, then that data is
returned until exhausted, after which the next call will signal the error.
*/ */
ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
@@ -1443,15 +1492,20 @@ ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
multiple of size, then the final partial item is nevertheless read into buf multiple of size, then the final partial item is nevertheless read into buf
and the end-of-file flag is set. The length of the partial item read is not and the end-of-file flag is set. The length of the partial item read is not
provided, but could be inferred from the result of gztell(). This behavior provided, but could be inferred from the result of gztell(). This behavior
is the same as the behavior of fread() implementations in common libraries, is the same as that of fread() implementations in common libraries. This
but it prevents the direct use of gzfread() to read a concurrently written could result in data loss if used with size != 1 when reading a concurrently
file, resetting and retrying on end-of-file, when size is not 1. written file or a non-blocking file. In that case, use size == 1 or gzread()
instead.
*/ */
ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len);
/* /*
Compress and write the len uncompressed bytes at buf to file. gzwrite Compress and write the len uncompressed bytes at buf to file. gzwrite
returns the number of uncompressed bytes written or 0 in case of error. returns the number of uncompressed bytes written, or 0 in case of error or
if len is 0. If the write destination is non-blocking, then gzwrite() may
return a number of bytes written that is not 0 and less than len.
If len does not fit in an int, then 0 is returned and nothing is written.
*/ */
ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
@@ -1466,6 +1520,11 @@ ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
if there was an error. If the multiplication of size and nitems overflows, if there was an error. If the multiplication of size and nitems overflows,
i.e. the product does not fit in a z_size_t, then nothing is written, zero i.e. the product does not fit in a z_size_t, then nothing is written, zero
is returned, and the error state is set to Z_STREAM_ERROR. is returned, and the error state is set to Z_STREAM_ERROR.
If writing a concurrently read file or a non-blocking file with size != 1,
a partial item could be written, with no way of knowing how much of it was
not written, resulting in data loss. In that case, use size == 1 or
gzwrite() instead.
*/ */
ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
@@ -1481,6 +1540,9 @@ ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
zlib was compiled with the insecure functions sprintf() or vsprintf(), zlib was compiled with the insecure functions sprintf() or vsprintf(),
because the secure snprintf() or vsnprintf() functions were not available. because the secure snprintf() or vsnprintf() functions were not available.
This can be determined using zlibCompileFlags(). This can be determined using zlibCompileFlags().
If a Z_BUF_ERROR is returned, then nothing was written due to a stall on
the non-blocking write destination.
*/ */
ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
@@ -1489,6 +1551,11 @@ ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
the terminating null character. the terminating null character.
gzputs returns the number of characters written, or -1 in case of error. gzputs returns the number of characters written, or -1 in case of error.
The number of characters written may be less than the length of the string
if the write destination is non-blocking.
If the length of the string does not fit in an int, then -1 is returned
and nothing is written.
*/ */
ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
@@ -1501,8 +1568,13 @@ ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
left untouched. left untouched.
gzgets returns buf which is a null-terminated string, or it returns NULL gzgets returns buf which is a null-terminated string, or it returns NULL
for end-of-file or in case of error. If there was an error, the contents at for end-of-file or in case of error. If some data was read before an error,
buf are indeterminate. then that data is returned until exhausted, after which the next call will
return NULL to signal the error.
gzgets can be used on a file being concurrently written, and on a non-
blocking device, both as for gzread(). However lines may be broken in the
middle, leaving it up to the application to reassemble them as needed.
*/ */
ZEXTERN int ZEXPORT gzputc(gzFile file, int c); ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
@@ -1513,11 +1585,19 @@ ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
ZEXTERN int ZEXPORT gzgetc(gzFile file); ZEXTERN int ZEXPORT gzgetc(gzFile file);
/* /*
Read and decompress one byte from file. gzgetc returns this byte or -1 Read and decompress one byte from file. gzgetc returns this byte or -1 in
in case of end of file or error. This is implemented as a macro for speed. case of end of file or error. If some data was read before an error, then
As such, it does not do all of the checking the other functions do. I.e. that data is returned until exhausted, after which the next call will return
it does not check to see if file is NULL, nor whether the structure file -1 to signal the error.
points to has been clobbered or not.
This is implemented as a macro for speed. As such, it does not do all of
the checking the other functions do. I.e. it does not check to see if file
is NULL, nor whether the structure file points to has been clobbered or not.
gzgetc can be used to read a gzip file on a non-blocking device. If the
input stalls and there is no uncompressed data to return, then gzgetc() will
return -1, and errno will be EAGAIN or EWOULDBLOCK. gzread() can then be
called again.
*/ */
ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
@@ -1530,6 +1610,11 @@ ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
output buffer size of pushed characters is allowed. (See gzbuffer above.) output buffer size of pushed characters is allowed. (See gzbuffer above.)
The pushed character will be discarded if the stream is repositioned with The pushed character will be discarded if the stream is repositioned with
gzseek() or gzrewind(). gzseek() or gzrewind().
gzungetc(-1, file) will force any pending seek to execute. Then gztell()
will report the position, even if the requested seek reached end of file.
This can be used to determine the number of uncompressed bytes in a gzip
file without having to read it into a buffer.
*/ */
ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
@@ -1559,7 +1644,8 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
If the file is opened for reading, this function is emulated but can be If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new supported; gzseek then compresses a sequence of zeroes up to the new
starting position. starting position. For reading or writing, any actual seeking is deferred
until the next read or write operation, or close operation when writing.
gzseek returns the resulting offset location as measured in bytes from gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in the beginning of the uncompressed stream, or -1 in case of error, in
@@ -1567,7 +1653,7 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
would be before the current position. would be before the current position.
*/ */
ZEXTERN int ZEXPORT gzrewind(gzFile file); ZEXTERN int ZEXPORT gzrewind(gzFile file);
/* /*
Rewind file. This function is supported only for reading. Rewind file. This function is supported only for reading.
@@ -1575,7 +1661,7 @@ ZEXTERN int ZEXPORT gzrewind(gzFile file);
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gztell(gzFile file); ZEXTERN z_off_t ZEXPORT gztell(gzFile file);
Return the starting position for the next gzread or gzwrite on file. Return the starting position for the next gzread or gzwrite on file.
This position represents a number of bytes in the uncompressed data stream, This position represents a number of bytes in the uncompressed data stream,
@@ -1620,8 +1706,11 @@ ZEXTERN int ZEXPORT gzdirect(gzFile file);
If gzdirect() is used immediately after gzopen() or gzdopen() it will If gzdirect() is used immediately after gzopen() or gzdopen() it will
cause buffers to be allocated to allow reading the file to determine if it cause buffers to be allocated to allow reading the file to determine if it
is a gzip file. Therefore if gzbuffer() is used, it should be called before is a gzip file. Therefore if gzbuffer() is used, it should be called before
gzdirect(). gzdirect(). If the input is being written concurrently or the device is non-
blocking, then gzdirect() may give a different answer once four bytes of
input have been accumulated, which is what is needed to confirm or deny a
gzip header. Before this, gzdirect() will return true (1).
When writing, gzdirect() returns true (1) if transparent writing was When writing, gzdirect() returns true (1) if transparent writing was
requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
@@ -1631,7 +1720,7 @@ ZEXTERN int ZEXPORT gzdirect(gzFile file);
gzip file reading and decompression, which may not be desired.) gzip file reading and decompression, which may not be desired.)
*/ */
ZEXTERN int ZEXPORT gzclose(gzFile file); ZEXTERN int ZEXPORT gzclose(gzFile file);
/* /*
Flush all pending output for file, if necessary, close file and Flush all pending output for file, if necessary, close file and
deallocate the (de)compression state. Note that once file is closed, you deallocate the (de)compression state. Note that once file is closed, you
@@ -1659,9 +1748,10 @@ ZEXTERN int ZEXPORT gzclose_w(gzFile file);
ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
/* /*
Return the error message for the last error which occurred on file. Return the error message for the last error which occurred on file.
errnum is set to zlib error number. If an error occurred in the file system If errnum is not NULL, *errnum is set to zlib error number. If an error
and not in the compression library, errnum is set to Z_ERRNO and the occurred in the file system and not in the compression library, *errnum is
application may consult errno to get the exact error code. set to Z_ERRNO and the application may consult errno to get the exact error
code.
The application must not modify the returned string. Future calls to The application must not modify the returned string. Future calls to
this function may invalidate the previously returned string. If file is this function may invalidate the previously returned string. If file is
@@ -1681,7 +1771,7 @@ ZEXTERN void ZEXPORT gzclearerr(gzFile file);
#endif /* !Z_SOLO */ #endif /* !Z_SOLO */
/* checksum functions */ /* checksum functions */
/* /*
These functions are not related to compression but are exported These functions are not related to compression but are exported
@@ -1776,7 +1866,7 @@ ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
*/ */
/* various hacks, don't look :) */ /* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version /* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream: * and the compiler's view of z_stream:
@@ -1856,13 +1946,13 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
* without large file support, _LFS64_LARGEFILE must also be true * without large file support, _LFS64_LARGEFILE must also be true
*/ */
#ifdef Z_LARGE64 #ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
#endif #endif
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
@@ -1884,29 +1974,29 @@ ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
# define crc32_combine_gen crc32_combine_gen64 # define crc32_combine_gen crc32_combine_gen64
# endif # endif
# ifndef Z_LARGE64 # ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int);
ZEXTERN z_off_t ZEXPORT gztell64(gzFile); ZEXTERN z_off_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
# endif # endif
#else #else
ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *);
ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int);
ZEXTERN z_off_t ZEXPORT gztell(gzFile); ZEXTERN z_off_t ZEXPORT gztell(gzFile);
ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); ZEXTERN z_off_t ZEXPORT gzoffset(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
#endif #endif
#else /* Z_SOLO */ #else /* Z_SOLO */
ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
#endif /* !Z_SOLO */ #endif /* !Z_SOLO */
@@ -1926,8 +2016,8 @@ ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path,
#if defined(STDC) || defined(Z_HAVE_STDARG_H) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO # ifndef Z_SOLO
ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, ZEXTERN int ZEXPORTVA gzvprintf(gzFile file,
const char *format, const char *format,
va_list va); va_list va);
# endif # endif
#endif #endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -277,8 +277,10 @@ BOOL IOCPServer::InitializeIOCP(VOID)
DWORD IOCPServer::WorkThreadProc(LPVOID lParam) DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
{ {
// 压缩库配置
ZSTD_DCtx* m_Dctx = ZSTD_createDCtx(); // 解压上下文 ZSTD_DCtx* m_Dctx = ZSTD_createDCtx(); // 解压上下文
z_stream m_stream = {};
inflateInit2(&m_stream, 15);
IOCPServer* This = (IOCPServer*)(lParam); IOCPServer* This = (IOCPServer*)(lParam);
HANDLE hCompletionPort = This->m_hCompletionPort; HANDLE hCompletionPort = This->m_hCompletionPort;
@@ -346,7 +348,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
if (!bError && !This->m_bTimeToKill) { if (!bError && !This->m_bTimeToKill) {
if(bOk && OverlappedPlus!=NULL && ContextObject!=NULL) { if(bOk && OverlappedPlus!=NULL && ContextObject!=NULL) {
try { try {
This->HandleIO(OverlappedPlus->m_ioType, ContextObject, dwTrans, m_Dctx); This->HandleIO(OverlappedPlus->m_ioType, ContextObject, dwTrans, m_Dctx, &m_stream);
ContextObject = NULL; ContextObject = NULL;
} catch (...) { } catch (...) {
@@ -367,13 +369,14 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
Mprintf("======> IOCPServer All WorkThreadProc done\n"); Mprintf("======> IOCPServer All WorkThreadProc done\n");
} }
inflateEnd(&m_stream);
ZSTD_freeDCtx(m_Dctx); ZSTD_freeDCtx(m_Dctx);
return 0; return 0;
} }
//在工作线程中被调用 //在工作线程中被调用
BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx) BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx, z_stream* z)
{ {
BOOL bRet = FALSE; BOOL bRet = FALSE;
@@ -382,7 +385,7 @@ BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWOR
bRet = OnClientInitializing(ContextObject, dwTrans); bRet = OnClientInitializing(ContextObject, dwTrans);
break; break;
case IORead: case IORead:
bRet = OnClientReceiving(ContextObject, dwTrans, ctx); bRet = OnClientReceiving(ContextObject, dwTrans, ctx, z);
break; break;
case IOWrite: case IOWrite:
bRet = OnClientPostSending(ContextObject, dwTrans); bRet = OnClientPostSending(ContextObject, dwTrans);
@@ -404,7 +407,7 @@ BOOL IOCPServer::OnClientInitializing(PCONTEXT_OBJECT ContextObject, DWORD dwTr
} }
// May be this function should be a member of `CONTEXT_OBJECT`. // May be this function should be a member of `CONTEXT_OBJECT`.
BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyProc m_NotifyProc, ZSTD_DCtx* m_Dctx) BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyProc m_NotifyProc, ZSTD_DCtx* m_Dctx, z_stream* z)
{ {
AUTO_TICK(50, ContextObject->GetPeerName()); AUTO_TICK(50, ContextObject->GetPeerName());
BOOL ret = 1; BOOL ret = 1;
@@ -459,7 +462,7 @@ BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyP
PBYTE DeCompressedBuffer = ContextObject->GetDecompressBuffer(ulOriginalLength); PBYTE DeCompressedBuffer = ContextObject->GetDecompressBuffer(ulOriginalLength);
size_t iRet = usingZstd ? size_t iRet = usingZstd ?
Muncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength) : Muncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength) :
uncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength); z_uncompress(z, DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength);
if (usingZstd ? C_SUCCESS(iRet) : (S_OK==iRet)) { if (usingZstd ? C_SUCCESS(iRet) : (S_OK==iRet)) {
ContextObject->InDeCompressedBuffer.ClearBuffer(); ContextObject->InDeCompressedBuffer.ClearBuffer();
ContextObject->Decode(DeCompressedBuffer, ulOriginalLength); ContextObject->Decode(DeCompressedBuffer, ulOriginalLength);
@@ -468,7 +471,7 @@ BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyP
ret = DeCompressedBuffer[0] == TOKEN_LOGIN ? 999 : 1; ret = DeCompressedBuffer[0] == TOKEN_LOGIN ? 999 : 1;
} else if (usingZstd) { } else if (usingZstd) {
// 尝试用zlib解压缩 // 尝试用zlib解压缩
if (Z_OK == uncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength)) { if (Z_OK == z_uncompress(z, DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength)) {
ContextObject->CompressMethod = COMPRESS_ZLIB; ContextObject->CompressMethod = COMPRESS_ZLIB;
ContextObject->InDeCompressedBuffer.ClearBuffer(); ContextObject->InDeCompressedBuffer.ClearBuffer();
ContextObject->Decode(DeCompressedBuffer, ulOriginalLength); ContextObject->Decode(DeCompressedBuffer, ulOriginalLength);
@@ -499,9 +502,9 @@ BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyP
return ret; return ret;
} }
BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx) BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx, z_stream* z)
{ {
if (FALSE == ParseReceivedData(ContextObject, dwTrans, m_NotifyProc, ctx)) { if (FALSE == ParseReceivedData(ContextObject, dwTrans, m_NotifyProc, ctx, z)) {
RemoveStaleContext(ContextObject); RemoveStaleContext(ContextObject);
return FALSE; return FALSE;
} }
@@ -511,7 +514,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
return TRUE; return TRUE;
} }
BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength, ZSTD_CCtx* m_Cctx) BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength, ZSTD_CCtx* m_Cctx, z_stream* z)
{ {
assert(ContextObject); assert(ContextObject);
// 输出服务端所发送的命令 // 输出服务端所发送的命令

View File

@@ -13,6 +13,23 @@
// ZLIB 压缩库 // ZLIB 压缩库
#include "zlib/zlib.h" #include "zlib/zlib.h"
inline int z_uncompress(z_stream* strm, Bytef* dest, uLongf* destLen, const Bytef* src, uLong srcLen)
{
inflateReset(strm);
strm->next_in = (Bytef*)src;
strm->avail_in = srcLen;
strm->next_out = dest;
strm->avail_out = *destLen;
int ret = inflate(strm, Z_FINISH);
*destLen = strm->total_out;
if (ret == Z_STREAM_END) return Z_OK;
return ret;
}
// ZSTD // ZSTD
#include "zstd/zstd.h" #include "zstd/zstd.h"
#ifdef _WIN64 #ifdef _WIN64
@@ -66,9 +83,9 @@ private:
BOOL RemoveStaleContext(CONTEXT_OBJECT* ContextObject); BOOL RemoveStaleContext(CONTEXT_OBJECT* ContextObject);
VOID MoveContextToFreePoolList(CONTEXT_OBJECT* ContextObject); VOID MoveContextToFreePoolList(CONTEXT_OBJECT* ContextObject);
VOID PostRecv(CONTEXT_OBJECT* ContextObject); VOID PostRecv(CONTEXT_OBJECT* ContextObject);
BOOL HandleIO(IOType PacketFlags, PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx); BOOL HandleIO(IOType PacketFlags, PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx, z_stream *z);
BOOL OnClientInitializing(PCONTEXT_OBJECT ContextObject, DWORD dwTrans); BOOL OnClientInitializing(PCONTEXT_OBJECT ContextObject, DWORD dwTrans);
BOOL OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx); BOOL OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans, ZSTD_DCtx* ctx, z_stream* z);
BOOL OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength); BOOL OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength);
BOOL OnClientPostSending(CONTEXT_OBJECT* ContextObject, ULONG ulCompressedLength); BOOL OnClientPostSending(CONTEXT_OBJECT* ContextObject, ULONG ulCompressedLength);
int AddWorkThread(int n) int AddWorkThread(int n)
@@ -210,6 +227,6 @@ public:
typedef CDialogBase DialogBase; typedef CDialogBase DialogBase;
BOOL ParseReceivedData(CONTEXT_OBJECT* ContextObject, DWORD dwTrans, pfnNotifyProc m_NotifyProc, ZSTD_DCtx *ctx=NULL); BOOL ParseReceivedData(CONTEXT_OBJECT* ContextObject, DWORD dwTrans, pfnNotifyProc m_NotifyProc, ZSTD_DCtx *ctx=NULL, z_stream* z=NULL);
BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength, ZSTD_CCtx *ctx=NULL); BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength, ZSTD_CCtx *ctx=NULL, z_stream* z = NULL);