if (ntohs(1)==1) { ReverseLogHead(&m_stHead); } Crypt((char*)&m_stHead, sizeof(m_stHead), szFilePassword); //memset(szCryptPassword, 0, sizeof(szCryptPassword)); strcpy(szCryptPassword, CRYPTPASSWORD); Crypt(szFilePassword, sizeof(szFilePassword), szCryptPassword); memcpy(m_stHead.stInfo.szPassword, szFilePassword, sizeof(szFilePassword)); fseek(m_fp, 0, SEEK_SET); fwrite(&m_stHead, sizeof(m_stHead), 1, m_fp); fflush(m_fp);
bool CLogFile::open() { int shflag; int len; struct tm tmloc; char fname[1024]; close(); len = strlen(logpath); if (logpath[len-1]==PATHMARK) logpath[len-1]='\0'; time(&lastftime); memcpy(&tmloc,localtime(&lastftime),sizeof(tmloc)); logdate = ((tmloc.tm_year+1900)*100+tmloc.tm_mon+1)*100+tmloc.tm_mday; #ifdef SYSLOG sprintf(fname,"%d.log",logdate); openlog(fname,LOG_PID|LOG_PERROR,LOG_USER); return(true); #else if (access(logpath,0)!=0) { MAKEPATH(logpath); } /* ****** Updated by CHENYH at 2005-11-17 16:28:25 ****** */ if (mode) { #ifdef WIN32 sprintf(fname,"%s%c%d_%u.log",logpath,PATHMARK,logdate,GetCurrentProcessId()); #else sprintf(fname,"%s%c%d_%d.log",logpath,PATHMARK,logdate,getpid()); #endif } else { sprintf(fname,"%s%c%d.log",logpath,PATHMARK,logdate); } /**********************************************************/ shflag = SH_DENYNO; fp = sh_fopen(fname,"a+t",shflag); if (fp==NULL) { fp = sh_fopen(fname,"w+t",shflag); } return(fp!=NULL); #endif }
USHORT SQUISH::GetHWM (ULONG &ulMsg) { CHAR File[128]; if (Locked == FALSE) { sprintf (File, "%s.sqd", SqBase.Base); if ((fpDat = sh_fopen (File, "r+b", SH_DENYNO)) != NULL) { fread (&SqBase, sizeof (SQBASE), 1, fpDat); fclose (fpDat); fpDat = NULL; } } ulMsg = SqBase.HighWater; return (TRUE); }
{ unsigned int dwTmp; char chTmp; dwTmp = GetTickCount(); chTmp = (char)((dwTmp%90) + 32); m_stHead.stInfo.szPassword[i] = chTmp; mysleep(chTmp%10); } m_stHead.stInfo.szPassword[i] = 0; ST_LOGFILEAPP *pApp = m_stHead.stApp; for(i=0;i<LOG_APPMAXCOUNT;i++) { pApp->nReserve = LOG_APPWRITE; //memcpy(&(m_stHead.stApp[i].nReserve),<ype,sizeof(short)); } // 设置文件头中固定的信息 m_stHead.stInfo.dwHeadLen = (unsigned int)(sizeof(m_stHead)); m_stHead.stInfo.dwValidLen = m_stHead.stInfo.dwHeadLen; // 系统日志 AddAppName(LOG_APPSYSID, LOG_APPSYSNAME); AddAppName(LOG_APPPACKID, LOG_APPPACKNAME); AddAppName(LOG_APPDATAID, LOG_APPDATANAME); } bool CKSLog::AddAppName(short nAppID, const char *pszAppName) { if(nAppID < 0 ) { ASSERT(false);
USHORT SQUISH::Delete (ULONG ulMsg) { int i; USHORT RetVal = TRUE; CHAR File[128]; ULONG Position; SQHDR SqHdr, SqHdrPrev, SqHdrNext; if (Locked == FALSE || fpDat == NULL) { sprintf (File, "%s.sqd", SqBase.Base); fpDat = sh_fopen (File, "r+b", SH_DENYNO); if (Locked == FALSE && fpDat != NULL) fread (&SqBase, sizeof (SQBASE), 1, fpDat); } if (Locked == FALSE) { if (pSqIdx != NULL) { free (pSqIdx); pSqIdx = NULL; } sprintf (File, "%s.sqi", SqBase.Base); if ((fpIdx = sh_fopen (File, "r+b", SH_DENYNO)) != NULL) { if ((pSqIdx = (SQIDX *)malloc (sizeof (SQIDX) * 4500)) != NULL) { if (SqBase.NumMsg > 0L) fread (pSqIdx, (int)filelength (fileno (fpIdx)), 1, fpIdx); } fclose (fpIdx); fpIdx = NULL; } } if (pSqIdx != NULL) { // Cerca il messaggio da cancellare all'interno dell'indice for (i = 0; i < SqBase.NumMsg; i++) { if (pSqIdx[i].MsgId == ulMsg) { Position = pSqIdx[i].Ofs; // Se il messaggio non e' l'ultimo dell'indice, elimina il record // spostando l'indice in memoria. if ((i + 1) < SqBase.NumMsg) memmove (&pSqIdx[i], &pSqIdx[i + 1], (int)((SqBase.NumMsg - i - 1) * sizeof (SQIDX))); RetVal = TRUE; break; } } } if (RetVal == TRUE && fpDat != NULL) { fseek (fpDat, Position, SEEK_SET); fread (&SqHdr, sizeof (SqHdr), 1, fpDat); SqHdr.FrameType = FRAME_FREE; if (SqHdr.PrevFrame != 0L) { fseek (fpDat, SqHdr.PrevFrame, SEEK_SET); fread (&SqHdrPrev, sizeof (SqHdr), 1, fpDat); SqHdrPrev.NextFrame = SqHdr.NextFrame; fseek (fpDat, SqHdr.PrevFrame, SEEK_SET); fwrite (&SqHdrPrev, sizeof (SqHdr), 1, fpDat); } if (SqHdr.NextFrame != 0L) { fseek (fpDat, SqHdr.NextFrame, SEEK_SET); fread (&SqHdrNext, sizeof (SqHdr), 1, fpDat); SqHdrNext.PrevFrame = SqHdr.PrevFrame; fseek (fpDat, SqHdr.NextFrame, SEEK_SET); fwrite (&SqHdrNext, sizeof (SqHdr), 1, fpDat); } SqHdr.NextFrame = 0L; fseek (fpDat, Position, SEEK_SET); fwrite (&SqHdr, sizeof (SqHdr), 1, fpDat); // fseek (fpDat, 0L, SEEK_SET); SqBase.NumMsg--; SqBase.HighMsg--; if (SqBase.FreeFrame == 0L) SqBase.FreeFrame = Position; if (SqBase.LastFreeFrame == 0L) { SqBase.LastFreeFrame = Position; SqHdr.PrevFrame = 0L; } else { SqHdr.PrevFrame = SqBase.LastFreeFrame; fseek (fpDat, SqBase.LastFreeFrame, SEEK_SET); fread (&SqHdrNext, sizeof (SqHdr), 1, fpDat); SqHdrNext.NextFrame = Position; fseek (fpDat, SqBase.LastFreeFrame, SEEK_SET); fwrite (&SqHdrNext, sizeof (SqHdr), 1, fpDat); SqBase.LastFreeFrame = Position; } fseek (fpDat, Position, SEEK_SET); fwrite (&SqHdr, sizeof (SqHdr), 1, fpDat); fseek (fpDat, 0L, SEEK_SET); fwrite (&SqBase, sizeof (SQBASE), 1, fpDat); } if (Locked == FALSE) { sprintf (File, "%s.sqi", SqBase.Base); if ((fpIdx = sh_fopen (File, "w+b", SH_DENYNO)) != NULL) { if (SqBase.NumMsg > 0L) fwrite (pSqIdx, (int)(SqBase.NumMsg * sizeof (SQIDX)), 1, fpIdx); free (pSqIdx); pSqIdx = NULL; if (SqBase.NumMsg != 0L) { fseek (fpIdx, 0L, SEEK_SET); if ((pSqIdx = (SQIDX *)malloc ((int)(sizeof (SQIDX) * SqBase.NumMsg))) != NULL) fread (pSqIdx, sizeof (SQIDX), (size_t)SqBase.NumMsg, fpIdx); } fclose (fpIdx); fpIdx = NULL; } if (fpDat != NULL) fclose (fpDat); fpDat = fpIdx = NULL; } return (RetVal); }
USHORT SQUISH::Add (class TCollection &MsgText) { CHAR File[128], NoMore; PSZ Text, pszAddress, p; ULONG EndFrame; SQHDR SqHdr; SQIDX SqIdx; XMSG XMsg; if (Locked == FALSE || fpDat == NULL) { sprintf (File, "%s.sqd", SqBase.Base); fpDat = sh_fopen (File, "r+b", SH_DENYNO); if (Locked == FALSE && fpDat != NULL) fread (&SqBase, sizeof (SQBASE), 1, fpDat); } if (Locked == FALSE || fpIdx == NULL) { sprintf (File, "%s.sqi", SqBase.Base); fpIdx = sh_fopen (File, "ab", SH_DENYNO); } if (fpDat != NULL) { // Allocate a frame at the end of the file, using the 'end_frame' value. memset (&SqHdr, 0, sizeof (SQHDR)); SqHdr.Id = SQHDRID; SqHdr.FrameType = FRAME_NORMAL; SqHdr.PrevFrame = SqBase.LastFrame; SqHdr.NextFrame = 0L; NoMore = FALSE; SqHdr.CLen = 1; if ((Text = (PSZ)MsgText.First ()) != NULL) do { if (Text[0] == 0x01 && NoMore == FALSE) SqHdr.CLen += strlen (Text); else { SqHdr.MsgLength += strlen (Text) + 1; NoMore = TRUE; } } while ((Text = (PSZ)MsgText.Next ()) != NULL); if (SqHdr.CLen == 1) SqHdr.CLen++; SqHdr.FrameLength = SqHdr.CLen + SqHdr.MsgLength + sizeof (XMSG); SqHdr.MsgLength = SqHdr.FrameLength; fseek (fpDat, SqBase.EndFrame, SEEK_SET); fwrite (&SqHdr, sizeof (SQHDR), 1, fpDat); // Write the XMSG header. memset (&XMsg, 0, sizeof (XMSG)); strcpy (XMsg.From, From); strcpy (XMsg.To, To); strcpy (XMsg.Subject, Subject); XMsg.MsgId = SqBase.Uid; pszAddress = FromAddress; if (strchr (pszAddress, ':') != NULL) { XMsg.Orig.Zone = (USHORT)atoi (pszAddress); pszAddress = strchr (pszAddress, ':') + 1; } if (strchr (pszAddress, '/') != NULL) { XMsg.Orig.Net = (USHORT)atoi (pszAddress); pszAddress = strchr (pszAddress, '/') + 1; } XMsg.Orig.Node = (USHORT)atoi (pszAddress); if ((p = strchr (pszAddress, '@')) != NULL) *p++ = '\0'; if (strchr (pszAddress, '.') != NULL) { pszAddress = strchr (pszAddress, '.') + 1; XMsg.Orig.Point = (USHORT)atoi (pszAddress); } pszAddress = ToAddress; if (strchr (pszAddress, ':') != NULL) { XMsg.Dest.Zone = (USHORT)atoi (pszAddress); pszAddress = strchr (pszAddress, ':') + 1; } if (strchr (pszAddress, '/') != NULL) { XMsg.Dest.Net = (USHORT)atoi (pszAddress); pszAddress = strchr (pszAddress, '/') + 1; } XMsg.Dest.Node = (USHORT)atoi (pszAddress); if ((p = strchr (pszAddress, '@')) != NULL) *p++ = '\0'; if (strchr (pszAddress, '.') != NULL) { pszAddress = strchr (pszAddress, '.') + 1; XMsg.Dest.Point = (USHORT)atoi (pszAddress); } XMsg.DateWritten = Written.Day & 0x1F; XMsg.DateWritten |= Written.Month << 5; XMsg.DateWritten |= (Written.Year - 1980) << 9; XMsg.DateWritten |= (Written.Second / 2) << 16; XMsg.DateWritten |= Written.Minute << 21; XMsg.DateWritten |= Written.Hour << 27; XMsg.DateArrived = Arrived.Day & 0x1F; XMsg.DateArrived |= Arrived.Month << 5; XMsg.DateArrived |= (Arrived.Year - 1980) << 9; XMsg.DateArrived |= (Arrived.Second / 2) << 16; XMsg.DateArrived |= Arrived.Minute << 21; XMsg.DateArrived |= Arrived.Hour << 27; XMsg.Attr = MSGUID; XMsg.Attr |= (Crash == TRUE) ? MSGCRASH : 0; XMsg.Attr |= (FileAttach == TRUE) ? MSGFILE : 0; XMsg.Attr |= (FileRequest == TRUE) ? MSGFRQ : 0; XMsg.Attr |= (Hold == TRUE) ? MSGHOLD : 0; XMsg.Attr |= (KillSent == TRUE) ? MSGKILL : 0; XMsg.Attr |= (Local == TRUE) ? MSGLOCAL : 0; XMsg.Attr |= (Private == TRUE) ? MSGPRIVATE : 0; XMsg.Attr |= (ReceiptRequest == TRUE) ? MSGRRQ : 0; XMsg.Attr |= (Received == TRUE) ? MSGREAD : 0; XMsg.Attr |= (Sent == TRUE) ? MSGSENT : 0; XMsg.ReplyTo = Original; XMsg.Replies[0] = Reply; fwrite (&XMsg, sizeof (XMsg), 1, fpDat); // Write the message's control information and body. if (SqHdr.CLen > 2) { if ((Text = (PSZ)MsgText.First ()) != NULL) do { if (Text[0] == 0x01) fwrite (Text, strlen (Text), 1, fpDat); else break; } while ((Text = (PSZ)MsgText.Next ()) != NULL); } else if (SqHdr.CLen == 2) fwrite ("\001", 1, 1, fpDat); fwrite ("", 1, 1, fpDat); NoMore = FALSE; if ((Text = (PSZ)MsgText.First ()) != NULL) do { if (Text[0] != 0x01 || NoMore == TRUE) { fwrite (Text, strlen (Text), 1, fpDat); fwrite ("\r", 1, 1, fpDat); NoMore = TRUE; } } while ((Text = (PSZ)MsgText.Next ()) != NULL); fflush (fpDat); EndFrame = ftell (fpDat); // Link the new SQHDR frame into the end of the message chain. // setvbuf (fpDat, NULL, _IONBF, 0L); if (SqBase.LastFrame != 0L) { fseek (fpDat, SqBase.LastFrame, SEEK_SET); fread (&SqHdr, sizeof (SQHDR), 1, fpDat); SqHdr.NextFrame = SqBase.EndFrame; fseek (fpDat, SqBase.LastFrame, SEEK_SET); fwrite (&SqHdr, sizeof (SQHDR), 1, fpDat); } SqBase.LastFrame = SqBase.EndFrame; SqBase.EndFrame = EndFrame; if (SqBase.BeginFrame == 0L) SqBase.BeginFrame = SqBase.LastFrame; SqBase.Uid++; SqBase.NumMsg++; SqBase.HighMsg++; if (Locked == FALSE) { fseek (fpDat, 0L, SEEK_SET); fwrite (&SqBase, sizeof (SQBASE), 1, fpDat); } // setvbuf (fpDat, NULL, _IOFBF, 4096L); } if (fpIdx != NULL) { // Write a SQIDX header for the new message. if (Locked == FALSE) { SqIdx.Ofs = SqBase.LastFrame; SqIdx.MsgId = SqBase.Uid - 1L; SqIdx.Hash = Hash (To); fwrite (&SqIdx, sizeof (SQIDX), 1, fpIdx); } else { pSqIdx[(int)(SqBase.NumMsg - 1L)].Ofs = SqBase.LastFrame; pSqIdx[(int)(SqBase.NumMsg - 1L)].MsgId = SqBase.Uid - 1L; pSqIdx[(int)(SqBase.NumMsg - 1L)].Hash = Hash (To); } } if (Locked == FALSE) { if (fpDat != NULL) fclose (fpDat); if (fpIdx != NULL) fclose (fpIdx); fpDat = fpIdx = NULL; if (pSqIdx != NULL) { free (pSqIdx); pSqIdx = NULL; } sprintf (File, "%s.sqd", SqBase.Base); if ((fpDat = sh_fopen (File, "r+b", SH_DENYNO)) != NULL) { fread (&SqBase, sizeof (SQBASE), 1, fpDat); fclose (fpDat); fpDat = NULL; } if (SqBase.NumMsg != 0L) { sprintf (File, "%s.sqi", SqBase.Base); if ((fpIdx = sh_fopen (File, "r+b", SH_DENYNO)) != NULL) { if ((pSqIdx = (SQIDX *)malloc ((int)(sizeof (SQIDX) * SqBase.NumMsg))) != NULL) fread (pSqIdx, sizeof (SQIDX), (size_t)SqBase.NumMsg, fpIdx); fclose (fpIdx); fpIdx = NULL; } } } return (TRUE); }