mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Removed some std::ostringstream.
To be continued. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5105 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
470951d664
commit
33f4d4f2b8
@ -34,7 +34,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <sstream> // for std::istringstream
|
||||
#include <iomanip>
|
||||
|
||||
#include <dirent.h>
|
||||
@ -915,10 +915,10 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& 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)))
|
||||
{
|
||||
|
@ -25,12 +25,13 @@
|
||||
#include "dbase/findex.h"
|
||||
#include "retroshare/rsexpr.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <sstream> // for std::stringstream
|
||||
#include <tr1/unordered_set>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
@ -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<std::string, DirEntry *>::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<std::string, DirEntry *>::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<std::string, FileEntry *>::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<std::string, DirEntry *>::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;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,6 @@
|
||||
#include <stdint.h>
|
||||
#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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <serialiser/rsserial.h>
|
||||
#include <serialiser/rsconfigitems.h>
|
||||
|
||||
#include <sstream> // 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 ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user