void JCheckSiteName ( const JCharacter* encSiteSuffix, const JCharacter siteCode, const JCharacter* map[], const JSize size ) { JString siteSuffix = encSiteSuffix; const JSize len = siteSuffix.GetLength(); for (JIndex i=1; i<=len; i++) { siteSuffix.SetCharacter(i, siteSuffix.GetCharacter(i) ^ siteCode); } map[1] = siteSuffix.GetCString(); if (!(JGetHostName()).EndsWith(siteSuffix, kJFalse)) { const JString msg = JGetString(kWrongSiteID, map, size); (JGetUserNotification())->DisplayMessage(msg); exit(0); } }
inline JBoolean jTranslateLocalToRemote1 ( const JString& localPath, const JCharacter* mountDev, const JCharacter* mountDir, JBoolean* found, JString* host, JString* remotePath ) { if (!JIsSamePartition(localPath, mountDir)) { return kJFalse; } const JString dev = mountDev; JIndex hostEndIndex; if (dev.LocateSubstring(":/", &hostEndIndex) && hostEndIndex > 1) { *host = dev.GetSubstring(1, hostEndIndex-1); #ifdef _J_CYGWIN if (host->GetLength() == 1 && 'A' <= host->GetFirstCharacter() && host->GetFirstCharacter() <= 'Z') { *host = JGetHostName(); *remotePath = localPath; JCleanPath(remotePath); *found = kJTrue; return kJTrue; } #endif jGetFullHostName(host); *remotePath = dev.GetSubstring(hostEndIndex+1, dev.GetLength()); JAppendDirSeparator(remotePath); // use JIndexRange to allow empty JIndexRange r(strlen(mountDir)+1, localPath.GetLength()); *remotePath += localPath.GetSubstring(r); JCleanPath(remotePath); *found = kJTrue; } return kJTrue; }
inline void jGetFullHostName ( JString* host ) { if (!host->Contains(".")) { const JString localhost = JGetHostName(); JIndex dotIndex; if (localhost.LocateSubstring(".", &dotIndex)) { *host += localhost.GetSubstring(dotIndex, localhost.GetLength()); } } }
JString JFileNameToURL ( const JCharacter* fileName ) { assert( !JIsRelativePath(fileName) ); JString host, file; if (!JTranslateLocalToRemote(fileName, &host, &file)) { host = JGetHostName(); file = fileName; } JString url("file://"); url += host; url += file; return url; }
JBoolean JURLToFileName ( const JCharacter* url, JString* fileName ) { JString s(url); JIndex index; if (s.LocateSubstring("://", &index)) { s.RemoveSubstring(1, index+2); if (!s.LocateSubstring("/", &index) || index == 1) { return kJFalse; } const JString urlHostName = s.GetSubstring(1, index-1); const JString urlFileName = s.GetSubstring(index, s.GetLength()); if (urlHostName == JGetHostName()) { *fileName = urlFileName; return kJTrue; } else { return JTranslateRemoteToLocal(urlHostName, urlFileName, fileName); } } else { fileName->Clear(); return kJFalse; } }