Пример #1
0
char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {

    char retVal = 0;

    // assert we can login
    retVal = assureLoggedIn();
    if (retVal) return retVal;

    SWBuf sourcePath = sourceURL;
    SWBuf outFile = (!destBuf) ? destPath : "swftplib.tmp";
    sourcePath << (6 + host.length()); // shift << "ftp://hostname";
    SWLog::getSystemLog()->logDebug("getting file %s to %s\n", sourcePath.c_str(), outFile.c_str());
    if (passive)
        FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, ftpConnection);
    else
        FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, ftpConnection);
    // !!!WDG also want to set callback options
    if (sourcePath.endsWith("/") || sourcePath.endsWith("\\")) {
        SWLog::getSystemLog()->logDebug("getting test directory %s\n", sourcePath.c_str());
        FtpDir(NULL, sourcePath, ftpConnection);
        SWLog::getSystemLog()->logDebug("getting real directory %s\n", sourcePath.c_str());
        retVal = FtpDir(outFile.c_str(), sourcePath, ftpConnection) - 1;
    }
    else {
        SWLog::getSystemLog()->logDebug("getting file %s\n", sourcePath.c_str());
        retVal = FtpGet(outFile.c_str(), sourcePath, FTPLIB_IMAGE, ftpConnection) - 1;
    }

    // Is there a way to FTPGet directly to a buffer?
    // If not, we probably want to add x-platform way to open a tmp file with FileMgr
    // This wreaks and will easily fail if a user's CWD is not writable.
    if (destBuf) {
        FileDesc *fd = FileMgr::getSystemFileMgr()->open("swftplib.tmp", FileMgr::RDONLY);
        long size = fd->seek(0, SEEK_END);
        fd->seek(0, SEEK_SET);
        destBuf->size(size);
        fd->read(destBuf->getRawData(), size);
        FileMgr::getSystemFileMgr()->close(fd);
        FileMgr::removeFile("swftplib.tmp");
    }

    return retVal;
}
Пример #2
0
int main(int argc, char **argv) {

	SWMgr library;

	SWModule *book = library.getModule("KJV");

	VerseKey *vk = (VerseKey *) book->getKey();
	for (;!vk->popError();vk->setChapter(vk->getChapter()+1)) {
		vk->setVerse(vk->getVerseMax());
		SWBuf text = book->stripText();
		text = text.trim();
		if (text.endsWith(",")) {
			cout << vk->getText() << ":\n\n";
			cout << text << endl;
		}
	}

	return 0;
}
Пример #3
0
void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths, SWConfig **providedSysConf) {
	SWBuf path;
	SWBuf sysConfPath;
	ConfigEntMap::iterator entry;
	ConfigEntMap::iterator lastEntry;

	SWConfig *sysConf = 0;
	SWBuf sysConfDataPath = "";

	*configType = 0;

	SWBuf homeDir = getHomeDir();

	// check for a sysConf passed in to us
	SWLog::getSystemLog()->logDebug("Checking for provided SWConfig(\"sword.conf\")...");
	if (providedSysConf && *providedSysConf) {
		sysConf = *providedSysConf;
		SWLog::getSystemLog()->logDebug("found.");
	}

	// if we haven't been given our datapath in a sysconf, we need to track it down
	if (!sysConf) {
		// check working directory
		SWLog::getSystemLog()->logDebug("Checking working directory for sword.conf...");
		if (FileMgr::existsFile(".", "sword.conf")) {
			SWLog::getSystemLog()->logDebug("Overriding any systemwide or ~/.sword/ sword.conf with one found in current directory.");
			sysConfPath = "./sword.conf";
			sysConf = new SWConfig(sysConfPath);
			if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) {
				sysConfDataPath = (*entry).second;
			}
			if (providedSysConf) {
				*providedSysConf = sysConf;
			}
			else {
				delete sysConf;
				sysConf = 0;
			}
		}
		if (!sysConfDataPath.size()) {
			SWLog::getSystemLog()->logDebug("Checking working directory for mods.conf...");
			if (FileMgr::existsFile(".", "mods.conf")) {
				SWLog::getSystemLog()->logDebug("found.");
				stdstr(prefixPath, "./");
				stdstr(configPath, "./mods.conf");
				return;
			}

			SWLog::getSystemLog()->logDebug("Checking working directory for mods.d...");
			if (FileMgr::existsDir(".", "mods.d")) {
				SWLog::getSystemLog()->logDebug("found.");
				stdstr(prefixPath, "./");
				stdstr(configPath, "./mods.d");
				*configType = 1;
				return;
			}

			// check working directory ../library/
			SWLog::getSystemLog()->logDebug("Checking working directory ../library/ for mods.d...");
			if (FileMgr::existsDir("../library", "mods.d")) {
				SWLog::getSystemLog()->logDebug("found.");
				stdstr(prefixPath, "../library/");
				stdstr(configPath, "../library/mods.d");
				*configType = 1;
				return;
			}

			// check environment variable SWORD_PATH
			SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH...");

			SWBuf envsworddir = getenv("SWORD_PATH");
			if (envsworddir.length()) {
				
				SWLog::getSystemLog()->logDebug("found (%s).", envsworddir.c_str());
				path = envsworddir;
				if ((envsworddir[envsworddir.length()-1] != '\\') && (envsworddir[envsworddir.length()-1] != '/'))
					path += "/";

				SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.conf...");
				if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
					SWLog::getSystemLog()->logDebug("found.");
					stdstr(prefixPath, path.c_str());
					path += "mods.conf";
					stdstr(configPath, path.c_str());
					return;
				}

				SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.d...");
				if (FileMgr::existsDir(path.c_str(), "mods.d")) {
					SWLog::getSystemLog()->logDebug("found.");
					stdstr(prefixPath, path.c_str());
					path += "mods.d";
					stdstr(configPath, path.c_str());
					*configType = 1;
					return;
				}
			}


			// check for systemwide globalConfPath

			SWLog::getSystemLog()->logDebug("Parsing %s...", globalConfPath);
			char *globPaths = 0;
			char *gfp;
			stdstr(&globPaths, globalConfPath);
			for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
				SWLog::getSystemLog()->logDebug("Checking for %s...", gfp);
				if (FileMgr::existsFile(gfp)) {
					SWLog::getSystemLog()->logDebug("found.");
					break;
				}
			}
			if (gfp)
				sysConfPath = gfp;
			delete [] globPaths;

			if (homeDir.length()) {
				SWBuf tryPath = homeDir;
				tryPath += ".sword/sword.conf";
				if (FileMgr::existsFile(tryPath)) {
					SWLog::getSystemLog()->logDebug("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str());
					sysConfPath = tryPath;
				}
				else {
					SWBuf tryPath = homeDir;
					tryPath += "sword/sword.conf";
					if (FileMgr::existsFile(tryPath)) {
						SWLog::getSystemLog()->logDebug("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str());
						sysConfPath = tryPath;
					}
				}
			}
		}
	}

	if (!sysConf && sysConfPath.size()) {
		sysConf = new SWConfig(sysConfPath);
	}

	if (sysConf) {
		if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) {
			sysConfDataPath = (*entry).second;
		}
		if (sysConfDataPath.size()) {
			if ((!sysConfDataPath.endsWith("\\")) && (!sysConfDataPath.endsWith("/")))
				sysConfDataPath += "/";

			path = sysConfDataPath;
			SWLog::getSystemLog()->logDebug("DataPath in %s is set to %s.", sysConfPath.c_str(), path.c_str());
			SWLog::getSystemLog()->logDebug("Checking for mods.conf in DataPath...");
			
			if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
				SWLog::getSystemLog()->logDebug("found.");
				stdstr(prefixPath, path.c_str());
				path += "mods.conf";
				stdstr(configPath, path.c_str());
				*configType = 1;
			}

			SWLog::getSystemLog()->logDebug("Checking for mods.d in DataPath...");

			if (FileMgr::existsDir(path.c_str(), "mods.d")) {
				SWLog::getSystemLog()->logDebug("found.");
				stdstr(prefixPath, path.c_str());
				path += "mods.d";
				stdstr(configPath, path.c_str());
				*configType = 1;
			}
		}
	}

	// do some extra processing of sysConf if we have one
	if (sysConf) {
		if (augPaths) {
			augPaths->clear();
			entry     = sysConf->Sections["Install"].lower_bound("AugmentPath");
			lastEntry = sysConf->Sections["Install"].upper_bound("AugmentPath");
			for (;entry != lastEntry; entry++) {
				path = entry->second;
				if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/'))
					path += "/";
				augPaths->push_back(path);
			}
		}
		if (providedSysConf) {
			*providedSysConf = sysConf;
		}
		else delete sysConf;
	}

	if (*configType)
		return;

	// WE STILL HAVEN'T FOUND A CONFIGURATION.  LET'S LOOK IN SOME OS SPECIFIC
	// LOCATIONS
	//
	// for various flavors of windoze...
	// check %ALLUSERSPROFILE%/Application Data/sword/

	SWLog::getSystemLog()->logDebug("Checking $ALLUSERSPROFILE/Application Data/sword/...");

	SWBuf envallusersdir  = getenv("ALLUSERSPROFILE");
	if (envallusersdir.length()) {
		SWLog::getSystemLog()->logDebug("found (%s).", envallusersdir.c_str());
		path = envallusersdir;
		if ((!path.endsWith("\\")) && (!path.endsWith("/")))
			path += "/";

		path += "Application Data/sword/";
		SWLog::getSystemLog()->logDebug("Checking %s for mods.d...", path.c_str());
		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
			SWLog::getSystemLog()->logDebug("found.");
			stdstr(prefixPath, path.c_str());
			path += "mods.d";
			stdstr(configPath, path.c_str());
			*configType = 1;
			return;
		}
	}

	// for Mac OSX...
	// check $HOME/Library/Application Support/Sword/

	SWLog::getSystemLog()->logDebug("Checking $HOME/Library/Application Support/Sword/...");

	SWBuf pathCheck = getHomeDir();
	if (pathCheck.length()) {
		SWLog::getSystemLog()->logDebug("found (%s).", pathCheck.c_str());
		path = pathCheck;
		if ((!path.endsWith("\\")) && (!path.endsWith("/")))
			path += "/";

		SWLog::getSystemLog()->logDebug("Checking %s for mods.d...", path.c_str());
		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
			SWLog::getSystemLog()->logDebug("found.");
			stdstr(prefixPath, path.c_str());
			path += "mods.d";
			stdstr(configPath, path.c_str());
			*configType = 1;
			return;
		}
	}

	// FINALLY CHECK PERSONAL HOME DIRECTORY LOCATIONS
	// check ~/.sword/

	SWLog::getSystemLog()->logDebug("Checking home directory for ~/.sword...");

	if (homeDir.length()) {
		path = homeDir;
		path += ".sword/";
		SWLog::getSystemLog()->logDebug("  Checking for %smods.conf...", path.c_str());
		if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
			SWLog::getSystemLog()->logDebug("found.");
			stdstr(prefixPath, path.c_str());
			path += "mods.conf";
			stdstr(configPath, path.c_str());
			return;
		}

		SWLog::getSystemLog()->logDebug("  Checking for %smods.d...", path.c_str());
		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
			SWLog::getSystemLog()->logDebug("found.");
			stdstr(prefixPath, path.c_str());
			path += "mods.d";
			stdstr(configPath, path.c_str());
			*configType = 2;
			return;
		}

		path = homeDir;
		path += "sword/";
		SWLog::getSystemLog()->logDebug("  Checking for %smods.d...", path.c_str());
		if (FileMgr::existsDir(path.c_str(), "mods.d")) {
			SWLog::getSystemLog()->logDebug("found.");
			stdstr(prefixPath, path.c_str());
			path += "mods.d";
			stdstr(configPath, path.c_str());
			*configType = 2;
			return;
		}
	}
}