diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 5c50ca42a..0f5f0d39a 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -34,7 +34,7 @@ #include #include -#include +#include // for std::istringstream #include #include @@ -915,10 +915,10 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) // rather send a completion ratio based on the size of files vs/ total size. // FileEntry fe(to_hash[i].fentries[j]) ; // copied, because hashFile updates the hash member - std::ostringstream tmpout; - tmpout << cnt+1 << "/" << n_files << " (" << friendlyUnit(size) << " - " << int(size/double(total_size)*100.0) << "%) : " << fe.name ; + std::string tmpout; + rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", cnt+1, n_files, friendlyUnit(size).c_str(), int(size/double(total_size)*100.0), fe.name.c_str()) ; - cb->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout.str()) ; + cb->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ; std::string real_path = RsDirUtil::makePath(to_hash[i].realpath, fe.name); @@ -991,14 +991,12 @@ void FileIndexMonitor::locked_saveFileIndexes() // Two files are saved: one with only browsable dirs, which will be shared by the cache system, // and one with the complete file collection. // - std::ostringstream out; - out << "fc-own-" << time(NULL) << ".rsfb"; - std::string tmpname_browsable = out.str(); + std::string tmpname_browsable; + rs_sprintf(tmpname_browsable, "fc-own-%ld.rsfb", time(NULL)); std::string fname_browsable = path + "/" + tmpname_browsable; - std::ostringstream out2; - out2 << "fc-own-" << time(NULL) << ".rsfc"; - std::string tmpname_total = out2.str(); + std::string tmpname_total; + rs_sprintf(tmpname_total, "fc-own-%ld.rsfc", time(NULL)); std::string fname_total = path + "/" + tmpname_total; #ifdef FIM_DEBUG @@ -1232,9 +1230,7 @@ bool FileIndexMonitor::internal_setSharedDirectories() std::string tst_dir = top_dir; if (i > 0) { - std::ostringstream out; - out << "-" << i; - tst_dir += out.str(); + rs_sprintf_append(tst_dir, "-%d", i); } if (directoryMap.end()== (cit=directoryMap.find(tst_dir))) { diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 25c3b3d08..01fe93aca 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -25,12 +25,13 @@ #include "dbase/findex.h" #include "retroshare/rsexpr.h" #include "util/rsdir.h" +#include "util/rsstring.h" #include #include #include #include -#include +#include // for std::stringstream #include #include #include @@ -476,34 +477,27 @@ FileEntry *DirEntry::updateFile(const FileEntry& fe, time_t utime) } -int FileEntry::print(std::ostream &out) +int FileEntry::print(std::string &out) { /* print this dir, then subdirs, then files */ - out << "file "; - out << std::setw(3) << std::setfill('0') << row; - out << " [" << updtime << "/" << modtime << "] : "; + rs_sprintf_append(out, "file %03d [%ld/%ld] : ", row, updtime, modtime); if (parent) - out << parent->path; + out += parent->path; else - out << "[MISSING PARENT]"; + out += "[MISSING PARENT]"; + + rs_sprintf_append(out, " %s [ s: %lld ] ==> [ %s ]\n", name.c_str(), size, hash.c_str()); - out << " " << name; - out << " [ s: " << size << " ] ==> "; - out << " [ " << hash << " ]"; - out << std::endl; return 1; } -int DirEntry::print(std::ostream &out) +int DirEntry::print(std::string &out) { /* print this dir, then subdirs, then files */ - out << "dir "; - out << std::setw(3) << std::setfill('0') << row; - out << " [" << updtime << "] : " << path; - out << std::endl; + rs_sprintf_append(out, "dir %03d [%ld] : %s\n", row, updtime, path.c_str()); std::map::iterator it; for(it = subdirs.begin(); it != subdirs.end(); it++) @@ -710,9 +704,9 @@ int FileIndex::cleanOldEntries(time_t old) /* removes entries older than old */ -int FileIndex::printFileIndex(std::ostream &out) +int FileIndex::printFileIndex(std::string &out) { - out << "FileIndex::printFileIndex()" << std::endl; + out += "FileIndex::printFileIndex()\n"; root->print(out); return 1; } @@ -747,13 +741,13 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte SHA1_Final(&sha_buf[0], sha_ctx); delete sha_ctx; - std::ostringstream tmpout; + std::string tmpout; for(int i = 0; i < SHA_DIGEST_LENGTH; i++) { - tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]); + rs_sprintf_append(tmpout, "%02x", (unsigned int) (sha_buf[i])); } - if (expectedHash != "" && expectedHash != tmpout.str()) + if (expectedHash != "" && expectedHash != tmpout) { #ifdef FI_DEBUG std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl; @@ -923,19 +917,19 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin { unsigned char sha_buf[SHA_DIGEST_LENGTH]; std::string filenametmp = filename + ".tmp" ; - std::ostringstream oss; + std::string s; size = 0 ; fileHash = "" ; /* print version and header */ - oss << "# FileIndex version 0.1" << std::endl; - oss << "# Dir: d name, path, parent, size, modtime, pop, updtime;" << std::endl; - oss << "# File: f name, hash, size, modtime, pop, updtime;" << std::endl; - oss << "#" << std::endl; + s += "# FileIndex version 0.1\n"; + s += "# Dir: d name, path, parent, size, modtime, pop, updtime;\n"; + s += "# File: f name, hash, size, modtime, pop, updtime;\n"; + s += "#\n"; /* begin recusion */ - root->writeDirInfo(oss) ; + root->writeDirInfo(s) ; std::map::iterator it; for(it = root->subdirs.begin(); it != root->subdirs.end(); it++) @@ -954,28 +948,26 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin #ifdef FI_DEBUG std::cerr << " will be saved." << std::endl ; #endif - (it->second)->saveEntry(oss); + (it->second)->saveEntry(s); } } - root->writeFileInfo(oss) ; // this should never do anything + root->writeFileInfo(s) ; // this should never do anything /* signal to pop directory from stack in loadIndex() */ - oss << "-" << std::endl; + s += "-\n"; /* calculate sha1 hash */ SHA_CTX *sha_ctx = new SHA_CTX; SHA1_Init(sha_ctx); - SHA1_Update(sha_ctx, oss.str().c_str(), oss.str().length()); + SHA1_Update(sha_ctx, s.c_str(), s.length()); SHA1_Final(&sha_buf[0], sha_ctx); delete sha_ctx; - std::ostringstream tmpout; for(int i = 0; i < SHA_DIGEST_LENGTH; i++) { - tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]); + rs_sprintf_append(fileHash, "%02x", (unsigned int) (sha_buf[i])); } - fileHash = tmpout.str(); /* finally, save to file */ @@ -985,7 +977,7 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin std::cerr << "FileIndex::saveIndex error opening file for writting: " << filename << ". Giving up." << std::endl; return 0; } - fprintf(file,"%s",oss.str().c_str()) ; + fprintf(file,"%s",s.c_str()) ; fclose(file); @@ -1023,49 +1015,49 @@ std::string FixName(const std::string& _in) return in; } -void DirEntry::writeDirInfo(std::ostringstream& oss) +void DirEntry::writeDirInfo(std::string& s) { /* print node info */ - oss << "d"; - oss << FixName(name) << FILE_CACHE_SEPARATOR_CHAR ; - oss << FixName(path) << FILE_CACHE_SEPARATOR_CHAR ; - oss << size << FILE_CACHE_SEPARATOR_CHAR ; - oss << modtime << FILE_CACHE_SEPARATOR_CHAR ; - oss << pop << FILE_CACHE_SEPARATOR_CHAR ; - oss << updtime << FILE_CACHE_SEPARATOR_CHAR << std::endl; + rs_sprintf_append(s, "d%s%c%s%c%lld%c%ld%c%d%c%ld%c\n", + FixName(name).c_str(), FILE_CACHE_SEPARATOR_CHAR, + FixName(path).c_str(), FILE_CACHE_SEPARATOR_CHAR, + size, FILE_CACHE_SEPARATOR_CHAR, + modtime, FILE_CACHE_SEPARATOR_CHAR, + pop, FILE_CACHE_SEPARATOR_CHAR, + updtime, FILE_CACHE_SEPARATOR_CHAR); } -void DirEntry::writeFileInfo(std::ostringstream& oss) +void DirEntry::writeFileInfo(std::string& s) { /* print file info */ std::map::iterator fit; for(fit = files.begin(); fit != files.end(); fit++) { - oss << "f"; - oss << FixName((fit->second)->name) << FILE_CACHE_SEPARATOR_CHAR ; - oss << (fit->second)->hash << FILE_CACHE_SEPARATOR_CHAR ; - oss << (fit->second)->size << FILE_CACHE_SEPARATOR_CHAR ; - oss << (fit->second)->modtime << FILE_CACHE_SEPARATOR_CHAR ; - oss << (fit->second)->pop << FILE_CACHE_SEPARATOR_CHAR ; - oss << (fit->second)->updtime << FILE_CACHE_SEPARATOR_CHAR << std::endl; + rs_sprintf_append(s, "f%s%c%s%c%lld%c%ld%c%d%c%ld%c\n", + FixName((fit->second)->name).c_str(), FILE_CACHE_SEPARATOR_CHAR, + (fit->second)->hash.c_str(), FILE_CACHE_SEPARATOR_CHAR, + (fit->second)->size, FILE_CACHE_SEPARATOR_CHAR, + (fit->second)->modtime, FILE_CACHE_SEPARATOR_CHAR, + (fit->second)->pop, FILE_CACHE_SEPARATOR_CHAR, + (fit->second)->updtime, FILE_CACHE_SEPARATOR_CHAR); } } /* recusive function for traversing the dir tree in preorder */ -int DirEntry::saveEntry(std::ostringstream &oss) +int DirEntry::saveEntry(std::string &s) { - writeDirInfo(oss) ; + writeDirInfo(s) ; std::map::iterator it; for(it = subdirs.begin(); it != subdirs.end(); it++) { - (it->second)->saveEntry(oss); + (it->second)->saveEntry(s); } - writeFileInfo(oss) ; + writeFileInfo(s) ; /* signal to pop directory from stack in loadIndex() */ - oss << "-" << std::endl; + s += "-\n"; return 1; } diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index f8830ce3c..5e2f32980 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -33,8 +33,6 @@ #include #include "retroshare/rstypes.h" -class ostream; - /****************************************************************************************** * The Key Data Types for the File Index: @@ -89,7 +87,7 @@ class FileEntry: public RsMemoryManagement::SmallObject virtual ~FileEntry() { return; } virtual uint32_t type() const { return DIR_TYPE_FILE ; } -virtual int print(std::ostream &out); +virtual int print(std::string &out); /* Data */ std::string name; @@ -142,11 +140,11 @@ DirEntry * findDirectory(const std::string& path); int updateDirectories(const std::string& path, int pop, int modtime); /* output */ -int print(std::ostream &out); +int print(std::string &out); -int saveEntry(std::ostringstream &out); -void writeDirInfo(std::ostringstream&); -void writeFileInfo(std::ostringstream&); +int saveEntry(std::string &out); +void writeDirInfo(std::string&); +void writeFileInfo(std::string&); /* Data */ std::string path; /* full path (includes name) */ @@ -227,7 +225,7 @@ class FileIndex int cleanOldEntries(time_t old); /* removes entries older than old */ /* debug */ - int printFileIndex(std::ostream &out); + int printFileIndex(std::string &out); /* load/save to file */ int loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size); diff --git a/plugins/LinksCloud/p3ranking.cc b/plugins/LinksCloud/p3ranking.cc index 0a49c8dae..805702880 100644 --- a/plugins/LinksCloud/p3ranking.cc +++ b/plugins/LinksCloud/p3ranking.cc @@ -218,7 +218,6 @@ void p3Ranking::publishMsgs(bool own) #endif std::string path = CacheSource::getCacheDir(); - std::ostringstream out; uint16_t subid; @@ -226,21 +225,21 @@ void p3Ranking::publishMsgs(bool own) * publishing own or friends... */ + /* determine filename */ + std::string tmpname; if (own) { /* setup to publish own messages */ - out << "rank-links-" << time(NULL) << ".rsrl"; + rs_sprintf(tmpname, "rank-links-%ld.rsrl", time(NULL)); subid = 1; } else { /* setup to publish friend messages */ - out << "rank-friend-links-" << time(NULL) << ".rsrl"; + rs_sprintf(tmpname, "rank-friend-links-%ld.rsrl", time(NULL)); subid = 2; } - /* determine filename */ - std::string tmpname = out.str(); std::string fname = path + "/" + tmpname; #ifdef RANK_DEBUG @@ -1100,29 +1099,26 @@ pqistore *createStore(std::string file, std::string src, bool reading) std::string generateRandomLinkId() { - std::ostringstream out; - out << std::hex; + std::string out; /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS /* 4 bytes per random number: 4 x 4 = 16 bytes */ for(int i = 0; i < 4; i++) { - out << std::setw(8) << std::setfill('0'); uint32_t rint = random(); - out << rint; + rs_sprintf_append(out, "%08x", rint); } #else srand(time(NULL)); /* 2 bytes per random number: 8 x 2 = 16 bytes */ for(int i = 0; i < 8; i++) { - out << std::setw(4) << std::setfill('0'); uint16_t rint = rand(); /* only gives 16 bits */ - out << rint; + rs_sprintf_append(out, "%04x", rint); } #endif /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - return out.str(); + return out; } diff --git a/plugins/VOIP/services/p3vors.cc b/plugins/VOIP/services/p3vors.cc index 1e037cd6c..c4c83a377 100644 --- a/plugins/VOIP/services/p3vors.cc +++ b/plugins/VOIP/services/p3vors.cc @@ -32,6 +32,7 @@ #include #include +#include // for std::istringstream #include "services/p3vors.h" #include "services/rsvoipitems.h" @@ -643,9 +644,7 @@ RsTlvKeyValue p3VoRS::push_int_value(const std::string& key,int value) { RsTlvKeyValue kv ; kv.key = key ; - std::ostringstream s ; - s << value; - kv.value = s.str() ; + rs_sprintf(kv.value, "%d", value); return kv ; }