diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index ab04899eb..4784a80c6 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -724,6 +724,14 @@ int FileIndex::cleanOldEntries(time_t old) /* removes entries older than old */ +int FileIndex::printFileIndex(std::ostream &out) +{ + std::string sout ; + printFileIndex(sout) ; + out << sout << std::endl; + + return 1 ; +} int FileIndex::printFileIndex(std::string &out) { out += "FileIndex::printFileIndex()\n"; diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index 4546f354c..32cfb66ea 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -227,6 +227,7 @@ class FileIndex /* debug */ int printFileIndex(std::string &out); + int printFileIndex(std::ostream &out); /* load/save to file */ int loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size); diff --git a/libretroshare/src/ft/ftdata.h b/libretroshare/src/ft/ftdata.h index 06c0ba10f..952e2ae01 100644 --- a/libretroshare/src/ft/ftdata.h +++ b/libretroshare/src/ft/ftdata.h @@ -101,92 +101,4 @@ class ftDataRecv virtual bool recvCRC32Map(const std::string& peer_id,const std::string& hash,const CRC32Map& crcmap) = 0; }; - /**************** FOR TESTING ***********************/ - -/******* Pair of Send/Recv (Only need to handle Send side) ******/ -class ftDataSendPair: public ftDataSend -{ - public: - - ftDataSendPair(ftDataRecv *recv); -virtual ~ftDataSendPair() { return; } - - /* Client Send */ -virtual bool sendDataRequest(const std::string &peerId, const std::string &hash, - uint64_t size, uint64_t offset, uint32_t chunksize); - - /* Server Send */ -virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size, - uint64_t offset, uint32_t chunksize, void *data); - - /* Send a request for a chunk map */ -virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client); - - /* Send a chunk map */ -virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client); - - /* Send a request for a chunk map */ -virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); - - /* Send a chunk map */ -virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap); - ftDataRecv *mDataRecv; -}; - - -class ftDataSendDummy: public ftDataSend -{ - public: -virtual ~ftDataSendDummy() { return; } - - /* Client Send */ -virtual bool sendDataRequest(const std::string &peerId, const std::string &hash, - uint64_t size, uint64_t offset, uint32_t chunksize); - - /* Server Send */ -virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size, - uint64_t offset, uint32_t chunksize, void *data); - - /* Send a request for a chunk map */ -virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client); - - /* Send a chunk map */ -virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client); - - /* Send a request for a chunk map */ -virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); - - /* Send a chunk map */ -virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap); -}; - -class ftDataRecvDummy: public ftDataRecv -{ - public: - -virtual ~ftDataRecvDummy() { return; } - - /* Client Recv */ -virtual bool recvData(const std::string& peerId, const std::string& hash, - uint64_t size, uint64_t offset, uint32_t chunksize, void *data); - - /* Server Recv */ -virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, - uint64_t size, uint64_t offset, uint32_t chunksize); - - /* Send a request for a chunk map */ -virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash, - bool is_client); - - /* Send a chunk map */ -virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash, - const CompressedChunkMap& cmap,bool is_client); - - /* Send a request for a chunk map */ -virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); - - /* Send a chunk map */ -virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap); -}; - #endif diff --git a/libretroshare/src/ft/ftfilesearch.cc b/libretroshare/src/ft/ftfilesearch.cc index e868ab6ca..2a87f4478 100644 --- a/libretroshare/src/ft/ftfilesearch.cc +++ b/libretroshare/src/ft/ftfilesearch.cc @@ -179,18 +179,3 @@ bool ftFileSearch::search(const std::string &hash, FileSearchFlags hintflags, Fi return false; } - -bool ftSearchDummy::search(std::string /*hash*/, FileSearchFlags hintflags, FileInfo &/*info*/) const -{ - /* remove unused parameter warnings */ - (void) hintflags; - -#ifdef DEBUG_SEARCH - std::cerr << "ftSearchDummy::search(" << hash ; - std::cerr << ", " << hintflags << ");"; - std::cerr << std::endl; -#endif - return false; -} - - diff --git a/libretroshare/src/ft/ftsearch.h b/libretroshare/src/ft/ftsearch.h index 67bf965e5..100864008 100644 --- a/libretroshare/src/ft/ftsearch.h +++ b/libretroshare/src/ft/ftsearch.h @@ -51,14 +51,4 @@ class ftSearch }; - -class ftSearchDummy: public ftSearch -{ - public: - - ftSearchDummy() { return; } -virtual ~ftSearchDummy() { return; } -virtual bool search(std::string hash, FileSearchFlags hintflags, FileInfo &info) const; -}; - #endif diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index a361a3d4d..21b1b20d7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -455,7 +455,6 @@ SOURCES += dbase/cachestrapper.cc \ SOURCES += ft/ftchunkmap.cc \ ft/ftcontroller.cc \ - ft/ftdata.cc \ ft/ftdatamultiplex.cc \ ft/ftdbase.cc \ ft/ftextralist.cc \ diff --git a/libretroshare/src/tests/network_simulator/argstream.h b/libretroshare/src/tests/common/argstream.h similarity index 100% rename from libretroshare/src/tests/network_simulator/argstream.h rename to libretroshare/src/tests/common/argstream.h diff --git a/libretroshare/src/tests/dbase/Makefile b/libretroshare/src/tests/dbase/Makefile index 6dd13174b..5e881dff6 100644 --- a/libretroshare/src/tests/dbase/Makefile +++ b/libretroshare/src/tests/dbase/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/dbase/fimontest.cc b/libretroshare/src/tests/dbase/fimontest.cc index 4440a35b0..ec9e9989b 100644 --- a/libretroshare/src/tests/dbase/fimontest.cc +++ b/libretroshare/src/tests/dbase/fimontest.cc @@ -71,7 +71,7 @@ int main(int argc, char **argv) { SharedDirInfo dir; dir.filename = argv[optind]; - dir.shareflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE; + dir.shareflags = DIR_FLAGS_PERMISSIONS_MASK ; rootdirs.push_back(dir); std::cerr << "Adding shared directory: " << argv[optind] << std::endl; } diff --git a/libretroshare/src/tests/dbase/fisavetest.cc b/libretroshare/src/tests/dbase/fisavetest.cc index edaa52520..34a2c2968 100644 --- a/libretroshare/src/tests/dbase/fisavetest.cc +++ b/libretroshare/src/tests/dbase/fisavetest.cc @@ -31,7 +31,9 @@ int main() FileIndex *fi1 = createBasicFileIndex(100); FileIndex *fi2 = new FileIndex("A SILLY ID"); - fi1->printFileIndex(std::cout); + std::string out ; + fi1->printFileIndex(out); + std::cout << out < forbiddenroots; @@ -41,7 +43,9 @@ int main() std::cout << " -- new file index -- " << std::endl; fi2->loadIndex("test.index", fhash, size); - fi2->printFileIndex(std::cout); + out.clear() ; + fi2->printFileIndex(out); + std::cout << out << std::endl; delete fi1; delete fi2; diff --git a/libretroshare/src/tests/dbase/fitest2.cc b/libretroshare/src/tests/dbase/fitest2.cc index 7d1fc4c9a..534fe0d6e 100644 --- a/libretroshare/src/tests/dbase/fitest2.cc +++ b/libretroshare/src/tests/dbase/fitest2.cc @@ -75,10 +75,15 @@ int test1(FileIndex *fi) /* clean up the dir (should have no effect) */ fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp); - fi -> printFileIndex(std::cout); + + std::string out ; + fi -> printFileIndex(out); + std::cout << out << std::endl; } - fi -> printFileIndex(std::cout); + std::string out ; + fi -> printFileIndex(out); + std::cout << out << std::endl; return 1; } @@ -133,10 +138,14 @@ int test2(FileIndex *fi) /* clean up the dir */ fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp); - fi -> printFileIndex(std::cout); + std::string out ; + fi -> printFileIndex(out); + std::cout << out << std::endl; } - fi -> printFileIndex(std::cout); + std::string out ; + fi -> printFileIndex(out); + std::cout << out << std::endl; return 1; } @@ -152,7 +161,9 @@ FileIndex *createBasicFileIndex(time_t age) FileEntry fe; /* print empty FileIndex */ - fi -> printFileIndex(std::cout); + std::string out ; + fi -> printFileIndex(out); + std::cout << out << std::endl; std::list rootdirs; rootdirs.push_back("base1"); @@ -206,7 +217,9 @@ FileIndex *createBasicFileIndex(time_t age) fe.name = "file20"; fi -> updateFileEntry("/base3/",fe, age); - fi -> printFileIndex(std::cout); + out.clear() ; + fi -> printFileIndex(out); + std::cout << out << std::endl; return fi; } diff --git a/libretroshare/src/tests/dbase/searchtest.cc b/libretroshare/src/tests/dbase/searchtest.cc index 2bd4bffa0..d09e1b565 100644 --- a/libretroshare/src/tests/dbase/searchtest.cc +++ b/libretroshare/src/tests/dbase/searchtest.cc @@ -51,7 +51,9 @@ int main() while(!hashresult.empty()) { - hashresult.back()->print(std::cout); + std::string out ; + hashresult.back()->print(out); + std::cout << out << std::endl; hashresult.pop_back(); } @@ -65,7 +67,9 @@ int main() while(!termresult.empty()) { - termresult.back()->print(std::cout); + std::string out ; + termresult.back()->print(out); + std::cout << out << std::endl; termresult.pop_back(); } diff --git a/libretroshare/src/tests/ft/Makefile b/libretroshare/src/tests/ft/Makefile index 286e69de0..4e0baffa1 100644 --- a/libretroshare/src/tests/ft/Makefile +++ b/libretroshare/src/tests/ft/Makefile @@ -1,6 +1,8 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src + ##### Define any flags that are needed for this section ####### ############################################################### @@ -8,9 +10,10 @@ DHT_TOP_DIR = ../../../../libbitdht/src include $(RS_TOP_DIR)/tests/scripts/config.mk ############################################################### -TESTOBJ = ftfilemappertest.o ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o ftcrossprovidercreatortest.o ftcontrollertest.o ftserver1test.o ftserver2test.o ftserver3test.o +TESTOBJ = ftfilemappertest.o ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o ftcrossprovidercreatortest.o ftcontrollertest.o ftserver1test.o ftserver2test.o ftserver3test.o ftdata_test.o -TESTS = ftfilemappertest ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test ftcrossprovidercreatortest ftcontrollertest ftserver1test ftserver2test fttransfermoduletest ftserver3test +TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test ftcrossprovidercreatortest ftcontrollertest ftserver1test ftserver2test fttransfermoduletest ftserver3test +#ftfilemappertest all: tests diff --git a/libretroshare/src/tests/ft/ftcontrollertest.cc b/libretroshare/src/tests/ft/ftcontrollertest.cc index 391bc3cd4..37f8f85d4 100644 --- a/libretroshare/src/tests/ft/ftcontrollertest.cc +++ b/libretroshare/src/tests/ft/ftcontrollertest.cc @@ -28,14 +28,15 @@ */ #include "retroshare/rsfiles.h" +#include "retroshare/rspeers.h" #include "ft/ftserver.h" #include "ft/ftextralist.h" #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" -#include "pqi/p3authmgr.h" -#include "pqi/p3connmgr.h" +//#include "pqi/p3authmgr.h" +//#include "pqi/p3connmgr.h" #include "util/rsdebug.h" @@ -123,7 +124,7 @@ int main(int argc, char **argv) std::cerr << "Adding: " << argv[optind] << std::endl; SharedDirInfo info ; - info.shareflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE ; + info.shareflags = DIR_FLAGS_PERMISSIONS_MASK; info.filename = std::string(argv[optind]); info.virtualname = info.filename ; @@ -140,8 +141,8 @@ int main(int argc, char **argv) std::list::const_iterator it, jit; - std::list baseFriendList, friendList; - std::list::iterator fit; + std::list baseFriendList, friendList; + std::list::iterator fit; P3Hub *testHub = new P3Hub(0,NULL); testHub->start(); @@ -149,12 +150,12 @@ int main(int argc, char **argv) /* Setup Base Friend Info */ for(it = peerIds.begin(); it != peerIds.end(); it++) { - pqiAuthDetails pad; + RsPeerDetails pad; pad.id = *it; pad.name = *it; pad.trustLvl = 5; pad.ownsign = true; - pad.trusted = false; + //pad.trusted = false; baseFriendList.push_back(pad); diff --git a/libretroshare/src/tests/ft/ftcrc32test.cc b/libretroshare/src/tests/ft/ftcrc32test.cc index fcdb8462e..35e39c773 100644 --- a/libretroshare/src/tests/ft/ftcrc32test.cc +++ b/libretroshare/src/tests/ft/ftcrc32test.cc @@ -23,6 +23,7 @@ * */ +#include #include #include "retroshare/rstypes.h" #include @@ -67,7 +68,9 @@ int main(int argc, char **argv) std::cerr << "Hashing file :" << *it << std::endl ; std::string hash ; - RsDirUtil::hashFile( *it,hash) ; + uint64_t size ; + std::string name ; + RsDirUtil::hashFile( *it,name,hash,size) ; std::cerr << "Hash = " << hash << std::endl; @@ -87,7 +90,7 @@ int main(int argc, char **argv) return 0 ; } - uint64_t size = ftell(f) ; + size = ftell(f) ; if(fseek(f,0,SEEK_SET)) { diff --git a/libretroshare/src/ft/ftdata.cc b/libretroshare/src/tests/ft/ftdata_test.cc similarity index 100% rename from libretroshare/src/ft/ftdata.cc rename to libretroshare/src/tests/ft/ftdata_test.cc diff --git a/libretroshare/src/tests/ft/ftdata_test.h b/libretroshare/src/tests/ft/ftdata_test.h new file mode 100644 index 000000000..03d509968 --- /dev/null +++ b/libretroshare/src/tests/ft/ftdata_test.h @@ -0,0 +1,144 @@ +/* + * libretroshare/src/ft: ftdata.h + * + * File Transfer for RetroShare. + * + * Copyright 2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef FT_DATA_TEST_INTERFACE_HEADER +#define FT_DATA_TEST_INTERFACE_HEADER + +/* + * ftData. + * + * Internal Interfaces for sending and receiving data. + * Most likely to be implemented by ftServer. + * Provided as an independent interface for testing purposes. + * + */ + +#include +#include + +#include +#include + + /*************** SEND INTERFACE *******************/ + +class CompressedChunkMap ; +class Sha1CheckSum ; + + /**************** FOR TESTING ***********************/ + +/******* Pair of Send/Recv (Only need to handle Send side) ******/ +class ftDataSendPair: public ftDataSend +{ + public: + + ftDataSendPair(ftDataRecv *recv); +virtual ~ftDataSendPair() { return; } + + /* Client Send */ +virtual bool sendDataRequest(const std::string &peerId, const std::string &hash, + uint64_t size, uint64_t offset, uint32_t chunksize); + + /* Server Send */ +virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size, + uint64_t offset, uint32_t chunksize, void *data); + + /* Send a request for a chunk map */ +virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client); + + /* Send a chunk map */ +virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client); + + /* Send a request for a chunk map */ +virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); + + /* Send a chunk map */ +virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap); + ftDataRecv *mDataRecv; + + virtual bool sendSingleChunkCRCRequest(const std::string&, const std::string&, uint32_t); + virtual bool sendSingleChunkCRC(const std::string&, const std::string&, uint32_t, const Sha1CheckSum&); +}; + + +class ftDataSendDummy: public ftDataSend +{ + public: + virtual ~ftDataSendDummy() { return; } + + /* Client Send */ + virtual bool sendDataRequest(const std::string &peerId, const std::string &hash, + uint64_t size, uint64_t offset, uint32_t chunksize); + + /* Server Send */ + virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size, + uint64_t offset, uint32_t chunksize, void *data); + + /* Send a request for a chunk map */ + virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client); + + /* Send a chunk map */ + virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client); + + /* Send a request for a chunk map */ + virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); + + /* Send a chunk map */ + virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap); + + virtual bool sendSingleChunkCRCRequest(const std::string&, const std::string&, uint32_t); + virtual bool sendSingleChunkCRC(const std::string&, const std::string&, uint32_t, const Sha1CheckSum&); + +}; + +class ftDataRecvDummy: public ftDataRecv +{ + public: + +virtual ~ftDataRecvDummy() { return; } + + /* Client Recv */ +virtual bool recvData(const std::string& peerId, const std::string& hash, + uint64_t size, uint64_t offset, uint32_t chunksize, void *data); + + /* Server Recv */ +virtual bool recvDataRequest(const std::string& peerId, const std::string& hash, + uint64_t size, uint64_t offset, uint32_t chunksize); + + /* Send a request for a chunk map */ +virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash, + bool is_client); + + /* Send a chunk map */ +virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash, + const CompressedChunkMap& cmap,bool is_client); + + /* Send a request for a chunk map */ +virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash); + + /* Send a chunk map */ +virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap); +}; + +#endif diff --git a/libretroshare/src/tests/ft/ftdataplextest.cc b/libretroshare/src/tests/ft/ftdataplextest.cc index 4736e5b57..bfa5464c6 100644 --- a/libretroshare/src/tests/ft/ftdataplextest.cc +++ b/libretroshare/src/tests/ft/ftdataplextest.cc @@ -40,6 +40,8 @@ #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" +#include "ftdata_test.h" + void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list &files); @@ -107,7 +109,7 @@ int main(int argc, char **argv) /* now work the thread */ std::list::iterator it; - uint32_t flags = 0; + TransferRequestFlags flags(0); for(it = fileList.begin(); it != fileList.end(); it++) { eList->hashExtraFile(*it, dPeriod, flags); diff --git a/libretroshare/src/tests/ft/ftextralisttest.cc b/libretroshare/src/tests/ft/ftextralisttest.cc index f3fdf76aa..7ac37810f 100644 --- a/libretroshare/src/tests/ft/ftextralisttest.cc +++ b/libretroshare/src/tests/ft/ftextralisttest.cc @@ -101,7 +101,7 @@ int main(int argc, char **argv) std::list hashed; std::list::iterator it; - uint32_t flags = 0; + TransferRequestFlags flags(0); for(it = hashList.begin(); it != hashList.end(); it++) { sleep(period); @@ -148,7 +148,7 @@ void displayExtraListDetails(ftExtraList *eList, std::list toHash, for(it = hashed.begin(); it != hashed.end(); it++) { FileInfo info; - if (eList->search(*it, 0, info)) + if (eList->search(*it, FileSearchFlags(0), info)) { std::cerr << "displayExtraListDetails() Found Hash: " << *it; std::cerr << std::endl; diff --git a/libretroshare/src/tests/ft/ftsearch_test.cc b/libretroshare/src/tests/ft/ftsearch_test.cc new file mode 100644 index 000000000..5803a7428 --- /dev/null +++ b/libretroshare/src/tests/ft/ftsearch_test.cc @@ -0,0 +1,16 @@ +#include "ftsearch_test.h" + +bool ftSearchDummy::search(std::string /*hash*/, FileSearchFlags hintflags, FileInfo &/*info*/) const +{ + /* remove unused parameter warnings */ + (void) hintflags; + +#ifdef DEBUG_SEARCH + std::cerr << "ftSearchDummy::search(" << hash ; + std::cerr << ", " << hintflags << ");"; + std::cerr << std::endl; +#endif + return false; +} + + diff --git a/libretroshare/src/tests/ft/ftsearch_test.h b/libretroshare/src/tests/ft/ftsearch_test.h new file mode 100644 index 000000000..9a5ffcdff --- /dev/null +++ b/libretroshare/src/tests/ft/ftsearch_test.h @@ -0,0 +1,38 @@ +/* + * libretroshare/src/ft: ftsearch.h + * + * File Transfer for RetroShare. + * + * Copyright 2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#pragma once + +#include "ft/ftsearch.h" + +class ftSearchDummy: public ftSearch +{ + public: + + ftSearchDummy() { return; } +virtual ~ftSearchDummy() { return; } +virtual bool search(const std::string& hash, FileSearchFlags hintflags, FileInfo &info) const; +}; + diff --git a/libretroshare/src/tests/ft/ftserver2test.cc b/libretroshare/src/tests/ft/ftserver2test.cc index 173da6e1b..7ab9630aa 100644 --- a/libretroshare/src/tests/ft/ftserver2test.cc +++ b/libretroshare/src/tests/ft/ftserver2test.cc @@ -40,8 +40,8 @@ #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" -#include "pqi/p3authmgr.h" -#include "pqi/p3connmgr.h" +//#include "pqi/p3authmgr.h" +//#include "pqi/p3connmgr.h" #include "util/rsdebug.h" diff --git a/libretroshare/src/tests/ft/ftserver3test.cc b/libretroshare/src/tests/ft/ftserver3test.cc index f7110a967..f7161be16 100644 --- a/libretroshare/src/tests/ft/ftserver3test.cc +++ b/libretroshare/src/tests/ft/ftserver3test.cc @@ -37,7 +37,10 @@ #include "util/rswin.h" #endif +#include #include "retroshare/rsexpr.h" +#include "retroshare/rstypes.h" +#include "retroshare/rsfiles.h" #include "ft/ftserver.h" @@ -45,8 +48,8 @@ #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" -#include "pqi/p3authmgr.h" -#include "pqi/p3connmgr.h" +//#include "pqi/p3authmgr.h" +//#include "pqi/p3connmgr.h" #include "util/rsdebug.h" @@ -163,7 +166,7 @@ int main(int argc, char **argv) SharedDirInfo info ; info.filename = std::string(argv[optind]); info.virtualname = info.filename ; - info.shareflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE ; + info.shareflags = DIR_FLAGS_PERMISSIONS_MASK; fileList.push_back(info) ; } diff --git a/libretroshare/src/tests/ft/fttransfermoduletest.cc b/libretroshare/src/tests/ft/fttransfermoduletest.cc index d1f06fd96..a16baedab 100644 --- a/libretroshare/src/tests/ft/fttransfermoduletest.cc +++ b/libretroshare/src/tests/ft/fttransfermoduletest.cc @@ -46,6 +46,7 @@ #include "ft/fttransfermodule.h" #include "util/utest.h" +#include "ftdata_test.h" INITTEST() @@ -122,7 +123,7 @@ int main(int argc, char **argv) /* now work the thread */ std::list::iterator it; - uint32_t flags = 0; + TransferRequestFlags flags(0); for(it = fileList.begin(); it != fileList.end(); it++) { eList->hashExtraFile(*it, dPeriod, flags); @@ -150,7 +151,7 @@ int main(int argc, char **argv) } std::string savename = "/tmp/" + info.fname; - ftFileCreator *creator = new ftFileCreator(savename, info.size, info.hash); + ftFileCreator *creator = new ftFileCreator(savename, info.size, info.hash,false); ftController *controller = NULL; ftTransferModule *transfer = new ftTransferModule(creator, ftmplex1, controller); diff --git a/libretroshare/src/tests/ft/pqitestor.h b/libretroshare/src/tests/ft/pqitestor.h index d06cb66b2..2dbad359c 100644 --- a/libretroshare/src/tests/ft/pqitestor.h +++ b/libretroshare/src/tests/ft/pqitestor.h @@ -109,7 +109,7 @@ private: class P3Pipe: public P3Interface { public: - P3Pipe() {return; } + P3Pipe() : pipeMtx(std::string("Pipe mutex")) {return; } virtual ~P3Pipe() {return; } virtual int tick() { return 1; } diff --git a/libretroshare/src/tests/general/Makefile b/libretroshare/src/tests/general/Makefile index 3b771b799..c21a36ceb 100644 --- a/libretroshare/src/tests/general/Makefile +++ b/libretroshare/src/tests/general/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/general/netsetup_test.cc b/libretroshare/src/tests/general/netsetup_test.cc index 4c096ba74..9e87b0216 100644 --- a/libretroshare/src/tests/general/netsetup_test.cc +++ b/libretroshare/src/tests/general/netsetup_test.cc @@ -1,6 +1,6 @@ -#include "pqi/p3connmgr.h" -#include "pqi/p3authmgr.h" +//#include "pqi/p3connmgr.h" +//#include "pqi/p3authmgr.h" #include "util/utest.h" #include "upnp/upnphandler.h" diff --git a/libretroshare/src/tests/general/pgpkey_test.cc b/libretroshare/src/tests/general/pgpkey_test.cc index 8f9de261e..a6b49651f 100644 --- a/libretroshare/src/tests/general/pgpkey_test.cc +++ b/libretroshare/src/tests/general/pgpkey_test.cc @@ -7,7 +7,7 @@ #include #include #include "util/utest.h" -#include "util/pgpkey.h" +#include "pgp/pgpkeyutil.h" INITTEST(); diff --git a/libretroshare/src/tests/network_simulator/main.cpp b/libretroshare/src/tests/network_simulator/main.cpp index 514bc0855..1b9cf2e0e 100644 --- a/libretroshare/src/tests/network_simulator/main.cpp +++ b/libretroshare/src/tests/network_simulator/main.cpp @@ -4,7 +4,7 @@ #include "NetworkSimulatorGUI.h" #include "MonitoredRsPeers.h" #include -#include +#include int main(int argc, char *argv[]) { diff --git a/libretroshare/src/tests/network_simulator/network.pro b/libretroshare/src/tests/network_simulator/network.pro index 8f795b0cc..805a756a2 100644 --- a/libretroshare/src/tests/network_simulator/network.pro +++ b/libretroshare/src/tests/network_simulator/network.pro @@ -3,7 +3,7 @@ TEMPLATE = app CONFIG *= qt qglviewer QT *= xml opengl -INCLUDEPATH *= ../.. +INCLUDEPATH *= ../.. .. TARGET = NetworkSim @@ -16,4 +16,4 @@ HEADERS = Network.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \ FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui -LIBS *= ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a ../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 +LIBS *= ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a ../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 -lixml diff --git a/libretroshare/src/tests/pgp/Makefile b/libretroshare/src/tests/pgp/Makefile index 8ad431885..a8a438e04 100644 --- a/libretroshare/src/tests/pgp/Makefile +++ b/libretroshare/src/tests/pgp/Makefile @@ -18,16 +18,16 @@ TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_cer all: tests test_certificate : test_certificate.o - $(CC) $(CFLAGS) -o test_certificate test_certificate.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 + $(CC) $(CFLAGS) -o test_certificate test_certificate.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 test_pgp_handler : test_pgp_handler.o - $(CC) $(CFLAGS) -o test_pgp_handler test_pgp_handler.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 + $(CC) $(CFLAGS) -o test_pgp_handler test_pgp_handler.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 test_pgp_signature_parsing : test_pgp_signature_parsing.o - $(CC) $(CFLAGS) -o test_pgp_signature_parsing test_pgp_signature_parsing.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 + $(CC) $(CFLAGS) -o test_pgp_signature_parsing test_pgp_signature_parsing.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2 test_key_parsing : test_key_parsing.o - $(CC) $(CFLAGS) -o test_key_parsing test_key_parsing.o ../../../../openpgpsdk/src/lib/libops.a -lssl -lcrypto -lbz2 + $(CC) $(CFLAGS) -o test_key_parsing test_key_parsing.o ../../../../openpgpsdk/src/lib/libops.a -lssl -lcrypto -lbz2 ############################################################### include $(RS_TOP_DIR)/scripts/rules.mk diff --git a/libretroshare/src/tests/pgp/argstream.h b/libretroshare/src/tests/pgp/argstream.h deleted file mode 100644 index 137856794..000000000 --- a/libretroshare/src/tests/pgp/argstream.h +++ /dev/null @@ -1,814 +0,0 @@ -/* Copyright (C) 2004 Xavier Décoret -* - * argsteam is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Foobar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Foobar; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef ARGSTREAM_H -#define ARGSTREAM_H - - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - class argstream; - - template - class ValueHolder; - - template - argstream& operator>> (argstream&, const ValueHolder&); - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValueHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValueHolder - { - public: - ValueHolder(char s, - const char* l, - T& b, - const char* desc, - bool mandatory); - ValueHolder(const char* l, - T& b, - const char* desc, - bool mandatory); - ValueHolder(char s, - T& b, - const char* desc, - bool mandatory); - friend argstream& operator>><>(argstream& s,const ValueHolder& v); - std::string name() const; - std::string description() const; - private: - std::string shortName_; - std::string longName_; - T* value_; - T initialValue_; - std::string description_; - bool mandatory_; - }; - template - inline ValueHolder - parameter(char s, - const char* l, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(s,l,b,desc,mandatory); - } - template - inline ValueHolder - parameter(char s, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(s,b,desc,mandatory); - } - template - inline ValueHolder - parameter(const char* l, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(l,b,desc,mandatory); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of OptionHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - class OptionHolder - { - public: - inline OptionHolder(char s, - const char* l, - bool& b, - const char* desc); - inline OptionHolder(const char* l, - bool& b, - const char* desc); - inline OptionHolder(char s, - bool& b, - const char* desc); - friend argstream& operator>>(argstream& s,const OptionHolder& v); - inline std::string name() const; - inline std::string description() const; - protected: - inline OptionHolder(char s, - const char* l, - const char* desc); - friend OptionHolder help(char s='h', - const char* l="help", - const char* desc="Display this help"); - private: - std::string shortName_; - std::string longName_; - bool* value_; - std::string description_; - }; - inline OptionHolder - option(char s, - const char* l, - bool& b, - const char* desc="") - { - return OptionHolder(s,l,b,desc); - } - inline OptionHolder - option(char s, - bool& b, - const char* desc="") - { - return OptionHolder(s,b,desc); - } - inline OptionHolder - option(const char* l, - bool& b, - const char* desc="") - { - return OptionHolder(l,b,desc); - } - inline OptionHolder - help(char s, - const char* l, - const char* desc) - { - return OptionHolder(s,l,desc); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValuesHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValuesHolder - { - public: - ValuesHolder(const O& o, - const char* desc, - int len); - template friend argstream& operator>>(argstream& s,const ValuesHolder& v); - std::string name() const; - std::string description() const; - typedef T value_type; - private: - mutable O value_; - std::string description_; - int len_; - char letter_; - }; - template - inline ValuesHolder - values(const O& o, - const char* desc="", - int len=-1) - { - return ValuesHolder(o,desc,len); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValueParser - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValueParser - { - public: - inline T operator()(const std::string& s) const - { - std::istringstream is(s); - T t; - is>>t; - return t; - } - }; - // We need to specialize for string otherwise parsing of a value that - // contains space (for example a string with space passed in quotes on the - // command line) would parse only the first element of the value!!! - template <> - class ValueParser - { - public: - inline std::string operator()(const std::string& s) const - { - return s; - } - }; - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of argstream - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - class argstream - { - public: - inline argstream(int argc,char** argv); - inline argstream(const char* c); - template - friend argstream& operator>>(argstream& s,const ValueHolder& v); - friend inline argstream& operator>>(argstream& s,const OptionHolder& v); - template - friend argstream& operator>>(argstream& s,const ValuesHolder& v); - - inline bool helpRequested() const; - inline bool isOk() const; - inline std::string errorLog() const; - inline std::string usage() const; - inline void defaultErrorHandling(bool ignoreUnused=false) const; - static inline char uniqueLetter(); - protected: - void parse(int argc,char** argv); - private: - typedef std::list::iterator value_iterator; - typedef std::pair help_entry; - std::string progName_; - std::map options_; - std::list values_; - bool minusActive_; - bool isOk_; - std::deque argHelps_; - std::string cmdLine_; - std::deque errors_; - bool helpRequested_; - }; - //************************************************************ - // Implementation of ValueHolder - //************************************************************ - template - ValueHolder::ValueHolder(char s, - const char* l, - T& v, - const char* desc, - bool mandatory) - : shortName_(1,s), - longName_(l), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - ValueHolder::ValueHolder(const char* l, - T& v, - const char* desc, - bool mandatory) - : longName_(l), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - ValueHolder::ValueHolder(char s, - T& v, - const char* desc, - bool mandatory) - : shortName_(1,s), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - std::string - ValueHolder::name() const - { - std::ostringstream os; - if (!shortName_.empty()) os<<'-'< - std::string - ValueHolder::description() const - { - std::ostringstream os; - os< - //************************************************************ - template - ValuesHolder::ValuesHolder(const O& o, - const char* desc, - int len) - : value_(o), - description_(desc), - len_(len) - { - letter_ = argstream::uniqueLetter(); - } - template - std::string - ValuesHolder::name() const - { - std::ostringstream os; - os< - std::string - ValuesHolder::description() const - { - return description_; - } - //************************************************************ - // Implementation of argstream - //************************************************************ - inline - argstream::argstream(int argc,char** argv) - : progName_(argv[0]), - minusActive_(true), - isOk_(true) - { - parse(argc,argv); - } - inline - argstream::argstream(const char* c) - : progName_(""), - minusActive_(true), - isOk_(true) - { - std::string s(c); - // Build argc, argv from s. We must add a dummy first element for - // progName because parse() expects it!! - std::deque args; - args.push_back(""); - std::istringstream is(s); - while (is.good()) - { - std::string t; - is>>t; - args.push_back(t); - } - char* pargs[args.size()]; - char** p = pargs; - for (std::deque::const_iterator - iter = args.begin(); - iter != args.end();++iter) - { - *p++ = const_cast(iter->c_str()); - } - parse(args.size(),pargs); - } - inline void - argstream::parse(int argc,char** argv) - { - // Run thru all arguments. - // * it has -- in front : it is a long name option, if remainder is empty, - // it is an error - // * it has - in front : it is a sequence of short name options, if - // remainder is empty, deactivates option (- will - // now be considered a char). - // * if any other char, or if option was deactivated - // : it is a value. Values are split in parameters - // (immediately follow an option) and pure values. - // Each time a value is parsed, if the previously parsed argument was an - // option, then the option is linked to the value in case of it is a - // option with parameter. The subtle point is that when several options - // are given with short names (ex: -abc equivalent to -a -b -c), the last - // parsed option is -c). - // Since we use map for option, any successive call overides the previous - // one: foo -a -b -a hello is equivalent to foo -b -a hello - // For values it is not true since we might have several times the same - // value. - value_iterator* lastOption = NULL; - for (char** a = argv,**astop=a+argc;++a!=astop;) - { - std::string s(*a); - if (minusActive_ && s[0] == '-') - { - if (s.size() > 1 && s[1] == '-') - { - if (s.size() == 2) - { - minusActive_ = false; - continue; - } - lastOption = &(options_[s.substr(2)] = values_.end()); - } - else - { - if (s.size() > 1) - { - // Parse all chars, if it is a minus we have an error - for (std::string::const_iterator cter = s.begin(); - ++cter != s.end();) - { - if (*cter == '-') - { - isOk_ = false; - std::ostringstream os; - os<<"- in the middle of a switch "<::const_iterator - iter = options_.begin();iter != options_.end();++iter) - { - std::cout<<"DEBUG: option "<first; - if (iter->second != values_.end()) - { - std::cout<<" -> "<<*(iter->second); - } - std::cout<::const_iterator - iter = values_.begin();iter != values_.end();++iter) - { - std::cout<<"DEBUG: value "<<*iter<::const_iterator - iter = argHelps_.begin();iter != argHelps_.end();++iter) - { - if (lmaxfirst.size()) lmax = iter->first.size(); - } - for (std::deque::const_iterator - iter = argHelps_.begin();iter != argHelps_.end();++iter) - { - os<<'\t'<first<first.size(),' ') - <<" : "<second<<'\n'; - } - return os.str(); - } - inline std::string - argstream::errorLog() const - { - std::string s; - for(std::deque::const_iterator iter = errors_.begin(); - iter != errors_.end();++iter) - { - s += *iter; - s += '\n'; - } - return s; - } - inline char - argstream::uniqueLetter() - { - static unsigned int c = 'a'; - return c++; - } - template - argstream& - operator>>(argstream& s,const ValueHolder& v) - { - // Search in the options if there is any such option defined either with a - // short name or a long name. If both are found, only the last one is - // used. -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: searching "<::iterator iter = - s.options_.find(v.shortName_); - if (iter == s.options_.end()) - { - iter = s.options_.find(v.longName_); - } - if (iter != s.options_.end()) - { - // If we find counterpart for value holder on command line, either it - // has an associated value in which case we assign it, or it has not, in - // which case we have an error. - if (iter->second != s.values_.end()) - { -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: found value "<<*(iter->second)< p; - *(v.value_) = p(*(iter->second)); - // The option and its associated value are removed, the subtle thing - // is that someother options might have this associated value too, - // which we must invalidate. - s.values_.erase(iter->second); - for (std::map::iterator - jter = s.options_.begin();jter != s.options_.end();++jter) - { - if (jter->second == iter->second) - { - jter->second = s.values_.end(); - } - } - s.options_.erase(iter); - } - else - { - s.isOk_ = false; - std::ostringstream os; - os<<"No value following switch "<first - <<" on command line"; - s.errors_.push_back(os.str()); - } - } - else - { - if (v.mandatory_) - { - s.isOk_ = false; - std::ostringstream os; - os<<"Mandatory parameter "; - if (!v.shortName_.empty()) os<<'-'<>(argstream& s,const OptionHolder& v) - { - // Search in the options if there is any such option defined either with a - // short name or a long name. If both are found, only the last one is - // used. -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: searching "<::iterator iter = - s.options_.find(v.shortName_); - if (iter == s.options_.end()) - { - iter = s.options_.find(v.longName_); - } - if (iter != s.options_.end()) - { - // If we find counterpart for value holder on command line then the - // option is true and if an associated value was found, it is ignored - if (v.value_ != NULL) - { - *(v.value_) = true; - } - else - { - s.helpRequested_ = true; - } - // The option only is removed - s.options_.erase(iter); - } - else - { - if (v.value_ != NULL) - { - *(v.value_) = false; - } - else - { - s.helpRequested_ = false; - } - } - return s; - } - template - argstream& - operator>>(argstream& s,const ValuesHolder& v) - { - s.argHelps_.push_back(argstream::help_entry(v.name(),v.description())); - { - std::ostringstream os; - os<<' '<::iterator first = s.values_.begin(); - // We add to the iterator as much values as we can, limited to the length - // specified (if different of -1) - int n = v.len_ != -1?v.len_:s.values_.size(); - while (first != s.values_.end() && n-->0) - { - // Read the value from the string *first - ValueParser p; - *(v.value_++) = p(*first ); - s.argHelps_.push_back(argstream::help_entry(v.name(),v.description())); - // The value we just removed was maybe "remembered" by an option so we - // remove it now. - for (std::map::iterator - jter = s.options_.begin();jter != s.options_.end();++jter) - { - if (jter->second == first) - { - jter->second = s.values_.end(); - } - } - ++first; - } - // Check if we have enough values - if (n != 0) - { - s.isOk_ = false; - std::ostringstream os; - os<<"Expecting "< #include -#include "argstream.h" +#include //#include #include #include diff --git a/libretroshare/src/tests/pgp/test_key_parsing.cc b/libretroshare/src/tests/pgp/test_key_parsing.cc index 5f3ced5f6..8d48d7bc6 100644 --- a/libretroshare/src/tests/pgp/test_key_parsing.cc +++ b/libretroshare/src/tests/pgp/test_key_parsing.cc @@ -10,7 +10,7 @@ extern "C" #include } -#include "argstream.h" +#include int main(int argc,char *argv[]) { diff --git a/libretroshare/src/tests/pgp/test_pgp_handler.cc b/libretroshare/src/tests/pgp/test_pgp_handler.cc index b4e1b001e..922d284b9 100644 --- a/libretroshare/src/tests/pgp/test_pgp_handler.cc +++ b/libretroshare/src/tests/pgp/test_pgp_handler.cc @@ -1,9 +1,10 @@ // COMPILE_LINE: g++ -o test_pgp_handler test_pgp_handler.cc -I../../../openpgpsdk/include -I../ -L../lib -lretroshare ../../../libbitdht/src/lib/libbitdht.a ../../../openpgpsdk/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 // +#include #include #include #include -#include "argstream.h" +#include static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad) { diff --git a/libretroshare/src/tests/pgp/test_pgp_signature_parsing.cc b/libretroshare/src/tests/pgp/test_pgp_signature_parsing.cc index cb0e236d2..83b44bb0a 100644 --- a/libretroshare/src/tests/pgp/test_pgp_signature_parsing.cc +++ b/libretroshare/src/tests/pgp/test_pgp_signature_parsing.cc @@ -1,6 +1,7 @@ // COMPILE_LINE: g++ -o test_pgp_signature_parsing test_pgp_signature_parsing.cc -g -I../../../openpgpsdk/include -I../ -L../lib -lretroshare ../../../libbitdht/src/lib/libbitdht.a ../../../openpgpsdk/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 // #include +#include #include #include diff --git a/libretroshare/src/tests/pqi/Makefile b/libretroshare/src/tests/pqi/Makefile index 7a9b10193..533a07f2b 100644 --- a/libretroshare/src/tests/pqi/Makefile +++ b/libretroshare/src/tests/pqi/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src/ +OPS_TOP_DIR = ../../../../openpgpsdk/src/ ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/printcache/argstream.h b/libretroshare/src/tests/printcache/argstream.h deleted file mode 100644 index 137856794..000000000 --- a/libretroshare/src/tests/printcache/argstream.h +++ /dev/null @@ -1,814 +0,0 @@ -/* Copyright (C) 2004 Xavier Décoret -* - * argsteam is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Foobar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Foobar; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef ARGSTREAM_H -#define ARGSTREAM_H - - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - class argstream; - - template - class ValueHolder; - - template - argstream& operator>> (argstream&, const ValueHolder&); - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValueHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValueHolder - { - public: - ValueHolder(char s, - const char* l, - T& b, - const char* desc, - bool mandatory); - ValueHolder(const char* l, - T& b, - const char* desc, - bool mandatory); - ValueHolder(char s, - T& b, - const char* desc, - bool mandatory); - friend argstream& operator>><>(argstream& s,const ValueHolder& v); - std::string name() const; - std::string description() const; - private: - std::string shortName_; - std::string longName_; - T* value_; - T initialValue_; - std::string description_; - bool mandatory_; - }; - template - inline ValueHolder - parameter(char s, - const char* l, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(s,l,b,desc,mandatory); - } - template - inline ValueHolder - parameter(char s, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(s,b,desc,mandatory); - } - template - inline ValueHolder - parameter(const char* l, - T& b, - const char* desc="", - bool mandatory = true) - { - return ValueHolder(l,b,desc,mandatory); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of OptionHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - class OptionHolder - { - public: - inline OptionHolder(char s, - const char* l, - bool& b, - const char* desc); - inline OptionHolder(const char* l, - bool& b, - const char* desc); - inline OptionHolder(char s, - bool& b, - const char* desc); - friend argstream& operator>>(argstream& s,const OptionHolder& v); - inline std::string name() const; - inline std::string description() const; - protected: - inline OptionHolder(char s, - const char* l, - const char* desc); - friend OptionHolder help(char s='h', - const char* l="help", - const char* desc="Display this help"); - private: - std::string shortName_; - std::string longName_; - bool* value_; - std::string description_; - }; - inline OptionHolder - option(char s, - const char* l, - bool& b, - const char* desc="") - { - return OptionHolder(s,l,b,desc); - } - inline OptionHolder - option(char s, - bool& b, - const char* desc="") - { - return OptionHolder(s,b,desc); - } - inline OptionHolder - option(const char* l, - bool& b, - const char* desc="") - { - return OptionHolder(l,b,desc); - } - inline OptionHolder - help(char s, - const char* l, - const char* desc) - { - return OptionHolder(s,l,desc); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValuesHolder - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValuesHolder - { - public: - ValuesHolder(const O& o, - const char* desc, - int len); - template friend argstream& operator>>(argstream& s,const ValuesHolder& v); - std::string name() const; - std::string description() const; - typedef T value_type; - private: - mutable O value_; - std::string description_; - int len_; - char letter_; - }; - template - inline ValuesHolder - values(const O& o, - const char* desc="", - int len=-1) - { - return ValuesHolder(o,desc,len); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of ValueParser - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - template - class ValueParser - { - public: - inline T operator()(const std::string& s) const - { - std::istringstream is(s); - T t; - is>>t; - return t; - } - }; - // We need to specialize for string otherwise parsing of a value that - // contains space (for example a string with space passed in quotes on the - // command line) would parse only the first element of the value!!! - template <> - class ValueParser - { - public: - inline std::string operator()(const std::string& s) const - { - return s; - } - }; - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Interface of argstream - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - class argstream - { - public: - inline argstream(int argc,char** argv); - inline argstream(const char* c); - template - friend argstream& operator>>(argstream& s,const ValueHolder& v); - friend inline argstream& operator>>(argstream& s,const OptionHolder& v); - template - friend argstream& operator>>(argstream& s,const ValuesHolder& v); - - inline bool helpRequested() const; - inline bool isOk() const; - inline std::string errorLog() const; - inline std::string usage() const; - inline void defaultErrorHandling(bool ignoreUnused=false) const; - static inline char uniqueLetter(); - protected: - void parse(int argc,char** argv); - private: - typedef std::list::iterator value_iterator; - typedef std::pair help_entry; - std::string progName_; - std::map options_; - std::list values_; - bool minusActive_; - bool isOk_; - std::deque argHelps_; - std::string cmdLine_; - std::deque errors_; - bool helpRequested_; - }; - //************************************************************ - // Implementation of ValueHolder - //************************************************************ - template - ValueHolder::ValueHolder(char s, - const char* l, - T& v, - const char* desc, - bool mandatory) - : shortName_(1,s), - longName_(l), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - ValueHolder::ValueHolder(const char* l, - T& v, - const char* desc, - bool mandatory) - : longName_(l), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - ValueHolder::ValueHolder(char s, - T& v, - const char* desc, - bool mandatory) - : shortName_(1,s), - value_(&v), - initialValue_(v), - description_(desc), - mandatory_(mandatory) - { - } - template - std::string - ValueHolder::name() const - { - std::ostringstream os; - if (!shortName_.empty()) os<<'-'< - std::string - ValueHolder::description() const - { - std::ostringstream os; - os< - //************************************************************ - template - ValuesHolder::ValuesHolder(const O& o, - const char* desc, - int len) - : value_(o), - description_(desc), - len_(len) - { - letter_ = argstream::uniqueLetter(); - } - template - std::string - ValuesHolder::name() const - { - std::ostringstream os; - os< - std::string - ValuesHolder::description() const - { - return description_; - } - //************************************************************ - // Implementation of argstream - //************************************************************ - inline - argstream::argstream(int argc,char** argv) - : progName_(argv[0]), - minusActive_(true), - isOk_(true) - { - parse(argc,argv); - } - inline - argstream::argstream(const char* c) - : progName_(""), - minusActive_(true), - isOk_(true) - { - std::string s(c); - // Build argc, argv from s. We must add a dummy first element for - // progName because parse() expects it!! - std::deque args; - args.push_back(""); - std::istringstream is(s); - while (is.good()) - { - std::string t; - is>>t; - args.push_back(t); - } - char* pargs[args.size()]; - char** p = pargs; - for (std::deque::const_iterator - iter = args.begin(); - iter != args.end();++iter) - { - *p++ = const_cast(iter->c_str()); - } - parse(args.size(),pargs); - } - inline void - argstream::parse(int argc,char** argv) - { - // Run thru all arguments. - // * it has -- in front : it is a long name option, if remainder is empty, - // it is an error - // * it has - in front : it is a sequence of short name options, if - // remainder is empty, deactivates option (- will - // now be considered a char). - // * if any other char, or if option was deactivated - // : it is a value. Values are split in parameters - // (immediately follow an option) and pure values. - // Each time a value is parsed, if the previously parsed argument was an - // option, then the option is linked to the value in case of it is a - // option with parameter. The subtle point is that when several options - // are given with short names (ex: -abc equivalent to -a -b -c), the last - // parsed option is -c). - // Since we use map for option, any successive call overides the previous - // one: foo -a -b -a hello is equivalent to foo -b -a hello - // For values it is not true since we might have several times the same - // value. - value_iterator* lastOption = NULL; - for (char** a = argv,**astop=a+argc;++a!=astop;) - { - std::string s(*a); - if (minusActive_ && s[0] == '-') - { - if (s.size() > 1 && s[1] == '-') - { - if (s.size() == 2) - { - minusActive_ = false; - continue; - } - lastOption = &(options_[s.substr(2)] = values_.end()); - } - else - { - if (s.size() > 1) - { - // Parse all chars, if it is a minus we have an error - for (std::string::const_iterator cter = s.begin(); - ++cter != s.end();) - { - if (*cter == '-') - { - isOk_ = false; - std::ostringstream os; - os<<"- in the middle of a switch "<::const_iterator - iter = options_.begin();iter != options_.end();++iter) - { - std::cout<<"DEBUG: option "<first; - if (iter->second != values_.end()) - { - std::cout<<" -> "<<*(iter->second); - } - std::cout<::const_iterator - iter = values_.begin();iter != values_.end();++iter) - { - std::cout<<"DEBUG: value "<<*iter<::const_iterator - iter = argHelps_.begin();iter != argHelps_.end();++iter) - { - if (lmaxfirst.size()) lmax = iter->first.size(); - } - for (std::deque::const_iterator - iter = argHelps_.begin();iter != argHelps_.end();++iter) - { - os<<'\t'<first<first.size(),' ') - <<" : "<second<<'\n'; - } - return os.str(); - } - inline std::string - argstream::errorLog() const - { - std::string s; - for(std::deque::const_iterator iter = errors_.begin(); - iter != errors_.end();++iter) - { - s += *iter; - s += '\n'; - } - return s; - } - inline char - argstream::uniqueLetter() - { - static unsigned int c = 'a'; - return c++; - } - template - argstream& - operator>>(argstream& s,const ValueHolder& v) - { - // Search in the options if there is any such option defined either with a - // short name or a long name. If both are found, only the last one is - // used. -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: searching "<::iterator iter = - s.options_.find(v.shortName_); - if (iter == s.options_.end()) - { - iter = s.options_.find(v.longName_); - } - if (iter != s.options_.end()) - { - // If we find counterpart for value holder on command line, either it - // has an associated value in which case we assign it, or it has not, in - // which case we have an error. - if (iter->second != s.values_.end()) - { -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: found value "<<*(iter->second)< p; - *(v.value_) = p(*(iter->second)); - // The option and its associated value are removed, the subtle thing - // is that someother options might have this associated value too, - // which we must invalidate. - s.values_.erase(iter->second); - for (std::map::iterator - jter = s.options_.begin();jter != s.options_.end();++jter) - { - if (jter->second == iter->second) - { - jter->second = s.values_.end(); - } - } - s.options_.erase(iter); - } - else - { - s.isOk_ = false; - std::ostringstream os; - os<<"No value following switch "<first - <<" on command line"; - s.errors_.push_back(os.str()); - } - } - else - { - if (v.mandatory_) - { - s.isOk_ = false; - std::ostringstream os; - os<<"Mandatory parameter "; - if (!v.shortName_.empty()) os<<'-'<>(argstream& s,const OptionHolder& v) - { - // Search in the options if there is any such option defined either with a - // short name or a long name. If both are found, only the last one is - // used. -#ifdef ARGSTREAM_DEBUG - std::cout<<"DEBUG: searching "<::iterator iter = - s.options_.find(v.shortName_); - if (iter == s.options_.end()) - { - iter = s.options_.find(v.longName_); - } - if (iter != s.options_.end()) - { - // If we find counterpart for value holder on command line then the - // option is true and if an associated value was found, it is ignored - if (v.value_ != NULL) - { - *(v.value_) = true; - } - else - { - s.helpRequested_ = true; - } - // The option only is removed - s.options_.erase(iter); - } - else - { - if (v.value_ != NULL) - { - *(v.value_) = false; - } - else - { - s.helpRequested_ = false; - } - } - return s; - } - template - argstream& - operator>>(argstream& s,const ValuesHolder& v) - { - s.argHelps_.push_back(argstream::help_entry(v.name(),v.description())); - { - std::ostringstream os; - os<<' '<::iterator first = s.values_.begin(); - // We add to the iterator as much values as we can, limited to the length - // specified (if different of -1) - int n = v.len_ != -1?v.len_:s.values_.size(); - while (first != s.values_.end() && n-->0) - { - // Read the value from the string *first - ValueParser p; - *(v.value_++) = p(*first ); - s.argHelps_.push_back(argstream::help_entry(v.name(),v.description())); - // The value we just removed was maybe "remembered" by an option so we - // remove it now. - for (std::map::iterator - jter = s.options_.begin();jter != s.options_.end();++jter) - { - if (jter->second == first) - { - jter->second = s.values_.end(); - } - } - ++first; - } - // Check if we have enough values - if (n != 0) - { - s.isOk_ = false; - std::ostringstream os; - os<<"Expecting "< #include -#include "argstream.h" +#include #include "pqi/pqistreamer.h" #include "pqi/pqibin.h" #include "serialiser/rsdistribitems.h" diff --git a/libretroshare/src/tests/printcache/main_extended.cpp b/libretroshare/src/tests/printcache/main_extended.cpp index 0c77a6348..2cdba7d8d 100644 --- a/libretroshare/src/tests/printcache/main_extended.cpp +++ b/libretroshare/src/tests/printcache/main_extended.cpp @@ -9,7 +9,7 @@ #include #include -#include "argstream.h" +#include #include "pqi/pqistreamer.h" #include "pqi/pqibin.h" #include "serialiser/rsdistribitems.h" diff --git a/libretroshare/src/tests/printcache/printcache.pro b/libretroshare/src/tests/printcache/printcache.pro index 04b19511c..ed61aa4c9 100644 --- a/libretroshare/src/tests/printcache/printcache.pro +++ b/libretroshare/src/tests/printcache/printcache.pro @@ -4,11 +4,12 @@ CONFIG = debug #SOURCES = main.cpp SOURCES = main_extended.cpp -INCLUDEPATH *= ../.. +LIBS += ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a ../../../../openpgpsdk/src/lib/libops.a +LIBS += -lssl -lcrypto -lupnp -lgnome-keyring -lixml -lbz2 + +INCLUDEPATH *= ../.. .. linux { #LIBS = -lstdc++ -lm - LIBS += ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a - LIBS += -lssl -lcrypto -lgpgme -lupnp -lgnome-keyring } macx { # ENABLE THIS OPTION FOR Univeral Binary BUILD. diff --git a/libretroshare/src/tests/scripts/config-linux.mk b/libretroshare/src/tests/scripts/config-linux.mk index 4d6b85893..a71696c7a 100644 --- a/libretroshare/src/tests/scripts/config-linux.mk +++ b/libretroshare/src/tests/scripts/config-linux.mk @@ -22,11 +22,12 @@ RM = /bin/rm RANLIB = ranlib LIBDIR = $(RS_TOP_DIR)/lib BITDIR = $(DHT_TOP_DIR)/lib +OPSDIR = $(OPS_TOP_DIR)/lib LIBRS = $(LIBDIR)/libretroshare.a BITDHT = $(BITDIR)/libbitdht.a # Unix: Linux/Cygwin INCLUDE = -I $(RS_TOP_DIR) -I$(OPENPGP_INCLUDE_DIR) -CFLAGS = -Wall -g $(INCLUDE) +CFLAGS = -Wall -g $(INCLUDE) -I.. #CFLAGS += -fprofile-arcs -ftest-coverage CFLAGS += ${DEFINES} @@ -58,8 +59,11 @@ BIOCFLAGS = -I $(SSL_DIR)/include ${DEFINES} -DOPENSSL_THREADS -D_REENTRANT -DD # OS specific Linking. ######################################################################### -LIBS = -lgpgme -L$(LIBDIR) -lretroshare +LIBS = -L$(LIBDIR) -lretroshare LIBS += -L$(BITDIR) -lbitdht -lgnome-keyring +LIBS += -L$(OPSDIR) -lops +LIBS += -lixml -lbz2 + ifdef PQI_USE_XPGP LIBS += -L$(SSL_DIR) endif diff --git a/libretroshare/src/tests/scripts/config-macosx.mk b/libretroshare/src/tests/scripts/config-macosx.mk index 3f122a3ea..b13a471f0 100644 --- a/libretroshare/src/tests/scripts/config-macosx.mk +++ b/libretroshare/src/tests/scripts/config-macosx.mk @@ -40,6 +40,7 @@ RANLIB = ranlib # Dummy ranlib -> can't do it until afterwards with universal binaries. # RANLIB = ls -l +OPSDIR = $(OPS_TOP_DIR)/lib BITDIR = $(DHT_TOP_DIR)/lib LIBDIR = $(RS_TOP_DIR)/lib LIBRS = $(LIBDIR)/libretroshare.a @@ -83,8 +84,9 @@ LIBS = -Wl,-search_paths_first # LIBS += -arch ppc -arch i386 #LIBS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5u.sdk -LIBS = -lgpgme -L$(LIBDIR) -lretroshare +LIBS = -L$(LIBDIR) -lretroshare LIBS += -L$(BITDIR) -lbitdht +LIBS += -L$(OPSDIR) -lops ifdef PQI_USE_XPGP LIBS += -L$(SSL_DIR) endif diff --git a/libretroshare/src/tests/serialiser/Makefile b/libretroshare/src/tests/serialiser/Makefile index 062543b2b..6206bf2ad 100644 --- a/libretroshare/src/tests/serialiser/Makefile +++ b/libretroshare/src/tests/serialiser/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/services/Makefile b/libretroshare/src/tests/services/Makefile index a0170e6c1..a57378ba4 100644 --- a/libretroshare/src/tests/services/Makefile +++ b/libretroshare/src/tests/services/Makefile @@ -1,6 +1,8 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src + ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/tcponudp/Makefile b/libretroshare/src/tests/tcponudp/Makefile index 9d71743b7..aa8835e9b 100644 --- a/libretroshare/src/tests/tcponudp/Makefile +++ b/libretroshare/src/tests/tcponudp/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/util/Makefile b/libretroshare/src/tests/util/Makefile index 9f1aa27da..f4fb514b6 100644 --- a/libretroshare/src/tests/util/Makefile +++ b/libretroshare/src/tests/util/Makefile @@ -1,6 +1,7 @@ RS_TOP_DIR = ../.. DHT_TOP_DIR = ../../../../libbitdht/src +OPS_TOP_DIR = ../../../../openpgpsdk/src ##### Define any flags that are needed for this section ####### ############################################################### diff --git a/libretroshare/src/tests/util/dirtest.cc b/libretroshare/src/tests/util/dirtest.cc index b2cbd4d3a..b8857b71b 100644 --- a/libretroshare/src/tests/util/dirtest.cc +++ b/libretroshare/src/tests/util/dirtest.cc @@ -74,7 +74,8 @@ bool testRsDirUtils(std::string path) std::string root = RsDirUtil::getRootDir(path); std::string topdirs = RsDirUtil::removeRootDir(path); std::string topdirs2 = RsDirUtil::removeRootDirs(path, root); - std::string restdirs = RsDirUtil::removeTopDir(path); + std::string restdirs ; + RsDirUtil::removeTopDir(path,restdirs); std::list split; std::list::iterator it; RsDirUtil::breakupDirList(path, split);