USHORT TFileBase::Open (PSZ pszDataPath, PSZ pszArea) { CHAR szFile[128]; strcpy (DataPath, pszDataPath); if (DataPath[0] != '\0') { #if defined(__LINUX__) if (DataPath[strlen (DataPath) - 1] != '/') strcat (DataPath, "/"); #else if (DataPath[strlen (DataPath) - 1] != '\\') strcat (DataPath, "\\"); #endif } sprintf (szFile, "%s%s", DataPath, "filebase.idx"); if ((fdIdx = sopen (AdjustPath (szFile), O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) == -1) return (FALSE); sprintf (szFile, "%s%s", DataPath, "filebase.dat"); if ((fdDat = sopen (AdjustPath (szFile), O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) == -1) { close (fdDat); fdDat = -1; return (FALSE); } strcpy (szArea, pszArea); return (TRUE); }
TProtocol::TProtocol (PSZ path) { fdDat = -1; strcpy (DataFile, path); strcat (DataFile, "protocol.dat"); AdjustPath (strlwr (DataFile)); }
String System::MakePath(const String& file,const String& path) { if(IsRelative(file)) { return NormalPath(AdjustPath(path,true)+file); } else if(file=="/"||file=="\\") { int pos=path.find(':'); if(pos<0) { return "/"; } else { return path.substr(0,pos); } } else { return NormalPath(file); } }
CCookie* CCookie::FromString(const CStringA& strCookie, LPCSTR lpszDefaultDomain, LPCSTR lpszDefaultPath) { CStringA strName; CStringA strValue; CStringA strDomain; CStringA strPath; int iMaxAge = -1; BOOL bHttpOnly = FALSE; BOOL bSecure = FALSE; EnSameSite enSameSite = SS_NONE; int i = 0; int iStart = 0; while(TRUE) { CStringA strField = strCookie.Tokenize(COOKIE_FIELD_SEP, iStart); strField.Trim(); if(strField.IsEmpty()) break; if(i == 0) { ParseFieldKV(strField, strName, strValue, COOKIE_KV_SEP_CHAR); if(strName.IsEmpty()) return nullptr; } else { CStringA strKey; CStringA strVal; ParseFieldKV(strField, strKey, strVal, COOKIE_KV_SEP_CHAR); if(strKey.CompareNoCase(COOKIE_DOMAIN) == 0) strDomain = strVal; else if(strKey.CompareNoCase(COOKIE_PATH) == 0) strPath = strVal; else if(strKey.CompareNoCase(COOKIE_MAX_AGE) == 0 && !strVal.IsEmpty()) iMaxAge = atoi(strVal); else if(strKey.CompareNoCase(COOKIE_EXPIRES) == 0 && !strVal.IsEmpty() && iMaxAge == -1) { __time64_t tmExpires = -1; if(!ParseExpires(strVal, tmExpires)) return nullptr; iMaxAge = ExpiresToMaxAge(tmExpires); } else if(strKey.CompareNoCase(COOKIE_HTTPONLY) == 0) bHttpOnly = TRUE; else if(strKey.CompareNoCase(COOKIE_SECURE) == 0) bSecure = TRUE; else if(strKey.CompareNoCase(COOKIE_SAMESITE) == 0) { if(strVal.IsEmpty() || strVal.CompareNoCase(COOKIE_SAMESITE_STRICT) == 0) enSameSite = SS_STRICT; else if(strVal.CompareNoCase(COOKIE_SAMESITE_LAX) == 0) enSameSite = SS_LAX; } } ++i; } if(!AdjustDomain(strDomain, lpszDefaultDomain) || !AdjustPath(strPath, lpszDefaultPath)) return nullptr; CCookie* pCookie = new CCookie(strName, strValue, strDomain, strPath, iMaxAge, bHttpOnly, bSecure, enSameSite); ASSERT(pCookie->IsValid()); return pCookie; }
VOID TFileBase::Pack (VOID) { int fdNdx, fdNdat, Readed; CHAR File[128], NewFile[128], *Buffer; FILEDATA fileData; FILEINDEX fileIndex; sprintf (File, "%s%s", DataPath, "filebase.$dx"); fdNdx = sopen (AdjustPath (File), O_RDWR|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE); sprintf (File, "%s%s", DataPath, "filebase.$at"); fdNdat = sopen (AdjustPath (File), O_RDWR|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE); Buffer = (CHAR *)malloc (2048); if (fdIdx != -1 && fdDat != -1 && fdNdx != -1 && fdNdat != -1 && Buffer != NULL) { while (read (fdIdx, &fileIndex, sizeof (FILEINDEX)) == sizeof (FILEINDEX)) { if (!(fileIndex.Flags & FILE_DELETED)) { lseek (fdDat, fileIndex.Offset, SEEK_SET); fileIndex.Offset = tell (fdNdat); write (fdNdx, &fileIndex, sizeof (FILEINDEX)); read (fdDat, &fileData, sizeof (FILEDATA)); write (fdNdat, &fileData, sizeof (FILEDATA)); while (fileData.Description > 0) { Readed = read (fdDat, Buffer, 2048); write (fdNdat, Buffer, Readed); fileData.Description -= (USHORT)Readed; } while (fileData.Uploader > 0) { Readed = read (fdDat, Buffer, 2048); write (fdNdat, Buffer, Readed); fileData.Uploader -= (USHORT)Readed; } } } close (fdNdat); close (fdDat); fdNdat = -1; sprintf (File, "%s%s", DataPath, "filebase.$at"); sprintf (NewFile, "%s%s", DataPath, "filebase.dat"); unlink (NewFile); rename (File, NewFile); fdDat = sopen (NewFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); close (fdNdx); close (fdIdx); fdNdx = -1; sprintf (File, "%s%s", DataPath, "filebase.$dx"); sprintf (NewFile, "%s%s", DataPath, "filebase.idx"); unlink (NewFile); rename (File, NewFile); fdIdx = sopen (NewFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE); } if (Buffer != NULL) delete Buffer; if (fdNdat != -1) close (fdNdat); sprintf (File, "%s%s", DataPath, "filebase.$at"); unlink (File); if (fdNdx != -1) close (fdNdx); sprintf (File, "%s%s", DataPath, "filebase.$dx"); unlink (File); }
VOID UpdateFilebase (USHORT KeepDate) { FILE *fp; DIR *dir; ULONG Total, Added; CHAR *p, Path[128], Temp[128]; time_t today; struct stat statbuf; struct tm *ltm; struct dirent *ent; class TFileData *Data; class TFileBase *File; class TPacker *Packer; printf (" * Updating filebase\r\n"); unlink ("file_id.diz"); Packer = new TPacker (Cfg->SystemPath); if ((Data = new TFileData (Cfg->SystemPath)) != NULL) { if (Data->First () == TRUE) do { Total = 0L; Added = 0L; cprintf (" +-- %-15.15s %-32.32s ", Data->Key, Data->Display); if ((File = new TFileBase (Cfg->SystemPath, Data->Key)) != NULL) { strcpy (Temp, Data->Download); if (Temp[strlen (Temp) - 1] == '\\' || Temp[strlen (Temp) - 1] == '/') Temp[strlen (Temp) - 1] = '\0'; if (File->First () == TRUE) do { sprintf (Path, "%s%s", Data->Download, File->Name); if (stat (AdjustPath (Path), &statbuf)) File->Delete (); } while (File->Next () == TRUE); File->SortByName (); if ((dir = opendir (AdjustPath (Temp))) != NULL) { while ((ent = readdir (dir)) != NULL) { if (!strcmp (ent->d_name, ".") || !strcmp (ent->d_name, "..")) continue; if (!stricmp (ent->d_name, "files.bbs") || !stricmp (ent->d_name, "descript.ion")) continue; if (File->Read (ent->d_name) == FALSE) { sprintf (Path, "%s%s", Data->Download, ent->d_name); if (!stat (AdjustPath (Path), &statbuf)) { File->Clear (); strcpy (File->Area, Data->Key); strcpy (File->Name, ent->d_name); strcpy (File->Complete, Path); File->Size = statbuf.st_size; ltm = localtime ((time_t *)&statbuf.st_mtime); File->Date.Day = (UCHAR)ltm->tm_mday; File->Date.Month = (UCHAR)(ltm->tm_mon + 1); File->Date.Year = (USHORT)(ltm->tm_year + 1900); File->Date.Hour = (UCHAR)ltm->tm_hour; File->Date.Minute = (UCHAR)ltm->tm_min; if (KeepDate == FALSE) { today = time (NULL); ltm = localtime (&today); File->UplDate.Day = (UCHAR)ltm->tm_mday; File->UplDate.Month = (UCHAR)(ltm->tm_mon + 1); File->UplDate.Year = (USHORT)(ltm->tm_year + 1900); File->UplDate.Hour = (UCHAR)ltm->tm_hour; File->UplDate.Minute = (UCHAR)ltm->tm_min; } else { File->UplDate.Day = File->Date.Day; File->UplDate.Month = File->Date.Month; File->UplDate.Year = File->Date.Year; File->UplDate.Hour = File->Date.Hour; File->UplDate.Minute = File->Date.Minute; } File->Uploader = "Sysop"; File->CdRom = Data->CdRom; File->Description->Add ("Description missing"); if (Packer != NULL) { if (Packer->CheckArc (Path) == TRUE) { #if defined(__LINUX__) mkdir ("lfiletmp", 0666); #else mkdir ("lfiletmp"); #endif if (strstr (Packer->UnpackCmd, "%3") == NULL && strstr (Packer->UnpackCmd, "%f") == NULL) strcat (Packer->UnpackCmd, " %3"); Packer->DoUnpack (Path, "lfiletmp", "file_id.diz"); strcpy (Temp, "lfiletmp\\file_id.diz"); if (!stat (AdjustPath (Temp), &statbuf)) { if ((fp = fopen (Temp, "rt")) != NULL) { File->Description->Clear (); while (fgets (Temp, sizeof (Temp) - 1, fp) != NULL) { if ((p = strchr (Temp, '\n')) != NULL) *p = '\0'; if ((p = strchr (Temp, '\r')) != NULL) *p = '\0'; File->Description->Add (Temp); } fclose (fp); } strcpy (Temp, "lfiletmp\\file_id.diz"); unlink (AdjustPath (Temp)); } rmdir ("lfiletmp"); } } File->Add (); Added++; } } Total++; } closedir (dir); } delete File; } cprintf ("Total: %5lu Added: %5lu\r\n", Total, Added); } while (Data->Next () == TRUE); delete Data; } if (Packer != NULL) delete Packer; }