From 592e5967b8fcd79423802071319d0c646f2080df Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Tue, 29 Sep 2026 21:39:24 +0100 Subject: New upstream version 6.0.25.41+repack --- CommonCode.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 241 insertions(+), 31 deletions(-) (limited to 'CommonCode.c') diff --git a/CommonCode.c b/CommonCode.c index 2c01b7c..3559135 100644 --- a/CommonCode.c +++ b/CommonCode.c @@ -89,6 +89,113 @@ extern int PoolBuilt; extern int EnableOARCAPI; +DllExport UCHAR * APIENTRY GetLogDirectory(); + + +FILE * DebugHandle = NULL; + +DllExport VOID APIENTRY OpenDebugLog() +{ + time_t T; + struct tm * tm; + char FN[256]; + + T = time(NULL); + tm = gmtime(&T); + + if (DebugHandle == 0) + { + sprintf(FN,"%s/logs/NodeDebuglog_%02d%02d%02d.log", GetLogDirectory(), tm->tm_year - 100, tm->tm_mon + 1, tm->tm_mday); + DebugHandle = fopen(FN, "ab"); + } +} + +DllExport VOID APIENTRY CloseDebugLog() +{ + if (DebugHandle) + fclose(DebugHandle); + DebugHandle = 0; +} + + +DllExport VOID __cdecl Debugprintf(const char * format, ...) +{ + char Mess[8192]; + time_t T; + struct tm * tm; + int Len; + char LogMsg[256]; + + va_list(arglist); + + va_start(arglist, format); + Len = vsnprintf(Mess, sizeof(Mess), format, arglist); + + T = time(NULL); + tm = gmtime(&T); + + if (DebugHandle == 0) + { + char FN[256]; + + sprintf(FN,"%s/logs/NodeDebuglog_%02d%02d%02d.log", GetLogDirectory(), tm->tm_year - 100, tm->tm_mon + 1, tm->tm_mday); + DebugHandle = fopen(FN, "ab"); + + if (DebugHandle == 0) + return; + } + + + Len = sprintf(LogMsg, "%02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); + fwrite(LogMsg, Len, 1, DebugHandle); + + if (DebugHandle == 0) + return; + + fwrite(Mess, strlen(Mess), 1, DebugHandle); + fwrite("\r\n", 2, 1, DebugHandle); + + return; +} + +DllExport VOID __cdecl DebugprintNOLF(const char * format, ...) +{ + char Mess[8192]; + time_t T; + struct tm * tm; + int Len; + char LogMsg[256]; + + va_list(arglist); + + va_start(arglist, format); + Len = vsnprintf(Mess, sizeof(Mess), format, arglist); + + T = time(NULL); + tm = gmtime(&T); + + if (DebugHandle == 0) + { + char FN[256]; + + sprintf(FN,"%s/logs/NodeDebuglog_%02d%02d%02d.log", GetLogDirectory(), tm->tm_year - 100, tm->tm_mon + 1, tm->tm_mday); + DebugHandle = fopen(FN, "ab"); + + if (DebugHandle == 0) + return; + } + + + Len = sprintf(LogMsg, "%02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); + fwrite(LogMsg, Len, 1, DebugHandle); + + if (DebugHandle == 0) + return; + + fwrite(Mess, strlen(Mess), 1, DebugHandle); + return; +} + // Read/Write length field in a buffer header // Needed for Big/LittleEndian and ARM5 (unaligned operation problem) portability @@ -395,6 +502,23 @@ BOK1: return 0; } +UINT ReleaseBufferQuick(VOID *pBUFF) +{ + void ** pointer, ** BUFF = pBUFF; + + if (Semaphore.Flag == 0) + Debugprintf("ReleaseBufferQuick called without semaphore"); + + pointer = FREE_Q; + + *BUFF = pointer; + + FREE_Q = BUFF; + + QCOUNT++; + return 0; +} + void CheckFreeQueue(char * File, int Line) { @@ -570,7 +694,7 @@ VOID * _GetBuff(char * File, int Line) char * fptr = 0; unsigned char * byteaddr; - CheckFreeQueue(File, Line); +// CheckFreeQueue(File, Line); Temp = Q_REM(&FREE_Q); @@ -621,6 +745,46 @@ VOID * _GetBuff(char * File, int Line) return Temp; } +VOID * GetBuffQuick() +{ + UINT * Temp; + MESSAGE * Msg; + char * fptr = 0; + + Temp = Q_REM(&FREE_Q); + + if (Semaphore.Flag == 0) + Debugprintf("GetBuff called without semaphore"); + + if (Temp) + { + QCOUNT--; + + if (QCOUNT < MINBUFFCOUNT) + MINBUFFCOUNT = QCOUNT; + + Msg = (MESSAGE *)Temp; + + Msg->Process = (short)GetCurrentProcessId(); + Msg->Linkptr = NULL; + Msg->Padding[0] = 0; // Used for modem status info + } + else if (QCOUNT != 0) + { + // Queue must be corrupt + + Debugprintf("Fatal - Getbuff returned NULL and Q not empty - exit"); + FindLostBuffers(); + WriteMiniDump(); + Restart(); + } + else + Debugprintf("Warning - Getbuff returned NULL"); + + return Temp; +} + + void * zalloc(int len) { // malloc and clear @@ -1508,6 +1672,42 @@ DllExport int APIENTRY SessionState(int stream, int * state, int * change) return 0; } +int SessionStateNoSem(int stream, int * state, int * change) +{ + // Get current Session State. Any state changed is ACK'ed + // automatically. See BPQHOST functions 4 and 5. + + BPQVECSTRUC * HOST = &BPQHOSTVECTOR[stream -1]; // API counts from 1 + + Check_Timer(); // In case Appl doesnt call it often ehough + + // CX = 0 if stream disconnected or CX = 1 if stream connected + // DX = 0 if no change of state since last read, or DX = 1 if + // the connected/disconnected state has changed since + // last read (ie. delta-stream status). + + // HOSTFLAGS = Bit 80 = Allocated + // Bit 40 = Disc Request + // Bit 20 = Stay Flag + // Bit 02 and 01 State Change Bits + + if ((HOST->HOSTFLAGS & 3) == 0) + // No Chaange + *change = 0; + else + *change = 1; + + if (HOST->HOSTSESSION) // LOCAL SESSION + // Connected + *state = 1; + else + *state = 0; + + HOST->HOSTFLAGS &= 0xFC; // Clear Change Bitd + return 0; +} + + DllExport int APIENTRY SessionStateNoAck(int stream, int * state) { // Get current Session State. Dont ACK any change @@ -2384,7 +2584,6 @@ HANDLE OpenCOMPort(char * pPort, int speed, BOOL SetDTR, BOOL SetRTS, BOOL Quiet sprintf(buf,"%s Setup Failed %d ", pPort, GetLastError()); WritetoConsoleLocal(buf); - OutputDebugString(buf); CloseHandle(fd); return 0; } @@ -3135,7 +3334,7 @@ char * FormatMH(PMHSTRUC MH, char Format) if (Format == 'U' || Format =='L') szClock = MH->MHTIME; else - szClock = time(NULL) - MH->MHTIME; + szClock = NOW - MH->MHTIME; if (Format == 'L') TM = localtime(&szClock); @@ -3159,7 +3358,6 @@ Dll VOID APIENTRY CreateOneTimePassword(char * Password, char * KeyPhrase, int T // Create a time dependent One Time Password from the KeyPhrase // TimeOffset is used when checking to allow for slight variation in clocks - time_t NOW = time(NULL); UCHAR Hash[16]; char Key[1000]; int i, chr; @@ -3505,7 +3703,6 @@ VOID SendNETROMRoute(struct PORTCONTROL * PORT, unsigned char * axcall) int Len; char Call[10]; char Report[16]; - time_t Now = time(NULL); int NeedSend = FALSE; @@ -3516,7 +3713,7 @@ VOID SendNETROMRoute(struct PORTCONTROL * PORT, unsigned char * axcall) sprintf(Report, "%s,%d,", Call, PORT->PORTTYPE); - if (Now - TimeLastNRRouteSent > 60) + if (NOW - TimeLastNRRouteSent > 60) NeedSend = TRUE; if (strstr(NRRouteMessage, Report) == 0) // reported recently @@ -3540,7 +3737,7 @@ VOID SendNETROMRoute(struct PORTCONTROL * PORT, unsigned char * axcall) SendReportMsg((char *)&AXMSG.DEST, Len + 16) ; - TimeLastNRRouteSent = Now; + TimeLastNRRouteSent = NOW; NRRouteMessage[0] = 0; } @@ -3632,6 +3829,7 @@ int __sync_lock_test_and_set(int * ptr, int val) #define GetSemaphore(Semaphore,ID) _GetSemaphore(Semaphore, ID, __FILE__, __LINE__) +BOOL Closing; void _GetSemaphore(struct SEM * Semaphore, int ID, char * File, int Line) { @@ -3646,7 +3844,7 @@ void _GetSemaphore(struct SEM * Semaphore, int ID, char * File, int Line) loop1: - while (Semaphore->Flag != 0) + while (Semaphore->Flag != 0 && Closing == 0) { Sleep(10); } @@ -3707,41 +3905,54 @@ USHORT WINAPI RtlCaptureStackBackTrace( */ #endif -void printStack(void) +void printStack() { -#ifdef WIN32 -#ifdef _DEBUG // So we can use on 98/2K +#ifdef BPQ32 + unsigned int i, n; + void * stack[ 100 ]; + unsigned short frames; + + DWORD dwDisplacement; + IMAGEHLP_LINE64 line; + char * fptr; + HANDLE process; - unsigned int i; - void * stack[ 100 ]; - unsigned short frames; - SYMBOL_INFO * symbol; - HANDLE process; - Debugprintf("Stack Backtrace"); + char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; + PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer; + + symbol->SizeOfStruct = sizeof(SYMBOL_INFO); + symbol->MaxNameLen = MAX_SYM_NAME; + + Debugprintf("Stack Backtrace\r\n"); process = GetCurrentProcess(); + SymSetOptions(SYMOPT_LOAD_LINES); SymInitialize( process, NULL, TRUE ); - frames = RtlCaptureStackBackTrace( 0, 60, stack, NULL ); - symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); - symbol->MaxNameLen = 255; - symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); + frames = RtlCaptureStackBackTrace(0, 60, stack, NULL ); for( i = 0; i < frames; i++ ) { - SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); + n = SymGetLineFromAddr64(process, (DWORD64)stack[i], &dwDisplacement, &line); + n = SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); - Debugprintf( "%i: %s - %p", frames - i - 1, symbol->Name, symbol->Address ); - } + if (line.FileName) + { + fptr = line.FileName + (int)strlen(line.FileName); // remove path + while (*fptr != '\\' && *fptr != '/') + fptr--; - free(symbol); + fptr++; -#endif + Debugprintf("%i: %s - %s Line %d Addr %p", frames - i - 1, symbol->Name, fptr, line.LineNumber, symbol->Address ); + } + } #endif } + pthread_t ResolveUpdateThreadId = 0; char NodeMapServer[80] = "update.g8bpq.net"; @@ -3801,7 +4012,7 @@ VOID ResolveUpdateThread(void * Unused) { hookNodeStarted(); nodeStartedSent = 1; - LastNodeStatus = time(NULL); + LastNodeStatus = NOW; } } @@ -3880,17 +4091,16 @@ VOID WriteMiniDumpThread() BOOL ret; char FN[256]; struct tm * TM; - time_t Now = time(NULL); - if (lastMiniDump == Now) // Not more than one per second + if (lastMiniDump == NOW) // Not more than one per second { Debugprintf("minidump suppressed"); return; } - lastMiniDump = Now; + lastMiniDump = NOW; - TM = gmtime(&Now); + TM = gmtime(&NOW); sprintf(FN, "%s/Logs/MiniDump%d%02d%02d%02d%02d%02d.dmp", BPQDirectory, TM->tm_year + 1900, TM->tm_mon +1, TM->tm_mday, TM->tm_hour, TM->tm_min, TM->tm_sec); -- cgit v1.2.3