Removed some std::ostringstream.

To be continued.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5097 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-04-14 00:30:23 +00:00
parent 3b85873313
commit 545743ad77
17 changed files with 506 additions and 947 deletions

View File

@ -23,13 +23,10 @@
*
*/
#include "pqi/pqihandler.h"
#include <sstream>
#include "util/rsdebug.h"
#include "util/rsstring.h"
#include <stdlib.h>
const int pqihandlerzone = 34283;
@ -51,13 +48,7 @@ pqihandler::pqihandler(SecurityPolicy *Global) : pqiQoS(PQI_HANDLER_NB_PRIORITY_
// cannot be enabled by module.
globsec = Global;
{
std::ostringstream out;
out << "New pqihandler()" << std::endl;
out << "Security Policy: " << secpolicy_print(globsec);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
}
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "New pqihandler()\nSecurity Policy: " + secpolicy_print(globsec));
// setup minimal total+individual rates.
rateIndiv_out = 0.01;
@ -171,17 +162,15 @@ int pqihandler::status()
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
{ // for output
std::ostringstream out;
out << "pqihandler::status() Active Modules:" << std::endl;
std::string out = "pqihandler::status() Active Modules:\n";
// display all interfaces...
for(it = mods.begin(); it != mods.end(); it++)
{
out << "\tModule [" << it -> first << "] Pointer <";
out << (void *) ((it -> second) -> pqi) << ">" << std::endl;
}
// display all interfaces...
for(it = mods.begin(); it != mods.end(); it++)
{
rs_sprintf_append(out, "\tModule [%s] Pointer <%p>", it -> first.c_str(), (void *) ((it -> second) -> pqi));
}
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
} // end of output.
@ -193,8 +182,6 @@ int pqihandler::status()
}
return 1;
}
bool pqihandler::AddSearchModule(SearchModule *mod)
{
@ -204,27 +191,21 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
if (mod->peerid != mod->pqi->PeerId())
{
// ERROR!
std::ostringstream out;
out << "ERROR peerid != PeerId!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
pqioutput(PQL_ALERT, pqihandlerzone, "ERROR peerid != PeerId!");
return false;
}
if (mod->peerid == "")
{
// ERROR!
std::ostringstream out;
out << "ERROR peerid == NULL" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
pqioutput(PQL_ALERT, pqihandlerzone, "ERROR peerid == NULL");
return false;
}
if (mods.find(mod->peerid) != mods.end())
{
// ERROR!
std::ostringstream out;
out << "ERROR PeerId Module already exists!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
pqioutput(PQL_ALERT, pqihandlerzone, "ERROR PeerId Module already exists!");
return false;
}
@ -280,12 +261,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
if (allowglobal)
{
/* error */
std::ostringstream out;
out << "pqihandler::HandleSearchItem()";
out << " Cannot send out Global RsItem";
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
std::string out = "pqihandler::HandleSearchItem() Cannot send out Global RsItem";
pqioutput(PQL_ALERT, pqihandlerzone, out);
#ifdef DEBUG_TICK
std::cerr << out.str();
std::cerr << out << std::endl;
#endif
delete item;
return -1;
@ -293,15 +272,13 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
if (!locked_checkOutgoingRsItem(item, allowglobal))
{
std::ostringstream out;
out << "pqihandler::HandleRsItem() checkOutgoingPQItem";
out << " Failed on item: " << std::endl;
std::string out = "pqihandler::HandleRsItem() checkOutgoingPQItem Failed on item: \n";
#ifdef DEBUG_TICK
std::cerr << out.str();
std::cerr << out;
#endif
item -> print(out);
item -> print_string(out);
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
pqioutput(PQL_ALERT, pqihandlerzone, out);
delete item;
return -1;
}
@ -316,11 +293,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
// find module.
if ((it = mods.find(item->PeerId())) == mods.end())
{
std::ostringstream out;
out << "pqihandler::HandleRsItem() Invalid chan!";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
std::string out = "pqihandler::HandleRsItem() Invalid chan!";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
#ifdef DEBUG_TICK
std::cerr << out.str();
std::cerr << out << std::endl;
#endif
delete item;
@ -330,12 +306,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
// check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
{
std::ostringstream out;
out << "pqihandler::HandleRsItem() sending to chan:";
out << it -> first << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
std::string out = "pqihandler::HandleRsItem() sending to chan: " + it -> first;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
#ifdef DEBUG_TICK
std::cerr << out.str();
std::cerr << out << std::endl;
#endif
// if yes send on item.
@ -344,12 +318,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
}
else
{
std::ostringstream out;
out << "pqihandler::HandleRsItem()";
out << " Sec not approved";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
std::string out = "pqihandler::HandleRsItem() Sec not approved";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
#ifdef DEBUG_TICK
std::cerr << out.str();
std::cerr << out << std::endl;
#endif
delete item;
@ -439,13 +411,12 @@ int pqihandler::locked_GetItems()
while((item = (mod -> pqi) -> GetItem()) != NULL)
{
#ifdef RSITEM_DEBUG
std::ostringstream out;
out << "pqihandler::GetItems() Incoming Item ";
out << " from: " << mod -> pqi << std::endl;
item -> print(out);
std::string out;
rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
item -> print_string(out);
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out.str());
pqihandlerzone, out);
#endif
if (item->PeerId() != (mod->pqi)->PeerId())
@ -465,16 +436,13 @@ int pqihandler::locked_GetItems()
// not allowed to recieve from here....
while((item = (mod -> pqi) -> GetItem()) != NULL)
{
std::ostringstream out;
out << "pqihandler::GetItems() Incoming Item ";
out << " from: " << mod -> pqi << std::endl;
item -> print(out);
out << std::endl;
out << "Item Not Allowed (Sec Pol). deleting!";
out << std::endl;
std::string out;
rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
item -> print_string(out);
out += "\nItem Not Allowed (Sec Pol). deleting!";
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out.str());
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out);
delete item;
}
@ -483,9 +451,6 @@ int pqihandler::locked_GetItems()
return count;
}
void pqihandler::locked_SortnStoreItem(RsItem *item)
{
/* get class type / subtype out of the item */

View File

@ -4,8 +4,6 @@
#include "pqi/pqinetstatebox.h"
#include "time.h"
#include <sstream>
// External Interface.
void pqiNetStateBox::setAddressStunDht(struct sockaddr_in *addr, bool stable)
@ -690,28 +688,28 @@ std::string NetStateNatHoleString(uint32_t natHole)
std::string NetStateConnectModesString(uint32_t connect)
{
std::ostringstream connOut;
std::string connOut;
if (connect & RSNET_CONNECT_OUTGOING_TCP)
{
connOut << "TCP_OUT ";
connOut += "TCP_OUT ";
}
if (connect & RSNET_CONNECT_ACCEPT_TCP)
{
connOut << "TCP_IN ";
connOut += "TCP_IN ";
}
if (connect & RSNET_CONNECT_DIRECT_UDP)
{
connOut << "DIRECT_UDP ";
connOut += "DIRECT_UDP ";
}
if (connect & RSNET_CONNECT_PROXY_UDP)
{
connOut << "PROXY_UDP ";
connOut += "PROXY_UDP ";
}
if (connect & RSNET_CONNECT_RELAY_UDP)
{
connOut << "RELAY_UDP ";
connOut += "RELAY_UDP ";
}
return connOut.str();
return connOut;
}

View File

@ -35,7 +35,7 @@
#include <unistd.h>
#include "util/rsdebug.h"
#include <sstream>
#include "util/rsstring.h"
#include <iomanip>
static const int pqinetzone = 96184;
@ -56,12 +56,10 @@ int errno;
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
std::ostream &showSocketError(std::ostream &out)
void showSocketError(std::string &out)
{
int err = errno;
out << "\tSocket Error(" << err << ") : ";
out << socket_errorType(err) << std::endl;
return out;
rs_sprintf_append(out, "\tSocket Error(%d) : %s\n", err, socket_errorType(err).c_str());
}
std::string socket_errorType(int err)
@ -178,10 +176,9 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
if(ioctl(sock, SIOCGIFADDR, &ifreq) != 0)
{
std::ostringstream out;
out << "Cannot Determine Address for Iface: ";
out << ifptr -> if_name << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
std::string out;
rs_sprintf(out, "Cannot Determine Address for Iface: %s", ifptr -> if_name);
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
}
else
{
@ -189,12 +186,9 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
(struct sockaddr_in *) &ifreq.ifr_addr;
std::string astr =rs_inet_ntoa(aptr -> sin_addr);
std::ostringstream out;
out << "Iface: ";
out << ifptr -> if_name << std::endl;
out << " Address: " << astr;
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
std::string out;
rs_sprintf(out, "Iface: %s\n Address: %s", ifptr -> if_name, astr.c_str());
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
// Now check wether the interface is up and running. If not, we don't use it!!
//
@ -223,12 +217,10 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#else
std::ostream &showSocketError(std::ostream &out)
void showSocketError(std::string &out)
{
int err = WSAGetLastError();
out << "\tSocket Error(" << err << ") : ";
out << socket_errorType(err) << std::endl;
return out;
rs_sprintf_append(out, "\tSocket Error(%d) : %s\n", err, socket_errorType(err).c_str());
}
@ -356,13 +348,11 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
for(unsigned int i = 0; i < iptable -> dwNumEntries; i++)
{
std::ostringstream out;
std::string out;
out << "Iface(" << iptable->table[i].dwIndex << ") ";
addr.s_addr = iptable->table[i].dwAddr;
out << " => " << rs_inet_ntoa(addr);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
rs_sprintf(out, "Iface(%ld) => %s\n", iptable->table[i].dwIndex, rs_inet_ntoa(addr).c_str());
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
addrs.push_back(addr);
}
@ -501,12 +491,9 @@ int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 )
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 )
{
#ifdef NET_DEBUG
std::ostringstream out;
out << "inaddr_cmp(" << rs_inet_ntoa(addr1.sin_addr);
out << "-" << addr1.sin_addr.s_addr;
out << "," << rs_inet_ntoa(addr2.sin_addr);
out << "-" << addr2.sin_addr.s_addr << ")" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
std::string out;
rs_sprintf(out, "inaddr_cmp(%s-%lu,%s-%lu)", rs_inet_ntoa(addr1.sin_addr).c_str(), addr1.sin_addr.s_addr, rs_inet_ntoa(addr2.sin_addr).c_str(), addr2.sin_addr.s_addr);
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
#endif
@ -525,13 +512,9 @@ int inaddr_cmp(struct sockaddr_in addr1, unsigned long addr2)
struct in_addr inaddr_tmp;
inaddr_tmp.s_addr = addr2;
std::ostringstream out;
out << "inaddr_cmp2(" << rs_inet_ntoa(addr1.sin_addr);
out << " vs " << rs_inet_ntoa(inaddr_tmp);
out << " /or/ ";
out << std::hex << std::setw(10) << addr1.sin_addr.s_addr;
out << " vs " << std::setw(10) << addr2 << ")" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
std::string out;
rs_sprintf(out, "inaddr_cmp2(%s vs %s /or/ %10x vs %10x)", rs_inet_ntoa(addr1.sin_addr).c_str(), rs_inet_ntoa(inaddr_tmp).c_str(), addr1.sin_addr.s_addr, addr2);
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
#endif
if (addr1.sin_addr.s_addr == addr2)

View File

@ -96,7 +96,7 @@ extern int errno; /* Define extern errno, to duplicate unix behaviour */
// Same def - different functions...
std::ostream &showSocketError(std::ostream &out);
void showSocketError(std::string &out);
std::string socket_errorType(int err);
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );

View File

@ -30,7 +30,7 @@
const int pqipersonzone = 82371;
#include "util/rsdebug.h"
#include <sstream>
#include "util/rsstring.h"
/****
* #define PERSON_DEBUG
@ -63,25 +63,23 @@ pqiperson::~pqiperson()
// The PQInterface interface.
int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size)
{
std::ostringstream out;
out << "pqiperson::SendItem()";
std::string out = "pqiperson::SendItem()";
if (active)
{
out << " Active: Sending On" << std::endl;
i->print(out, 5);
out += " Active: Sending On\n";
i->print_string(out, 5);
#ifdef PERSON_DEBUG
std::cerr << out.str() << std::endl;
std::cerr << out << std::endl;
#endif
return activepqi -> SendItem(i,serialized_size);
}
else
{
out << " Not Active: Used to put in ToGo Store";
out << std::endl;
out << " Now deleting...";
out += " Not Active: Used to put in ToGo Store\n";
out += " Now deleting...";
delete i;
}
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
return 0; // queued.
}
@ -116,23 +114,19 @@ int pqiperson::tick()
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
{
int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS();
std::ostringstream out;
out << "pqiperson::tick() WARNING No heartbeat from: " << PeerId();
std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId();
//out << " assume dead. calling pqissl::reset(), LastHeartbeat was: ";
out << " LastHeartbeat was: ";
out << time(NULL) - lastHeartbeatReceived << " secs ago";
out << " LastIncoming was: ";
out << ageLastIncoming << " secs ago";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
rs_sprintf_append(out, " LastHeartbeat was: %ld secs ago", time(NULL) - lastHeartbeatReceived);
rs_sprintf_append(out, " LastIncoming was: %d secs ago", ageLastIncoming);
pqioutput(PQL_WARNING, pqipersonzone, out);
#define NO_PACKET_TIMEOUT 60
if (ageLastIncoming > NO_PACKET_TIMEOUT)
{
std::ostringstream out2;
out2 << "pqiperson::tick() " << PeerId();
out2 << " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
pqioutput(PQL_WARNING, pqipersonzone, out2.str());
out = "pqiperson::tick() " + PeerId();
out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
pqioutput(PQL_WARNING, pqipersonzone, out);
this->reset();
}
@ -142,35 +136,33 @@ int pqiperson::tick()
int activeTick = 0;
{
std::ostringstream out;
out << "pqiperson::tick() Id: " << PeerId() << " ";
if (active)
out << "***Active***";
else
out << ">>InActive<<";
std::string out = "pqiperson::tick() Id: " + PeerId() + " ";
if (active)
out += "***Active***";
else
out += ">>InActive<<";
out << std::endl;
out << "Activepqi: " << activepqi << " inConnectAttempt: ";
out += "\n";
rs_sprintf_append(out, "Activepqi: %p inConnectAttempt: ", activepqi);
if (inConnectAttempt)
out << "In Connection Attempt";
else
out << " Not Connecting ";
out << std::endl;
if (inConnectAttempt)
out += "In Connection Attempt";
else
out += " Not Connecting ";
out += "\n";
// tick the children.
std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++)
{
if (0 < (it->second) -> tick())
// tick the children.
std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++)
{
activeTick = 1;
if (0 < (it->second) -> tick())
{
activeTick = 1;
}
rs_sprintf_append(out, "\tTicking Child: %d\n", it->first);
}
out << "\tTicking Child: " << (it->first) << std::endl;
}
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out.str());
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out);
} // end of pqioutput.
return activeTick;
@ -182,13 +174,11 @@ int pqiperson::tick()
int pqiperson::notifyEvent(NetInterface *ni, int newState)
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << std::endl;
out << "Message: " << newState << " from: " << ni << std::endl;
out << "Active pqi : " << activepqi;
std::string out = "pqiperson::notifyEvent() Id: " + PeerId() + "\n";
rs_sprintf_append(out, "Message: %d from: %p\n", newState, ni);
rs_sprintf_append(out, "Active pqi : %p", activepqi);
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
}
/* find the pqi, */
@ -200,14 +190,10 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
int i = 0;
for(it = kids.begin(); it != kids.end(); it++)
{
std::ostringstream out;
out << "pqiperson::connectattempt() Kid# ";
out << i << " of " << kids.size();
out << std::endl;
out << " type: " << (it->first);
//out << " ni: " << (it->second)->ni;
out << " in_ni: " << ni;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
std::string out;
rs_sprintf(out, "pqiperson::connectattempt() Kid# %d of %u\n", i, kids.size());
rs_sprintf_append(out, " type: %u in_ni: %p", it->first, ni);
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
i++;
if ((it->second)->thisNetInterface(ni))
@ -238,12 +224,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
if ((active) && (activepqi != pqi)) // already connected - trouble
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_SUCCESS+active-> activing new connection, shutting others";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS+active-> activing new connection, shutting others");
// This is the RESET that's killing the connections.....
//activepqi -> reset();
@ -255,12 +236,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
/* now install a new one. */
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_SUCCESS->marking so! (resetting others)";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS->marking so! (resetting others)");
// mark as active.
active = true;
@ -271,15 +247,15 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
/* reset all other children? (clear up long UDP attempt) */
for(it = kids.begin(); it != kids.end(); it++)
{
if (!(it->second)->thisNetInterface(ni))
{
std::ostringstream out;
out << "Resetting pqi ref : " << &(it->second) << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
it->second->reset();
} else {
//std::cerr << "Active pqi : not resetting." << std::endl;
}
if (!(it->second)->thisNetInterface(ni))
{
std::string out;
rs_sprintf(out, "Resetting pqi ref : %p", &(it->second));
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
it->second->reset();
} else {
//std::cerr << "Active pqi : not resetting." << std::endl;
}
}
return 1;
}
@ -293,40 +269,25 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
{
if (activepqi == pqi)
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED->marking so!";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED->marking so!");
active = false;
activepqi = NULL;
}
}
else
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
}
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !");
}
}
else
{
{
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED+NOT active -> try connect again";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED+NOT active -> try connect again");
}
/* notify up */
if (pqipg)
{
struct sockaddr_in raddr;
struct sockaddr_in raddr;
sockaddr_clear(&raddr);
pqipg->notifyConnect(PeerId(), type, false, raddr);
}
@ -344,11 +305,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
int pqiperson::reset()
{
{
std::ostringstream out;
out << "pqiperson::reset() resetting all pqiconnect for Id: " << PeerId();
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId());
std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++)
@ -358,7 +315,7 @@ int pqiperson::reset()
activepqi = NULL;
active = false;
lastHeartbeatReceived = 0;
lastHeartbeatReceived = 0;
return 1;
}
@ -366,10 +323,9 @@ int pqiperson::reset()
int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
{
{
std::ostringstream out;
out << "pqiperson::addChildInterface() : Id " << PeerId() << " " << type;
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
std::string out;
rs_sprintf(out, "pqiperson::addChildInterface() : Id %s %u", PeerId().c_str(), type);
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
}
kids[type] = pqi;
@ -382,12 +338,7 @@ int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
int pqiperson::listen()
{
{
std::ostringstream out;
out << "pqiperson::listen() Id: " << PeerId();
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
}
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::listen() Id: " + PeerId());
if (!active)
{
@ -404,12 +355,7 @@ int pqiperson::listen()
int pqiperson::stoplistening()
{
{
std::ostringstream out;
out << "pqiperson::stoplistening() Id: " << PeerId();
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
}
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::stoplistening() Id: " + PeerId());
std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++)
@ -427,20 +373,18 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
#ifdef PERSON_DEBUG
#endif
{
std::ostringstream out;
out << "pqiperson::connect() Id: " << PeerId();
out << " type: " << type;
out << " addr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
out << " proxyaddr: " << rs_inet_ntoa(proxyaddr.sin_addr) << ":" << ntohs(proxyaddr.sin_port);
out << " srcaddr: " << rs_inet_ntoa(srcaddr.sin_addr) << ":" << ntohs(srcaddr.sin_port);
out << " delay: " << delay;
out << " period: " << period;
out << " timeout: " << timeout;
out << " flags: " << flags;
out << " bandwidth: " << bandwidth;
out << std::endl;
//std::cerr << out.str();
pqioutput(PQL_WARNING, pqipersonzone, out.str());
std::string out = "pqiperson::connect() Id: " + PeerId();
rs_sprintf_append(out, " type: %u", type);
rs_sprintf_append(out, " addr: %s:%u", rs_inet_ntoa(raddr.sin_addr).c_str(), ntohs(raddr.sin_port));
rs_sprintf_append(out, " proxyaddr: %s:%u", rs_inet_ntoa(proxyaddr.sin_addr).c_str(), ntohs(proxyaddr.sin_port));
rs_sprintf_append(out, " srcaddr: %s:%u", rs_inet_ntoa(srcaddr.sin_addr).c_str(), ntohs(srcaddr.sin_port));
rs_sprintf_append(out, " delay: %u", delay);
rs_sprintf_append(out, " period: %u", period);
rs_sprintf_append(out, " timeout: %u", timeout);
rs_sprintf_append(out, " flags: %u", flags);
rs_sprintf_append(out, " bandwidth: %u", bandwidth);
//std::cerr << out.str();
pqioutput(PQL_WARNING, pqipersonzone, out);
}
std::map<uint32_t, pqiconnect *>::iterator it;
@ -449,12 +393,7 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
if (it == kids.end())
{
#ifdef PERSON_DEBUG
std::ostringstream out;
out << "pqiperson::connect()";
out << " missing pqiconnect";
out << std::endl;
std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::connect() missing pqiconnect");
#endif
/* notify of fail! */

View File

@ -27,7 +27,6 @@
#include "pqi/p3linkmgr.h"
#include "util/rsdebug.h"
#include <sstream>
#include <stdio.h>
const int pqipersongrpzone = 354;
@ -59,13 +58,10 @@ static std::list<std::string> waitingIds;
// handle the tunnel services.
int pqipersongrp::tickServiceRecv()
{
RsRawItem *pqi = NULL;
RsRawItem *pqi = NULL;
int i = 0;
{
std::ostringstream out;
out << "pqipersongrp::tickTunnelServer()";
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, "pqipersongrp::tickTunnelServer()");
//p3ServiceServer::tick();
@ -89,11 +85,8 @@ int pqipersongrp::tickServiceSend()
{
RsRawItem *pqi = NULL;
int i = 0;
{
std::ostringstream out;
out << "pqipersongrp::tickServiceSend()";
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, "pqipersongrp::tickServiceSend()");
p3ServiceServer::tick();
@ -390,11 +383,7 @@ void pqipersongrp::statusChanged()
int pqipersongrp::addPeer(std::string id)
{
{
std::ostringstream out;
out << "pqipersongrp::addPeer() PeerId: " << id;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::addPeer() PeerId: " + id);
std::cerr << "pqipersongrp::addPeer() id: " << id;
std::cerr << std::endl;
@ -707,11 +696,7 @@ pqilistener * pqipersongrpDummy::createListener(struct sockaddr_in /*laddr*/)
pqiperson * pqipersongrpDummy::createPerson(std::string id, pqilistener */*listener*/)
{
{
std::ostringstream out;
out << "pqipersongrpDummy::createPerson() PeerId: " << id;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrpDummy::createPerson() PeerId: " + id);
pqiperson *pqip = new pqiperson(id, this);

View File

@ -25,7 +25,7 @@
#include "pqi/pqiservice.h"
#include "util/rsdebug.h"
#include <sstream>
#include "util/rsstring.h"
const int pqiservicezone = 60478;
@ -77,16 +77,10 @@ int p3ServiceServer::incoming(RsRawItem *item)
"p3ServiceServer::incoming()");
{
std::ostringstream out;
out << "p3ServiceServer::incoming() PacketId: ";
out << std::hex << item -> PacketId() << std::endl;
out << "Looking for Service: ";
out << (item -> PacketId() & 0xffffff00) << std::dec << std::endl;
out << "Item:" << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
std::string out;
rs_sprintf(out, "p3ServiceServer::incoming() PacketId: %x\nLooking for Service: %x\nItem:\n", item -> PacketId(), (item -> PacketId() & 0xffffff00));
item -> print_string(out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
}
#endif
@ -108,10 +102,9 @@ int p3ServiceServer::incoming(RsRawItem *item)
{
#ifdef SERVICE_DEBUG
std::ostringstream out;
out << "p3ServiceServer::incoming() Sending to";
out << it -> second << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
std::string out;
rs_sprintf(out, "p3ServiceServer::incoming() Sending to %p", it -> second);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
#endif
return (it->second) -> receive(item);
@ -152,14 +145,12 @@ RsRawItem *p3ServiceServer::outgoing()
{
#ifdef SERVICE_DEBUG
std::ostringstream out;
out << "p3ServiceServer::outgoing() Got Item From:";
out << rrit -> second << std::endl;
std::string out;
rs_sprintf(out, "p3ServiceServer::outgoing() Got Item From: %p\n", rrit -> second);
item -> print(out);
out << std::endl;
std::cerr << out.str();
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
item -> print_string(out);
std::cerr << out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
#endif
return item;
@ -173,14 +164,12 @@ RsRawItem *p3ServiceServer::outgoing()
{
#ifdef SERVICE_DEBUG
std::ostringstream out;
out << "p3ServiceServer::outgoing() Got Item From:";
out << rrit -> second << std::endl;
std::string out;
rs_sprintf(out, "p3ServiceServer::outgoing() Got Item From: %p\n", rrit -> second);
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
std::cerr << out.str();
item -> print_string(out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
std::cerr << out << std::endl;
#endif
return item;
@ -208,11 +197,9 @@ int p3ServiceServer::tick()
{
#ifdef SERVICE_DEBUG
std::ostringstream out;
out << "p3ServiceServer::service id:" << it -> first;
out << " -> Service: " << it -> second;
out << std::endl;
pqioutput(PQL_DEBUG_ALL, pqiservicezone, out.str());
std::string out;
rs_sprintf(out, "p3ServiceServer::service id: %u -> Service: %p", it -> first, it -> second);
pqioutput(PQL_DEBUG_ALL, pqiservicezone, out);
#endif
// now we should actually tick the service.

View File

@ -23,23 +23,18 @@
*
*/
#include "pqi/pqissl.h"
#include "pqi/pqinetwork.h"
#include "pqi/sslfns.h"
#include "util/rsnet.h"
#include "util/rsdebug.h"
#include "util/rsstring.h"
#include <unistd.h>
#include <errno.h>
#include <openssl/err.h>
#include <sstream>
#include "pqi/pqissllistener.h"
#include "pqi/p3linkmgr.h"
@ -66,10 +61,6 @@ const int PQISSL_REMOTE_FLAG = 0x02;
const int PQISSL_UDP_FLAG = 0x02;
***********/
static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
static const time_t PQISSL_MAX_READ_ZERO_TIME = 15; // 15 seconds of no data => reset. (atm HeartBeat pkt sent 5 secs)
@ -115,11 +106,7 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3LinkMgr *lm)
sockaddr_clear(&remote_addr);
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl for PeerId: " << PeerId();
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
}
rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl for PeerId: " + PeerId());
#endif
#if 0
@ -203,7 +190,7 @@ int pqissl::close()
// put back on the listening queue.
int pqissl::reset()
{
std::ostringstream outLog;
std::string outLog;
/* a reset shouldn't cause us to stop listening
* only reasons for stoplistening() are;
@ -214,13 +201,13 @@ int pqissl::reset()
*
*/
outLog << "pqissl::reset():" << PeerId();
outLog << " (A: " << (int) active;
outLog << " FD: " << sockfd;
outLog << " W: " << waiting;
outLog << " SSL: " << ssl_connection << ") ";
outLog += "pqissl::reset():" + PeerId();
rs_sprintf_append(outLog, " (A: %d", (int) active);
rs_sprintf_append(outLog, " FD: %d", sockfd);
rs_sprintf_append(outLog, " W: %d", waiting);
rs_sprintf_append(outLog, " SSL: %p) ", ssl_connection);
#ifdef PQISSL_LOG_DEBUG
outLog << std::endl;
outLog += "\n";
#endif
bool neededReset = false;
@ -238,8 +225,7 @@ int pqissl::reset()
if (sockfd > 0)
{
#ifdef PQISSL_LOG_DEBUG
outLog << "pqissl::reset() Shutting down (active) socket";
outLog << std::endl;
outLog += "pqissl::reset() Shutting down (active) socket\n";
#endif
net_internal_close(sockfd);
sockfd = -1;
@ -258,13 +244,12 @@ int pqissl::reset()
if (neededReset)
{
#ifdef PQISSL_LOG_DEBUG
outLog << "pqissl::reset() Reset Required!" << std::endl;
outLog << "pqissl::reset() Will Attempt notifyEvent(FAILED)";
outLog << std::endl;
outLog += "pqissl::reset() Reset Required!\n";
outLog += "pqissl::reset() Will Attempt notifyEvent(FAILED)\n";
#endif
}
rslog(RSL_ALERT, pqisslzone, outLog.str());
rslog(RSL_ALERT, pqisslzone, outLog);
// notify people of problem!
// but only if we really shut something down.
@ -283,20 +268,18 @@ bool pqissl::connect_parameter(uint32_t type, uint32_t value)
{
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl::connect_parameter() Peer: " << PeerId();
out << " type: " << type << "value: " << value;
rslog(RSL_DEBUG_ALL, pqisslzone, out.str());
std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
rs_sprintf_append(out, " type: %u value: %u", type, value);
rslog(RSL_DEBUG_ALL, pqisslzone, out);
}
#endif
if (type == NET_PARAM_CONNECT_DELAY)
{
#ifdef PQISSL_LOG_DEBUG
std::ostringstream out;
out << "pqissl::connect_parameter() Peer: " << PeerId();
out << " DELAY: " << value;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
rs_sprintf_append(out, " DELAY: %u", value);
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif
@ -306,10 +289,9 @@ bool pqissl::connect_parameter(uint32_t type, uint32_t value)
else if (type == NET_PARAM_CONNECT_TIMEOUT)
{
#ifdef PQISSL_LOG_DEBUG
std::ostringstream out;
out << "pqissl::connect_parameter() Peer: " << PeerId();
out << " TIMEOUT: " << value;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
rs_sprintf_append(out, " TIMEOUT: %u", value);
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif
mConnectTimeout = value;
@ -337,32 +319,26 @@ int pqissl::status()
{
#ifdef PQISSL_LOG_DEBUG
std::ostringstream out;
out << "pqissl::status()";
std::string out = "pqissl::status()";
if (active)
{
int alg;
out << " active: " << std::endl;
out += " active: \n";
// print out connection.
out << "Connected TO : " << PeerId();
out << std::endl;
out += "Connected TO : " + PeerId() + "\n";
// print out cipher.
out << "\t\tSSL Cipher:" << SSL_get_cipher(ssl_connection);
out << " (" << SSL_get_cipher_bits(ssl_connection, &alg);
out << ":" << alg << ") ";
out << "Vers:" << SSL_get_cipher_version(ssl_connection);
out << std::endl;
out << std::endl;
rs_sprintf_append(out, "\t\tSSL Cipher:%s", SSL_get_cipher(ssl_connection));
rs_sprintf_append(out, " (%d:%d)", SSL_get_cipher_bits(ssl_connection, &alg), alg);
rs_sprintf_append(out, "Vers:%s\n\n", SSL_get_cipher_version(ssl_connection));
}
else
{
out << " Waiting for connection!" << std::endl;
out += " Waiting for connection!\n";
}
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif
if (active)
@ -388,13 +364,10 @@ int pqissl::tick()
if (waiting > 0)
{
#ifdef PQISSL_LOG_DEBUG
std::ostringstream out;
out << "pqissl::tick() ";
out << "Continuing Connection Attempt!";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::tick() Continuing Connection Attempt!");
#endif
ConnectAttempt();
ConnectAttempt();
return 1;
}
}
@ -544,17 +517,12 @@ int pqissl::Delay_Connection()
*/
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl::Delay_Connection() ";
out << " Delaying Connection to ";
out << PeerId() << " for ";
out << mConnectDelay;
out << " seconds";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Delay_Connection() Delaying Connection to %s for %lu seconds", PeerId().c_str(), mConnectDelay);
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
}
#endif
mConnectTS = time(NULL) + mConnectDelay;
return 0;
}
@ -562,13 +530,9 @@ int pqissl::Delay_Connection()
{
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl::Delay_Connection() ";
out << " Connection to ";
out << PeerId() << " starting in ";
out << mConnectTS - time(NULL);
out << " seconds";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Delay_Connection() Connection to %s starting in %ld seconds", PeerId().c_str(), mConnectTS - time(NULL));
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
}
#endif
@ -612,19 +576,17 @@ int pqissl::Initiate_Connection()
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl::Initiate_Connection() osock = " << osock;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() osock = %d", osock);
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
}
#endif
if (osock < 0)
{
std::ostringstream out;
out << "pqissl::Initiate_Connection()";
out << "Failed to open socket!" << std::endl;
out << "Socket Error:" << socket_errorType(errno) << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out = "pqissl::Initiate_Connection() Failed to open socket!\n";
out += "Socket Error:" + socket_errorType(errno);
rslog(RSL_WARNING, pqisslzone, out);
net_internal_close(osock);
waiting = WAITING_FAIL_INTERFACE;
@ -639,11 +601,9 @@ int pqissl::Initiate_Connection()
err = unix_fcntl_nonblock(osock);
if (err < 0)
{
std::ostringstream out;
out << "pqissl::Initiate_Connection()";
out << "Error: Cannot make socket NON-Blocking: ";
out << err << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() Error: Cannot make socket NON-Blocking: %d", err);
rslog(RSL_WARNING, pqisslzone, out);
waiting = WAITING_FAIL_INTERFACE;
net_internal_close(osock);
@ -651,23 +611,14 @@ int pqissl::Initiate_Connection()
}
{
std::ostringstream out;
out << "pqissl::Initiate_Connection() ";
out << "Connecting To: ";
out << PeerId() << " via: ";
out << rs_inet_ntoa(addr.sin_addr);
out << ":" << ntohs(addr.sin_port);
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() Connecting To: %s via: %s:%u", PeerId().c_str(), rs_inet_ntoa(addr.sin_addr).c_str(), ntohs(addr.sin_port));
rslog(RSL_WARNING, pqisslzone, out);
}
if (addr.sin_addr.s_addr == 0)
{
std::ostringstream out;
out << "pqissl::Initiate_Connection() ";
out << "Invalid (0.0.0.0) Remote Address,";
out << " Aborting Connect.";
out << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Invalid (0.0.0.0) Remote Address, Aborting Connect.");
waiting = WAITING_FAIL_INTERFACE;
net_internal_close(osock);
return -1;
@ -725,10 +676,8 @@ int pqissl::Initiate_Connection()
if (0 != (err = unix_connect(osock, (struct sockaddr *) &addr, sizeof(addr))))
{
std::ostringstream out;
out << "pqissl::Initiate_Connection() connect returns:";
out << err << " -> errno: " << errno << " error: ";
out << socket_errorType(errno) << std::endl;
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() connect returns:%d -> errno: %d error: %s\n", err, errno, socket_errorType(errno).c_str());
if (errno == EINPROGRESS)
{
@ -737,16 +686,16 @@ int pqissl::Initiate_Connection()
sockfd = osock;
#ifdef PQISSL_LOG_DEBUG
out << " EINPROGRESS Waiting for Socket Connection";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
out += " EINPROGRESS Waiting for Socket Connection";
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif
return 0;
}
else if ((errno == ENETUNREACH) || (errno == ETIMEDOUT))
{
out << "ENETUNREACHABLE: cert: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
out += "ENETUNREACHABLE: cert: " + PeerId();
rslog(RSL_WARNING, pqisslzone, out);
// Then send unreachable message.
net_internal_close(osock);
@ -763,14 +712,13 @@ int pqissl::Initiate_Connection()
* Known reasons to get here: EINVAL (bad address)
*/
out << "Error: Connection Failed: " << errno;
out << " - " << socket_errorType(errno) << std::endl;
rs_sprintf_append(out, "Error: Connection Failed: %d - %s", errno, socket_errorType(errno).c_str());
net_internal_close(osock);
osock=-1;
waiting = WAITING_FAIL_INTERFACE;
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, out);
// extra output for the moment.
//std::cerr << out.str();
@ -820,12 +768,10 @@ int pqissl::Basic_Connection_Complete()
/* new TimeOut code. */
if (time(NULL) > mTimeoutTS)
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete() Connection Timed Out. ";
out << "Peer: " << PeerId() << " Period: ";
out << mConnectTimeout;
std::string out;
rs_sprintf(out, "pqissl::Basic_Connection_Complete() Connection Timed Out. Peer: %s Period: %lu", PeerId().c_str(), mConnectTimeout);
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, out);
/* as sockfd is valid, this should close it all up */
rslog(RSL_ALERT, pqisslzone, "pqissl::Basic_Connection_Complete() -> calling reset()");
@ -888,10 +834,9 @@ int pqissl::Basic_Connection_Complete()
#ifdef PQISSL_LOG_DEBUG
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete() Select ";
out << " returned " << sr;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Basic_Connection_Complete() Select returned %d", sr);
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
}
#endif
@ -949,34 +894,22 @@ int pqissl::Basic_Connection_Complete()
{
if (err == 0)
{
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " TCP Connection Complete: cert: ";
out << PeerId();
out << " on osock: " << sockfd;
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::Basic_Connection_Complete() TCP Connection Complete: cert: %s on osock: ", PeerId().c_str(), sockfd);
rslog(RSL_WARNING, pqisslzone, out);
}
return 1;
}
else if (err == EINPROGRESS)
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " EINPROGRESS: cert: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() EINPROGRESS: cert: " + PeerId());
return 0;
}
else if ((err == ENETUNREACH) || (err == ETIMEDOUT))
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " ENETUNREACH/ETIMEDOUT: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() ENETUNREACH/ETIMEDOUT: cert: " + PeerId());
// Then send unreachable message.
net_internal_close(sockfd);
@ -989,11 +922,7 @@ int pqissl::Basic_Connection_Complete()
}
else if ((err == EHOSTUNREACH) || (err == EHOSTDOWN))
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " EHOSTUNREACH/EHOSTDOWN: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() EHOSTUNREACH/EHOSTDOWN: cert: " + PeerId());
// Then send unreachable message.
net_internal_close(sockfd);
@ -1005,11 +934,7 @@ int pqissl::Basic_Connection_Complete()
}
else if ((err == ECONNREFUSED))
{
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " ECONNREFUSED: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() ECONNREFUSED: cert: " + PeerId());
// Then send unreachable message.
net_internal_close(sockfd);
@ -1020,10 +945,9 @@ int pqissl::Basic_Connection_Complete()
return -1;
}
std::ostringstream out;
out << "Error: Connection Failed UNKNOWN ERROR: " << err;
out << " - " << socket_errorType(err);
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "Error: Connection Failed UNKNOWN ERROR: %d - %s", err, socket_errorType(err).c_str());
rslog(RSL_WARNING, pqisslzone, out);
net_internal_close(sockfd);
sockfd=-1;
@ -1083,13 +1007,10 @@ int pqissl::Initiate_SSL_Connection()
net_internal_SSL_set_fd(ssl, sockfd);
if (err < 1)
{
std::ostringstream out;
out << "pqissl::Initiate_SSL_Connection() SSL_set_fd failed!";
out << std::endl;
printSSLError(ssl, err, SSL_get_error(ssl, err),
ERR_get_error(), out);
std::string out = "pqissl::Initiate_SSL_Connection() SSL_set_fd failed!\n";
printSSLError(ssl, err, SSL_get_error(ssl, err), ERR_get_error(), out);
rslog(RSL_ALERT, pqisslzone, out.str());
rslog(RSL_ALERT, pqisslzone, out);
}
#ifdef PQISSL_LOG_DEBUG
@ -1162,14 +1083,11 @@ int pqissl::SSL_Connection_Complete()
}
std::ostringstream out;
out << "pqissl::SSL_Connection_Complete()" << std::endl;
out << "Issues with SSL Connect(" << err << ")!" << std::endl;
printSSLError(ssl_connection, err, serr,
ERR_get_error(), out);
std::string out;
rs_sprintf(out, "pqissl::SSL_Connection_Complete()\nIssues with SSL Connect(%d)!\n", err);
printSSLError(ssl_connection, err, serr, ERR_get_error(), out);
rslog(RSL_WARNING, pqisslzone,
out.str());
rslog(RSL_WARNING, pqisslzone, out);
// attempt real error.
Extract_Failed_SSL_Certificate();
@ -1182,11 +1100,7 @@ int pqissl::SSL_Connection_Complete()
}
// if we get here... success v quickly.
{
std::ostringstream out;
out << "pqissl::SSL_Connection_Complete() Success!: Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
}
rslog(RSL_WARNING, pqisslzone, "pqissl::SSL_Connection_Complete() Success!: Peer: " + PeerId());
waiting = WAITING_SSL_AUTHORISE;
return 1;
@ -1310,20 +1224,13 @@ int pqissl::Authorise_SSL_Connection()
if (certCorrect)
{
// then okay...
std::ostringstream out;
out << "pqissl::Authorise_SSL_Connection() Accepting Conn. Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, "pqissl::Authorise_SSL_Connection() Accepting Conn. Peer: " + PeerId());
accept(ssl_connection, sockfd, remote_addr);
return 1;
}
{
std::ostringstream out;
out << "pqissl::Authorise_SSL_Connection() Something Wrong ... ";
out << " Shutdown. Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
}
rslog(RSL_WARNING, pqisslzone, "pqissl::Authorise_SSL_Connection() Something Wrong ... Shutdown. Peer: " + PeerId());
// else shutdown ssl connection.
rslog(RSL_ALERT, pqisslzone, "pqissl::Authorise_Connection_Complete() -> calling reset()");
@ -1336,12 +1243,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
{
if (waiting != WAITING_NOT)
{
{
std::ostringstream out;
out << "pqissl::accept() Peer: " << PeerId();
out << " - Two connections in progress - Shut 1 down!";
rslog(RSL_WARNING, pqisslzone, out.str());
}
rslog(RSL_WARNING, pqisslzone, "pqissl::accept() Peer: " + PeerId() + " - Two connections in progress - Shut 1 down!");
// outgoing connection in progress.
// shut this baby down.
@ -1435,21 +1337,20 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(localaddr.sin_addr));
{
std::ostringstream out;
out << "pqissl::accept() SUCCESSFUL connection to: " << PeerId();
out << " localaddr: " << rs_inet_ntoa(localaddr.sin_addr);
out << " remoteaddr: " << rs_inet_ntoa(remote_addr.sin_addr);
std::string out = "pqissl::accept() SUCCESSFUL connection to: " + PeerId();
out += " localaddr: " + rs_inet_ntoa(localaddr.sin_addr);
out += " remoteaddr: " + rs_inet_ntoa(remote_addr.sin_addr);
if (sameLAN)
{
out << " SAME LAN";
}
else
{
out << " DIFF LANs";
}
if (sameLAN)
{
out += " SAME LAN";
}
else
{
out += " DIFF LANs";
}
rslog(RSL_WARNING, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, out);
}
// establish the ssl details.
@ -1459,12 +1360,11 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
#ifdef PQISSL_LOG_DEBUG
{
int alg;
std::ostringstream out;
out << "SSL Cipher:" << SSL_get_cipher(ssl) << std::endl;
out << "SSL Cipher Bits:" << SSL_get_cipher_bits(ssl, &alg);
out << " - " << alg << std::endl;
out << "SSL Cipher Version:" << SSL_get_cipher_version(ssl) << std::endl;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "SSL Cipher:%s\n", SSL_get_cipher(ssl));
rs_sprintf_append(out, "SSL Cipher Bits:%d - %d\n", SSL_get_cipher_bits(ssl, &alg), alg);
rs_sprintf_append(out, "SSL Cipher Version:%s\n", SSL_get_cipher_version(ssl));
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
}
#endif
@ -1517,43 +1417,35 @@ int pqissl::senddata(void *data, int len)
if (len != tmppktlen)
{
std::ostringstream out;
out << "pqissl::senddata() " << PeerId();
out << " Partial Send: ";
out << "len: " << len << " sent: ";
out << tmppktlen << " ";
std::string out = "pqissl::senddata() " + PeerId();
rs_sprintf_append(out, " Partial Send: len: %d sent: %d ", len, tmppktlen);
int err = SSL_get_error(ssl_connection, tmppktlen);
// incomplete operations - to repeat....
// handled by the pqistreamer...
if (err == SSL_ERROR_SYSCALL)
{
out << "SSL_write() SSL_ERROR_SYSCALL ";
out << "SOCKET_DEAD -> calling reset()";
out << " errno: " << errno;
out << " " << socket_errorType(errno);
std::cerr << out.str() << std::endl;
rslog(RSL_ALERT, pqisslzone, out.str());
rs_sprintf_append(out, "SSL_write() SSL_ERROR_SYSCALL SOCKET_DEAD -> calling reset() errno: %d ", errno);
out += socket_errorType(errno);
std::cerr << out << std::endl;
rslog(RSL_ALERT, pqisslzone, out);
/* extra debugging - based on SSL_get_error() man page */
{
int errsys = errno;
int sslerr = 0;
std::ostringstream out2;
out2 << "SSL_ERROR_SYSCALL, ret == " << tmppktlen;
out2 << " errno: " << errsys;
out2 << " " << socket_errorType(errsys);
out2 << std::endl;
std::string out2;
rs_sprintf(out2, "SSL_ERROR_SYSCALL, ret == %d errno: %d %s\n", tmppktlen, errsys, socket_errorType(errsys).c_str());
while(0 != (sslerr = ERR_get_error()))
{
out2 << "SSLERR:" << sslerr << " : ";
rs_sprintf_append(out2, "SSLERR:%d:", sslerr);
char sslbuf[256] = {0};
out2 << ERR_error_string(sslerr, sslbuf);
out2 << std::endl;
out2 += ERR_error_string(sslerr, sslbuf);
out2 += "\n";
}
rslog(RSL_ALERT, pqisslzone, out2.str());
rslog(RSL_ALERT, pqisslzone, out2);
}
rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()");
@ -1562,27 +1454,24 @@ int pqissl::senddata(void *data, int len)
}
else if (err == SSL_ERROR_WANT_WRITE)
{
out << "SSL_write() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out.str());
out += "SSL_write() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out);
return -1;
}
else if (err == SSL_ERROR_WANT_READ)
{
out << "SSL_write() SSL_ERROR_WANT_READ";
rslog(RSL_WARNING, pqisslzone, out.str());
//std::cerr << out.str() << std::endl;
out += "SSL_write() SSL_ERROR_WANT_READ";
rslog(RSL_WARNING, pqisslzone, out);
//std::cerr << out << std::endl;
return -1;
}
else
{
out << "SSL_write() UNKNOWN ERROR: " << err;
out << std::endl;
rs_sprintf_append(out, "SSL_write() UNKNOWN ERROR: %d\n", err);
printSSLError(ssl_connection, tmppktlen, err, ERR_get_error(), out);
out << std::endl;
out << "\tResetting!";
out << std::endl;
std::cerr << out.str() ;
rslog(RSL_ALERT, pqisslzone, out.str());
out += "\n\tResetting!";
std::cerr << out << std::endl;
rslog(RSL_ALERT, pqisslzone, out);
rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()");
reset();
@ -1626,7 +1515,7 @@ int pqissl::readdata(void *data, int len)
//
if (tmppktlen <= 0) // probably needs a reset.
{
std::ostringstream out;
std::string out;
int error = SSL_get_error(ssl_connection, tmppktlen);
unsigned long err2 = ERR_get_error();
@ -1655,65 +1544,62 @@ int pqissl::readdata(void *data, int len)
}
++n_read_zero;
out << "pqissl::readdata() " << PeerId();
out << " SSL_read() SSL_ERROR_ZERO_RETURN : nReadZero: " << n_read_zero;
out += "pqissl::readdata() " + PeerId();
rs_sprintf_append(out, " SSL_read() SSL_ERROR_ZERO_RETURN : nReadZero: %d", n_read_zero);
if ((PQISSL_MAX_READ_ZERO_COUNT < n_read_zero)
&& (time(NULL) - mReadZeroTS > PQISSL_MAX_READ_ZERO_TIME))
{
out << "Count passed Limit, shutting down!";
out << " ReadZero Age: " << time(NULL) - mReadZeroTS;
out += " Count passed Limit, shutting down!";
rs_sprintf_append(out, " ReadZero Age: %ld", time(NULL) - mReadZeroTS);
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset();
}
rslog(RSL_ALERT, pqisslzone, out.str());
std::cerr << out.str() << std::endl ;
rslog(RSL_ALERT, pqisslzone, out);
std::cerr << out << std::endl ;
return -1;
}
/* the only real error we expect */
if (error == SSL_ERROR_SYSCALL)
{
out << "pqissl::readdata() " << PeerId();
out << " SSL_read() SSL_ERROR_SYSCALL";
out << " SOCKET_DEAD -> calling reset()";
out << " errno: " << errno;
out << " " << socket_errorType(errno);
rslog(RSL_ALERT, pqisslzone, out.str());
out += "pqissl::readdata() " + PeerId();
out += " SSL_read() SSL_ERROR_SYSCALL";
out += " SOCKET_DEAD -> calling reset()";
rs_sprintf_append(out, " errno: %d", errno);
out += " " + socket_errorType(errno);
rslog(RSL_ALERT, pqisslzone, out);
/* extra debugging - based on SSL_get_error() man page */
{
int syserr = errno;
int sslerr = 0;
std::ostringstream out2;
out2 << "SSL_ERROR_SYSCALL, ret == " << tmppktlen;
out2 << " errno: " << syserr;
out2 << " " << socket_errorType(syserr);
out2 << std::endl;
std::string out2;
rs_sprintf(out2, "SSL_ERROR_SYSCALL, ret == %d errno: %d %s\n", tmppktlen, syserr, socket_errorType(syserr).c_str());
while(0 != (sslerr = ERR_get_error()))
{
out2 << "SSLERR:" << sslerr << " : ";
rs_sprintf_append(out2, "SSLERR:%d : ", sslerr);
char sslbuf[256] = {0};
out2 << ERR_error_string(sslerr, sslbuf);
out2 << std::endl;
out2 += ERR_error_string(sslerr, sslbuf);
out2 += "\n";
}
rslog(RSL_ALERT, pqisslzone, out2.str());
rslog(RSL_ALERT, pqisslzone, out2);
}
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset();
std::cerr << out.str() << std::endl ;
std::cerr << out << std::endl ;
return -1;
}
else if (error == SSL_ERROR_WANT_WRITE)
{
out << "SSL_read() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out.str());
std::cerr << out.str() << std::endl ;
out += "SSL_read() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out);
std::cerr << out << std::endl ;
return -1;
}
else if (error == SSL_ERROR_WANT_READ)
@ -1724,25 +1610,23 @@ int pqissl::readdata(void *data, int len)
// call of readdata().
#ifdef PQISSL_DEBUG
out << "SSL_read() SSL_ERROR_WANT_READ";
out << std::endl;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
out += "SSL_read() SSL_ERROR_WANT_READ";
rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif
return -1;
}
else
{
out << "SSL_read() UNKNOWN ERROR: " << error;
out << " Resetting!";
rslog(RSL_ALERT, pqisslzone, out.str());
std::cerr << out.str() << std::endl ;
rs_sprintf_append(out, "SSL_read() UNKNOWN ERROR: %d Resetting!", error);
rslog(RSL_ALERT, pqisslzone, out);
std::cerr << out << std::endl ;
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset();
return -1;
}
rslog(RSL_ALERT, pqisslzone, out.str());
rslog(RSL_ALERT, pqisslzone, out);
//exit(1);
}
else
@ -1755,13 +1639,10 @@ int pqissl::readdata(void *data, int len)
if (len != total_len)
{
std::ostringstream out;
out << "pqissl::readdata()";
out << " Full Packet Not read!" << std::endl;
out << " -> Expected len(" << len << ") actually read(";
out << total_len << ")" << std::endl;
std::cerr << out.str() ;
rslog(RSL_WARNING, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::readdata() Full Packet Not read!\n -> Expected len(%d) actually read(%d)", len, total_len);
std::cerr << out << std::endl;
rslog(RSL_WARNING, pqisslzone, out);
}
total_len = 0 ; // reset the packet pointer as we have finished a packet.
n_read_zero = 0;
@ -1784,10 +1665,9 @@ bool pqissl::moretoread()
{
#ifdef PQISSL_DEBUG
{
std::ostringstream out;
out << "pqissl::moretoread()";
out << " polling socket (" << sockfd << ")";
rslog(RSL_DEBUG_ALL, pqisslzone, out.str());
std::string out;
rs_sprintf(out, "pqissl::moretoread() polling socket (%d)", sockfd);
rslog(RSL_DEBUG_ALL, pqisslzone, out);
}
#endif

View File

@ -23,10 +23,6 @@
*
*/
#include "pqi/pqissl.h"
#include "pqi/pqissllistener.h"
#include "pqi/pqinetwork.h"
@ -38,7 +34,7 @@
#include <openssl/err.h>
#include "util/rsdebug.h"
#include <sstream>
#include "util/rsstring.h"
#include <unistd.h>
const int pqissllistenzone = 49787;
@ -90,15 +86,12 @@ int pqissllistenbase::tick()
int pqissllistenbase::status()
{
std::ostringstream out;
out << "pqissllistenbase::status(): ";
out << " Listening on port: " << ntohs(laddr.sin_port) << std::endl;
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "pqissllistenbase::status(): Listening on port: %u", ntohs(laddr.sin_port));
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out);
return 1;
}
int pqissllistenbase::setuplisten()
{
int err;
@ -119,10 +112,9 @@ int pqissllistenbase::setuplisten()
err = fcntl(lsock, F_SETFL, O_NONBLOCK);
if (err < 0)
{
std::ostringstream out;
out << "Error: Cannot make socket NON-Blocking: ";
out << err << std::endl;
pqioutput(PQL_ERROR, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "Error: Cannot make socket NON-Blocking: %d", err);
pqioutput(PQL_ERROR, pqissllistenzone, out);
return -1;
}
@ -131,12 +123,9 @@ int pqissllistenbase::setuplisten()
#else //WINDOWS_SYS
if ((unsigned) lsock == INVALID_SOCKET)
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << " Cannot Open Socket!" << std::endl;
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::string out = "pqissllistenbase::setuplisten() Cannot Open Socket!\n";
out += "Socket Error: "+ socket_errorType(WSAGetLastError());
pqioutput(PQL_ALERT, pqissllistenzone, out);
return -1;
}
@ -145,13 +134,10 @@ int pqissllistenbase::setuplisten()
unsigned long int on = 1;
if (0 != (err = ioctlsocket(lsock, FIONBIO, &on)))
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << "Error: Cannot make socket NON-Blocking: ";
out << err << std::endl;
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "pqissllistenbase::setuplisten() Error: Cannot make socket NON-Blocking: %d\n", err);
out += "Socket Error: " + socket_errorType(WSAGetLastError());
pqioutput(PQL_ALERT, pqissllistenzone, out);
return -1;
}
@ -165,15 +151,12 @@ int pqissllistenbase::setuplisten()
laddr.sin_family = AF_INET;
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << "\tAddress Family: " << (int) laddr.sin_family;
out << std::endl;
out << "\tSetup Address: " << rs_inet_ntoa(laddr.sin_addr);
out << std::endl;
out << "\tSetup Port: " << ntohs(laddr.sin_port);
std::string out = "pqissllistenbase::setuplisten()\n";
rs_sprintf_append(out, "\tAddress Family: %d\n", (int) laddr.sin_family);
rs_sprintf_append(out, "\tSetup Address: %s\n", rs_inet_ntoa(laddr.sin_addr).c_str());
rs_sprintf_append(out, "\tSetup Port: %u", ntohs(laddr.sin_port));
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
//std::cerr << out.str() << std::endl;
}
@ -192,12 +175,10 @@ int pqissllistenbase::setuplisten()
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << " Cannot setsockopt SO_REUSEADDR!" << std::endl;
std::string out = "pqissllistenbase::setuplisten() Cannot setsockopt SO_REUSEADDR!\n";
showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::cerr << out.str() << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out << std::endl;
exit(1);
}
@ -211,12 +192,10 @@ int pqissllistenbase::setuplisten()
if (0 != (err = bind(lsock, (struct sockaddr *) &laddr, sizeof(laddr))))
#endif
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << " Cannot Bind to Local Address!" << std::endl;
std::string out = "pqissllistenbase::setuplisten() Cannot Bind to Local Address!\n";
showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::cerr << out.str() << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out << std::endl;
exit(1);
return -1;
@ -271,13 +250,11 @@ int pqissllistenbase::setuplisten()
if (0 != (err = listen(lsock, 100)))
{
std::ostringstream out;
out << "pqissllistenbase::setuplisten()";
out << "Error: Cannot Listen to Socket: ";
out << err << std::endl;
std::string out;
rs_sprintf(out, "pqissllistenbase::setuplisten() Error: Cannot Listen to Socket: %d\n", err);
showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::cerr << out.str() << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out << std::endl;
exit(1);
return -1;
@ -345,11 +322,9 @@ int pqissllistenbase::acceptconnection()
err = fcntl(fd, F_SETFL, O_NONBLOCK);
if (err < 0)
{
std::ostringstream out;
out << "pqissllistenbase::acceptconnection()";
out << "Error: Cannot make socket NON-Blocking: ";
out << err << std::endl;
pqioutput(PQL_ERROR, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "pqissllistenbase::acceptconnection() Error: Cannot make socket NON-Blocking: %d", err);
pqioutput(PQL_ERROR, pqissllistenzone, out;
close(fd);
return -1;
@ -368,13 +343,10 @@ int pqissllistenbase::acceptconnection()
unsigned long int on = 1;
if (0 != (err = ioctlsocket(fd, FIONBIO, &on)))
{
std::ostringstream out;
out << "pqissllistenbase::acceptconnection()";
out << "Error: Cannot make socket NON-Blocking: ";
out << err << std::endl;
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "pqissllistenbase::acceptconnection() Error: Cannot make socket NON-Blocking: %d\n", err);
out += "Socket Error:" + socket_errorType(WSAGetLastError());
pqioutput(PQL_ALERT, pqissllistenzone, out);
closesocket(fd);
return 0;
@ -383,16 +355,15 @@ int pqissllistenbase::acceptconnection()
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
{
std::ostringstream out;
out << "Accepted Connection from ";
out << rs_inet_ntoa(remote_addr.sin_addr) << ":" << ntohs(remote_addr.sin_port);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "Accepted Connection from %s:%u", rs_inet_ntoa(remote_addr.sin_addr).c_str(), ntohs(remote_addr.sin_port));
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
}
// Negotiate certificates. SSL stylee.
// Allow negotiations for secure transaction.
SSL *ssl = SSL_new(AuthSSL::getAuthSSL() -> getCTX());
SSL *ssl = SSL_new(AuthSSL::getAuthSSL() -> getCTX());
SSL_set_fd(ssl, fd);
return continueSSL(ssl, remote_addr, true); // continue and save if incomplete.
@ -409,31 +380,26 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
int err_err = ERR_get_error();
{
std::ostringstream out;
out << "pqissllistenbase::continueSSL() ";
out << "Issues with SSL Accept(" << err << ")!" << std::endl;
printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
std::string out;
rs_sprintf(out, "pqissllistenbase::continueSSL() Issues with SSL Accept(%d)!\n", err);
printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
}
if ((ssl_err == SSL_ERROR_WANT_READ) ||
(ssl_err == SSL_ERROR_WANT_WRITE))
{
std::ostringstream out;
out << "pqissllistenbase::continueSSL() ";
out << " Connection Not Complete!";
out << std::endl;
std::string out = "pqissllistenbase::continueSSL() Connection Not Complete!\n";
if (addin)
{
out << "pqissllistenbase::continueSSL() ";
out << "Adding SSL to incoming!";
out += "pqissllistenbase::continueSSL() Adding SSL to incoming!";
// add to incomingqueue.
incoming_ssl[ssl] = remote_addr;
}
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
// zero means still continuing....
return 0;
@ -444,11 +410,7 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
closeConnection(fd, ssl);
std::ostringstream out;
out << "Read Error on the SSL Socket";
out << std::endl;
out << "Shutting it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
pqioutput(PQL_WARNING, pqissllistenzone, "Read Error on the SSL Socket\nShutting it down!");
// failure -1, pending 0, sucess 1.
return -1;
@ -466,9 +428,7 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
closeConnection(fd, ssl);
std::ostringstream out;
out << "Shutting it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
pqioutput(PQL_WARNING, pqissllistenzone, "Shutting it down!");
// failure -1, pending 0, sucess 1.
return -1;
@ -514,13 +474,11 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
if (peercert == NULL)
{
std::ostringstream out;
out << "pqissllistenbase::Extract_Failed_SSL_Certificate() from: ";
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
out << " ERROR Peer didn't give Cert!";
std::cerr << out.str() << std::endl;
std::string out;
rs_sprintf(out, "pqissllistenbase::Extract_Failed_SSL_Certificate() from: %s:%u ERROR Peer didn't give Cert!", rs_inet_ntoa(addr->sin_addr).c_str(), ntohs(addr->sin_port));
std::cerr << out << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
pqioutput(PQL_WARNING, pqissllistenzone, out);
return -1;
}
@ -528,15 +486,11 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
"pqissllistenbase::Extract_Failed_SSL_Certificate() Have Peer Cert - Registering");
{
std::ostringstream out;
std::string out;
rs_sprintf(out, "pqissllistenbase::Extract_Failed_SSL_Certificate() from: %s:%u Passing Cert to AuthSSL() for analysis", rs_inet_ntoa(addr->sin_addr).c_str(), ntohs(addr->sin_port));
std::cerr << out << std::endl;
out << "pqissllistenbase::Extract_Failed_SSL_Certificate() from: ";
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
out << " Passing Cert to AuthSSL() for analysis";
out << std::endl;
std::cerr << out.str() << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
pqioutput(PQL_WARNING, pqissllistenzone, out);
}
// save certificate... (and ip locations)
@ -639,21 +593,15 @@ int pqissllistenbase::isSSLActive(int /*fd*/, SSL *ssl)
int err_err = ERR_get_error();
{
std::ostringstream out;
out << "pqissllistenbase::isSSLActive() ";
out << "Issues with SSL_Accept(" << err << ")!" << std::endl;
std::string out;
rs_sprintf(out, "pqissllistenbase::isSSLActive() Issues with SSL_Accept(%d)!\n", err);
printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
}
if (ssl_err == SSL_ERROR_ZERO_RETURN)
{
std::ostringstream out;
out << "pqissllistenbase::isSSLActive() SSL_ERROR_ZERO_RETURN ";
out << " Connection state unknown";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, "pqissllistenbase::isSSLActive() SSL_ERROR_ZERO_RETURN Connection state unknown");
// zero means still continuing....
return 0;
@ -661,38 +609,27 @@ int pqissllistenbase::isSSLActive(int /*fd*/, SSL *ssl)
if ((ssl_err == SSL_ERROR_WANT_READ) ||
(ssl_err == SSL_ERROR_WANT_WRITE))
{
std::ostringstream out;
out << "pqissllistenbase::isSSLActive() SSL_ERROR_WANT_READ || SSL_ERROR_WANT_WRITE ";
out << " Connection state unknown";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, "pqissllistenbase::isSSLActive() SSL_ERROR_WANT_READ || SSL_ERROR_WANT_WRITE Connection state unknown");
// zero means still continuing....
return 0;
}
else
{
std::ostringstream out;
out << "pqissllistenbase::isSSLActive() ";
out << "Issues with SSL Peek(" << err << ") Likely the Connection was killed by Peer" << std::endl;
std::string out;
rs_sprintf(out, "pqissllistenbase::isSSLActive() Issues with SSL Peek(%d) Likely the Connection was killed by Peer\n", err);
printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
pqioutput(PQL_ALERT, pqissllistenzone, out);
return -1;
}
}
std::ostringstream out;
out << "pqissllistenbase::isSSLActive() Successful Peer -> Connection Okay";
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
pqioutput(PQL_WARNING, pqissllistenzone, "pqissllistenbase::isSSLActive() Successful Peer -> Connection Okay");
return 1;
}
/************************ PQI SSL LISTENER ****************************
*
* This is the standard pqissl listener interface....
@ -717,26 +654,21 @@ int pqissllistener::addlistenaddr(std::string id, pqissl *acc)
{
std::map<std::string, pqissl *>::iterator it;
std::ostringstream out;
out << "Adding to Cert Listening Addresses Id: " << id << std::endl;
out << "Current Certs:" << std::endl;
std::string out = "Adding to Cert Listening Addresses Id: " + id + "\nCurrent Certs:\n";
for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{
out << id << std::endl;
out += id + "\n";
if (it -> first == id)
{
out << "pqissllistener::addlistenaddr()";
out << "Already listening for Certificate!";
out << std::endl;
out += "pqissllistener::addlistenaddr() Already listening for Certificate!\n";
pqioutput(PQL_DEBUG_ALERT, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_ALERT, pqissllistenzone, out);
return -1;
}
}
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
// not there can accept it!
listenaddr[id] = acc;
@ -775,14 +707,13 @@ int pqissllistener::status()
// print certificates we are listening for.
std::map<std::string, pqissl *>::iterator it;
std::ostringstream out;
out << "pqissllistener::status(): ";
out << " Listening (" << ntohs(laddr.sin_port) << ") for Certs:" << std::endl;
std::string out = "pqissllistener::status(): ";
rs_sprintf(out, " Listening (%u) for Certs:", ntohs(laddr.sin_port));
for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{
out << it -> first << std::endl;
out += "\n" + it -> first ;
}
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out);
return 1;
}
@ -831,19 +762,16 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
}
else
{
std::ostringstream out;
out << "pqissllistener::continueSSL()" << std::endl;
out << "checking: " << newPeerId << std::endl;
std::string out = "pqissllistener::continueSSL()\nchecking: " + newPeerId + "\n";
// check if cert is in our list.....
for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());)
{
out << "\tagainst: " << it->first << std::endl;
out + "\tagainst: " + it->first + "\n";
if (it -> first == newPeerId)
{
// accept even if already connected.
out << "\t\tMatch!";
found = true;
out += "\t\tMatch!";
found = true;
}
else
{
@ -851,17 +779,13 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
}
}
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
}
if (found == false)
{
std::ostringstream out;
out << "No Matching Certificate";
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr);
out << std::endl;
out << "pqissllistenbase: Will shut it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
std::string out = "No Matching Certificate for Connection:" + rs_inet_ntoa(remote_addr.sin_addr) +"\npqissllistenbase: Will shut it down!";
pqioutput(PQL_WARNING, pqissllistenzone, out);
// but as it passed the authentication step,
// we can add it into the AuthSSL, and mConnMgr.
@ -889,46 +813,33 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
accepted_ssl.push_back(as);
std::ostringstream out;
out << "pqissllistener::completeConnection() Successful Connection with: " << newPeerId;
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr) << " Adding to WAIT-ACCEPT Queue";
out << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
std::string out = "pqissllistener::completeConnection() Successful Connection with: " + newPeerId;
out += " for Connection:" + rs_inet_ntoa(remote_addr.sin_addr) + " Adding to WAIT-ACCEPT Queue";
pqioutput(PQL_WARNING, pqissllistenzone, out);
return 1;
}
int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, struct sockaddr_in &remote_addr)
{
std::map<std::string, pqissl *>::iterator it;
std::ostringstream out;
out << "pqissllistener::finaliseConnection()" << std::endl;
out << "checking: " << peerId << std::endl;
std::string out = "pqissllistener::finaliseConnection()\n";
out += "checking: " + peerId + "\n";
// check if cert is in the list.....
it = listenaddr.find(peerId);
if (it == listenaddr.end())
{
out << "No Matching Peer";
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr);
out << std::endl;
out << "pqissllistener => Shutting Down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
out += "No Matching Peer for Connection:" + rs_inet_ntoa(remote_addr.sin_addr);
out += "\npqissllistener => Shutting Down!";
pqioutput(PQL_WARNING, pqissllistenzone, out);
return -1;
}
out << "Found Matching Peer";
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr);
out << std::endl;
out << "pqissllistener => Passing to pqissl module!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
out += "Found Matching Peer for Connection:" + rs_inet_ntoa(remote_addr.sin_addr);
out += "\npqissllistener => Passing to pqissl module!";
pqioutput(PQL_WARNING, pqissllistenzone, out);
// hand off ssl conection.
pqissl *pqis = it -> second;
@ -936,7 +847,3 @@ int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, str
return 1;
}

View File

@ -45,8 +45,8 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include "util/rsdebug.h"
#include "util/rsstring.h"
//
// #define PQISTORE_DEBUG
@ -58,20 +58,12 @@ pqistore::pqistore(RsSerialiser *rss, const std::string &srcId, BinInterface *bi
:PQInterface(""), rsSerialiser(rss), bio_flags(bio_flags_in),
nextPkt(NULL), mSrcId(srcId), bio(bio_in)
{
{
std::ostringstream out;
out << "pqistore::pqistore()";
out << " Initialisation!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::pqistore() Initialisation!");
if (!bio_in)
{
std::ostringstream out;
out << "pqistore::pqistore()";
out << " NULL bio, FATAL ERROR!" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
exit(1);
{
pqioutput(PQL_ALERT, pqistorezone, "pqistore::pqistore() NULL bio, FATAL ERROR!");
exit(1);
}
return;
@ -79,28 +71,17 @@ pqistore::pqistore(RsSerialiser *rss, const std::string &srcId, BinInterface *bi
pqistore::~pqistore()
{
{
std::ostringstream out;
out << "pqistore::~pqistore()";
out << " Destruction!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Destruction!");
if (bio_flags & BIN_FLAGS_NO_CLOSE)
{
std::ostringstream out;
out << "pqistore::~pqistore()";
out << " Not Closing BinInterface!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Not Closing BinInterface!;");
}
else if (bio)
{
std::ostringstream out;
out << "pqistore::~pqistore()";
out << " Deleting BinInterface!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Deleting BinInterface!");
delete bio;
delete bio;
}
if (rsSerialiser)
@ -119,10 +100,9 @@ int pqistore::SendItem(RsItem *si)
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::SendItem()" << std::endl;
std::string out = "pqistore::SendItem()\n";
si -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
}
#endif
@ -144,21 +124,14 @@ int pqistore::SendItem(RsItem *si)
RsItem *pqistore::GetItem()
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::GetItem()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::GetItem()");
#endif
// check if this is a reading bio.
if (!(bio_flags & BIN_FLAGS_READABLE))
{
#ifdef PQISTORE_DEBUG
std::ostringstream out;
out << "pqistore::GetItem()";
out << "Error Not Readable" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Error Not Readable");
#endif
return NULL;
}
@ -168,10 +141,7 @@ RsItem *pqistore::GetItem()
{
if (!readPkt(&nextPkt))
{
std::ostringstream out;
out << "pqistore::GetItem()";
out << "Failed to ReadPkt" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Failed to ReadPkt");
return NULL;
}
}
@ -184,10 +154,9 @@ RsItem *pqistore::GetItem()
#ifdef PQISTORE_DEBUG
if (outPkt != NULL)
{
std::ostringstream out;
out << "pqistore::GetItem() Returning:" << std::endl;
std::string out = "pqistore::GetItem() Returning:\n";
outPkt -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
}
#endif
return outPkt;
@ -200,11 +169,7 @@ RsItem *pqistore::GetItem()
int pqistore::tick()
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::tick()";
out << std::endl;
}
std::cerr << "pqistore::tick()" << std::endl;
#endif
return 0;
}
@ -212,11 +177,7 @@ int pqistore::tick()
int pqistore::status()
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::status()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::status()");
#endif
return 0;
}
@ -228,11 +189,7 @@ int pqistore::writePkt(RsItem *pqi)
{
// std::cerr << "writePkt, pqi->peerId()=" << pqi->PeerId() << std::endl ;
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::writePkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::writePkt()");
#endif
uint32_t pktsize = rsSerialiser->size(pqi);
@ -240,12 +197,9 @@ int pqistore::writePkt(RsItem *pqi)
if (!(rsSerialiser->serialise(pqi, ptr, &pktsize)))
{
#ifdef PQISTORE_DEBUG
std::ostringstream out;
out << "pqistore::writePkt() Null Pkt generated!";
out << std::endl;
out << "Caused By: " << std::endl;
std::string out = "pqistore::writePkt() Null Pkt generated!\nCaused By:\n";
pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
pqioutput(PQL_ALERT, pqistorezone, out);
#endif
free(ptr);
@ -258,13 +212,10 @@ int pqistore::writePkt(RsItem *pqi)
uint32_t len = getRsItemSize(ptr);
if (len != pktsize)
{
std::ostringstream out;
out << "pqistore::writePkt() Length MisMatch: len: " << len;
out << " != pktsize: " << pktsize;
out << std::endl;
out << "Caused By: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
std::string out;
rs_sprintf(out, "pqistore::writePkt() Length MisMatch: len: %u!= pktsize: %u\nCaused By:\n", len, pktsize);
pqi -> print_string(out);
pqioutput(PQL_ALERT, pqistorezone, out);
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
@ -275,12 +226,10 @@ int pqistore::writePkt(RsItem *pqi)
if (!(bio->cansend()))
{
std::ostringstream out;
out << "pqistore::writePkt() BIO cannot write!";
out << std::endl;
out << "Discarding: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
std::string out;
rs_sprintf(out, "pqistore::writePkt() BIO cannot write!\niscarding:\n");
pqi -> print_string(out);
pqioutput(PQL_ALERT, pqistorezone, out);
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
@ -290,16 +239,14 @@ int pqistore::writePkt(RsItem *pqi)
}
#ifdef PQISTORE_DEBUG
std::ostringstream out;
out << "Writing Pkt Body" << std::endl;
std::string out = "Writing Pkt Body";
#endif
// write packet.
if (len != (uint32_t) bio->senddata(ptr, len))
{
#ifdef PQISTORE_DEBUG
out << "Problems with Send Data!";
out << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
out += " Problems with Send Data!";
pqioutput(PQL_ALERT, pqistorezone, out);
#endif
free(ptr);
@ -310,8 +257,8 @@ int pqistore::writePkt(RsItem *pqi)
}
#ifdef PQISTORE_DEBUG
out << " Success!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
out += " Success!";
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
#endif
free(ptr);
@ -328,11 +275,7 @@ int pqistore::writePkt(RsItem *pqi)
int pqistore::readPkt(RsItem **item_out)
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::readPkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::readPkt()");
#endif
if ((!(bio->isactive())) || (!(bio->moretoread())))
@ -353,8 +296,7 @@ int pqistore::readPkt(RsItem **item_out)
// read the basic block (minimum packet size)
if (blen != (tmplen = bio->readdata(block, blen)))
{
pqioutput(PQL_WARNING, pqistorezone,
"pqistore::readPkt() bad read(2)");
pqioutput(PQL_WARNING, pqistorezone, "pqistore::readPkt() bad read(2)");
free(block);
return 0;
@ -379,12 +321,9 @@ int pqistore::readPkt(RsItem **item_out)
if (extralen != (tmplen = bio->readdata(extradata, extralen)))
{
std::ostringstream out;
out << "pqistore::readPkt() ";
out << "Error Completing Read (read ";
out << tmplen << "/" << extralen << ")" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
std::string out;
rs_sprintf(out, "pqistore::readPkt() Error Completing Read (read %d/%d)", tmplen, extralen);
pqioutput(PQL_ALERT, pqistorezone, out);
free(block);
return 0;
@ -401,8 +340,7 @@ int pqistore::readPkt(RsItem **item_out)
if (item == NULL)
{
pqioutput(PQL_ALERT, pqistorezone,
"pqistore::readPkt() Failed to create Item from store!");
pqioutput(PQL_ALERT, pqistorezone, "pqistore::readPkt() Failed to create Item from store!");
return 0;
}
@ -480,20 +418,13 @@ bool pqiSSLstore::getEncryptedItems(std::list<RsItem* >& rsItemList)
RsItem *pqiSSLstore::GetItem()
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::GetItem()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::GetItem()");
#endif
// check if this is a reading bio.
if (!(bio_flags & BIN_FLAGS_READABLE))
{
std::ostringstream out;
out << "pqistore::GetItem()";
out << "Error Not Readable" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Error Not Readable");
return NULL;
}
@ -502,10 +433,7 @@ RsItem *pqiSSLstore::GetItem()
{
if (!readPkt(&nextPkt))
{
std::ostringstream out;
out << "pqistore::GetItem()";
out << "Failed to ReadPkt" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Failed to ReadPkt");
return NULL;
}
}
@ -517,11 +445,11 @@ RsItem *pqiSSLstore::GetItem()
#ifdef PQISTORE_DEBUG
if (outPkt != NULL)
{
std::ostringstream out;
out << "pqistore::GetItem() Returning:" << std::endl;
outPkt -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
{
std::string out;
rs_sprintf(out, "pqistore::GetItem() Returning:\n");
outPkt -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
}
#endif
return outPkt;
@ -531,11 +459,7 @@ RsItem *pqiSSLstore::GetItem()
int pqiSSLstore::readPkt(RsItem **item_out)
{
#ifdef PQISTORE_DEBUG
{
std::ostringstream out;
out << "pqistore::readPkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::readPkt()");
#endif
if ((!(enc_bio->isactive())) || (!(enc_bio->moretoread())))
@ -582,12 +506,9 @@ int pqiSSLstore::readPkt(RsItem **item_out)
if (extralen != (tmplen = enc_bio->readdata(extradata, extralen)))
{
std::ostringstream out;
out << "pqistore::readPkt() ";
out << "Error Completing Read (read ";
out << tmplen << "/" << extralen << ")" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
std::string out;
rs_sprintf(out, "pqistore::readPkt() Error Completing Read (read %d/%d)", tmplen, extralen);
pqioutput(PQL_ALERT, pqistorezone, out);
free(block);
return 0;

View File

@ -33,6 +33,7 @@
#include "pqi/sslfns.h"
#include "pqi/pqi_base.h"
#include "util/rsdir.h"
#include "util/rsstring.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
@ -649,17 +650,16 @@ bool getX509id(X509 *x509, std::string &xid) {
// else copy in the first CERTSIGNLEN.
unsigned char *signdata = ASN1_STRING_data(signature);
std::ostringstream id;
xid.clear();
/* switched to the other end of the signature. for
* more randomness
*/
for(int i = signlen - CERTSIGNLEN; i < signlen; i++)
{
id << std::hex << std::setw(2) << std::setfill('0')
<< (uint16_t) (((uint8_t *) (signdata))[i]);
rs_sprintf_append(xid, "%02x", (uint16_t) (((uint8_t *) (signdata))[i]));
}
xid = id.str();
return true;
}
@ -875,8 +875,7 @@ std::string getX509Info(X509 *cert)
/********** SSL ERROR STUFF ******************************************/
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2,
std::ostream &out)
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::string &out)
{
(void) ssl; /* remove unused parameter warnings */
@ -919,9 +918,7 @@ int printSSLError(SSL *ssl, int retval, int err, unsigned long err2,
{
mainreason = std::string("SSL_ERROR_SSL");
}
out << "RetVal(" << retval;
out << ") -> SSL Error: " << mainreason << std::endl;
out << "\t + ERR Error: " << ERR_error_string(err2, NULL) << std::endl;
rs_sprintf_append(out, "RetVal(%d) -> SSL Error: %s\n\t + ERR Error: %s\n", retval, mainreason.c_str(), ERR_error_string(err2, NULL));
return 1;
}

View File

@ -126,8 +126,7 @@ std::string getX509Info(X509 *cert);
/********** SSL ERROR STUFF ******************************************/
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2,
std::ostream &out);
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::string &out);
#endif /* RS_PQI_SSL_HELPER_H */

View File

@ -44,7 +44,6 @@
#include <list>
#include <string>
#include <sstream>
#include <dirent.h>
#include <sys/types.h>
@ -1392,14 +1391,10 @@ bool RsInit::GenerateSSLCertificate(const std::string& gpg_id, const std::st
/* Flag as first time run */
RsInitConfig::firsttime_run = true;
{
std::ostringstream out;
out << "RetroShare has Successfully generated";
out << "a Certficate/Key" << std::endl;
out << "\tCert Located: " << cert_name << std::endl;
out << "\tLocated: " << key_name << std::endl;
std::cerr << out.str();
}
std::cerr << "RetroShare has Successfully generated a Certficate/Key" << std::endl;
std::cerr << "\tCert Located: " << cert_name << std::endl;
std::cerr << "\tLocated: " << key_name << std::endl;
return true;
}
@ -1643,13 +1638,10 @@ std::string RsInit::getHomePath()
#else /* Windows */
std::ostringstream out;
char *h2 = getenv("HOMEDRIVE");
out << "getHomePath() -> $HOMEDRIVE = ";
out << h2 << std::endl;
std::cerr << "getHomePath() -> $HOMEDRIVE = " << h2 << std::endl;
char *h3 = getenv("HOMEPATH");
out << "getHomePath() -> $HOMEPATH = ";
out << h3 << std::endl;
std::cerr << "getHomePath() -> $HOMEPATH = " << h3 << std::endl;
if (h2 == NULL)
{
@ -1664,8 +1656,7 @@ std::string RsInit::getHomePath()
home += "\\Desktop";
}
out << "fltkserver::getHomePath() -> " << home << std::endl;
std::cerr << out.str();
std::cerr << "fltkserver::getHomePath() -> " << home << std::endl;
// convert to FLTK desired format.
home = RsDirUtil::convertPathToUnix(home);

View File

@ -125,7 +125,13 @@ RsItem::~RsItem()
{
}
void RsItem::print_string(std::string &out, uint16_t indent)
{
std::ostringstream stream;
print(stream, indent);
out += stream.str();
}
uint32_t RsItem::PacketId()
{
return type;

View File

@ -81,6 +81,7 @@ class RsItem: public RsMemoryManagement::SmallObject
virtual ~RsItem();
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */
const std::string& PeerId() const { return peerId; }

View File

@ -191,7 +191,7 @@ int locked_getZoneLevel(int zone)
return it -> second;
}
int rslog(unsigned int lvl, int zone, std::string msg)
int rslog(unsigned int lvl, int zone, const std::string &msg)
{
RsStackMutex stack(logMtx); /******** LOCKED ****************/
if ((signed) lvl <= locked_getZoneLevel(zone))

View File

@ -49,7 +49,7 @@ int clearDebugCrashLog();
int setDebugFile(const char *fname);
int setOutputLevel(int lvl);
int setZoneLevel(int lvl, int zone);
int rslog(unsigned int lvl, int zone, std::string msg);
int rslog(unsigned int lvl, int zone, const std::string &msg);