mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
Removed some std::ostringstream.
To be continued. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5104 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
83bd45caa4
commit
470951d664
@ -35,7 +35,6 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include "retroshare/rsdistrib.h"
|
||||
@ -1130,10 +1129,9 @@ void p3GroupDistrib::locked_publishPendingMsgs()
|
||||
|
||||
/* create filename */
|
||||
std::string path = CacheSource::getCacheDir();
|
||||
std::ostringstream out;
|
||||
out << "grpdist-t" << CacheSource::getCacheType() << "-msgs-" << time(NULL) << ".dist";
|
||||
|
||||
std::string tmpname = out.str();
|
||||
std::string tmpname;
|
||||
rs_sprintf(tmpname, "grpdist-t%u-msgs-%ld.dist", CacheSource::getCacheType(), time(NULL));
|
||||
std::string filename = path + "/" + tmpname ;
|
||||
std::string filenametmp = path + "/" + tmpname + ".tmp";
|
||||
|
||||
@ -1183,14 +1181,14 @@ void p3GroupDistrib::locked_publishPendingMsgs()
|
||||
|
||||
if(!RsDirUtil::renameFile(filenametmp,filename))
|
||||
{
|
||||
std::ostringstream errlog;
|
||||
std::string errlog;
|
||||
ok &= false;
|
||||
#ifdef WIN32
|
||||
errlog << "Error " << GetLastError() ;
|
||||
rs_sprintf(errlog, "Error %u", GetLastError());
|
||||
#else
|
||||
errlog << "Error " << errno ;
|
||||
rs_sprintf(errlog, "Error %d", errno);
|
||||
#endif
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error "+errlog.str());
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error " + errlog);
|
||||
}
|
||||
|
||||
/* indicate not to save for a while */
|
||||
@ -1230,10 +1228,9 @@ void p3GroupDistrib::publishDistribGroups()
|
||||
|
||||
/* create filename */
|
||||
std::string path = CacheSource::getCacheDir();
|
||||
std::ostringstream out;
|
||||
out << "grpdist-t" << CacheSource::getCacheType() << "-grps-" << time(NULL) << ".dist";
|
||||
|
||||
std::string tmpname = out.str();
|
||||
std::string tmpname;
|
||||
rs_sprintf(tmpname, "grpdist-t%u-grps-%ld.dist", CacheSource::getCacheType(), time(NULL));
|
||||
std::string filename = path + "/" + tmpname;
|
||||
std::string filenametmp = path + "/" + tmpname + ".tmp";
|
||||
std::string tempPeerId; // to store actual id temporarily
|
||||
@ -1333,13 +1330,13 @@ void p3GroupDistrib::publishDistribGroups()
|
||||
|
||||
if(!RsDirUtil::renameFile(filenametmp,filename))
|
||||
{
|
||||
std::ostringstream errlog;
|
||||
std::string errlog;
|
||||
#ifdef WIN32
|
||||
errlog << "Error " << GetLastError() ;
|
||||
rs_sprintf(errlog, "Error %u", GetLastError());
|
||||
#else
|
||||
errlog << "Error " << errno ;
|
||||
rs_sprintf(errlog, "Error %d", errno);
|
||||
#endif
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error "+errlog.str());
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error " + errlog);
|
||||
}
|
||||
|
||||
/* push file to CacheSource */
|
||||
@ -2155,13 +2152,13 @@ bool p3GroupDistrib::backUpKeys(const std::list<RsDistribGrpKey* >& keysToBackUp
|
||||
|
||||
if(!RsDirUtil::renameFile(filenametmp,filename))
|
||||
{
|
||||
std::ostringstream errlog;
|
||||
std::string errlog;
|
||||
#ifdef WIN32
|
||||
errlog << "Error " << GetLastError() ;
|
||||
rs_sprintf(errlog, "Error %u", GetLastError());
|
||||
#else
|
||||
errlog << "Error " << errno ;
|
||||
rs_sprintf(errlog, "Error %d", errno);
|
||||
#endif
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error "+errlog.str());
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + filename + ": got error " + errlog);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
||||
#include "retroshare/rsdistrib.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
p3DistribSecurity::p3DistribSecurity()
|
||||
{
|
||||
}
|
||||
@ -203,15 +201,13 @@ std::string p3DistribSecurity::getBinDataSign(void *data, int len)
|
||||
len = CERTSIGNLEN;
|
||||
}
|
||||
|
||||
std::ostringstream id;
|
||||
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
id << std::hex << std::setw(2) << std::setfill('0')
|
||||
<< (uint16_t) (((uint8_t *) (tmp))[i]);
|
||||
std::string id;
|
||||
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
rs_sprintf(id, "%02x", (uint16_t) (((uint8_t *) (tmp))[i]));
|
||||
}
|
||||
std::string Id = id.str();
|
||||
|
||||
return Id;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@ -364,15 +360,13 @@ std::string p3DistribSecurity::getRsaKeySign(RSA *pubkey)
|
||||
len = CERTSIGNLEN;
|
||||
}
|
||||
|
||||
std::ostringstream id;
|
||||
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
id << std::hex << std::setw(2) << std::setfill('0')
|
||||
<< (uint16_t) (((uint8_t *) (tmp))[i]);
|
||||
std::string id;
|
||||
for(uint32_t i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
rs_sprintf(id, "%02x", (uint16_t) (((uint8_t *) (tmp))[i]));
|
||||
}
|
||||
std::string rsaId = id.str();
|
||||
|
||||
return rsaId;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "retroshare/rsplugin.h"
|
||||
|
||||
#include "tcponudp/tou.h"
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
@ -258,15 +257,12 @@ void RsServer::run()
|
||||
double cycleTime = endCycleTs - ts;
|
||||
if (cycleTime > WARN_BIG_CYCLE_TIME)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "RsServer::run() WARNING Excessively Long Cycle Time: " << cycleTime;
|
||||
out << " secs => Please DEBUG";
|
||||
std::cerr << out.str() << std::endl;
|
||||
std::string out;
|
||||
rs_sprintf(out, "RsServer::run() WARNING Excessively Long Cycle Time: %g secs => Please DEBUG", cycleTime);
|
||||
std::cerr << out << std::endl;
|
||||
|
||||
rslog(RSL_ALERT, rsserverzone, out.str());
|
||||
rslog(RSL_ALERT, rsserverzone, out);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <sstream> // for std::istringstream
|
||||
|
||||
#include <gpgme.h>
|
||||
|
||||
@ -60,7 +60,7 @@ RsPeers *rsPeers = NULL;
|
||||
* #define P3PEERS_DEBUG 1
|
||||
*******/
|
||||
|
||||
int ensureExtension(std::string &name, std::string def_ext);
|
||||
//int ensureExtension(std::string &name, std::string def_ext);
|
||||
|
||||
std::string RsPeerTrustString(uint32_t trustLvl)
|
||||
{
|
||||
@ -119,14 +119,6 @@ std::string RsPeerNetModeString(uint32_t netModel)
|
||||
}
|
||||
|
||||
|
||||
std::string RsPeerLastConnectString(uint32_t lastConnect)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << lastConnect << " secs ago";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
p3Peers::p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm)
|
||||
:mLinkMgr(lm), mPeerMgr(pm), mNetMgr(nm)
|
||||
{
|
||||
@ -305,16 +297,16 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("L:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("E:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
}
|
||||
|
||||
|
||||
@ -388,16 +380,10 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_TUNNEL;
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_TCP;
|
||||
|
||||
std::ostringstream str;
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
rs_sprintf(d.connectStateString, "%s:%u", rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr).c_str(), ntohs(pcs.currentConnAddrAttempt.addr.sin_port));
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_UDP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_UDP;
|
||||
|
||||
std::ostringstream str;
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
rs_sprintf(d.connectStateString, "%s:%u", rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr).c_str(), ntohs(pcs.currentConnAddrAttempt.addr.sin_port));
|
||||
}
|
||||
}
|
||||
else if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
@ -477,14 +463,14 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
std::ostringstream toto; // please do not use std::ostringstream
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
std::ostringstream toto; // please do not use std::ostringstream
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
}
|
||||
@ -575,13 +561,13 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_TCP;
|
||||
|
||||
std::ostringstream str;
|
||||
std::ostringstream str; // please do not use std::ostringstream
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_UDP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_UDP;
|
||||
|
||||
std::ostringstream str;
|
||||
std::ostringstream str; // please do not use std::ostringstream
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
}
|
||||
@ -1040,13 +1026,9 @@ p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_signatures)
|
||||
invite += CERT_SSL_ID + Detail.id + ";";
|
||||
invite += CERT_LOCATION + Detail.location + ";\n";
|
||||
invite += CERT_LOCAL_IP + Detail.localAddr + ":";
|
||||
std::ostringstream out;
|
||||
out << Detail.localPort;
|
||||
invite += out.str() + ";";
|
||||
rs_sprintf_append(invite, "%u;", Detail.localPort);
|
||||
invite += CERT_EXT_IP + Detail.extAddr + ":";
|
||||
std::ostringstream out2;
|
||||
out2 << Detail.extPort;
|
||||
invite += out2.str() + ";";
|
||||
rs_sprintf_append(invite, "%u;", Detail.extPort);
|
||||
if (!Detail.dyndns.empty()) {
|
||||
invite += "\n" + CERT_DYNDNS + Detail.dyndns + ";";
|
||||
}
|
||||
@ -1348,38 +1330,36 @@ bool p3Peers::trustGPGCertificate(const std::string &id, uint32_t trustlvl)
|
||||
}
|
||||
|
||||
|
||||
int ensureExtension(std::string &name, std::string def_ext)
|
||||
{
|
||||
/* if it has an extension, don't change */
|
||||
int len = name.length();
|
||||
int extpos = name.find_last_of('.');
|
||||
//int ensureExtension(std::string &name, std::string def_ext)
|
||||
//{
|
||||
// /* if it has an extension, don't change */
|
||||
// int len = name.length();
|
||||
// int extpos = name.find_last_of('.');
|
||||
|
||||
std::ostringstream out;
|
||||
out << "ensureExtension() name: " << name << std::endl;
|
||||
out << "\t\t extpos: " << extpos;
|
||||
out << " len: " << len << std::endl;
|
||||
// std::string out;
|
||||
// rs_sprintf_append(out, "ensureExtension() name: %s\n\t\t extpos: %d len: \n", name.c_str(), extpos, len);
|
||||
|
||||
/* check that the '.' has between 1 and 4 char after it (an extension) */
|
||||
if ((extpos > 0) && (extpos < len - 1) && (extpos + 6 > len))
|
||||
{
|
||||
/* extension there */
|
||||
std::string curext = name.substr(extpos, len);
|
||||
out << "ensureExtension() curext: " << curext << std::endl;
|
||||
std::cerr << out.str();
|
||||
return 0;
|
||||
}
|
||||
// /* check that the '.' has between 1 and 4 char after it (an extension) */
|
||||
// if ((extpos > 0) && (extpos < len - 1) && (extpos + 6 > len))
|
||||
// {
|
||||
// /* extension there */
|
||||
// std::string curext = name.substr(extpos, len);
|
||||
// out += "ensureExtension() curext: " + curext;
|
||||
// std::cerr << out << std::endl;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
if (extpos != len - 1)
|
||||
{
|
||||
name += ".";
|
||||
}
|
||||
name += def_ext;
|
||||
// if (extpos != len - 1)
|
||||
// {
|
||||
// name += ".";
|
||||
// }
|
||||
// name += def_ext;
|
||||
|
||||
out << "ensureExtension() added ext: " << name << std::endl;
|
||||
// out += "ensureExtension() added ext: " + name;
|
||||
|
||||
std::cerr << out.str();
|
||||
return 1;
|
||||
}
|
||||
// std::cerr << out << std::endl;
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
/* Group Stuff */
|
||||
bool p3Peers::addGroup(RsGroupInfo &groupInfo)
|
||||
|
@ -572,9 +572,7 @@ bool p3turtle::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "TURTLE_CONFIG_MAX_TR_RATE" ;
|
||||
|
||||
std::ostringstream s ;
|
||||
s << _max_tr_up_rate;
|
||||
kv.value = s.str() ;
|
||||
rs_sprintf(kv.value, "%g", _max_tr_up_rate);
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
lst.push_back(vitem) ;
|
||||
@ -2270,8 +2268,6 @@ bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info)
|
||||
|
||||
static std::string printFloatNumber(float num,bool friendly=false)
|
||||
{
|
||||
std::ostringstream out ;
|
||||
|
||||
if(friendly)
|
||||
{
|
||||
char tmp[100] ;
|
||||
@ -2286,8 +2282,9 @@ static std::string printFloatNumber(float num,bool friendly=false)
|
||||
}
|
||||
else
|
||||
{
|
||||
out << num ;
|
||||
return out.str() ;
|
||||
std::string out ;
|
||||
rs_sprintf(out, "%g", num) ;
|
||||
return out ;
|
||||
}
|
||||
}
|
||||
static std::string printNumber(uint64_t num,bool hex=false)
|
||||
@ -2304,9 +2301,9 @@ static std::string printNumber(uint64_t num,bool hex=false)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream out ;
|
||||
out << num ;
|
||||
return out.str() ;
|
||||
std::string out ;
|
||||
rs_sprintf(out, "%lld", num) ;
|
||||
return out ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "extaddrfinder.h"
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <netdb.h>
|
||||
@ -8,7 +9,6 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
@ -43,9 +43,9 @@ static std::string scan_ip(const std::string& text)
|
||||
|
||||
if(a < 256 && b<256 && c<256 && d<256)
|
||||
{
|
||||
std::ostringstream o ;
|
||||
o << a << "." << b << "." << c << "." << d ;
|
||||
return o.str();
|
||||
std::string s ;
|
||||
rs_sprintf(s, "%u.%u.%u.%u", a, b, c, d) ;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return "" ;
|
||||
|
@ -30,17 +30,16 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "rsthreads.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
@ -665,13 +664,13 @@ bool Sha1CheckSum::operator==(const Sha1CheckSum& s) const
|
||||
|
||||
std::string Sha1CheckSum::toStdString() const
|
||||
{
|
||||
std::ostringstream tmpout;
|
||||
std::string tmpout;
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
for(int j = 0; j < 4; j++)
|
||||
tmpout << std::setw(2) << std::setfill('0') << std::hex << ((fourbytes[i] >> (8*j)) & 0xff ) ;
|
||||
|
||||
return tmpout.str() ;
|
||||
rs_sprintf_append(tmpout, "%02x", ((fourbytes[i] >> (8*j)) & 0xff ));
|
||||
|
||||
return tmpout;
|
||||
}
|
||||
|
||||
Sha1CheckSum::Sha1CheckSum(const uint8_t *buf)
|
||||
@ -767,7 +766,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
|
||||
// search last backup
|
||||
int nLast;
|
||||
for (nLast = nCount; nLast >= 1; nLast--) {
|
||||
std::ostringstream sStream;
|
||||
std::ostringstream sStream; // please do not use std::ostringstream
|
||||
sStream << sFilename << nLast << ".bak";
|
||||
|
||||
if (GetFileAttributesA (sStream.str ().c_str ()) != -1) {
|
||||
@ -777,7 +776,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
|
||||
|
||||
// delete max backup
|
||||
if (nLast == nCount) {
|
||||
std::ostringstream sStream;
|
||||
std::ostringstream sStream; // please do not use std::ostringstream
|
||||
sStream << sFilename << nCount << ".bak";
|
||||
if (DeleteFileA (sStream.str ().c_str ()) == FALSE) {
|
||||
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File delete error", "Error while deleting file " + sStream.str ());
|
||||
@ -788,9 +787,9 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
|
||||
|
||||
// rename backups
|
||||
for (int nIndex = nLast; nIndex >= 1; nIndex--) {
|
||||
std::ostringstream sStream;
|
||||
std::ostringstream sStream; // please do not use std::ostringstream
|
||||
sStream << sFilename << nIndex << ".bak";
|
||||
std::ostringstream sStream1;
|
||||
std::ostringstream sStream1; // please do not use std::ostringstream
|
||||
sStream1 << sFilename << nIndex + 1 << ".bak";
|
||||
|
||||
if (renameFile (sStream.str (), sStream1.str ()) == false) {
|
||||
@ -800,7 +799,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
|
||||
}
|
||||
|
||||
// copy backup
|
||||
std::ostringstream sStream;
|
||||
std::ostringstream sStream; // please do not use std::ostringstream
|
||||
sStream << sFilename << 1 << ".bak";
|
||||
if (CopyFileA (sFilename.c_str (), sStream.str ().c_str (), FALSE) == FALSE) {
|
||||
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + sFilename + " to " + sStream.str ());
|
||||
@ -1201,7 +1200,7 @@ bool RsDirUtil::getWideFileHash(std::wstring filepath,
|
||||
|
||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
||||
|
||||
std::ostringstream tmpout;
|
||||
std::ostringstream tmpout; // please do not use std::ostringstream
|
||||
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
||||
{
|
||||
tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]);
|
||||
|
@ -25,8 +25,7 @@
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#else
|
||||
@ -141,12 +140,8 @@ std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr)
|
||||
|
||||
std::string rs_inet_ntoa(struct in_addr in)
|
||||
{
|
||||
std::ostringstream str;
|
||||
std::string str;
|
||||
uint8_t *bytes = (uint8_t *) &(in.s_addr);
|
||||
str << (int) bytes[0] << ".";
|
||||
str << (int) bytes[1] << ".";
|
||||
str << (int) bytes[2] << ".";
|
||||
str << (int) bytes[3];
|
||||
return str.str();
|
||||
rs_sprintf(str, "%u.%u.%u.%u", (int) bytes[0], (int) bytes[1], (int) bytes[2], (int) bytes[3]);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -25,34 +25,40 @@
|
||||
*/
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsstring.h"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <openssl/sha.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
std::string RsUtil::BinToHex(std::string bin)
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
std::string RsUtil::BinToHex(const std::string &bin)
|
||||
{
|
||||
return BinToHex(bin.c_str(), bin.length());
|
||||
}
|
||||
|
||||
std::string RsUtil::BinToHex(const char *arr, const uint32_t len)
|
||||
{
|
||||
std::ostringstream out;
|
||||
std::string out;
|
||||
|
||||
for(uint32_t j = 0; j < len; j++)
|
||||
{
|
||||
out << std::hex << std::setw(2) << std::setfill('0') << (int32_t) (((const uint8_t *) arr)[j]);
|
||||
}
|
||||
return out.str();
|
||||
for(uint32_t j = 0; j < len; j++)
|
||||
{
|
||||
rs_sprintf_append(out, "%02x", (int32_t) (((const uint8_t *) arr)[j]));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::string RsUtil::HashId(std::string id, bool reverse)
|
||||
std::string RsUtil::HashId(const std::string &id, bool reverse)
|
||||
{
|
||||
std::string hash;
|
||||
std::string tohash;
|
||||
if (reverse)
|
||||
{
|
||||
std::string::reverse_iterator rit;
|
||||
std::string::const_reverse_iterator rit;
|
||||
for(rit = id.rbegin(); rit != id.rend(); rit++)
|
||||
{
|
||||
tohash += (*rit);
|
||||
@ -81,43 +87,24 @@ std::string RsUtil::HashId(std::string id, bool reverse)
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
static double getCurrentTS();
|
||||
//static double getCurrentTS()
|
||||
//{
|
||||
//#ifndef WINDOWS_SYS
|
||||
// struct timeval cts_tmp;
|
||||
// gettimeofday(&cts_tmp, NULL);
|
||||
// double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
|
||||
//#else
|
||||
// struct _timeb timebuf;
|
||||
// _ftime( &timebuf);
|
||||
// double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
|
||||
//#endif
|
||||
// return cts;
|
||||
//}
|
||||
|
||||
// Little fn to get current timestamp in an independent manner.
|
||||
std::string RsUtil::AccurateTimeString()
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << std::setprecision(15) << getCurrentTS();
|
||||
return out.str();
|
||||
}
|
||||
|
||||
static double getCurrentTS()
|
||||
{
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
struct timeval cts_tmp;
|
||||
gettimeofday(&cts_tmp, NULL);
|
||||
double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
|
||||
#else
|
||||
struct _timeb timebuf;
|
||||
_ftime( &timebuf);
|
||||
double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
|
||||
#endif
|
||||
return cts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//std::string RsUtil::AccurateTimeString()
|
||||
//{
|
||||
// std::ostringstream out; // please do not use std::stringstream
|
||||
// out << std::setprecision(15) << getCurrentTS();
|
||||
// return out.str();
|
||||
//}
|
||||
|
@ -33,11 +33,11 @@
|
||||
|
||||
namespace RsUtil {
|
||||
|
||||
std::string BinToHex(std::string bin);
|
||||
std::string BinToHex(const std::string &bin);
|
||||
std::string BinToHex(const char *arr, const uint32_t len);
|
||||
std::string HashId(std::string id, bool reverse = false);
|
||||
std::string HashId(const std::string &id, bool reverse = false);
|
||||
|
||||
std::string AccurateTimeString();
|
||||
//std::string AccurateTimeString();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user