From bcdfa4f0b9f19a33d850080e614582e66cc61097 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 15 Oct 2013 20:16:26 +0200 Subject: [PATCH] Simple client for testing. --- Makefile | 9 ++- run.cpp | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 run.cpp diff --git a/Makefile b/Makefile index 64d01f2..ce1ac72 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,18 @@ DMLITE_PREFIX?=/usr DMLITE_CPPFLAGS?=-I$(DMLITE_PREFIX)/include DMLITE_LIBS?=-L$(DMLITE_PREFIX)/$(libarch) -ldmlite -all: scan +PROGRAMS=scan run + +all: $(PROGRAMS) scan: scan.o walk.o $(CXX) $(LDFLAGS) $(DMLITE_LIBS) $+ -o $@ +run: run.o + $(CXX) $(LDFLAGS) $(DMLITE_LIBS) $+ -o $@ + clean: - rm -fv scan *.o + rm -fv *.o $(PROGRAMS) .cpp.o: $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DMLITE_CPPFLAGS) -c $< -o $@ diff --git a/run.cpp b/run.cpp new file mode 100644 index 0000000..7608027 --- /dev/null +++ b/run.cpp @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include + +#define DMLITE_DEFAULT_CONF "/etc/dmlite.conf" + +int main(int argc, char *argv[]) { + dmlite::PluginManager manager; + std::string conf = DMLITE_DEFAULT_CONF; + + if (argc < 3) { + std::cout << "Usage: " << argv[0] << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] ] ]" << std::endl; + std::cout << " s ... stat" << std::endl; + std::cout << " d ... opendir/readdir" << std::endl; + std::cout << " r ... read" << std::endl; + std::cout << " h ... chdir" << std::endl; + std::cout << " w ... whereToWrite" << std::endl; + std::cout << " c ... create" << std::endl; + } + + if (argc >= 2) conf = argv[1]; + std::cout << "Config file: " << conf << std::endl; + + try { + manager.loadConfiguration(conf); + } catch (dmlite::DmException& e) { + std::cout << "Could not load the configuration file." << std::endl + << "Reason: " << e.what() << std::endl; + return 1; + } + + dmlite::StackInstance stack(&manager); + + // Set security credentials + + dmlite::SecurityCredentials creds; + + creds.clientName = std::string("/C=UG/L=Tropic/O=Utopia/OU=Relaxation/CN=dpmtest"); + creds.remoteAddress = std::string("127.0.0.1"); + try { + stack.setSecurityCredentials(creds); + } catch (dmlite::DmException& e) { + std::cout << "Could not set the credentials." << std::endl + << "Reason: " << e.what() << std::endl; + return 1; + } + + // Action + dmlite::Catalog* catalog = stack.getCatalog(); + dmlite::PoolManager* poolManager = stack.getPoolManager(); + + if (argc < 3) return 0; + + switch (argv[2][0]) { + case 's': + try { + dmlite::ExtendedStat xstat = catalog->extendedStat("pokus"); + std::cout << "Success!" << std::endl; + } + catch (dmlite::DmException& e) { + std::cout << "Could not stat the file." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + + case 'd': + + try { + std::string path; + dmlite::Directory* dir; + + path="/tmp/pokus"; + if (argc >= 4) path = argv[3]; + + dmlite::ExtendedStat* xstat; + + dir = catalog->openDir(path); + + std::cout << "Content of the directory " << path << std::endl; + printf(" %6s %5s %5s %5s %s\n", "Mode", "UID", "GID", "Size", "Name"); + while ((xstat = catalog->readDirx(dir)) != NULL) { + printf(" %06o %5d %5d %5zu %s\n", xstat->stat.st_mode, xstat->stat.st_uid, xstat->stat.st_gid, xstat->stat.st_size, xstat->name.c_str()); + //std::cout << '\t' << xstat->name << std::endl; + } + + catalog->closeDir(dir); + std::cout << "Success!" << std::endl; +#if 0 + struct dirent *ent; + + dir = catalog->openDir(path); + + std::cout << "Content of the directory " << path << std::endl; + while ((ent = catalog->readDir(dir)) != NULL) { + std::cout << '\t' << ent->d_name << std::endl; + } + + catalog->closeDir(dir); + std::cout << "Success!" << std::endl; +#endif + } + catch (dmlite::DmException& e) { + std::cout << "Could not open the directory." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + + case 'h': + try { + std::string d; + + d = catalog->getWorkingDir(); + std::cout << "Current directory before: '" << d << "'" << std::endl; + + catalog->changeDir("/tmp"); + + d = catalog->getWorkingDir(); + std::cout << "Current directory after: '" << d << "'" << std::endl; + } catch (dmlite::DmException& e) { + std::cout << "Error." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + + case 'r': + try { + std::string path; + dmlite::Location loc; + dmlite::Location::const_iterator i; + unsigned n; + + path = "/tmp/pokus"; + //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg"; + if (argc >= 4) path = argv[3]; + loc = poolManager->whereToRead(path); + + for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) { + std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl; + } + } catch (dmlite::DmException& e) { + std::cout << "Could not read." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + + case 'w': + try { + std::string path; + dmlite::Location loc; + dmlite::Location::const_iterator i; + unsigned n; + + path = "/tmp/pokus"; + //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg"; + if (argc >= 4) path = argv[3]; + loc = poolManager->whereToWrite(path); + + for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) { + std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl; + } + } catch (dmlite::DmException& e) { + std::cout << "Could not write." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + + case 'c': + try { + std::string path; + + path = "/tmp/pokus"; + if (argc >= 4) path = argv[3]; + catalog->create(path, 0644); + } catch (dmlite::DmException& e) { + std::cout << "Could not create." << std::endl + << "Reason: " << e.what() << std::endl; + return e.code(); + } + break; + } + +// delete catalog; +// delete poolManager; + + return 0; +} -- 1.8.2.3