Removed some std::ostringstream.

To be continued.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5107 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-04-17 21:00:54 +00:00
parent d52904e7c6
commit b2ea453804
8 changed files with 82 additions and 169 deletions

View File

@ -571,14 +571,12 @@ void p3disc::sendOwnVersion(std::string to)
void p3disc::sendHeartbeat(std::string to) void p3disc::sendHeartbeat(std::string to)
{ {
{ {
std::ostringstream out; std::string out = "p3disc::sendHeartbeat() to : " + to;
out << "p3disc::sendHeartbeat()";
out << " to : " << to;
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << out.str() << std::endl; std::cerr << out << std::endl;
#endif #endif
rslog(RSL_WARNING, pqidisczone, out.str()); rslog(RSL_WARNING, pqidisczone, out);
} }
@ -1168,6 +1166,7 @@ void p3disc::getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCoun
} }
} }
#ifdef UNUSED_CODE
int p3disc::idServers() int p3disc::idServers()
{ {
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -1176,56 +1175,36 @@ int p3disc::idServers()
std::map<std::string, autoserver>::iterator sit; std::map<std::string, autoserver>::iterator sit;
int cts = time(NULL); int cts = time(NULL);
std::ostringstream out; std::string out = "::::AutoDiscovery Neighbours::::\n";
out << "::::AutoDiscovery Neighbours::::" << std::endl;
for(nit = neighbours.begin(); nit != neighbours.end(); nit++) for(nit = neighbours.begin(); nit != neighbours.end(); nit++)
{ {
out << "Neighbour: " << (nit->second).id; out += "Neighbour: " + (nit->second).id + "\n";
out << std::endl; rs_sprintf_append(out, "-> LocalAddr: %s:%u\n", rs_inet_ntoa(nit->second.localAddr.sin_addr).c_str(), ntohs(nit->second.localAddr.sin_port));
out << "-> LocalAddr: "; rs_sprintf_append(out, "-> RemoteAddr: %s:%u\n", rs_inet_ntoa(nit->second.remoteAddr.sin_addr).c_str(), ntohs(nit->second.remoteAddr.sin_port));
out << rs_inet_ntoa(nit->second.localAddr.sin_addr); rs_sprintf_append(out, " Last Contact: %ld sec ago\n", cts - (nit->second.ts));
out << ":" << ntohs(nit->second.localAddr.sin_port) << std::endl;
out << "-> RemoteAddr: ";
out << rs_inet_ntoa(nit->second.remoteAddr.sin_addr);
out << ":" << ntohs(nit->second.remoteAddr.sin_port) << std::endl;
out << " Last Contact: ";
out << cts - (nit->second.ts) << " sec ago";
out << std::endl;
out << " -->DiscFlags: 0x" << std::hex << nit->second.discFlags; rs_sprintf_append(out, " -->DiscFlags: 0x%x\n", nit->second.discFlags);
out << std::dec << std::endl;
for(sit = (nit->second.neighbour_of).begin(); for(sit = (nit->second.neighbour_of).begin();
sit != (nit->second.neighbour_of).end(); sit++) sit != (nit->second.neighbour_of).end(); sit++)
{ {
out << "\tConnected via: " << (sit->first); out += "\tConnected via: " + (sit->first) + "\n";
out << std::endl; rs_sprintf_append(out, "\t\tLocalAddr: %s:%u\n", rs_inet_ntoa(sit->second.localAddr.sin_addr).c_str(), ntohs(sit->second.localAddr.sin_port));
out << "\t\tLocalAddr: "; rs_sprintf_append(out, "\t\tRemoteAddr: %s:%u\n", rs_inet_ntoa(sit->second.remoteAddr.sin_addr).c_str(), ntohs(sit->second.remoteAddr.sin_port));
out << rs_inet_ntoa(sit->second.localAddr.sin_addr);
out <<":"<< ntohs(sit->second.localAddr.sin_port);
out << std::endl;
out << "\t\tRemoteAddr: ";
out << rs_inet_ntoa(sit->second.remoteAddr.sin_addr);
out <<":"<< ntohs(sit->second.remoteAddr.sin_port);
out << std::endl; rs_sprintf_append(out, "\t\tLast Contact: %ld sec ago\n", cts - (sit->second.ts));
out << "\t\tLast Contact:"; rs_sprintf_append(out, "\t\tDiscFlags: 0x%x\n", sit->second.discFlags);
out << cts - (sit->second.ts) << " sec ago";
out << std::endl;
out << "\t\tDiscFlags: 0x" << std::hex << (sit->second.discFlags);
out << std::dec << std::endl;
} }
} }
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::idServers()" << std::endl; std::cerr << "p3disc::idServers()" << std::endl;
std::cerr << out.str(); std::cerr << out;
std::cerr << std::endl;
#endif #endif
return 1; return 1;
} }
#endif
// tdelta -> trange. // tdelta -> trange.
// -inf...<0 0 (invalid) // -inf...<0 0 (invalid)
@ -1287,9 +1266,7 @@ bool p3disc::saveList(bool& cleanup, std::list<RsItem*>& /*lst*/)
{ {
RsTlvKeyValue kv; RsTlvKeyValue kv;
kv.key = mapIt->first; kv.key = mapIt->first;
std::ostringstream time_string; rs_sprintf(kv.value, "%ld", mapIt->second);
time_string << mapIt->second;
kv.value = time_string.str();
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::saveList() saving : " << mapIt->first << " ; " << mapIt->second << std::endl ; std::cerr << "p3disc::saveList() saving : " << mapIt->first << " ; " << mapIt->second << std::endl ;

View File

@ -140,7 +140,7 @@ int addDiscoveryData(const std::string& fromId, const std::string& aboutId,
const struct sockaddr_in& laddr, const struct sockaddr_in& raddr, const struct sockaddr_in& laddr, const struct sockaddr_in& raddr,
uint32_t flags, time_t ts,bool& new_info); uint32_t flags, time_t ts,bool& new_info);
int idServers(); //int idServers();
private: private:

View File

@ -31,8 +31,6 @@
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
#include "util/rsrandom.h" #include "util/rsrandom.h"
#include <sstream>
#include <openssl/sha.h> #include <openssl/sha.h>
/**** /****
@ -653,7 +651,6 @@ int p3Dsdv::addTestService()
int rndhash1[SHA_DIGEST_LENGTH / 4]; int rndhash1[SHA_DIGEST_LENGTH / 4];
int rndhash2[SHA_DIGEST_LENGTH / 4]; int rndhash2[SHA_DIGEST_LENGTH / 4];
std::ostringstream rh, sh;
std::string realHash; std::string realHash;
std::string seedHash; std::string seedHash;
@ -664,35 +661,30 @@ int p3Dsdv::addTestService()
rndhash2[i] = RSRandom::random_u32(); rndhash2[i] = RSRandom::random_u32();
} }
for(int i = 0; i < SHA_DIGEST_LENGTH; i++) for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{ {
rh << std::setw(2) << std::setfill('0') << std::hex << (uint32_t) ((uint8_t *) rndhash1)[i]; rs_sprintf_append(realHash, "%02x", (uint32_t) ((uint8_t *) rndhash1)[i]);
sh << std::setw(2) << std::setfill('0') << std::hex << (uint32_t) ((uint8_t *) rndhash2)[i]; rs_sprintf_append(seedHash, "%02x", (uint32_t) ((uint8_t *) rndhash2)[i]);
}
realHash = rh.str();
seedHash = sh.str();
uint8_t sha_hash[SHA_DIGEST_LENGTH];
memset(sha_hash,0,SHA_DIGEST_LENGTH*sizeof(uint8_t)) ;
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, realHash.c_str(), realHash.length());
SHA1_Update(sha_ctx, seedHash.c_str(), seedHash.length());
SHA1_Final(sha_hash, sha_ctx);
delete sha_ctx;
std::ostringstream keystr;
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
keystr << std::setw(2) << std::setfill('0') << std::hex << (uint32_t) (sha_hash)[i];
} }
uint8_t sha_hash[SHA_DIGEST_LENGTH];
memset(sha_hash,0,SHA_DIGEST_LENGTH*sizeof(uint8_t)) ;
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, realHash.c_str(), realHash.length());
SHA1_Update(sha_ctx, seedHash.c_str(), seedHash.length());
SHA1_Final(sha_hash, sha_ctx);
delete sha_ctx;
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
rs_sprintf_append(testId.mHash, "%02x", (uint32_t) (sha_hash)[i]);
}
testId.mIdType = RSDSDV_IDTYPE_TEST; testId.mIdType = RSDSDV_IDTYPE_TEST;
testId.mAnonChunk = seedHash; testId.mAnonChunk = seedHash;
testId.mHash = keystr.str();
addDsdvId(&testId, realHash); addDsdvId(&testId, realHash);
return 1; return 1;

View File

@ -141,34 +141,6 @@ int p3GameLauncher::status()
/**** Interface to GUI Game Launcher ****/ /**** Interface to GUI Game Launcher ****/
std::string generateRandomGameId()
{
std::ostringstream out;
out << std::hex;
/********************************** 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;
}
#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;
}
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
return out.str();
}
/**** GUI Interface ****/ /**** GUI Interface ****/
@ -218,7 +190,7 @@ std::string p3GameLauncher::newGame(uint16_t srvId, std::wstring name)
#endif #endif
/* generate GameId (random string) */ /* generate GameId (random string) */
std::string gameId = generateRandomGameId(); std::string gameId = generateRandomServiceId();
gameStatus newGame; gameStatus newGame;
newGame.gameId = gameId; newGame.gameId = gameId;
@ -747,9 +719,7 @@ bool p3GameLauncher::getGameList(std::list<RsGameInfo> &gameList)
info.gameId = git->first; info.gameId = git->first;
info.serverId = git->second.serverId; info.serverId = git->second.serverId;
std::ostringstream out; rs_sprintf(info.gameType, "GameType: %lu", git->second.serviceId);
out << "GameType: " << git->second.serviceId;
info.gameType = out.str();
info.serverName = "ServerName"; info.serverName = "ServerName";
info.numPlayers = git->second.numPlayers; info.numPlayers = git->second.numPlayers;

View File

@ -37,7 +37,6 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include <sstream>
#include <iomanip> #include <iomanip>
#include <map> #include <map>
@ -156,9 +155,9 @@ void p3MsgService::processMsg(RsMsgItem *mi)
librs::util::ConvertUtf16ToUtf8(mi->message, message); librs::util::ConvertUtf16ToUtf8(mi->message, message);
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(), title, message); notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(), title, message);
std::ostringstream out; std::string out;
out << mi->msgId; rs_sprintf(out, "%lu", mi->msgId);
notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, out.str(), "", ""); notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, out, "", "");
} }
} }
@ -843,9 +842,7 @@ bool p3MsgService::getMsgParentId(const std::string &msgId, std::string &msgP
return false; return false;
} }
std::ostringstream out; rs_sprintf(msgParentId, "%lu", mit->second->msgParentId);
out << mit->second->msgParentId;
msgParentId = out.str();
return true; return true;
} }
@ -967,9 +964,7 @@ bool p3MsgService::MessageSend(MessageInfo &info)
processMsg(msg); processMsg(msg);
// return new message id // return new message id
std::ostringstream out; rs_sprintf(info.msgId, "%lu", msg->msgId);
out << msg->msgId;
info.msgId = out.str();
} }
return true; return true;
@ -1011,9 +1006,7 @@ bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParen
imsg[msg->msgId] = msg; imsg[msg->msgId] = msg;
// return new message id // return new message id
std::ostringstream out; rs_sprintf(info.msgId, "%lu", msg->msgId);
out << msg->msgId;
info.msgId = out.str();
} }
setMsgParentId(msg->msgId, atoi(msgParentId.c_str())); setMsgParentId(msg->msgId, atoi(msgParentId.c_str()));
@ -1164,10 +1157,7 @@ bool p3MsgService::getMessageTag(const std::string &msgId, MsgTagInfo& info)
std::map<uint32_t, RsMsgTags*>::iterator mit; std::map<uint32_t, RsMsgTags*>::iterator mit;
if(mMsgTags.end() != (mit = mMsgTags.find(mid))) { if(mMsgTags.end() != (mit = mMsgTags.find(mid))) {
std::ostringstream out; rs_sprintf(info.msgId, "%lu", mit->second->msgId);
out << mit->second->msgId;
info.msgId = out.str();
info.tagIds = mit->second->tagIds; info.tagIds = mit->second->tagIds;
return true; return true;
@ -1390,9 +1380,7 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
mi.srcId = msg->PeerId(); mi.srcId = msg->PeerId();
{ {
//msg->msgId; //msg->msgId;
std::ostringstream out; rs_sprintf(mi.msgId, "%lu", msg->msgId);
out << msg->msgId;
mi.msgId = out.str();
} }
std::list<std::string>::iterator pit; std::list<std::string>::iterator pit;
@ -1488,9 +1476,7 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
mis.srcId = msg->PeerId(); mis.srcId = msg->PeerId();
{ {
//msg->msgId; //msg->msgId;
std::ostringstream out; rs_sprintf(mis.msgId, "%lu", msg->msgId);
out << msg->msgId;
mis.msgId = out.str();
} }
mis.title = msg->subject; mis.title = msg->subject;

View File

@ -30,8 +30,6 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include <sstream>
std::string generateRandomShowId(); std::string generateRandomShowId();
/**** /****
@ -306,10 +304,9 @@ void p3PhotoService::publishPhotos()
/* determine filename */ /* determine filename */
std::string path = CacheSource::getCacheDir(); std::string path = CacheSource::getCacheDir();
std::ostringstream out;
out << "photo-index-" << time(NULL) << ".pdx";
std::string tmpname = out.str(); std::string tmpname;
rs_sprintf(tmpname, "photo-index-%ld.pdx", time(NULL));
std::string fname = path + "/" + tmpname; std::string fname = path + "/" + tmpname;
#ifdef PHOTO_DEBUG #ifdef PHOTO_DEBUG
@ -778,31 +775,28 @@ RsPhotoShowItem *p3PhotoService::locked_getShow(std::string id, std::string show
std::string generateRandomShowId() std::string generateRandomShowId()
{ {
std::ostringstream out; std::string out;
out << std::hex;
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
/* 4 bytes per random number: 4 x 4 = 16 bytes */ /* 4 bytes per random number: 4 x 4 = 16 bytes */
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
out << std::setw(8) << std::setfill('0'); uint32_t rint = random();
uint32_t rint = random(); rs_sprintf_append(out, "%08x", rint);
out << rint; }
}
#else #else
srand(time(NULL)); srand(time(NULL));
/* 2 bytes per random number: 8 x 2 = 16 bytes */ /* 2 bytes per random number: 8 x 2 = 16 bytes */
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{ {
out << std::setw(4) << std::setfill('0'); uint16_t rint = rand(); /* only gives 16 bits */
uint16_t rint = rand(); /* only gives 16 bits */ rs_sprintf_append(out, "%04x", rint);
out << rint; }
}
#endif #endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
return out.str(); return out;
} }

View File

@ -24,8 +24,8 @@
*/ */
#include "pqi/pqi.h" #include "pqi/pqi.h"
#include "util/rsstring.h"
#include "services/p3service.h" #include "services/p3service.h"
#include <sstream>
#include <iomanip> #include <iomanip>
/***** /*****
@ -226,29 +226,27 @@ RsRawItem *p3Service::send()
std::string generateRandomServiceId() std::string generateRandomServiceId()
{ {
std::ostringstream out; std::string out;
out << std::hex;
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
/* 4 bytes per random number: 4 x 4 = 16 bytes */ /* 4 bytes per random number: 4 x 4 = 16 bytes */
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
out << std::setw(8) << std::setfill('0');
uint32_t rint = random(); uint32_t rint = random();
out << rint; rs_sprintf_append(out, "%08x", rint);
} }
#else #else
srand(time(NULL)); srand(time(NULL));
/* 2 bytes per random number: 8 x 2 = 16 bytes */ /* 2 bytes per random number: 8 x 2 = 16 bytes */
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{ {
out << std::setw(4) << std::setfill('0');
uint16_t rint = rand(); /* only gives 16 bits */ uint16_t rint = rand(); /* only gives 16 bits */
out << rint; rs_sprintf_append(out, "%04x", rint);
} }
#endif #endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
return out.str(); return out;
} }

View File

@ -29,7 +29,6 @@
//#include "retroshare/rspeers.h" //#include "retroshare/rspeers.h"
#include "services/p3tunnel.h" #include "services/p3tunnel.h"
#include "pqi/pqissltunnel.h" #include "pqi/pqissltunnel.h"
#include <sstream>
#include "pqi/authssl.h" #include "pqi/authssl.h"
#include "pqi/p3connmgr.h" #include "pqi/p3connmgr.h"
@ -86,11 +85,9 @@ int p3tunnel::handleIncoming()
{ {
#ifdef P3TUNNEL_DEBUG #ifdef P3TUNNEL_DEBUG
std::ostringstream out; std::string out = "p3tunnel::handleIncoming() Received Message!\n";
out << "p3tunnel::handleIncoming()"; item -> print_string(out);
out << " Received Message!" << std::endl; std::cerr << out;
item -> print(out);
std::cerr << out.str();
#endif #endif
} }
@ -125,10 +122,9 @@ void p3tunnel::sendTunnelDataPrivate(std::string to, std::string sourcePeerId, s
// Then send message. // Then send message.
{ {
#ifdef P3TUNNEL_DEBUG #ifdef P3TUNNEL_DEBUG
std::ostringstream out; std::string out = "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!\n";
out << "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!" << std::endl; out += "Sending to: " + to;
out << "Sending to: " << to; std::cerr << out << std::endl;
std::cerr << out.str() << std::endl;
#endif #endif
} }