ULONG TFileBase::ChangeLibrary (PSZ pszFrom, PSZ pszTo) { ULONG CrcFrom, Number; FILEDATA fileData; FILEINDEX fileIndex; CrcFrom = StringCrc32 (pszFrom, 0xFFFFFFFFL); Number = 0L; lseek (fdIdx, 0L, SEEK_SET); while (read (fdIdx, &fileIndex, sizeof (fileIndex)) == sizeof (fileIndex)) { if (fileIndex.Flags & FILE_DELETED) continue; if (fileIndex.Area == CrcFrom) { lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); strcpy (fileData.Area, pszTo); lseek (fdDat, fileIndex.Offset, SEEK_SET); write (fdDat, &fileData, sizeof (fileData)); fileIndex.Area = StringCrc32 (pszTo, 0xFFFFFFFFL); lseek (fdIdx, tell (fdIdx) - sizeof (fileIndex), SEEK_SET); write (fdIdx, &fileIndex, sizeof (fileIndex)); Number++; } } return (Number); }
USHORT TUser::Add () { USHORT RetVal = FALSE; if (fdDat == -1) fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); if (fdIdx == -1) fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); if (fdDat != -1 && fdIdx != -1) { lseek (fdDat, 0L, SEEK_END); lseek (fdIdx, 0L, SEEK_END); memset (&Idx, 0, sizeof (Idx)); Idx.Deleted = FALSE; Idx.NameCrc = StringCrc32 (Name, 0xFFFFFFFFL); Idx.RealNameCrc = StringCrc32 (RealName, 0xFFFFFFFFL); Idx.Position = tell (fdDat); CurrentCRC = Idx.NameCrc; Class2Struct (); write (fdDat, &Usr, sizeof (Usr)); write (fdIdx, &Idx, sizeof (Idx)); MsgTag->UserId = Idx.NameCrc; MsgTag->Load (); FileTag->UserId = Idx.NameCrc; FileTag->Load (); RetVal = TRUE; } return (RetVal); }
VOID TUser::Pack () { int fdNew; if (fdDat == -1) fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); if (fdIdx == -1) fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); fdNew = sopen ("users.new", O_RDWR|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE); if (fdNew != -1 && fdDat != -1 && fdIdx != -1) { lseek (fdIdx, 0L, SEEK_SET); lseek (fdDat, 0L, SEEK_SET); while (read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) { if (Idx.Deleted == FALSE) { lseek (fdDat, Idx.Position, SEEK_SET); read (fdDat, &Usr, sizeof (Usr)); write (fdNew, &Usr, sizeof (Usr)); } } lseek (fdIdx, 0L, SEEK_SET); lseek (fdDat, 0L, SEEK_SET); lseek (fdNew, 0L, SEEK_SET); while (read (fdNew, &Usr, sizeof (Usr)) == sizeof (Usr)) { memset (&Idx, 0, sizeof (Idx)); Idx.Deleted = FALSE; Idx.NameCrc = StringCrc32 (Usr.Name, 0xFFFFFFFFL); Idx.RealNameCrc = StringCrc32 (Usr.RealName, 0xFFFFFFFFL); Idx.Position = tell (fdDat); write (fdDat, &Usr, sizeof (Usr)); write (fdIdx, &Idx, sizeof (Idx)); } chsize (fdDat, tell (fdDat)); chsize (fdIdx, tell (fdIdx)); } if (fdNew != -1) { close (fdNew); unlink ("users.new"); } if (fdIdx != -1) { close (fdIdx); fdIdx = -1; } if (fdDat != -1) { close (fdDat); fdDat = -1; } }
USHORT TUser::CheckPassword (PSZ pszPassword) { USHORT RetVal = FALSE; if (Password == StringCrc32 (strupr (pszPassword), 0xFFFFFFFFL)) RetVal = TRUE; return (RetVal); }
USHORT TUser::GetData (PSZ pszName, USHORT fCheckRealName) { USHORT RetVal = FALSE, DoClose = FALSE; ULONG TestCrc; if (fdDat == -1) { fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdIdx == -1) { fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdDat != -1 && fdIdx != -1) { Clear (); TestCrc = StringCrc32 (pszName, 0xFFFFFFFFL); lseek (fdIdx, 0L, SEEK_SET); while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) { if (Idx.Deleted == FALSE && Idx.NameCrc == TestCrc) RetVal = TRUE; } if (RetVal == FALSE && fCheckRealName == TRUE) { lseek (fdIdx, 0L, SEEK_SET); while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) { if (Idx.Deleted == FALSE && Idx.RealNameCrc == TestCrc) RetVal = TRUE; } } if (RetVal == TRUE) { lseek (fdDat, Idx.Position, SEEK_SET); read (fdDat, &Usr, sizeof (Usr)); Struct2Class (); MsgTag->UserId = Idx.NameCrc; MsgTag->Load (); FileTag->UserId = Idx.NameCrc; FileTag->Load (); } } if (DoClose == TRUE) { if (fdDat != -1) { close (fdDat); fdDat = -1; } if (fdIdx != -1) { close (fdIdx); fdIdx = -1; } } return (RetVal); }
VOID TUser::Reindex () { ULONG Position; if (fdDat != -1) close (fdDat); if (fdIdx != -1) close (fdIdx); fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE); if (fdDat != -1 && fdIdx != -1) { lseek (fdDat, 0L, SEEK_SET); Position = tell (fdDat); while (read (fdDat, &Usr, sizeof (Usr)) == sizeof (Usr)) { if (Usr.Size == sizeof (Usr)) { memset (&Idx, 0, sizeof (Idx)); Idx.Deleted = FALSE; Idx.NameCrc = StringCrc32 (Usr.Name, 0xFFFFFFFFL); Idx.RealNameCrc = StringCrc32 (Usr.RealName, 0xFFFFFFFFL); Idx.Position = Position; write (fdIdx, &Idx, sizeof (Idx)); } Position = tell (fdDat); } } if (fdDat != -1) { close (fdDat); fdDat = -1; } if (fdIdx != -1) { close (fdIdx); fdIdx = -1; } }
USHORT TUser::Delete () { USHORT RetVal = FALSE, DoClose = FALSE; ULONG NameCrc; if (fdDat == -1) { fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdIdx == -1) { fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdDat != -1 && fdIdx != -1) { NameCrc = StringCrc32 (Name, 0xFFFFFFFFL); lseek (fdIdx, 0L, SEEK_SET); while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) { if (Idx.Deleted == FALSE && Idx.NameCrc == NameCrc) RetVal = TRUE; } if (RetVal == TRUE) { Idx.Deleted = TRUE; lseek (fdIdx, tell (fdIdx) - sizeof (Idx), SEEK_SET); write (fdIdx, &Idx, sizeof (Idx)); } } if (DoClose == TRUE) { if (fdDat != -1) { close (fdDat); fdDat = -1; } if (fdIdx != -1) { close (fdIdx); fdIdx = -1; } } return (RetVal); }
USHORT TFileBase::Add (VOID) { PSZ pszTemp; FILEDATA fileData; FILEINDEX fileIndex; struct tm ftm; fUploader = FALSE; memset (&fileIndex, 0, sizeof (fileIndex)); fileIndex.Area = StringCrc32 (Area, 0xFFFFFFFFL); strcpy (fileIndex.Name, Name); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; fileIndex.UploadDate = mktime (&ftm); lseek (fdDat, 0L, SEEK_END); fileIndex.Offset = tell (fdDat); if (Unapproved == TRUE) fileIndex.Flags |= FILE_UNAPPROVED; lseek (fdIdx, 0L, SEEK_END); write (fdIdx, &fileIndex, sizeof (fileIndex)); memset (&fileData, 0, sizeof (fileData)); fileData.Id = FILEBASE_ID; strcpy (fileData.Area, Area); strcpy (fileData.Name, Name); strcpy (fileData.Complete, Complete); strcpy (fileData.Keyword, Keyword); fileData.Size = Size; fileData.DlTimes = DlTimes; memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = Date.Minute; ftm.tm_hour = Date.Hour; ftm.tm_mday = Date.Day; ftm.tm_mon = Date.Month - 1; ftm.tm_year = Date.Year - 1900; FileDate = fileData.FileDate = mktime (&ftm); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; UploadDate = fileData.UploadDate = mktime (&ftm); fileData.Cost = Cost; fileData.Password = Password; fileData.Level = Level; fileData.AccessFlags = AccessFlags; fileData.DenyFlags = DenyFlags; if (Unapproved == TRUE) fileData.Flags |= FILE_UNAPPROVED; if (CdRom == TRUE) fileData.Flags |= FILE_CDROM; if ((pszTemp = (PSZ)Description->First ()) != NULL) { do { fileData.Description += strlen (pszTemp) + 2; } while ((pszTemp = (PSZ)Description->Next ()) != NULL); } if (Uploader != NULL) fileData.Uploader = (USHORT)(strlen (Uploader) + 1); lseek (fdDat, 0L, SEEK_END); write (fdDat, &fileData, sizeof (fileData)); if ((pszTemp = (PSZ)Description->First ()) != NULL) { do { write (fdDat, pszTemp, strlen (pszTemp)); write (fdDat, "\r\n", 2); } while ((pszTemp = (PSZ)Description->Next ()) != NULL); } if (Uploader != NULL) write (fdDat, Uploader, fileData.Uploader); return (TRUE); }
VOID TFileBase::SearchText (PSZ pszText) { USHORT x, i, r, w, Readed, RetVal = FALSE, AddThis; CHAR szTemp[80], szLine[80]; ULONG Crc; NAMESORT ns, *pns; FILEDATA fileData; FILEINDEX *fileIndex; if (List == NULL) List = new TCollection; fileIndex = (FILEINDEX *)malloc (sizeof (FILEINDEX) * MAX_INDEX); strlwr (pszText); if (List != NULL && fileIndex != NULL) { List->Clear (); Crc = StringCrc32 (szArea, 0xFFFFFFFFL); if (fdDat != -1 && fdIdx != -1) { lseek (fdIdx, 0L, SEEK_SET); while ((Readed = (USHORT)read (fdIdx, fileIndex, sizeof (FILEINDEX) * MAX_INDEX)) > 0) { Readed /= sizeof (FILEINDEX); for (x = 0; x < Readed; x++) { if (!(fileIndex[x].Flags & (FILE_DELETED|FILE_UNAPPROVED)) && (szArea[0] == '\0' || fileIndex[x].Area == Crc)) { lseek (fdDat, fileIndex[x].Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); if (fileData.Id == FILEBASE_ID) { AddThis = FALSE; fileData.Name[sizeof (fileData.Name) - 1] = '\0'; fileData.Keyword[sizeof (fileData.Keyword) - 1] = '\0'; if (strstr (strlwr (fileData.Name), pszText) != NULL) AddThis = TRUE; if (strstr (strlwr (fileData.Keyword), pszText) != NULL) AddThis = TRUE; if (fileData.Description != 0 && AddThis == FALSE) { w = 0; do { if ((r = (USHORT)sizeof (szTemp)) > fileData.Description) r = fileData.Description; r = (USHORT)read (fdDat, szTemp, r); for (i = 0; i < r && AddThis == FALSE; i++) { if (szTemp[i] == '\r') { szLine[w++] = '\0'; if (strstr (strlwr (szLine), pszText) != NULL) AddThis = TRUE; w = 0; } else if (szTemp[i] != '\n') szLine[w++] = szTemp[i]; } fileData.Description -= r; } while (AddThis == FALSE && fileData.Description > 0); if (w > 0) { szLine[w++] = '\0'; if (strstr (strlwr (szLine), pszText) != NULL) AddThis = TRUE; } } if (fileData.Uploader != 0 && AddThis == FALSE) { fUploader = TRUE; pszMemUploader = Uploader = (PSZ)malloc (fileData.Uploader); read (fdDat, Uploader, fileData.Uploader); } if (AddThis == TRUE) { fileIndex[x].Name[sizeof (fileIndex[x].Name) - 1] = '\0'; strcpy (ns.Name, fileIndex[x].Name); ns.Position = fileIndex[x].Offset; RetVal = FALSE; if ((pns = (NAMESORT *)List->First ()) != NULL) { if (strcmp (pns->Name, ns.Name) > 0) { List->Insert (&ns, sizeof (ns)); List->Insert (pns, sizeof (ns)); List->First (); List->Remove (); RetVal = TRUE; } if (RetVal == FALSE) do { if (strcmp (pns->Name, ns.Name) > 0) { List->Previous (); List->Insert (&ns, sizeof (ns)); RetVal = TRUE; } } while (RetVal == FALSE && (pns = (NAMESORT *)List->Next ()) != NULL); } if (RetVal == FALSE) List->Add (&ns, sizeof (ns)); } } } } } } } if (fileIndex != NULL) free (fileIndex); }
Aggregate* Definition::FindAggregate ( const char* name ) { return FindAggregate ( StringCrc32 ( name ) ); }
SelectItem* Select::FindItem ( const char* name ) { return FindItem ( StringCrc32 ( name ) ); }
// Aggiorna i dati relativi ad un nominativo. // ----------------------------------------------------------------------------- USHORT TUser::Update () { USHORT RetVal = FALSE, DoClose = FALSE; // Verifica se i file dati devono essere aperti, nel qual caso attiva il flag // DoClose per poi forzarne la chiusura al termine della funzione. if (fdDat == -1) { fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdIdx == -1) { fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); DoClose = TRUE; } if (fdDat != -1 && fdIdx != -1) { // Cerca tramite l'indice il record corrispondente all'ultimo nominativo // selezionato. Non si puo' utilizzare il nome nella classe perche' potrebbe // non essere piu' quello letto originariamente. lseek (fdIdx, 0L, SEEK_SET); while (read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) { if (Idx.Deleted == FALSE && Idx.NameCrc == CurrentCRC) { RetVal = TRUE; break; } } if (RetVal == TRUE) { // Copia tutti i dati della classe nella struttura dati da scrivere // nel record. Class2Struct (); // Aggiorna il CRC di nome e alias nell'indice, nel caso in cui questi // dati fossero stati cambiati. Idx.NameCrc = StringCrc32 (Name, 0xFFFFFFFFL); Idx.RealNameCrc = StringCrc32 (RealName, 0xFFFFFFFFL); lseek (fdIdx, tell (fdIdx) - sizeof (Idx), SEEK_SET); write (fdIdx, &Idx, sizeof (Idx)); // Aggiorna il record dati vero e proprio. lseek (fdDat, Idx.Position, SEEK_SET); write (fdDat, &Usr, sizeof (Usr)); // Se e' stato cambiato il nome dell'utente, cambia anche le associazioni // con i file contenenti i puntatori agli ultimi messaggi letti e i files // marcati per il download. if (CurrentCRC != Idx.NameCrc) { MsgTag->Change (CurrentCRC, Idx.NameCrc); FileTag->Change (CurrentCRC, Idx.NameCrc); CurrentCRC = Idx.NameCrc; } // Aggiorna il file contenenti i puntatori agli ultimi messaggi letti. MsgTag->UserId = Idx.NameCrc; MsgTag->Save (); // Aggiorna il file contenente i nome dei file marcati per il download. FileTag->UserId = Idx.NameCrc; FileTag->Save (); } } // Se i file non erano gia' aperti prima di invocare questa funzione, vengono // chiusi automaticamente per non lasciare handle aperti inutilmente. if (DoClose == TRUE) { if (fdDat != -1) { close (fdDat); fdDat = -1; } if (fdIdx != -1) { close (fdIdx); fdIdx = -1; } } return (RetVal); }
BitfieldFlag* Bitfield::FindFlag ( const char* name ) { return FindFlag ( StringCrc32 ( name ) ); }
StructField* Struct::FindField ( const char* name ) { return FindField ( StringCrc32 ( name ) ); }
USHORT TFileBase::ReplaceHeader (VOID) { USHORT RetVal = FALSE; ULONG ulCrc; FILEDATA fileData; FILEINDEX fileIndex; NAMESORT *ns; struct tm ftm; if (List == NULL) { ulCrc = StringCrc32 (szArea, 0xFFFFFFFFL); if (fdDat != -1 && fdIdx != -1) { lseek (fdIdx, 0L, SEEK_SET); while (read (fdIdx, &fileIndex, sizeof (fileIndex)) == sizeof (fileIndex)) { if (!(fileIndex.Flags & FILE_DELETED)) { if (szArea[0] == '\0' || fileIndex.Area == ulCrc) { if (!stricmp (fileIndex.Name, Name)) { lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); if (fileData.Id == FILEBASE_ID) { RetVal = TRUE; break; } } } } } } } else { if ((ns = (NAMESORT *)List->Value ()) != NULL) { lseek (fdIdx, ns->IdxPosition, SEEK_SET); read (fdIdx, &fileIndex, sizeof (fileIndex)); lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); if (fileData.Id == FILEBASE_ID && !strcmp (fileData.Name, Name)) RetVal = TRUE; } if (RetVal == FALSE) { if ((ns = (NAMESORT *)List->First ()) != NULL) do { if (!stricmp (ns->Name, Name)) { lseek (fdIdx, ns->IdxPosition, SEEK_SET); read (fdIdx, &fileIndex, sizeof (fileIndex)); lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); if (fileData.Id == FILEBASE_ID) { RetVal = TRUE; break; } } } while ((ns = (NAMESORT *)List->Next ()) != NULL); } } if (RetVal == TRUE) { // Aggiornamento dell'indice fileIndex.Area = StringCrc32 (Area, 0xFFFFFFFFL); strcpy (fileIndex.Name, Name); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; fileIndex.UploadDate = mktime (&ftm); if (Unapproved == TRUE) fileIndex.Flags |= FILE_UNAPPROVED; else fileIndex.Flags &= ~FILE_UNAPPROVED; lseek (fdIdx, tell (fdIdx) - sizeof (fileIndex), SEEK_SET); write (fdIdx, &fileIndex, sizeof (fileIndex)); // Aggiornamento della struttura dati principale strcpy (fileData.Area, Area); strcpy (fileData.Name, Name); strcpy (fileData.Complete, Complete); strcpy (fileData.Keyword, Keyword); fileData.Size = Size; fileData.DlTimes = DlTimes; memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = Date.Minute; ftm.tm_hour = Date.Hour; ftm.tm_mday = Date.Day; ftm.tm_mon = Date.Month - 1; ftm.tm_year = Date.Year - 1900; FileDate = fileData.FileDate = mktime (&ftm); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; UploadDate = fileData.UploadDate = mktime (&ftm); fileData.Cost = Cost; fileData.Password = Password; fileData.Level = Level; fileData.AccessFlags = AccessFlags; fileData.DenyFlags = DenyFlags; if (Unapproved == TRUE) fileData.Flags |= FILE_UNAPPROVED; else fileData.Flags &= ~FILE_UNAPPROVED; if (CdRom == TRUE) fileData.Flags |= FILE_CDROM; else fileData.Flags &= ~FILE_CDROM; lseek (fdDat, fileIndex.Offset, SEEK_SET); write (fdDat, &fileData, sizeof (fileData)); } return (TRUE); }
USHORT TFileBase::Read (PSZ pszFile) { USHORT fRet = FALSE, i, r, w; CHAR szTemp[80], szLine[80]; ULONG ulCrc; FILEDATA fileData; FILEINDEX fileIndex; struct tm *ftm; ulCrc = StringCrc32 (szArea, 0xFFFFFFFFL); if (fdDat != -1 && fdIdx != -1) { lseek (fdIdx, 0L, SEEK_SET); while (read (fdIdx, &fileIndex, sizeof (fileIndex)) == sizeof (fileIndex)) { if (!(fileIndex.Flags & FILE_DELETED)) { if (szArea[0] == '\0' || fileIndex.Area == ulCrc) { if (!stricmp (fileIndex.Name, pszFile)) { fRet = TRUE; break; } } } } if (fRet == TRUE) { lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); fRet = FALSE; if (fileData.Id == FILEBASE_ID) { Clear (); fileData.Area[sizeof (fileData.Area) - 1] = '\0'; fileData.Name[sizeof (fileData.Name) - 1] = '\0'; fileData.Complete[sizeof (fileData.Complete) - 1] = '\0'; fileData.Keyword[sizeof (fileData.Keyword) - 1] = '\0'; strcpy (Area, fileData.Area); strcpy (Name, fileData.Name); strcpy (Complete, fileData.Complete); strcpy (Keyword, fileData.Keyword); if (fileData.Description != 0) { w = 0; do { if ((r = (USHORT)sizeof (szTemp)) > fileData.Description) r = fileData.Description; r = (USHORT)read (fdDat, szTemp, r); for (i = 0; i < r; i++) { if (szTemp[i] == '\r') { szLine[w++] = '\0'; Description->Add (szLine, w); w = 0; } else if (szTemp[i] != '\n') szLine[w++] = szTemp[i]; } fileData.Description -= r; } while (fileData.Description > 0); if (w > 0) { szLine[w++] = '\0'; Description->Add (szLine, w); } } if (fileData.Uploader != 0) { fUploader = TRUE; pszMemUploader = Uploader = (PSZ)malloc (fileData.Uploader); read (fdDat, Uploader, fileData.Uploader); } Size = fileData.Size; DlTimes = fileData.DlTimes; FileDate = fileData.FileDate; ftm = localtime ((time_t *)&fileData.FileDate); Date.Day = (UCHAR)ftm->tm_mday; Date.Month = (UCHAR)(ftm->tm_mon + 1); Date.Year = (USHORT)(ftm->tm_year + 1900); Date.Hour = (UCHAR)ftm->tm_hour; Date.Minute = (UCHAR)ftm->tm_min; UploadDate = fileData.UploadDate; ftm = localtime ((time_t *)&fileData.UploadDate); UplDate.Day = (UCHAR)ftm->tm_mday; UplDate.Month = (UCHAR)(ftm->tm_mon + 1); UplDate.Year = (USHORT)(ftm->tm_year + 1900); UplDate.Hour = (UCHAR)ftm->tm_hour; UplDate.Minute = (UCHAR)ftm->tm_min; Cost = fileData.Cost; Password = fileData.Password; Level = fileData.Level; AccessFlags = fileData.AccessFlags; DenyFlags = fileData.DenyFlags; Unapproved = (fileData.Flags & FILE_UNAPPROVED) ? TRUE : FALSE; CdRom = (fileData.Flags & FILE_CDROM) ? TRUE : FALSE; fRet = TRUE; } } } return (fRet); }
VOID TUser::Struct2Class () { strcpy (Name, Usr.Name); Password = Usr.Password; strcpy (RealName, Usr.RealName); strcpy (Company, Usr.Company); strcpy (Address, Usr.Address); strcpy (City, Usr.City); strcpy (DayPhone, Usr.DayPhone); Ansi = Usr.Ansi; Avatar = Usr.Avatar; Color = Usr.Color; HotKey = Usr.HotKey; Sex = Usr.Sex; FullEd = Usr.FullEd; FullReader = Usr.FullReader; NoDisturb = Usr.NoDisturb; AccessFailed = Usr.AccessFailed; ScreenHeight = Usr.ScreenHeight; ScreenWidth = Usr.ScreenWidth; Level = Usr.Level; AccessFlags = Usr.AccessFlags; DenyFlags = Usr.DenyFlags; CreationDate = Usr.CreationDate; LastCall = Usr.LastCall; TotalCalls = Usr.TotalCalls; TodayTime = Usr.TodayTime; WeekTime = Usr.WeekTime; MonthTime = Usr.MonthTime; YearTime = Usr.YearTime; strcpy (MailBox, Usr.MailBox); strcpy (LimitClass, Usr.LimitClass); strcpy (Language, Usr.Language); strcpy (FtpHost, Usr.FtpHost); strcpy (FtpName, Usr.FtpName); strcpy (FtpPwd, Usr.FtpPwd); strcpy (LastMsgArea, Usr.LastMsgArea); strcpy (LastFileArea, Usr.LastFileArea); UploadFiles = Usr.UploadFiles; UploadBytes = Usr.UploadBytes; DownloadFiles = Usr.DownloadFiles; DownloadBytes = Usr.DownloadBytes; FilesToday = Usr.FilesToday; BytesToday = Usr.BytesToday; ImportPOP3Mail = Usr.ImportPOP3Mail; UseInetAddress = Usr.UseInetAddress; strcpy (InetAddress, Usr.InetAddress); strcpy (Pop3Pwd, Usr.Pop3Pwd); strcpy (Archiver, Usr.Archiver); strcpy (Protocol, Usr.Protocol); strcpy (Signature, Usr.Signature); FullScreen = Usr.FullScreen; IBMChars = Usr.IBMChars; MorePrompt = Usr.MorePrompt; ScreenClear = Usr.ScreenClear; InUserList = Usr.InUserList; MailCheck = Usr.MailCheck; NewFileCheck = Usr.NewFileCheck; BirthDay = Usr.BirthDay; BirthMonth = Usr.BirthMonth; BirthYear = Usr.BirthYear; LastPwdChange = Usr.LastPwdChange; PwdLength = Usr.PwdLength; strcpy (PwdText, Usr.PwdText); CurrentCRC = StringCrc32 (Name, 0xFFFFFFFFL); }
USHORT TFileBase::Replace (VOID) { PSZ pszTemp; USHORT RetVal = FALSE; ULONG ulCrc; FILEDATA fileData; FILEINDEX fileIndex; struct tm ftm; fUploader = FALSE; ulCrc = StringCrc32 (szArea, 0xFFFFFFFFL); lseek (fdIdx, tell (fdIdx) - sizeof (fileIndex), SEEK_SET); read (fdIdx, &fileIndex, sizeof (fileIndex)); if ((szArea[0] != '\0' && fileIndex.Area != ulCrc) || stricmp (fileIndex.Name, Name)) { lseek (fdIdx, 0L, SEEK_SET); while (read (fdIdx, &fileIndex, sizeof (fileIndex)) == sizeof (fileIndex)) { if (!(fileIndex.Flags & FILE_DELETED)) { if (szArea[0] == '\0' || fileIndex.Area == ulCrc) { if (!stricmp (fileIndex.Name, Name)) { RetVal = TRUE; break; } } } } } else RetVal = TRUE; if (RetVal == TRUE) { lseek (fdDat, fileIndex.Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); RetVal = FALSE; if (fileData.Id == FILEBASE_ID) { fileData.Flags |= FILE_DELETED; lseek (fdDat, fileIndex.Offset, SEEK_SET); write (fdDat, &fileData, sizeof (fileData)); lseek (fdDat, 0L, SEEK_END); fileIndex.Offset = tell (fdDat); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; fileIndex.UploadDate = mktime (&ftm); if (Unapproved == TRUE) fileIndex.Flags |= FILE_UNAPPROVED; else fileIndex.Flags &= ~FILE_UNAPPROVED; lseek (fdIdx, tell (fdIdx) - sizeof (fileIndex), SEEK_SET); write (fdIdx, &fileIndex, sizeof (fileIndex)); memset (&fileData, 0, sizeof (fileData)); strcpy (fileData.Area, Area); strcpy (fileData.Name, Name); strcpy (fileData.Complete, Complete); strcpy (fileData.Keyword, Keyword); fileData.Size = Size; fileData.DlTimes = DlTimes; memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = Date.Minute; ftm.tm_hour = Date.Hour; ftm.tm_mday = Date.Day; ftm.tm_mon = Date.Month - 1; ftm.tm_year = Date.Year - 1900; FileDate = fileData.FileDate = mktime (&ftm); memset (&ftm, 0, sizeof (ftm)); ftm.tm_min = UplDate.Minute; ftm.tm_hour = UplDate.Hour; ftm.tm_mday = UplDate.Day; ftm.tm_mon = UplDate.Month - 1; ftm.tm_year = UplDate.Year - 1900; UploadDate = fileData.UploadDate = mktime (&ftm); fileData.Cost = Cost; fileData.Password = Password; fileData.Level = Level; fileData.AccessFlags = AccessFlags; fileData.DenyFlags = DenyFlags; if (Unapproved == TRUE) fileData.Flags |= FILE_UNAPPROVED; if (CdRom == TRUE) fileData.Flags |= FILE_CDROM; if ((pszTemp = (PSZ)Description->First ()) != NULL) { do { fileData.Description += strlen (pszTemp) + 2; } while ((pszTemp = (PSZ)Description->Next ()) != NULL); } if (Uploader != NULL) fileData.Uploader = (USHORT)(strlen (Uploader) + 1); lseek (fdDat, 0L, SEEK_END); write (fdDat, &fileData, sizeof (fileData)); if ((pszTemp = (PSZ)Description->First ()) != NULL) { do { write (fdDat, pszTemp, strlen (pszTemp)); write (fdDat, "\r\n", 2); } while ((pszTemp = (PSZ)Description->Next ()) != NULL); } if (Uploader != NULL) write (fdDat, Uploader, fileData.Uploader); RetVal = TRUE; } } return (RetVal); }
VOID TUser::SetPassword (PSZ pszPassword) { Password = StringCrc32 (strupr (pszPassword), 0xFFFFFFFFL); }
VOID TFileBase::SearchFile (PSZ pszFile) { USHORT i, Readed, RetVal = FALSE; ULONG Crc; NAMESORT ns, *pns; FILEDATA fileData; FILEINDEX *fileIndex; if (List == NULL) List = new TCollection; fileIndex = (FILEINDEX *)malloc (sizeof (FILEINDEX) * MAX_INDEX); strlwr (pszFile); if (List != NULL && fileIndex != NULL) { List->Clear (); Crc = StringCrc32 (szArea, 0xFFFFFFFFL); if (fdDat != -1 && fdIdx != -1) { lseek (fdIdx, 0L, SEEK_SET); while ((Readed = (USHORT)read (fdIdx, fileIndex, sizeof (FILEINDEX) * MAX_INDEX)) > 0) { Readed /= sizeof (FILEINDEX); for (i = 0; i < Readed; i++) { if (!(fileIndex[i].Flags & (FILE_DELETED|FILE_UNAPPROVED)) && (szArea[0] == '\0' || fileIndex[i].Area == Crc)) { lseek (fdDat, fileIndex[i].Offset, SEEK_SET); read (fdDat, &fileData, sizeof (fileData)); if (fileData.Id == FILEBASE_ID) { RetVal = FALSE; if (MatchName (fileIndex[i].Name, pszFile) == TRUE) { fileIndex[i].Name[sizeof (fileIndex[i].Name) - 1] = '\0'; strcpy (ns.Name, fileIndex[i].Name); ns.Position = fileIndex[i].Offset; if ((pns = (NAMESORT *)List->First ()) != NULL) { if (strcmp (pns->Name, ns.Name) > 0) { List->Insert (&ns, sizeof (ns)); List->Insert (pns, sizeof (ns)); List->First (); List->Remove (); RetVal = TRUE; } if (RetVal == FALSE) do { if (strcmp (pns->Name, ns.Name) > 0) { List->Previous (); List->Insert (&ns, sizeof (ns)); RetVal = TRUE; } } while (RetVal == FALSE && (pns = (NAMESORT *)List->Next ()) != NULL); } if (RetVal == FALSE) List->Add (&ns, sizeof (ns)); } } } } } } } if (fileIndex != NULL) free (fileIndex); }
VOID TRoute::MakeArcMailName (PSZ pszAddress, CHAR Flag) { USHORT i, Found; CHAR *p; class TAddress Addr; class TOutbound *Out; struct stat statbuf; struct dosdate_t d_date; _dos_getdate (&d_date); Addr.Parse (pszAddress); if (Addr.Zone == 0 || Cfg->MailAddress.Zone == Addr.Zone) { if (Addr.Point != 0) sprintf (ArcMailName, "%s\\%04x%04x.pnt\\%08lx.%s", Outbound, Addr.Net, Addr.Node, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]); else sprintf (ArcMailName, "%s\\%08lx.%s", Outbound, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]); } else { if (Addr.Point != 0) sprintf (ArcMailName, "%s.%03x\\%04x%04x.pnt\\%08lx.%s", Outbound, Addr.Zone, Addr.Net, Addr.Node, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]); else sprintf (ArcMailName, "%s.%03x\\%08lx.%s", Outbound, Addr.Zone, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]); } Found = FALSE; if ((p = strchr (ArcMailName, '\0')) != NULL) { p--; for (i = '0'; i <= '9' && Found == FALSE; i++) { *p = (CHAR)i; if (stat (ArcMailName, &statbuf) == 0) { Found = TRUE; if (statbuf.st_size == 0L) { unlink (ArcMailName); if (++i > '9') i = '0'; *p = (CHAR)i; } } } if (Found == FALSE) *p = '0'; } if ((Out = new TOutbound (Cfg->Outbound)) != NULL) { if (Cfg->MailAddress.First () == TRUE) Out->DefaultZone = Cfg->MailAddress.Zone; Found = FALSE; Out->Add (Addr.Zone, Addr.Net, Addr.Node, Addr.Point, Addr.Domain); if (Out->First () == TRUE) do { if (!stricmp (Out->Complete, ArcMailName)) { Found = TRUE; break; } } while (Out->Next () == TRUE); if (Found == FALSE) { Out->New (); Out->Zone = Addr.Zone; Out->Net = Addr.Net; Out->Node = Addr.Node; Out->Point = Addr.Point; strcpy (Out->Domain, Addr.Domain); strcpy (Out->Name, &ArcMailName[strlen (ArcMailName) - 12]); strcpy (Out->Complete, ArcMailName); Out->Status = Flag; Out->ArcMail = TRUE; Out->TruncateAfter = TRUE; Out->Add (); Out->Update (); } delete Out; } }